From: bert hubert Date: Mon, 6 May 2013 19:06:58 +0000 (+0200) Subject: unittest now links in 75% of PowerDNS, plus actuall tests for AddressIsUs now. X-Git-Tag: auth-3.3-rc1~120 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=38720c1b340034fa783452fcf4c550f465d966b2;p=thirdparty%2Fpdns.git unittest now links in 75% of PowerDNS, plus actuall tests for AddressIsUs now. --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index a7655eda6c..82a6b23eba 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -241,7 +241,11 @@ 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.cc test-misc_hh.cc +testrunner_SOURCES=testrunner.cc test-misc_hh.cc test-nameserver_cc.cc nameserver.cc misc.cc \ + unix_utility.cc logger.cc statbag.cc arguments.cc qtype.cc dnspacket.cc \ + dnswriter.cc base64.cc base32.cc dnsrecords.cc dnslabeltext.cc dnsparser.cc \ + rcpgenerator.cc ednssubnet.cc nsecrecords.cc sillyrecords.cc dnssecinfra.cc \ + md5.cc testrunner_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) testrunner_LDADD= $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) diff --git a/pdns/nameserver.hh b/pdns/nameserver.hh index f7b56cb037..ff0cb87a17 100644 --- a/pdns/nameserver.hh +++ b/pdns/nameserver.hh @@ -34,6 +34,7 @@ #include #include "statbag.hh" #include "namespaces.hh" +#include "dnspacket.hh" /** This is the main class. It opens a socket on udp port 53 and waits for packets. Those packets can be retrieved with the receive() member function, which returns a DNSPacket. diff --git a/pdns/test-nameserver_cc.cc b/pdns/test-nameserver_cc.cc new file mode 100644 index 0000000000..7a91b22d13 --- /dev/null +++ b/pdns/test-nameserver_cc.cc @@ -0,0 +1,55 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#include +#include "iputils.hh" +#include "nameserver.hh" +#include "statbag.hh" +#include "arguments.hh" +#include + +extern vector g_localaddresses; +StatBag S; + +ArgvMap &arg() +{ + static ArgvMap theArg; + return theArg; +} + +BOOST_AUTO_TEST_SUITE(nameserver_cc) + +BOOST_AUTO_TEST_CASE(test_AddressIsUs4) { + ComboAddress local1("127.0.0.1", 53); + ComboAddress local2("127.0.0.2", 53); + ComboAddress Remote("192.168.255.255", 53); + + g_localaddresses.push_back(ComboAddress("0.0.0.0", 53)); + + BOOST_CHECK_EQUAL(AddressIsUs(local1), true); + BOOST_CHECK_EQUAL(AddressIsUs(local2), false); + BOOST_CHECK_EQUAL(AddressIsUs(Remote), false); + + g_localaddresses.clear(); + g_localaddresses.push_back(ComboAddress("192.168.255.255", 53)); + BOOST_CHECK_EQUAL(AddressIsUs(Remote), true); + Remote.sin4.sin_port = 1; + BOOST_CHECK_EQUAL(AddressIsUs(Remote), false); +} + +BOOST_AUTO_TEST_CASE(test_AddressIsUs6) { + ComboAddress local1("127.0.0.1", 53); + ComboAddress local2("127.0.0.2", 53); + ComboAddress local3("::1", 53); + ComboAddress NotUs("192.168.255.255", 53); + + g_localaddresses.clear(); + g_localaddresses.push_back(ComboAddress("::", 53)); + + BOOST_CHECK_EQUAL(AddressIsUs(local1), true); + BOOST_CHECK_EQUAL(AddressIsUs(local2), false); + BOOST_CHECK_EQUAL(AddressIsUs(local3), true); + BOOST_CHECK_EQUAL(AddressIsUs(NotUs), false); +} + +BOOST_AUTO_TEST_SUITE_END()