Renamed VirtualTestFile to DataBlockFixture
This commit is contained in:
parent
5413384ee3
commit
b275d47dd9
@ -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