]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add unit test for Transaction move/copy
authorCasey Bodley <cbodley@redhat.com>
Wed, 20 Jan 2016 22:17:39 +0000 (17:17 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 22 Jan 2016 16:02:30 +0000 (11:02 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/CMakeLists.txt
src/test/Makefile-server.am
src/test/objectstore/test_transaction.cc [new file with mode: 0644]

index 13bf2070a138054a488e7d7bf8c8ab292c153514..9bceafe9de8f08e0e288cfe0ff01c5723f7c6a21 100644 (file)
@@ -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
index fc4d53dc6414d29adff6dbdd30454f7a8414635d..fbb42e49b234f1f3ff10ff880f431cfc85fbb03f 100644 (file)
@@ -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 (file)
index 0000000..6e12b5d
--- /dev/null
@@ -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 <cbodley@redhat.com>
+ *
+ * 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 <gtest/gtest.h>
+
+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());
+}