tests: Integrated ImGui Test Engine

This commit is contained in:
WerWolv
2025-05-29 23:44:49 +02:00
parent fe1309fb3d
commit 1ca40481bb
41 changed files with 17612 additions and 14 deletions

View File

@@ -2,6 +2,8 @@
#include <hex/api/event_manager.hpp>
struct ImGuiTestEngine;
/* Lifecycle events definitions */
namespace hex {
@@ -75,4 +77,10 @@ namespace hex {
*/
EVENT_DEF(EventNativeMessageReceived, std::vector<u8>);
/**
* @brief Called when ImGui is initialized to register tests
* @param testEngine Pointer to the ImGui Test Engine Context
*/
EVENT_DEF(EventRegisterImGuiTests, ImGuiTestEngine*);
}

View File

@@ -7,6 +7,14 @@
#include <hex/helpers/logger.hpp>
#include <hex/api/plugin_manager.hpp>
#if defined(IMGUI_TEST_ENGINE)
#include <imgui_te_context.h>
#include <imgui_te_engine.h>
#include <source_location>
#include <hex/api/events/events_lifecycle.hpp>
#endif
#include <wolv/utils/preproc.hpp>
#include <string>
@@ -32,6 +40,15 @@
#define INIT_PLUGIN(name) \
if (!hex::test::initPluginImpl(name)) TEST_FAIL();
#if defined(IMGUI_TEST_ENGINE)
#define IMGUI_TEST_SEQUENCE(category, name, ctx) \
static auto WOLV_ANONYMOUS_VARIABLE(TEST_SEQUENCE) = \
::hex::test::ImGuiTestSequenceExecutor(category, name, std::source_location::current()) + \
[](ImGuiTestContext *ctx) -> void
#else
#define IMGUI_TEST_SEQUENCE(...) static auto WOLV_ANONYMOUS_VARIABLE(TEST_SEQUENCE) = []() -> int
#endif
namespace hex::test {
using Function = int(*)();
@@ -91,5 +108,51 @@ namespace hex::test {
return TestSequence<F>(executor.getName(), std::forward<F>(f), executor.shouldFail());
}
#if defined(IMGUI_TEST_ENGINE)
template<class F>
class ImGuiTestSequence {
public:
ImGuiTestSequence(const std::string &category, const std::string &name, std::source_location sourceLocation, F func) noexcept {
log::info("Registering ImGui Test");
EventRegisterImGuiTests::subscribe([=](ImGuiTestEngine *engine) {
auto test = ImGuiTestEngine_RegisterTest(engine, category.c_str(), name.c_str(), sourceLocation.file_name(), sourceLocation.line());
test->TestFunc = func;
});
}
ImGuiTestSequence &operator=(ImGuiTestSequence &&) = delete;
};
struct ImGuiTestSequenceExecutor {
explicit ImGuiTestSequenceExecutor(std::string category, std::string name, std::source_location sourceLocation) noexcept
: m_category(std::move(category)), m_name(std::move(name)), m_sourceLocation(sourceLocation) {
}
[[nodiscard]] const auto &getCategory() const noexcept {
return m_category;
}
[[nodiscard]] const auto &getName() const noexcept {
return m_name;
}
[[nodiscard]] const auto &getSourceLocation() const noexcept {
return m_sourceLocation;
}
private:
std::string m_category, m_name;
std::source_location m_sourceLocation;
};
template<typename F>
ImGuiTestSequence<F> operator+(const ImGuiTestSequenceExecutor &executor, F &&f) noexcept {
return ImGuiTestSequence<F>(executor.getCategory(), executor.getName(), executor.getSourceLocation(), std::forward<F>(f));
}
#endif
bool initPluginImpl(std::string name);
}