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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
//
// System.Xml.NameTableTests.cs
//
// Author: Duncan Mak (duncan@ximian.com)
// Author: Martin Willemoes Hansen (mwh@sysrq.dk)
//
// (C) Ximian, Inc.
// (C) 2003 Martin Willemoes Hansen
//
using System;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.Xml
{
[TestFixture]
public class NameTableTests : Assertion
{
NameTable table;
[SetUp]
public void GetReady ()
{
table = new NameTable ();
}
//
// Tests System.Xml.NameTable.Add (string)
//
[Test]
public void Add1 ()
{
string add = "add1";
string testAdd = table.Add (add);
AssertEquals ("#1", add, testAdd);
AssertSame ("#2", add, testAdd);
testAdd = table.Add ("");
AssertEquals ("#3", string.Empty, testAdd);
AssertSame ("#4", string.Empty, testAdd);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Add1_Null ()
{
table.Add ((string) null);
}
//
// Tests System.Xml.NameTable.Add (char[], int, int)
//
[Test]
public void Add2 ()
{
char[] test = new char [4] { 'a', 'd', 'd', '2' };
int index = 0;
int length = 3; // "add"
string testAdd = table.Add (test, index, length);
AssertEquals ("#1", "add", testAdd);
testAdd = table.Add ((char[]) null, 0, 0);
AssertEquals ("#2", string.Empty, testAdd);
AssertSame ("#3", string.Empty, testAdd);
testAdd = table.Add (new char[0], 0, 0);
AssertEquals ("#4", string.Empty, testAdd);
AssertSame ("#5", string.Empty, testAdd);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void Add2_Null ()
{
table.Add ((char[]) null, 0, 1);
}
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void Add2_InvalidIndex ()
{
table.Add (new char[3] { 'a', 'b', 'c' }, 4, 1);
}
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void Add2_InvalidLength ()
{
table.Add (new char[0], 0, 1);
}
//
// Tests System.Xml.NameTable.Get (string)
//
[Test]
public void Get1 ()
{
string get1 = "get1";
string testGet = table.Add (get1);
AssertEquals ("#1", "get1", testGet);
AssertEquals ("#2", testGet, table.Get (get1));
AssertSame ("#3", get1, testGet );
testGet = table.Get ("");
AssertEquals ("#1", string.Empty, testGet);
AssertSame ("#2", string.Empty, testGet);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Get1_Null ()
{
table.Get ((string) null);
}
//
// Tests System.Xml.NameTable.Get (char[], int, int)
//
[Test]
public void Get2 ()
{
char[] test = new char [4] { 'g', 'e', 't', '2' };
int index = 0;
int length = 3; // "get"
string testGet = table.Add (test, index, length);
AssertEquals ("#1", "get", testGet);
AssertEquals ("#2", testGet, table.Get ("get"));
AssertEquals ("#3", testGet, table.Get (test, index, length));
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void Get2_Null ()
{
table.Get ((char[]) null, 0, 1);
}
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void Get2_InvalidIndex ()
{
table.Get (new char[3] { 'a', 'b', 'c' }, 4, 1);
}
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void Get2_InvalidLength ()
{
table.Get (new char[3] { 'a', 'b', 'c' }, 2, 6);
}
//
// Tests System.Xml.NameTable.Get (char[], int, 0)
//
[Test]
public void Get3 ()
{
string testGet = null;
testGet = table.Get ((char[]) null, 10, 0);
AssertEquals ("#1", string.Empty, testGet);
AssertSame ("#2", string.Empty, testGet);
testGet = table.Get (new char[0], 2, 0);
AssertEquals ("#3", string.Empty, testGet);
AssertSame ("#4", string.Empty, testGet);
testGet = table.Get (new char[3] { 'a', 'b', 'c' }, 5, 0);
AssertEquals ("#5", string.Empty, testGet);
AssertSame ("#6", string.Empty, testGet);
}
}
}
|