]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Improved testAppendSBuf to actually test SBuf::append() optimization.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Nov 2016 22:04:34 +0000 (16:04 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Nov 2016 22:04:34 +0000 (16:04 -0600)
... 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.

src/tests/testSBuf.cc

index 4f29d2955095dfcaa306022f6ce22bd78834bebb..e80ca60be2b03e5c0090331fc48740901267c538 100644 (file)
@@ -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