Extract app preference planning into app core

This commit is contained in:
2026-06-03 09:36:38 +02:00
parent 19cb14b5dc
commit a64a63def7
8 changed files with 431 additions and 22 deletions

View File

@@ -318,6 +318,16 @@ add_test(NAME pp_app_core_document_recording_tests COMMAND pp_app_core_document_
set_tests_properties(pp_app_core_document_recording_tests PROPERTIES
LABELS "app;desktop-fast;fuzz")
add_executable(pp_app_core_app_preferences_tests
app_core/app_preferences_tests.cpp)
target_link_libraries(pp_app_core_app_preferences_tests PRIVATE
pp_app_core
pp_test_harness)
add_test(NAME pp_app_core_app_preferences_tests COMMAND pp_app_core_app_preferences_tests)
set_tests_properties(pp_app_core_app_preferences_tests PROPERTIES
LABELS "app;desktop-fast;fuzz")
add_executable(pp_app_core_document_sharing_tests
app_core/document_sharing_tests.cpp)
target_link_libraries(pp_app_core_document_sharing_tests PRIVATE
@@ -601,6 +611,32 @@ if(TARGET pano_cli)
LABELS "app;integration;desktop-fast;fuzz"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-recording-session\".*\"platformDeletesRecordedFiles\":true.*\"deleteRecordedFiles\":true.*\"frameCountAfterClear\":0")
add_test(NAME pano_cli_plan_app_preferences_smoke
COMMAND pano_cli plan-app-preferences
--ui-scale 1.5
--display-density 2
--current-scale 1.6
--scale-option 0.75
--scale-option 1
--scale-option 1.5
--viewport-scale 0.5
--rtl
--cursor-mode 2)
set_tests_properties(pano_cli_plan_app_preferences_smoke PROPERTIES
LABELS "app;integration;desktop-fast"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-preferences\".*\"fontScale\":3.*\"scaleSelection\":\\{\"hasSelection\":true,\"index\":2\\}.*\"viewportScale\":\\{\"scale\":0.5\\}.*\"direction\":\"right-to-left\".*\"recordingAction\":\"start-recording\".*\"vrControllers\":\\{\"enabled\":true\\}.*\"cursor\":\\{\"mode\":2\\}")
add_test(NAME pano_cli_plan_app_preferences_stops_timelapse_smoke
COMMAND pano_cli plan-app-preferences
--current-scale 0.5
--scale-option 1
--timelapse-disabled
--recording-running
--vr-controllers-disabled)
set_tests_properties(pano_cli_plan_app_preferences_stops_timelapse_smoke PROPERTIES
LABELS "app;integration;desktop-fast;fuzz"
PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-preferences\".*\"scaleSelection\":\\{\"hasSelection\":false,\"index\":0\\}.*\"direction\":\"left-to-right\".*\"timelapse\":\\{\"enabled\":false,\"recordingAction\":\"stop-recording\"\\}.*\"vrControllers\":\\{\"enabled\":false\\}")
add_test(NAME pano_cli_plan_share_file_unsaved_smoke
COMMAND pano_cli plan-share-file)
set_tests_properties(pano_cli_plan_share_file_unsaved_smoke PROPERTIES

View File

@@ -0,0 +1,92 @@
#include "app_core/app_preferences.h"
#include "test_harness.h"
#include <array>
namespace {
void ui_scale_computes_font_scale_from_display_density(pp::tests::Harness& harness)
{
const auto plan = pp::app::plan_ui_scale(1.5F, 2.0F);
PP_EXPECT(harness, plan.scale == 1.5F);
PP_EXPECT(harness, plan.display_density == 2.0F);
PP_EXPECT(harness, plan.font_scale == 3.0F);
}
void scale_option_selection_uses_last_option_not_above_current(pp::tests::Harness& harness)
{
constexpr std::array<float, 4> options { 0.75F, 1.0F, 1.5F, 2.0F };
const auto plan = pp::app::plan_scale_option_selection(1.6F, options);
PP_EXPECT(harness, plan.has_selection);
PP_EXPECT(harness, plan.index == 2U);
}
void scale_option_selection_handles_empty_or_too_large_options(pp::tests::Harness& harness)
{
constexpr std::array<float, 0> empty {};
const auto empty_plan = pp::app::plan_scale_option_selection(1.0F, empty);
PP_EXPECT(harness, !empty_plan.has_selection);
PP_EXPECT(harness, empty_plan.index == 0U);
constexpr std::array<float, 2> options { 2.0F, 3.0F };
const auto low_plan = pp::app::plan_scale_option_selection(1.0F, options);
PP_EXPECT(harness, !low_plan.has_selection);
PP_EXPECT(harness, low_plan.index == 0U);
}
void interface_direction_tracks_requested_layout_direction(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_interface_direction(false).direction == pp::app::InterfaceDirection::left_to_right);
PP_EXPECT(
harness,
pp::app::plan_interface_direction(true).direction == pp::app::InterfaceDirection::right_to_left);
}
void timelapse_preference_starts_and_stops_only_on_state_change(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_timelapse_preference(true, false).recording_action
== pp::app::TimelapseRecordingAction::start_recording);
PP_EXPECT(
harness,
pp::app::plan_timelapse_preference(false, true).recording_action
== pp::app::TimelapseRecordingAction::stop_recording);
PP_EXPECT(
harness,
pp::app::plan_timelapse_preference(true, true).recording_action
== pp::app::TimelapseRecordingAction::no_op);
PP_EXPECT(
harness,
pp::app::plan_timelapse_preference(false, false).recording_action
== pp::app::TimelapseRecordingAction::no_op);
}
void simple_preferences_preserve_values_for_storage(pp::tests::Harness& harness)
{
PP_EXPECT(harness, pp::app::plan_vr_controllers_preference(true).value);
PP_EXPECT(harness, !pp::app::plan_vr_controllers_preference(false).value);
PP_EXPECT(harness, pp::app::plan_canvas_cursor_mode(2).value == 2);
}
}
int main()
{
pp::tests::Harness harness;
harness.run("ui scale computes font scale from display density", ui_scale_computes_font_scale_from_display_density);
harness.run(
"scale option selection uses last option not above current",
scale_option_selection_uses_last_option_not_above_current);
harness.run(
"scale option selection handles empty or too large options",
scale_option_selection_handles_empty_or_too_large_options);
harness.run("interface direction tracks requested layout direction", interface_direction_tracks_requested_layout_direction);
harness.run(
"timelapse preference starts and stops only on state change",
timelapse_preference_starts_and_stops_only_on_state_change);
harness.run("simple preferences preserve values for storage", simple_preferences_preserve_values_for_storage);
return harness.finish();
}