]> granicus.if.org Git - pdns/commitdiff
add bindparser tests
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Mon, 20 Jan 2014 18:15:02 +0000 (19:15 +0100)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Tue, 21 Jan 2014 08:50:10 +0000 (09:50 +0100)
pdns/Makefile.am
pdns/bindparserclasses.hh
pdns/named.conf.parsertest [new file with mode: 0644]
pdns/test-bindparser_cc.cc [new file with mode: 0644]

index cb8541f903f62e4160c01a07b8ec253260fd07d9..acea4209aa973499c832b67d4fbd1a81b665d9fb 100644 (file)
@@ -16,7 +16,7 @@ endif
 EXTRA_DIST = dnslabeltext.rl dnslabeltext.cc mtasker.cc inflighter.cc docs/pdns_control.8  \
        docs/pdns_server.8 docs/zone2sql.8 docs/zone2ldap.8 docs/pdnssec.8 \
        docs/dnsreplay.8 docs/dnsscope.8 docs/dnswasher.8 docs/pdnssec.8 docs/zone2ldap.8 \
-       bind-dnssec.schema.sqlite3.sql bindparser.h
+       bind-dnssec.schema.sqlite3.sql bindparser.h named.conf.parsertest
 
 SUBDIRS= $(POLARSSL_SUBDIR) ext/yahttp
 
@@ -267,7 +267,8 @@ testrunner_SOURCES=testrunner.cc test-misc_hh.cc test-nameserver_cc.cc test-dnsr
        dnswriter.cc base64.cc base32.cc dnsrecords.cc dnslabeltext.cc dnsparser.cc \
        rcpgenerator.cc ednssubnet.cc nsecrecords.cc sillyrecords.cc dnssecinfra.cc \
        test-base64_cc.cc test-iputils_hh.cc test-dns_random_hh.cc dns_random.cc \
-       test-rcpgenerator_cc.cc responsestats.cc
+       test-rcpgenerator_cc.cc responsestats.cc test-bindparser_cc.cc \
+       bindparser.cc bindlexer.c
 
 testrunner_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
 testrunner_LDADD= $(POLARSSL_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
index 92bad31a5ca9721f089373fd0978c15ec599f9ed..f554bd7e9675ab3679accd45e3cd3ecc697c1d8d 100644 (file)
@@ -25,6 +25,7 @@
 #include <map>
 #include <vector>
 #include <set>
+#include <stdio.h>
 
 #include "namespaces.hh"
 
diff --git a/pdns/named.conf.parsertest b/pdns/named.conf.parsertest
new file mode 100644 (file)
index 0000000..4d38d22
--- /dev/null
@@ -0,0 +1,70 @@
+# this file is used by ../pdns/test-bindparser_cc.cc
+# if you change it, please make check!
+
+options {
+       directory "./zones/";
+       recursion no;
+       listen-on port 5300 {
+               127.0.0.1;
+       };
+       version "Meow!Meow!";
+       minimal-responses yes;
+};
+zone "example.com"{
+       type master;
+       file "example.com";
+};
+
+zone "test.com"{
+       type slave;
+       file "test.com";
+       masters { 1.2.3.4:5678; };
+};
+
+zone "test.dyndns" {
+       type garblewarble;
+       file "test.dyndns";
+       allow-update {
+               127.0.0.0/8;
+       };
+};
+
+zone "wtest.com"{
+       type master;
+       file "wtest.com";
+};
+
+zone "nztest.com"{
+       type master;
+       file "nztest.com";
+};
+
+zone "dnssec-parent.com"{
+       type master;
+       file "dnssec-parent.com";
+};
+
+zone "delegated.dnssec-parent.com"{
+       type master;
+       file "delegated.dnssec-parent.com";
+};
+
+zone "secure-delegated.dnssec-parent.com"{
+       type master;
+       file "secure-delegated.dnssec-parent.com";
+};
+
+zone "minimal.com"{
+       type master;
+       file "minimal.com";
+};
+
+zone "tsig.com"{
+       type master;
+       file "tsig.com";
+};
+
+zone "stest.com"{
+       type master;
+       file "stest.com";
+};
diff --git a/pdns/test-bindparser_cc.cc b/pdns/test-bindparser_cc.cc
new file mode 100644 (file)
index 0000000..647617f
--- /dev/null
@@ -0,0 +1,45 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+
+#include <boost/test/unit_test.hpp>
+#include "bindparserclasses.hh"
+#include "misc.hh"
+#include "pdnsexception.hh"
+#include <utility>
+#include <boost/foreach.hpp>
+
+using std::string;
+
+BOOST_AUTO_TEST_SUITE(bindparser_cc)
+
+BOOST_AUTO_TEST_CASE(test_parser) {
+        BindParser BP;
+        BOOST_CHECK_THROW( BP.parse("../regression-tests/named.confx"), PDNSException);
+        BP.parse("./named.conf.parsertest");
+
+        vector<BindDomainInfo> domains=BP.getDomains();
+        BOOST_CHECK_EQUAL(domains.size(), 11);
+
+#define checkzone(i, dname, fname, ztype, nmasters) { \
+                BOOST_CHECK_EQUAL(domains[i].name, #dname); \
+                BOOST_CHECK_EQUAL(domains[i].filename, fname); \
+                BOOST_CHECK_EQUAL(domains[i].type, #ztype); \
+                BOOST_CHECK_EQUAL(domains[i].masters.size(), nmasters); \
+        }
+
+        checkzone(0, example.com, "./zones//example.com", master, 0);
+        checkzone(1, test.com, "./zones//test.com", slave, 1);
+        BOOST_CHECK_EQUAL(domains[1].masters[0], "1.2.3.4:5678");
+        checkzone(2, test.dyndns, "./zones//test.dyndns", garblewarble, 0);
+        checkzone(3, wtest.com, "./zones//wtest.com", master, 0);
+        checkzone(4, nztest.com, "./zones//nztest.com", master, 0);
+        checkzone(5, dnssec-parent.com, "./zones//dnssec-parent.com", master, 0);
+        checkzone(6, delegated.dnssec-parent.com, "./zones//delegated.dnssec-parent.com", master, 0);
+        checkzone(7, secure-delegated.dnssec-parent.com, "./zones//secure-delegated.dnssec-parent.com", master, 0);
+        checkzone(8, minimal.com, "./zones//minimal.com", master, 0);
+        checkzone(9, tsig.com, "./zones//tsig.com", master, 0);
+        checkzone(10, stest.com, "./zones//stest.com", master, 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+