Add animation panel service boundary
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#define PP_REQUIRE(harness, expression) \
|
||||
do { \
|
||||
@@ -14,6 +15,97 @@
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeDocumentAnimationServices final : public pp::app::DocumentAnimationServices {
|
||||
public:
|
||||
void add_frame() override
|
||||
{
|
||||
adds += 1;
|
||||
call_order += "add;";
|
||||
}
|
||||
|
||||
void duplicate_frame(int selected_frame) override
|
||||
{
|
||||
duplicates += 1;
|
||||
last_selected_frame = selected_frame;
|
||||
call_order += "duplicate;";
|
||||
}
|
||||
|
||||
void remove_frame(int selected_frame, int target_frame) override
|
||||
{
|
||||
removes += 1;
|
||||
last_selected_frame = selected_frame;
|
||||
last_target_frame = target_frame;
|
||||
call_order += "remove;";
|
||||
}
|
||||
|
||||
void set_frame_duration(int selected_frame, int duration) override
|
||||
{
|
||||
duration_sets += 1;
|
||||
last_selected_frame = selected_frame;
|
||||
last_duration = duration;
|
||||
call_order += "duration;";
|
||||
}
|
||||
|
||||
int move_frame(int selected_frame, int move_offset) override
|
||||
{
|
||||
moves += 1;
|
||||
last_selected_frame = selected_frame;
|
||||
last_move_offset = move_offset;
|
||||
call_order += "move;";
|
||||
return move_result;
|
||||
}
|
||||
|
||||
void goto_frame(int target_frame) override
|
||||
{
|
||||
gotos += 1;
|
||||
last_target_frame = target_frame;
|
||||
call_order += "goto;";
|
||||
}
|
||||
|
||||
void set_onion_size(int onion_size) override
|
||||
{
|
||||
onion_sets += 1;
|
||||
last_onion_size = onion_size;
|
||||
call_order += "onion;";
|
||||
}
|
||||
|
||||
void update_canvas_animation() override
|
||||
{
|
||||
canvas_updates += 1;
|
||||
call_order += "update;";
|
||||
}
|
||||
|
||||
void reload_animation_layers() override
|
||||
{
|
||||
reloads += 1;
|
||||
call_order += "reload;";
|
||||
}
|
||||
|
||||
void mark_unsaved() override
|
||||
{
|
||||
unsaved_marks += 1;
|
||||
call_order += "unsaved;";
|
||||
}
|
||||
|
||||
int adds = 0;
|
||||
int duplicates = 0;
|
||||
int removes = 0;
|
||||
int duration_sets = 0;
|
||||
int moves = 0;
|
||||
int gotos = 0;
|
||||
int onion_sets = 0;
|
||||
int canvas_updates = 0;
|
||||
int reloads = 0;
|
||||
int unsaved_marks = 0;
|
||||
int last_selected_frame = -1;
|
||||
int last_target_frame = -1;
|
||||
int last_duration = -1;
|
||||
int last_move_offset = 0;
|
||||
int last_onion_size = -1;
|
||||
int move_result = 0;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
void add_duplicate_and_remove_validate_frame_bounds(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto add = pp::app::plan_animation_add_frame(2, 0);
|
||||
@@ -120,6 +212,107 @@ void onion_size_updates_canvas_without_document_mutation(pp::tests::Harness& har
|
||||
PP_EXPECT(harness, !pp::app::plan_animation_onion_size(-1));
|
||||
}
|
||||
|
||||
void executor_dispatches_mutating_frame_operations(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentAnimationServices services;
|
||||
|
||||
const auto add = pp::app::plan_animation_add_frame(2, 0);
|
||||
PP_REQUIRE(harness, add);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(add.value(), services).ok());
|
||||
|
||||
const auto duplicate = pp::app::plan_animation_duplicate_frame(3, 1);
|
||||
PP_REQUIRE(harness, duplicate);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(duplicate.value(), services).ok());
|
||||
|
||||
const auto remove = pp::app::plan_animation_remove_frame(3, 2);
|
||||
PP_REQUIRE(harness, remove);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(remove.value(), services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.adds == 1);
|
||||
PP_EXPECT(harness, services.duplicates == 1);
|
||||
PP_EXPECT(harness, services.removes == 1);
|
||||
PP_EXPECT(harness, services.unsaved_marks == 3);
|
||||
PP_EXPECT(harness, services.canvas_updates == 2);
|
||||
PP_EXPECT(harness, services.gotos == 1);
|
||||
PP_EXPECT(harness, services.reloads == 3);
|
||||
PP_EXPECT(harness, services.last_selected_frame == 2);
|
||||
PP_EXPECT(harness, services.last_target_frame == 1);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order == "add;unsaved;update;reload;duplicate;unsaved;update;reload;remove;unsaved;goto;reload;");
|
||||
}
|
||||
|
||||
void executor_dispatches_timeline_and_parameter_operations(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentAnimationServices services;
|
||||
services.move_result = 2;
|
||||
|
||||
const auto duration = pp::app::plan_animation_adjust_duration(3, 1, 4, 1);
|
||||
PP_REQUIRE(harness, duration);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(duration.value(), services).ok());
|
||||
|
||||
const auto duration_noop = pp::app::plan_animation_adjust_duration(3, 1, 1, -1);
|
||||
PP_REQUIRE(harness, duration_noop);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(duration_noop.value(), services).ok());
|
||||
|
||||
const auto move = pp::app::plan_animation_move_frame(3, 1, 1);
|
||||
PP_REQUIRE(harness, move);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(move.value(), services).ok());
|
||||
|
||||
const auto next = pp::app::plan_animation_step_frame(5, 4, 1);
|
||||
PP_REQUIRE(harness, next);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(next.value(), services).ok());
|
||||
|
||||
const auto onion = pp::app::plan_animation_onion_size(3);
|
||||
PP_REQUIRE(harness, onion);
|
||||
PP_EXPECT(harness, pp::app::execute_animation_operation_plan(onion.value(), services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.duration_sets == 1);
|
||||
PP_EXPECT(harness, services.last_duration == 5);
|
||||
PP_EXPECT(harness, services.moves == 1);
|
||||
PP_EXPECT(harness, services.last_move_offset == 1);
|
||||
PP_EXPECT(harness, services.gotos == 2);
|
||||
PP_EXPECT(harness, services.last_target_frame == 0);
|
||||
PP_EXPECT(harness, services.onion_sets == 1);
|
||||
PP_EXPECT(harness, services.last_onion_size == 3);
|
||||
PP_EXPECT(harness, services.unsaved_marks == 2);
|
||||
PP_EXPECT(harness, services.canvas_updates == 2);
|
||||
PP_EXPECT(harness, services.reloads == 3);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order == "duration;unsaved;update;reload;move;unsaved;goto;reload;goto;reload;onion;update;");
|
||||
}
|
||||
|
||||
void executor_rejects_malformed_animation_plans(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentAnimationServices services;
|
||||
|
||||
auto add = pp::app::plan_animation_add_frame(2, 0).value();
|
||||
add.marks_unsaved = false;
|
||||
PP_EXPECT(harness, !pp::app::execute_animation_operation_plan(add, services).ok());
|
||||
|
||||
auto remove = pp::app::plan_animation_remove_frame(2, 1).value();
|
||||
remove.frame_count = 1;
|
||||
PP_EXPECT(harness, !pp::app::execute_animation_operation_plan(remove, services).ok());
|
||||
|
||||
auto duration = pp::app::plan_animation_adjust_duration(2, 1, 4, 1).value();
|
||||
duration.frame_duration = 0;
|
||||
PP_EXPECT(harness, !pp::app::execute_animation_operation_plan(duration, services).ok());
|
||||
|
||||
auto move = pp::app::plan_animation_move_frame(3, 1, 1).value();
|
||||
move.move_offset = 0;
|
||||
PP_EXPECT(harness, !pp::app::execute_animation_operation_plan(move, services).ok());
|
||||
|
||||
auto go = pp::app::plan_animation_goto_frame(3, 1).value();
|
||||
go.target_frame = 3;
|
||||
PP_EXPECT(harness, !pp::app::execute_animation_operation_plan(go, services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.adds == 0);
|
||||
PP_EXPECT(harness, services.duration_sets == 0);
|
||||
PP_EXPECT(harness, services.gotos == 0);
|
||||
PP_EXPECT(harness, services.call_order.empty());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -129,5 +322,8 @@ int main()
|
||||
harness.run("duration plans clamp floor and reject overflow", duration_plans_clamp_floor_and_reject_overflow);
|
||||
harness.run("move and timeline plans handle edges", move_and_timeline_plans_handle_edges);
|
||||
harness.run("onion size updates canvas without document mutation", onion_size_updates_canvas_without_document_mutation);
|
||||
harness.run("executor dispatches mutating frame operations", executor_dispatches_mutating_frame_operations);
|
||||
harness.run("executor dispatches timeline and parameter operations", executor_dispatches_timeline_and_parameter_operations);
|
||||
harness.run("executor rejects malformed animation plans", executor_rejects_malformed_animation_plans);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user