2005-03-31 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / Test / System.Security.Permissions / UrlIdentityPermissionTest.cs
index b6ce3e9b6bf8569bf9376fa41555900bd23a96d4..3b9cf6f9c002477643169717dffcf8d56d06daf0 100644 (file)
@@ -62,15 +62,17 @@ namespace MonoTests.System.Security.Permissions {
                {
                        UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
 #if NET_2_0
+                       // that cause a NullReferenceException before 2.0
                        Assert.AreEqual (String.Empty, uip.Url, "Url");
 #endif
                        SecurityElement se = uip.ToXml ();
                        // only class and version are present
                        Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
                        Assert.IsNull (se.Children, "Xml-Children");
-
+#if NET_2_0
                        UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy ();
                        Assert.IsFalse (Object.ReferenceEquals (uip, copy), "ReferenceEquals");
+#endif
                }
 
 #if !NET_2_0
@@ -83,13 +85,29 @@ namespace MonoTests.System.Security.Permissions {
                }
 #endif
 
+#if NET_2_0
+               [Test]
+               [Category ("NotWorking")]
+               public void PermissionStateUnrestricted ()
+               {
+                       // In 2.0 Unrestricted are permitted for identity permissions
+                       UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.Unrestricted);
+                       Assert.AreEqual (String.Empty, uip.Url, "Url");
+                       SecurityElement se = uip.ToXml ();
+                       // only class and version are present
+                       Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes");
+                       Assert.IsNull (se.Children, "Xml-Children");
+                       // and they aren't equals to None
+                       Assert.IsFalse (uip.Equals (new UrlIdentityPermission (PermissionState.None)));
+               }
+#else
                [Test]
                [ExpectedException (typeof (ArgumentException))]
                public void PermissionState_Unrestricted ()
                {
                        UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.Unrestricted);
                }
-
+#endif
                [Test]
                [ExpectedException (typeof (ArgumentException))]
                public void PermissionState_Bad ()
@@ -110,12 +128,23 @@ namespace MonoTests.System.Security.Permissions {
                        UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
                        foreach (string s in GoodUrls) {
                                uip.Url = s;
+#if NET_2_0
                                Assert.AreEqual (s, uip.Url, s);
+#else
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+#endif
                        }
                }
 
                [Test]
+#if NET_2_0
+               // this was working in beta1 but is broken in Nov CTP
+               [ExpectedException (typeof (NullReferenceException))]
+               [Category ("NotWorking")]
+#else
                [ExpectedException (typeof (ArgumentNullException))]
+#endif
                public void Url_Null ()
                {
                        UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
@@ -126,14 +155,25 @@ namespace MonoTests.System.Security.Permissions {
                public void Copy ()
                {
                        UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
-                       foreach (string s in GoodUrls)
-                       {
+                       foreach (string s in GoodUrls) {
                                uip.Url = s;
                                UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy ();
-                               Assert.AreEqual (s, copy.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.AreEqual (uip.Url, copy.Url, "Url");
                        }
                }
 
+               [Test]
+#if !NET_2_0
+               [ExpectedException (typeof (NullReferenceException))]
+#endif
+               public void Copy_None ()
+               {
+                       UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
+                       UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy ();
+               }
+
                [Test]
                public void Intersect_Null ()
                {
@@ -144,7 +184,9 @@ namespace MonoTests.System.Security.Permissions {
                                Assert.IsNull (uip.Intersect (null), s);
                        }
                }
-
+#if NET_2_0
+               [Category ("NotWorking")]
+#endif
                [Test]
                public void Intersect_None ()
                {
@@ -170,7 +212,9 @@ namespace MonoTests.System.Security.Permissions {
                        foreach (string s in GoodUrls) {
                                uip.Url = s;
                                UrlIdentityPermission result = (UrlIdentityPermission)uip.Intersect (uip);
-                               Assert.AreEqual (s, result.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.IsTrue (result.Url.StartsWith (uip.Url), s);
                        }
                }
 
@@ -194,6 +238,9 @@ namespace MonoTests.System.Security.Permissions {
                        }
                }
 
+#if NET_2_0
+               [Category ("NotWorking")]
+#endif
                [Test]
                public void IsSubset_None ()
                {
@@ -241,7 +288,9 @@ namespace MonoTests.System.Security.Permissions {
                        foreach (string s in GoodUrls) {
                                uip.Url = s;
                                UrlIdentityPermission union = (UrlIdentityPermission)uip.Union (null);
-                               Assert.AreEqual (s, union.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.IsTrue (union.Url.StartsWith (uip.Url), s);
                        }
                }
 
@@ -255,14 +304,18 @@ namespace MonoTests.System.Security.Permissions {
                        foreach (string s in GoodUrls) {
                                uip1.Url = s;
                                UrlIdentityPermission union = (UrlIdentityPermission)uip1.Union (uip2);
-                               Assert.AreEqual (s, union.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.IsTrue (union.Url.StartsWith (uip1.Url), s);
                        }
                        uip1 = new UrlIdentityPermission (PermissionState.None);
                        // b. destination (target) is none
                        foreach (string s in GoodUrls) {
                                uip2.Url = s;
                                UrlIdentityPermission union = (UrlIdentityPermission)uip2.Union (uip1);
-                               Assert.AreEqual (s, union.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.IsTrue (union.Url.StartsWith (uip2.Url), s);
                        }
                }
 
@@ -275,18 +328,32 @@ namespace MonoTests.System.Security.Permissions {
                        foreach (string s in GoodUrls) {
                                uip.Url = s;
                                union = (UrlIdentityPermission)uip.Union (uip);
-                               Assert.AreEqual (s, union.Url, s);
+                               // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
+                               // so we only compare the start of the url
+                               Assert.IsTrue (union.Url.StartsWith (uip.Url), s);
                        }
                }
-
+#if NET_2_0
+               [Category ("NotWorking")]
+#endif
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void Union_Different ()
                {
                        UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]);
                        UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]);
                        UrlIdentityPermission result = (UrlIdentityPermission)uip1.Union (uip2);
+#if NET_2_0
+                       Assert.IsNotNull (result, "Mono U Novell");
+                       // new XML format is used to contain more than one site
+                       SecurityElement se = result.ToXml ();
+                       Assert.AreEqual (2, se.Children.Count, "Childs");
+                       Assert.AreEqual (GoodUrls [0], (se.Children [0] as SecurityElement).Attribute ("Url"), "Url#1");
+                       Assert.AreEqual (GoodUrls [1], (se.Children [1] as SecurityElement).Attribute ("Url"), "Url#2");
+                       // strangely it is still versioned as 'version="1"'.
+                       Assert.AreEqual ("1", se.Attribute ("version"), "Version");
+#else
                        Assert.IsNull (result, "Mono U Novell");
+#endif
                }
 
                [Test]