Files
panopainter/tests/app_core/app_preferences_tests.cpp

93 lines
3.5 KiB
C++

#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();
}