(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Permissions / GacIdentityPermissionTest.cs
blobf3d64a13c9c1022247d51a0ecd187892a642902e
1 //
2 // GacIdentityPermissionTest.cs - NUnit Test Cases for GacIdentityPermission
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #if NET_2_0
31 using NUnit.Framework;
32 using System;
33 using System.Security;
34 using System.Security.Permissions;
36 namespace MonoTests.System.Security.Permissions {
38 [TestFixture]
39 public class GacIdentityPermissionTest {
41 [Test]
42 public void PermissionStateNone ()
44 GacIdentityPermission gip = new GacIdentityPermission (PermissionState.None);
46 SecurityElement se = gip.ToXml ();
47 // only class and version are present
48 Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
49 Assert.IsNull (se.Children, "Xml-Children");
51 GacIdentityPermission copy = (GacIdentityPermission)gip.Copy ();
52 Assert.IsFalse (Object.ReferenceEquals (gip, copy), "ReferenceEquals");
55 [Test]
56 [ExpectedException (typeof (ArgumentException))]
57 public void PermissionStateUnrestricted ()
59 GacIdentityPermission gip = new GacIdentityPermission (PermissionState.Unrestricted);
62 [Test]
63 [ExpectedException (typeof (ArgumentException))]
64 public void PermissionStateInvalid ()
66 GacIdentityPermission gip = new GacIdentityPermission ((PermissionState)2);
69 [Test]
70 public void GacIdentityPermission_Empty ()
72 GacIdentityPermission gip = new GacIdentityPermission ();
73 Assert.IsNotNull (gip);
76 [Test]
77 public void Intersect ()
79 GacIdentityPermission gip = new GacIdentityPermission ();
81 GacIdentityPermission intersect = (GacIdentityPermission)gip.Intersect (null);
82 Assert.IsNull (intersect, "gip N null");
84 GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
85 intersect = (GacIdentityPermission)gip.Intersect (empty);
86 Assert.IsNotNull (intersect, "gip N null");
88 intersect = (GacIdentityPermission)gip.Intersect (gip);
89 Assert.IsNotNull (intersect, "gip N gip");
92 [Test]
93 [ExpectedException (typeof (ArgumentException))]
94 public void Intersect_DifferentPermissions ()
96 GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
97 SecurityPermission b = new SecurityPermission (PermissionState.None);
98 a.Intersect (b);
101 [Test]
102 public void IsSubsetOf ()
104 GacIdentityPermission gip = new GacIdentityPermission ();
105 Assert.IsFalse (gip.IsSubsetOf (null), "gip.IsSubsetOf (null)");
107 GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
108 Assert.IsFalse (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
111 [Test]
112 [ExpectedException (typeof (ArgumentException))]
113 public void IsSubsetOf_DifferentPermissions ()
115 GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
116 SecurityPermission b = new SecurityPermission (PermissionState.None);
117 a.IsSubsetOf (b);
120 [Test]
121 public void Union ()
123 GacIdentityPermission gip = new GacIdentityPermission ();
125 GacIdentityPermission union = (GacIdentityPermission)gip.Union (null);
126 Assert.IsNotNull (union, "gip U null");
128 GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
129 union = (GacIdentityPermission)gip.Union (empty);
130 Assert.IsNotNull (union, "gip U empty");
132 union = (GacIdentityPermission)gip.Union (gip);
133 Assert.IsNotNull (union, "gip U gip");
135 // note: can't be tested with PermissionState.Unrestricted
138 [Test]
139 [ExpectedException (typeof (ArgumentException))]
140 public void Union_DifferentPermissions ()
142 GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
143 SecurityPermission b = new SecurityPermission (PermissionState.None);
144 a.Union (b);
147 [Test]
148 [ExpectedException (typeof (ArgumentNullException))]
149 public void FromXml_Null ()
151 GacIdentityPermission gip = new GacIdentityPermission ();
152 gip.FromXml (null);
155 [Test]
156 [ExpectedException (typeof (ArgumentException))]
157 public void FromXml_WrongTag ()
159 GacIdentityPermission gip = new GacIdentityPermission ();
160 SecurityElement se = gip.ToXml ();
161 se.Tag = "IMono";
162 gip.FromXml (se);
165 [Test]
166 [ExpectedException (typeof (ArgumentException))]
167 public void FromXml_WrongTagCase ()
169 GacIdentityPermission gip = new GacIdentityPermission ();
170 SecurityElement se = gip.ToXml ();
171 se.Tag = "IPERMISSION"; // instead of IPermission
172 gip.FromXml (se);
175 [Test]
176 public void FromXml_WrongClass ()
178 GacIdentityPermission gip = new GacIdentityPermission ();
179 SecurityElement se = gip.ToXml ();
181 SecurityElement w = new SecurityElement (se.Tag);
182 w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
183 w.AddAttribute ("version", se.Attribute ("version"));
184 gip.FromXml (w);
185 // doesn't care of the class name at that stage
186 // anyway the class has already be created so...
189 [Test]
190 public void FromXml_NoClass ()
192 GacIdentityPermission gip = new GacIdentityPermission ();
193 SecurityElement se = gip.ToXml ();
195 SecurityElement w = new SecurityElement (se.Tag);
196 w.AddAttribute ("version", se.Attribute ("version"));
197 gip.FromXml (w);
198 // doesn't even care of the class attribute presence
201 [Test]
202 [ExpectedException (typeof (ArgumentException))]
203 public void FromXml_WrongVersion ()
205 GacIdentityPermission gip = new GacIdentityPermission ();
206 SecurityElement se = gip.ToXml ();
207 se.Attributes.Remove ("version");
208 se.Attributes.Add ("version", "2");
209 gip.FromXml (se);
212 [Test]
213 public void FromXml_NoVersion ()
215 GacIdentityPermission gip = new GacIdentityPermission ();
216 SecurityElement se = gip.ToXml ();
218 SecurityElement w = new SecurityElement (se.Tag);
219 w.AddAttribute ("class", se.Attribute ("class"));
220 gip.FromXml (w);
225 #endif