[svn] commit: r365 - in /branches/jinmei-dnsmessageapi/src/lib/dns/cpp: unittest_util.cc unittest_util.h

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Dec 15 05:00:19 UTC 2009


Author: jinmei
Date: Tue Dec 15 05:00:19 2009
New Revision: 365

Log:
add a utility for checking name equality

Modified:
    branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.cc
    branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.h

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.cc
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.cc (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.cc Tue Dec 15 05:00:19 2009
@@ -23,9 +23,11 @@
 
 #include <gtest/gtest.h>
 
+#include "name.h"
 #include "unittest_util.h"
 
 using isc::UnitTestUtil;
+using isc::dns::NameComparisonResult;
 
 void
 UnitTestUtil::readWireData(const char* datafile,
@@ -102,3 +104,21 @@
     }
     return ::testing::AssertionSuccess();
 }
+
+::testing::AssertionResult
+UnitTestUtil::matchName(const char* nameexp1, const char* nameexp2,
+                        const isc::dns::Name& name1,
+                        const isc::dns::Name& name2)
+{
+    ::testing::Message msg;
+
+    NameComparisonResult cmpresult = name1.compare(name2);
+    if (cmpresult.getOrder() != 0 ||
+        cmpresult.getRelation() != NameComparisonResult::EQUAL) {
+        msg << "Two names are expected to be equal but not:\n"
+            << "  One: " << name1 << "\n"
+            << "Other: " << name2 << "\n";
+        return (::testing::AssertionFailure(msg));
+    }
+    return ::testing::AssertionSuccess();
+}

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.h
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.h (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/unittest_util.h Tue Dec 15 05:00:19 2009
@@ -20,6 +20,8 @@
 #include <vector>
 #include <string>
 
+#include "name.h"
+
 #include <gtest/gtest.h>
 
 namespace isc {
@@ -41,6 +43,7 @@
 
     ///
     /// Compare len1 bytes of data1 with len2 bytes of data2 as binary data.
+    ///
     /// If they don't match report the point of mismatch in the google test
     /// format.  This method is expected to be used from the EXPECT_PRED_FORMAT4
     /// macro of google test as follows:
@@ -59,6 +62,19 @@
                   const char* dataexp2, const char* lenexp2,
                   const void* data1, size_t len1,
                   const void* data2, size_t len2);
+
+    ///
+    /// Compare two names.
+    ///
+    /// This check method uses \c Name::compare() for comparison, which performs
+    /// deeper checks including the equality of offsets, and should be better
+    /// than EXPECT_EQ, which uses operater==.  Like the \c matchWireData()
+    /// method, the usage is a bit awkward; the caller should use
+    /// \c EXPECT_PRED_FORMAT2.
+    ///
+    static ::testing::AssertionResult
+    matchName(const char* nameexp1, const char* nameexp2,
+              const isc::dns::Name& name1, const isc::dns::Name& name2);
 };
 
 }




More information about the bind10-changes mailing list