1
0
mirror of synced 2024-11-30 18:34:29 +01:00
ImHex/tests/include/test_provider.hpp

52 lines
1.7 KiB
C++
Raw Normal View History

2021-09-11 14:41:18 +02:00
#include <hex/providers/provider.hpp>
2021-09-11 14:41:18 +02:00
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp>
#include <stdexcept>
2021-09-11 14:41:18 +02:00
namespace hex::test {
using namespace hex::prv;
class TestProvider : public prv::Provider {
public:
2021-09-12 20:28:32 +02:00
TestProvider() : Provider(), m_testFile(File("test_data", File::Mode::Read)) {
if (!this->m_testFile.isValid() || this->m_testFile.getSize() == 0) {
2021-09-11 14:41:18 +02:00
hex::log::fatal("Failed to open test data!");
throw std::runtime_error("");
}
}
~TestProvider() override = default;
2021-09-21 02:48:41 +02:00
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool isReadable() const override { return true; }
[[nodiscard]] bool isWritable() const override { return false; }
[[nodiscard]] bool isResizable() const override { return false; }
[[nodiscard]] bool isSavable() const override { return false; }
[[nodiscard]] std::string getName() const override {
return "";
}
2021-09-11 14:41:18 +02:00
2021-09-21 02:48:41 +02:00
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override {
2021-09-11 14:41:18 +02:00
return { };
}
void readRaw(u64 offset, void *buffer, size_t size) override {
this->m_testFile.seek(offset);
this->m_testFile.readBuffer(static_cast<u8*>(buffer), size);
}
void writeRaw(u64 offset, const void *buffer, size_t size) override {
this->m_testFile.seek(offset);
this->m_testFile.write(static_cast<const u8*>(buffer), size);
}
2021-09-21 02:48:41 +02:00
size_t getActualSize() const override {
return this->m_testFile.getSize();
2021-09-11 14:41:18 +02:00
}
private:
File m_testFile;
};
}