Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save knocte/6062974 to your computer and use it in GitHub Desktop.
Save knocte/6062974 to your computer and use it in GitHub Desktop.
This should be fixed before adding IPAddress.MapToIPv4/6 new APIs to Mono (https://github.com/mono/mono/pull/641)
From 937a30e99c9e2641e96fc7efc8776d96a5a98115 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20G=2E=20Aragoneses?= <knocte@gmail.com>
Date: Tue, 23 Jul 2013 16:52:14 +0200
Subject: [PATCH] [System.Net.IPAddress] Fix tests to pass in MS.NET 4.0
profile
Apparently the 4.0 MS profile doesn't parse IP addresses with spaces
inside. The behaviour of parsing null is also different. Plus this
commit also includes some cases which don't pass on Mono yet (such
as "4294967296").
---
mcs/class/System/Test/System.Net/IPAddressTest.cs | 69 +++++++++++++++++++----
1 file changed, 57 insertions(+), 12 deletions(-)
diff --git a/mcs/class/System/Test/System.Net/IPAddressTest.cs b/mcs/class/System/Test/System.Net/IPAddressTest.cs
index 965b1cd..2c20129 100644
--- a/mcs/class/System/Test/System.Net/IPAddressTest.cs
+++ b/mcs/class/System/Test/System.Net/IPAddressTest.cs
@@ -4,10 +4,12 @@
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Martin Willemoes Hansen (mwh@sysrq.dk)
+// Andrés G. Aragoneses (knocte@gmail.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// (C) 2003 Martin Willemoes Hansen
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2013 Andrés G. Aragoneses
//
using NUnit.Framework;
@@ -72,24 +74,35 @@ public class IPAddressTest
"0xff.0x7f.0x20.0xf", "255.127.32.15",
"0.0.0.0", IPAddress.Any.ToString(),
"255.255.255.255", IPAddress.Broadcast.ToString(),
+ "12.1.7", "12.1.0.7",
+ "12", "0.0.0.12",
+ "65536", "0.1.0.0",
+ "65535", "0.0.255.255",
+ "20.65535", "20.0.255.255",
+ int.MaxValue.ToString (), "127.255.255.255",
+ (((double)int.MaxValue) + 1).ToString (), "128.0.0.0",
+ (((double)int.MaxValue) * 2).ToString (), "255.255.255.254",
+#if NET_4_0 // PLEASE keep this NET_4_0 block in sync with its counterpart in ipv4ParseWrong array
+ (((double)int.MaxValue) * 2 + 1).ToString (), "255.255.255.255",
+#else
+// IP addresses with spaces start here...
"12.1.1.3 abc", "12.1.1.3",
"12.1 .1.2", "12.0.0.1",
"12.1 .zzzz.2", "12.0.0.1",
- "12.1.7", "12.1.0.7",
- "12", "0.0.0.12",
"12.5.3 foo.67.test.test.7FFFFFFFFFfaFFF789FFFFFFFFFFFFFFF", "12.5.0.3",
"12.1 foo.bar.test.test.baf", "12.0.0.1",
"12.1.4.6 foo.bar.test.test.baf", "12.1.4.6",
"12.3 foo.bar.test.test.4", "12.0.0.3",
"12 foo.bar.test.test.baf", "0.0.0.12",
- "65536", "0.1.0.0",
- "65535", "0.0.255.255",
- "20.65535", "20.0.255.255",
- "0313.027035210", "203.92.58.136", // bug #411920
- "0313.0134.035210", "203.92.58.136", // too
- "7848198702", "211.202.2.46", // too
- "1434328179", "85.126.28.115", // too
- "3397943208", "202.136.127.168", // too
+// IP addresses with spaces end here
+// Testcases from bug411920 start here... // http://bugzilla.novell.com/show_bug.cgi?id=411920
+ "7848198702", "211.202.2.46",
+#endif
+ "0313.027035210", "203.92.58.136",
+ "0313.0134.035210", "203.92.58.136",
+ "1434328179", "85.126.28.115",
+ "3397943208", "202.136.127.168",
+// Testcases from bug411920 end here
};
static string [] ipv4ParseWrong = new string [] {
@@ -113,7 +126,22 @@ public class IPAddressTest
"12.",
"12.1.2.",
"12...",
- " "
+ " ",
+ (((double)int.MaxValue) * 2 + 2).ToString (), // 4,294,967,296
+
+#if NET_4_0
+ "12.1.1.3 abc",
+ "12.1 .1.2",
+ "12.1 .zzzz.2",
+ "12.5.3 foo.67.test.test.7FFFFFFFFFfaFFF789FFFFFFFFFFFFFFF",
+ "12.1 foo.bar.test.test.baf",
+ "12.1.4.6 foo.bar.test.test.baf",
+ "12.3 foo.bar.test.test.4",
+ "12 foo.bar.test.test.baf",
+ "7848198702",
+#else
+ (((double)int.MaxValue) * 2 + 1).ToString (), // 4,294,967,295 == "255.255.255.255",
+#endif
};
[Test]
@@ -464,15 +492,32 @@ public class IPAddressTest
{
IPAddress i;
+ bool? success = null;
+ bool exception = false;
+
try {
- IPAddress.TryParse ((string) null, out i);
+ success = IPAddress.TryParse((string) null, out i);
+#if !NET_4_0
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
+ exception = true;
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("ipString", ex.ParamName, "#5");
}
+ Assert.IsTrue (exception, "#6");
+ Assert.IsFalse (success.HasValue, "#7");
+#else
+ }
+ catch
+ {
+ exception = true;
+ }
+ Assert.IsFalse (exception, "#6");
+ Assert.IsTrue (success.HasValue, "#7");
+ Assert.IsFalse (success.Value, "#8");
+#endif
}
[Test]
--
1.8.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment