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
|
|
|
};
|
|
|
|
|
|
|
|
TYPED_TEST_CASE_P(BlockStore2Test);
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnExistingBlock_thenFails) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_FALSE(this->blockStore->tryCreate(key, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenCallingTryCreateOnNonExistingBlock_thenSucceeds) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024)));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadExistingBlock_thenSucceeds) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadNonexistingBlock_thenFails) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenLoadNonexistingBlock_thenFails) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringExistingBlock_thenSucceeds) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
this->blockStore->store(key, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenStoringNonexistingBlock_thenSucceeds) {
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenCreatingTwoBlocks_thenTheyGetDifferentKeys) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key1 = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
blockstore::Key key2 = this->blockStore->create(cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_NE(key1, key2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(key));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(key));
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingBlock_thenBlockIsNotLoadableAnymore) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_NE(boost::none, this->blockStore->load(key));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(key));
|
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenOtherwiseEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
|
|
|
EXPECT_TRUE(this->blockStore->remove(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenRemovingExistingBlock_thenSucceeds) {
|
2017-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = this->blockStore->create(cpputils::Data(1024));
|
2017-02-21 23:27:46 +01:00
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(true, this->blockStore->remove(key));
|
2017-02-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenRemovingNonexistingBlock_thenFails) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
auto result = this->blockStore->remove(key);
|
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) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
blockstore::Key differentKey = blockstore::Key::FromString("290AC2C7097274A389EE14B91B72B493");
|
2017-07-21 04:32:42 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(1024)));
|
|
|
|
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-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).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-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).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-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).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-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).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) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973");
|
2017-07-21 04:32:42 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(0)));
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
2017-07-21 04:32:42 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(key, cpputils::Data(0)));
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(key, data.copy()));
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-07-07 17:50:45 +02:00
|
|
|
EXPECT_EQ(loaded, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenNonEmptyBlockStore_whenTryCreatingAndLoadingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772973");
|
|
|
|
this->blockStore->create(cpputils::Data(512));
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
ASSERT_TRUE(this->blockStore->tryCreate(key, data.copy()));
|
|
|
|
auto loaded = this->blockStore->load(key).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) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).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));
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingNonExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).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));
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingEmptyBlock_thenCorrectBlockLoads) {
|
2017-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(cpputils::Data(512));
|
|
|
|
this->blockStore->store(key, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).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));
|
|
|
|
auto key = this->blockStore->create(cpputils::Data(512));
|
|
|
|
this->blockStore->store(key, cpputils::Data(0));
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(0u, loaded.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenStoringAndLoadingExistingNonEmptyBlock_thenCorrectBlockLoads) {
|
2017-07-21 04:32:42 +02:00
|
|
|
auto key = this->blockStore->create(cpputils::Data(512));
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).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));
|
|
|
|
auto key = this->blockStore->create(cpputils::Data(512));
|
2017-02-21 23:27:46 +01:00
|
|
|
cpputils::Data data = cpputils::DataFixture::generate(1024);
|
2017-07-21 04:32:42 +02:00
|
|
|
this->blockStore->store(key, data.copy());
|
|
|
|
auto loaded = this->blockStore->load(key).value();
|
2017-02-21 23:27:46 +01:00
|
|
|
EXPECT_EQ(data, loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, givenEmptyBlockStore_whenLoadingNonExistingBlock_thenFails) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
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-02-21 23:27:46 +01:00
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2017-07-21 04:32:42 +02:00
|
|
|
EXPECT_EQ(boost::none, this->blockStore->load(key));
|
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-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(key));
|
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-07-21 04:32:42 +02:00
|
|
|
blockstore::Key key = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(key));
|
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) {
|
|
|
|
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockStore->store(key, cpputils::Data(1));
|
|
|
|
EXPECT_EQ(1u, blockStore->numBlocks());
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, NumBlocksIsCorrectAfterStoringAnExistingBlock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
|
|
|
blockstore::Key key = blockStore->create(cpputils::Data(1));
|
|
|
|
blockStore->store(key, cpputils::Data(1));
|
|
|
|
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-07-21 04:32:42 +02:00
|
|
|
auto key = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({key}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_twoblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-07-21 04:32:42 +02:00
|
|
|
auto key1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto key2 = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({key1, key2}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_threeblocks) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-07-21 04:32:42 +02:00
|
|
|
auto key1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto key2 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto key3 = blockStore->create(cpputils::Data(1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({key1, key2, key3}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStore2Test, ForEachBlock_doesntListRemovedBlocks_oneblock) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2017-07-21 04:32:42 +02:00
|
|
|
auto key1 = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(key1));
|
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-07-21 04:32:42 +02:00
|
|
|
auto key1 = blockStore->create(cpputils::Data(1));
|
|
|
|
auto key2 = blockStore->create(cpputils::Data(1));
|
|
|
|
EXPECT_TRUE(blockStore->remove(key1));
|
2017-07-07 23:18:09 +02:00
|
|
|
MockForEachBlockCallback mockForEachBlockCallback;
|
|
|
|
blockStore->forEachBlock(mockForEachBlockCallback.callback());
|
|
|
|
this->EXPECT_UNORDERED_EQ({key2}, mockForEachBlockCallback.called_with);
|
|
|
|
}
|
2017-02-21 23:27:46 +01:00
|
|
|
|
|
|
|
REGISTER_TYPED_TEST_CASE_P(BlockStore2Test,
|
|
|
|
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,
|
|
|
|
ForEachBlock_doesntListRemovedBlocks_twoblocks
|
2017-02-21 23:27:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|