1
0
mirror of synced 2024-11-14 19:17:42 +01:00
ImHex/tests/common/include/hex/test/test_provider.hpp
WerWolv 966f3b8597
sys: Replace existing bad project system with a much better one (#663)
* sys: Initial effort to replace existing project files with a better system

* sys: Added back marking provider as dirty

* sys: Remove git commit information from project files

* sys: Format data processor save file nicely

* fix: Automatic pattern loading not working correctly

* ui: Added warning popup when closing a provider with modifications

Closes #604

* sys: Fixed build issues

* tests: Removed useless debug logs

* patterns: Updated pattern language

* sys: Added log message when crashing with a signal

* sys: Make sure abnormal termination handlers are being called more reliably
2022-08-08 21:23:52 +02:00

61 lines
1.8 KiB
C++

#include <hex/providers/provider.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp>
#include <stdexcept>
namespace hex::test {
using namespace hex::prv;
class TestProvider : public prv::Provider {
public:
explicit TestProvider(std::vector<u8> *data) : Provider() {
this->setData(data);
}
~TestProvider() override = default;
[[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; }
void setData(std::vector<u8> *data) {
this->m_data = data;
}
[[nodiscard]] std::string getName() const override {
return "";
}
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override {
return {};
}
void readRaw(u64 offset, void *buffer, size_t size) override {
if (offset + size > this->m_data->size()) return;
std::memcpy(buffer, m_data->data() + offset, size);
}
void writeRaw(u64 offset, const void *buffer, size_t size) override {
if (offset + size > this->m_data->size()) return;
std::memcpy(m_data->data() + offset, buffer, size);
}
[[nodiscard]] size_t getActualSize() const override {
return this->m_data->size();
}
[[nodiscard]] virtual std::string getTypeName() const { return "hex.test.provider.test"; }
bool open() override { return true; }
void close() override { }
private:
std::vector<u8> *m_data = nullptr;
};
}