diff --git a/test/implementations/encrypted/CipherTest.cpp b/test/implementations/encrypted/CipherTest.cpp index ec84837b..620e60db 100644 --- a/test/implementations/encrypted/CipherTest.cpp +++ b/test/implementations/encrypted/CipherTest.cpp @@ -3,14 +3,14 @@ #include "../../../implementations/encrypted/ciphers/AES256_GCM.h" #include "../../../implementations/encrypted/ciphers/Cipher.h" -#include +#include #include #include using namespace blockstore::encrypted; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; template class CipherTest: public ::testing::Test { @@ -19,7 +19,7 @@ public: typename Cipher::EncryptionKey encKey = createRandomKey(); static typename Cipher::EncryptionKey createRandomKey(int seed = 0) { - DataBlockFixture data(Cipher::EncryptionKey::BINARY_LENGTH, seed); + Data data = DataFixture::generate(Cipher::EncryptionKey::BINARY_LENGTH, seed); return Cipher::EncryptionKey::FromBinary(data.data()); } @@ -50,16 +50,11 @@ public: } static Data CreateZeroes(unsigned int size) { - Data zeroes(size); - zeroes.FillWithZeroes(); - return zeroes; + return std::move(Data(size).FillWithZeroes()); } static Data CreateData(unsigned int size, unsigned int seed = 0) { - DataBlockFixture data(size, seed); - Data result(size); - std::memcpy(result.data(), data.data(), size); - return result; + return DataFixture::generate(size, seed); } }; diff --git a/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp b/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp index 9ac4c602..2ef0b2a2 100644 --- a/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp +++ b/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockFlushTest.cpp @@ -1,6 +1,6 @@ #include "../../../../implementations/ondisk/FileAlreadyExistsException.h" #include "../../../../implementations/ondisk/OnDiskBlock.h" -#include +#include #include "google/gtest/gtest.h" #include @@ -12,7 +12,7 @@ using ::testing::Values; using std::unique_ptr; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; using cpputils::TempFile; using cpputils::TempDir; @@ -28,13 +28,13 @@ public: : dir(), key(Key::FromString("1491BB4932A389EE14BC7090AC772972")), file(dir.path() / key.ToString(), false), - randomData(GetParam()) { + randomData(DataFixture::generate(GetParam())) { } TempDir dir; Key key; TempFile file; - DataBlockFixture randomData; + Data randomData; unique_ptr CreateBlockAndLoadItFromDisk() { { diff --git a/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp b/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp index 364a2033..8fdf8ff6 100644 --- a/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp +++ b/test/implementations/ondisk/OnDiskBlockTest/OnDiskBlockLoadTest.cpp @@ -1,5 +1,5 @@ #include "../../../../implementations/ondisk/OnDiskBlock.h" -#include +#include #include "../../../../utils/FileDoesntExistException.h" #include "google/gtest/gtest.h" @@ -16,7 +16,7 @@ using std::ofstream; using std::unique_ptr; using std::ios; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; using cpputils::TempFile; using cpputils::TempDir; @@ -41,18 +41,15 @@ public: data.StoreToFile(file.path()); } - void StoreData(const DataBlockFixture &data) { - //TODO Implement data.StoreToFile(filepath) instead - Data dataobj(data.size()); - std::memcpy(dataobj.data(), data.data(), data.size()); - dataobj.StoreToFile(file.path()); + void StoreData(const Data &data) { + data.StoreToFile(file.path()); } unique_ptr LoadBlock() { return OnDiskBlock::LoadFromDisk(dir.path(), key); } - void EXPECT_BLOCK_DATA_EQ(const DataBlockFixture &expected, const OnDiskBlock &actual) { + void EXPECT_BLOCK_DATA_EQ(const Data &expected, const OnDiskBlock &actual) { EXPECT_EQ(expected.size(), actual.size()); EXPECT_EQ(0, std::memcmp(expected.data(), actual.data(), expected.size())); } @@ -68,7 +65,7 @@ TEST_P(OnDiskBlockLoadTest, FileSizeIsCorrect) { } TEST_P(OnDiskBlockLoadTest, LoadedDataIsCorrect) { - DataBlockFixture randomData(GetParam()); + Data randomData = DataFixture::generate(GetParam()); StoreData(randomData); auto block = LoadBlock(); diff --git a/test/interface/helpers/BlockStoreWithRandomKeysTest.cpp b/test/interface/helpers/BlockStoreWithRandomKeysTest.cpp index 78a8535b..d4c0513e 100644 --- a/test/interface/helpers/BlockStoreWithRandomKeysTest.cpp +++ b/test/interface/helpers/BlockStoreWithRandomKeysTest.cpp @@ -1,7 +1,7 @@ #include "../../../interface/helpers/BlockStoreWithRandomKeys.h" #include "google/gtest/gtest.h" #include "google/gmock/gmock.h" -#include +#include using ::testing::Test; using ::testing::_; @@ -14,7 +14,7 @@ using std::string; using std::unique_ptr; using std::make_unique; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; using namespace blockstore; @@ -49,7 +49,7 @@ public: const blockstore::Key key = Key::FromString("1491BB4932A389EE14BC7090AC772972"); Data createDataWithSize(size_t size) { - DataBlockFixture fixture(size); + Data fixture(DataFixture::generate(size)); Data data(size); std::memcpy(data.data(), fixture.data(), size); return data; diff --git a/test/testutils/BlockStoreTest_Data.h b/test/testutils/BlockStoreTest_Data.h index 30acbff1..daac33d8 100644 --- a/test/testutils/BlockStoreTest_Data.h +++ b/test/testutils/BlockStoreTest_Data.h @@ -12,11 +12,8 @@ public: BlockStoreDataParametrizedTest(std::unique_ptr blockStore_, const DataRange &testData_) : blockStore(std::move(blockStore_)), testData(testData_), - foregroundData(testData.count), backgroundData(testData.blocksize) { - cpputils::DataBlockFixture _foregroundData(testData.count); - cpputils::DataBlockFixture _backgroundData(testData.blocksize); - std::memcpy(foregroundData.data(), _foregroundData.data(), foregroundData.size()); - std::memcpy(backgroundData.data(), _backgroundData.data(), backgroundData.size()); + foregroundData(cpputils::DataFixture::generate(testData.count, 0)), + backgroundData(cpputils::DataFixture::generate(testData.blocksize, 1)) { } void TestWriteAndReadImmediately() { diff --git a/test/testutils/BlockStoreTest_Size.h b/test/testutils/BlockStoreTest_Size.h index 02679e20..20ee3fbb 100644 --- a/test/testutils/BlockStoreTest_Size.h +++ b/test/testutils/BlockStoreTest_Size.h @@ -1,7 +1,7 @@ // This file is meant to be included by BlockStoreTest.h only #include -#include +#include class BlockStoreSizeParameterizedTest { public: @@ -19,39 +19,34 @@ public: } void TestCreatedBlockData() { - cpputils::DataBlockFixture dataFixture(size); - cpputils::Data data(size); - std::memcpy(data.data(), dataFixture.data(), size); - auto block = blockStore->create(data); - EXPECT_EQ(0, std::memcmp(dataFixture.data(), block->data(), size)); - + cpputils::Data data = cpputils::DataFixture::generate(size); + auto block = blockStore->create(data); + EXPECT_EQ(0, std::memcmp(data.data(), block->data(), size)); } void TestLoadingUnchangedBlockData() { - cpputils::DataBlockFixture dataFixture(size); - cpputils::Data data(size); - std::memcpy(data.data(), dataFixture.data(), size); - blockstore::Key key = blockStore->create(data)->key(); + cpputils::Data data = cpputils::DataFixture::generate(size); + blockstore::Key key = blockStore->create(data)->key(); auto loaded_block = blockStore->load(key); - EXPECT_EQ(0, std::memcmp(dataFixture.data(), loaded_block->data(), size)); + EXPECT_EQ(0, std::memcmp(data.data(), loaded_block->data(), size)); } void TestLoadedBlockIsCorrect() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); auto loaded_block = StoreDataToBlockAndLoadIt(randomData); EXPECT_EQ(size, loaded_block->size()); EXPECT_EQ(0, std::memcmp(randomData.data(), loaded_block->data(), size)); } void TestLoadedBlockIsCorrectWhenLoadedDirectlyAfterFlushing() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); auto loaded_block = StoreDataToBlockAndLoadItDirectlyAfterFlushing(randomData); EXPECT_EQ(size, loaded_block->size()); EXPECT_EQ(0, std::memcmp(randomData.data(), loaded_block->data(), size)); } void TestAfterCreate_FlushingDoesntChangeBlock() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); auto block = CreateBlock(); WriteDataToBlock(block.get(), randomData); block->flush(); @@ -60,7 +55,7 @@ public: } void TestAfterLoad_FlushingDoesntChangeBlock() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); auto block = CreateBlockAndLoadIt(); WriteDataToBlock(block.get(), randomData); block->flush(); @@ -69,7 +64,7 @@ public: } void TestAfterCreate_FlushesWhenDestructed() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); blockstore::Key key = key; { auto block = blockStore->create(cpputils::Data(size)); @@ -81,7 +76,7 @@ public: } void TestAfterLoad_FlushesWhenDestructed() { - cpputils::DataBlockFixture randomData(size); + cpputils::Data randomData = cpputils::DataFixture::generate(size); blockstore::Key key = key; { key = CreateBlock()->key(); @@ -109,20 +104,16 @@ private: return ZEROES; } - std::unique_ptr StoreDataToBlockAndLoadIt(const cpputils::DataBlockFixture &data) { + std::unique_ptr StoreDataToBlockAndLoadIt(const cpputils::Data &data) { blockstore::Key key = StoreDataToBlockAndGetKey(data); return blockStore->load(key); } - blockstore::Key StoreDataToBlockAndGetKey(const cpputils::DataBlockFixture &dataFixture) { - cpputils::Data data(dataFixture.size()); - std::memcpy(data.data(), dataFixture.data(), dataFixture.size()); + blockstore::Key StoreDataToBlockAndGetKey(const cpputils::Data &data) { return blockStore->create(data)->key(); } - std::unique_ptr StoreDataToBlockAndLoadItDirectlyAfterFlushing(const cpputils::DataBlockFixture &dataFixture) { - cpputils::Data data(dataFixture.size()); - std::memcpy(data.data(), dataFixture.data(), dataFixture.size()); + std::unique_ptr StoreDataToBlockAndLoadItDirectlyAfterFlushing(const cpputils::Data &data) { auto block = blockStore->create(data); block->flush(); return blockStore->load(block->key()); @@ -137,11 +128,11 @@ private: return blockStore->create(cpputils::Data(size)); } - void WriteDataToBlock(blockstore::Block *block, const cpputils::DataBlockFixture &randomData) { + void WriteDataToBlock(blockstore::Block *block, const cpputils::Data &randomData) { block->write(randomData.data(), 0, randomData.size()); } - void EXPECT_BLOCK_DATA_CORRECT(const blockstore::Block &block, const cpputils::DataBlockFixture &randomData) { + void EXPECT_BLOCK_DATA_CORRECT(const blockstore::Block &block, const cpputils::Data &randomData) { EXPECT_EQ(randomData.size(), block.size()); EXPECT_EQ(0, std::memcmp(randomData.data(), block.data(), randomData.size())); } diff --git a/test/utils/BlockStoreUtilsTest.cpp b/test/utils/BlockStoreUtilsTest.cpp index 4d0aca82..adc72ad8 100644 --- a/test/utils/BlockStoreUtilsTest.cpp +++ b/test/utils/BlockStoreUtilsTest.cpp @@ -1,5 +1,5 @@ #include "../../implementations/testfake/FakeBlockStore.h" -#include +#include #include "../../utils/BlockStoreUtils.h" #include "google/gtest/gtest.h" @@ -12,7 +12,7 @@ using ::testing::Values; using std::make_unique; using std::unique_ptr; using cpputils::Data; -using cpputils::DataBlockFixture; +using cpputils::DataFixture; using namespace blockstore; using namespace blockstore::utils; @@ -24,13 +24,13 @@ public: unsigned int SIZE = 1024 * 1024; BlockStoreUtilsTest(): ZEROES(SIZE), - dataFixture(SIZE), + dataFixture(DataFixture::generate(SIZE)), blockStore(make_unique()) { ZEROES.FillWithZeroes(); } Data ZEROES; - DataBlockFixture dataFixture; + Data dataFixture; unique_ptr blockStore; };