0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

[test/misc] tests: extended route.cpp test for new IPv4/v6-specialized RouteType

Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
James Yonan 2018-07-31 23:52:45 -06:00 committed by Frank Lichtenheld
parent 3e6b46ff78
commit 564b0dfcba

View File

@ -43,6 +43,73 @@ void test_set()
OPENVPN_LOG(r.to_string());
}
template <typename LIST>
void test_split(const LIST& rtlist)
{
OPENVPN_LOG("TEST SPLIT");
typedef typename LIST::value_type RT;
for (const auto &r : rtlist)
{
RT r1, r2;
if (r.is_canonical() && r.split(r1, r2))
OPENVPN_LOG(r << ' ' << r1 << ' ' << r2);
}
}
void test_list4()
{
OPENVPN_LOG("===== ROUTE4 LIST =====");
IP::Route4List routes;
routes.emplace_back("1.2.3.4/24");
routes.emplace_back("1.2.3.0/24");
routes.emplace_back("1.2.3.2/24");
routes.emplace_back("1.2.3.1/24");
routes.emplace_back("128.0.0.0/1");
OPENVPN_LOG_NTNL(routes.to_string());
if (routes.contains(IPv4::Addr::from_string("100.1.2.3")))
throw Exception("unexpected contains #1");
if (!routes.contains(IPv4::Addr::from_string("200.1.2.3")))
throw Exception("unexpected contains #2");
test_split(routes);
}
void test_list6()
{
OPENVPN_LOG("===== ROUTE6 LIST =====");
IP::Route6List routes;
routes.emplace_back("1:2:3:4:5:6:dead:beef/64");
routes.emplace_back("cafe:babe::/64");
OPENVPN_LOG_NTNL(routes.to_string());
if (routes.contains(IPv6::Addr::from_string("1111:2222:3333:4444:5555:6666:7777:8888")))
throw Exception("unexpected contains #1");
if (!routes.contains(IPv6::Addr::from_string("cafe:babe:0:0:1111:2222:3333:4444")))
throw Exception("unexpected contains #2");
test_split(routes);
}
void test_list()
{
OPENVPN_LOG("===== ROUTE LIST =====");
IP::RouteList routes;
routes.emplace_back("1.2.3.4/24");
routes.emplace_back("1.2.3.0/24");
routes.emplace_back("1.2.3.2/24");
routes.emplace_back("1.2.3.1/24");
routes.emplace_back("128.0.0.0/1");
routes.emplace_back("1:2:3:4:5:6:dead:beef/64");
routes.emplace_back("cafe:babe::/64");
OPENVPN_LOG_NTNL(routes.to_string());
if (routes.contains(IP::Addr::from_string("100.1.2.3")))
throw Exception("unexpected contains #1");
if (!routes.contains(IP::Addr::from_string("200.1.2.3")))
throw Exception("unexpected contains #2");
if (routes.contains(IP::Addr::from_string("1111:2222:3333:4444:5555:6666:7777:8888")))
throw Exception("unexpected contains #3");
if (!routes.contains(IP::Addr::from_string("cafe:babe:0:0:1111:2222:3333:4444")))
throw Exception("unexpected contains #4");
test_split(routes);
}
int main(int /*argc*/, char* /*argv*/[])
{
try {
@ -63,6 +130,10 @@ int main(int /*argc*/, char* /*argv*/[])
}
test_set();
test_list4();
test_list6();
test_list();
}
catch (const std::exception& e)
{