Fix Blob::write() and add some test cases for it
This commit is contained in:
parent
4658de552f
commit
a9c44a40ed
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user