Extract history UI operation planning

This commit is contained in:
2026-06-03 11:13:57 +02:00
parent 8dc476d205
commit 58afa672c7
9 changed files with 392 additions and 7 deletions

View File

@@ -288,6 +288,16 @@ add_test(NAME pp_app_core_grid_ui_tests COMMAND pp_app_core_grid_ui_tests)
set_tests_properties(pp_app_core_grid_ui_tests PROPERTIES
LABELS "app;ui;renderer;desktop-fast;fuzz")
add_executable(pp_app_core_history_ui_tests
app_core/history_ui_tests.cpp)
target_link_libraries(pp_app_core_history_ui_tests PRIVATE
pp_app_core
pp_test_harness)
add_test(NAME pp_app_core_history_ui_tests COMMAND pp_app_core_history_ui_tests)
set_tests_properties(pp_app_core_history_ui_tests PROPERTIES
LABELS "app;document;ui;desktop-fast;fuzz")
add_executable(pp_app_core_quick_ui_tests
app_core/quick_ui_tests.cpp)
target_link_libraries(pp_app_core_quick_ui_tests PRIVATE
@@ -872,6 +882,30 @@ if(TARGET pano_cli)
LABELS "app;ui;renderer;integration;desktop-fast;fuzz"
WILL_FAIL TRUE)
add_test(NAME pano_cli_plan_history_operation_undo_smoke
COMMAND pano_cli plan-history-operation --kind undo --undo-count 2)
set_tests_properties(pano_cli_plan_history_operation_undo_smoke PROPERTIES
LABELS "app;document;ui;integration;desktop-fast"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-history-operation\".*\"operation\":\"undo\".*\"undoCount\":2.*\"invokesUndo\":true.*\"updatesMemoryLabel\":true.*\"updatesTitle\":true")
add_test(NAME pano_cli_plan_history_operation_redo_empty_smoke
COMMAND pano_cli plan-history-operation --kind redo)
set_tests_properties(pano_cli_plan_history_operation_redo_empty_smoke PROPERTIES
LABELS "app;document;ui;integration;desktop-fast;fuzz"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-history-operation\".*\"operation\":\"redo\".*\"redoCount\":0.*\"invokesRedo\":false.*\"noOp\":true")
add_test(NAME pano_cli_plan_history_operation_clear_smoke
COMMAND pano_cli plan-history-operation --kind clear --undo-count 2 --redo-count 1 --memory-bytes 4096)
set_tests_properties(pano_cli_plan_history_operation_clear_smoke PROPERTIES
LABELS "app;document;ui;integration;desktop-fast"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-history-operation\".*\"operation\":\"clear\".*\"undoCount\":2.*\"redoCount\":1.*\"memoryBytes\":4096.*\"clearsHistory\":true.*\"updatesMemoryLabel\":true")
add_test(NAME pano_cli_plan_history_operation_rejects_negative_count
COMMAND pano_cli plan-history-operation --kind undo --undo-count -1)
set_tests_properties(pano_cli_plan_history_operation_rejects_negative_count PROPERTIES
LABELS "app;document;ui;integration;desktop-fast;fuzz"
WILL_FAIL TRUE)
add_test(NAME pano_cli_plan_quick_operation_select_brush_smoke
COMMAND pano_cli plan-quick-operation --kind brush --current-index 0 --slot-index 2)
set_tests_properties(pano_cli_plan_quick_operation_select_brush_smoke PROPERTIES

View File

@@ -0,0 +1,90 @@
#include "app_core/history_ui.h"
#include "test_harness.h"
namespace {
void undo_and_redo_plan_availability(pp::tests::Harness& harness)
{
const auto undo = pp::app::plan_history_undo(2);
PP_EXPECT(harness, undo);
if (undo) {
PP_EXPECT(harness, undo.value().operation == pp::app::HistoryUiOperation::undo);
PP_EXPECT(harness, undo.value().undo_count == 2);
PP_EXPECT(harness, undo.value().invokes_undo);
PP_EXPECT(harness, undo.value().updates_memory_label);
PP_EXPECT(harness, undo.value().updates_title);
PP_EXPECT(harness, !undo.value().no_op);
}
const auto undo_empty = pp::app::plan_history_undo(0);
PP_EXPECT(harness, undo_empty);
if (undo_empty) {
PP_EXPECT(harness, undo_empty.value().no_op);
PP_EXPECT(harness, !undo_empty.value().invokes_undo);
}
const auto redo = pp::app::plan_history_redo(1);
PP_EXPECT(harness, redo);
if (redo) {
PP_EXPECT(harness, redo.value().operation == pp::app::HistoryUiOperation::redo);
PP_EXPECT(harness, redo.value().redo_count == 1);
PP_EXPECT(harness, redo.value().invokes_redo);
PP_EXPECT(harness, redo.value().updates_title);
}
const auto redo_empty = pp::app::plan_history_redo(0);
PP_EXPECT(harness, redo_empty);
if (redo_empty) {
PP_EXPECT(harness, redo_empty.value().no_op);
PP_EXPECT(harness, !redo_empty.value().invokes_redo);
}
}
void clear_plan_tracks_stacks_and_memory(pp::tests::Harness& harness)
{
const auto clear = pp::app::plan_history_clear(2, 1, 4096);
PP_EXPECT(harness, clear);
if (clear) {
PP_EXPECT(harness, clear.value().operation == pp::app::HistoryUiOperation::clear);
PP_EXPECT(harness, clear.value().undo_count == 2);
PP_EXPECT(harness, clear.value().redo_count == 1);
PP_EXPECT(harness, clear.value().memory_bytes == 4096);
PP_EXPECT(harness, clear.value().clears_history);
PP_EXPECT(harness, clear.value().updates_memory_label);
PP_EXPECT(harness, !clear.value().updates_title);
}
const auto memory_only = pp::app::plan_history_clear(0, 0, 1024);
PP_EXPECT(harness, memory_only);
if (memory_only) {
PP_EXPECT(harness, memory_only.value().clears_history);
PP_EXPECT(harness, !memory_only.value().no_op);
}
const auto empty = pp::app::plan_history_clear(0, 0, 0);
PP_EXPECT(harness, empty);
if (empty) {
PP_EXPECT(harness, empty.value().no_op);
PP_EXPECT(harness, !empty.value().clears_history);
}
}
void rejects_negative_metrics(pp::tests::Harness& harness)
{
PP_EXPECT(harness, !pp::app::plan_history_undo(-1));
PP_EXPECT(harness, !pp::app::plan_history_redo(-1));
PP_EXPECT(harness, !pp::app::plan_history_clear(-1, 0, 0));
PP_EXPECT(harness, !pp::app::plan_history_clear(0, -1, 0));
PP_EXPECT(harness, !pp::app::plan_history_clear(0, 0, -1));
}
} // namespace
int main()
{
pp::tests::Harness harness;
harness.run("undo and redo plan availability", undo_and_redo_plan_availability);
harness.run("clear plan tracks stacks and memory", clear_plan_tracks_stacks_and_memory);
harness.run("rejects negative metrics", rejects_negative_metrics);
return harness.finish();
}