File: HybridDictionaryTest.cs

package info (click to toggle)
mono 2.6.7-5.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 327,344 kB
  • ctags: 413,649
  • sloc: cs: 2,471,883; xml: 1,768,594; ansic: 350,665; sh: 13,644; makefile: 8,640; perl: 1,784; asm: 717; cpp: 209; python: 146; sql: 81; sed: 16
file content (98 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// HybridDictionaryTest.cs - NUnit Test Cases for System.Net.HybridDictionary
//
// Authors:
//   Lawrence Pit (loz@cable.a2000.nl)
//   Martin Willemoes Hansen (mwh@sysrq.dk)
//   Sebastien Pouliot  <sebastien@ximian.com>
//
// (C) 2003 Martin Willemoes Hansen
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//

using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;

namespace MonoTests.System.Collections.Specialized
{
	[TestFixture]
	public class HybridDictionaryTest {

		[Test]
		public void DefaultValues ()
		{
			HybridDictionary hd = new HybridDictionary (100);
			Assert.AreEqual (0, hd.Count, "Count");
			Assert.IsFalse (hd.IsFixedSize, "IsFixedSize");
			Assert.IsFalse (hd.IsReadOnly, "IsReadOnly");
			Assert.IsFalse (hd.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, hd.Keys.Count, "Keys");
			Assert.AreEqual (0, hd.Values.Count, "Values");
			Assert.AreSame (hd, hd.SyncRoot, "SyncRoot");
			Assert.IsNotNull (hd.GetEnumerator (), "GetEnumerator");
			Assert.IsNotNull ((hd as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
		}

		[Test]
		public void All ()
		{
			HybridDictionary dict = new HybridDictionary (true);
			dict.Add ("CCC", "ccc");
			dict.Add ("BBB", "bbb");
			dict.Add ("fff", "fff");
			dict ["EEE"] = "eee";
			dict ["ddd"] = "ddd";
			
			Assert.AreEqual (5, dict.Count, "#1");
			Assert.AreEqual ("eee", dict["eee"], "#2");
			
			dict.Add ("CCC2", "ccc");
			dict.Add ("BBB2", "bbb");
			dict.Add ("fff2", "fff");
			dict ["EEE2"] = "eee";
			dict ["ddd2"] = "ddd";
			dict ["xxx"] = "xxx";
			dict ["yyy"] = "yyy";

			Assert.AreEqual (12, dict.Count, "#3");
			Assert.AreEqual ("eee", dict["eee"], "#4");

			dict.Remove ("eee");
			Assert.AreEqual (11, dict.Count, "Removed/Count");
			Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
			DictionaryEntry[] entries = new DictionaryEntry [11];
			dict.CopyTo (entries, 0);

			Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
			dict.Clear ();
			Assert.AreEqual (0, dict.Count, "Cleared/Count");
			Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
		}

		[Test]
#if NET_2_0
		[ExpectedException (typeof (ArgumentNullException))]
#endif
		public void Empty () 
		{
			HybridDictionary hd = new HybridDictionary ();
			Assert.AreEqual (0, hd.Count, "Count");
			Assert.IsFalse (hd.Contains ("unexisting"), "unexisting");
			// under 1.x no exception, under 2.0 ArgumentNullException
			Assert.IsFalse (hd.Contains (null), "Contains(null)");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void NotEmpty () 
		{
			HybridDictionary hd = new HybridDictionary (1, false);
			hd.Add ("CCC", "ccc");
			Assert.AreEqual (1, hd.Count, "Count");
			// ArgumentNullException under all fx versions
			Assert.IsFalse (hd.Contains (null), "Contains(null)");
		}
	}
}