[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Security.Policy / ApplicationDirectoryTest.cs
blob9b734eb6e02e2d3287e3e1dfbabc93c6c7870446
1 //
2 // ApplicationDirectoryTest.cs - NUnit Test Cases for ApplicationDirectory
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
30 using System;
31 using System.IO;
32 using System.Security.Policy;
33 using System.Text;
35 namespace MonoTests.System.Security.Policy {
37 [TestFixture]
38 public class ApplicationDirectoryTest {
40 private string Invalid (bool exception)
42 StringBuilder sb = new StringBuilder ();
43 foreach (char c in Path.InvalidPathChars)
44 sb.Append (c);
45 if ((exception) && (sb.Length < 1))
46 throw new ArgumentException ("no invalid chars");
47 return sb.ToString ();
50 [Test]
51 [ExpectedException (typeof (ArgumentNullException))]
52 public void ApplicationDirectory_Null ()
54 new ApplicationDirectory (null);
57 [Test]
58 [ExpectedException (typeof (FormatException))]
59 public void ApplicationDirectory_Empty ()
61 new ApplicationDirectory (String.Empty);
64 [Test]
65 public void ApplicationDirectory_Invalid ()
67 new ApplicationDirectory (Invalid (false));
70 [Test]
71 public void ApplicationDirectory_String ()
73 ApplicationDirectory ad = new ApplicationDirectory ("mono");
74 Assert.AreEqual ("mono", ad.Directory, "Directory");
77 [Test]
78 public void ApplicationDirectory_FileUrl ()
80 ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
81 Assert.AreEqual ("file://MONO", ad.Directory, "Directory");
84 [Test]
85 public void ApplicationDirectory_HttpUrl ()
87 ApplicationDirectory ad = new ApplicationDirectory ("http://www.example.com/");
88 Assert.AreEqual ("http://www.example.com/", ad.Directory, "Directory");
91 [Test]
92 public void Copy ()
94 ApplicationDirectory ad = new ApplicationDirectory ("novell");
95 Assert.AreEqual ("novell", ad.Directory, "Directory");
96 ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
97 Assert.IsTrue (ad.Equals (copy), "ad.Equals(copy)");
98 Assert.IsTrue (copy.Equals (ad), "copy.Equals(ad)");
99 Assert.IsFalse (Object.ReferenceEquals (ad, copy), "Copy");
100 Assert.AreEqual (ad.GetHashCode (), copy.GetHashCode (), "GetHashCode");
101 Assert.AreEqual (ad.ToString (), copy.ToString (), "ToString");
104 [Test]
105 public void Equals ()
107 ApplicationDirectory ad1 = new ApplicationDirectory ("mono");
108 Assert.IsFalse (ad1.Equals (null), "Equals(null)");
109 Assert.IsFalse (ad1.Equals (String.Empty), "Equals(String.Empty)");
110 Assert.IsFalse (ad1.Equals ("mono"), "Equals(mono)");
111 Assert.IsTrue (ad1.Equals (ad1), "Equals(self)");
112 ApplicationDirectory ad2 = new ApplicationDirectory (ad1.Directory);
113 Assert.IsTrue (ad1.Equals (ad2), "Equals(ad2)");
114 Assert.IsTrue (ad2.Equals (ad1), "Equals(ad2)");
115 ApplicationDirectory ad3 = new ApplicationDirectory ("..");
116 Assert.IsFalse (ad2.Equals (ad3), "Equals(ad3)");
119 [Test]
120 public void GetHashCode_ ()
122 string linux = "/unix/path/mono";
123 ApplicationDirectory ad1 = new ApplicationDirectory (linux);
124 Assert.AreEqual (linux, ad1.Directory);
125 Assert.AreEqual (linux.GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");
127 string windows = "\\windows\\path\\mono";
128 ApplicationDirectory ad2 = new ApplicationDirectory (windows);
129 Assert.AreEqual (windows, ad2.Directory);
130 Assert.AreEqual (windows.GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
133 [Test]
134 public void ToString_ ()
136 ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
137 string ts = ad.ToString ();
138 Assert.IsTrue (ts.StartsWith ("<System.Security.Policy.ApplicationDirectory"), "Tag");
139 Assert.IsTrue (ts.IndexOf ("version=\"1\"") > 0, "Directory");
140 Assert.IsTrue (ts.IndexOf ("<Directory>file://MONO</Directory>") > 0, "Directory");
143 [Test]
144 [ExpectedException (typeof (ArgumentException))]
145 public void Equals_Invalid ()
147 // funny one
148 string appdir = Invalid (true);
149 // constructor is ok with an invalid path...
150 ApplicationDirectory ad = new ApplicationDirectory (appdir);
151 // we can copy it...
152 ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
153 // we can't get it's hash code
154 Assert.AreEqual (appdir.GetHashCode (), ad.GetHashCode (), "GetHashCode");
155 // we can convert it to string...
156 Assert.IsTrue (ad.ToString ().IndexOf (appdir) > 0, "ToString");
157 // ... but it throws in Equals - with self!
158 Assert.IsTrue (ad.Equals (ad), "Equals(self)");
161 [Test]
162 [ExpectedException (typeof (ArgumentException))]
163 public void ToString_Invalid ()
165 new ApplicationDirectory (Invalid (true)).ToString ();