]>
Commit | Line | Data |
---|---|---|
108a4c3c AT |
1 | #define BOOST_TEST_DYN_LINK |
2 | #define BOOST_TEST_NO_MAIN | |
870a0fe4 AT |
3 | #ifdef HAVE_CONFIG_H |
4 | #include "config.h" | |
5 | #endif | |
108a4c3c AT |
6 | #include <boost/test/unit_test.hpp> |
7 | #include <boost/assign/list_of.hpp> | |
fa8fd4d2 | 8 | |
108a4c3c | 9 | #include <boost/tuple/tuple.hpp> |
108a4c3c | 10 | #include <boost/iostreams/device/file.hpp> |
108a4c3c AT |
11 | #include "dns.hh" |
12 | #include "zoneparser-tng.hh" | |
c14af8a9 | 13 | #include "dnsrecords.hh" |
a61e8e59 | 14 | #include "dnsname.hh" |
108a4c3c | 15 | #include <fstream> |
a245e51c | 16 | #include <cstdlib> |
108a4c3c AT |
17 | |
18 | BOOST_AUTO_TEST_SUITE(test_zoneparser_tng_cc) | |
19 | ||
20 | BOOST_AUTO_TEST_CASE(test_tng_record_types) { | |
c14af8a9 | 21 | reportAllTypes(); |
c14af8a9 | 22 | |
a245e51c | 23 | std::ostringstream pathbuf; |
0d73f0ab | 24 | const char* p = std::getenv("SRCDIR"); |
25 | if(!p) | |
26 | p = "."; | |
27 | pathbuf << p << "/../regression-tests/zones/unit.test"; | |
eaedd091 | 28 | ZoneParserTNG zp(pathbuf.str(), DNSName("unit.test")); |
108a4c3c AT |
29 | DNSResourceRecord rr; |
30 | ||
e59c5996 | 31 | ifstream ifs(pathbuf.str()); |
108a4c3c AT |
32 | |
33 | while(zp.get(rr)) { | |
34 | // make sure these concur. | |
35 | std::string host, type, data; | |
335da0ba | 36 | unsigned int ttl; |
108a4c3c AT |
37 | std::getline(ifs, host, ' '); |
38 | std::getline(ifs, type, ' '); | |
335da0ba | 39 | ttl = pdns_stou(type); |
108a4c3c AT |
40 | std::getline(ifs, type, ' '); |
41 | std::getline(ifs, type, ' '); | |
42 | std::getline(ifs, data, '\n'); | |
43 | // see if these agree | |
d66269ef | 44 | BOOST_CHECK_EQUAL(rr.qname.toString(), host); |
108a4c3c AT |
45 | BOOST_CHECK_EQUAL(rr.ttl, ttl); |
46 | BOOST_CHECK_EQUAL(rr.qtype.getName(), type); | |
77e0833b | 47 | if (rr.qtype == QType::SOA) |
3343ad1f | 48 | continue; // FIXME400 remove trailing dots from data |
4c22f7c5 AT |
49 | if (*(rr.content.rbegin()) != '.' && *(data.rbegin()) == '.') |
50 | BOOST_CHECK_EQUAL(rr.content, std::string(data.begin(),data.end()-1)); | |
51 | else | |
52 | BOOST_CHECK_EQUAL(rr.content, data); | |
411368f8 OM |
53 | } |
54 | } | |
55 | ||
56 | BOOST_AUTO_TEST_CASE(test_tng_record_generate) { | |
57 | reportAllTypes(); | |
58 | ||
59 | std::ostringstream pathbuf; | |
60 | const char* p = std::getenv("SRCDIR"); | |
61 | if(!p) | |
62 | p = "."; | |
63 | pathbuf << p << "/../regression-tests/zones/unit2.test"; | |
64 | ZoneParserTNG zp(pathbuf.str(), DNSName("unit2.test")); | |
65 | ||
71f785ac | 66 | vector<string> expected = { |
411368f8 OM |
67 | "0.01.0003.000005.00000007.unit2.test.", |
68 | "1.02.0004.000006.00000008.unit2.test.", | |
69 | "2.03.0005.000007.00000009.unit2.test.", | |
70 | "3.04.0006.000008.0000000a.unit2.test.", | |
71 | "4.05.0007.000009.0000000b.unit2.test.", | |
72 | "5.06.0008.00000A.0000000c.unit2.test.", | |
73 | "6.07.0009.00000B.0000000d.unit2.test.", | |
74 | "7.10.0010.00000C.0000000e.unit2.test.", | |
75 | "8.11.0011.00000D.0000000f.unit2.test.", | |
76 | "9.12.0012.00000E.00000010.unit2.test.", | |
77 | "10.13.0013.00000F.00000011.unit2.test.", | |
78 | "11.14.0014.000010.00000012.unit2.test.", | |
79 | "12.15.0015.000011.00000013.unit2.test.", | |
80 | "13.16.0016.000012.00000014.unit2.test.", | |
81 | "14.17.0017.000013.00000015.unit2.test.", | |
82 | "15.20.0018.000014.00000016.unit2.test.", | |
83 | "16.21.0019.000015.00000017.unit2.test." | |
84 | }; | |
85 | ||
71f785ac | 86 | for (auto const & exp : expected) { |
411368f8 OM |
87 | DNSResourceRecord rr; |
88 | zp.get(rr); | |
71f785ac | 89 | BOOST_CHECK_EQUAL(rr.qname.toString(), exp); |
411368f8 OM |
90 | BOOST_CHECK_EQUAL(rr.ttl, 86400U); |
91 | BOOST_CHECK_EQUAL(rr.qclass, 1U); | |
92 | BOOST_CHECK_EQUAL(rr.qtype.getName(), "A"); | |
93 | BOOST_CHECK_EQUAL(rr.content, "1.2.3.4"); | |
94 | } | |
108a4c3c AT |
95 | |
96 | } | |
97 | ||
98 | BOOST_AUTO_TEST_SUITE_END(); |