mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-31 06:42:07 +00:00
feat(automation): pure UI node model + JSON serializer with unit test
This commit is contained in:
@@ -52,5 +52,6 @@ add_subdirectory(libslic3r)
|
||||
add_subdirectory(slic3rutils)
|
||||
add_subdirectory(fff_print)
|
||||
add_subdirectory(sla_print)
|
||||
add_subdirectory(automation)
|
||||
|
||||
|
||||
|
||||
16
tests/automation/CMakeLists.txt
Normal file
16
tests/automation/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
|
||||
|
||||
add_executable(${_TEST_NAME}_tests
|
||||
automation_tests.cpp
|
||||
test_serializer.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/slic3r/GUI/Automation/WidgetSerializer.cpp
|
||||
)
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common Catch2::Catch2WithMain nlohmann_json)
|
||||
# The nlohmann_json INTERFACE target only exposes deps_src/nlohmann on the include
|
||||
# path (so <json.hpp> resolves). The rest of the codebase reaches <nlohmann/json.hpp>
|
||||
# via the deps_src root that admesh re-exports transitively; this pure unit-test
|
||||
# target does not link admesh, so add the deps_src root explicitly to match.
|
||||
target_include_directories(${_TEST_NAME}_tests PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/deps_src)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
orcaslicer_copy_test_dlls()
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
4
tests/automation/automation_tests.cpp
Normal file
4
tests/automation/automation_tests.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
// Catch2 provides main() via Catch2::Catch2WithMain. This TU exists so the
|
||||
// executable has at least one source plus a stable name; per-feature TEST_CASEs
|
||||
// live in the test_*.cpp files.
|
||||
#include <catch2/catch_all.hpp>
|
||||
32
tests/automation/test_serializer.cpp
Normal file
32
tests/automation/test_serializer.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include "slic3r/GUI/Automation/WidgetSerializer.hpp"
|
||||
|
||||
using namespace Slic3r::GUI::Automation;
|
||||
|
||||
TEST_CASE("node_to_json emits the unified node shape", "[automation][serializer]") {
|
||||
UiNode n;
|
||||
n.backend = BackendKind::Wx;
|
||||
n.id = "btn_slice";
|
||||
n.path = "MainFrame/Panel[2]/Button[0]";
|
||||
n.klass = "Button";
|
||||
n.label = "Slice plate";
|
||||
n.rect = {100, 200, 120, 32};
|
||||
n.enabled = true;
|
||||
n.visible = true;
|
||||
|
||||
const nlohmann::json j = node_to_json(n, /*include_children*/ false);
|
||||
|
||||
CHECK(j.at("backend") == "wx");
|
||||
CHECK(j.at("id") == "btn_slice");
|
||||
CHECK(j.at("path") == "MainFrame/Panel[2]/Button[0]");
|
||||
CHECK(j.at("class") == "Button");
|
||||
CHECK(j.at("label") == "Slice plate");
|
||||
CHECK(j.at("rect").at("x") == 100);
|
||||
CHECK(j.at("rect").at("w") == 120);
|
||||
CHECK(j.at("enabled") == true);
|
||||
CHECK(j.at("visible") == true);
|
||||
// `handle` must never leak into JSON.
|
||||
CHECK_FALSE(j.contains("handle"));
|
||||
// No value set -> no "value" key.
|
||||
CHECK_FALSE(j.contains("value"));
|
||||
}
|
||||
Reference in New Issue
Block a user