Parcourir la source

[2107] (unrelated) added operator==() to LabelSequence.

so I can use the LabelSequence objects in EXPECT_EQ().
also fixed a minor error in doxygen comment in equals().
JINMEI Tatuya il y a 12 ans
Parent
commit
3128629ce0
2 fichiers modifiés avec 20 ajouts et 1 suppressions
  1. 11 1
      src/lib/dns/labelsequence.h
  2. 9 0
      src/lib/dns/tests/labelsequence_unittest.cc

+ 11 - 1
src/lib/dns/labelsequence.h

@@ -200,7 +200,7 @@ public:
 
     /// \brief Compares two label sequences for equality.
     ///
-    /// Performs a (optionally case-insensitive) comparison between this
+    /// Performs a (optionally case-sensitive) comparison between this
     /// LabelSequence and another LabelSequence for equality.
     ///
     /// \param other The LabelSequence to compare with
@@ -209,6 +209,16 @@ public:
     ///         and contain the same data.
     bool equals(const LabelSequence& other, bool case_sensitive = false) const;
 
+    /// \brief Compares two label sequences for equality (case ignored).
+    ///
+    /// This is equivalent to <code>this->equals(other)</code>.
+    ///
+    /// The operator version is convenient some specific cases such as in
+    /// unit tests.
+    bool operator==(const LabelSequence& other) const {
+        return (equals(other));
+    }
+
     /// \brief Compares two label sequences.
     ///
     /// Performs a (optionally case-insensitive) comparison between this

+ 9 - 0
src/lib/dns/tests/labelsequence_unittest.cc

@@ -177,6 +177,15 @@ TEST_F(LabelSequenceTest, equals_insensitive) {
     EXPECT_TRUE(ls11.equals(ls12));
 }
 
+// operator==().  This is mostly trivial wrapper, so it should suffice to
+// check some basic cases.
+TEST_F(LabelSequenceTest, operatorEqual) {
+    EXPECT_TRUE(ls1 == ls1);      // self equivalence
+    EXPECT_TRUE(ls1 == LabelSequence(n1)); // equivalent two different objects
+    EXPECT_FALSE(ls1 == ls2);      // non equivalent objects
+    EXPECT_TRUE(ls1 == ls5);       // it's always case insensitive
+}
+
 // Compare tests
 TEST_F(LabelSequenceTest, compare) {
     // "example.org." and "example.org.", case sensitive