]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/bufferlist: Avoid false-positive tests 7955/head
authorErwan Velu <erwan@redhat.com>
Wed, 24 Feb 2016 16:12:19 +0000 (17:12 +0100)
committerErwan Velu <erwan@redhat.com>
Mon, 7 Mar 2016 09:36:06 +0000 (10:36 +0100)
The current code is using the length of ptr to determine if the string is
correct.

As 'ptr' is a copy of the original 'str', it sounds safer to compare against the
original string size of the consider the actual size of the string : if 'ptr' is
shorter than 'str', the actual code will PASS while 'ptr' is broken.

This patch offer to use the same testing logic as per "ptr(const ptr& p,
unsigned o, unsigned l)" test by using a memcmp against the original string
length.

Signed-off-by: Erwan Velu <erwan@redhat.com>
src/test/bufferlist.cc

index a6120fd0614141e7583f1f71cf3c1b5456fa72b6..8be65f60896da66390836b4961d9939d84ad900c 100644 (file)
@@ -478,7 +478,7 @@ TEST(BufferPtr, constructors) {
     bufferptr ptr(std::move(original));
     EXPECT_TRUE(ptr.have_raw());
     EXPECT_FALSE(original.have_raw());
-    EXPECT_EQ(str.compare(0, str.size(), ptr.c_str(), ptr.length()), 0);
+    EXPECT_EQ(0, ::memcmp(str.c_str(), ptr.c_str(), len));
     EXPECT_EQ(1, ptr.raw_nref());
   }
 }