2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORETEST_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORETEST_H_
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2016-02-11 15:19:58 +01:00
|
|
|
#include <gtest/gtest.h>
|
2016-06-23 21:14:07 +02:00
|
|
|
#include <gmock/gmock.h>
|
2016-06-24 06:28:06 +02:00
|
|
|
#include <cpp-utils/data/DataFixture.h>
|
2017-09-29 06:15:51 +02:00
|
|
|
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
2016-06-23 21:14:07 +02:00
|
|
|
|
2016-02-11 15:19:58 +01:00
|
|
|
#include "blockstore/interface/BlockStore.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2016-06-23 21:14:07 +02:00
|
|
|
class MockForEachBlockCallback final {
|
|
|
|
public:
|
2017-09-17 03:07:27 +02:00
|
|
|
std::function<void (const blockstore::BlockId &)> callback() {
|
|
|
|
return [this] (const blockstore::BlockId &blockId) {
|
|
|
|
called_with.push_back(blockId);
|
2016-06-23 21:14:07 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
std::vector<blockstore::BlockId> called_with;
|
2016-06-23 21:14:07 +02:00
|
|
|
};
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
class BlockStoreTestFixture {
|
|
|
|
public:
|
2015-10-17 21:10:26 +02:00
|
|
|
virtual ~BlockStoreTestFixture() {}
|
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:
|
2015-10-17 21:10:26 +02:00
|
|
|
BlockStoreTest() :fixture() {}
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
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;
|
2016-06-24 06:28:06 +02:00
|
|
|
|
|
|
|
void TestBlockIsUsable(cpputils::unique_ref<blockstore::Block> block, blockstore::BlockStore *blockStore) {
|
|
|
|
// Write full block space and check it was correctly written
|
|
|
|
cpputils::Data fixture = cpputils::DataFixture::generate(block->size());
|
|
|
|
block->write(fixture.data(), 0, fixture.size());
|
|
|
|
EXPECT_EQ(0, std::memcmp(fixture.data(), block->data(), fixture.size()));
|
|
|
|
|
|
|
|
// Store and reload block and check data is still correct
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = block->blockId();
|
2016-06-24 06:28:06 +02:00
|
|
|
cpputils::destruct(std::move(block));
|
2017-09-17 03:07:27 +02:00
|
|
|
block = blockStore->load(blockId).value();
|
2016-06-24 06:28:06 +02:00
|
|
|
EXPECT_EQ(0, std::memcmp(fixture.data(), block->data(), fixture.size()));
|
|
|
|
}
|
2016-06-23 21:14:07 +02:00
|
|
|
|
|
|
|
template<class Entry>
|
|
|
|
void EXPECT_UNORDERED_EQ(const std::vector<Entry> &expected, std::vector<Entry> actual) {
|
|
|
|
EXPECT_EQ(expected.size(), actual.size());
|
|
|
|
for (const Entry &expectedEntry : expected) {
|
|
|
|
removeOne(&actual, expectedEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Entry>
|
|
|
|
void removeOne(std::vector<Entry> *entries, const Entry &toRemove) {
|
|
|
|
auto found = std::find(entries->begin(), entries->end(), toRemove);
|
|
|
|
if (found != entries->end()) {
|
|
|
|
entries->erase(found);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
}
|
2014-12-09 17:19:59 +01:00
|
|
|
};
|
|
|
|
|
2019-10-13 14:16:06 +02:00
|
|
|
TYPED_TEST_SUITE_P(BlockStoreTest);
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, TwoCreatedBlocksHaveDifferentBlockIds) {
|
2014-12-09 17:19:59 +01:00
|
|
|
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));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_NE(block1->blockId(), block2->blockId());
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:06:37 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting_DeleteByBlock) {
|
2015-02-22 00:29:21 +01:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore->create(cpputils::Data(1024))->blockId();
|
|
|
|
auto block = blockStore->load(blockId);
|
2015-07-21 14:50:52 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
blockStore->remove(std::move(*block));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_EQ(boost::none, blockStore->load(blockId));
|
2015-02-22 00:29:21 +01:00
|
|
|
}
|
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting_DeleteByBlockId) {
|
2016-07-13 11:06:37 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore->create(cpputils::Data(1024))->blockId();
|
|
|
|
blockStore->remove(blockId);
|
|
|
|
EXPECT_EQ(boost::none, blockStore->load(blockId));
|
2016-07-13 11:06:37 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 14:42:26 +01:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectOnEmptyBlockstore) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
2015-02-24 14:42:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
2015-04-17 13:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
2015-02-24 14:42:26 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:06:37 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlock) {
|
2015-02-24 14:42:26 +01:00
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
2015-02-24 14:42:26 +01:00
|
|
|
}
|
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlockId) {
|
2016-07-13 11:06:37 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore->create(cpputils::Data(1))->blockId();
|
|
|
|
blockStore->remove(blockId);
|
2016-07-13 11:06:37 +02:00
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2015-02-24 14:42:26 +01:00
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(2u, blockStore->numBlocks());
|
2015-04-17 13:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(2u, blockStore->numBlocks());
|
2015-04-17 13:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(2u, blockStore->numBlocks());
|
2015-04-17 13:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(2u, blockStore->numBlocks());
|
2015-02-24 14:42:26 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:06:37 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlock) {
|
2015-02-24 14:42:26 +01:00
|
|
|
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));
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
2015-02-24 14:42:26 +01:00
|
|
|
}
|
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlockId) {
|
2016-07-13 11:06:37 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore->create(cpputils::Data(1))->blockId();
|
2016-07-13 11:06:37 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
2017-09-17 03:07:27 +02:00
|
|
|
blockStore->remove(blockId);
|
2016-07-13 11:06:37 +02:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2015-09-29 18:51:59 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, CanRemoveModifiedBlock) {
|
2016-06-23 21:14:07 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(5));
|
|
|
|
block->write("data", 0, 4);
|
|
|
|
blockStore->remove(std::move(block));
|
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_zeroblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_oneblock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(1));
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({block->blockId()}, mockForEachBlockCallback.called_with);
|
2016-06-23 21:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_twoblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(1));
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({block1->blockId(), block2->blockId()}, mockForEachBlockCallback.called_with);
|
2016-06-23 21:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_threeblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto block3 = blockStore->create(cpputils::Data(1));
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({block1->blockId(), block2->blockId(), block3->blockId()}, mockForEachBlockCallback.called_with);
|
2016-06-23 21:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_doesntListRemovedBlocks_oneblock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->remove(std::move(block1));
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, ForEachBlock_doesntListRemovedBlocks_twoblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto block2 = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->remove(std::move(block1));
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({block2->blockId()}, mockForEachBlockCallback.called_with);
|
2015-09-29 18:51:59 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 06:20:36 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Larger_FromZero) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(0));
|
|
|
|
block->resize(10);
|
|
|
|
EXPECT_EQ(10u, block->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Larger_FromZero_BlockIsStillUsable) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(0));
|
|
|
|
block->resize(10);
|
|
|
|
this->TestBlockIsUsable(std::move(block), blockStore.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Larger) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(20);
|
|
|
|
EXPECT_EQ(20u, block->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Larger_BlockIsStillUsable) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(20);
|
|
|
|
this->TestBlockIsUsable(std::move(block), blockStore.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Smaller) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(5);
|
|
|
|
EXPECT_EQ(5u, block->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Smaller_BlockIsStillUsable) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(5);
|
|
|
|
this->TestBlockIsUsable(std::move(block), blockStore.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Smaller_ToZero) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(0);
|
|
|
|
EXPECT_EQ(0u, block->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, Resize_Smaller_ToZero_BlockIsStillUsable) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
auto block = blockStore->create(cpputils::Data(10));
|
|
|
|
block->resize(0);
|
|
|
|
this->TestBlockIsUsable(std::move(block), blockStore.get());
|
|
|
|
}
|
2017-09-29 00:13:03 +02:00
|
|
|
/*
|
2017-09-18 21:42:07 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, TryCreateTwoBlocksWithSameBlockIdAndSameSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto block = blockStore->tryCreate(blockId, cpputils::Data(1024));
|
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
|
|
|
auto block2 = blockStore->tryCreate(blockId, cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
|
|
|
}
|
2017-09-29 00:13:03 +02:00
|
|
|
|
2017-09-18 21:42:07 +02:00
|
|
|
TYPED_TEST_P(BlockStoreTest, TryCreateTwoBlocksWithSameBlockIdAndDifferentSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto block = blockStore->tryCreate(blockId, cpputils::Data(1024));
|
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
|
|
|
auto block2 = blockStore->tryCreate(blockId, cpputils::Data(4096));
|
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, TryCreateTwoBlocksWithSameBlockIdAndFirstNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto block = blockStore->tryCreate(blockId, cpputils::Data(0));
|
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
|
|
|
auto block2 = blockStore->tryCreate(blockId, cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, TryCreateTwoBlocksWithSameBlockIdAndSecondNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto block = blockStore->tryCreate(blockId, cpputils::Data(1024));
|
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
|
|
|
auto block2 = blockStore->tryCreate(blockId, cpputils::Data(0));
|
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreTest, TryCreateTwoBlocksWithSameBlockIdAndBothNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto block = blockStore->tryCreate(blockId, cpputils::Data(0));
|
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
|
|
|
auto block2 = blockStore->tryCreate(blockId, cpputils::Data(0));
|
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
|
|
|
}*/
|
|
|
|
|
2015-03-08 02:15:31 +01:00
|
|
|
#include "BlockStoreTest_Size.h"
|
|
|
|
#include "BlockStoreTest_Data.h"
|
|
|
|
|
|
|
|
|
2019-10-13 14:16:06 +02:00
|
|
|
REGISTER_TYPED_TEST_SUITE_P(BlockStoreTest,
|
2014-12-09 17:19:59 +01:00
|
|
|
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,
|
2017-09-17 03:07:27 +02:00
|
|
|
TwoCreatedBlocksHaveDifferentBlockIds,
|
2016-07-13 11:06:37 +02:00
|
|
|
BlockIsNotLoadableAfterDeleting_DeleteByBlock,
|
2017-09-17 03:07:27 +02:00
|
|
|
BlockIsNotLoadableAfterDeleting_DeleteByBlockId,
|
2015-02-24 14:42:26 +01:00
|
|
|
NumBlocksIsCorrectOnEmptyBlockstore,
|
|
|
|
NumBlocksIsCorrectAfterAddingOneBlock,
|
2015-04-17 13:27:17 +02:00
|
|
|
NumBlocksIsCorrectAfterAddingOneBlock_AfterClosingBlock,
|
2016-07-13 11:06:37 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlock,
|
2017-09-17 03:07:27 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingTheLastBlock_DeleteByBlockId,
|
2015-02-24 14:42:26 +01:00
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks,
|
2015-04-17 13:27:17 +02:00
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingFirstBlock,
|
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingSecondBlock,
|
|
|
|
NumBlocksIsCorrectAfterAddingTwoBlocks_AfterClosingBothBlocks,
|
2016-07-13 11:06:37 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlock,
|
2017-09-17 03:07:27 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingABlock_DeleteByBlockId,
|
2015-03-08 02:15:31 +01:00
|
|
|
WriteAndReadImmediately,
|
|
|
|
WriteAndReadAfterLoading,
|
2016-07-16 11:42:06 +02:00
|
|
|
WriteTwiceAndRead,
|
|
|
|
OverwriteSameSizeAndReadImmediately,
|
|
|
|
OverwriteSameSizeAndReadAfterLoading,
|
|
|
|
OverwriteSmallerSizeAndReadImmediately,
|
|
|
|
OverwriteSmallerSizeAndReadAfterLoading,
|
|
|
|
OverwriteLargerSizeAndReadAfterLoading,
|
|
|
|
OverwriteLargerSizeAndReadImmediately,
|
|
|
|
OverwriteNonexistingAndReadAfterLoading,
|
|
|
|
OverwriteNonexistingAndReadImmediately,
|
2016-06-24 06:20:36 +02:00
|
|
|
CanRemoveModifiedBlock,
|
2016-06-23 21:14:07 +02:00
|
|
|
ForEachBlock_zeroblocks,
|
|
|
|
ForEachBlock_oneblock,
|
|
|
|
ForEachBlock_twoblocks,
|
|
|
|
ForEachBlock_threeblocks,
|
|
|
|
ForEachBlock_doesntListRemovedBlocks_oneblock,
|
2017-09-29 00:13:03 +02:00
|
|
|
ForEachBlock_doesntListRemovedBlocks_twoblocks,
|
2016-06-24 06:20:36 +02:00
|
|
|
Resize_Larger_FromZero,
|
|
|
|
Resize_Larger_FromZero_BlockIsStillUsable,
|
|
|
|
Resize_Larger,
|
|
|
|
Resize_Larger_BlockIsStillUsable,
|
|
|
|
Resize_Smaller,
|
|
|
|
Resize_Smaller_BlockIsStillUsable,
|
|
|
|
Resize_Smaller_ToZero,
|
2017-09-29 00:13:03 +02:00
|
|
|
Resize_Smaller_ToZero_BlockIsStillUsable
|
2017-09-18 21:42:07 +02:00
|
|
|
//TODO Just disabled because gtest doesn't allow more template parameters. Fix and reenable!
|
|
|
|
// see https://github.com/google/googletest/issues/1267
|
2017-09-29 00:13:03 +02:00
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndSameSize,
|
2017-09-18 21:42:07 +02:00
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndDifferentSize,
|
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndFirstNullSize,
|
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndSecondNullSize,
|
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndBothNullSize,
|
2014-12-09 17:19:59 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|