2017-02-21 23:27:46 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORE2TEST_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_TESTUTILS_BLOCKSTORE2TEST_H_
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <cpp-utils/data/DataFixture.h>
|
|
|
|
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
|
|
|
|
|
|
|
#include "blockstore/interface/BlockStore2.h"
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
inline void PrintTo(const optional<cpputils::Data> &, ::std::ostream *os) {
|
|
|
|
*os << "optional<Data>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlockStore2TestFixture {
|
|
|
|
public:
|
|
|
|
virtual ~BlockStore2TestFixture() {}
|
|
|
|
virtual cpputils::unique_ref<blockstore::BlockStore2> createBlockStore() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class ConcreteBlockStoreTestFixture>
|
|
|
|
class BlockStore2Test: public ::testing::Test {
|
|
|
|
public:
|
|
|
|
BlockStore2Test() :fixture(), blockStore(this->fixture.createBlockStore()) {}
|
|
|
|
|
|
|
|
BOOST_STATIC_ASSERT_MSG(
|
|
|
|
(std::is_base_of<BlockStore2TestFixture, ConcreteBlockStoreTestFixture>::value),
|
|
|
|
"Given test fixture for instantiating the (type parameterized) BlockStoreTest must inherit from BlockStoreTestFixture"
|
|
|
|
);
|
|
|
|
|
|
|
|
ConcreteBlockStoreTestFixture fixture;
|
|
|
|
cpputils::unique_ref<blockstore::BlockStore2> blockStore;
|
2017-07-07 23:18:09 +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);
|
|
|
|
}
|
2017-02-21 23:27:46 +01:00
|
|
|
};
|
|
|
|
|
2019-10-13 14:16:06 +02:00
|
|
|
TYPED_TEST_SUITE_P(BlockStore2Test);
|
2017-02-21 23:27:46 +01:00
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnExistingBlock_thenFails) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_FALSE(this->blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadExistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadNonexistingBlock_thenFails) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadNonexistingBlock_thenFails) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringExistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingTwoBlocks_thenTheyGetDifferentKeys) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId1 = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
blockstore::BlockId blockId2 = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_NE(blockId1, blockId2);
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(blockId));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(blockId));
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(blockId));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(blockId));
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = this->blockStore->create(cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_EQ(true, this->blockStore->remove(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenRemovingNonexistingBlock_thenFails) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto result = this->blockStore->remove(blockId);
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(false, result);
|
|
|
|
}
|
|
|
|
|
2017-07-07 17:50:45 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingNonexistingBlock_thenFails) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
blockstore::BlockId differentKey = blockstore::BlockId::FromString("290AC2C7097274A389EE14B91B72B493");
|
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(false, this->blockStore->remove(differentKey));
|
2017-07-07 17:50:45 +02:00
|
|
|
}
|
|
|
|
|
2017-02-21 23:27:46 +01:00
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(loaded, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(loaded, data);
|
|
|
|
}
|
|
|
|
|
2017-07-07 17:50:45 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973");
|
2017-07-07 17:50:45 +02:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973");
|
2017-07-07 17:50:45 +02:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(blockId, data.copy()));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(loaded, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772973");
|
2017-07-07 17:50:45 +02:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(blockId, data.copy()));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(loaded, data);
|
|
|
|
}
|
|
|
|
|
2017-02-21 23:27:46 +01:00
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
this->blockStore->store(blockId, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
this->blockStore->store(blockId, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(512));
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads) {
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(512));
|
|
|
|
this->blockStore->store(blockId, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(512));
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
this->blockStore->store(blockId, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = this->blockStore->create(cpputils::Data(512));
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-09-17 03:07:27 +02:00
|
|
|
this->blockStore->store(blockId, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(blockId).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadingNonExistingBlock_thenFails) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadingNonExistingBlock_thenFails) {
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(blockId));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
2017-07-07 23:18:09 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectOnEmptyBlockstore) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2017-08-22 00:09:43 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterCreatingOneBlock) {
|
2017-07-07 23:18:09 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-07-21 04:32:42 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterRemovingTheLastBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(blockId));
|
2017-07-07 23:18:09 +02:00
|
|
|
EXPECT_EQ(0u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2017-08-22 00:09:43 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterCreatingTwoBlocks) {
|
2017-07-07 23:18:09 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-07-21 04:32:42 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->create(cpputils::Data(0));
|
2017-07-07 23:18:09 +02:00
|
|
|
EXPECT_EQ(2u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterRemovingABlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockStore->create(cpputils::Data(1));
|
2017-07-21 04:32:42 +02:00
|
|
|
blockStore->create(cpputils::Data(1));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_TRUE(blockStore->remove(blockId));
|
2017-07-07 23:18:09 +02:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2017-08-22 00:09:43 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterStoringANewBlock) {
|
2017-09-17 03:07:27 +02:00
|
|
|
const blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-08-22 00:09:43 +02:00
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
blockStore->store(blockId, cpputils::Data(1));
|
2017-08-22 00:09:43 +02:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterStoringAnExistingBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
blockstore::BlockId blockId = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->store(blockId, cpputils::Data(1));
|
2017-08-22 00:09:43 +02:00
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:18:09 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_zeroblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_oneblock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({blockId}, mockForEachBlockCallback.called_with);
|
2017-07-07 23:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_twoblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto blockId2 = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({blockId1, blockId2}, mockForEachBlockCallback.called_with);
|
2017-07-07 23:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_threeblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto blockId2 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto blockId3 = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({blockId1, blockId2, blockId3}, mockForEachBlockCallback.called_with);
|
2017-07-07 23:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_oneblock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId1 = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(blockId1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_twoblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto blockId2 = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(blockId1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
2017-09-17 03:07:27 +02:00
|
|
|
this->EXPECT_UNORDERED_EQ({blockId2}, mockForEachBlockCallback.called_with);
|
2017-07-07 23:18:09 +02:00
|
|
|
}
|
2017-02-21 23:27:46 +01:00
|
|
|
|
2017-09-18 21:42:07 +02:00
|
|
|
TYPED_TEST_P(BlockStore2Test, TryCreateTwoBlocksWithSameBlockIdAndSameSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
|
|
|
EXPECT_FALSE(blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, TryCreateTwoBlocksWithSameBlockIdAndDifferentSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
|
|
|
EXPECT_FALSE(blockStore->tryCreate(blockId, cpputils::Data(4096)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, TryCreateTwoBlocksWithSameBlockIdAndFirstNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
EXPECT_FALSE(blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
TYPED_TEST_P(BlockStore2Test, TryCreateTwoBlocksWithSameBlockIdAndSecondNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(blockStore->tryCreate(blockId, cpputils::Data(1024)));
|
|
|
|
EXPECT_FALSE(blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, TryCreateTwoBlocksWithSameBlockIdAndBothNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::BlockId blockId = blockstore::BlockId::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
EXPECT_TRUE(blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
EXPECT_FALSE(blockStore->tryCreate(blockId, cpputils::Data(0)));
|
|
|
|
}*/
|
|
|
|
|
2019-10-13 14:16:06 +02:00
|
|
|
REGISTER_TYPED_TEST_SUITE_P(BlockStore2Test,
|
2017-02-21 23:27:46 +01:00
|
|
|
givenNonEmptyBlockStore_whenCallingTryCreateOnExistingBlock_thenFails,
|
|
|
|
givenEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds,
|
|
|
|
givenNonEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds,
|
|
|
|
givenNonEmptyBlockStore_whenLoadExistingBlock_thenSucceeds,
|
|
|
|
givenEmptyBlockStore_whenLoadNonexistingBlock_thenFails,
|
|
|
|
givenNonEmptyBlockStore_whenLoadNonexistingBlock_thenFails,
|
|
|
|
givenNonEmptyBlockStore_whenStoringExistingBlock_thenSucceeds,
|
|
|
|
givenEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds,
|
|
|
|
givenNonEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds,
|
|
|
|
givenEmptyBlockStore_whenCreatingTwoBlocks_thenTheyGetDifferentKeys,
|
|
|
|
givenOtherwiseEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore,
|
|
|
|
givenNonEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore,
|
|
|
|
givenOtherwiseEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds,
|
|
|
|
givenNonEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds,
|
|
|
|
givenEmptyBlockStore_whenRemovingNonexistingBlock_thenFails,
|
2017-07-07 17:50:45 +02:00
|
|
|
givenNonEmptyBlockStore_whenRemovingNonexistingBlock_thenFails,
|
2017-02-21 23:27:46 +01:00
|
|
|
givenEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads,
|
2017-07-07 17:50:45 +02:00
|
|
|
givenEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads,
|
2017-02-21 23:27:46 +01:00
|
|
|
givenEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenNonEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads,
|
|
|
|
givenEmptyBlockStore_whenLoadingNonExistingBlock_thenFails,
|
2017-07-07 23:18:09 +02:00
|
|
|
givenNonEmptyBlockStore_whenLoadingNonExistingBlock_thenFails,
|
|
|
|
NumBlocksIsCorrectOnEmptyBlockstore,
|
2017-08-22 00:09:43 +02:00
|
|
|
NumBlocksIsCorrectAfterCreatingOneBlock,
|
2017-07-07 23:18:09 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingTheLastBlock,
|
2017-08-22 00:09:43 +02:00
|
|
|
NumBlocksIsCorrectAfterCreatingTwoBlocks,
|
2017-07-07 23:18:09 +02:00
|
|
|
NumBlocksIsCorrectAfterRemovingABlock,
|
2017-08-22 00:09:43 +02:00
|
|
|
NumBlocksIsCorrectAfterStoringANewBlock,
|
|
|
|
NumBlocksIsCorrectAfterStoringAnExistingBlock,
|
2017-07-07 23:18:09 +02:00
|
|
|
ForEachBlock_zeroblocks,
|
|
|
|
ForEachBlock_oneblock,
|
|
|
|
ForEachBlock_twoblocks,
|
|
|
|
ForEachBlock_threeblocks,
|
|
|
|
ForEachBlock_doesntListRemovedBlocks_oneblock,
|
2017-09-18 21:42:07 +02:00
|
|
|
ForEachBlock_doesntListRemovedBlocks_twoblocks,
|
|
|
|
TryCreateTwoBlocksWithSameBlockIdAndSameSize,
|
|
|
|
TryCreateTwoBlocksWithSameBlockIdAndDifferentSize,
|
|
|
|
TryCreateTwoBlocksWithSameBlockIdAndFirstNullSize
|
|
|
|
//TODO Just disabled because gtest doesn't allow more template parameters. Fix and reenable!
|
|
|
|
// see https://github.com/google/googletest/issues/1267
|
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndSecondNullSize,
|
|
|
|
//TryCreateTwoBlocksWithSameBlockIdAndBothNullSize
|
2017-02-21 23:27:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|