From 250913ea621090523bd5402e00e0306a203ce370 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 9 Dec 2014 11:01:32 +0100 Subject: [PATCH] Renamed VirtualTestFile to DataBlockFixture --- .../fuse/read/FuseReadReturnedDataTest.cpp | 7 ++-- .../fspp/fuse/write/FuseWriteDataTest.cpp | 11 +++---- .../fspp/fuse/write/FuseWriteOverflowTest.cpp | 7 ++-- ...rtualTestFile.cpp => DataBlockFixture.cpp} | 33 +++++++++---------- .../{VirtualTestFile.h => DataBlockFixture.h} | 17 +++++----- 5 files changed, 35 insertions(+), 40 deletions(-) rename src/test/testutils/{VirtualTestFile.cpp => DataBlockFixture.cpp} (51%) rename src/test/testutils/{VirtualTestFile.h => DataBlockFixture.h} (62%) diff --git a/src/test/fspp/fuse/read/FuseReadReturnedDataTest.cpp b/src/test/fspp/fuse/read/FuseReadReturnedDataTest.cpp index 3033ae0b..59e404b1 100644 --- a/src/test/fspp/fuse/read/FuseReadReturnedDataTest.cpp +++ b/src/test/fspp/fuse/read/FuseReadReturnedDataTest.cpp @@ -1,7 +1,6 @@ +#include #include "testutils/FuseReadTest.h" -#include "test/testutils/VirtualTestFile.h" - #include "fspp/fuse/FuseErrnoException.h" #include @@ -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> { public: - unique_ptr testFile; + unique_ptr testFile; TestData testData; FuseReadReturnedDataTest() { testData = GetParam(); - testFile = make_unique(testData.fileSize()); + testFile = make_unique(testData.fileSize()); ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize()); OnOpenReturnFileDescriptor(FILENAME, 0); diff --git a/src/test/fspp/fuse/write/FuseWriteDataTest.cpp b/src/test/fspp/fuse/write/FuseWriteDataTest.cpp index 727f2fdb..f5a65380 100644 --- a/src/test/fspp/fuse/write/FuseWriteDataTest.cpp +++ b/src/test/fspp/fuse/write/FuseWriteDataTest.cpp @@ -1,7 +1,6 @@ +#include #include "testutils/FuseWriteTest.h" -#include "test/testutils/VirtualTestFile.h" - #include "fspp/fuse/FuseErrnoException.h" #include @@ -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> { public: - unique_ptr testFile; + unique_ptr testFile; TestData testData; FuseWriteDataTest() { testData = GetParam(); - testFile = make_unique(testData.fileSize(), 1); + testFile = make_unique(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()); diff --git a/src/test/fspp/fuse/write/FuseWriteOverflowTest.cpp b/src/test/fspp/fuse/write/FuseWriteOverflowTest.cpp index 36baf0c2..549b047a 100644 --- a/src/test/fspp/fuse/write/FuseWriteOverflowTest.cpp +++ b/src/test/fspp/fuse/write/FuseWriteOverflowTest.cpp @@ -1,7 +1,6 @@ +#include #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) { diff --git a/src/test/testutils/VirtualTestFile.cpp b/src/test/testutils/DataBlockFixture.cpp similarity index 51% rename from src/test/testutils/VirtualTestFile.cpp rename to src/test/testutils/DataBlockFixture.cpp index ac863572..b4413121 100644 --- a/src/test/testutils/VirtualTestFile.cpp +++ b/src/test/testutils/DataBlockFixture.cpp @@ -1,19 +1,18 @@ -#include "VirtualTestFile.h" - +#include #include #include 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); } diff --git a/src/test/testutils/VirtualTestFile.h b/src/test/testutils/DataBlockFixture.h similarity index 62% rename from src/test/testutils/VirtualTestFile.h rename to src/test/testutils/DataBlockFixture.h index 1a45d49d..73d763d9 100644 --- a/src/test/testutils/VirtualTestFile.h +++ b/src/test/testutils/DataBlockFixture.h @@ -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 -//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);