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 <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…
x
Reference in New Issue
Block a user