2 // ApplicationMembershipConditionTest.cs -
3 // NUnit Test Cases for ApplicationMembershipCondition
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2004 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 #if NET_2_0 && !TARGET_JVM
32 using NUnit.Framework;
34 using System.Reflection;
35 using System.Security;
36 using System.Security.Policy;
38 namespace MonoTests.System.Security.Policy {
41 public class ApplicationMembershipConditionTest {
44 public void Constructor ()
46 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
47 Assert.IsNotNull (app);
53 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
55 Assert.IsFalse (app.Check (e), "Check (null)");
57 Assert.IsFalse (app.Check (e), "Check (empty)");
58 e.AddHost (new Zone (SecurityZone.MyComputer));
59 Assert.IsFalse (app.Check (e), "Check (zone)");
61 // TODO - more (non failing ;) tests
67 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
68 ApplicationMembershipCondition copy = (ApplicationMembershipCondition)app.Copy ();
69 Assert.AreEqual (app, copy, "Equals");
70 Assert.IsFalse (Object.ReferenceEquals (app, copy), "ReferenceEquals");
76 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
77 Assert.IsFalse (app.Equals (null), "Equals(null)");
78 ApplicationMembershipCondition g2 = new ApplicationMembershipCondition ();
79 Assert.IsTrue (app.Equals (g2), "Equals(g2)");
80 Assert.IsTrue (g2.Equals (app), "Equals(app)");
81 Assert.IsFalse (app.Equals (new object ()), "Equals (object)");
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void FromXml_Null ()
88 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
93 public void FromXml ()
95 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
96 SecurityElement se = app.ToXml ();
101 [ExpectedException (typeof (ArgumentException))]
102 public void FromXml_InvalidTag ()
104 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
105 SecurityElement se = app.ToXml ();
106 se.Tag = "IMonoship";
111 [ExpectedException (typeof (ArgumentException))]
112 public void FromXml_WrongTagCase ()
114 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
115 SecurityElement se = app.ToXml ();
116 se.Tag = "IMEMBERSHIPCONDITION"; // insteapp of IMembershipCondition
121 public void FromXml_InvalidClass ()
123 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
124 SecurityElement se = app.ToXml ();
125 se.Attributes ["class"] = "Hello world";
130 public void FromXml_NoClass ()
132 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
133 SecurityElement se = app.ToXml ();
135 SecurityElement w = new SecurityElement (se.Tag);
136 w.AddAttribute ("version", se.Attribute ("version"));
138 // doesn't even care of the class attribute presence
142 public void FromXml_InvalidVersion ()
144 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
145 SecurityElement se = app.ToXml ();
147 SecurityElement w = new SecurityElement (se.Tag);
148 w.AddAttribute ("class", se.Attribute ("class"));
149 w.AddAttribute ("version", "2");
151 // doesn't seems to care about the version number!
155 public void FromXml_NoVersion ()
157 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
158 SecurityElement se = app.ToXml ();
160 SecurityElement w = new SecurityElement (se.Tag);
161 w.AddAttribute ("class", se.Attribute ("class"));
166 [ExpectedException (typeof (ArgumentNullException))]
167 public void FromXml_SecurityElementNull ()
169 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
170 app.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
174 public void FromXml_NonBooleanLookAtDir ()
176 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
177 SecurityElement se = app.ToXml ();
179 SecurityElement w = new SecurityElement (se.Tag);
180 w.AddAttribute ("class", se.Attribute ("class"));
181 w.AddAttribute ("version", se.Attribute ("version"));
182 w.AddAttribute ("LookAtDir", "Maybe"); // not (generally) a boolean ;)
184 ApplicationMembershipCondition app2 = new ApplicationMembershipCondition ();
188 Assert.IsNull (se.Attribute ("LookAtDir"), "LookAtDir");
189 // LookAtDir isn't part of the Equals computation
190 Assert.IsTrue (app2.Equals (app), "Equals-1");
191 Assert.IsTrue (app.Equals (app2), "Equals-2");
193 ApplicationMembershipCondition app3 = (ApplicationMembershipCondition)app2.Copy ();
195 // LookAtDir isn't copied either
196 Assert.AreEqual ("true", se.Attribute ("LookAtDir"), "Copy-LookAtDir");
200 public void FromXml_PolicyLevelNull ()
202 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
203 SecurityElement se = app.ToXml ();
204 app.FromXml (se, null);
208 public void GetHashCode_ ()
210 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
211 Assert.AreEqual (-1, app.GetHashCode ());
212 ApplicationMembershipCondition copy = (ApplicationMembershipCondition)app.Copy ();
213 Assert.AreEqual (app.GetHashCode (), copy.GetHashCode ());
217 public void ToString_ ()
219 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
220 Assert.AreEqual ("Application", app.ToString ());
226 ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
227 SecurityElement se = app.ToXml ();
228 Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
229 Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.ApplicationMembershipCondition"), "class");
230 Assert.AreEqual ("1", se.Attribute ("version"), "version");
231 Assert.AreEqual ("true", se.Attribute ("LookAtDir"), "LookAtDir");
232 Assert.AreEqual (se.ToString (), app.ToXml (null).ToString (), "ToXml(null)");
233 Assert.AreEqual (se.ToString (), app.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");