Use cpputils::DataFixture instead of DataBlockFixture
This commit is contained in:
parent
3e12c771a1
commit
a2c89ed73a
@ -3,14 +3,14 @@
|
||||
#include "../../../implementations/encrypted/ciphers/AES256_GCM.h"
|
||||
#include "../../../implementations/encrypted/ciphers/Cipher.h"
|
||||
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
#include <messmer/cpp-utils/data/Data.h>
|
||||
|
||||
#include <boost/optional/optional_io.hpp>
|
||||
|
||||
using namespace blockstore::encrypted;
|
||||
using cpputils::Data;
|
||||
using cpputils::DataBlockFixture;
|
||||
using cpputils::DataFixture;
|
||||
|
||||
template<class Cipher>
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "../../../../implementations/ondisk/FileAlreadyExistsException.h"
|
||||
#include "../../../../implementations/ondisk/OnDiskBlock.h"
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
#include "google/gtest/gtest.h"
|
||||
|
||||
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
||||
@ -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<OnDiskBlock> CreateBlockAndLoadItFromDisk() {
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "../../../../implementations/ondisk/OnDiskBlock.h"
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
#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<OnDiskBlock> 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();
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../../../interface/helpers/BlockStoreWithRandomKeys.h"
|
||||
#include "google/gtest/gtest.h"
|
||||
#include "google/gmock/gmock.h"
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
|
||||
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;
|
||||
|
@ -12,11 +12,8 @@ public:
|
||||
BlockStoreDataParametrizedTest(std::unique_ptr<blockstore::BlockStore> 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() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This file is meant to be included by BlockStoreTest.h only
|
||||
|
||||
#include <messmer/cpp-utils/data/Data.h>
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
|
||||
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<blockstore::Block> StoreDataToBlockAndLoadIt(const cpputils::DataBlockFixture &data) {
|
||||
std::unique_ptr<blockstore::Block> 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<blockstore::Block> StoreDataToBlockAndLoadItDirectlyAfterFlushing(const cpputils::DataBlockFixture &dataFixture) {
|
||||
cpputils::Data data(dataFixture.size());
|
||||
std::memcpy(data.data(), dataFixture.data(), dataFixture.size());
|
||||
std::unique_ptr<blockstore::Block> 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()));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "../../implementations/testfake/FakeBlockStore.h"
|
||||
#include <messmer/cpp-utils/data/DataBlockFixture.h>
|
||||
#include <messmer/cpp-utils/data/DataFixture.h>
|
||||
#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<FakeBlockStore>()) {
|
||||
ZEROES.FillWithZeroes();
|
||||
}
|
||||
|
||||
Data ZEROES;
|
||||
DataBlockFixture dataFixture;
|
||||
Data dataFixture;
|
||||
unique_ptr<BlockStore> blockStore;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user