[svn] commit: r381 - in /branches/jinmei-dnsmessageapi/src/lib/dns/cpp: name.cc name.h name_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Dec 18 03:47:52 UTC 2009


Author: jinmei
Date: Fri Dec 18 03:47:52 2009
New Revision: 381

Log:
added <=, <, >=, >

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

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc Fri Dec 18 03:47:52 2009
@@ -520,6 +520,30 @@
 }
 
 bool
+Name::leq(const Name& other) const
+{
+    return (compare(other).getOrder() <= 0);
+}
+
+bool
+Name::geq(const Name& other) const
+{
+    return (compare(other).getOrder() >= 0);
+}
+
+bool
+Name::lthan(const Name& other) const
+{
+    return (compare(other).getOrder() < 0);
+}
+
+bool
+Name::gthan(const Name& other) const
+{
+    return (compare(other).getOrder() > 0);
+}
+
+bool
 Name::isWildcard() const
 {
     return (length_ >= 2 && ndata_[0] == 1 && ndata_[1] == '*'); 

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h Fri Dec 18 03:47:52 2009
@@ -313,46 +313,46 @@
     ///
     /// The comparison is based on the result of the \c compare() method.
     /// \param other the <code>Name</code> object to compare against.
-    /// \return true if <code>compare(other).get_order() <= 0</code>;
+    /// \return true if <code>compare(other).getOrder() <= 0</code>;
     /// otherwise false.
     bool leq(const Name& other) const;
 
     /// Same as leq()
-    bool operator<=(const Name& other) const;
+    bool operator<=(const Name& other) const { return (leq(other)); }
 
     /// \brief Greater-than or equal comparison for Name against
     /// <code>other</code>
     ///
     /// The comparison is based on the result of the \c compare() method.
     /// \param other the <code>Name</code> object to compare against.
-    /// \return true if <code>compare(other).get_order() >= 0</code>;
+    /// \return true if <code>compare(other).getOrder() >= 0</code>;
     /// otherwise false.
     bool geq(const Name& other) const;
 
     /// Same as geq()
-    bool operator>=(const Name& other) const;
+    bool operator>=(const Name& other) const { return (geq(other)); }
 
     /// \brief Less-than comparison for Name against <code>other</code>
     ///
     /// The comparison is based on the result of the \c compare() method.
     /// \param other the <code>Name</code> object to compare against.
-    /// \return true if <code>compare(other).get_order() < 0</code>;
+    /// \return true if <code>compare(other).getOrder() < 0</code>;
     /// otherwise false.
     bool lthan(const Name& other) const;
 
     /// Same as lthan()
-    bool operator<(const Name& other) const;
+    bool operator<(const Name& other) const { return (lthan(other)); }
 
     /// \brief Greater-than comparison for Name against <code>other</code>
     ///
     /// The comparison is based on the result of the \c compare() method.
     /// \param other the <code>Name</code> object to compare against.
-    /// \return true if <code>compare(other).get_order() > 0</code>;
+    /// \return true if <code>compare(other).getOrder() > 0</code>;
     /// otherwise false.
     bool gthan(const Name& other) const;
 
     /// Same as gthan()
-    bool operator>(const Name& other) const;
+    bool operator>(const Name& other) const { return (gthan(other)); }
     //@}
 
     ///

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc Fri Dec 18 03:47:52 2009
@@ -39,11 +39,15 @@
 protected:
     NameTest() : example_name("www.example.com"),
                  example_name_upper("WWW.EXAMPLE.COM"),
+                 small_name("aaa.example.com"),
+                 large_name("zzz.example.com"),
                  buffer_actual(0), buffer_expected(0)
     {}
 
-    Name example_name;
-    Name example_name_upper;
+    const Name example_name;
+    Name example_name_upper;    // this will be modified and cannot be const
+    const Name small_name;
+    const Name large_name;
     OutputBuffer buffer_actual, buffer_expected;
 
     static const size_t MAX_WIRE = Name::MAX_WIRE;
@@ -402,4 +406,60 @@
     compareInWireFormat(example_name_upper, example_name);
     
 }
-}
+
+//
+// The following set of tests confirm the result of <=, <, >=, >
+// The test logic is simple, and all tests are just straightforward variations
+// of the first one.
+//
+TEST_F(NameTest, leq)
+{
+    // small <= large is true
+    EXPECT_TRUE(small_name.leq(large_name));
+    EXPECT_TRUE(small_name <= large_name);
+
+    // small <= small is true
+    EXPECT_TRUE(small_name.leq(small_name));
+    EXPECT_TRUE(small_name <= small_name);
+
+    // large <= small is false
+    EXPECT_FALSE(large_name.leq(small_name));
+    EXPECT_FALSE(large_name <= small_name);
+}
+
+TEST_F(NameTest, geq)
+{
+    EXPECT_TRUE(large_name.geq(small_name));
+    EXPECT_TRUE(large_name >= small_name);
+
+    EXPECT_TRUE(large_name.geq(large_name));
+    EXPECT_TRUE(large_name >= large_name);
+
+    EXPECT_FALSE(small_name.geq(large_name));
+    EXPECT_FALSE(small_name >= large_name);
+}
+
+TEST_F(NameTest, lthan)
+{
+    EXPECT_TRUE(small_name.lthan(large_name));
+    EXPECT_TRUE(small_name < large_name);
+
+    EXPECT_FALSE(small_name.lthan(small_name));
+    EXPECT_FALSE(small_name < small_name);
+
+    EXPECT_FALSE(large_name.lthan(small_name));
+    EXPECT_FALSE(large_name < small_name);
+}
+
+TEST_F(NameTest, gthan)
+{
+    EXPECT_TRUE(large_name.gthan(small_name));
+    EXPECT_TRUE(large_name > small_name);
+
+    EXPECT_FALSE(large_name.gthan(large_name));
+    EXPECT_FALSE(large_name > large_name);
+
+    EXPECT_FALSE(small_name.gthan(large_name));
+    EXPECT_FALSE(small_name > large_name);
+}
+}




More information about the bind10-changes mailing list