googerteller/testrunner.cc

46 lines
856 B
C++
Raw Permalink Normal View History

2022-08-29 09:06:39 -05:00
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "ext/doctest.h"
2022-08-29 09:17:42 -05:00
#include "lpmwrapper.hh"
2022-08-29 09:06:39 -05:00
using namespace std;
TEST_CASE("basic test") {
2022-08-29 09:17:42 -05:00
LPMWrapper t;
void* ptr = (void*)1;
t.insert("127.0.0.1/32", ptr);
CHECK(t.lookup("127.0.0.1") == ptr);
CHECK(t.lookup("127.0.0.2") == 0);
2022-08-29 09:06:39 -05:00
}
TEST_CASE("IPv6 test") {
LPMWrapper t;
void* ptr = (void*)1;
t.insert("::1", ptr);
CHECK(t.lookup("::1") == ptr);
CHECK(t.lookup("::2") == 0);
}
TEST_CASE("Mixed test") {
LPMWrapper t;
void* ptr = (void*)1;
t.insert("::1", ptr);
ptr = (void*)2;
t.insert("192.168.0.0/16", ptr);
CHECK(t.lookup("::1") == (void*)1);
CHECK(t.lookup("192.168.1.1") == (void*)2);
CHECK(t.lookup("192.168.255.255") == (void*)2);
CHECK(t.lookup("10.0.0.1") == 0);
CHECK(t.lookup("172.16.2.3") == 0);
CHECK(t.lookup("1.0.0.0") == 0);
}