2 // CodeTypeReferenceCas.cs
3 // - CAS unit tests for System.CodeDom.CodeTypeReference
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 CodeTypeReferenceCas {
47 if (!SecurityManager.SecurityEnabled)
48 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
51 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
52 public void Constructor0_Deny_Unrestricted ()
54 CodeTypeReference ctr = new CodeTypeReference ();
55 Assert.IsNull (ctr.ArrayElementType, "ArrayElementType");
56 ctr.ArrayElementType = new CodeTypeReference ();
57 Assert.AreEqual (0, ctr.ArrayRank, "ArrayRank");
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");
66 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
67 public void Constructor1_Deny_Unrestricted ()
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");
76 Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
77 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
78 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
82 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
83 public void Constructor2_Deny_Unrestricted ()
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");
92 Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
93 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
94 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
98 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
99 public void Constructor3_Deny_Unrestricted ()
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;
109 Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
110 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
111 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
114 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
115 public void Constructor4_Deny_Unrestricted ()
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;
125 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, ctr.Options, "Options");
126 ctr.Options = CodeTypeReferenceOptions.GlobalReference;
127 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
131 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
132 public void Constructor5_Deny_Unrestricted ()
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;
141 Assert.AreEqual (CodeTypeReferenceOptions.GlobalReference, ctr.Options, "Options");
142 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
143 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
147 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
148 public void Constructor6_Deny_Unrestricted ()
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;
157 Assert.AreEqual (CodeTypeReferenceOptions.GlobalReference, ctr.Options, "Options");
158 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
159 Assert.AreEqual (0, ctr.TypeArguments.Count, "TypeArguments");
163 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
164 public void Constructor7_Deny_Unrestricted ()
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;
174 Assert.AreEqual ((CodeTypeReferenceOptions) 0, ctr.Options, "Options");
175 ctr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
176 Assert.AreEqual (1, ctr.TypeArguments.Count, "TypeArguments");
179 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
180 public void LinkDemand_Deny_Unrestricted ()
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");