3 using System.Reflection;
\r
5 using NUnit.Framework;
\r
7 namespace MonoTests.System
\r
10 public class UriTest2 : Assertion
\r
12 // Segments cannot be validated here...
\r
13 public void AssertUri (string relsrc, Uri uri,
\r
25 UriHostNameType hostNameType,
\r
26 string absolutePath,
\r
27 string pathAndQuery,
\r
32 AssertEquals (relsrc + " AbsoluteUri", absoluteUri, uri.AbsoluteUri);
\r
33 AssertEquals (relsrc + " Scheme", scheme, uri.Scheme);
\r
34 AssertEquals (relsrc + " Host", host, uri.Host);
\r
35 AssertEquals (relsrc + " Port", port, uri.Port);
\r
36 // Windows UNC path is not automatically testable on *nix environment,
\r
37 if (relsrc.StartsWith ("\\\\") && Path.DirectorySeparatorChar == '\\')
\r
38 AssertEquals (relsrc + " LocalPath", localPath, uri.LocalPath);
\r
39 AssertEquals (relsrc + " Query", query, uri.Query);
\r
40 AssertEquals (relsrc + " Fragment", fragment, uri.Fragment);
\r
41 AssertEquals (relsrc + " IsFile", isFile, uri.IsFile);
\r
42 AssertEquals (relsrc + " IsUnc", isUnc, uri.IsUnc);
\r
43 AssertEquals (relsrc + " IsLoopback", isLoopback, uri.IsLoopback);
\r
44 AssertEquals (relsrc + " Authority", authority, uri.Authority);
\r
45 AssertEquals (relsrc + " UserEscaped", userEscaped, uri.UserEscaped);
\r
46 AssertEquals (relsrc + " UserInfo", userInfo, uri.UserInfo);
\r
47 AssertEquals (relsrc + " HostNameType", hostNameType, uri.HostNameType);
\r
48 AssertEquals (relsrc + " AbsolutePath", absolutePath, uri.AbsolutePath);
\r
49 AssertEquals (relsrc + " PathAndQuery", pathAndQuery, uri.PathAndQuery);
\r
50 AssertEquals (relsrc + " ToString()", toString, uri.ToString ());
\r
54 public void AbsoluteUriFromFile ()
\r
56 FromResource ("test-uri-props.txt", null);
\r
60 [Category("NotDotNet")]
\r
61 public void AbsoluteUriFromFileManual ()
\r
63 FromResource ("test-uri-props-manual.txt", null);
\r
67 public void RelativeUriFromFile ()
\r
69 FromResource ("test-uri-relative-props.txt", new Uri ("http://www.go-mono.com"));
\r
72 private void FromResource (string res, Uri baseUri)
\r
74 Assembly a = Assembly.GetExecutingAssembly ();
75 Stream s = a.GetManifestResourceStream (res);
\r
76 StreamReader sr = new StreamReader (s, Encoding.UTF8);
\r
77 while (sr.Peek () > 0) {
\r
78 sr.ReadLine (); // skip
\r
79 string uriString = sr.ReadLine ();
\r
81 TextWriter sw = Console.Out;
\r
82 sw.WriteLine ("-------------------------");
\r
83 sw.WriteLine (uriString);
\r
85 if (uriString == null || uriString.Length == 0)
\r
89 Uri uri = baseUri == null ? new Uri (uriString) : new Uri (baseUri, uriString);
\r
91 sw.WriteLine ("ToString(): " + uri.ToString ());
\r
92 sw.WriteLine (uri.AbsoluteUri);
\r
93 sw.WriteLine (uri.Scheme);
\r
94 sw.WriteLine (uri.Host);
\r
95 sw.WriteLine (uri.LocalPath);
\r
96 sw.WriteLine (uri.Query);
\r
97 sw.WriteLine ("Port: " + uri.Port);
\r
98 sw.WriteLine (uri.IsFile);
\r
99 sw.WriteLine (uri.IsUnc);
\r
100 sw.WriteLine (uri.IsLoopback);
\r
101 sw.WriteLine (uri.UserEscaped);
\r
102 sw.WriteLine ("HostNameType: " + uri.HostNameType);
\r
103 sw.WriteLine (uri.AbsolutePath);
\r
104 sw.WriteLine ("PathAndQuery: " + uri.PathAndQuery);
\r
105 sw.WriteLine (uri.Authority);
\r
106 sw.WriteLine (uri.Fragment);
\r
107 sw.WriteLine (uri.UserInfo);
\r
109 AssertUri (uriString, uri,
\r
116 int.Parse (sr.ReadLine ()),
\r
117 bool.Parse (sr.ReadLine ()),
\r
118 bool.Parse (sr.ReadLine ()),
\r
119 bool.Parse (sr.ReadLine ()),
\r
120 bool.Parse (sr.ReadLine ()),
\r
121 (UriHostNameType) Enum.Parse (typeof (UriHostNameType), sr.ReadLine (), false),
\r
127 // Console.WriteLine ("Passed: " + uriString);
\r
128 } catch (UriFormatException ex) {
\r
129 Fail (String.Format ("Construction failed: [{0}] {1}", uriString, ex.Message));
\r
135 public void MoreUnescape () // bug 733316
138 char unesc = Uri.HexUnescape ("%F6", ref index);
139 AssertEquals ("#01", 3, index);
140 AssertEquals ("#02", 0xf6, unesc);