Renamed VirtualTestFile to DataBlockFixture
This commit is contained in:
parent
32d28665a0
commit
c306d8be66
@ -1,8 +1,7 @@
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "test/testutils/TempFile.h"
|
||||
#include "test/testutils/VirtualTestFile.h"
|
||||
|
||||
#include "blobstore/implementations/ondisk/OnDiskBlob.h"
|
||||
#include "blobstore/implementations/ondisk/FileAlreadyExistsException.h"
|
||||
|
||||
@ -25,7 +24,7 @@ public:
|
||||
}
|
||||
TempFile file;
|
||||
|
||||
VirtualTestFile randomData;
|
||||
DataBlockFixture randomData;
|
||||
|
||||
unique_ptr<OnDiskBlob> CreateBlobAndLoadItFromDisk() {
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "test/testutils/TempFile.h"
|
||||
#include "test/testutils/VirtualTestFile.h"
|
||||
|
||||
#include "blobstore/implementations/ondisk/OnDiskBlob.h"
|
||||
#include "blobstore/utils/FileDoesntExistException.h"
|
||||
#include "blobstore/utils/Data.h"
|
||||
@ -31,7 +30,7 @@ public:
|
||||
data.StoreToFile(file.path());
|
||||
}
|
||||
|
||||
void StoreData(const VirtualTestFile &data) {
|
||||
void StoreData(const DataBlockFixture &data) {
|
||||
//TODO Implement data.StoreToFile(filepath) instead
|
||||
Data dataobj(data.size());
|
||||
std::memcpy(dataobj.data(), data.data(), data.size());
|
||||
@ -42,7 +41,7 @@ public:
|
||||
return OnDiskBlob::LoadFromDisk(file.path());
|
||||
}
|
||||
|
||||
void EXPECT_BLOB_DATA_EQ(const VirtualTestFile &expected, const OnDiskBlob &actual) {
|
||||
void EXPECT_BLOB_DATA_EQ(const DataBlockFixture &expected, const OnDiskBlob &actual) {
|
||||
EXPECT_EQ(expected.size(), actual.size());
|
||||
EXPECT_EQ(0, std::memcmp(expected.data(), actual.data(), expected.size()));
|
||||
}
|
||||
@ -58,7 +57,7 @@ TEST_P(OnDiskBlobLoadTest, FileSizeIsCorrect) {
|
||||
}
|
||||
|
||||
TEST_P(OnDiskBlobLoadTest, LoadedDataIsCorrect) {
|
||||
VirtualTestFile randomData(GetParam());
|
||||
DataBlockFixture randomData(GetParam());
|
||||
StoreData(randomData);
|
||||
|
||||
auto blob = LoadBlob();
|
||||
|
@ -2,8 +2,8 @@
|
||||
#ifndef TEST_BLOBSTORE_IMPLEMENTATIONS_TESTUTILS_BLOBSTORETEST_H_
|
||||
#define TEST_BLOBSTORE_IMPLEMENTATIONS_TESTUTILS_BLOBSTORETEST_H_
|
||||
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include "test/testutils/TempDir.h"
|
||||
#include "test/testutils/VirtualTestFile.h"
|
||||
#include "blobstore/interface/BlobStore.h"
|
||||
#include "blobstore/utils/RandomKeyGenerator.h"
|
||||
|
||||
@ -53,21 +53,21 @@ public:
|
||||
}
|
||||
|
||||
void TestLoadedBlobIsCorrect() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
auto loaded_blob = StoreDataToBlobAndLoadIt(randomData);
|
||||
EXPECT_EQ(size, loaded_blob->size());
|
||||
EXPECT_EQ(0, std::memcmp(randomData.data(), loaded_blob->data(), size));
|
||||
}
|
||||
|
||||
void TestLoadedBlobIsCorrectWhenLoadedDirectlyAfterFlushing() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
auto loaded_blob = StoreDataToBlobAndLoadItDirectlyAfterFlushing(randomData);
|
||||
EXPECT_EQ(size, loaded_blob->size());
|
||||
EXPECT_EQ(0, std::memcmp(randomData.data(), loaded_blob->data(), size));
|
||||
}
|
||||
|
||||
void TestAfterCreate_FlushingDoesntChangeBlob() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
auto blob = CreateBlob();
|
||||
WriteDataToBlob(blob.get(), randomData);
|
||||
blob->flush();
|
||||
@ -76,7 +76,7 @@ public:
|
||||
}
|
||||
|
||||
void TestAfterLoad_FlushingDoesntChangeBlob() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
auto blob = CreateBlobAndLoadIt();
|
||||
WriteDataToBlob(blob.get(), randomData);
|
||||
blob->flush();
|
||||
@ -85,7 +85,7 @@ public:
|
||||
}
|
||||
|
||||
void TestAfterCreate_FlushesWhenDestructed() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
std::string key;
|
||||
{
|
||||
auto blob = blobStore->create(size);
|
||||
@ -97,7 +97,7 @@ public:
|
||||
}
|
||||
|
||||
void TestAfterLoad_FlushesWhenDestructed() {
|
||||
VirtualTestFile randomData(size);
|
||||
DataBlockFixture randomData(size);
|
||||
std::string key;
|
||||
{
|
||||
key = blobStore->create(size).key;
|
||||
@ -136,18 +136,18 @@ private:
|
||||
return ZEROES;
|
||||
}
|
||||
|
||||
std::unique_ptr<blobstore::Blob> StoreDataToBlobAndLoadIt(const VirtualTestFile &data) {
|
||||
std::unique_ptr<blobstore::Blob> StoreDataToBlobAndLoadIt(const DataBlockFixture &data) {
|
||||
std::string key = StoreDataToBlobAndGetKey(data);
|
||||
return blobStore->load(key);
|
||||
}
|
||||
|
||||
std::string StoreDataToBlobAndGetKey(const VirtualTestFile &data) {
|
||||
std::string StoreDataToBlobAndGetKey(const DataBlockFixture &data) {
|
||||
auto blob = blobStore->create(data.size());
|
||||
std::memcpy(blob.blob->data(), data.data(), data.size());
|
||||
return blob.key;
|
||||
}
|
||||
|
||||
std::unique_ptr<blobstore::Blob> StoreDataToBlobAndLoadItDirectlyAfterFlushing(const VirtualTestFile &data) {
|
||||
std::unique_ptr<blobstore::Blob> StoreDataToBlobAndLoadItDirectlyAfterFlushing(const DataBlockFixture &data) {
|
||||
auto blob = blobStore->create(data.size());
|
||||
std::memcpy(blob.blob->data(), data.data(), data.size());
|
||||
blob.blob->flush();
|
||||
@ -163,11 +163,11 @@ private:
|
||||
return blobStore->create(size).blob;
|
||||
}
|
||||
|
||||
void WriteDataToBlob(blobstore::Blob *blob, const VirtualTestFile &randomData) {
|
||||
void WriteDataToBlob(blobstore::Blob *blob, const DataBlockFixture &randomData) {
|
||||
std::memcpy(blob->data(), randomData.data(), randomData.size());
|
||||
}
|
||||
|
||||
void EXPECT_BLOB_DATA_CORRECT(const blobstore::Blob &blob, const VirtualTestFile &randomData) {
|
||||
void EXPECT_BLOB_DATA_CORRECT(const blobstore::Blob &blob, const DataBlockFixture &randomData) {
|
||||
EXPECT_EQ(randomData.size(), blob.size());
|
||||
EXPECT_EQ(0, std::memcmp(randomData.data(), blob.data(), randomData.size()));
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
#ifndef TEST_BLOBSTORE_IMPLEMENTATIONS_TESTUTILS_BLOBSTOREWITHRANDOMKEYSTEST_H_
|
||||
#define TEST_BLOBSTORE_IMPLEMENTATIONS_TESTUTILS_BLOBSTOREWITHRANDOMKEYSTEST_H_
|
||||
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include "test/testutils/TempDir.h"
|
||||
#include "test/testutils/VirtualTestFile.h"
|
||||
#include "blobstore/interface/BlobStore.h"
|
||||
#include "blobstore/utils/RandomKeyGenerator.h"
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "blobstore/utils/Data.h"
|
||||
#include "blobstore/utils/FileDoesntExistException.h"
|
||||
|
||||
#include "test/testutils/VirtualTestFile.h"
|
||||
#include "test/testutils/TempFile.h"
|
||||
|
||||
#include <fstream>
|
||||
@ -28,12 +28,12 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void FillData(const VirtualTestFile &fillData, Data *data) {
|
||||
void FillData(const DataBlockFixture &fillData, Data *data) {
|
||||
ASSERT_EQ(fillData.size(), data->size());
|
||||
std::memcpy(data->data(), fillData.data(), fillData.size());
|
||||
}
|
||||
|
||||
void EXPECT_DATA_CORRECT(const VirtualTestFile &expectedData, const Data &data) {
|
||||
void EXPECT_DATA_CORRECT(const DataBlockFixture &expectedData, const Data &data) {
|
||||
ASSERT_EQ(expectedData.size(), data.size());
|
||||
EXPECT_EQ(0, std::memcmp(expectedData.data(), data.data(), expectedData.size()));
|
||||
}
|
||||
@ -41,7 +41,7 @@ public:
|
||||
|
||||
class DataTestWithSizeParam: public DataTest, public WithParamInterface<size_t> {
|
||||
public:
|
||||
VirtualTestFile randomData;
|
||||
DataBlockFixture randomData;
|
||||
|
||||
DataTestWithSizeParam(): randomData(GetParam()) {}
|
||||
|
||||
@ -134,7 +134,7 @@ TEST_F(DataTest, InitializeWithZeroes) {
|
||||
|
||||
TEST_F(DataTest, FillModifiedDataWithZeroes) {
|
||||
Data data(10*1024);
|
||||
VirtualTestFile randomData(10*1024);
|
||||
DataBlockFixture randomData(10*1024);
|
||||
FillData(randomData, &data);
|
||||
EXPECT_FALSE(DataIsZeroes(data));
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
#include "VirtualTestFile.h"
|
||||
|
||||
#include <test/testutils/DataBlockFixture.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
using std::min;
|
||||
|
||||
VirtualTestFile::VirtualTestFile(size_t size, long long int IV): _fileData(new char[size]), _size(size) {
|
||||
DataBlockFixture::DataBlockFixture(size_t size, long long int IV): _fileData(new char[size]), _size(size) {
|
||||
fillFileWithRandomData(IV);
|
||||
}
|
||||
|
||||
VirtualTestFile::~VirtualTestFile() {
|
||||
DataBlockFixture::~DataBlockFixture() {
|
||||
delete[] _fileData;
|
||||
}
|
||||
|
||||
void VirtualTestFile::fillFileWithRandomData(long long int IV) {
|
||||
void DataBlockFixture::fillFileWithRandomData(long long int IV) {
|
||||
long long int val = IV;
|
||||
for(size_t i=0; i<_size/sizeof(long long int); ++i) {
|
||||
//MMIX linear congruential generator
|
||||
@ -23,47 +22,47 @@ void VirtualTestFile::fillFileWithRandomData(long long int IV) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *VirtualTestFile::data() const {
|
||||
const char *DataBlockFixture::data() const {
|
||||
return _fileData;
|
||||
}
|
||||
|
||||
int VirtualTestFile::read(void *buf, size_t count, off_t offset) {
|
||||
int DataBlockFixture::read(void *buf, size_t count, off_t offset) {
|
||||
size_t realCount = min(count, _size - offset);
|
||||
memcpy(buf, _fileData+offset, realCount);
|
||||
return realCount;
|
||||
}
|
||||
|
||||
size_t VirtualTestFile::size() const {
|
||||
size_t DataBlockFixture::size() const {
|
||||
return _size;
|
||||
}
|
||||
|
||||
bool VirtualTestFile::fileContentEqual(const char *content, size_t count, off_t offset) {
|
||||
bool DataBlockFixture::fileContentEqual(const char *content, size_t count, off_t offset) {
|
||||
return 0 == memcmp(content, _fileData + offset, count);
|
||||
}
|
||||
|
||||
VirtualTestFileWriteable::VirtualTestFileWriteable(size_t size, long long int IV)
|
||||
:VirtualTestFile(size, IV), _originalSize(size) {
|
||||
DataBlockFixtureWriteable::DataBlockFixtureWriteable(size_t size, long long int IV)
|
||||
:DataBlockFixture(size, IV), _originalSize(size) {
|
||||
_originalFileData = new char[size];
|
||||
memcpy(_originalFileData, _fileData, size);
|
||||
}
|
||||
|
||||
VirtualTestFileWriteable::~VirtualTestFileWriteable() {
|
||||
DataBlockFixtureWriteable::~DataBlockFixtureWriteable() {
|
||||
delete[] _originalFileData;
|
||||
}
|
||||
|
||||
void VirtualTestFileWriteable::write(const void *buf, size_t count, off_t offset) {
|
||||
void DataBlockFixtureWriteable::write(const void *buf, size_t count, off_t offset) {
|
||||
extendFileSizeIfNecessary(count + offset);
|
||||
|
||||
memcpy(_fileData+offset, buf, count);
|
||||
}
|
||||
|
||||
void VirtualTestFileWriteable::extendFileSizeIfNecessary(size_t size) {
|
||||
void DataBlockFixtureWriteable::extendFileSizeIfNecessary(size_t size) {
|
||||
if (size > _size) {
|
||||
extendFileSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualTestFileWriteable::extendFileSize(size_t size) {
|
||||
void DataBlockFixtureWriteable::extendFileSize(size_t size) {
|
||||
char *newfile = new char[size];
|
||||
memcpy(newfile, _fileData, _size);
|
||||
delete[] _fileData;
|
||||
@ -71,10 +70,10 @@ void VirtualTestFileWriteable::extendFileSize(size_t size) {
|
||||
_size = size;
|
||||
}
|
||||
|
||||
bool VirtualTestFileWriteable::sizeUnchanged() {
|
||||
bool DataBlockFixtureWriteable::sizeUnchanged() {
|
||||
return _size == _originalSize;
|
||||
}
|
||||
|
||||
bool VirtualTestFileWriteable::regionUnchanged(off_t offset, size_t count) {
|
||||
bool DataBlockFixtureWriteable::regionUnchanged(off_t offset, size_t count) {
|
||||
return 0 == memcmp(_fileData+offset, _originalFileData+offset, count);
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
#ifndef TEST_TESTUTILS_VIRTUALTESTFILE_H_
|
||||
#define TEST_TESTUTILS_VIRTUALTESTFILE_H_
|
||||
#ifndef TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
||||
#define TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
//TODO Rename to RandomData or something more speaking about what this class does.
|
||||
class VirtualTestFile {
|
||||
class DataBlockFixture {
|
||||
public:
|
||||
VirtualTestFile(size_t size, long long int IV = 1);
|
||||
virtual ~VirtualTestFile();
|
||||
DataBlockFixture(size_t size, long long int IV = 1);
|
||||
virtual ~DataBlockFixture();
|
||||
|
||||
int read(void *buf, size_t count, off_t offset);
|
||||
|
||||
@ -27,10 +26,10 @@ private:
|
||||
void fillFileWithRandomData(long long int IV);
|
||||
};
|
||||
|
||||
class VirtualTestFileWriteable: public VirtualTestFile {
|
||||
class DataBlockFixtureWriteable: public DataBlockFixture {
|
||||
public:
|
||||
VirtualTestFileWriteable(size_t size, long long int IV = 1);
|
||||
virtual ~VirtualTestFileWriteable();
|
||||
DataBlockFixtureWriteable(size_t size, long long int IV = 1);
|
||||
virtual ~DataBlockFixtureWriteable();
|
||||
|
||||
void write(const void *buf, size_t count, off_t offset);
|
||||
|
Loading…
x
Reference in New Issue
Block a user