Merge pull request #3066 from alexanderkyte/pedump_sgen
[mono.git] / mcs / class / System / Test / System / UriTypeConverterTest.cs
index 26a81b617aad84902fafc85e08b6a2141df85b6d..c444a7916f00847acac9d30296b9ba7b9536608f 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using NUnit.Framework;
 
 using System;
+using System.IO;
 using System.ComponentModel;
 using System.ComponentModel.Design.Serialization;
 using System.Globalization;
@@ -76,11 +76,14 @@ namespace MonoTests.System {
                private UriTypeConverter converter;
                private UriTypeDescriptorContext context;
 
+               protected bool isWin32 = false;
+               
                [SetUp]
                public void SetUp ()
                {
                        converter = new UriTypeConverter ();
                        context = new UriTypeDescriptorContext ();
+                       isWin32 = (Path.DirectorySeparatorChar == '\\');
                }
 
                [Test]
@@ -95,8 +98,11 @@ namespace MonoTests.System {
                {
                        Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertFrom (typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertFrom (typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertFrom (typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertFrom (typeof (char)), "char");
@@ -115,8 +121,11 @@ namespace MonoTests.System {
                {
                        Assert.IsTrue (converter.CanConvertFrom (null, typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertFrom (null, typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertFrom (null, typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertFrom (null, typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertFrom (null, typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertFrom (null, typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertFrom (null, typeof (char)), "char");
@@ -128,8 +137,11 @@ namespace MonoTests.System {
                {
                        Assert.IsTrue (converter.CanConvertFrom (context, typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertFrom (context, typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertFrom (context, typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertFrom (context, typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertFrom (context, typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertFrom (context, typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertFrom (context, typeof (char)), "char");
@@ -143,8 +155,11 @@ namespace MonoTests.System {
 
                        Assert.IsTrue (converter.CanConvertTo (typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertTo (typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertTo (typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertTo (typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertTo (typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertTo (typeof (char)), "char");
@@ -158,8 +173,11 @@ namespace MonoTests.System {
 
                        Assert.IsTrue (converter.CanConvertTo (null, typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertTo (null, typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertTo (null, typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertTo (null, typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertTo (null, typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertTo (null, typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertTo (null, typeof (char)), "char");
@@ -171,8 +189,11 @@ namespace MonoTests.System {
                {
                        Assert.IsTrue (converter.CanConvertTo (context, typeof (string)), "string");
                        Assert.IsTrue (converter.CanConvertTo (context, typeof (Uri)), "Uri");
+#if MOBILE
+                       Assert.IsFalse (converter.CanConvertTo (context, typeof (InstanceDescriptor)), "InstanceDescriptor");
+#else
                        Assert.IsTrue (converter.CanConvertTo (context, typeof (InstanceDescriptor)), "InstanceDescriptor");
-
+#endif
                        Assert.IsFalse (converter.CanConvertTo (context, typeof (object)), "object");
                        Assert.IsFalse (converter.CanConvertTo (context, typeof (int)), "int");
                        Assert.IsFalse (converter.CanConvertTo (context, typeof (char)), "char");
@@ -188,10 +209,35 @@ namespace MonoTests.System {
                        o = converter.ConvertFrom (uri);
                        Assert.AreEqual (url, (o as Uri).AbsoluteUri, "uri");
 
+#if MOBILE
+                       o = converter.ConvertFrom ("");
+                       Assert.IsNull (o, "null");
+#else
                        o = converter.ConvertFrom (converter.ConvertTo (uri, typeof (InstanceDescriptor)));
                        Assert.AreEqual (url, (o as Uri).AbsoluteUri, "uri");
+
+                       o = converter.ConvertFrom ("");
+                       Assert.IsNotNull (o, "not null");
+#endif
                }
 
+               [Test]
+               public void ConvertFromString ()
+               {
+                       object o = converter.ConvertFrom ("~/SomeUri.txt");
+                       Assert.IsFalse ((o as Uri).IsAbsoluteUri, "CFS_01");
+                       Assert.AreEqual ("~/SomeUri.txt", (o as Uri).ToString (), "CFS_02");
+                       
+                       o = converter.ConvertFrom ("/SomeUri.txt");
+                       if (isWin32) {
+                               Assert.IsFalse ((o as Uri).IsAbsoluteUri, "CFS_03_WIN");
+                               Assert.AreEqual ("/SomeUri.txt", (o as Uri).ToString (), "CFS_04_WIN");
+                       } else {
+                               Assert.IsTrue ((o as Uri).IsAbsoluteUri, "CFS_03_UNIX");
+                               Assert.AreEqual ("file:///SomeUri.txt", (o as Uri).ToString (), "CFS_04_UNIX");
+                       }
+               }
+               
                [Test]
                [ExpectedException (typeof (NotSupportedException))]
                public void ConvertFrom_Bad ()
@@ -208,8 +254,10 @@ namespace MonoTests.System {
                        o = converter.ConvertFrom (context, CultureInfo.InvariantCulture, uri);
                        Assert.AreEqual (url, (o as Uri).AbsoluteUri, "uri");
 
+#if !MOBILE
                        o = converter.ConvertFrom (context, null, converter.ConvertTo (uri, typeof (InstanceDescriptor)));
                        Assert.AreEqual (url, (o as Uri).AbsoluteUri, "uri");
+#endif
                }
 
                [Test]
@@ -222,14 +270,28 @@ namespace MonoTests.System {
                [Test]
                public void ConvertTo ()
                {
-                       object o = converter.ConvertTo (url, typeof (string));
-                       Assert.AreEqual (url, (o as String), "string-string");
+                       object o;
+                       o = converter.ConvertTo (uri, typeof (Uri));
+                       Assert.AreEqual (uri, (o as Uri), "uri-uri");
 
                        o = converter.ConvertTo (uri, typeof (string));
                        Assert.AreEqual (url, (o as String), "uri-string");
 
-                       o = converter.ConvertTo (uri, typeof (Uri));
-                       Assert.AreEqual (uri, (o as Uri), "uri-uri");
+#if MOBILE
+                       try {
+                               converter.ConvertTo (url, typeof (string));
+                               Assert.Fail ("string-string");
+                       } catch (NotSupportedException) {
+                       }
+
+                       try {
+                               converter.ConvertTo (uri, typeof (InstanceDescriptor));
+                               Assert.Fail ("uri-InstanceDescriptor");
+                       } catch (NotSupportedException) {
+                       }
+#else
+                       o = converter.ConvertTo (url, typeof (string));
+                       Assert.AreEqual (url, (o as String), "string-string");
 
                        o = converter.ConvertTo (uri, typeof (InstanceDescriptor));
                        Assert.IsTrue (o is InstanceDescriptor, "uri-InstanceDescriptor");
@@ -238,7 +300,7 @@ namespace MonoTests.System {
 
                        o = converter.ConvertTo (descriptor, typeof (string));
                        Assert.AreEqual ("System.ComponentModel.Design.Serialization.InstanceDescriptor", (o as string), "InstanceDescriptor-string");
-
+#endif
                        // InstanceDescriptor to Uri or to InstanceDescriptor aren't supported either
                }
 
@@ -259,17 +321,24 @@ namespace MonoTests.System {
                [Test]
                public void ConvertTo_Bad ()
                {
+#if MOBILE
+                       try {
+                               converter.ConvertTo (new object (), typeof (string));
+                               Assert.Fail ("object");
+                       } catch (NotSupportedException) {
+                       }
+#else
                        Assert.AreEqual ("System.Object", converter.ConvertTo (new object (), typeof (string)), "object");
                        Assert.AreEqual ("4", converter.ConvertTo (4, typeof (string)), "int");
                        Assert.AreEqual ("c", converter.ConvertTo ('c', typeof (string)), "char");
                        Assert.AreEqual (String.Empty, converter.ConvertTo (null, typeof (string)), "null");
+#endif
                }
 
                [Test]
                public void ConvertTo_TypeDescriptorContext ()
                {
-                       object o = converter.ConvertTo (context, CultureInfo.InvariantCulture, url, typeof (string));
-                       Assert.AreEqual (url, (o as String), "string-string");
+                       object o;
 
                        o = converter.ConvertTo (context, null, uri, typeof (string));
                        Assert.AreEqual (url, (o as String), "uri-string");
@@ -277,6 +346,16 @@ namespace MonoTests.System {
                        o = converter.ConvertTo (context, CultureInfo.InvariantCulture, uri, typeof (Uri));
                        Assert.AreEqual (uri, (o as Uri), "uri-uri");
 
+#if MOBILE
+                       try {
+                               o = converter.ConvertTo (context, CultureInfo.InvariantCulture, url, typeof (string));
+                               Assert.AreEqual (url, (o as String), "string-string");
+                       } catch (NotSupportedException) {
+                       }
+#else
+                       o = converter.ConvertTo (context, CultureInfo.InvariantCulture, url, typeof (string));
+                       Assert.AreEqual (url, (o as String), "string-string");
+
                        o = converter.ConvertTo (context, CultureInfo.CurrentCulture, uri, typeof (InstanceDescriptor));
                        Assert.IsTrue (o is InstanceDescriptor, "uri-InstanceDescriptor");
 
@@ -284,7 +363,7 @@ namespace MonoTests.System {
 
                        o = converter.ConvertTo (context, CultureInfo.InvariantCulture, descriptor, typeof (string));
                        Assert.AreEqual ("System.ComponentModel.Design.Serialization.InstanceDescriptor", (o as string), "InstanceDescriptor-string");
-
+#endif
                        // InstanceDescriptor to Uri or to InstanceDescriptor aren't supported either
                }
 
@@ -305,10 +384,18 @@ namespace MonoTests.System {
                [Test]
                public void ConvertTo_TypeDescriptorContext_Bad ()
                {
+#if MOBILE
+                       try {
+                               converter.ConvertTo (context, null, new object (), typeof (string));
+                               Assert.Fail ("object");
+                       } catch (NotSupportedException) {
+                       }
+#else
                        Assert.AreEqual ("System.Object", converter.ConvertTo (context, null, new object (), typeof (string)), "object");
                        Assert.AreEqual ("4", converter.ConvertTo (context, CultureInfo.CurrentCulture, 4, typeof (string)), "int");
                        Assert.AreEqual ("c", converter.ConvertTo (context, CultureInfo.InvariantCulture, 'c', typeof (string)), "char");
                        Assert.AreEqual (String.Empty, converter.ConvertTo (null, null, null, typeof (string)), "null");
+#endif
                }
 
                [Test]
@@ -333,4 +420,3 @@ namespace MonoTests.System {
        }
 }
 
-#endif