mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-18 00:12:09 +00:00
Keep action identity and display metadata constructor-set so registry keys cannot drift from the objects they index. Require sources to publish unique ownership while the registry retains shared keepalive for runs. Preserve opaque IDs and persisted state keys.
71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "slic3r/GUI/ActionRegistry.hpp"
|
|
#include "slic3r/GUI/IActionSource.hpp"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <type_traits>
|
|
|
|
using Slic3r::GUI::AppAction;
|
|
using Slic3r::GUI::AppActionRunResult;
|
|
using Slic3r::GUI::ActionRegistry;
|
|
using Slic3r::GUI::IActionSource;
|
|
|
|
namespace {
|
|
|
|
class RecordingActionSource final : public IActionSource
|
|
{
|
|
public:
|
|
explicit RecordingActionSource(bool& started) : m_started(started) {}
|
|
|
|
void start(ActionRegistry&) override { m_started = true; }
|
|
|
|
private:
|
|
bool& m_started;
|
|
};
|
|
|
|
// AppAction is abstract; this minimal concrete action lets the tests exercise
|
|
// its constructor-set definition without involving a plugin runner.
|
|
class TestAppAction final : public AppAction
|
|
{
|
|
public:
|
|
TestAppAction() : AppAction("action-id", "Action title", "Action source") {}
|
|
|
|
AppActionRunResult run() const override { return {}; }
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("AppAction definitions are immutable after construction", "[speeddial][actions]")
|
|
{
|
|
using StringAccessor = const std::string& (AppAction::*)() const;
|
|
|
|
STATIC_CHECK(std::is_same_v<decltype(&AppAction::id), StringAccessor>);
|
|
STATIC_CHECK(std::is_same_v<decltype(&AppAction::title), StringAccessor>);
|
|
STATIC_CHECK(std::is_same_v<decltype(&AppAction::source), StringAccessor>);
|
|
|
|
const TestAppAction action;
|
|
CHECK(action.id() == "action-id");
|
|
CHECK(action.title() == "Action title");
|
|
CHECK(action.source() == "Action source");
|
|
}
|
|
|
|
TEST_CASE("ActionRegistry takes exclusive ownership of published actions", "[speeddial][actions]")
|
|
{
|
|
using ExpectedUpsert = void (ActionRegistry::*)(std::unique_ptr<AppAction>);
|
|
|
|
STATIC_CHECK(std::is_same_v<decltype(&ActionRegistry::upsert), ExpectedUpsert>);
|
|
}
|
|
|
|
TEST_CASE("ActionRegistry starts registered action sources", "[speeddial][actions]")
|
|
{
|
|
bool started = false;
|
|
ActionRegistry registry;
|
|
registry.add_source(std::make_unique<RecordingActionSource>(started));
|
|
|
|
registry.init();
|
|
|
|
CHECK(started);
|
|
}
|