Fix Blob::write() and add some test cases for it

This commit is contained in:
Sebastian Messmer 2015-03-06 16:08:30 +01:00
parent 4658de552f
commit a9c44a40ed
3 changed files with 37 additions and 3 deletions

View File

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

View File

@ -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());
}

View File

@ -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