From 26a0352851621735e85c25e4202dd8d1aafd72e7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 21 Sep 2021 02:48:41 +0200 Subject: [PATCH] tests: Fixed unit test compiling --- include/views/view_diff.hpp | 25 ++++++++++++++++++ plugins/libimhex/include/hex/helpers/file.hpp | 4 +-- plugins/libimhex/source/helpers/file.cpp | 2 +- source/views/view_diff.cpp | 26 +++++++++++++++++++ tests/include/test_provider.hpp | 20 ++++++++------ 5 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 include/views/view_diff.hpp create mode 100644 source/views/view_diff.cpp diff --git a/include/views/view_diff.hpp b/include/views/view_diff.hpp new file mode 100644 index 000000000..c202c3ac9 --- /dev/null +++ b/include/views/view_diff.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include +#include + +#include +#include + +namespace hex { + + namespace prv { class Provider; } + + class ViewTools : public View { + public: + ViewTools(); + ~ViewTools() override; + + void drawContent() override; + void drawMenu() override; + + }; + +} \ No newline at end of file diff --git a/plugins/libimhex/include/hex/helpers/file.hpp b/plugins/libimhex/include/hex/helpers/file.hpp index 64bc8ff77..51d2d6ad5 100644 --- a/plugins/libimhex/include/hex/helpers/file.hpp +++ b/plugins/libimhex/include/hex/helpers/file.hpp @@ -30,7 +30,7 @@ namespace hex { ~File(); - bool isValid() { return this->m_file != nullptr; } + bool isValid() const { return this->m_file != nullptr; } void seek(u64 offset); @@ -42,7 +42,7 @@ namespace hex { void write(const std::vector &bytes); void write(const std::string &string); - size_t getSize(); + size_t getSize() const; void setSize(u64 size); auto getHandle() { return this->m_file; } diff --git a/plugins/libimhex/source/helpers/file.cpp b/plugins/libimhex/source/helpers/file.cpp index f58793314..bce8ce739 100644 --- a/plugins/libimhex/source/helpers/file.cpp +++ b/plugins/libimhex/source/helpers/file.cpp @@ -72,7 +72,7 @@ namespace hex { fwrite(string.data(), string.size(), 1, this->m_file); } - size_t File::getSize() { + size_t File::getSize() const { if (!isValid()) return 0; auto startPos = ftello64(this->m_file); diff --git a/source/views/view_diff.cpp b/source/views/view_diff.cpp new file mode 100644 index 000000000..e62129b55 --- /dev/null +++ b/source/views/view_diff.cpp @@ -0,0 +1,26 @@ +#include "views/view_tools.hpp" + +#include + +namespace hex { + + ViewTools::ViewTools() : View("hex.view.tools.name") { } + + ViewTools::~ViewTools() { } + + void ViewTools::drawContent() { + if (ImGui::Begin(View::toWindowName("hex.view.tools.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + for (const auto& [name, function] : ContentRegistry::Tools::getEntries()) { + if (ImGui::CollapsingHeader(LangEntry(name))) { + function(); + } + } + } + ImGui::End(); + } + + void ViewTools::drawMenu() { + + } + +} \ No newline at end of file diff --git a/tests/include/test_provider.hpp b/tests/include/test_provider.hpp index e2e7e5802..7b6fb2cd3 100644 --- a/tests/include/test_provider.hpp +++ b/tests/include/test_provider.hpp @@ -17,13 +17,17 @@ namespace hex::test { } ~TestProvider() override = default; - bool isAvailable() override { return true; } - bool isReadable() override { return true; } - bool isWritable() override { return false; } - bool isResizable() override { return false; } - bool isSavable() override { return false; } + [[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; } - std::vector> getDataInformation() override { + [[nodiscard]] std::string getName() const override { + return ""; + } + + [[nodiscard]] std::vector> getDataInformation() const override { return { }; } @@ -37,8 +41,8 @@ namespace hex::test { this->m_testFile.write(static_cast(buffer), size); } - size_t getActualSize() override { - return m_testFile.getSize(); + size_t getActualSize() const override { + return this->m_testFile.getSize(); } private: