Renamed VirtualTestFile to DataBlockFixture
This commit is contained in:
parent
2d59c93d80
commit
250913ea62
@ -1,7 +1,6 @@
|
|||||||
|
#include <test/testutils/DataBlockFixture.h>
|
||||||
#include "testutils/FuseReadTest.h"
|
#include "testutils/FuseReadTest.h"
|
||||||
|
|
||||||
#include "test/testutils/VirtualTestFile.h"
|
|
||||||
|
|
||||||
#include "fspp/fuse/FuseErrnoException.h"
|
#include "fspp/fuse/FuseErrnoException.h"
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -45,12 +44,12 @@ struct TestData {
|
|||||||
// memory region and check methods to check for data equality of a region.
|
// memory region and check methods to check for data equality of a region.
|
||||||
class FuseReadReturnedDataTest: public FuseReadTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
class FuseReadReturnedDataTest: public FuseReadTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
||||||
public:
|
public:
|
||||||
unique_ptr<VirtualTestFile> testFile;
|
unique_ptr<DataBlockFixture> testFile;
|
||||||
TestData testData;
|
TestData testData;
|
||||||
|
|
||||||
FuseReadReturnedDataTest() {
|
FuseReadReturnedDataTest() {
|
||||||
testData = GetParam();
|
testData = GetParam();
|
||||||
testFile = make_unique<VirtualTestFile>(testData.fileSize());
|
testFile = make_unique<DataBlockFixture>(testData.fileSize());
|
||||||
|
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
||||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
#include <test/testutils/DataBlockFixture.h>
|
||||||
#include "testutils/FuseWriteTest.h"
|
#include "testutils/FuseWriteTest.h"
|
||||||
|
|
||||||
#include "test/testutils/VirtualTestFile.h"
|
|
||||||
|
|
||||||
#include "fspp/fuse/FuseErrnoException.h"
|
#include "fspp/fuse/FuseErrnoException.h"
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -44,12 +43,12 @@ struct TestData {
|
|||||||
// memory region and check methods to check for data equality of a region.
|
// memory region and check methods to check for data equality of a region.
|
||||||
class FuseWriteDataTest: public FuseWriteTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
class FuseWriteDataTest: public FuseWriteTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
||||||
public:
|
public:
|
||||||
unique_ptr<VirtualTestFileWriteable> testFile;
|
unique_ptr<DataBlockFixtureWriteable> testFile;
|
||||||
TestData testData;
|
TestData testData;
|
||||||
|
|
||||||
FuseWriteDataTest() {
|
FuseWriteDataTest() {
|
||||||
testData = GetParam();
|
testData = GetParam();
|
||||||
testFile = make_unique<VirtualTestFileWriteable>(testData.fileSize(), 1);
|
testFile = make_unique<DataBlockFixtureWriteable>(testData.fileSize(), 1);
|
||||||
|
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
||||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||||
@ -66,14 +65,14 @@ INSTANTIATE_TEST_CASE_P(FuseWriteDataTest, FuseWriteDataTest, Combine(Values(0,1
|
|||||||
|
|
||||||
|
|
||||||
TEST_P(FuseWriteDataTest, DataWasCorrectlyWritten) {
|
TEST_P(FuseWriteDataTest, DataWasCorrectlyWritten) {
|
||||||
VirtualTestFile randomWriteData(testData.count, 2);
|
DataBlockFixture randomWriteData(testData.count, 2);
|
||||||
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
||||||
|
|
||||||
EXPECT_TRUE(testFile->fileContentEqual(randomWriteData.data(), testData.count, testData.offset));
|
EXPECT_TRUE(testFile->fileContentEqual(randomWriteData.data(), testData.count, testData.offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(FuseWriteDataTest, RestOfFileIsUnchanged) {
|
TEST_P(FuseWriteDataTest, RestOfFileIsUnchanged) {
|
||||||
VirtualTestFile randomWriteData(testData.count, 2);
|
DataBlockFixture randomWriteData(testData.count, 2);
|
||||||
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
||||||
|
|
||||||
EXPECT_TRUE(testFile->sizeUnchanged());
|
EXPECT_TRUE(testFile->sizeUnchanged());
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
#include <test/testutils/DataBlockFixture.h>
|
||||||
#include "testutils/FuseWriteTest.h"
|
#include "testutils/FuseWriteTest.h"
|
||||||
|
|
||||||
#include "test/testutils/VirtualTestFile.h"
|
|
||||||
|
|
||||||
#include "fspp/fuse/FuseErrnoException.h"
|
#include "fspp/fuse/FuseErrnoException.h"
|
||||||
|
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
@ -21,8 +20,8 @@ public:
|
|||||||
size_t WRITESIZE;
|
size_t WRITESIZE;
|
||||||
size_t OFFSET;
|
size_t OFFSET;
|
||||||
|
|
||||||
VirtualTestFileWriteable testFile;
|
DataBlockFixtureWriteable testFile;
|
||||||
VirtualTestFile writeData;
|
DataBlockFixture writeData;
|
||||||
|
|
||||||
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
|
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
|
||||||
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(FILESIZE), writeData(WRITESIZE) {
|
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(FILESIZE), writeData(WRITESIZE) {
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
#include "VirtualTestFile.h"
|
#include <test/testutils/DataBlockFixture.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
using std::min;
|
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);
|
fillFileWithRandomData(IV);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualTestFile::~VirtualTestFile() {
|
DataBlockFixture::~DataBlockFixture() {
|
||||||
delete[] _fileData;
|
delete[] _fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualTestFile::fillFileWithRandomData(long long int IV) {
|
void DataBlockFixture::fillFileWithRandomData(long long int IV) {
|
||||||
long long int val = IV;
|
long long int val = IV;
|
||||||
for(size_t i=0; i<_size/sizeof(long long int); ++i) {
|
for(size_t i=0; i<_size/sizeof(long long int); ++i) {
|
||||||
//MMIX linear congruential generator
|
//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;
|
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);
|
size_t realCount = min(count, _size - offset);
|
||||||
memcpy(buf, _fileData+offset, realCount);
|
memcpy(buf, _fileData+offset, realCount);
|
||||||
return realCount;
|
return realCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t VirtualTestFile::size() const {
|
size_t DataBlockFixture::size() const {
|
||||||
return _size;
|
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);
|
return 0 == memcmp(content, _fileData + offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualTestFileWriteable::VirtualTestFileWriteable(size_t size, long long int IV)
|
DataBlockFixtureWriteable::DataBlockFixtureWriteable(size_t size, long long int IV)
|
||||||
:VirtualTestFile(size, IV), _originalSize(size) {
|
:DataBlockFixture(size, IV), _originalSize(size) {
|
||||||
_originalFileData = new char[size];
|
_originalFileData = new char[size];
|
||||||
memcpy(_originalFileData, _fileData, size);
|
memcpy(_originalFileData, _fileData, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualTestFileWriteable::~VirtualTestFileWriteable() {
|
DataBlockFixtureWriteable::~DataBlockFixtureWriteable() {
|
||||||
delete[] _originalFileData;
|
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);
|
extendFileSizeIfNecessary(count + offset);
|
||||||
|
|
||||||
memcpy(_fileData+offset, buf, count);
|
memcpy(_fileData+offset, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualTestFileWriteable::extendFileSizeIfNecessary(size_t size) {
|
void DataBlockFixtureWriteable::extendFileSizeIfNecessary(size_t size) {
|
||||||
if (size > _size) {
|
if (size > _size) {
|
||||||
extendFileSize(size);
|
extendFileSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualTestFileWriteable::extendFileSize(size_t size) {
|
void DataBlockFixtureWriteable::extendFileSize(size_t size) {
|
||||||
char *newfile = new char[size];
|
char *newfile = new char[size];
|
||||||
memcpy(newfile, _fileData, _size);
|
memcpy(newfile, _fileData, _size);
|
||||||
delete[] _fileData;
|
delete[] _fileData;
|
||||||
@ -71,10 +70,10 @@ void VirtualTestFileWriteable::extendFileSize(size_t size) {
|
|||||||
_size = size;
|
_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualTestFileWriteable::sizeUnchanged() {
|
bool DataBlockFixtureWriteable::sizeUnchanged() {
|
||||||
return _size == _originalSize;
|
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);
|
return 0 == memcmp(_fileData+offset, _originalFileData+offset, count);
|
||||||
}
|
}
|
@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef TEST_TESTUTILS_VIRTUALTESTFILE_H_
|
#ifndef TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
||||||
#define TEST_TESTUTILS_VIRTUALTESTFILE_H_
|
#define TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
//TODO Rename to RandomData or something more speaking about what this class does.
|
class DataBlockFixture {
|
||||||
class VirtualTestFile {
|
|
||||||
public:
|
public:
|
||||||
VirtualTestFile(size_t size, long long int IV = 1);
|
DataBlockFixture(size_t size, long long int IV = 1);
|
||||||
virtual ~VirtualTestFile();
|
virtual ~DataBlockFixture();
|
||||||
|
|
||||||
int read(void *buf, size_t count, off_t offset);
|
int read(void *buf, size_t count, off_t offset);
|
||||||
|
|
||||||
@ -27,10 +26,10 @@ private:
|
|||||||
void fillFileWithRandomData(long long int IV);
|
void fillFileWithRandomData(long long int IV);
|
||||||
};
|
};
|
||||||
|
|
||||||
class VirtualTestFileWriteable: public VirtualTestFile {
|
class DataBlockFixtureWriteable: public DataBlockFixture {
|
||||||
public:
|
public:
|
||||||
VirtualTestFileWriteable(size_t size, long long int IV = 1);
|
DataBlockFixtureWriteable(size_t size, long long int IV = 1);
|
||||||
virtual ~VirtualTestFileWriteable();
|
virtual ~DataBlockFixtureWriteable();
|
||||||
|
|
||||||
void write(const void *buf, size_t count, off_t offset);
|
void write(const void *buf, size_t count, off_t offset);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user