|
|
@ -155,6 +155,80 @@ BOOST_AUTO_TEST_CASE(subnet_test) |
|
|
|
BOOST_CHECK(CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).Match(CNetAddr("1:2:3:4:5:6:7:8"))); |
|
|
|
BOOST_CHECK(CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).Match(CNetAddr("1:2:3:4:5:6:7:8"))); |
|
|
|
BOOST_CHECK(!CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).Match(CNetAddr("1:2:3:4:5:6:7:9"))); |
|
|
|
BOOST_CHECK(!CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).Match(CNetAddr("1:2:3:4:5:6:7:9"))); |
|
|
|
BOOST_CHECK(CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).ToString() == "1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
|
|
|
BOOST_CHECK(CSubNet(CNetAddr("1:2:3:4:5:6:7:8")).ToString() == "1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSubNet subnet = CSubNet("1.2.3.4/255.255.255.255"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/32"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.254"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/31"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.252"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/30"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.248"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/29"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.240"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/28"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.224"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/27"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.192"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/26"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.128"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/25"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.255.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/24"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.254.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.2.0/23"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.252.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/22"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.248.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/21"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.240.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/20"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.224.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/19"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.192.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/18"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.128.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/17"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.255.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/16"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.254.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/15"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.252.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/14"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.248.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/13"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.240.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/12"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.224.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/11"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.192.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/10"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.128.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/9"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/255.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/8"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/254.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/7"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/252.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/6"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/248.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/5"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/240.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/4"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/224.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/3"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/192.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/2"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/128.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/1"); |
|
|
|
|
|
|
|
subnet = CSubNet("1.2.3.4/0.0.0.0"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/0"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subnet = CSubNet("1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1:2:3:4:5:6:7:8/128"); |
|
|
|
|
|
|
|
subnet = CSubNet("1:2:3:4:5:6:7:8/ffff:0000:0000:0000:0000:0000:0000:0000"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1::/16"); |
|
|
|
|
|
|
|
subnet = CSubNet("1:2:3:4:5:6:7:8/0000:0000:0000:0000:0000:0000:0000:0000"); |
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "::/0"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(netbase_getgroup) |
|
|
|
BOOST_AUTO_TEST_CASE(netbase_getgroup) |
|
|
|