From: Casey Bodley Date: Wed, 20 Jan 2016 22:17:39 +0000 (-0500) Subject: test: add unit test for Transaction move/copy X-Git-Tag: v10.0.4~177^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9e37a87ac40bb24ba41453e2c5da9294db91047d;p=ceph.git test: add unit test for Transaction move/copy Signed-off-by: Casey Bodley --- diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 13bf2070a138..9bceafe9de8f 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -2160,6 +2160,12 @@ target_link_libraries(test_objectstore_workloadgen ${CMAKE_DL_LIBS} ) +# test_transaction +add_executable(unittest_transaction objectstore/test_transaction.cc) +add_test(unittest_transaction unittest_transaction) +set_target_properties(unittest_transaction PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}) +target_link_libraries(unittest_transaction os common ${UNITTEST_LIBS}) + #test_filestore add_executable(test_filestore filestore/TestFileStore.cc) set_target_properties(test_filestore PROPERTIES COMPILE_FLAGS diff --git a/src/test/Makefile-server.am b/src/test/Makefile-server.am index fc4d53dc6414..fbb42e49b234 100644 --- a/src/test/Makefile-server.am +++ b/src/test/Makefile-server.am @@ -94,6 +94,11 @@ ceph_test_filestore_idempotent_sequence_SOURCES = \ ceph_test_filestore_idempotent_sequence_LDADD = $(LIBOS) $(CEPH_GLOBAL) bin_DEBUGPROGRAMS += ceph_test_filestore_idempotent_sequence +unittest_transaction_SOURCES = test/objectstore/test_transaction.cc +unittest_transaction_LDADD = $(LIBOS) $(UNITTEST_LDADD) $(CEPH_GLOBAL) +unittest_transaction_CXXFLAGS = $(UNITTEST_CXXFLAGS) +check_TESTPROGRAMS += unittest_transaction + ceph_xattr_bench_SOURCES = test/xattr_bench.cc ceph_xattr_bench_LDADD = $(LIBOS) $(UNITTEST_LDADD) $(CEPH_GLOBAL) ceph_xattr_bench_CXXFLAGS = $(UNITTEST_CXXFLAGS) diff --git a/src/test/objectstore/test_transaction.cc b/src/test/objectstore/test_transaction.cc new file mode 100644 index 000000000000..6e12b5da299f --- /dev/null +++ b/src/test/objectstore/test_transaction.cc @@ -0,0 +1,75 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 Casey Bodley + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "os/ObjectStore.h" +#include + +TEST(Transaction, MoveConstruct) +{ + auto a = ObjectStore::Transaction{}; + a.nop(); + ASSERT_FALSE(a.empty()); + + // move-construct in b + auto b = std::move(a); + ASSERT_TRUE(a.empty()); + ASSERT_FALSE(b.empty()); +} + +TEST(Transaction, MoveAssign) +{ + auto a = ObjectStore::Transaction{}; + a.nop(); + ASSERT_FALSE(a.empty()); + + auto b = ObjectStore::Transaction{}; + b = std::move(a); // move-assign to b + ASSERT_TRUE(a.empty()); + ASSERT_FALSE(b.empty()); +} + +TEST(Transaction, CopyConstruct) +{ + auto a = ObjectStore::Transaction{}; + a.nop(); + ASSERT_FALSE(a.empty()); + + auto b = a; // copy-construct in b + ASSERT_FALSE(a.empty()); + ASSERT_FALSE(b.empty()); +} + +TEST(Transaction, CopyAssign) +{ + auto a = ObjectStore::Transaction{}; + a.nop(); + ASSERT_FALSE(a.empty()); + + auto b = ObjectStore::Transaction{}; + b = a; // copy-assign to b + ASSERT_FALSE(a.empty()); + ASSERT_FALSE(b.empty()); +} + +TEST(Transaction, Swap) +{ + auto a = ObjectStore::Transaction{}; + a.nop(); + ASSERT_FALSE(a.empty()); + + auto b = ObjectStore::Transaction{}; + std::swap(a, b); // swap a and b + ASSERT_TRUE(a.empty()); + ASSERT_FALSE(b.empty()); +}