Parcourir la source

Merge branch 'trac3263_2'

Mukund Sivaraman il y a 11 ans
Parent
commit
b26f6251fc
2 fichiers modifiés avec 17 ajouts et 2 suppressions
  1. 7 0
      src/lib/dns/rrset.h
  2. 10 2
      src/lib/dns/tests/rrset_unittest.cc

+ 7 - 0
src/lib/dns/rrset.h

@@ -376,6 +376,13 @@ public:
     /// Still, this version would offer a more intuitive interface and is
     /// provided as such.
     ///
+    /// NOTE: Because a new Rdata object is constructed, this method can
+    /// throw a std::bad_cast exception if this RRset's class is NONE,
+    /// or if some other error occurs. If you want to be able to add
+    /// RDATA to an RRset whose class is NONE, please use the other
+    /// variant of \c addRdata() which accepts a \c ConstRdataPtr
+    /// argument.
+    ///
     /// \param rdata A reference to a \c rdata::RdataPtr (derived) class
     /// object, a copy of which is to be added to the \c RRset.
     virtual void addRdata(const rdata::Rdata& rdata) = 0;

+ 10 - 2
src/lib/dns/tests/rrset_unittest.cc

@@ -157,14 +157,22 @@ TEST_F(RRsetTest, addRdataPtr) {
     rrset_a_empty.addRdata(createRdata(rrset_a_empty.getType(),
                                        rrset_a_empty.getClass(),
                                        "192.0.2.2"));
-
     addRdataTestCommon(rrset_a);
+}
 
+TEST_F(RRsetTest, addRdataPtrMismatched) {
     // Pointer version of addRdata() doesn't type check and does allow to
     //add a different type of Rdata as a result.
+
+    // Type mismatch
     rrset_a_empty.addRdata(createRdata(RRType::NS(), RRClass::IN(),
                                        "ns.example.com."));
-    EXPECT_EQ(3, rrset_a_empty.getRdataCount());
+    EXPECT_EQ(1, rrset_a_empty.getRdataCount());
+
+    // Class mismatch
+    rrset_ch_txt.addRdata(createRdata(RRType::TXT(), RRClass::IN(),
+                                      "Test String"));
+    EXPECT_EQ(1, rrset_ch_txt.getRdataCount());
 }
 
 TEST_F(RRsetTest, iterator) {