2015-04-25 16:43:37 +02:00
|
|
|
#pragma once
|
2015-10-15 13:04:57 +02:00
|
|
|
#ifndef MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
|
|
|
|
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
|
2015-04-25 16:43:37 +02:00
|
|
|
|
2016-02-11 12:53:42 +01:00
|
|
|
#include <cpp-utils/data/Data.h>
|
2015-04-25 16:43:37 +02:00
|
|
|
|
2015-11-27 15:18:33 +01:00
|
|
|
class InMemoryFile {
|
2015-04-25 16:43:37 +02:00
|
|
|
public:
|
|
|
|
InMemoryFile(cpputils::Data data);
|
2015-11-27 15:18:33 +01:00
|
|
|
virtual ~InMemoryFile();
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
int read(void *buf, size_t count, off_t offset) const;
|
|
|
|
|
|
|
|
const void *data() const;
|
|
|
|
size_t size() const;
|
|
|
|
|
|
|
|
bool fileContentEquals(const cpputils::Data &expected, off_t offset) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cpputils::Data _data;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WriteableInMemoryFile: public InMemoryFile {
|
|
|
|
public:
|
|
|
|
WriteableInMemoryFile(cpputils::Data data);
|
|
|
|
|
|
|
|
void write(const void *buf, size_t count, off_t offset);
|
|
|
|
|
|
|
|
bool sizeUnchanged() const;
|
|
|
|
bool regionUnchanged(off_t offset, size_t count) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void _extendFileSizeIfNecessary(size_t size);
|
|
|
|
void _extendFileSize(size_t size);
|
|
|
|
|
|
|
|
cpputils::Data _originalData;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|