CodeCatchClauseTest.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // CodeCatchClauseTest.cs
  3. // - Unit tests for System.CodeDom.CodeCatchClause
  4. //
  5. // Author:
  6. // Gert Driesen <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.CodeDom;
  32. namespace MonoTests.System.CodeDom
  33. {
  34. [TestFixture]
  35. public class CodeCatchClauseTest
  36. {
  37. [Test]
  38. public void Constructor0 ()
  39. {
  40. CodeCatchClause ccc = new CodeCatchClause ();
  41. Assert.IsNotNull (ccc.CatchExceptionType, "#1");
  42. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
  43. Assert.IsNotNull (ccc.LocalName, "#3");
  44. Assert.AreEqual (string.Empty, ccc.LocalName, "#4");
  45. Assert.IsNotNull (ccc.Statements, "#5");
  46. Assert.AreEqual (0, ccc.Statements.Count, "#6");
  47. ccc.LocalName = null;
  48. Assert.IsNotNull (ccc.LocalName, "#7");
  49. Assert.AreEqual (string.Empty, ccc.LocalName, "#8");
  50. string localName = "mono";
  51. ccc.LocalName = localName;
  52. Assert.AreSame (localName, ccc.LocalName, "#9");
  53. ccc.CatchExceptionType = null;
  54. Assert.IsNotNull (ccc.CatchExceptionType, "#10");
  55. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
  56. CodeTypeReference cet = new CodeTypeReference("SomeException");
  57. ccc.CatchExceptionType = cet;
  58. Assert.AreSame (cet, ccc.CatchExceptionType, "#12");
  59. }
  60. [Test]
  61. public void Constructor1 () {
  62. string localName = "mono";
  63. CodeCatchClause ccc = new CodeCatchClause (localName);
  64. Assert.IsNotNull (ccc.CatchExceptionType, "#1");
  65. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
  66. Assert.IsNotNull (ccc.LocalName, "#3");
  67. Assert.AreEqual (localName, ccc.LocalName, "#4");
  68. Assert.AreSame (localName, ccc.LocalName, "#5");
  69. Assert.IsNotNull (ccc.Statements, "#6");
  70. Assert.AreEqual (0, ccc.Statements.Count, "#7");
  71. ccc.LocalName = null;
  72. Assert.IsNotNull (ccc.LocalName, "#8");
  73. Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
  74. ccc = new CodeCatchClause ((string) null);
  75. Assert.IsNotNull (ccc.LocalName, "#10");
  76. Assert.AreEqual (string.Empty, ccc.LocalName, "#22");
  77. }
  78. [Test]
  79. public void Constructor2 () {
  80. string localName = "mono";
  81. CodeTypeReference cet = new CodeTypeReference("SomeException");
  82. CodeCatchClause ccc = new CodeCatchClause (localName, cet);
  83. Assert.IsNotNull (ccc.CatchExceptionType, "#1");
  84. Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
  85. Assert.IsNotNull (ccc.LocalName, "#3");
  86. Assert.AreEqual (localName, ccc.LocalName, "#4");
  87. Assert.AreSame (localName, ccc.LocalName, "#5");
  88. Assert.IsNotNull (ccc.Statements, "#6");
  89. Assert.AreEqual (0, ccc.Statements.Count, "#7");
  90. ccc.LocalName = null;
  91. Assert.IsNotNull (ccc.LocalName, "#8");
  92. Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
  93. ccc.CatchExceptionType = null;
  94. Assert.IsNotNull (ccc.CatchExceptionType, "#10");
  95. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
  96. ccc = new CodeCatchClause ((string) null, (CodeTypeReference) null);
  97. Assert.IsNotNull (ccc.LocalName, "#12");
  98. Assert.AreEqual (string.Empty, ccc.LocalName, "#13");
  99. Assert.IsNotNull (ccc.CatchExceptionType, "#14");
  100. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#15");
  101. }
  102. [Test]
  103. public void Constructor3 () {
  104. string localName = "mono";
  105. CodeTypeReference cet = new CodeTypeReference("SomeException");
  106. CodeStatement cs1 = new CodeStatement ();
  107. CodeStatement cs2 = new CodeStatement ();
  108. CodeCatchClause ccc = new CodeCatchClause (localName, cet, cs1, cs2);
  109. Assert.IsNotNull (ccc.CatchExceptionType, "#1");
  110. Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
  111. Assert.IsNotNull (ccc.LocalName, "#3");
  112. Assert.AreEqual (localName, ccc.LocalName, "#4");
  113. Assert.AreSame (localName, ccc.LocalName, "#5");
  114. Assert.IsNotNull (ccc.Statements, "#6");
  115. Assert.AreEqual (2, ccc.Statements.Count, "#7");
  116. Assert.AreSame (cs1, ccc.Statements[0], "#8");
  117. Assert.AreSame (cs2, ccc.Statements[1], "#9");
  118. ccc.LocalName = null;
  119. Assert.IsNotNull (ccc.LocalName, "#8");
  120. Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
  121. ccc.CatchExceptionType = null;
  122. Assert.IsNotNull (ccc.CatchExceptionType, "#10");
  123. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
  124. ccc = new CodeCatchClause ((string) null, (CodeTypeReference) null, cs1);
  125. Assert.IsNotNull (ccc.LocalName, "#12");
  126. Assert.AreEqual (string.Empty, ccc.LocalName, "#13");
  127. Assert.IsNotNull (ccc.CatchExceptionType, "#14");
  128. Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#15");
  129. Assert.AreEqual (1, ccc.Statements.Count, "#16");
  130. Assert.AreSame (cs1, ccc.Statements[0], "#17");
  131. }
  132. }
  133. }