[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Security.Permissions / IBuiltInPermissionTest.cs
blobff6f57a07f5e2fbd29956746bc01f3ee80407f0a
1 //
2 // IBuiltInPermissionTest.cs - NUnit Test Cases for IBuiltInPermission
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004-2005 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));
114 [Test]
115 #if MOBILE
116 [Ignore]
117 #endif
118 public void HostProtection ()
120 HostProtectionAttribute hpa = new HostProtectionAttribute ();
121 // internal permission
122 IPermission p = hpa.CreatePermission ();
123 Assert.AreEqual (9, GetTokenIndex (p));
126 [Test]
127 public void PublisherIdentity ()
129 IPermission p = (IPermission) new PublisherIdentityPermission (PermissionState.None);
130 Assert.AreEqual (10, GetTokenIndex (p));
133 [Test]
134 public void SiteIdentity ()
136 IPermission p = (IPermission) new SiteIdentityPermission (PermissionState.None);
137 Assert.AreEqual (11, GetTokenIndex (p));
140 [Test]
141 public void StrongNameIdentity ()
143 IPermission p = (IPermission) new StrongNameIdentityPermission (PermissionState.None);
144 Assert.AreEqual (12, GetTokenIndex (p));
147 [Test]
148 public void UrlIdentity ()
150 IPermission p = (IPermission) new UrlIdentityPermission (PermissionState.None);
151 Assert.AreEqual (13, GetTokenIndex (p));
154 [Test]
155 public void ZoneIdentity ()
157 IPermission p = (IPermission) new ZoneIdentityPermission (PermissionState.None);
158 Assert.AreEqual (14, GetTokenIndex (p));
161 [Test]
162 public void GacIdentity ()
164 IPermission p = (IPermission) new GacIdentityPermission (PermissionState.None);
165 Assert.AreEqual (15, GetTokenIndex (p));
168 [Test]
169 public void KeyContainer ()
171 IPermission p = (IPermission)new KeyContainerPermission (PermissionState.None);
172 Assert.AreEqual (16, GetTokenIndex (p));