]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Tests: improve SBuf::append tests
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Nov 2016 12:51:17 +0000 (01:51 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Nov 2016 12:51:17 +0000 (01:51 +1300)
This adds tests to verify append properly updates
the content of destination SBuf without altering
other critical internal fields (ie no bitwise copy)

src/sbuf/SBuf.h
src/tests/testSBuf.cc

index 4e2780fd269db069012b9daeacbe09d7adfa3a43..7b5e0a038cc509e02a4ea760323cb42dd1de9587 100644 (file)
@@ -125,6 +125,9 @@ public:
 
     ~SBuf();
 
+    /// retrieve the SBuf ID number
+    unsigned int getId() const { return id.value; }
+
     /** Explicit assignment.
      *
      * Current SBuf will share backing store with the assigned one.
index 5bd88235795439457c7b3d86057ad1801b233ec0..23dd6b6396434ed340d9a29951725f41e70cc143 100644 (file)
@@ -151,9 +151,20 @@ testSBuf::testEqualityTest()
 void
 testSBuf::testAppendSBuf()
 {
-    SBuf s1(fox1),s2(fox2);
+    SBuf empty, s1(fox1), s2(fox2);
+    auto oldId1 = s1.getId();
     s1.append(s2);
     CPPUNIT_ASSERT_EQUAL(s1,literal);
+
+    // SBuf docs state that InstanceId does not change
+    CPPUNIT_ASSERT_EQUAL(oldId1, s1.getId());
+
+    // append() has a shortcut for assignment-to-empty
+    // if compiler uses bitwise copy wrongly the ID would copy too
+    auto oldIdEmpty = empty.getId();
+    empty.append(s2);
+    CPPUNIT_ASSERT(empty.getId() != s2.getId());
+    CPPUNIT_ASSERT_EQUAL(oldIdEmpty, empty.getId());
 }
 
 void