From: Amos Jeffries Date: Thu, 3 Nov 2016 12:51:17 +0000 (+1300) Subject: Tests: improve SBuf::append tests X-Git-Tag: SQUID_4_0_17~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37ef8293592125608d704e4de5e8cdc5879f914d;p=thirdparty%2Fsquid.git Tests: improve SBuf::append tests This adds tests to verify append properly updates the content of destination SBuf without altering other critical internal fields (ie no bitwise copy) --- diff --git a/src/sbuf/SBuf.h b/src/sbuf/SBuf.h index 4e2780fd26..7b5e0a038c 100644 --- a/src/sbuf/SBuf.h +++ b/src/sbuf/SBuf.h @@ -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. diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index 5bd8823579..23dd6b6396 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -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