2 // System.Xml.NameTableTests.cs
4 // Author: Duncan Mak (duncan@ximian.com)
5 // Author: Martin Willemoes Hansen (mwh@sysrq.dk)
8 // (C) 2003 Martin Willemoes Hansen
14 using NUnit.Framework;
16 namespace MonoTests.System.Xml
19 public class NameTableTests
24 public void GetReady ()
26 table = new NameTable ();
30 // Tests System.Xml.NameTable.Add (string)
36 string testAdd = table.Add (add);
37 Assert.AreEqual (add, testAdd, "#1");
38 Assert.AreSame (add, testAdd, "#2");
40 testAdd = table.Add ("");
41 Assert.AreEqual (string.Empty, testAdd, "#3");
42 Assert.AreSame (string.Empty, testAdd, "#4");
46 [ExpectedException (typeof (ArgumentNullException))]
47 public void Add1_Null ()
49 table.Add ((string) null);
53 // Tests System.Xml.NameTable.Add (char[], int, int)
58 char[] test = new char [4] { 'a', 'd', 'd', '2' };
60 int length = 3; // "add"
62 string testAdd = table.Add (test, index, length);
63 Assert.AreEqual ("add", testAdd, "#1");
65 testAdd = table.Add ((char[]) null, 0, 0);
66 Assert.AreEqual (string.Empty, testAdd, "#2");
67 Assert.AreSame (string.Empty, testAdd, "#3");
69 testAdd = table.Add (new char[0], 0, 0);
70 Assert.AreEqual (string.Empty, testAdd, "#4");
71 Assert.AreSame (string.Empty, testAdd, "#5");
75 [ExpectedException (typeof (NullReferenceException))]
76 public void Add2_Null ()
78 table.Add ((char[]) null, 0, 1);
82 [ExpectedException (typeof (IndexOutOfRangeException))]
83 public void Add2_InvalidIndex ()
85 table.Add (new char[3] { 'a', 'b', 'c' }, 4, 1);
89 [ExpectedException (typeof (IndexOutOfRangeException))]
90 public void Add2_InvalidLength ()
92 table.Add (new char[0], 0, 1);
96 // Tests System.Xml.NameTable.Get (string)
101 string get1 = "get1";
102 string testGet = table.Add (get1);
103 Assert.AreEqual ("get1", testGet, "#1");
105 Assert.AreEqual (testGet, table.Get (get1), "#2");
106 Assert.AreSame (get1, testGet, "#3");
108 testGet = table.Get ("");
109 Assert.AreEqual (string.Empty, testGet, "#1");
110 Assert.AreSame (string.Empty, testGet, "#2");
114 [ExpectedException (typeof (ArgumentNullException))]
115 public void Get1_Null ()
117 table.Get ((string) null);
121 // Tests System.Xml.NameTable.Get (char[], int, int)
126 char[] test = new char [4] { 'g', 'e', 't', '2' };
128 int length = 3; // "get"
130 string testGet = table.Add (test, index, length);
131 Assert.AreEqual ("get", testGet, "#1");
133 Assert.AreEqual (testGet, table.Get ("get"), "#2");
134 Assert.AreEqual (testGet, table.Get (test, index, length), "#3");
138 [ExpectedException (typeof (NullReferenceException))]
139 public void Get2_Null ()
141 table.Get ((char[]) null, 0, 1);
145 [ExpectedException (typeof (IndexOutOfRangeException))]
146 public void Get2_InvalidIndex ()
148 table.Get (new char[3] { 'a', 'b', 'c' }, 4, 1);
152 [ExpectedException (typeof (IndexOutOfRangeException))]
153 public void Get2_InvalidLength ()
155 table.Get (new char[3] { 'a', 'b', 'c' }, 2, 6);
159 // Tests System.Xml.NameTable.Get (char[], int, 0)
164 string testGet = null;
166 testGet = table.Get ((char[]) null, 10, 0);
167 Assert.AreEqual (string.Empty, testGet, "#1");
168 Assert.AreSame (string.Empty, testGet, "#2");
170 testGet = table.Get (new char[0], 2, 0);
171 Assert.AreEqual (string.Empty, testGet, "#3");
172 Assert.AreSame (string.Empty, testGet, "#4");
174 testGet = table.Get (new char[3] { 'a', 'b', 'c' }, 5, 0);
175 Assert.AreEqual (string.Empty, testGet, "#5");
176 Assert.AreSame (string.Empty, testGet, "#6");