From: JINMEI Tatuya Date: Mon, 20 Aug 2012 23:59:08 +0000 (-0700) Subject: [2107] (unrelated) added operator==() to LabelSequence. X-Git-Tag: trac2351_base~109^2~1^2~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3128629ce0cf4ae59b249e5fb4cbc0873b7ace7f;p=thirdparty%2Fkea.git [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(). --- diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h index 186bda6ff8..f6dac20d5d 100644 --- a/src/lib/dns/labelsequence.h +++ b/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 this->equals(other). + /// + /// 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 diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc index e8e2846d7e..41f4b1361a 100644 --- a/src/lib/dns/tests/labelsequence_unittest.cc +++ b/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