Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / class / System / Test / System / FileStyleUriParserTest.cs
1 //
2 // FileStyleUriParserTest.cs - Unit tests for System.FileStyleUriParser
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 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.
27 //
28
29 #if NET_2_0
30
31 using NUnit.Framework;
32
33 using System;
34 using System.IO;
35
36 namespace MonoTests.System {
37
38         public class UnitTestFileStyleUriParser: FileStyleUriParser {
39
40                 static bool registered;
41
42                 public static bool Registered {
43                         get { return registered; }
44                 }
45
46                 protected override string GetComponents (Uri uri, UriComponents components, UriFormat format)
47                 {
48                         throw new UriFormatException ();
49                         // return components.ToString ();
50                 }
51
52                 protected override void InitializeAndValidate (Uri uri, out UriFormatException parsingError)
53                 {
54                         throw new NotImplementedException ();
55                         // base.InitializeAndValidate (uri, out parsingError);
56                 }
57
58                 protected override bool IsBaseOf (Uri baseUri, Uri relativeUri)
59                 {
60                         throw new NotSupportedException ();
61                         // return base.IsBaseOf (baseUri, relativeUri);
62                 }
63
64                 protected override bool IsWellFormedOriginalString (Uri uri)
65                 {
66                         throw new FormatException ();
67                         // return base.IsWellFormedOriginalString (uri);
68                 }
69
70                 protected override UriParser OnNewUri ()
71                 {
72                         throw new OverflowException ();
73                         // return base.OnNewUri ();
74                 }
75
76                 protected override void OnRegister (string schemeName, int defaultPort)
77                 {
78                         registered = true;
79                         // try to mess up registration
80                         base.OnRegister (schemeName, 4040);
81                         base.OnRegister ("s" + schemeName, 4444);
82                 }
83
84                 protected override string Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parsingError)
85                 {
86                         throw new OutOfMemoryException ();
87                         // return base.Resolve (baseUri, relativeUri, out parsingError);
88                 }
89         }
90
91         [TestFixture]
92         public class FileStyleUriParserTest {
93
94                 private UnitTestFileStyleUriParser parser;
95
96                 [TestFixtureSetUp]
97                 public void FixtureSetUp ()
98                 {
99                         parser = new UnitTestFileStyleUriParser ();
100                         // unit tests are being reused in CAS tests
101                         if (!UriParser.IsKnownScheme ("filex"))
102                                 UriParser.Register (parser, "filex", 8080);
103
104                         Assert.IsTrue (UnitTestFileStyleUriParser.Registered, "Registered");
105                         // our parser code was called
106                 }
107
108                 [Test]
109                 public void Filex ()
110                 {
111                         Uri uri = new Uri ("filex:///readme.txt");
112                         Assert.AreEqual (8080, uri.Port, "Port");
113                         // OnRegister cannot be used to change the registering informations
114                 }
115
116                 [Test]
117                 [Category ("NotWorking")]
118                 public void Filex_Methods ()
119                 {
120                         Uri uri = new Uri ("filex:///readme.txt");
121                         Assert.AreEqual ("readme.txt", uri.GetComponents (UriComponents.Path, UriFormat.SafeUnescaped), "GetComponents");
122                         Assert.IsTrue (uri.IsBaseOf (uri), "IsBaseOf");
123                         Assert.IsTrue (uri.IsWellFormedOriginalString (), "IsWellFormedOriginalString");
124                         // ??? our parser doesn't seems to be called :(
125                 }
126
127                 [Test]
128                 public void SecureFilex ()
129                 {
130                         Uri uri = new Uri ("sfilex:///readme.txt");
131                         Assert.AreEqual (-1, uri.Port, "Port");
132                         // OnRegister cannot be used to change the registering informations
133                 }
134         }
135 }
136
137 #endif