From b4e2eaa3e86830dd81eb70d08803c1721615770c Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 25 Apr 2015 16:44:00 +0200 Subject: [PATCH] Use cpputils::DataFixture instead of DataBlockFixture --- .../onblocks/BlobReadWriteTest.cpp | 20 +++++++++---------- .../implementations/onblocks/BlobSizeTest.cpp | 8 ++++---- .../datanodestore/DataLeafNodeTest.cpp | 14 ++++++------- .../datanodestore/DataNodeViewTest.cpp | 8 ++++---- .../datatreestore/testutils/LeafDataFixture.h | 6 +++--- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/test/implementations/onblocks/BlobReadWriteTest.cpp b/test/implementations/onblocks/BlobReadWriteTest.cpp index 17d2a4e8..0ff562a8 100644 --- a/test/implementations/onblocks/BlobReadWriteTest.cpp +++ b/test/implementations/onblocks/BlobReadWriteTest.cpp @@ -1,6 +1,6 @@ #include "testutils/BlobStoreTest.h" #include -#include +#include #include "../../../implementations/onblocks/datanodestore/DataNodeView.h" using std::unique_ptr; @@ -11,7 +11,7 @@ using namespace blobstore; using blobstore::onblocks::datanodestore::DataNodeLayout; using blockstore::Key; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; class BlobReadWriteTest: public BlobStoreTest { public: @@ -19,7 +19,7 @@ public: static constexpr DataNodeLayout LAYOUT = DataNodeLayout(BLOCKSIZE_BYTES); BlobReadWriteTest() - :randomData(LARGE_SIZE), + :randomData(DataFixture::generate(LARGE_SIZE)), blob(blobStore->create()) { } @@ -36,7 +36,7 @@ public: EXPECT_EQ(0, std::memcmp(expected.data(), read.data(), size)); } - DataBlockFixture randomData; + Data randomData; unique_ptr blob; }; constexpr uint32_t BlobReadWriteTest::LARGE_SIZE; @@ -64,13 +64,13 @@ struct DataRange { }; class BlobReadWriteDataTest: public BlobReadWriteTest, public WithParamInterface { public: - DataBlockFixture foregroundData; - DataBlockFixture backgroundData; + Data foregroundData; + Data backgroundData; BlobReadWriteDataTest() - : foregroundData(GetParam().count), - backgroundData(GetParam().blobsize) { - } + : foregroundData(DataFixture::generate(GetParam().count, 0)), + backgroundData(DataFixture::generate(GetParam().blobsize, 1)) { + } template void EXPECT_DATA_READS_AS_OUTSIDE_OF(const DataClass &expected, const Blob &blob, off_t start, size_t count) { @@ -146,7 +146,7 @@ TEST_P(BlobReadWriteDataTest, WriteWholeAndReadPart) { blob->write(this->backgroundData.data(), 0, GetParam().blobsize); Data read(GetParam().count); blob->read(read.data(), GetParam().offset, GetParam().count); - EXPECT_EQ(0, std::memcmp(read.data(), this->backgroundData.data()+GetParam().offset, GetParam().count)); + EXPECT_EQ(0, std::memcmp(read.data(), (uint8_t*)this->backgroundData.data()+GetParam().offset, GetParam().count)); } TEST_P(BlobReadWriteDataTest, WritePartAndReadWhole) { diff --git a/test/implementations/onblocks/BlobSizeTest.cpp b/test/implementations/onblocks/BlobSizeTest.cpp index 99cccaa9..16e5077c 100644 --- a/test/implementations/onblocks/BlobSizeTest.cpp +++ b/test/implementations/onblocks/BlobSizeTest.cpp @@ -1,13 +1,13 @@ #include "testutils/BlobStoreTest.h" #include -#include +#include using std::unique_ptr; using namespace blobstore; using blockstore::Key; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; class BlobSizeTest: public BlobStoreTest { public: @@ -122,7 +122,7 @@ class BlobSizeDataTest: public BlobSizeTest { public: BlobSizeDataTest() :ZEROES(LARGE_SIZE), - randomData(LARGE_SIZE) { + randomData(DataFixture::generate(LARGE_SIZE)) { ZEROES.FillWithZeroes(); } @@ -133,7 +133,7 @@ public: } Data ZEROES; - DataBlockFixture randomData; + Data randomData; }; TEST_F(BlobSizeDataTest, BlobIsZeroedOutAfterGrowing) { diff --git a/test/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp b/test/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp index c562c51c..e719dcc2 100644 --- a/test/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp +++ b/test/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp @@ -8,7 +8,7 @@ #include "messmer/blockstore/implementations/testfake/FakeBlockStore.h" #include "messmer/blockstore/implementations/testfake/FakeBlock.h" -#include +#include using ::testing::Test; using ::testing::WithParamInterface; @@ -17,7 +17,7 @@ using ::testing::Combine; using std::unique_ptr; using std::make_unique; using std::string; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; //TODO Split into multiple files @@ -49,7 +49,7 @@ public: ZEROES.FillWithZeroes(); - DataBlockFixture dataFixture(nodeStore->layout().maxBytesPerLeaf()); + Data dataFixture(DataFixture::generate(nodeStore->layout().maxBytesPerLeaf())); std::memcpy(randomData.data(), dataFixture.data(), randomData.size()); } @@ -282,11 +282,9 @@ public: Data foregroundData; Data backgroundData; - DataLeafNodeDataTest(): foregroundData(GetParam().count), backgroundData(GetParam().leafsize) { - DataBlockFixture _foregroundData(GetParam().count); - DataBlockFixture _backgroundData(GetParam().leafsize); - std::memcpy(foregroundData.data(), _foregroundData.data(), foregroundData.size()); - std::memcpy(backgroundData.data(), _backgroundData.data(), backgroundData.size()); + DataLeafNodeDataTest(): + foregroundData(DataFixture::generate(GetParam().count, 0)), + backgroundData(DataFixture::generate(GetParam().leafsize, 1)) { } void EXPECT_DATA_EQ(const Data &expected, const Data &actual) { diff --git a/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp b/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp index c3a12c2b..71838474 100644 --- a/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp +++ b/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp @@ -4,7 +4,7 @@ #include "messmer/blockstore/implementations/testfake/FakeBlockStore.h" #include "messmer/blockstore/implementations/testfake/FakeBlock.h" #include "../../../../implementations/onblocks/BlobStoreOnBlocks.h" -#include +#include using ::testing::Test; using ::testing::WithParamInterface; @@ -16,7 +16,7 @@ using std::string; using blockstore::BlockStore; using blockstore::testfake::FakeBlockStore; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; using namespace blobstore; using namespace blobstore::onblocks; using namespace blobstore::onblocks::datanodestore; @@ -60,7 +60,7 @@ TEST_P(DataNodeViewSizeTest, SizeIsStored) { } TEST_F(DataNodeViewTest, DataIsStored) { - DataBlockFixture randomData(DATASIZE_BYTES); + Data randomData = DataFixture::generate(DATASIZE_BYTES); auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); auto key = block->key(); { @@ -72,7 +72,7 @@ TEST_F(DataNodeViewTest, DataIsStored) { } TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { - DataBlockFixture randomData(DATASIZE_BYTES); + Data randomData = DataFixture::generate(DATASIZE_BYTES); auto block = blockStore->create(Data(BLOCKSIZE_BYTES)); auto key = block->key(); { diff --git a/test/implementations/onblocks/datatreestore/testutils/LeafDataFixture.h b/test/implementations/onblocks/datatreestore/testutils/LeafDataFixture.h index b36da93e..25d1b2b3 100644 --- a/test/implementations/onblocks/datatreestore/testutils/LeafDataFixture.h +++ b/test/implementations/onblocks/datatreestore/testutils/LeafDataFixture.h @@ -4,14 +4,14 @@ #include -#include +#include // A data fixture containing data for a leaf. // The class can fill this data into a given leaf // and check, whether the data stored in a given leaf is correct. class LeafDataFixture { public: - LeafDataFixture(int size, int iv = 0): _data(size, iv) {} + LeafDataFixture(int size, int iv = 0): _data(cpputils::DataFixture::generate(size, iv)) {} void FillInto(blobstore::onblocks::datanodestore::DataLeafNode *leaf) const { leaf->resize(_data.size()); @@ -34,7 +34,7 @@ private: leaf.read(data.data(), 0, leaf.numBytes()); return data; } - cpputils::DataBlockFixture _data; + cpputils::Data _data; }; #endif