From: Casey Bodley Date: Fri, 31 Jul 2015 17:36:26 +0000 (-0400) Subject: c++11: fix shared_ptr conversions to bool X-Git-Tag: v9.1.0~419^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=511106e353846b9ac7b7105ff9b1915728ca7acd;p=ceph.git c++11: fix shared_ptr conversions to bool operator bool() is marked as explicit, which prevents it from being used directly in gtest macros Signed-off-by: Casey Bodley --- diff --git a/src/test/common/test_shared_cache.cc b/src/test/common/test_shared_cache.cc index b9f53771f90a..f54a2a36a6b5 100644 --- a/src/test/common/test_shared_cache.cc +++ b/src/test/common/test_shared_cache.cc @@ -28,8 +28,6 @@ #include "global/global_init.h" #include -using namespace std::tr1; - class SharedLRUTest : public SharedLRU { public: Mutex &get_lock() { return lock; } @@ -141,28 +139,28 @@ TEST_F(SharedLRU_all, lookup) { unsigned int key = 1; { int value = 2; - ASSERT_TRUE(cache.add(key, new int(value))); - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.add(key, new int(value)).get()); + ASSERT_TRUE(cache.lookup(key).get()); ASSERT_EQ(value, *cache.lookup(key)); } - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); } TEST_F(SharedLRU_all, lookup_or_create) { SharedLRUTest cache; { int value = 2; unsigned int key = 1; - ASSERT_TRUE(cache.add(key, new int(value))); - ASSERT_TRUE(cache.lookup_or_create(key)); + ASSERT_TRUE(cache.add(key, new int(value)).get()); + ASSERT_TRUE(cache.lookup_or_create(key).get()); ASSERT_EQ(value, *cache.lookup(key)); } { unsigned int key = 2; - ASSERT_TRUE(cache.lookup_or_create(key)); + ASSERT_TRUE(cache.lookup_or_create(key).get()); ASSERT_EQ(0, *cache.lookup(key)); } - ASSERT_TRUE(cache.lookup(1)); - ASSERT_TRUE(cache.lookup(2)); + ASSERT_TRUE(cache.lookup(1).get()); + ASSERT_TRUE(cache.lookup(2).get()); } TEST_F(SharedLRU_all, wait_lookup) { @@ -207,7 +205,7 @@ TEST_F(SharedLRU_all, wait_lookup_or_create) { ASSERT_TRUE(wait_for(cache, 1)); EXPECT_EQ(value, *t.ptr); // waiting on a key does not block lookups on other keys - EXPECT_TRUE(cache.lookup_or_create(key + 12345)); + EXPECT_TRUE(cache.lookup_or_create(key + 12345).get()); { Mutex::Locker l(cache.get_lock()); cache.get_weak_refs().erase(key); @@ -226,8 +224,8 @@ TEST_F(SharedLRU_all, lower_bound) { ASSERT_FALSE(cache.lower_bound(key)); int value = 2; - ASSERT_TRUE(cache.add(key, new int(value))); - ASSERT_TRUE(cache.lower_bound(key)); + ASSERT_TRUE(cache.add(key, new int(value)).get()); + ASSERT_TRUE(cache.lower_bound(key).get()); EXPECT_EQ(value, *cache.lower_bound(key)); } } @@ -239,7 +237,7 @@ TEST_F(SharedLRU_all, wait_lower_bound) { unsigned int other_key = key + 1; int other_value = value + 1; - ASSERT_TRUE(cache.add(other_key, new int(other_value))); + ASSERT_TRUE(cache.add(other_key, new int(other_value)).get()); { shared_ptr ptr(new int); @@ -252,7 +250,7 @@ TEST_F(SharedLRU_all, wait_lower_bound) { ASSERT_TRUE(wait_for(cache, 1)); EXPECT_FALSE(t.ptr); // waiting on a key does not block getting lower_bound on other keys - EXPECT_TRUE(cache.lower_bound(other_key)); + EXPECT_TRUE(cache.lower_bound(other_key).get()); { Mutex::Locker l(cache.get_lock()); cache.get_weak_refs().erase(key); @@ -260,7 +258,7 @@ TEST_F(SharedLRU_all, wait_lower_bound) { } ASSERT_TRUE(wait_for(cache, 0)); t.join(); - EXPECT_TRUE(t.ptr); + EXPECT_TRUE(t.ptr.get()); } TEST_F(SharedLRU_all, get_next) { @@ -322,14 +320,14 @@ TEST_F(SharedLRU_all, clear) { ceph::shared_ptr ptr = cache.add(key, new int(value)); ASSERT_EQ(value, *cache.lookup(key)); } - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); cache.clear(key); ASSERT_FALSE(cache.lookup(key)); { ceph::shared_ptr ptr = cache.add(key, new int(value)); } - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); cache.clear(key); ASSERT_FALSE(cache.lookup(key)); } @@ -341,14 +339,14 @@ TEST_F(SharedLRU_all, clear_all) { ceph::shared_ptr ptr = cache.add(key, new int(value)); ASSERT_EQ(value, *cache.lookup(key)); } - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); cache.clear(); ASSERT_FALSE(cache.lookup(key)); ceph::shared_ptr ptr2 = cache.add(key, new int(value)); - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); cache.clear(); - ASSERT_TRUE(cache.lookup(key)); + ASSERT_TRUE(cache.lookup(key).get()); ASSERT_FALSE(cache.empty()); } @@ -379,12 +377,12 @@ TEST(SharedCache_all, lru) { ASSERT_FALSE(existed); } - ASSERT_TRUE(cache.lookup(0)); + ASSERT_TRUE(cache.lookup(0).get()); ASSERT_EQ(0, *cache.lookup(0)); ASSERT_FALSE(cache.lookup(SIZE-1)); ASSERT_FALSE(cache.lookup(SIZE)); - ASSERT_TRUE(cache.lookup(SIZE+1)); + ASSERT_TRUE(cache.lookup(SIZE+1).get()); ASSERT_EQ((int)SIZE+1, *cache.lookup(SIZE+1)); cache.purge(0); @@ -392,7 +390,7 @@ TEST(SharedCache_all, lru) { shared_ptr ptr2 = cache.add(0, new int(0), &existed); ASSERT_FALSE(ptr == ptr2); ptr = shared_ptr(); - ASSERT_TRUE(cache.lookup(0)); + ASSERT_TRUE(cache.lookup(0).get()); } int main(int argc, char **argv) { diff --git a/src/test/common/test_sharedptr_registry.cc b/src/test/common/test_sharedptr_registry.cc index 9c9e89f9cf78..7b06b7e163f6 100644 --- a/src/test/common/test_sharedptr_registry.cc +++ b/src/test/common/test_sharedptr_registry.cc @@ -27,8 +27,6 @@ #include "global/global_init.h" #include -using namespace std::tr1; - class SharedPtrRegistryTest : public SharedPtrRegistry { public: Mutex &get_lock() { return lock; } @@ -136,11 +134,11 @@ TEST_F(SharedPtrRegistry_all, wait_lookup_or_create) { ASSERT_TRUE(wait_for(registry, 1)); EXPECT_FALSE(t.ptr); // waiting on a key does not block lookups on other keys - EXPECT_TRUE(registry.lookup_or_create(key + 12345)); + EXPECT_TRUE(registry.lookup_or_create(key + 12345).get()); registry.remove(key); ASSERT_TRUE(wait_for(registry, 0)); t.join(); - EXPECT_TRUE(t.ptr); + EXPECT_TRUE(t.ptr.get()); } { unsigned int key = 2; @@ -160,13 +158,13 @@ TEST_F(SharedPtrRegistry_all, wait_lookup_or_create) { int other_value = value + 1; unsigned int other_key = key + 1; shared_ptr ptr = registry.lookup_or_create(other_key, other_value); - EXPECT_TRUE(ptr); + EXPECT_TRUE(ptr.get()); EXPECT_EQ(other_value, *ptr); } registry.remove(key); ASSERT_TRUE(wait_for(registry, 0)); t.join(); - EXPECT_TRUE(t.ptr); + EXPECT_TRUE(t.ptr.get()); EXPECT_EQ(value, *t.ptr); } } @@ -320,7 +318,7 @@ TEST_F(SharedPtrRegistry_destructor, destructor) { { shared_ptr a = registry.lookup_or_create(key); EXPECT_EQ(NO, died); - EXPECT_TRUE(a); + EXPECT_TRUE(a.get()); } EXPECT_EQ(YES, died); EXPECT_FALSE(registry.lookup(key)); diff --git a/src/test/erasure-code/TestErasureCodePlugin.cc b/src/test/erasure-code/TestErasureCodePlugin.cc index e8c594fc8e6f..ee620a280b43 100644 --- a/src/test/erasure-code/TestErasureCodePlugin.cc +++ b/src/test/erasure-code/TestErasureCodePlugin.cc @@ -92,7 +92,7 @@ TEST_F(ErasureCodePluginRegistryTest, all) &erasure_code, &cerr)); EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("example", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); ErasureCodePlugin *plugin = 0; { Mutex::Locker l(instance.lock); diff --git a/src/test/erasure-code/TestErasureCodePluginIsa.cc b/src/test/erasure-code/TestErasureCodePluginIsa.cc index e730b4001541..a07b387f1584 100644 --- a/src/test/erasure-code/TestErasureCodePluginIsa.cc +++ b/src/test/erasure-code/TestErasureCodePluginIsa.cc @@ -43,7 +43,7 @@ TEST(ErasureCodePlugin, factory) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("isa", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); } } diff --git a/src/test/erasure-code/TestErasureCodePluginJerasure.cc b/src/test/erasure-code/TestErasureCodePluginJerasure.cc index ad456c0235f9..4c4ed1ed975b 100644 --- a/src/test/erasure-code/TestErasureCodePluginJerasure.cc +++ b/src/test/erasure-code/TestErasureCodePluginJerasure.cc @@ -55,7 +55,7 @@ TEST(ErasureCodePlugin, factory) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("jerasure", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); } } @@ -201,7 +201,7 @@ TEST(ErasureCodePlugin, sse) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("jerasure_" + *sse_variant, profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); // // encode diff --git a/src/test/erasure-code/TestErasureCodePluginLrc.cc b/src/test/erasure-code/TestErasureCodePluginLrc.cc index fea576c54608..c6909e6e1dd8 100644 --- a/src/test/erasure-code/TestErasureCodePluginLrc.cc +++ b/src/test/erasure-code/TestErasureCodePluginLrc.cc @@ -34,7 +34,7 @@ TEST(ErasureCodePlugin, factory) ErasureCodeInterfaceRef erasure_code; EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("lrc", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); } int main(int argc, char **argv) diff --git a/src/test/erasure-code/TestErasureCodePluginShec.cc b/src/test/erasure-code/TestErasureCodePluginShec.cc index 405aca2330a6..da3ed67d3bf5 100644 --- a/src/test/erasure-code/TestErasureCodePluginShec.cc +++ b/src/test/erasure-code/TestErasureCodePluginShec.cc @@ -36,7 +36,7 @@ TEST(ErasureCodePlugin, factory) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("shec", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); } const char *techniques[] = { "single", @@ -50,7 +50,7 @@ TEST(ErasureCodePlugin, factory) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("shec", profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); } } @@ -197,7 +197,7 @@ TEST(ErasureCodePlugin, sse) EXPECT_FALSE(erasure_code); EXPECT_EQ(0, instance.factory("shec_" + *sse_variant, profile, &erasure_code, &cerr)); - EXPECT_TRUE(erasure_code); + EXPECT_TRUE(erasure_code.get()); // // encode