From c293dc05716420d763aa6d42fc8335bf3afae7b9 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Fri, 6 Mar 2015 16:54:49 +0100 Subject: [PATCH] Added test cases --- .../onblocks/BlobReadWriteTest.cpp | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/test/implementations/onblocks/BlobReadWriteTest.cpp b/test/implementations/onblocks/BlobReadWriteTest.cpp index 7eb7c1d7..49d6dc2c 100644 --- a/test/implementations/onblocks/BlobReadWriteTest.cpp +++ b/test/implementations/onblocks/BlobReadWriteTest.cpp @@ -1,9 +1,6 @@ #include "testutils/BlobStoreTest.h" #include - -//TODO Test read/write -//TODO Test read/write with loading inbetween -//TODO Test flushing isn't necessary (writing immediately flushes) +#include "../../testutils/DataBlockFixture.h" using std::unique_ptr; @@ -13,4 +10,37 @@ using blockstore::Data; class BlobReadWriteTest: public BlobStoreTest { public: + static constexpr uint32_t LARGE_SIZE = 10 * 1024 * 1024; + + BlobReadWriteTest() + :randomData(LARGE_SIZE), + blob(blobStore->create()) { + } + + Data readBlob(const Blob &blob) { + Data data(blob.size()); + blob.read(data.data(), 0, data.size()); + return data; + } + + DataBlockFixture randomData; + unique_ptr blob; }; +constexpr uint32_t BlobReadWriteTest::LARGE_SIZE; + +TEST_F(BlobReadWriteTest, WritingImmediatelyFlushes_SmallSize) { + blob->resize(5); + blob->write(randomData.data(), 0, 5); + auto loaded = blobStore->load(blob->key()); + EXPECT_EQ(0, std::memcmp(readBlob(*loaded).data(), randomData.data(), 5)); +} + +TEST_F(BlobReadWriteTest, WritingImmediatelyFlushes_LargeSize) { + blob->resize(LARGE_SIZE); + blob->write(randomData.data(), 0, LARGE_SIZE); + auto loaded = blobStore->load(blob->key()); + EXPECT_EQ(0, std::memcmp(readBlob(*loaded).data(), randomData.data(), LARGE_SIZE)); +} + +//TODO Test read/write +//TODO Test read/write with loading inbetween