]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-zoneparser_tng_cc.cc
Merge pull request #7908 from omoerbeek/rec-4.1.14-changelog
[thirdparty/pdns.git] / pdns / test-zoneparser_tng_cc.cc
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_NO_MAIN
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
6 #include <boost/test/unit_test.hpp>
7 #include <boost/assign/list_of.hpp>
8
9 #include <boost/tuple/tuple.hpp>
10 #include <boost/iostreams/device/file.hpp>
11 #include "dns.hh"
12 #include "zoneparser-tng.hh"
13 #include "dnsrecords.hh"
14 #include "dnsname.hh"
15 #include <fstream>
16 #include <cstdlib>
17
18 BOOST_AUTO_TEST_SUITE(test_zoneparser_tng_cc)
19
20 BOOST_AUTO_TEST_CASE(test_tng_record_types) {
21 reportAllTypes();
22
23 std::ostringstream pathbuf;
24 const char* p = std::getenv("SRCDIR");
25 if(!p)
26 p = ".";
27 pathbuf << p << "/../regression-tests/zones/unit.test";
28 ZoneParserTNG zp(pathbuf.str(), DNSName("unit.test"));
29 DNSResourceRecord rr;
30
31 ifstream ifs(pathbuf.str());
32
33 while(zp.get(rr)) {
34 // make sure these concur.
35 std::string host, type, data;
36 unsigned int ttl;
37 std::getline(ifs, host, ' ');
38 std::getline(ifs, type, ' ');
39 ttl = pdns_stou(type);
40 std::getline(ifs, type, ' ');
41 std::getline(ifs, type, ' ');
42 std::getline(ifs, data, '\n');
43 // see if these agree
44 BOOST_CHECK_EQUAL(rr.qname.toString(), host);
45 BOOST_CHECK_EQUAL(rr.ttl, ttl);
46 BOOST_CHECK_EQUAL(rr.qtype.getName(), type);
47 if (rr.qtype == QType::SOA)
48 continue; // FIXME400 remove trailing dots from data
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);
53 }
54
55 }
56
57 BOOST_AUTO_TEST_SUITE_END();