Renamed VirtualTestFile to DataBlockFixture

This commit is contained in:
Sebastian Messmer 2014-12-09 11:01:32 +01:00
parent 2d59c93d80
commit 250913ea62
5 changed files with 35 additions and 40 deletions

View File

@ -1,7 +1,6 @@
#include <test/testutils/DataBlockFixture.h>
#include "testutils/FuseReadTest.h"
#include "test/testutils/VirtualTestFile.h"
#include "fspp/fuse/FuseErrnoException.h"
#include <tuple>
@ -45,12 +44,12 @@ struct TestData {
// 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>> {
public:
unique_ptr<VirtualTestFile> testFile;
unique_ptr<DataBlockFixture> testFile;
TestData testData;
FuseReadReturnedDataTest() {
testData = GetParam();
testFile = make_unique<VirtualTestFile>(testData.fileSize());
testFile = make_unique<DataBlockFixture>(testData.fileSize());
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
OnOpenReturnFileDescriptor(FILENAME, 0);

View File

@ -1,7 +1,6 @@
#include <test/testutils/DataBlockFixture.h>
#include "testutils/FuseWriteTest.h"
#include "test/testutils/VirtualTestFile.h"
#include "fspp/fuse/FuseErrnoException.h"
#include <tuple>
@ -44,12 +43,12 @@ struct TestData {
// 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>> {
public:
unique_ptr<VirtualTestFileWriteable> testFile;
unique_ptr<DataBlockFixtureWriteable> testFile;
TestData testData;
FuseWriteDataTest() {
testData = GetParam();
testFile = make_unique<VirtualTestFileWriteable>(testData.fileSize(), 1);
testFile = make_unique<DataBlockFixtureWriteable>(testData.fileSize(), 1);
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
OnOpenReturnFileDescriptor(FILENAME, 0);
@ -66,14 +65,14 @@ INSTANTIATE_TEST_CASE_P(FuseWriteDataTest, FuseWriteDataTest, Combine(Values(0,1
TEST_P(FuseWriteDataTest, DataWasCorrectlyWritten) {
VirtualTestFile randomWriteData(testData.count, 2);
DataBlockFixture randomWriteData(testData.count, 2);
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
EXPECT_TRUE(testFile->fileContentEqual(randomWriteData.data(), testData.count, testData.offset));
}
TEST_P(FuseWriteDataTest, RestOfFileIsUnchanged) {
VirtualTestFile randomWriteData(testData.count, 2);
DataBlockFixture randomWriteData(testData.count, 2);
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
EXPECT_TRUE(testFile->sizeUnchanged());

View File

@ -1,7 +1,6 @@
#include <test/testutils/DataBlockFixture.h>
#include "testutils/FuseWriteTest.h"
#include "test/testutils/VirtualTestFile.h"
#include "fspp/fuse/FuseErrnoException.h"
using ::testing::_;
@ -21,8 +20,8 @@ public:
size_t WRITESIZE;
size_t OFFSET;
VirtualTestFileWriteable testFile;
VirtualTestFile writeData;
DataBlockFixtureWriteable testFile;
DataBlockFixture writeData;
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(FILESIZE), writeData(WRITESIZE) {

View File

@ -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);
}

View File

@ -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);