2 // CodeArrayCreateExpressionCas.cs
3 // - CAS unit tests for System.CodeDom.CodeArrayCreateExpression
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
34 using System.Reflection;
35 using System.Security;
36 using System.Security.Permissions;
38 namespace MonoCasTests.System.CodeDom {
42 public class CodeArrayCreateExpressionCas {
44 private CodeTypeReference ctr;
45 private CodeExpression ce;
48 public void FixtureSetUp ()
51 ctr = new CodeTypeReference ("System.Void");
52 ce = new CodeExpression ();
58 if (!SecurityManager.SecurityEnabled)
59 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
62 private void CheckProperties (CodeArrayCreateExpression cace)
67 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
68 public void Constructor0_Deny_Unrestricted ()
70 CodeArrayCreateExpression cace = new CodeArrayCreateExpression ();
71 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
72 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
73 Assert.AreEqual (0, cace.Size, "Size");
74 Assert.IsNull (cace.SizeExpression, "SizeExpression");
78 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
79 public void Constructor1_Deny_Unrestricted ()
81 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, ce);
82 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
83 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
84 Assert.AreEqual (0, cace.Size, "Size");
85 Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
89 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
90 public void Constructor2_Deny_Unrestricted ()
92 CodeExpression[] parameters = new CodeExpression[1] { ce };
93 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, parameters);
94 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
95 Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
96 Assert.AreEqual (0, cace.Size, "Size");
97 Assert.IsNull (cace.SizeExpression, "SizeExpression");
101 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
102 public void Constructor3_Deny_Unrestricted ()
104 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, Int32.MinValue);
105 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
106 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
107 Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
108 Assert.IsNull (cace.SizeExpression, "SizeExpression");
112 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
113 public void Constructor4_Deny_Unrestricted ()
115 CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", ce);
116 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
117 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
118 Assert.AreEqual (0, cace.Size, "Size");
119 Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
123 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
124 public void Constructor5_Deny_Unrestricted ()
126 CodeExpression[] parameters = new CodeExpression[1] { ce };
127 CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", parameters);
128 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
129 Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
130 Assert.AreEqual (0, cace.Size, "Size");
131 Assert.IsNull (cace.SizeExpression, "SizeExpression");
135 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
136 public void Constructor6_Deny_Unrestricted ()
138 CodeArrayCreateExpression cace = new CodeArrayCreateExpression ("System.Void", Int32.MinValue);
139 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
140 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
141 Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
142 Assert.IsNull (cace.SizeExpression, "SizeExpression");
146 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
147 public void Constructor7_Deny_Unrestricted ()
149 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof(void), ce);
150 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
151 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
152 Assert.AreEqual (0, cace.Size, "Size");
153 Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
157 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
158 public void Constructor8_Deny_Unrestricted ()
160 CodeExpression[] parameters = new CodeExpression[1] { ce };
161 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof (void), parameters);
162 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
163 Assert.AreEqual (1, cace.Initializers.Count, "Initializers");
164 Assert.AreEqual (0, cace.Size, "Size");
165 Assert.IsNull (cace.SizeExpression, "SizeExpression");
169 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
170 public void Constructor9_Deny_Unrestricted ()
172 CodeArrayCreateExpression cace = new CodeArrayCreateExpression (typeof (void), Int32.MinValue);
173 Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
174 Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
175 Assert.AreEqual (Int32.MinValue, cace.Size, "Size");
176 Assert.IsNull (cace.SizeExpression, "SizeExpression");
180 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
181 public void LinkDemand_Deny_Unrestricted ()
183 ConstructorInfo ci = typeof (CodeArrayCreateExpression).GetConstructor (new Type[0]);
184 Assert.IsNotNull (ci, "default .ctor");
185 Assert.IsNotNull (ci.Invoke (null), "invoke");