Remove Key::CreateDummyKey()

This commit is contained in:
Sebastian Messmer 2014-12-09 20:57:10 +01:00
parent fa5058c8e3
commit 1924c936a4
5 changed files with 10 additions and 15 deletions

View File

@ -35,12 +35,6 @@ Key Key::CreateRandomKey() {
return result; return result;
} }
Key Key::CreateDummyKey() {
Key result;
std::memset(result._key, 0, KEYLENGTH_BINARY);
return result;
}
Key Key::FromString(const std::string &key) { Key Key::FromString(const std::string &key) {
assert(key.size() == KEYLENGTH_STRING); assert(key.size() == KEYLENGTH_STRING);
Key result; Key result;

View File

@ -16,7 +16,6 @@ public:
static constexpr unsigned int KEYLENGTH_STRING = 2 * KEYLENGTH_BINARY; // Hex encoding static constexpr unsigned int KEYLENGTH_STRING = 2 * KEYLENGTH_BINARY; // Hex encoding
static Key CreateRandomKey(); static Key CreateRandomKey();
static Key CreateDummyKey();
static Key FromString(const std::string &key); static Key FromString(const std::string &key);
std::string AsString() const; std::string AsString() const;

View File

@ -38,6 +38,7 @@ class BlockStoreWithRandomKeysTest: public Test {
public: public:
BlockStoreWithRandomKeysMock blockStoreMock; BlockStoreWithRandomKeysMock blockStoreMock;
BlockStore &blockStore = blockStoreMock; BlockStore &blockStore = blockStoreMock;
const blockstore::Key key = Key::FromString("1491BB4932A389EE14BC7090AC772972");
}; };
TEST_F(BlockStoreWithRandomKeysTest, SizeIsPassedThrough0) { TEST_F(BlockStoreWithRandomKeysTest, SizeIsPassedThrough0) {
@ -65,7 +66,7 @@ TEST_F(BlockStoreWithRandomKeysTest, KeyHasCorrectSize) {
} }
TEST_F(BlockStoreWithRandomKeysTest, TwoBlocksGetDifferentKeys) { TEST_F(BlockStoreWithRandomKeysTest, TwoBlocksGetDifferentKeys) {
Key first_key = Key::CreateDummyKey(); Key first_key = key;
EXPECT_CALL(blockStoreMock, do_create(_, _)) EXPECT_CALL(blockStoreMock, do_create(_, _))
.WillOnce(Invoke([&first_key](const Key &key, size_t) { .WillOnce(Invoke([&first_key](const Key &key, size_t) {
first_key = key; first_key = key;
@ -81,7 +82,7 @@ TEST_F(BlockStoreWithRandomKeysTest, TwoBlocksGetDifferentKeys) {
} }
TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExists) { TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExists) {
Key first_key = Key::CreateDummyKey(); Key first_key = key;
EXPECT_CALL(blockStoreMock, do_create(_, _)) EXPECT_CALL(blockStoreMock, do_create(_, _))
.WillOnce(Invoke([&first_key](const Key &key, size_t) { .WillOnce(Invoke([&first_key](const Key &key, size_t) {
first_key = key; first_key = key;
@ -96,7 +97,7 @@ TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExists) {
} }
TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExistsTwoTimes) { TEST_F(BlockStoreWithRandomKeysTest, WillTryADifferentKeyIfKeyAlreadyExistsTwoTimes) {
Key first_key = Key::CreateDummyKey(); Key first_key = key;
EXPECT_CALL(blockStoreMock, do_create(_, _)) EXPECT_CALL(blockStoreMock, do_create(_, _))
.WillOnce(Invoke([&first_key](const Key &key, size_t) { .WillOnce(Invoke([&first_key](const Key &key, size_t) {
first_key = key; first_key = key;

View File

@ -85,7 +85,7 @@ public:
void TestAfterCreate_FlushesWhenDestructed() { void TestAfterCreate_FlushesWhenDestructed() {
DataBlockFixture randomData(size); DataBlockFixture randomData(size);
blockstore::Key key = blockstore::Key::CreateDummyKey(); blockstore::Key key = key;
{ {
auto block = blockStore->create(size); auto block = blockStore->create(size);
key = block.key; key = block.key;
@ -97,7 +97,7 @@ public:
void TestAfterLoad_FlushesWhenDestructed() { void TestAfterLoad_FlushesWhenDestructed() {
DataBlockFixture randomData(size); DataBlockFixture randomData(size);
blockstore::Key key = blockstore::Key::CreateDummyKey(); blockstore::Key key = key;
{ {
key = blockStore->create(size).key; key = blockStore->create(size).key;
auto block = blockStore->load(key); auto block = blockStore->load(key);
@ -109,17 +109,18 @@ public:
void TestLoadNonExistingBlock() { void TestLoadNonExistingBlock() {
EXPECT_FALSE( EXPECT_FALSE(
(bool)blockStore->load(blockstore::Key::CreateRandomKey()) (bool)blockStore->load(key)
); );
} }
void TestLoadNonExistingBlockWithEmptyKey() { void TestLoadNonExistingBlockWithEmptyKey() {
EXPECT_FALSE( EXPECT_FALSE(
(bool)blockStore->load(blockstore::Key::CreateDummyKey()) (bool)blockStore->load(key)
); );
} }
private: private:
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
std::unique_ptr<blockstore::BlockStore> blockStore; std::unique_ptr<blockstore::BlockStore> blockStore;
size_t size; size_t size;

View File

@ -21,7 +21,7 @@ public:
"Given test fixture for instantiating the (type parameterized) BlockStoreWithRandomKeysTest must inherit from BlockStoreWithRandomKeysTestFixture" "Given test fixture for instantiating the (type parameterized) BlockStoreWithRandomKeysTest must inherit from BlockStoreWithRandomKeysTestFixture"
); );
blockstore::Key key = blockstore::Key::CreateDummyKey(); blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
const std::vector<size_t> SIZES = {0, 1, 1024, 4096, 10*1024*1024}; const std::vector<size_t> SIZES = {0, 1, 1024, 4096, 10*1024*1024};