**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.Security.Permissions / IBuiltInPermissionTest.cs
blob4cbecae769152276f38bb4d080686672bed0cb3d
1 //
2 // IBuiltInPermissionTest.cs - NUnit Test Cases for IBuiltInPermission
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 using NUnit.Framework;
30 using System;
31 using System.Reflection;
32 using System.Security;
33 using System.Security.Permissions;
35 namespace MonoTests.System.Security.Permissions {
37 [TestFixture]
38 public class IBuiltInPermissionTest {
40 // IBuiltInPermission is internal but we can test it's values
41 // using reflection.
42 private int GetTokenIndex (IPermission p)
44 Type t = p.GetType ();
45 int result = (int) t.InvokeMember ("System.Security.Permissions.IBuiltInPermission.GetTokenIndex",
46 BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
47 null, p, null);
48 return result;
51 [Test]
52 public void Environment ()
54 IPermission p = (IPermission) new EnvironmentPermission (PermissionState.None);
55 Assert.AreEqual (0, GetTokenIndex (p));
58 [Test]
59 public void FileDialog ()
61 IPermission p = (IPermission) new FileDialogPermission (PermissionState.None);
62 Assert.AreEqual (1, GetTokenIndex (p));
65 [Test]
66 public void FileIO ()
68 IPermission p = (IPermission) new FileIOPermission (PermissionState.None);
69 Assert.AreEqual (2, GetTokenIndex (p));
72 [Test]
73 public void IsolatedStorageFile ()
75 IPermission p = (IPermission) new IsolatedStorageFilePermission (PermissionState.None);
76 Assert.AreEqual (3, GetTokenIndex (p));
79 [Test]
80 public void Reflection ()
82 IPermission p = (IPermission) new ReflectionPermission (PermissionState.None);
83 Assert.AreEqual (4, GetTokenIndex (p));
86 [Test]
87 public void Registry ()
89 IPermission p = (IPermission) new RegistryPermission (PermissionState.None);
90 Assert.AreEqual (5, GetTokenIndex (p));
93 [Test]
94 public void Security ()
96 IPermission p = (IPermission) new SecurityPermission (PermissionState.None);
97 Assert.AreEqual (6, GetTokenIndex (p));
100 [Test]
101 public void UI ()
103 IPermission p = (IPermission) new UIPermission (PermissionState.None);
104 Assert.AreEqual (7, GetTokenIndex (p));
107 [Test]
108 public void Principal ()
110 IPermission p = (IPermission) new PrincipalPermission (PermissionState.None);
111 Assert.AreEqual (8, GetTokenIndex (p));
113 #if NET_2_0
114 [Test]
115 public void HostProtection ()
117 HostProtectionAttribute hpa = new HostProtectionAttribute ();
118 // internal permission
119 IPermission p = hpa.CreatePermission ();
120 Assert.AreEqual (9, GetTokenIndex (p));
122 #endif
123 [Test]
124 public void PublisherIdentity ()
126 IPermission p = (IPermission) new PublisherIdentityPermission (PermissionState.None);
127 #if NET_2_0
128 Assert.AreEqual (10, GetTokenIndex (p));
129 #else
130 Assert.AreEqual (9, GetTokenIndex (p));
131 #endif
134 [Test]
135 public void SiteIdentity ()
137 IPermission p = (IPermission) new SiteIdentityPermission (PermissionState.None);
138 #if NET_2_0
139 Assert.AreEqual (11, GetTokenIndex (p));
140 #else
141 Assert.AreEqual (10, GetTokenIndex (p));
142 #endif
145 [Test]
146 public void StrongNameIdentity ()
148 IPermission p = (IPermission) new StrongNameIdentityPermission (PermissionState.None);
149 #if NET_2_0
150 Assert.AreEqual (12, GetTokenIndex (p));
151 #else
152 Assert.AreEqual (11, GetTokenIndex (p));
153 #endif
156 [Test]
157 public void UrlIdentity ()
159 IPermission p = (IPermission) new UrlIdentityPermission (PermissionState.None);
160 #if NET_2_0
161 Assert.AreEqual (13, GetTokenIndex (p));
162 #else
163 Assert.AreEqual (12, GetTokenIndex (p));
164 #endif
167 [Test]
168 public void ZoneIdentity ()
170 IPermission p = (IPermission) new ZoneIdentityPermission (PermissionState.None);
171 #if NET_2_0
172 Assert.AreEqual (14, GetTokenIndex (p));
173 #else
174 Assert.AreEqual (13, GetTokenIndex (p));
175 #endif
178 #if NET_2_0
179 // FIXME: where's #15 ???
181 [Test]
182 public void GacIdentity ()
184 IPermission p = (IPermission) new GacIdentityPermission (PermissionState.None);
185 Assert.AreEqual (16, GetTokenIndex (p));
188 [Test]
189 public void KeyContainer ()
191 IPermission p = (IPermission)new KeyContainerPermission (PermissionState.None);
192 Assert.AreEqual (17, GetTokenIndex (p));
195 [Test]
196 public void DataProtection ()
198 IPermission p = (IPermission) new DataProtectionPermission (PermissionState.None);
199 Assert.AreEqual (18, GetTokenIndex (p));
201 #endif