diff options
author | Marcos Henrich <marcoshenrich@gmail.com> | 2015-09-09 15:50:07 +0300 |
---|---|---|
committer | Marcos Henrich <marcoshenrich@gmail.com> | 2015-09-09 15:50:07 +0300 |
commit | c7b0e92984a6344149d774cdafd156666404ceac (patch) | |
tree | cd02fbf4a6d092ee27561d04e32055525b69d0ca /mcs | |
parent | d935996d8851cff38ae1e4c64a8ff91271cdea89 (diff) | |
parent | 4d3b8b856b6b01cb87848a656fea0beea10d481b (diff) |
Merge pull request #2041 from esdrubal/uritestfix
Fixes DotNetRelativeOrAbsoluteTest.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System/Test/System/UriTest.cs | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/mcs/class/System/Test/System/UriTest.cs b/mcs/class/System/Test/System/UriTest.cs index 904ee9a94c9..a8cb6283403 100644 --- a/mcs/class/System/Test/System/UriTest.cs +++ b/mcs/class/System/Test/System/UriTest.cs @@ -1920,32 +1920,44 @@ namespace MonoTests.System [Test] public void DotNetRelativeOrAbsoluteTest () { - Uri uri; - - uri = new Uri ("/foo", DotNetRelativeOrAbsolute); - Assert.IsFalse (uri.IsAbsoluteUri); - - Uri.TryCreate("/foo", DotNetRelativeOrAbsolute, out uri); - Assert.IsFalse (uri.IsAbsoluteUri); + FieldInfo useDotNetRelativeOrAbsoluteField = null; + bool useDotNetRelativeOrAbsoluteOld = false; if (Type.GetType ("Mono.Runtime") != null) { - uri = new Uri ("/foo", UriKind.RelativeOrAbsolute); - Assert.IsTrue (uri.IsAbsoluteUri); + useDotNetRelativeOrAbsoluteField = typeof (Uri).GetField ("useDotNetRelativeOrAbsolute", + BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic); + useDotNetRelativeOrAbsoluteOld = (bool) useDotNetRelativeOrAbsoluteField.GetValue (null); + useDotNetRelativeOrAbsoluteField.SetValue (null, false); + } + + try { + Uri uri; - Uri.TryCreate("/foo", UriKind.RelativeOrAbsolute, out uri); - Assert.IsTrue (uri.IsAbsoluteUri); + uri = new Uri ("/foo", DotNetRelativeOrAbsolute); + Assert.IsFalse (uri.IsAbsoluteUri); + + Uri.TryCreate("/foo", DotNetRelativeOrAbsolute, out uri); + Assert.IsFalse (uri.IsAbsoluteUri); - var useDotNetRelativeOrAbsoluteField = typeof (Uri).GetField ("useDotNetRelativeOrAbsolute", - BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic); + if (useDotNetRelativeOrAbsoluteField != null) { + uri = new Uri ("/foo", UriKind.RelativeOrAbsolute); + Assert.IsTrue (uri.IsAbsoluteUri); - useDotNetRelativeOrAbsoluteField.SetValue (null, true); - } + Uri.TryCreate("/foo", UriKind.RelativeOrAbsolute, out uri); + Assert.IsTrue (uri.IsAbsoluteUri); - uri = new Uri ("/foo", UriKind.RelativeOrAbsolute); - Assert.IsFalse (uri.IsAbsoluteUri); + useDotNetRelativeOrAbsoluteField.SetValue (null, true); + } - Uri.TryCreate("/foo", DotNetRelativeOrAbsolute, out uri); - Assert.IsFalse (uri.IsAbsoluteUri); + uri = new Uri ("/foo", UriKind.RelativeOrAbsolute); + Assert.IsFalse (uri.IsAbsoluteUri); + + Uri.TryCreate("/foo", DotNetRelativeOrAbsolute, out uri); + Assert.IsFalse (uri.IsAbsoluteUri); + } finally { + if (useDotNetRelativeOrAbsoluteField != null) + useDotNetRelativeOrAbsoluteField.SetValue (null, useDotNetRelativeOrAbsoluteOld); + } } [Test] |