Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeTypeReferenceCas.cs
1 //
2 // CodeTypeReferenceCas.cs 
3 //      - CAS unit tests for System.CodeDom.CodeTypeReference
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 CodeTypeReferenceCas {
43
44                 [SetUp]
45                 public void SetUp ()
46                 {
47                         if (!SecurityManager.SecurityEnabled)
48                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
49                 }
50                 [Test]
51                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
52                 public void Constructor0_Deny_Unrestricted ()
53                 {
54                         CodeTypeReference ctr = new CodeTypeReference ();
55                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
56                         ctr.ArrayElementType = new CodeTypeReference ();
57                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
58                         ctr.ArrayRank = 1;
59                         Assert.AreEqual (String.Empty, ctr.BaseType, "BaseType");
60                         ctr.BaseType = "System.Void";
61                         Assert.AreEqual ((CodeTypeReferenceOptions)0, ctr.Options, "Options");
62                         ctr.Options = CodeTypeReferenceOptions.GlobalReference;
63                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
64                 }
65                 [Test]
66                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
67                 public void Constructor1_Deny_Unrestricted ()
68                 {
69                         CodeTypeReference ctr = new CodeTypeReference ("System.Int32");
70                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
71                         ctr.BaseType = String.Empty;
72                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
73                         ctr.ArrayElementType = new CodeTypeReference ("System.String");
74                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
75                         ctr.ArrayRank = 1;
76                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
77                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
78                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
79                 }
80
81                 [Test]
82                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
83                 public void Constructor2_Deny_Unrestricted ()
84                 {
85                         CodeTypeReference ctr = new CodeTypeReference (typeof (int));
86                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
87                         ctr.BaseType = String.Empty;
88                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
89                         ctr.ArrayElementType = new CodeTypeReference ("System.String");
90                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
91                         ctr.ArrayRank = 1;
92                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
93                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
94                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
95                 }
96
97                 [Test]
98                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
99                 public void Constructor3_Deny_Unrestricted ()
100                 {
101                         CodeTypeReference array = new CodeTypeReference ("System.Int32");
102                         CodeTypeReference ctr = new CodeTypeReference (array, 1);
103                         Assert.AreSame (array, ctr.ArrayElementType, "ArrayElementType");
104                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
105                         Assert.AreEqual (1, ctr.ArrayRank, "ArrayRank");
106                         ctr.ArrayElementType = new CodeTypeReference ("System.String");
107                         ctr.BaseType = String.Empty;
108                         ctr.ArrayRank = 0;
109                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
110                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
111                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
112                 }
113                 [Test]
114                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
115                 public void Constructor4_Deny_Unrestricted ()
116                 {
117                         CodeTypeParameter parameter = new CodeTypeParameter ("System.Int32");
118                         CodeTypeReference ctr = new CodeTypeReference (parameter);
119                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
120                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
121                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
122                         ctr.ArrayElementType = new CodeTypeReference ();
123                         ctr.BaseType = String.Empty;
124                         ctr.ArrayRank = 1;
125                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, ctr.Options, "Options");
126                         ctr.Options = CodeTypeReferenceOptions.GlobalReference;
127                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
128                 }
129
130                 [Test]
131                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
132                 public void Constructor5_Deny_Unrestricted ()
133                 {
134                         CodeTypeReference ctr = new CodeTypeReference ("System.Int32", CodeTypeReferenceOptions.GlobalReference);
135                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
136                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
137                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
138                         ctr.ArrayElementType = new CodeTypeReference ();
139                         ctr.BaseType = String.Empty;
140                         ctr.ArrayRank = 1;
141                         Assert.AreEqual (CodeTypeReferenceOptions.GlobalReference, ctr.Options, "Options");
142                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
143                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
144                 }
145
146                 [Test]
147                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
148                 public void Constructor6_Deny_Unrestricted ()
149                 {
150                         CodeTypeReference ctr = new CodeTypeReference (typeof (int), CodeTypeReferenceOptions.GlobalReference);
151                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
152                         Assert.AreEqual ("System.Int32", ctr.BaseType, "BaseType");
153                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
154                         ctr.ArrayElementType = new CodeTypeReference ();
155                         ctr.BaseType = String.Empty;
156                         ctr.ArrayRank = 1;
157                         Assert.AreEqual (CodeTypeReferenceOptions.GlobalReference, ctr.Options, "Options");
158                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
159                         Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
160                 }
161
162                 [Test]
163                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
164                 public void Constructor7_Deny_Unrestricted ()
165                 {
166                         CodeTypeReference[] arguments = new CodeTypeReference[1] { new CodeTypeReference ("System.Int32") };
167                         CodeTypeReference ctr = new CodeTypeReference ("System.Int32", arguments);
168                         Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
169                         Assert.AreEqual ("System.Int32`1", ctr.BaseType, "BaseType");
170                         Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
171                         ctr.ArrayElementType = new CodeTypeReference ();
172                         ctr.BaseType = String.Empty;
173                         ctr.ArrayRank = 1;
174                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
175                         ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
176                         Assert.AreEqual (1, ctr.TypeArguments.Count, "TypeArguments");
177                 }
178                 [Test]
179                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
180                 public void LinkDemand_Deny_Unrestricted ()
181                 {
182                         Type[] types = new Type[1] { typeof (string) };
183                         ConstructorInfo ci = typeof (CodeTypeReference).GetConstructor (types);
184                         Assert.IsNotNull (ci, ".ctor(string)");
185                         Assert.IsNotNull (ci.Invoke (new object[1] { String.Empty }), "invoke");
186                 }
187         }
188 }