CodeArrayCreateExpressionCas.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // CodeArrayCreateExpressionCas.cs
  3. // - CAS unit tests for System.CodeDom.CodeArrayCreateExpression
  4. //
  5. // Author:
  6. // Sebastien Pouliot <[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. using System.Reflection;
  33. using System.Security;
  34. using System.Security.Permissions;
  35. namespace MonoCasTests.System.CodeDom {
  36. [TestFixture]
  37. [Category ("CAS")]
  38. public class CodeArrayCreateExpressionCas {
  39. private CodeTypeReference ctr;
  40. private CodeExpression ce;
  41. [TestFixtureSetUp]
  42. public void FixtureSetUp ()
  43. {
  44. // at fulltrust
  45. ctr = new CodeTypeReference ("System.Void");
  46. ce = new CodeExpression ();
  47. }
  48. [SetUp]
  49. public void SetUp ()
  50. {
  51. if (!SecurityManager.SecurityEnabled)
  52. Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
  53. }
  54. private void CheckProperties (CodeArrayCreateExpression cace)
  55. {
  56. }
  57. [Test]
  58. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  59. public void Constructor0_Deny_Unrestricted ()
  60. {
  61. CodeArrayCreateExpression cace = new CodeArrayCreateExpression ();
  62. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  63. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  64. Assert.AreEqual (0, cace.Size, "Size");
  65. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  66. }
  67. [Test]
  68. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  69. public void Constructor1_Deny_Unrestricted ()
  70. {
  71. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, ce);
  72. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  73. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  74. Assert.AreEqual (0, cace.Size, "Size");
  75. Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
  76. }
  77. [Test]
  78. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  79. public void Constructor2_Deny_Unrestricted ()
  80. {
  81. CodeExpression[] parameters = new CodeExpression[1] { ce };
  82. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, parameters);
  83. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  84. Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
  85. Assert.AreEqual (0, cace.Size, "Size");
  86. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  87. }
  88. [Test]
  89. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  90. public void Constructor3_Deny_Unrestricted ()
  91. {
  92. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, Int32.MinValue);
  93. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  94. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  95. Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
  96. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  97. }
  98. [Test]
  99. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  100. public void Constructor4_Deny_Unrestricted ()
  101. {
  102. CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", ce);
  103. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  104. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  105. Assert.AreEqual (0, cace.Size, "Size");
  106. Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
  107. }
  108. [Test]
  109. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  110. public void Constructor5_Deny_Unrestricted ()
  111. {
  112. CodeExpression[] parameters = new CodeExpression[1] { ce };
  113. CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", parameters);
  114. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  115. Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
  116. Assert.AreEqual (0, cace.Size, "Size");
  117. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  118. }
  119. [Test]
  120. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  121. public void Constructor6_Deny_Unrestricted ()
  122. {
  123. CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", Int32.MinValue);
  124. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  125. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  126. Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
  127. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  128. }
  129. [Test]
  130. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  131. public void Constructor7_Deny_Unrestricted ()
  132. {
  133. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof(void), ce);
  134. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  135. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  136. Assert.AreEqual (0, cace.Size, "Size");
  137. Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
  138. }
  139. [Test]
  140. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  141. public void Constructor8_Deny_Unrestricted ()
  142. {
  143. CodeExpression[] parameters = new CodeExpression[1] { ce };
  144. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof (void), parameters);
  145. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  146. Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
  147. Assert.AreEqual (0, cace.Size, "Size");
  148. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  149. }
  150. [Test]
  151. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  152. public void Constructor9_Deny_Unrestricted ()
  153. {
  154. CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof (void), Int32.MinValue);
  155. Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
  156. Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
  157. Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
  158. Assert.IsNull (cace.SizeExpression, "SizeExpression");
  159. }
  160. [Test]
  161. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  162. public void LinkDemand_Deny_Unrestricted ()
  163. {
  164. ConstructorInfo ci = typeof (CodeArrayCreateExpression).GetConstructor (new Type[0]);
  165. Assert.IsNotNull (ci, "default .ctor");
  166. Assert.IsNotNull (ci.Invoke (null), "invoke");
  167. }
  168. }
  169. }