Extract brush UI operation planning
This commit is contained in:
@@ -268,6 +268,16 @@ add_test(NAME pp_ui_core_layout_xml_tests COMMAND pp_ui_core_layout_xml_tests)
|
||||
set_tests_properties(pp_ui_core_layout_xml_tests PROPERTIES
|
||||
LABELS "ui;desktop-fast;fuzz")
|
||||
|
||||
add_executable(pp_app_core_brush_ui_tests
|
||||
app_core/brush_ui_tests.cpp)
|
||||
target_link_libraries(pp_app_core_brush_ui_tests PRIVATE
|
||||
pp_app_core
|
||||
pp_test_harness)
|
||||
|
||||
add_test(NAME pp_app_core_brush_ui_tests COMMAND pp_app_core_brush_ui_tests)
|
||||
set_tests_properties(pp_app_core_brush_ui_tests PROPERTIES
|
||||
LABELS "app;paint;desktop-fast;fuzz")
|
||||
|
||||
add_executable(pp_app_core_document_route_tests
|
||||
app_core/document_route_tests.cpp)
|
||||
target_link_libraries(pp_app_core_document_route_tests PRIVATE
|
||||
@@ -776,6 +786,36 @@ if(TARGET pano_cli)
|
||||
LABELS "app;integration;desktop-fast;fuzz"
|
||||
WILL_FAIL TRUE)
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_operation_color_smoke
|
||||
COMMAND pano_cli plan-brush-operation --kind color --r 0.25 --g 0.5 --b 0.75 --a 1)
|
||||
set_tests_properties(pano_cli_plan_brush_operation_color_smoke PROPERTIES
|
||||
LABELS "app;paint;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-brush-operation\".*\"operation\":\"set-tip-color\".*\"r\":0.25.*\"g\":0.5.*\"b\":0.75.*\"updateColorUi\":true.*\"updateBrushUi\":false")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_operation_texture_smoke
|
||||
COMMAND pano_cli plan-brush-operation --kind pattern --path data/patterns/noise.png --thumb data/patterns/thumbs/noise.png)
|
||||
set_tests_properties(pano_cli_plan_brush_operation_texture_smoke PROPERTIES
|
||||
LABELS "app;paint;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-brush-operation\".*\"operation\":\"set-texture\".*\"textureSlot\":\"pattern\".*\"path\":\"data/patterns/noise.png\".*\"loadsBrushResources\":true.*\"updateBrushUi\":true")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_operation_preset_smoke
|
||||
COMMAND pano_cli plan-brush-operation --kind preset)
|
||||
set_tests_properties(pano_cli_plan_brush_operation_preset_smoke PROPERTIES
|
||||
LABELS "app;paint;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-brush-operation\".*\"operation\":\"replace-brush-from-preset\".*\"preservesExistingColor\":true.*\"loadsBrushResources\":true")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_operation_rejects_bad_color
|
||||
COMMAND pano_cli plan-brush-operation --kind color --r 1.5)
|
||||
set_tests_properties(pano_cli_plan_brush_operation_rejects_bad_color PROPERTIES
|
||||
LABELS "app;paint;integration;desktop-fast;fuzz"
|
||||
WILL_FAIL TRUE)
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_operation_rejects_empty_texture
|
||||
COMMAND pano_cli plan-brush-operation --kind tip)
|
||||
set_tests_properties(pano_cli_plan_brush_operation_rejects_empty_texture PROPERTIES
|
||||
LABELS "app;paint;integration;desktop-fast;fuzz"
|
||||
WILL_FAIL TRUE)
|
||||
|
||||
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
|
||||
|
||||
85
tests/app_core/brush_ui_tests.cpp
Normal file
85
tests/app_core/brush_ui_tests.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace {
|
||||
|
||||
void color_plan_validates_all_channels(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_color(0.25F, 0.5F, 0.75F, 1.0F);
|
||||
PP_EXPECT(harness, plan);
|
||||
if (plan) {
|
||||
PP_EXPECT(harness, plan.value().operation == pp::app::BrushUiOperation::set_tip_color);
|
||||
PP_EXPECT(harness, plan.value().r == 0.25F);
|
||||
PP_EXPECT(harness, plan.value().g == 0.5F);
|
||||
PP_EXPECT(harness, plan.value().b == 0.75F);
|
||||
PP_EXPECT(harness, plan.value().a == 1.0F);
|
||||
PP_EXPECT(harness, plan.value().mutates_brush);
|
||||
PP_EXPECT(harness, plan.value().update_color_ui);
|
||||
PP_EXPECT(harness, !plan.value().update_brush_ui);
|
||||
}
|
||||
|
||||
PP_EXPECT(harness, !pp::app::plan_brush_ui_color(-0.01F, 0.5F, 0.5F, 1.0F));
|
||||
PP_EXPECT(harness, !pp::app::plan_brush_ui_color(0.5F, 1.01F, 0.5F, 1.0F));
|
||||
PP_EXPECT(harness, !pp::app::plan_brush_ui_color(0.5F, 0.5F, std::nanf(""), 1.0F));
|
||||
}
|
||||
|
||||
void texture_plan_validates_path_and_slot(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_texture(
|
||||
pp::app::BrushUiTextureSlot::pattern,
|
||||
"data/patterns/noise.png",
|
||||
"data/patterns/thumbs/noise.png");
|
||||
PP_EXPECT(harness, plan);
|
||||
if (plan) {
|
||||
PP_EXPECT(harness, plan.value().operation == pp::app::BrushUiOperation::set_texture);
|
||||
PP_EXPECT(harness, plan.value().texture_slot == pp::app::BrushUiTextureSlot::pattern);
|
||||
PP_EXPECT(harness, plan.value().path == "data/patterns/noise.png");
|
||||
PP_EXPECT(harness, plan.value().thumbnail_path == "data/patterns/thumbs/noise.png");
|
||||
PP_EXPECT(harness, plan.value().loads_brush_resources);
|
||||
PP_EXPECT(harness, plan.value().update_color_ui);
|
||||
PP_EXPECT(harness, plan.value().update_brush_ui);
|
||||
}
|
||||
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::plan_brush_ui_texture(pp::app::BrushUiTextureSlot::tip, "", "thumb.png"));
|
||||
}
|
||||
|
||||
void preset_plan_preserves_color_and_requires_brush(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_preset_replace(true);
|
||||
PP_EXPECT(harness, plan);
|
||||
if (plan) {
|
||||
PP_EXPECT(harness, plan.value().operation == pp::app::BrushUiOperation::replace_brush_from_preset);
|
||||
PP_EXPECT(harness, plan.value().preserves_existing_color);
|
||||
PP_EXPECT(harness, plan.value().loads_brush_resources);
|
||||
PP_EXPECT(harness, plan.value().update_color_ui);
|
||||
PP_EXPECT(harness, plan.value().update_brush_ui);
|
||||
}
|
||||
|
||||
PP_EXPECT(harness, !pp::app::plan_brush_ui_preset_replace(false));
|
||||
}
|
||||
|
||||
void stroke_settings_plan_updates_brush_preview(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_stroke_settings_changed();
|
||||
PP_EXPECT(harness, plan.operation == pp::app::BrushUiOperation::stroke_settings_changed);
|
||||
PP_EXPECT(harness, plan.mutates_brush);
|
||||
PP_EXPECT(harness, plan.update_color_ui);
|
||||
PP_EXPECT(harness, plan.update_brush_ui);
|
||||
PP_EXPECT(harness, !plan.loads_brush_resources);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("color plan validates all channels", color_plan_validates_all_channels);
|
||||
harness.run("texture plan validates path and slot", texture_plan_validates_path_and_slot);
|
||||
harness.run("preset plan preserves color and requires brush", preset_plan_preserves_color_and_requires_brush);
|
||||
harness.run("stroke settings plan updates brush preview", stroke_settings_plan_updates_brush_preview);
|
||||
return harness.finish();
|
||||
}
|
||||
Reference in New Issue
Block a user