From 1006c2cc385b6b8c01f43569a92cf0e56cd78623 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 24 Feb 2015 14:42:26 +0100 Subject: [PATCH] Test cases for BlockStore::numBlocks() --- interface/BlockStore.h | 1 - test/testutils/BlockStoreTest.h | 40 ++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/interface/BlockStore.h b/interface/BlockStore.h index 028c98c1..8c797fc6 100644 --- a/interface/BlockStore.h +++ b/interface/BlockStore.h @@ -21,7 +21,6 @@ public: virtual std::unique_ptr load(const Key &key) = 0; virtual void remove(std::unique_ptr block) = 0; virtual uint64_t numBlocks() const = 0; - //TODO Test numBlocks }; } diff --git a/test/testutils/BlockStoreTest.h b/test/testutils/BlockStoreTest.h index d374f642..7ede1ae6 100644 --- a/test/testutils/BlockStoreTest.h +++ b/test/testutils/BlockStoreTest.h @@ -209,6 +209,39 @@ TYPED_TEST_P(BlockStoreTest, BlockIsNotLoadableAfterDeleting) { EXPECT_EQ(nullptr, blockStore->load(blockkey)); } +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectOnEmptyBlockstore) { + auto blockStore = this->fixture.createBlockStore(); + EXPECT_EQ(0, blockStore->numBlocks()); +} + +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingOneBlock) { + auto blockStore = this->fixture.createBlockStore(); + blockStore->create(1); + EXPECT_EQ(1, blockStore->numBlocks()); +} + +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingTheLastBlock) { + auto blockStore = this->fixture.createBlockStore(); + auto block = blockStore->create(1); + blockStore->remove(std::move(block)); + EXPECT_EQ(0, blockStore->numBlocks()); +} + +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterAddingTwoBlocks) { + auto blockStore = this->fixture.createBlockStore(); + blockStore->create(1); + blockStore->create(0); + EXPECT_EQ(2, blockStore->numBlocks()); +} + +TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock) { + auto blockStore = this->fixture.createBlockStore(); + auto block = blockStore->create(1); + blockStore->create(1); + blockStore->remove(std::move(block)); + EXPECT_EQ(1, blockStore->numBlocks()); +} + REGISTER_TYPED_TEST_CASE_P(BlockStoreTest, CreatedBlockHasCorrectSize, LoadingUnchangedBlockHasCorrectSize, @@ -223,7 +256,12 @@ REGISTER_TYPED_TEST_CASE_P(BlockStoreTest, LoadNonExistingBlock, LoadNonExistingBlockWithEmptyKey, TwoCreatedBlocksHaveDifferentKeys, - BlockIsNotLoadableAfterDeleting + BlockIsNotLoadableAfterDeleting, + NumBlocksIsCorrectOnEmptyBlockstore, + NumBlocksIsCorrectAfterAddingOneBlock, + NumBlocksIsCorrectAfterRemovingTheLastBlock, + NumBlocksIsCorrectAfterAddingTwoBlocks, + NumBlocksIsCorrectAfterRemovingABlock );