NameTableTests.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // System.Xml.NameTableTests.cs
  3. //
  4. // Author: Duncan Mak ([email protected])
  5. // Author: Martin Willemoes Hansen ([email protected])
  6. //
  7. // (C) Ximian, Inc.
  8. // (C) 2003 Martin Willemoes Hansen
  9. //
  10. using System;
  11. using System.Xml;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Xml
  14. {
  15. [TestFixture]
  16. public class NameTableTests : Assertion
  17. {
  18. NameTable table;
  19. [SetUp]
  20. public void GetReady ()
  21. {
  22. table = new NameTable ();
  23. }
  24. //
  25. // Tests System.Xml.NameTable.Add (string)
  26. //
  27. [Test]
  28. public void Add1 ()
  29. {
  30. string add = "add1";
  31. string testAdd = table.Add (add);
  32. AssertEquals ("#1", add, testAdd);
  33. AssertSame ("#2", add, testAdd);
  34. testAdd = table.Add ("");
  35. AssertEquals ("#3", string.Empty, testAdd);
  36. AssertSame ("#4", string.Empty, testAdd);
  37. }
  38. [Test]
  39. [ExpectedException (typeof (ArgumentNullException))]
  40. public void Add1_Null ()
  41. {
  42. table.Add ((string) null);
  43. }
  44. //
  45. // Tests System.Xml.NameTable.Add (char[], int, int)
  46. //
  47. [Test]
  48. public void Add2 ()
  49. {
  50. char[] test = new char [4] { 'a', 'd', 'd', '2' };
  51. int index = 0;
  52. int length = 3; // "add"
  53. string testAdd = table.Add (test, index, length);
  54. AssertEquals ("#1", "add", testAdd);
  55. testAdd = table.Add ((char[]) null, 0, 0);
  56. AssertEquals ("#2", string.Empty, testAdd);
  57. AssertSame ("#3", string.Empty, testAdd);
  58. testAdd = table.Add (new char[0], 0, 0);
  59. AssertEquals ("#4", string.Empty, testAdd);
  60. AssertSame ("#5", string.Empty, testAdd);
  61. }
  62. [Test]
  63. [ExpectedException (typeof (NullReferenceException))]
  64. public void Add2_Null ()
  65. {
  66. table.Add ((char[]) null, 0, 1);
  67. }
  68. [Test]
  69. [ExpectedException (typeof (IndexOutOfRangeException))]
  70. public void Add2_InvalidIndex ()
  71. {
  72. table.Add (new char[3] { 'a', 'b', 'c' }, 4, 1);
  73. }
  74. [Test]
  75. [ExpectedException (typeof (IndexOutOfRangeException))]
  76. public void Add2_InvalidLength ()
  77. {
  78. table.Add (new char[0], 0, 1);
  79. }
  80. //
  81. // Tests System.Xml.NameTable.Get (string)
  82. //
  83. [Test]
  84. public void Get1 ()
  85. {
  86. string get1 = "get1";
  87. string testGet = table.Add (get1);
  88. AssertEquals ("#1", "get1", testGet);
  89. AssertEquals ("#2", testGet, table.Get (get1));
  90. AssertSame ("#3", get1, testGet );
  91. testGet = table.Get ("");
  92. AssertEquals ("#1", string.Empty, testGet);
  93. AssertSame ("#2", string.Empty, testGet);
  94. }
  95. [Test]
  96. [ExpectedException (typeof (ArgumentNullException))]
  97. public void Get1_Null ()
  98. {
  99. table.Get ((string) null);
  100. }
  101. //
  102. // Tests System.Xml.NameTable.Get (char[], int, int)
  103. //
  104. [Test]
  105. public void Get2 ()
  106. {
  107. char[] test = new char [4] { 'g', 'e', 't', '2' };
  108. int index = 0;
  109. int length = 3; // "get"
  110. string testGet = table.Add (test, index, length);
  111. AssertEquals ("#1", "get", testGet);
  112. AssertEquals ("#2", testGet, table.Get ("get"));
  113. AssertEquals ("#3", testGet, table.Get (test, index, length));
  114. }
  115. [Test]
  116. [ExpectedException (typeof (NullReferenceException))]
  117. public void Get2_Null ()
  118. {
  119. table.Get ((char[]) null, 0, 1);
  120. }
  121. [Test]
  122. [ExpectedException (typeof (IndexOutOfRangeException))]
  123. public void Get2_InvalidIndex ()
  124. {
  125. table.Get (new char[3] { 'a', 'b', 'c' }, 4, 1);
  126. }
  127. [Test]
  128. [ExpectedException (typeof (IndexOutOfRangeException))]
  129. public void Get2_InvalidLength ()
  130. {
  131. table.Get (new char[3] { 'a', 'b', 'c' }, 2, 6);
  132. }
  133. //
  134. // Tests System.Xml.NameTable.Get (char[], int, 0)
  135. //
  136. [Test]
  137. public void Get3 ()
  138. {
  139. string testGet = null;
  140. testGet = table.Get ((char[]) null, 10, 0);
  141. AssertEquals ("#1", string.Empty, testGet);
  142. AssertSame ("#2", string.Empty, testGet);
  143. testGet = table.Get (new char[0], 2, 0);
  144. AssertEquals ("#3", string.Empty, testGet);
  145. AssertSame ("#4", string.Empty, testGet);
  146. testGet = table.Get (new char[3] { 'a', 'b', 'c' }, 5, 0);
  147. AssertEquals ("#5", string.Empty, testGet);
  148. AssertSame ("#6", string.Empty, testGet);
  149. }
  150. }
  151. }