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>
|
2018-09-15 23:32:58 +02:00
|
|
|
#include <fspp/fs_interface/Types.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
|
|
|
|
2018-09-15 23:32:58 +02:00
|
|
|
fspp::num_bytes_t read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const;
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
const void *data() const;
|
2018-09-15 23:32:58 +02:00
|
|
|
fspp::num_bytes_t size() const;
|
2015-04-25 16:43:37 +02:00
|
|
|
|
2018-09-15 23:32:58 +02:00
|
|
|
bool fileContentEquals(const cpputils::Data &expected, fspp::num_bytes_t offset) const;
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
cpputils::Data _data;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WriteableInMemoryFile: public InMemoryFile {
|
|
|
|
public:
|
|
|
|
WriteableInMemoryFile(cpputils::Data data);
|
|
|
|
|
2018-09-15 23:32:58 +02:00
|
|
|
void write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
bool sizeUnchanged() const;
|
2018-09-15 23:32:58 +02:00
|
|
|
bool regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const;
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
private:
|
2018-09-15 23:32:58 +02:00
|
|
|
void _extendFileSizeIfNecessary(fspp::num_bytes_t size);
|
|
|
|
void _extendFileSize(fspp::num_bytes_t size);
|
2015-04-25 16:43:37 +02:00
|
|
|
|
|
|
|
cpputils::Data _originalData;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|