Browse Source

added test/documentation for operator= and copy constructor
(trac ticket #47, reviewed by Evan)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@788 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 15 years ago
parent
commit
c2fb21d9b3
2 changed files with 34 additions and 0 deletions
  1. 4 0
      src/lib/dns/cpp/name.h
  2. 30 0
      src/lib/dns/cpp/name_unittest.cc

+ 4 - 0
src/lib/dns/cpp/name.h

@@ -261,7 +261,11 @@ public:
     /// \param buffer A buffer storing the wire format data.
     /// \param downcase Whether to convert upper case alphabets to lower case.
     explicit Name(InputBuffer& buffer, bool downcase = false);
+    ///
+    /// We use the default copy constructor intentionally.
     //@}
+    /// We use the default copy assignment operator intentionally.
+    ///
 
     ///
     /// \name Getter Methods

+ 30 - 0
src/lib/dns/cpp/name_unittest.cc

@@ -266,6 +266,36 @@ TEST_F(NameTest, fromWire)
                                   25).getLabelCount());
 }
 
+TEST_F(NameTest, copyConstruct)
+{
+    Name copy(example_name);
+    EXPECT_EQ(copy, example_name);
+
+    // Check the copied data is valid even after the original is deleted
+    Name* copy2 = new Name(example_name);
+    Name copy3(*copy2);
+    delete copy2;
+    EXPECT_EQ(copy3, example_name);
+}
+
+TEST_F(NameTest, assignment)
+{
+    Name copy(".");
+    copy = example_name;
+    EXPECT_EQ(copy, example_name);
+
+    // Check if the copied data is valid even after the original is deleted
+    Name* copy2 = new Name(example_name);
+    Name copy3(".");
+    copy3 = *copy2;
+    delete copy2;
+    EXPECT_EQ(copy3, example_name);
+
+    // Self assignment
+    copy = copy;
+    EXPECT_EQ(copy, example_name);
+}
+
 TEST_F(NameTest, toText)
 {
     // tests derived from BIND9