Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeArrayCreateExpressionCas.cs
1 //
2 // CodeArrayCreateExpressionCas.cs
3 //      - CAS unit tests for System.CodeDom.CodeArrayCreateExpression
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
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
30 using NUnit.Framework;
31
32 using System;
33 using System.CodeDom;
34 using System.Reflection;
35 using System.Security;
36 using System.Security.Permissions;
37
38 namespace MonoCasTests.System.CodeDom {
39
40         [TestFixture]
41         [Category ("CAS")]
42         public class CodeArrayCreateExpressionCas {
43
44                 private CodeTypeReference ctr;
45                 private CodeExpression ce;
46
47                 [TestFixtureSetUp]
48                 public void FixtureSetUp ()
49                 {
50                         // at fulltrust
51                         ctr = new CodeTypeReference ("System.Void");
52                         ce = new CodeExpression ();
53                 }
54
55                 [SetUp]
56                 public void SetUp ()
57                 {
58                         if (!SecurityManager.SecurityEnabled)
59                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
60                 }
61
62                 private void CheckProperties (CodeArrayCreateExpression cace)
63                 {
64                 }
65
66                 [Test]
67                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
68                 public void Constructor0_Deny_Unrestricted ()
69                 {
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");
75                 }
76
77                 [Test]
78                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
79                 public void Constructor1_Deny_Unrestricted ()
80                 {
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");
86                 }
87
88                 [Test]
89                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
90                 public void Constructor2_Deny_Unrestricted ()
91                 {
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");
98                 }
99
100                 [Test]
101                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
102                 public void Constructor3_Deny_Unrestricted ()
103                 {
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");
109                 }
110
111                 [Test]
112                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
113                 public void Constructor4_Deny_Unrestricted ()
114                 {
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");
120                 }
121
122                 [Test]
123                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
124                 public void Constructor5_Deny_Unrestricted ()
125                 {
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");
132                 }
133
134                 [Test]
135                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
136                 public void Constructor6_Deny_Unrestricted ()
137                 {
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");
143                 }
144
145                 [Test]
146                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
147                 public void Constructor7_Deny_Unrestricted ()
148                 {
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");
154                 }
155
156                 [Test]
157                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
158                 public void Constructor8_Deny_Unrestricted ()
159                 {
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");
166                 }
167
168                 [Test]
169                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
170                 public void Constructor9_Deny_Unrestricted ()
171                 {
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");
177                 }
178
179                 [Test]
180                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
181                 public void LinkDemand_Deny_Unrestricted ()
182                 {
183                         ConstructorInfo ci = typeof (CodeArrayCreateExpression).GetConstructor (new Type[0]);
184                         Assert.IsNotNull (ci, "default .ctor");
185                         Assert.IsNotNull (ci.Invoke (null), "invoke");
186                 }
187         }
188 }