[svn] commit: r1471 - /trunk/src/lib/dns/tests/base32_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Mar 17 00:42:57 UTC 2010


Author: jinmei
Date: Wed Mar 17 00:42:56 2010
New Revision: 1471

Log:
add failing tests.  base32 implementation is still quite immature.

Modified:
    trunk/src/lib/dns/tests/base32_unittest.cc

Modified: trunk/src/lib/dns/tests/base32_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/base32_unittest.cc (original)
+++ trunk/src/lib/dns/tests/base32_unittest.cc Wed Mar 17 00:42:56 2010
@@ -32,11 +32,34 @@
 
 class Base32Test : public ::testing::Test {
 protected:
-    Base32Test() {}
+    Base32Test() {
+        // test vectors from RFC4648
+#if 0   // the current implementation doesn't seem to handle '=' correctly
+        test_sequence.push_back(StringPair("", ""));
+        test_sequence.push_back(StringPair("f", "CO======"));
+        test_sequence.push_back(StringPair("fo", "CPNG===="));
+        test_sequence.push_back(StringPair("foo", "CPNMU==="));
+        test_sequence.push_back(StringPair("foob", "CPNMUOG="));
+#endif
+        test_sequence.push_back(StringPair("fooba", "CPNMUOJ1"));
+#if 0                           // this fails
+        test_sequence.push_back(StringPair("foobar", "CPNMUOJ1E8======"));
+#endif
+    }
+    vector<StringPair> test_sequence;
+    vector<uint8_t> decoded_data;
 };
 
-TEST_F(Base32Test, reversibility)
+void
+decodeCheck(const string& input_string, vector<uint8_t>& output,
+            const string& expected)
 {
+    decodeBase32(input_string, output);
+    EXPECT_EQ(expected, string(&output[0], &output[0] + output.size()));
+}
+
+
+TEST_F(Base32Test, reversibility) {
     vector<uint8_t> result;
 //    const string input("H9RSFB7FPF2L8HG35CMPC765TDK23RP6");
     const string input("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
@@ -45,8 +68,15 @@
     EXPECT_EQ(input, output);
 }
 
-TEST_F(Base32Test, decode1)
-{
+TEST_F(Base32Test, decode0) {
+    for (vector<StringPair>::const_iterator it = test_sequence.begin();
+         it != test_sequence.end();
+         ++it) {
+        decodeCheck((*it).second, decoded_data, (*it).first);
+    }
+}
+
+TEST_F(Base32Test, decode1) {
     vector<uint8_t> result;
     const std::string input("000G40O40K30E209185GO38E1S8124GJ");
     decodeBase32(input, result);
@@ -56,8 +86,16 @@
     }
 }
 
-TEST_F(Base32Test, encode1)
-{
+TEST_F(Base32Test, encode0) {
+    for (vector<StringPair>::const_iterator it = test_sequence.begin();
+         it != test_sequence.end();
+         ++it) {
+        decoded_data.assign((*it).first.begin(), (*it).first.end());
+        EXPECT_EQ((*it).second, encodeBase32(decoded_data));
+    }
+}
+
+TEST_F(Base32Test, encode1) {
     const std::string expect("000G40O40K30E209185GO38E1S8124GJ");
     vector<uint8_t> binary;
     for (uint8_t i = 0; i < 20; i++) {




More information about the bind10-changes mailing list