public static void TestCount() { for (int i = 0; i < IPv6.BitCount; i++) { IPv6 addr = IPv6.NetMask(i); if (IPv6.GetMaskLength(addr) != i) { throw new TestFailedException( String.Format("TestCount {0}", i) ); } IPv6 addrDup = IPv6.Parse(addr.ToString()); if (addrDup != addr) { throw new TestFailedException( String.Format("TestCountDup {0}", i) ); } } }
private static void TestParse() { // // grumble, grumble, no clean struct array initializer syntax !?! // // Okay, these are pairs of Valid IPv6 string representations // and their manually parsed IPv6 representations. // SrepV6Pair [] pairs = new SrepV6Pair[] { new SrepV6Pair( "FfEe:DdCc:BbAa:9876:5432:1001:2345:6789", new IPv6(0xffeeddcc, 0xbbaa9876, 0x54321001, 0x23456789) ), new SrepV6Pair( "ffe8:c181::192:101", new IPv6(0xffe8c181U, 0x0U, 0x0U, 0x01920101U) ), new SrepV6Pair( "::", IPv6.Zero ), new SrepV6Pair( "0:0:0:0:0:0:0:0", IPv6.Zero ), new SrepV6Pair( "1::", new IPv6(0x00010000U, 0x0U, 0x0U, 0x0U) ), new SrepV6Pair( "12::", new IPv6(0x00120000U, 0x0U, 0x0U, 0x0U) ), new SrepV6Pair( "123::", new IPv6(0x01230000U, 0x0U, 0x0U, 0x0U) ), new SrepV6Pair( "1234::", new IPv6(0x12340000U, 0x0U, 0x0U, 0x0U) ), new SrepV6Pair( "1234:5678:9abc:def0::", new IPv6(0x12345678U, 0x9abcdef0U, 0x0U, 0x0U) ), new SrepV6Pair( "::1", new IPv6(0x0U, 0x0U, 0x0U, 0x1U) ), new SrepV6Pair( "::12", new IPv6(0x0U, 0x0U, 0x0U, 0x12U) ), new SrepV6Pair( "::123", new IPv6(0x0U, 0x0U, 0x0U, 0x123U) ), new SrepV6Pair( "::1234", new IPv6(0x0U, 0x0U, 0x0U, 0x1234U) ), new SrepV6Pair( "::1234:5678:9abc:def0", new IPv6(0x0U, 0x0U, 0x12345678U, 0x9abcdef0U) ), }; for (int i = 0; i < pairs.Length; i++) { IPv6 a = IPv6.Parse(pairs[i].srep); if (a != pairs[i].v6rep) { Console.WriteLine("{0} {1}", a, pairs[i].v6rep); throw new TestFailedException( String.Format("Parse {0}", i) ); } IPv6 dup = IPv6.Parse(a.ToString()); if (dup != a) { throw new TestFailedException( String.Format("ToString {0}", i) ); } } // // Test bogus strings // string [] badSreps = new string [] { "Frank", "00000::", "0:1:2:3:4:5:6:7:8", "0.1.2.3.4::0.1.2.3.4.", "0:1:2:3:4:5:6:7:trailing junk", }; for (int i = 0; i < badSreps.Length; i++) { try { IPv6 bad = IPv6.Parse(badSreps[i]); throw new TestFailedException(badSreps[i]); } catch (FormatException) { } } }