2011-06-21 21:42:20 +10:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "ip.hpp"
|
2011-06-21 21:42:20 +10:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "debug.hpp"
|
|
|
|
#include "platform.hpp"
|
|
|
|
#include "tap.hpp"
|
|
|
|
#include "types.hpp"
|
2011-06-21 21:42:20 +10:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static void
|
2018-08-05 14:42:02 +10:00
|
|
|
test_good (cruft::TAP::logger &tap)
|
2016-01-19 18:31:49 +11:00
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
const char *str;
|
|
|
|
ipv4::ip ip;
|
|
|
|
const char *msg;
|
|
|
|
} TESTS[] = {
|
|
|
|
{ "0.0.0.0", { 0, 0, 0, 0 }, "null" },
|
|
|
|
{ "255.255.255.255", { 255, 255, 255, 255 }, "full" },
|
|
|
|
{ "127.0.0.1", { 127, 0, 0, 1 }, "localhost" }
|
|
|
|
};
|
2011-06-21 21:42:20 +10:00
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
for (const auto &i: TESTS)
|
|
|
|
tap.expect_eq (ipv4::ip::parse (i.str), i.ip, "%s", i.msg);
|
2016-01-19 18:31:49 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static void
|
2018-08-05 14:42:02 +10:00
|
|
|
test_bad (cruft::TAP::logger &tap)
|
2016-01-19 18:31:49 +11:00
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
const char *str;
|
|
|
|
const char *msg;
|
|
|
|
} TESTS[] = {
|
|
|
|
{ "::1", "ipv6" },
|
|
|
|
{ "foo", "alpha" },
|
|
|
|
{ "", "empty" },
|
|
|
|
{ "256.0.0.1", "overflow" }
|
2011-06-21 21:42:20 +10:00
|
|
|
};
|
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
for (const auto &i: TESTS)
|
|
|
|
tap.expect_throw<ipv4::error> ([&] { ipv4::ip::parse (i.str); }, "%s", i.msg);
|
2016-01-19 18:31:49 +11:00
|
|
|
}
|
|
|
|
|
2011-06-21 21:42:20 +10:00
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
main (int, char **) {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2016-01-19 18:31:49 +11:00
|
|
|
|
|
|
|
test_good (tap);
|
|
|
|
test_bad (tap);
|
|
|
|
|
|
|
|
return tap.status ();
|
2011-06-21 21:42:20 +10:00
|
|
|
}
|