**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.Security.Policy / UrlTest.cs
blobbe6c5ad4e066917cdff1d7bbbed73689576af83f
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 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.
30 using NUnit.Framework;
31 using System;
32 using System.Security;
33 using System.Security.Permissions;
34 using System.Security.Policy;
36 namespace MonoTests.System.Security.Policy {
38 [TestFixture]
39 public class UrlTest {
41 [Test]
42 [ExpectedException (typeof (ArgumentNullException))]
43 public void Url_Null ()
45 Url u = new Url (null);
48 [Test]
49 [ExpectedException (typeof (FormatException))]
50 public void Url_Empty ()
52 Url u = new Url (String.Empty);
55 [Test]
56 public void Url_NoProtocol ()
58 Url u = new Url ("index.html");
59 #if NET_2_0
60 Assert.AreEqual ("index.html", u.Value, "Value");
61 #else
62 Assert.AreEqual ("file://INDEX.HTML", u.Value, "Value");
63 #endif
66 [Test]
67 public void Url_WellKnownProtocol ()
69 Url u1 = new Url ("file://mono/index.html");
70 Url u2 = new Url ("ftp://www.go-mono.com");
71 Url u3 = new Url ("http://www.go-mono.com");
72 Url u4 = new Url ("https://www.go-mono.com");
73 #if NET_2_0
74 Assert.AreEqual ("file://mono/index.html", u1.Value, "file.Value");
75 Assert.AreEqual ("ftp://www.go-mono.com", u2.Value, "ftp.Value");
76 Assert.AreEqual ("http://www.go-mono.com", u3.Value, "http.Value");
77 Assert.AreEqual ("https://www.go-mono.com", u4.Value, "https.Value");
78 #else
79 Assert.AreEqual ("file://MONO/INDEX.HTML", u1.Value, "file.Value");
80 Assert.AreEqual ("ftp://www.go-mono.com/", u2.Value, "ftp.Value");
81 Assert.AreEqual ("http://www.go-mono.com/", u3.Value, "http.Value");
82 Assert.AreEqual ("https://www.go-mono.com/", u4.Value, "https.Value");
83 #endif
86 [Test]
87 public void Url_UnknownProtocol ()
89 string url = "mono://www.go-mono.com";
90 Url u = new Url (url);
91 // Fx 2.0 returns the original url, while 1.0/1.1 adds a '/' at it's end
92 Assert.IsTrue (u.Value.StartsWith (url), "mono.Value");
95 [Test]
96 public void Url_RelativePath ()
98 Url u = new Url ("http://www.go-mono.com/path/../newpath/index.html");
99 Assert.AreEqual ("http://www.go-mono.com/path/../newpath/index.html", u.Value, "Value");
102 [Test]
103 public void Url_GoMonoWebUrl ()
105 string url = "http://www.go-mono.com";
106 Url u = new Url (url);
108 Assert.IsTrue (u.Value.StartsWith (url), "Value");
109 #if NET_2_0
110 // no spaces in XML, no ending '/' on url
111 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");
112 #else
113 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");
114 #endif
115 Url u2 = (Url) u.Copy ();
116 Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
117 Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");
119 UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
120 Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
122 Assert.IsTrue (u.Equals (u2), "Equals");
123 Url u3 = new Url ("go-mono.com");
124 Assert.IsFalse (u.Equals (u3), "!Equals");
127 [Test]
128 #if !NET_2_0
129 [ExpectedException (typeof (ArgumentException))]
130 #endif
131 public void Url_InvalidSite ()
133 Url u = new Url ("http://www.go-mono.*");
134 #if NET_2_0
135 Assert.AreEqual ("http://www.go-mono.*", u.Value, "Value");
136 #endif
139 [Test]
140 public void EqualsCaseSensitive ()
142 Url u1 = new Url ("http://www.go-mono.com");
143 Url u2 = new Url ("http://www.Go-Mono.com");
144 Assert.IsTrue (u1.Equals (u2), "CaseSensitive");
147 [Test]
148 public void EqualsPartial ()
150 Url u1 = new Url ("http://www.go-mono.com/index.html");
151 Url u2 = new Url ("http://www.go-mono.com/*");
152 Assert.IsFalse (u1.Equals (u2), "Partial:1-2");
153 Assert.IsFalse (u2.Equals (u1), "Partial:2-1");
156 [Test]
157 public void EqualsNull ()
159 Url u = new Url ("http://www.go-mono.com");
160 Assert.IsFalse (u.Equals (null), "EqualsNull");
163 [Test]
164 public void Url_LoneStar ()
166 Url u = new Url ("*");
167 #if NET_2_0
168 Assert.AreEqual ("*", u.Value, "Value");
169 Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "<Url>*</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
170 #else
171 Assert.AreEqual ("file://*", u.Value, "Value");
172 Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + " <Url>file://*</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
173 #endif
174 Url u2 = (Url) u.Copy ();
175 Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
176 Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");
178 UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
179 Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
181 Assert.IsTrue (u.Equals (u2), "Equals");
182 Url u3 = new Url ("index.html");
183 Assert.IsFalse (u.Equals (u3), "!Equals(*)");
185 u2 = new Url ("file://*");
186 Assert.AreEqual ("file://*", u2.Value, "Value-file://*");
187 Assert.IsTrue (u.Equals (u2), "Equals-file://*");