[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / corlib / Test / System.Security.Policy / UrlTest.cs
1 //
2 // UrlTest.cs - NUnit Test Cases for Url
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Security;
33 using System.Security.Permissions;
34 using System.Security.Policy;
35
36 namespace MonoTests.System.Security.Policy {
37
38         [TestFixture]
39         public class UrlTest {
40
41                 [Test]
42                 [ExpectedException (typeof (ArgumentNullException))]
43                 public void Url_Null () 
44                 {
45                         Url u = new Url (null);
46                 }
47
48                 [Test]
49                 [ExpectedException (typeof (FormatException))]
50                 public void Url_Empty () 
51                 {
52                         Url u = new Url (String.Empty);
53                 }
54
55                 [Test]
56                 public void Url_NoProtocol () 
57                 {
58                         Url u = new Url ("index.html");
59                         Assert.AreEqual ("index.html", u.Value, "Value");
60                 }
61
62                 [Test]
63                 public void Url_WellKnownProtocol () 
64                 {
65                         Url u1 = new Url ("file://mono/index.html");
66                         Url u2 = new Url ("ftp://www.go-mono.com");
67                         Url u3 = new Url ("http://www.go-mono.com");
68                         Url u4 = new Url ("https://www.go-mono.com");
69                         Assert.AreEqual ("file://mono/index.html", u1.Value, "file.Value");
70                         Assert.AreEqual ("ftp://www.go-mono.com", u2.Value, "ftp.Value");
71                         Assert.AreEqual ("http://www.go-mono.com", u3.Value, "http.Value");
72                         Assert.AreEqual ("https://www.go-mono.com", u4.Value, "https.Value");
73                 }
74
75                 [Test]
76                 public void Url_UnknownProtocol () 
77                 {
78                         string url = "mono://www.go-mono.com";
79                         Url u = new Url (url);
80                         // Fx 2.0 returns the original url, while 1.0/1.1 adds a '/' at it's end
81                         Assert.IsTrue (u.Value.StartsWith (url), "mono.Value");
82                 }
83
84                 [Test]
85                 public void Url_RelativePath () 
86                 {
87                         Url u = new Url ("http://www.go-mono.com/path/../newpath/index.html");
88                         Assert.AreEqual ("http://www.go-mono.com/path/../newpath/index.html", u.Value, "Value");
89                 }
90
91                 [Test]
92                 public void Url_GoMonoWebUrl () 
93                 {
94                         string url = "http://www.go-mono.com";
95                         Url u = new Url (url);
96
97                         Assert.IsTrue (u.Value.StartsWith (url), "Value");
98                         // no spaces in XML, no ending '/' on url
99                         Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "<Url>http://www.go-mono.com</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
100                         Url u2 = (Url) u.Copy ();
101                         Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
102                         Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");
103
104                         UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
105                         Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
106
107                         Assert.IsTrue (u.Equals (u2), "Equals");
108                         Url u3 = new Url ("go-mono.com");
109                         Assert.IsFalse (u.Equals (u3), "!Equals");
110                 }
111
112                 [Test]
113                 public void Url_InvalidSite () 
114                 {
115                         Url u = new Url ("http://www.go-mono.*");
116                         Assert.AreEqual ("http://www.go-mono.*", u.Value, "Value");
117                 }
118
119                 [Test]
120                 public void EqualsCaseSensitive () 
121                 {
122                         Url u1 = new Url ("http://www.go-mono.com");
123                         Url u2 = new Url ("http://www.Go-Mono.com");
124                         Assert.IsTrue (u1.Equals (u2), "CaseSensitive");
125                 }
126
127                 [Test]
128                 public void EqualsPartial () 
129                 {
130                         Url u1 = new Url ("http://www.go-mono.com/index.html");
131                         Url u2 = new Url ("http://www.go-mono.com/*");
132                         Assert.IsFalse (u1.Equals (u2), "Partial:1-2");
133                         Assert.IsFalse (u2.Equals (u1), "Partial:2-1");
134                 }
135
136                 [Test]
137                 public void EqualsNull () 
138                 {
139                         Url u = new Url ("http://www.go-mono.com");
140                         Assert.IsFalse (u.Equals (null), "EqualsNull");
141                 }
142
143                 [Test]
144                 public void Url_LoneStar () 
145                 {
146                         Url u = new Url ("*");
147                         Assert.AreEqual ("*", u.Value, "Value");
148                         Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "<Url>*</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
149                         Url u2 = (Url) u.Copy ();
150                         Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
151                         Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");
152
153                         UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
154                         Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
155
156                         Assert.IsTrue (u.Equals (u2), "Equals");
157                         Url u3 = new Url ("index.html");
158                         Assert.IsFalse (u.Equals (u3), "!Equals(*)");
159
160                         u2 = new Url ("file://*");
161                         Assert.AreEqual ("file://*", u2.Value, "Value-file://*");
162                         Assert.IsTrue (u.Equals (u2), "Equals-file://*");
163                 }
164         }
165 }