transaction_t -> gmock

This commit is contained in:
Joe Thornber 2013-03-22 15:19:40 +00:00
parent 2ec15f74b8
commit f2a388dbab
2 changed files with 27 additions and 32 deletions

View File

@ -37,12 +37,6 @@ unit-test: $(TEST_PROGRAMS)
unit-tests/run_list_t: unit-tests/run_list_t.o $(OBJECTS) unit-tests/run_list_t: unit-tests/run_list_t.o $(OBJECTS)
g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT) g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT)
unit-tests/space_map_disk_t: unit-tests/space_map_disk_t.o $(OBJECTS)
g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT)
unit-tests/transaction_manager_t: unit-tests/transaction_manager_t.o $(OBJECTS)
g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT)
unit-tests/metadata_t: unit-tests/metadata_t.o $(OBJECTS) unit-tests/metadata_t: unit-tests/metadata_t.o $(OBJECTS)
g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT) g++ $(CXXFLAGS) $(INCLUDES) -o $@ $+ $(LIBS) $(LIBEXPAT)
@ -79,7 +73,8 @@ MOCK_SOURCE=\
unit-tests/buffer_t.cc \ unit-tests/buffer_t.cc \
unit-tests/cache_t.cc \ unit-tests/cache_t.cc \
unit-tests/endian_t.cc \ unit-tests/endian_t.cc \
unit-tests/space_map_t.cc unit-tests/space_map_t.cc \
unit-tests/transaction_manager_t.cc
# .gmo files are plain .o files, only they've been built with gmock # .gmo files are plain .o files, only they've been built with gmock
# include paths. # include paths.

View File

@ -16,15 +16,13 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "gmock/gmock.h"
#include "persistent-data/transaction_manager.h" #include "persistent-data/transaction_manager.h"
#include "persistent-data/space-maps/core.h" #include "persistent-data/space-maps/core.h"
#define BOOST_TEST_MODULE TransactionManagerTests
#include <boost/test/included/unit_test.hpp>
using namespace std; using namespace std;
using namespace boost;
using namespace persistent_data; using namespace persistent_data;
using namespace testing;
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -54,13 +52,13 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
BOOST_AUTO_TEST_CASE(commit_succeeds) TEST(TransactionManagerTests, commit_succeeds)
{ {
transaction_manager::ptr tm = create_tm(); transaction_manager::ptr tm = create_tm();
tm->begin(0, noop_validator()); tm->begin(0, noop_validator());
} }
BOOST_AUTO_TEST_CASE(shadowing) TEST(TransactionManagerTests, shadowing)
{ {
transaction_manager::ptr tm = create_tm(); transaction_manager::ptr tm = create_tm();
block_manager<>::write_ref superblock = tm->begin(0, noop_validator()); block_manager<>::write_ref superblock = tm->begin(0, noop_validator());
@ -72,27 +70,27 @@ BOOST_AUTO_TEST_CASE(shadowing)
{ {
pair<write_ref, bool> p = tm->shadow(1, noop_validator()); pair<write_ref, bool> p = tm->shadow(1, noop_validator());
b = p.first.get_location(); b = p.first.get_location();
BOOST_CHECK(b != 1); ASSERT_THAT(b, Ne(1u));
BOOST_CHECK(!p.second); ASSERT_FALSE(p.second);
BOOST_CHECK(sm->get_count(1) == 0); ASSERT_THAT(sm->get_count(1), Eq(0u));
} }
{ {
pair<write_ref, bool> p = tm->shadow(b, noop_validator()); pair<write_ref, bool> p = tm->shadow(b, noop_validator());
BOOST_CHECK(p.first.get_location() == b); ASSERT_THAT(p.first.get_location(), Eq(b));
BOOST_CHECK(!p.second); ASSERT_FALSE(p.second);
} }
sm->inc(b); sm->inc(b);
{ {
pair<write_ref, bool> p = tm->shadow(b, noop_validator()); pair<write_ref, bool> p = tm->shadow(b, noop_validator());
BOOST_CHECK(p.first.get_location() != b); ASSERT_THAT(p.first.get_location(), Ne(b));
BOOST_CHECK(p.second); ASSERT_TRUE(p.second);
} }
} }
BOOST_AUTO_TEST_CASE(multiple_shadowing) TEST(TransactionManagerTests, multiple_shadowing)
{ {
transaction_manager::ptr tm = create_tm(); transaction_manager::ptr tm = create_tm();
space_map::ptr sm = tm->get_sm(); space_map::ptr sm = tm->get_sm();
@ -103,8 +101,8 @@ BOOST_AUTO_TEST_CASE(multiple_shadowing)
write_ref superblock = tm->begin(0, noop_validator()); write_ref superblock = tm->begin(0, noop_validator());
pair<write_ref, bool> p = tm->shadow(1, noop_validator()); pair<write_ref, bool> p = tm->shadow(1, noop_validator());
b = p.first.get_location(); b = p.first.get_location();
BOOST_CHECK(b != 1); ASSERT_THAT(b, Ne(1u));
BOOST_CHECK(p.second); ASSERT_TRUE(p.second);
sm->commit(); sm->commit();
} }
@ -112,9 +110,9 @@ BOOST_AUTO_TEST_CASE(multiple_shadowing)
write_ref superblock = tm->begin(0, noop_validator()); write_ref superblock = tm->begin(0, noop_validator());
pair<write_ref, bool> p = tm->shadow(1, noop_validator()); pair<write_ref, bool> p = tm->shadow(1, noop_validator());
b2 = p.first.get_location(); b2 = p.first.get_location();
BOOST_CHECK(b2 != 1); ASSERT_THAT(b2, Ne(1u));
BOOST_CHECK(b2 != b); ASSERT_THAT(b2, Ne(b));
BOOST_CHECK(p.second); ASSERT_TRUE(p.second);
sm->commit(); sm->commit();
} }
@ -122,17 +120,19 @@ BOOST_AUTO_TEST_CASE(multiple_shadowing)
write_ref superblock = tm->begin(0, noop_validator()); write_ref superblock = tm->begin(0, noop_validator());
pair<write_ref, bool> p = tm->shadow(1, noop_validator()); pair<write_ref, bool> p = tm->shadow(1, noop_validator());
block_address b3 = p.first.get_location(); block_address b3 = p.first.get_location();
BOOST_CHECK(b3 != b2); ASSERT_THAT(b3, Ne(b2));
BOOST_CHECK(b3 != b); ASSERT_THAT(b3, Ne(b));
BOOST_CHECK(b3 != 1); ASSERT_THAT(b3, Ne(1u));
BOOST_CHECK(!p.second); ASSERT_FALSE(p.second);
sm->commit(); sm->commit();
} }
} }
BOOST_AUTO_TEST_CASE(shadow_free_block_fails) TEST(TransactionManagerTests, shadow_free_block_fails)
{ {
transaction_manager::ptr tm = create_tm(); transaction_manager::ptr tm = create_tm();
write_ref superblock = tm->begin(0, noop_validator()); write_ref superblock = tm->begin(0, noop_validator());
BOOST_CHECK_THROW(tm->shadow(1, noop_validator()), runtime_error); ASSERT_THROW(tm->shadow(1, noop_validator()), runtime_error);
} }
//----------------------------------------------------------------