From: Alex Rousskov Date: Fri, 4 Nov 2016 22:04:34 +0000 (-0600) Subject: Improved testAppendSBuf to actually test SBuf::append() optimization. X-Git-Tag: SQUID_4_0_17~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5534a101594a15ebe2ac67ceea7ad56b0e7cf4d4;p=thirdparty%2Fsquid.git Improved testAppendSBuf to actually test SBuf::append() optimization. ... rather than to test SBuf::id preservation across assignments [currently used by that optimization]. Trunk r14911 talks about bitwise object copy but making sure that SBuf has a working assignment operator is an issue unrelated to append() and its optimization. Besides, it is not really the prohibited by C++ bitwise copy that we might worry about but the default member-wise assignment that we may forget to customize. --- diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index 4f29d29550..e80ca60be2 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -151,20 +151,22 @@ testSBuf::testEqualityTest() void testSBuf::testAppendSBuf() { - SBuf empty, s1(fox1), s2(fox2); - auto oldId1 = s1.getId(); - s1.append(s2); - CPPUNIT_ASSERT_EQUAL(s1,literal); + const SBuf appendix(fox1); + const char * const rawAppendix = appendix.rawContent(); - // SBuf docs state that InstanceId does not change - CPPUNIT_ASSERT_EQUAL(oldId1, s1.getId()); + // check whether the optimization that prevents copying when append()ing to + // default-constructed SBuf actually works + SBuf s0; + s0.append(appendix); + CPPUNIT_ASSERT_EQUAL(s0.rawContent(), appendix.rawContent()); + CPPUNIT_ASSERT_EQUAL(s0, appendix); - // 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()); + // paranoid: check that the above code can actually detect copies + SBuf s1(fox1); + s1.append(appendix); + CPPUNIT_ASSERT(s1.rawContent() != appendix.rawContent()); + CPPUNIT_ASSERT(s1 != appendix); + CPPUNIT_ASSERT_EQUAL(rawAppendix, appendix.rawContent()); } void