From a9c44a40ed58d25fce1834a6855f62c452b69c83 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Fri, 6 Mar 2015 16:08:30 +0100 Subject: [PATCH] Fix Blob::write() and add some test cases for it --- implementations/onblocks/BlobOnBlocks.cpp | 4 +-- .../implementations/onblocks/BlobSizeTest.cpp | 33 +++++++++++++++++++ .../onblocks/BlobStoreTest.cpp | 3 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/implementations/onblocks/BlobOnBlocks.cpp b/implementations/onblocks/BlobOnBlocks.cpp index 26ecffe1..38ff2be0 100644 --- a/implementations/onblocks/BlobOnBlocks.cpp +++ b/implementations/onblocks/BlobOnBlocks.cpp @@ -39,8 +39,8 @@ void BlobOnBlocks::traverseLeaves(uint64_t beginByte, uint64_t sizeBytes, functi _datatree->traverseLeaves(firstLeaf, endLeaf, [&func, beginByte, endByte](DataLeafNode *leaf, uint32_t leafIndex) { uint64_t indexOfFirstLeafByte = leafIndex * leaf->maxStoreableBytes(); uint32_t dataBegin = utils::maxZeroSubtraction(beginByte, indexOfFirstLeafByte); - uint32_t dataSize = std::min((uint64_t)leaf->maxStoreableBytes(), endByte - indexOfFirstLeafByte); - func(indexOfFirstLeafByte, leaf, dataBegin, dataSize); + uint32_t dataEnd = std::min((uint64_t)leaf->maxStoreableBytes(), endByte - indexOfFirstLeafByte); + func(indexOfFirstLeafByte, leaf, dataBegin, dataEnd-dataBegin); }); } diff --git a/test/implementations/onblocks/BlobSizeTest.cpp b/test/implementations/onblocks/BlobSizeTest.cpp index 7f8a20bf..5000ef5b 100644 --- a/test/implementations/onblocks/BlobSizeTest.cpp +++ b/test/implementations/onblocks/BlobSizeTest.cpp @@ -72,3 +72,36 @@ TEST_F(BlobSizeTest, BlobSizeStaysIntactWhenLoading) { auto loaded = blobStore->load(key); EXPECT_EQ(LARGE_SIZE, loaded->size()); } + +TEST_F(BlobSizeTest, WritingAtEndOfBlobGrowsBlob_Empty) { + int value; + blob->write(&value, 0, 4); + EXPECT_EQ(4, blob->size()); +} + +TEST_F(BlobSizeTest, WritingAfterEndOfBlobGrowsBlob_Empty) { + int value; + blob->write(&value, 2, 4); + EXPECT_EQ(6, blob->size()); +} + +TEST_F(BlobSizeTest, WritingOverEndOfBlobGrowsBlob_NonEmpty) { + blob->resize(1); + int value; + blob->write(&value, 0, 4); + EXPECT_EQ(4, blob->size()); +} + +TEST_F(BlobSizeTest, WritingAtEndOfBlobGrowsBlob_NonEmpty) { + blob->resize(1); + int value; + blob->write(&value, 1, 4); + EXPECT_EQ(5, blob->size()); +} + +TEST_F(BlobSizeTest, WritingAfterEndOfBlobGrowsBlob_NonEmpty) { + blob->resize(1); + int value; + blob->write(&value, 2, 4); + EXPECT_EQ(6, blob->size()); +} diff --git a/test/implementations/onblocks/BlobStoreTest.cpp b/test/implementations/onblocks/BlobStoreTest.cpp index 90cf7548..d418b297 100644 --- a/test/implementations/onblocks/BlobStoreTest.cpp +++ b/test/implementations/onblocks/BlobStoreTest.cpp @@ -36,8 +36,9 @@ TEST_F(BlobStoreTest, BlobIsNotLoadableAfterDeletion_DeleteAfterLoading) { //TODO Test read/write //TODO Test read/write with loading inbetween +//TODO Test flushing isn't necessary (changes do auto-flush) //Taken from BlockStoreTest.h: //TODO Blob is zeroed out after growing //TODO Blob is zeroed out after growing and loading -//TODO Last blob part is zeroed out after shrinking and regrowing +//TODO Last blob part is zeroed out after shrinking and regrowing \ No newline at end of file