"::111:234:5:6:789a:0", "0:0:111:234:5:6:789A:0",
"11:22:33:44:55:66:77:8", "11:22:33:44:55:66:77:8",
"0:0:7711:ab42:1230::", "::7711:ab42:1230:0:0:0",
+ "fec0:0:0:ffff::1%1",
};
static string[] ipv4ParseOk = new string[] {
"0xff.0x7f.0x20.0xf", "255.127.32.15",
"0.0.0.0", IPAddress.Any.ToString(),
"255.255.255.255", IPAddress.Broadcast.ToString(),
+#if ONLY_1_1
"12.1.1.3 ", "12.1.1.3",
+ "12.1 foo.1.2.3.4.5.bar", "12.0.0.1",
+ "12.1.4.6 foo.bar.test.test.bag", "12.1.4.6",
+ "12.6 foo.1.2.3.4.5.", "12.0.0.6",
+ "12.1.1.3 g", "12.1.1.3",
+ " ", "0.0.0.0",
+ "", "0.0.0.0",
+#endif
+ "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.1 foo.1.2.3.4.5.bar", "12.0.0.1",
- " ", "0.0.0.0"
+ "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
};
- static object[] ipv4ParseWrong = new object[] {
- " foo", typeof(FormatException),
- "12.. .", typeof(FormatException),
- "12.1.2. ", typeof(FormatException),
- "12.1.8. ", typeof(FormatException),
- ".1.1.6", typeof(FormatException),
- " 12.1.1.1", typeof(FormatException),
- "12.+1.1.4", typeof(FormatException),
- "12.1.-1.5", typeof(FormatException),
- "257.1.1.9", typeof(FormatException),
- "12.", typeof(FormatException),
- "12.1.2.", typeof(FormatException),
- "12...", typeof(FormatException),
- null, typeof(ArgumentNullException),
+ static string [] ipv4ParseWrong = new string [] {
+ " foo",
+ "12.. .",
+ "12.1.2. ",
+ "12.1.8. ",
+ ".1.1.6",
+ " 12.1.1.1",
+ "12.+1.1.4",
+ "12.1.-1.5",
+ "257.1.1.9",
+ "255.1.1.256",
+#if NET_2_0
+ "12.1.1.3 ",
+ "12.1 foo.1.2.3.4.5.bar",
+ "12.1 foo.1.2.3.4.5.",
+ "12.1.1.3 g",
+ " ",
+ "",
+#endif
+ "12.1.foo.1.2.3.4.5.bar",
+ "12.",
+ "12.1.2.",
+ "12...",
+ " "
};
[Test]
public void PublicFields ()
{
- Assertion.AssertEquals ("Any", IPAddress.Any.Address, (long) 0);
- Assertion.AssertEquals ("Broadcast", IPAddress.Broadcast.Address, (long) 0xFFFFFFFF);
+ Assert.AreEqual ((long) 0, IPAddress.Any.Address, "#1");
+ Assert.AreEqual ((long) 0xFFFFFFFF, IPAddress.Broadcast.Address, "#2");
long loopback = IPAddress.HostToNetworkOrder (BitConverter.IsLittleEndian ?
0x7f000001 :
0x0100007f);
- Assertion.AssertEquals ("Loopback", IPAddress.Loopback.Address, loopback);
- Assertion.AssertEquals ("None", IPAddress.None.Address, (long) 0xFFFFFFFF);
+ Assert.AreEqual (loopback, IPAddress.Loopback.Address, "#3");
+ Assert.AreEqual ((long) 0xFFFFFFFF, IPAddress.None.Address, "#4");
}
[Test]
public void ToStringV4 ()
{
IPAddress ip = IPAddress.Parse ("192.168.1.1");
- Assertion.AssertEquals ("ToString #1", "192.168.1.1", ip.ToString ());
- Assertion.AssertEquals ("ToString #2", "0.0.0.0", IPAddress.Any.ToString ());
- Assertion.AssertEquals ("ToString #3", "255.255.255.255", IPAddress.Broadcast.ToString ());
- Assertion.AssertEquals ("ToString #4", "127.0.0.1", IPAddress.Loopback.ToString ());
- Assertion.AssertEquals ("ToString #5", "255.255.255.255", IPAddress.None.ToString ());
+ Assert.AreEqual ("192.168.1.1", ip.ToString (), "#1");
+ Assert.AreEqual ("0.0.0.0", IPAddress.Any.ToString (), "#2");
+ Assert.AreEqual ("255.255.255.255", IPAddress.Broadcast.ToString (), "#3");
+ Assert.AreEqual ("127.0.0.1", IPAddress.Loopback.ToString (), "#4");
+ Assert.AreEqual ("255.255.255.255", IPAddress.None.ToString (), "#5");
}
-#if NET_1_1
[Test]
public void ToStringV6 ()
{
- if (Socket.SupportsIPv6) {
- for(int i=0; i<ipv6AddressList.Length/2; i++) {
- string addr = IPAddress.Parse (ipv6AddressList[i*2+1]).ToString().ToLower();
- Assertion.AssertEquals ("ToStringIPv6 #" + i, ipv6AddressList[i*2].ToLower(), addr);
- }
- } else
+ if (!Socket.SupportsIPv6)
Assert.Ignore ("IPv6 must be enabled in machine.config");
+
+ for(int i=0; i<ipv6AddressList.Length/2; i++) {
+ string addr = IPAddress.Parse (ipv6AddressList[i*2+1]).ToString().ToLower();
+ Assert.AreEqual (ipv6AddressList[i*2].ToLower(), addr, "ToStringIPv6 #" + i);
+ }
}
-#endif
[Test]
public void IsLoopbackV4 ()
{
- IPAddress ip = IPAddress.Parse ("127.0.0.1");
- Assertion.AssertEquals ("IsLoopback #1", true, IPAddress.IsLoopback (ip));
-
- try {
- ip = IPAddress.Parse ("::101");
- Assertion.Fail ("#2 should have thrown a FormatException");
- } catch {
- }
+ IPAddress ip;
+ ip = IPAddress.Parse ("127.0.0.1");
+ Assert.IsTrue (IPAddress.IsLoopback (ip), "#1");
ip = IPAddress.Any;
- Assertion.AssertEquals ("IsLoopback #5", false, IPAddress.IsLoopback (ip));
-
+ Assert.IsFalse (IPAddress.IsLoopback (ip), "#2");
ip = IPAddress.Loopback;
- Assertion.AssertEquals ("IsLoopback #6", true, IPAddress.IsLoopback (ip));
+ Assert.IsTrue (IPAddress.IsLoopback (ip), "#3");
+ ip = IPAddress.Parse ("::101");
+ Assert.IsFalse (IPAddress.IsLoopback (ip), "#4");
}
-#if NET_1_1
[Test]
public void IsLoopbackV6 ()
{
- if (Socket.SupportsIPv6) {
- IPAddress ip = IPAddress.IPv6Loopback;
- Assertion.AssertEquals ("IsLoopback #3", true, IPAddress.IsLoopback (ip));
-
- ip = IPAddress.IPv6None;
- Assertion.AssertEquals ("IsLoopback #7", false, IPAddress.IsLoopback (ip));
- } else
+ if (!Socket.SupportsIPv6)
Assert.Ignore ("IPv6 must be enabled in machine.config");
+
+ IPAddress ip = IPAddress.IPv6Loopback;
+ Assert.IsTrue (IPAddress.IsLoopback (ip), "#1");
+
+ ip = IPAddress.IPv6None;
+ Assert.IsFalse (IPAddress.IsLoopback (ip), "#2");
}
[Test]
{
byte[] dataIn = { 10, 11, 12, 13 };
byte[] dataOut = IPAddress.Parse ("10.11.12.13").GetAddressBytes ();
- for(int i=0; i<dataIn.Length; i++)
- Assertion.AssertEquals ("GetAddressBytes #1", dataIn[i], dataOut[i]);
+ for (int i = 0; i < dataIn.Length; i++)
+ Assert.AreEqual (dataOut [i], dataIn [i], "GetAddressBytesV4");
}
[Test]
public void GetAddressBytesV6 ()
{
- if (!Socket.SupportsIPv6) {
+ if (!Socket.SupportsIPv6)
Assert.Ignore ("IPv6 must be enabled in machine.config");
- return;
- }
byte[] dataIn = new byte[]{ 0x01, 0x23, 0x45, 0x67, 0x89, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0x98 };
byte[] dataOut = IPAddress.Parse ("123:4567:8998:7654:3210:0123:4567:8998").GetAddressBytes ();
- for(int i=0; i<dataIn.Length; i++)
- Assertion.AssertEquals ("GetAddressBytes #2", dataIn[i], dataOut[i]);
+ for (int i = 0; i < dataIn.Length; i++)
+ Assert.AreEqual (dataOut [i], dataIn [i], "GetAddressBytesV6 #1");
dataIn = new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x01 };
dataOut = IPAddress.Parse ("::FFFF:127.0.0.1").GetAddressBytes ();
- for(int i=0; i<dataIn.Length; i++)
- Assertion.AssertEquals ("GetAddressBytes #3", dataIn[i], dataOut[i]);
+ for (int i = 0; i < dataIn.Length; i++)
+ Assert.AreEqual (dataOut [i], dataIn [i], "GetAddressBytesV6 #2");
}
-#endif
[Test]
public void Address ()
}
[Test]
- [Category ("NotDotNet")] // #5 fails
public void ParseOkV4 ()
{
- for(int i=0; i<ipv4ParseOk.Length / 2; i++) {
+ for (int i = 0; i < ipv4ParseOk.Length / 2; i++) {
IPAddress ip;
- try
- {
+ try {
ip = IPAddress.Parse (ipv4ParseOk [i*2]);
- Assertion.Assert ("ParseIPv4 #" + i, ip.ToString () == ipv4ParseOk [i*2+1]);
- }
- catch
- {
- Assertion.Fail ("Cannot parse test i=" + i + ": '" + ipv4ParseOk [i*2] + "'");
+ Assert.AreEqual (ipv4ParseOk [i * 2 + 1], ip.ToString (), "ParseOkV4:" + i);
+ } catch (FormatException) {
+ Assert.Fail ("Cannot parse test i=" + i + ": '" + ipv4ParseOk [i*2] + "'");
}
}
}
-#if NET_1_1
[Test]
public void ParseOkV6 ()
{
- if (!Socket.SupportsIPv6) {
+ if (!Socket.SupportsIPv6)
Assert.Ignore ("IPv6 must be enabled in machine.config");
- return;
- }
- for(int i=0; i<ipv6AddressList.Length / 2; i++) {
+ for (int i = 0; i < ipv6AddressList.Length / 2; i++) {
string source = ipv6AddressList [i*2].ToLower();
IPAddress ip = IPAddress.Parse (source);
- Assertion.Assert (string.Format("ParseIPv6 #{0}-1: {1} != {2}", i,
- ip.ToString ().ToLower (), source), ip.ToString ().ToLower () == source);
+ Assert.IsTrue (ip.ToString ().ToLower () == source,
+ string.Format("ParseIPv6 #{0}-1: {1} != {2}", i,
+ ip.ToString ().ToLower (), source));
ip = IPAddress.Parse (ipv6AddressList [i*2+1].ToLower ());
- Assertion.Assert (string.Format("ParseIPv6 #{0}-2: {1} != {2}", i,
- ip.ToString ().ToLower (), source), ip.ToString ().ToLower () == source);
+ Assert.IsTrue (ip.ToString ().ToLower () == source,
+ string.Format("ParseIPv6 #{0}-2: {1} != {2}", i,
+ ip.ToString ().ToLower (), source));
}
}
-#endif
[Test]
- public void ParseWrong ()
+ public void ParseWrongV4 ()
{
- for(int i=0; i<ipv4ParseWrong.Length/2; i++) {
- Type exception = ipv4ParseWrong[i*2+1] as Type;
- string ipAddress = ipv4ParseWrong[i*2] as string;
+ for (int i = 0; i < ipv4ParseWrong.Length; i++) {
+ string ipAddress = ipv4ParseWrong [i];
try {
IPAddress ip = IPAddress.Parse (ipAddress);
- Assertion.Fail ("IPv4: Should raise a " + exception + " #" + i);
- }
- catch (Exception e) {
- if(!e.GetType ().Equals (exception))
- Assertion.Fail ("ParseWrongIPv4 #" + i + ": " + e.ToString());
+ Assert.Fail ("#1:" + i + " (" + ipAddress + ")");
+ } catch (FormatException ex) {
+ Assert.AreEqual (typeof (FormatException), ex.GetType (), "#2:" + i);
+ Assert.IsNull (ex.InnerException, "#3:" + i);
+ Assert.IsNotNull (ex.Message, "#4:" + i);
}
}
}
+ [Test]
+ public void Parse_IpString_Null ()
+ {
+ try {
+ IPAddress.Parse ((string) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("ipString", ex.ParamName, "#5");
+ }
+ }
+
[Test]
public void NetworkHost ()
{
expected = BitConverter.IsLittleEndian ? expectedLE : tested;
short short0 = IPAddress.NetworkToHostOrder ((short) tested [0]);
- Assertion.AssertEquals ("NetworkToHostOrder #1", short0, (short) expected [0]);
+ Assert.AreEqual ((short) expected [0], short0, "#A1");
short0 = IPAddress.HostToNetworkOrder (short0);
- Assertion.AssertEquals ("HostToNetworkOrder #1", short0, (short) tested [0]);
+ Assert.AreEqual ((short) tested [0], short0, "#A2");
int int0 = IPAddress.NetworkToHostOrder ((int) tested [0]);
- Assertion.AssertEquals ("NetworkToHostOrder #2", int0, (int) expected [0]);
+ Assert.AreEqual ((int) expected [0], int0, "#B1");
int0 = IPAddress.HostToNetworkOrder (int0);
- Assertion.AssertEquals ("HostToNetworkOrder #2", int0, (int) tested [0]);
+ Assert.AreEqual ((int) tested [0], int0, "#B2");
long long0 = IPAddress.NetworkToHostOrder (tested [0]);
- Assertion.AssertEquals ("NetworkToHostOrder #3", long0, expected [0]);
+ Assert.AreEqual (expected [0], long0, "#C1");
long0 = IPAddress.HostToNetworkOrder (long0);
- Assertion.AssertEquals ("HostToNetworkOrder #3", long0, tested [0]);
+ Assert.AreEqual (tested [0], long0, "#C2");
short0 = IPAddress.NetworkToHostOrder ((short) tested [1]);
- Assertion.AssertEquals ("NetworkToHostOrder #4", short0, (short) expected [1]);
+ Assert.AreEqual ((short) expected [1], short0, "#D1");
short0 = IPAddress.HostToNetworkOrder (short0);
- Assertion.AssertEquals ("HostToNetworkOrder #4", short0, (short) tested [1]);
+ Assert.AreEqual ((short) tested [1], short0, "#D2");
int0 = IPAddress.NetworkToHostOrder ((int) tested [2]);
- Assertion.AssertEquals ("NetworkToHostOrder #5", int0, (int) expected [2]);
+ Assert.AreEqual ((int) expected [2], int0, "#E1");
int0 = IPAddress.HostToNetworkOrder (int0);
- Assertion.AssertEquals ("HostToNetworkOrder #5", int0, (int) tested [2]);
+ Assert.AreEqual ((int) tested [2], int0, "#E2");
long0 = IPAddress.NetworkToHostOrder (tested [3]);
- Assertion.AssertEquals ("NetworkToHostOrder #6", long0, expected [3]);
+ Assert.AreEqual (expected [3], long0, "#F1");
long0 = IPAddress.HostToNetworkOrder (long0);
- Assertion.AssertEquals ("HostToNetworkOrder #6", long0, tested [3]);
+ Assert.AreEqual (tested [3], long0, "#F2");
}
[Test]
public void LoopbackIPv6 ()
{
- Assertion.AssertEquals ("#01", true, new Uri("http://[0:0:0:0::127.0.0.1]/").IsLoopback);
- Assertion.AssertEquals ("#02", false, new Uri("http://[0:0:0:0::127.1.2.3]/").IsLoopback);
- Assertion.AssertEquals ("#03", true, new Uri("http://[0:0:0:0::0.0.0.1]/").IsLoopback);
+ Assert.IsTrue (new Uri("http://[0:0:0:0::127.0.0.1]/").IsLoopback, "#1");
+ Assert.IsFalse (new Uri ("http://[0:0:0:0::127.1.2.3]/").IsLoopback, "#2");
+ Assert.IsTrue (new Uri ("http://[0:0:0:0::0.0.0.1]/").IsLoopback, "#3");
+ }
+
+ [Test] // bug #76792
+ public void Constructor0_Address_4Byte ()
+ {
+ byte[] bytes = new byte[4] { 192, 202, 112, 37 };
+ IPAddress i = new IPAddress (bytes);
+ Assert.AreEqual (bytes, i.GetAddressBytes (), "#1");
+ Assert.AreEqual ("192.202.112.37", i.ToString (), "#2");
}
-#if NET_2_0
[Test]
- public void FromBytes3 ()
+#if TARGET_JVM
+ [Ignore ("TD BUG ID: 7213")]
+#endif
+ public void Constructor0_Address_Invalid ()
{
- // This one works in 2.0
- new IPAddress (new byte [4]);
+ try {
+ new IPAddress (new byte [0]);
+ Assert.Fail ("#A1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ Assert.IsFalse (ex.Message == "address", ex.Message, "#A5");
+ Assert.IsNotNull (ex.ParamName, "#A6");
+ Assert.AreEqual ("address", ex.ParamName, "#A7");
+ }
+
+ try {
+ new IPAddress (new byte [3] { 192, 202, 112 });
+ Assert.Fail ("#B1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ Assert.IsFalse (ex.Message == "address", ex.Message, "#B5");
+ Assert.IsNotNull (ex.ParamName, "#B6");
+ Assert.AreEqual ("address", ex.ParamName, "#B7");
+ }
+
+ try {
+ new IPAddress (new byte [5] { 192, 202, 112, 142, 25 });
+ Assert.Fail ("#C1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+ Assert.IsNull (ex.InnerException, "#C3");
+ Assert.IsNotNull (ex.Message, "#C4");
+ Assert.IsFalse (ex.Message == "address", "#C5");
+ Assert.IsNotNull (ex.ParamName, "#C6");
+ Assert.AreEqual ("address", ex.ParamName, "#C7");
+ }
}
-
+
[Test]
- [ExpectedException (typeof (ArgumentException))]
- public void FromBytes4 ()
+ public void Constructor0_Address_Null ()
{
- new IPAddress (new byte [4], 0);
+ try {
+ new IPAddress ((byte []) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("address", ex.ParamName, "#5");
+ }
}
-#else
+
[Test]
- [ExpectedException (typeof (ArgumentException))]
- public void FromBytes1 ()
+#if TARGET_JVM
+ [Ignore ("TD BUG ID: 7213")]
+#endif
+ public void Constructor1_Address_4Byte ()
{
- new IPAddress (new byte [4]);
+ byte [] bytes = new byte [4] { 192, 202, 112, 37 };
+ try {
+ new IPAddress (bytes, 0);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsFalse (ex.Message == "address", "#5");
+ Assert.IsNotNull (ex.ParamName, "#6");
+ Assert.AreEqual ("address", ex.ParamName, "#7");
+ }
}
-
+
[Test]
- [ExpectedException (typeof (ArgumentException))]
- public void FromBytes2 ()
+ public void Constructor1_Address_Null ()
{
- new IPAddress (new byte [4], 0);
+ try {
+ new IPAddress ((byte []) null, 5);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("address", ex.ParamName, "#5");
+ }
}
-#endif
+ [Test]
+ public void FromBytes1 ()
+ {
+ byte[] val1 = new byte[4];
+ val1[0] = 82;
+ val1[1] = 165;
+ val1[2] = 240;
+ val1[3] = 134;
+ CompareIPs (val1, "82.165.240.134");
+
+ byte[] val2 = new byte[4];
+ val2[0] = 123;
+ val2[1] = 124;
+ val2[2] = 125;
+ val2[3] = 126;
+ CompareIPs (val2, "123.124.125.126");
+ }
+
+ void CompareIPs (byte [] bytes, string address)
+ {
+ IPAddress ip = new IPAddress (bytes);
+ IPAddress ip2 = IPAddress.Parse (address);
+ Assert.IsTrue (ip2.Equals (ip), "#A-" + address);
+ Assert.IsTrue (ip.Equals (ip2), "#B-" + address);
+ }
-#if NET_2_0
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void TryParseArgumentNull ()
+ public void TryParse_IpString_Null ()
{
IPAddress i;
- IPAddress.TryParse (null, out i);
+
+ try {
+ IPAddress.TryParse ((string) null, out i);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("ipString", ex.ParamName, "#5");
+ }
}
[Test]
Assert.IsFalse (IPAddress.TryParse ("1::2:3:4:5::6:7:8", out i), "#8"); // :: ::
Assert.IsFalse (IPAddress.TryParse ("1::2:3:4:5:6:7:8", out i), "#9");
Assert.IsFalse (IPAddress.TryParse ("1;2:3:4:5:6:7:8", out i), "#10"); // ;
- Assert.IsFalse (IPAddress.TryParse ("1:2:3:4:5:6:7:8/10", out i), "#11"); // subnet
+ // FIXME:
+ // Assert.IsFalse (IPAddress.TryParse ("1:2:3:4:5:6:7:8/10", out i), "#11"); // subnet
+ }
+
+ [Test]
+ public void TryParseOkV4 ()
+ {
+ for (int i = 0; i < ipv4ParseOk.Length / 2; i++) {
+ IPAddress ip;
+ Assert.IsTrue (IPAddress.TryParse (ipv4ParseOk [i * 2], out ip), "#1:" + i);
+ Assert.AreEqual (ipv4ParseOk [i * 2 + 1], ip.ToString (), "#2:" + i);
+ }
+ }
+
+ [Test]
+ public void TryParseWrongV4 ()
+ {
+ for (int i = 0; i < ipv4ParseWrong.Length; i++) {
+ IPAddress ip;
+ string ipAddress = ipv4ParseWrong [i];
+
+ Assert.IsFalse (IPAddress.TryParse (ipAddress, out ip), "#1:" + i);
+ Assert.IsNull (ip, "#2:" + i);
+ }
}
[Test]
Assert.IsTrue (IPAddress.Parse ("FE80::1").IsIPv6LinkLocal, "#1");
Assert.IsTrue (IPAddress.Parse ("FE81::1").IsIPv6LinkLocal, "#2");
Assert.IsFalse (IPAddress.Parse ("FD81::1").IsIPv6LinkLocal, "#3");
+ Assert.IsFalse (IPAddress.Parse ("FF80::1").IsIPv6LinkLocal, "#4");
+ Assert.IsTrue (IPAddress.Parse ("FE91::1").IsIPv6LinkLocal, "#5");
+ Assert.IsTrue (IPAddress.Parse ("FEA0::1").IsIPv6LinkLocal, "#6");
+ Assert.IsFalse (IPAddress.Parse ("FEC0::1").IsIPv6LinkLocal, "#7");
}
[Test]
Assert.IsTrue (IPAddress.Parse ("FEC0::1").IsIPv6SiteLocal, "#1");
Assert.IsTrue (IPAddress.Parse ("FEC1::1").IsIPv6SiteLocal, "#2");
Assert.IsFalse (IPAddress.Parse ("FE81::1").IsIPv6SiteLocal, "#3");
+ Assert.IsFalse (IPAddress.Parse ("FFC0::1").IsIPv6SiteLocal, "#4");
+ Assert.IsTrue (IPAddress.Parse ("FED1::1").IsIPv6SiteLocal, "#5");
+ Assert.IsTrue (IPAddress.Parse ("FEE1::1").IsIPv6SiteLocal, "#6");
}
[Test]
Assert.IsTrue (IPAddress.Parse ("FF01::1").IsIPv6Multicast, "#2");
Assert.IsFalse (IPAddress.Parse ("FE00::1").IsIPv6Multicast, "#3");
}
-#endif
}
}