sp
[ghsmtp.git] / IP4-test.cpp
blob2c9d83db7ac0e1c60a73f5583121a8663ec1b5c4
1 #include "IP4.hpp"
3 #include "Domain.hpp"
5 #include <glog/logging.h>
7 int main(int argc, char const* argv[])
9 using IP4::as_address;
10 using IP4::is_address;
11 using IP4::is_address_literal;
12 using IP4::is_private;
13 using IP4::reverse;
14 using IP4::to_address_literal;
16 CHECK(is_address_literal("[69.0.0.0]"));
17 CHECK(!is_address_literal("69.0.0.0]"));
18 CHECK(!is_address_literal("[69.0.0.0"));
19 CHECK(!is_address_literal("[]"));
20 CHECK(!is_address_literal("[1234]"));
22 CHECK(is_address("0.0.0.0"));
23 CHECK(is_address("69.0.0.0"));
24 CHECK(is_address("160.0.0.0"));
25 CHECK(is_address("250.0.0.0"));
26 CHECK(is_address("251.0.0.0"));
27 CHECK(is_address("252.0.0.0"));
28 CHECK(is_address("253.0.0.0"));
29 CHECK(is_address("254.0.0.0"));
30 CHECK(is_address("111.0.0.0"));
32 CHECK(is_address("9.9.9.9"));
33 CHECK(is_address("99.99.99.99"));
34 CHECK(is_address("255.0.0.1"));
35 CHECK(is_address("127.0.0.1"));
37 CHECK(!is_address("127.0.0.1."));
38 CHECK(!is_address("foo.bar"));
39 CHECK(!is_address(""));
41 // This is acceptable:
42 CHECK(is_address("001.001.001.001"));
43 // and this
44 CHECK(is_address("01.01.01.01"));
45 // and this
46 CHECK(is_address("000.000.000.000"));
47 // but not:
48 CHECK(!is_address("0001.0.0.0"));
49 // or:
50 CHECK(!is_address("00001.0.0.0"));
51 // or:
52 CHECK(!is_address("0000.0.0.0"));
54 CHECK(!is_address("256.0.0.0"));
55 CHECK(!is_address("260.0.0.0"));
56 CHECK(!is_address("300.0.0.0"));
57 CHECK(!is_address("1000.0.0.0"));
59 CHECK(!is_address("1.256.0.0"));
60 CHECK(!is_address("1.260.0.0"));
61 CHECK(!is_address("1.300.0.0"));
62 CHECK(!is_address("1.1000.0.0"));
64 CHECK(!is_address("1.1.256.0"));
65 CHECK(!is_address("1.1.260.0"));
66 CHECK(!is_address("1.1.300.0"));
67 CHECK(!is_address("1.1.1000.0"));
69 CHECK(!is_address("1.1.1.256"));
70 CHECK(!is_address("1.1.1.260"));
71 CHECK(!is_address("1.1.1.300"));
72 CHECK(!is_address("1.1.1.1000"));
74 auto const rev{reverse("1.2.3.4")};
75 CHECK_EQ(0, rev.compare("4.3.2.1."));
77 auto const addr = "108.83.36.113";
78 auto const addr_lit = "[108.83.36.113]";
80 CHECK(is_address(addr));
81 CHECK(is_address_literal(addr_lit));
83 CHECK_EQ(to_address_literal(addr), addr_lit);
84 CHECK_EQ(as_address(addr_lit), addr);
86 CHECK(!is_private("1.2.3.4"));
87 CHECK(!is_private("127.0.0.1"));
89 CHECK(is_private("10.0.0.1"));
91 CHECK(!is_private("172.15.0.1"));
92 CHECK(is_private("172.16.0.1"));
93 CHECK(is_private("172.31.255.255"));
94 CHECK(!is_private("172.32.0.1"));
96 CHECK(is_private("192.168.0.1"));