libcryfs/test/fspp/testutils/InMemoryFile.h

42 lines
1.0 KiB
C
Raw Normal View History

#pragma once
2015-10-15 13:04:57 +02:00
#ifndef MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
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-11-27 15:18:33 +01:00
class InMemoryFile {
public:
InMemoryFile(cpputils::Data data);
2015-11-27 15:18:33 +01:00
virtual ~InMemoryFile();
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;
const void *data() const;
2018-09-15 23:32:58 +02:00
fspp::num_bytes_t size() const;
2018-09-15 23:32:58 +02:00
bool fileContentEquals(const cpputils::Data &expected, fspp::num_bytes_t offset) const;
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);
bool sizeUnchanged() const;
2018-09-15 23:32:58 +02:00
bool regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const;
private:
2018-09-15 23:32:58 +02:00
void _extendFileSizeIfNecessary(fspp::num_bytes_t size);
void _extendFileSize(fspp::num_bytes_t size);
cpputils::Data _originalData;
};
#endif