2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / System.XML / Test / System.Xml / NameTableTests.cs
1 //
2 // System.Xml.NameTableTests.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 // Author: Martin Willemoes Hansen (mwh@sysrq.dk)
6 //
7 // (C) Ximian, Inc.
8 // (C) 2003 Martin Willemoes Hansen
9 //
10
11 using System;
12 using System.Xml;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Xml
17 {
18         [TestFixture]
19         public class NameTableTests
20         {
21                 NameTable table;
22                 
23                 [SetUp]
24                 public void GetReady ()
25                 {
26                         table = new NameTable ();
27                 }
28
29                 //
30                 // Tests System.Xml.NameTable.Add (string)
31                 //              
32                 [Test]
33                 public void Add1 ()
34                 {
35                         string add = "add1";
36                         string testAdd = table.Add (add);
37                         Assert.AreEqual (add, testAdd, "#1");
38                         Assert.AreSame (add, testAdd, "#2");
39
40                         testAdd = table.Add ("");
41                         Assert.AreEqual (string.Empty, testAdd, "#3");
42                         Assert.AreSame (string.Empty, testAdd, "#4");
43                 }
44
45                 [Test]
46                 [ExpectedException (typeof (ArgumentNullException))]
47                 public void Add1_Null ()
48                 {
49                         table.Add ((string) null);
50                 }
51
52                 //
53                 // Tests System.Xml.NameTable.Add (char[], int, int)
54                 //              
55                 [Test]
56                 public void Add2 ()
57                 {
58                         char[] test = new char [4] { 'a', 'd', 'd', '2' };
59                         int index = 0;
60                         int length = 3; // "add"
61
62                         string testAdd = table.Add (test, index, length);
63                         Assert.AreEqual ("add", testAdd, "#1");
64
65                         testAdd = table.Add ((char[]) null, 0, 0);
66                         Assert.AreEqual (string.Empty, testAdd, "#2");
67                         Assert.AreSame (string.Empty, testAdd, "#3");
68
69                         testAdd = table.Add (new char[0], 0, 0);
70                         Assert.AreEqual (string.Empty, testAdd, "#4");
71                         Assert.AreSame (string.Empty, testAdd, "#5");
72                 }
73
74                 [Test]
75                 [ExpectedException (typeof (NullReferenceException))]
76                 public void Add2_Null ()
77                 {
78                         table.Add ((char[]) null, 0, 1);
79                 }
80
81                 [Test]
82                 [ExpectedException (typeof (IndexOutOfRangeException))]
83                 public void Add2_InvalidIndex ()
84                 {
85                         table.Add (new char[3] { 'a', 'b', 'c' }, 4, 1);
86                 }
87
88                 [Test]
89                 [ExpectedException (typeof (IndexOutOfRangeException))]
90                 public void Add2_InvalidLength ()
91                 {
92                         table.Add (new char[0], 0, 1);
93                 }
94
95                 //
96                 // Tests System.Xml.NameTable.Get (string)
97                 //
98                 [Test]
99                 public void Get1 ()
100                 {
101                         string get1 = "get1";
102                         string testGet = table.Add (get1);
103                         Assert.AreEqual ("get1", testGet, "#1");
104
105                         Assert.AreEqual (testGet, table.Get (get1), "#2");
106                         Assert.AreSame (get1, testGet, "#3");
107
108                         testGet = table.Get ("");
109                         Assert.AreEqual (string.Empty, testGet, "#1");
110                         Assert.AreSame (string.Empty, testGet, "#2");
111                 }
112
113                 [Test]
114                 [ExpectedException (typeof (ArgumentNullException))]
115                 public void Get1_Null ()
116                 {
117                         table.Get ((string) null);
118                 }
119
120                 //
121                 // Tests System.Xml.NameTable.Get (char[], int, int)
122                 //
123                 [Test]
124                 public void Get2 ()
125                 {
126                         char[] test = new char [4] { 'g', 'e', 't', '2' };
127                         int index = 0; 
128                         int length = 3; // "get"
129                         
130                         string testGet = table.Add (test, index, length);
131                         Assert.AreEqual ("get", testGet, "#1");
132
133                         Assert.AreEqual (testGet, table.Get ("get"), "#2");
134                         Assert.AreEqual (testGet, table.Get (test, index, length), "#3");
135                 }
136
137                 [Test]
138                 [ExpectedException (typeof (NullReferenceException))]
139                 public void Get2_Null ()
140                 {
141                         table.Get ((char[]) null, 0, 1);
142                 }
143
144                 [Test]
145                 [ExpectedException (typeof (IndexOutOfRangeException))]
146                 public void Get2_InvalidIndex ()
147                 {
148                         table.Get (new char[3] { 'a', 'b', 'c' }, 4, 1);
149                 }
150
151                 [Test]
152                 [ExpectedException (typeof (IndexOutOfRangeException))]
153                 public void Get2_InvalidLength ()
154                 {
155                         table.Get (new char[3] { 'a', 'b', 'c' }, 2, 6);
156                 }
157
158                 //
159                 // Tests System.Xml.NameTable.Get (char[], int, 0)
160                 //
161                 [Test]
162                 public void Get3 ()
163                 {
164                         string testGet = null;
165
166                         testGet = table.Get ((char[]) null, 10, 0);
167                         Assert.AreEqual (string.Empty, testGet, "#1");
168                         Assert.AreSame (string.Empty, testGet, "#2");
169
170                         testGet = table.Get (new char[0], 2, 0);
171                         Assert.AreEqual (string.Empty, testGet, "#3");
172                         Assert.AreSame (string.Empty, testGet, "#4");
173
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");
177                 }
178         }
179 }