[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Security.Policy / UrlTest.cs
blob5dab88ac51cce8cfd68c21a7019bfe8b0af119cf
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.
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 Assert.AreEqual ("index.html", u.Value, "Value");
62 [Test]
63 public void Url_WellKnownProtocol ()
65 Url u1 = new Url ("file://mono/index.html");
66 Url u2 = new Url ("ftp://www.example.com");
67 Url u3 = new Url ("http://www.example.com");
68 Url u4 = new Url ("https://www.example.com");
69 Assert.AreEqual ("file://mono/index.html", u1.Value, "file.Value");
70 Assert.AreEqual ("ftp://www.example.com", u2.Value, "ftp.Value");
71 Assert.AreEqual ("http://www.example.com", u3.Value, "http.Value");
72 Assert.AreEqual ("https://www.example.com", u4.Value, "https.Value");
75 [Test]
76 public void Url_UnknownProtocol ()
78 string url = "mono://www.example.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");
84 [Test]
85 public void Url_RelativePath ()
87 Url u = new Url ("http://www.example.com/path/../newpath/index.html");
88 Assert.AreEqual ("http://www.example.com/path/../newpath/index.html", u.Value, "Value");
91 [Test]
92 public void Url_GoMonoWebUrl ()
94 string url = "http://www.example.com";
95 Url u = new Url (url);
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.example.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");
104 UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
105 Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
107 Assert.IsTrue (u.Equals (u2), "Equals");
108 Url u3 = new Url ("example.com");
109 Assert.IsFalse (u.Equals (u3), "!Equals");
112 [Test]
113 public void Url_InvalidSite ()
115 Url u = new Url ("http://www.go-mono.*");
116 Assert.AreEqual ("http://www.go-mono.*", u.Value, "Value");
119 [Test]
120 public void EqualsCaseSensitive ()
122 Url u1 = new Url ("http://www.example.com");
123 Url u2 = new Url ("http://www.Example.com");
124 Assert.IsTrue (u1.Equals (u2), "CaseSensitive");
127 [Test]
128 public void EqualsPartial ()
130 Url u1 = new Url ("http://www.example.com/index.html");
131 Url u2 = new Url ("http://www.example.com/*");
132 Assert.IsFalse (u1.Equals (u2), "Partial:1-2");
133 Assert.IsFalse (u2.Equals (u1), "Partial:2-1");
136 [Test]
137 public void EqualsNull ()
139 Url u = new Url ("http://www.example.com");
140 Assert.IsFalse (u.Equals (null), "EqualsNull");
143 [Test]
144 public void Url_LoneStar ()
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");
153 UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
154 Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");
156 Assert.IsTrue (u.Equals (u2), "Equals");
157 Url u3 = new Url ("index.html");
158 Assert.IsFalse (u.Equals (u3), "!Equals(*)");
160 u2 = new Url ("file://*");
161 Assert.AreEqual ("file://*", u2.Value, "Value-file://*");
162 Assert.IsTrue (u.Equals (u2), "Equals-file://*");