[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Security.Policy / ApplicationMembershipConditionTest.cs
blob7a14586e78bedd1b8e05a3d19f3166c2a3a381c4
1 //
2 // ApplicationMembershipConditionTest.cs -
3 // NUnit Test Cases for ApplicationMembershipCondition
4 //
5 // Author:
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // Copyright (C) 2004 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.
31 using NUnit.Framework;
32 using System;
33 using System.Reflection;
34 using System.Security;
35 using System.Security.Policy;
37 namespace MonoTests.System.Security.Policy {
39 [TestFixture]
40 public class ApplicationMembershipConditionTest {
42 [Test]
43 public void Constructor ()
45 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
46 Assert.IsNotNull (app);
49 [Test]
50 public void Check ()
52 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
53 Evidence e = null;
54 Assert.IsFalse (app.Check (e), "Check (null)");
55 e = new Evidence ();
56 Assert.IsFalse (app.Check (e), "Check (empty)");
57 e.AddHost (new Zone (SecurityZone.MyComputer));
58 Assert.IsFalse (app.Check (e), "Check (zone)");
60 // TODO - more (non failing ;) tests
63 [Test]
64 public void Copy ()
66 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
67 ApplicationMembershipCondition copy = (ApplicationMembershipCondition)app.Copy ();
68 Assert.AreEqual (app, copy, "Equals");
69 Assert.IsFalse (Object.ReferenceEquals (app, copy), "ReferenceEquals");
72 [Test]
73 public void Equals ()
75 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
76 Assert.IsFalse (app.Equals (null), "Equals(null)");
77 ApplicationMembershipCondition g2 = new ApplicationMembershipCondition ();
78 Assert.IsTrue (app.Equals (g2), "Equals(g2)");
79 Assert.IsTrue (g2.Equals (app), "Equals(app)");
80 Assert.IsFalse (app.Equals (new object ()), "Equals (object)");
83 [Test]
84 [ExpectedException (typeof (ArgumentNullException))]
85 public void FromXml_Null ()
87 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
88 app.FromXml (null);
91 [Test]
92 public void FromXml ()
94 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
95 SecurityElement se = app.ToXml ();
96 app.FromXml (se);
99 [Test]
100 [ExpectedException (typeof (ArgumentException))]
101 public void FromXml_InvalidTag ()
103 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
104 SecurityElement se = app.ToXml ();
105 se.Tag = "IMonoship";
106 app.FromXml (se);
109 [Test]
110 [ExpectedException (typeof (ArgumentException))]
111 public void FromXml_WrongTagCase ()
113 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
114 SecurityElement se = app.ToXml ();
115 se.Tag = "IMEMBERSHIPCONDITION"; // insteapp of IMembershipCondition
116 app.FromXml (se);
119 [Test]
120 public void FromXml_InvalidClass ()
122 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
123 SecurityElement se = app.ToXml ();
124 se.Attributes ["class"] = "Hello world";
125 app.FromXml (se);
128 [Test]
129 public void FromXml_NoClass ()
131 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
132 SecurityElement se = app.ToXml ();
134 SecurityElement w = new SecurityElement (se.Tag);
135 w.AddAttribute ("version", se.Attribute ("version"));
136 app.FromXml (w);
137 // doesn't even care of the class attribute presence
140 [Test]
141 public void FromXml_InvalidVersion ()
143 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
144 SecurityElement se = app.ToXml ();
146 SecurityElement w = new SecurityElement (se.Tag);
147 w.AddAttribute ("class", se.Attribute ("class"));
148 w.AddAttribute ("version", "2");
149 app.FromXml (w);
150 // doesn't seems to care about the version number!
153 [Test]
154 public void FromXml_NoVersion ()
156 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
157 SecurityElement se = app.ToXml ();
159 SecurityElement w = new SecurityElement (se.Tag);
160 w.AddAttribute ("class", se.Attribute ("class"));
161 app.FromXml (w);
164 [Test]
165 [ExpectedException (typeof (ArgumentNullException))]
166 public void FromXml_SecurityElementNull ()
168 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
169 app.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
172 [Test]
173 public void FromXml_NonBooleanLookAtDir ()
175 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
176 SecurityElement se = app.ToXml ();
178 SecurityElement w = new SecurityElement (se.Tag);
179 w.AddAttribute ("class", se.Attribute ("class"));
180 w.AddAttribute ("version", se.Attribute ("version"));
181 w.AddAttribute ("LookAtDir", "Maybe"); // not (generally) a boolean ;)
183 ApplicationMembershipCondition app2 = new ApplicationMembershipCondition ();
184 app2.FromXml (w);
186 se = app2.ToXml ();
187 Assert.IsNull (se.Attribute ("LookAtDir"), "LookAtDir");
188 // LookAtDir isn't part of the Equals computation
189 Assert.IsTrue (app2.Equals (app), "Equals-1");
190 Assert.IsTrue (app.Equals (app2), "Equals-2");
192 ApplicationMembershipCondition app3 = (ApplicationMembershipCondition)app2.Copy ();
193 se = app3.ToXml ();
194 // LookAtDir isn't copied either
195 Assert.AreEqual ("true", se.Attribute ("LookAtDir"), "Copy-LookAtDir");
198 [Test]
199 public void FromXml_PolicyLevelNull ()
201 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
202 SecurityElement se = app.ToXml ();
203 app.FromXml (se, null);
206 [Test]
207 public void GetHashCode_ ()
209 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
210 Assert.AreEqual (-1, app.GetHashCode ());
211 ApplicationMembershipCondition copy = (ApplicationMembershipCondition)app.Copy ();
212 Assert.AreEqual (app.GetHashCode (), copy.GetHashCode ());
215 [Test]
216 public void ToString_ ()
218 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
219 Assert.AreEqual ("Application", app.ToString ());
222 [Test]
223 public void ToXml ()
225 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
226 SecurityElement se = app.ToXml ();
227 Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
228 Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.ApplicationMembershipCondition"), "class");
229 Assert.AreEqual ("1", se.Attribute ("version"), "version");
230 Assert.AreEqual ("true", se.Attribute ("LookAtDir"), "LookAtDir");
231 Assert.AreEqual (se.ToString (), app.ToXml (null).ToString (), "ToXml(null)");
232 Assert.AreEqual (se.ToString (), app.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");