]> granicus.if.org Git - pdns/commitdiff
Test cases for base32
authorAki Tuomi <cmouse@desteem.org>
Mon, 27 May 2013 10:19:42 +0000 (13:19 +0300)
committerAki Tuomi <cmouse@desteem.org>
Mon, 27 May 2013 10:19:42 +0000 (13:19 +0300)
pdns/Makefile.am
pdns/test-base32_cc.cc [new file with mode: 0644]

index 12c1b930c290cca5ef64075d3dc8b18d977654ff..9028b8cbed17bd1f62f50bdab098b7836e4f419c 100644 (file)
@@ -243,7 +243,8 @@ 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 test-nameserver_cc.cc test-dnsrecords_cc.cc nameserver.cc misc.cc \
+testrunner_SOURCES=testrunner.cc test-misc_hh.cc test-nameserver_cc.cc test-dnsrecords_cc.cc test-base32_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 \
diff --git a/pdns/test-base32_cc.cc b/pdns/test-base32_cc.cc
new file mode 100644 (file)
index 0000000..7293a2c
--- /dev/null
@@ -0,0 +1,35 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+#include <boost/test/unit_test.hpp>
+#include <boost/assign/list_of.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
+#include "base32.hh"
+
+BOOST_AUTO_TEST_SUITE(test_base32_cc)
+
+BOOST_AUTO_TEST_CASE(test_record_types) {
+  typedef boost::tuple<const std::string, const std::string> case_t;
+  typedef std::list<case_t> cases_t;
+
+  // RFC test vectors
+  cases_t cases = boost::assign::list_of
+    (case_t(std::string(""), std::string("")))
+    (case_t(std::string("f"), std::string("CO======")))
+    (case_t(std::string("fo"), std::string("CPNG====")))
+    (case_t(std::string("foo"), std::string("CPNMU===")))
+    (case_t(std::string("foob"), std::string("CPNMUOG=")))
+    (case_t(std::string("fooba"), std::string("CPNMUOJ1")))
+    (case_t(std::string("foobar"), std::string("CPNMUOJ1E8======")))
+  ;
+
+  BOOST_FOREACH(const case_t& val, cases) {
+     std::string res;
+     res = toBase32Hex(val.get<0>());
+     BOOST_CHECK_EQUAL(res, val.get<1>());
+     res = fromBase32Hex(val.get<1>());
+     BOOST_CHECK_EQUAL(res, val.get<0>());
+  }
+};
+
+BOOST_AUTO_TEST_SUITE_END();