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 );