]> granicus.if.org Git - pdns/commitdiff
add Boost Test based unit test suite
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Fri, 15 Mar 2013 11:52:47 +0000 (11:52 +0000)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Fri, 15 Mar 2013 11:52:47 +0000 (11:52 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3119 d19b8d6e-7fed-0310-83ef-9ca221ded41b

configure.ac
pdns/Makefile.am
pdns/test-misc_hh.cc [new file with mode: 0644]
pdns/testrunner.cc [new file with mode: 0644]

index 1beab8224b0d54069ad2be89eda331a78f6a95f5..05da963c9f7f2121c897ed5930be0ae7d85ce0b0 100644 (file)
@@ -22,6 +22,7 @@ BOOST_FOREACH
 #BOOST_FILESYSTEM([mt])
 BOOST_PROGRAM_OPTIONS([mt])
 BOOST_SERIALIZATION([mt])
+BOOST_TEST([mt])
 #BOOST_SYSTEM([mt])
 
 # detect pkg-config explicitly
index 8e7a2eb1cb795f49a1fc28fdab10175d4968f0fb..82955c154b8bed6f423adba6392fadff1b5e02b4 100644 (file)
@@ -40,6 +40,7 @@ bin_PROGRAMS = pdns_control pdnssec dnsreplay
 endif
 
 EXTRA_PROGRAMS=pdns_recursor sdig tsig-tests speedtest pdns_control dnsscope dnsgram \
+testrunner \
 toysdig dnsdemog dnswasher dnsscan nproxy notify pdnssec dnsbulktest nsec3dig # dnslabel # tcptorture
 
 pdns_server_SOURCES=dnspacket.cc nameserver.cc tcpreceiver.hh \
@@ -232,6 +233,10 @@ dnsdemog_SOURCES=dnsdemog.cc misc.cc unix_utility.cc qtype.cc \
 rec_control_SOURCES=rec_channel.cc rec_channel.hh rec_control.cc arguments.cc arguments.hh misc.cc qtype.cc \
        unix_utility.cc logger.cc statbag.cc
 
+testrunner_SOURCES=testrunner.c test-misc_hh.cc
+testrunner_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
+testrunner_LDADD= $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
+
 pdns_recursor_SOURCES=syncres.cc resolver.hh misc.cc unix_utility.cc qtype.cc \
 logger.cc statbag.cc arguments.cc  lwres.cc pdns_recursor.cc reczones.cc lwres.hh \
 mtasker.hh syncres.hh recursor_cache.cc recursor_cache.hh dnsparser.cc \
diff --git a/pdns/test-misc_hh.cc b/pdns/test-misc_hh.cc
new file mode 100644 (file)
index 0000000..f8f0f29
--- /dev/null
@@ -0,0 +1,46 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+
+#include <boost/test/unit_test.hpp>
+#include "misc.hh"
+#include <utility>
+
+using std::string;
+
+BOOST_AUTO_TEST_SUITE(misc_hh)
+typedef pair<std::string, uint16_t> typedns_t;
+
+BOOST_AUTO_TEST_CASE(test_CIStringCompare) {
+       set<std::string, CIStringCompare> nsset;  
+       nsset.insert("abc");
+       nsset.insert("ns.example.com");
+       nsset.insert("");
+       nsset.insert("ns.example.com");
+       BOOST_CHECK_EQUAL(nsset.size(), 3);
+
+       ostringstream s;
+       for(set<std::string, CIStringCompare>::const_iterator i=nsset.begin();i!=nsset.end();++i) {
+               s<<"["<<*i<<"]";
+       }
+       BOOST_CHECK_EQUAL(s.str(), "[][abc][ns.example.com]");
+}
+
+BOOST_AUTO_TEST_CASE(test_CIStringPairCompare) {
+       set<typedns_t, CIStringPairCompare> nsset2;  
+       nsset2.insert(make_pair("ns.example.com", 1));
+       nsset2.insert(make_pair("abc", 1));
+       nsset2.insert(make_pair("", 1));
+       nsset2.insert(make_pair("abc", 2));
+       nsset2.insert(make_pair("abc", 1));
+       nsset2.insert(make_pair("ns.example.com", 0));
+       BOOST_CHECK_EQUAL(nsset2.size(), 5);
+
+       ostringstream s;
+       for(set<typedns_t, CIStringPairCompare>::const_iterator i=nsset2.begin();i!=nsset2.end();++i) {
+               s<<"["<<i->first<<"|"<<i->second<<"]";
+       }
+       BOOST_CHECK_EQUAL(s.str(), "[|1][abc|1][abc|2][ns.example.com|0][ns.example.com|1]");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
diff --git a/pdns/testrunner.cc b/pdns/testrunner.cc
new file mode 100644 (file)
index 0000000..3203866
--- /dev/null
@@ -0,0 +1,5 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_MODULE unit
+
+#include <boost/test/unit_test.hpp>