From: Greg Farnum Date: Wed, 26 Jun 2013 23:28:22 +0000 (-0700) Subject: test: switch the cls_replica_log tests to use a test fixture X-Git-Tag: v0.67-rc3~47^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f4675dcb545b9a1cdd22f9a64149e898fbd99a2f;p=ceph.git test: switch the cls_replica_log tests to use a test fixture Instead of the silly macros. Signed-off-by: Greg Farnum --- diff --git a/src/test/cls_replica_log/test_cls_replica_log.cc b/src/test/cls_replica_log/test_cls_replica_log.cc index eabe0b3860d..8c204caef04 100644 --- a/src/test/cls_replica_log/test_cls_replica_log.cc +++ b/src/test/cls_replica_log/test_cls_replica_log.cc @@ -14,34 +14,42 @@ #include "cls/replica_log/cls_replica_log_client.h" #include "cls/replica_log/cls_replica_log_types.h" -#define SETUP_DATA \ - librados::Rados rados; \ - librados::IoCtx ioctx; \ - string pool_name = get_temp_pool_name(); \ - ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); \ - ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); \ - string oid = "obj"; \ - ASSERT_EQ(0, ioctx.create(oid, true)); - -#define ADD_MARKER \ - string entity = "tester_entity"; \ - string marker = "tester_marker1"; \ - utime_t time; \ - time.set_from_double(10); \ - list > entries; \ - entries.push_back(make_pair("tester_obj1", time)); \ - time.set_from_double(20); \ - cls_replica_log_progress_marker progress; \ - cls_replica_log_prepare_marker(progress, entity, marker, time, &entries); \ - librados::ObjectWriteOperation opw; \ - cls_replica_log_update_bound(opw, progress); \ - ASSERT_EQ(0, ioctx.operate(oid, &opw)); - -TEST(cls_replica_log, test_set_get_marker) +class cls_replica_log_Test : public ::testing::Test { +public: + librados::Rados rados; + librados::IoCtx ioctx; + string pool_name; + string oid; + string entity; + string marker; + utime_t time; + list > entries; + cls_replica_log_progress_marker progress; + + void SetUp() { + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); + ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); + oid = "obj"; + ASSERT_EQ(0, ioctx.create(oid, true)); + } + + void add_marker() { + entity = "tester_entity"; + marker = "tester_marker1"; + time.set_from_double(10); + entries.push_back(make_pair("tester_obj1", time)); + time.set_from_double(20); + cls_replica_log_prepare_marker(progress, entity, marker, time, &entries); + librados::ObjectWriteOperation opw; + cls_replica_log_update_bound(opw, progress); + ASSERT_EQ(0, ioctx.operate(oid, &opw)); + } +}; + +TEST_F(cls_replica_log_Test, test_set_get_marker) { - SETUP_DATA - - ADD_MARKER + add_marker(); string reply_position_marker; utime_t reply_time; @@ -66,11 +74,9 @@ TEST(cls_replica_log, test_set_get_marker) ASSERT_EQ("tester_obj1", response_item_list.front().first); } -TEST(cls_replica_log, test_bad_update) +TEST_F(cls_replica_log_Test, test_bad_update) { - SETUP_DATA - - ADD_MARKER + add_marker(); time.set_from_double(15); cls_replica_log_progress_marker bad_marker; @@ -80,22 +86,18 @@ TEST(cls_replica_log, test_bad_update) ASSERT_EQ(-EINVAL, ioctx.operate(oid, &badw)); } -TEST(cls_replica_log, test_bad_delete) +TEST_F(cls_replica_log_Test, test_bad_delete) { - SETUP_DATA - - ADD_MARKER + add_marker(); librados::ObjectWriteOperation badd; cls_replica_log_delete_bound(badd, entity); ASSERT_EQ(-ENOTEMPTY, ioctx.operate(oid, &badd)); } -TEST(cls_replica_log, test_good_delete) +TEST_F(cls_replica_log_Test, test_good_delete) { - SETUP_DATA - - ADD_MARKER + add_marker(); librados::ObjectWriteOperation opc; progress.items.clear(); @@ -113,10 +115,8 @@ TEST(cls_replica_log, test_good_delete) ASSERT_EQ((unsigned)0, return_progress_list.size()); } -TEST(cls_replica_log, test_bad_get) +TEST_F(cls_replica_log_Test, test_bad_get) { - SETUP_DATA - string reply_position_marker; utime_t reply_time; list return_progress_list; @@ -125,11 +125,9 @@ TEST(cls_replica_log, test_bad_get) reply_time, return_progress_list)); } -TEST(cls_replica_log, test_double_delete) +TEST_F(cls_replica_log_Test, test_double_delete) { - SETUP_DATA - - ADD_MARKER + add_marker(); librados::ObjectWriteOperation opc; progress.items.clear();