2
0

XmlDictionaryReaderQuotasTest.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // XmlDictionaryReaderQuotasTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Xml;
  30. using NUnit.Framework;
  31. using Q = System.Xml.XmlDictionaryReaderQuotas;
  32. namespace MonoTests.System.Xml
  33. {
  34. [TestFixture]
  35. public class XmlDictionaryReaderQuotasTest
  36. {
  37. [Test]
  38. public void StaticAndDefaultValues ()
  39. {
  40. /*
  41. Assert.AreEqual (
  42. int.MaxValue, Q.DefaultMaxArrayLength,
  43. "static DefaultMaxArrayLength");
  44. Assert.AreEqual (
  45. int.MaxValue, Q.DefaultMaxBytesPerRead,
  46. "static DefaultMaxBytesPerRead");
  47. Assert.AreEqual (
  48. int.MaxValue, Q.DefaultMaxDepth,
  49. "static DefaultMaxDepth");
  50. Assert.AreEqual (
  51. int.MaxValue, Q.DefaultMaxNameTableCharCount,
  52. "static DefaultMaxNameTableCharCount");
  53. Assert.AreEqual (
  54. int.MaxValue, Q.DefaultMaxStringContentLength,
  55. "static DefaultMaxStringContentLength");
  56. */
  57. Q q = new Q (); //Q.Default;
  58. Assert.AreEqual (
  59. 0x4000, q.MaxArrayLength,
  60. "default - MaxArrayLength");
  61. Assert.AreEqual (
  62. 0x1000, q.MaxBytesPerRead,
  63. "default - MaxBytesPerRead");
  64. Assert.AreEqual (
  65. 0x20, q.MaxDepth,
  66. "default - MaxDepth");
  67. Assert.AreEqual (
  68. 0x4000, q.MaxNameTableCharCount,
  69. "default - MaxNameTableCharCount");
  70. Assert.AreEqual (
  71. 0x2000, q.MaxStringContentLength,
  72. "default - MaxStringContentLength");
  73. q = Q.Max;
  74. Assert.AreEqual (
  75. int.MaxValue, q.MaxArrayLength,
  76. "max - MaxArrayLength");
  77. Assert.AreEqual (
  78. int.MaxValue, q.MaxBytesPerRead,
  79. "max - MaxBytesPerRead");
  80. Assert.AreEqual (
  81. int.MaxValue, q.MaxDepth,
  82. "max - MaxDepth");
  83. Assert.AreEqual (
  84. int.MaxValue, q.MaxNameTableCharCount,
  85. "max - MaxNameTableCharCount");
  86. Assert.AreEqual (
  87. int.MaxValue, q.MaxStringContentLength,
  88. "max - MaxStringContentLength");
  89. }
  90. [Test]
  91. public void SetZero ()
  92. {
  93. // having ExpectedExceptions for each test and splitting
  94. // methods is messy, so am just having all of them
  95. // in this test.
  96. Q q = new Q ();
  97. try {
  98. q.MaxArrayLength = 0;
  99. Assert.Fail ("MaxArrayLength = 0 should fail.");
  100. } catch (ArgumentException) {
  101. }
  102. try {
  103. q.MaxBytesPerRead = 0;
  104. Assert.Fail ("MaxBytesPerRead = 0 should fail.");
  105. } catch (ArgumentException) {
  106. }
  107. try {
  108. q.MaxDepth = 0;
  109. Assert.Fail ("MaxDepth = 0 should fail.");
  110. } catch (ArgumentException) {
  111. }
  112. try {
  113. q.MaxNameTableCharCount = 0;
  114. Assert.Fail ("MaxNameTableCharCount = 0 should fail.");
  115. } catch (ArgumentException) {
  116. }
  117. try {
  118. q.MaxStringContentLength = 0;
  119. Assert.Fail ("MaxStringContentLength = 0 should fail.");
  120. } catch (ArgumentException) {
  121. }
  122. }
  123. [Test]
  124. public void ReadonlyCheck ()
  125. {
  126. // having ExpectedExceptions for each test and splitting
  127. // methods is messy, so am just having all of them
  128. // in this test.
  129. Q q = Q.Max;
  130. try {
  131. q.MaxArrayLength = int.MaxValue;
  132. Assert.Fail ("Default MaxArrayLength is readonly");
  133. } catch (InvalidOperationException) {
  134. }
  135. try {
  136. q.MaxBytesPerRead = int.MaxValue;
  137. Assert.Fail ("Default MaxBytesPerRead is readonly");
  138. } catch (InvalidOperationException) {
  139. }
  140. try {
  141. q.MaxDepth = int.MaxValue;
  142. Assert.Fail ("Default MaxDepth is readonly");
  143. } catch (InvalidOperationException) {
  144. }
  145. try {
  146. q.MaxNameTableCharCount = int.MaxValue;
  147. Assert.Fail ("Default MaxNameTableCharCount is readonly");
  148. } catch (InvalidOperationException) {
  149. }
  150. try {
  151. q.MaxStringContentLength = int.MaxValue;
  152. Assert.Fail ("Default MaxStringContentLength is readonly");
  153. } catch (InvalidOperationException) {
  154. }
  155. }
  156. }
  157. }