2 // UrlTest.cs - NUnit Test Cases for Url
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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 using NUnit
.Framework
;
32 using System
.Security
;
33 using System
.Security
.Permissions
;
34 using System
.Security
.Policy
;
36 namespace MonoTests
.System
.Security
.Policy
{
39 public class UrlTest
{
42 [ExpectedException (typeof (ArgumentNullException
))]
43 public void Url_Null ()
45 Url u
= new Url (null);
49 [ExpectedException (typeof (FormatException
))]
50 public void Url_Empty ()
52 Url u
= new Url (String
.Empty
);
56 public void Url_NoProtocol ()
58 Url u
= new Url ("index.html");
60 Assert
.AreEqual ("index.html", u
.Value
, "Value");
62 Assert
.AreEqual ("file://INDEX.HTML", u
.Value
, "Value");
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");
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");
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");
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");
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");
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");
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");
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");
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");
129 [ExpectedException (typeof (ArgumentException
))]
131 public void Url_InvalidSite ()
133 Url u
= new Url ("http://www.go-mono.*");
135 Assert
.AreEqual ("http://www.go-mono.*", u
.Value
, "Value");
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");
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");
157 public void EqualsNull ()
159 Url u
= new Url ("http://www.go-mono.com");
160 Assert
.IsFalse (u
.Equals (null), "EqualsNull");
164 public void Url_LoneStar ()
166 Url u
= new Url ("*");
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");
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");
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://*");