2014-11-27 15:23:51 +01:00
|
|
|
#pragma once
|
2014-12-09 11:01:32 +01:00
|
|
|
#ifndef TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
|
|
|
#define TEST_TESTUTILS_DATABLOCKFIXTURE_H_
|
2014-11-27 15:23:51 +01:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
2014-12-09 11:01:32 +01:00
|
|
|
class DataBlockFixture {
|
2014-11-27 15:23:51 +01:00
|
|
|
public:
|
2014-12-09 11:01:32 +01:00
|
|
|
DataBlockFixture(size_t size, long long int IV = 1);
|
|
|
|
virtual ~DataBlockFixture();
|
2014-11-27 15:23:51 +01:00
|
|
|
|
|
|
|
int read(void *buf, size_t count, off_t offset);
|
|
|
|
|
|
|
|
// Return true, iff the given data is equal to the data of the file at the given offset.
|
2014-11-27 16:40:22 +01:00
|
|
|
bool fileContentEqual(const char *content, size_t count, off_t offset);
|
|
|
|
|
2014-12-05 11:50:24 +01:00
|
|
|
const char *data() const;
|
2014-11-27 16:40:22 +01:00
|
|
|
|
2014-12-05 11:50:24 +01:00
|
|
|
size_t size() const;
|
2014-11-27 15:23:51 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
char *_fileData;
|
|
|
|
size_t _size;
|
|
|
|
|
|
|
|
private:
|
2014-11-27 16:40:22 +01:00
|
|
|
void fillFileWithRandomData(long long int IV);
|
2014-11-27 15:23:51 +01:00
|
|
|
};
|
|
|
|
|
2014-12-09 11:01:32 +01:00
|
|
|
class DataBlockFixtureWriteable: public DataBlockFixture {
|
2014-11-27 15:23:51 +01:00
|
|
|
public:
|
2014-12-09 11:01:32 +01:00
|
|
|
DataBlockFixtureWriteable(size_t size, long long int IV = 1);
|
|
|
|
virtual ~DataBlockFixtureWriteable();
|
2014-11-27 16:40:22 +01:00
|
|
|
|
|
|
|
void write(const void *buf, size_t count, off_t offset);
|
|
|
|
|
|
|
|
bool sizeUnchanged();
|
|
|
|
bool regionUnchanged(off_t offset, size_t count);
|
|
|
|
|
2014-11-27 15:23:51 +01:00
|
|
|
private:
|
2014-11-27 16:40:22 +01:00
|
|
|
void extendFileSizeIfNecessary(size_t size);
|
|
|
|
void extendFileSize(size_t size);
|
|
|
|
|
|
|
|
char *_originalFileData;
|
|
|
|
size_t _originalSize;
|
2014-11-27 15:23:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|