2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef TEST_BLOCKSTORE_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORETEST_H_
|
|
|
|
#define TEST_BLOCKSTORE_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORETEST_H_
|
|
|
|
|
2015-02-17 00:23:33 +01:00
|
|
|
#include "google/gtest/gtest.h"
|
|
|
|
|
|
|
|
#include "../../interface/BlockStore.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
class BlockStoreTestFixture {
|
|
|
|
public:
|
2015-07-21 18:19:34 +02:00
|
|
|
virtual cpputils::unique_ref<blockstore::BlockStore> createBlockStore() = 0;
|
2014-12-09 17:19:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class ConcreteBlockStoreTestFixture>
|
|
|
|
class BlockStoreTest: public ::testing::Test {
|
|
|
|
public:
|
|
|
|
BOOST_STATIC_ASSERT_MSG(
|
|
|
|
(std::is_base_of<BlockStoreTestFixture, ConcreteBlockStoreTestFixture>::value),
|
|
|
|
"Given test fixture for instantiating the (type parameterized) BlockStoreTest must inherit from BlockStoreTestFixture"
|
|
|
|
);
|
|
|
|
|
|
|
|
ConcreteBlockStoreTestFixture fixture;
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPED_TEST_CASE_P(BlockStoreTest);
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, TwoCreatedBlocksHaveDifferentKeys) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block1 = blockStore->create(cpputils::Data(1024));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(1024));
|
2015-01-24 22:27:14 +01:00
|
|
|
EXPECT_NE(block1->key(), block2->key());
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
2015-02-22 00:29:21 +01:00
|
|
|
TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto blockkey = blockStore->create(cpputils::Data(1024))->key();
|
2015-02-22 16:53:49 +01:00
|
|
|
auto block = blockStore->load(blockkey);
|
2015-07-21 14:50:52 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
blockStore->remove(std::move(*block));
|
|
|
|
EXPECT_EQ(boost::none, blockStore->load(blockkey));
|
2015-02-22 00:29:21 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 14:42:26 +01:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectOnEmptyBlockstore) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
EXPECT_EQ(0, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingOneBlock) {
|
2015-04-17 13:27:17 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->create(cpputils::Data(1));
|
2015-04-17 13:27:17 +02:00
|
|
|
EXPECT_EQ(1, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingOneBlock_AfterClosingBlock) {
|
2015-02-24 14:42:26 +01:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
2015-02-24 14:42:26 +01:00
|
|
|
EXPECT_EQ(1, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->create(cpputils::Data(1));
|
2015-07-21 14:50:52 +02:00
|
|
|
blockStore->remove(std::move(block));
|
2015-02-24 14:42:26 +01:00
|
|
|
EXPECT_EQ(0, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocks) {
|
2015-04-17 13:27:17 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(0));
|
2015-04-17 13:27:17 +02:00
|
|
|
EXPECT_EQ(2, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingFirstBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(0));
|
2015-04-17 13:27:17 +02:00
|
|
|
EXPECT_EQ(2, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingSecondBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->create(cpputils::Data(0));
|
2015-04-17 13:27:17 +02:00
|
|
|
EXPECT_EQ(2, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingBothBlocks) {
|
2015-02-24 14:42:26 +01:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->create(cpputils::Data(0));
|
2015-02-24 14:42:26 +01:00
|
|
|
EXPECT_EQ(2, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->create(cpputils::Data(1));
|
2015-07-21 14:50:52 +02:00
|
|
|
blockStore->remove(std::move(block));
|
2015-02-24 14:42:26 +01:00
|
|
|
EXPECT_EQ(1, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2015-03-08 02:15:31 +01:00
|
|
|
#include "BlockStoreTest_Size.h"
|
|
|
|
#include "BlockStoreTest_Data.h"
|
|
|
|
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
REGISTER_TYPED_TEST_CASE_P(BlockStoreTest,
|
|
|
|
CreatedBlockHasCorrectSize,
|
|
|
|
LoadingUnchangedBlockHasCorrectSize,
|
2015-04-18 14:47:12 +02:00
|
|
|
CreatedBlockData,
|
|
|
|
LoadingUnchangedBlockData,
|
2014-12-09 17:19:59 +01:00
|
|
|
LoadedBlockIsCorrect,
|
2015-03-28 18:44:22 +01:00
|
|
|
// LoadedBlockIsCorrectWhenLoadedDirectlyAfterFlushing,
|
2014-12-09 17:19:59 +01:00
|
|
|
AfterCreate_FlushingDoesntChangeBlock,
|
|
|
|
AfterLoad_FlushingDoesntChangeBlock,
|
|
|
|
AfterCreate_FlushesWhenDestructed,
|
|
|
|
AfterLoad_FlushesWhenDestructed,
|
2014-12-09 20:36:32 +01:00
|
|
|
LoadNonExistingBlock,
|
2015-02-22 00:29:21 +01:00
|
|
|
TwoCreatedBlocksHaveDifferentKeys,
|
2015-02-24 14:42:26 +01:00
|
|
|
BlockIsNotLoadableAfterDeleting,
|
|
|
|
NumBlocksIsCorrectOnEmptyBlockstore,
|
|
|
|
NumBlocksIsCorrectAfterAddingOneBlock,
|
2015-04-17 13:27:17 +02:00
|
|
|
NumBlocksIsCorrectAfterAddingOneBlock_AfterClosingBlock,
|
2015-02-24 14:42:26 +01:00
|
|
|
NumBlocksIsCorrectAfterRemovingTheLastBlock,
|
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks,
|
2015-04-17 13:27:17 +02:00
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingFirstBlock,
|
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingSecondBlock,
|
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingBothBlocks,
|
2015-03-08 02:15:31 +01:00
|
|
|
NumBlocksIsCorrectAfterRemovingABlock,
|
|
|
|
WriteAndReadImmediately,
|
|
|
|
WriteAndReadAfterLoading,
|
|
|
|
OverwriteAndRead
|
2014-12-09 17:19:59 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|