Route layer merge through app core
This commit is contained in:
@@ -152,6 +152,22 @@ public:
|
||||
std::string last_name;
|
||||
};
|
||||
|
||||
class FakeDocumentLayerMergeServices final : public pp::app::DocumentLayerMergeServices {
|
||||
public:
|
||||
void merge_layers(int from_index, int to_index, bool create_history) override
|
||||
{
|
||||
merge_calls += 1;
|
||||
last_from_index = from_index;
|
||||
last_to_index = to_index;
|
||||
last_create_history = create_history;
|
||||
}
|
||||
|
||||
int merge_calls = 0;
|
||||
int last_from_index = -1;
|
||||
int last_to_index = -1;
|
||||
bool last_create_history = false;
|
||||
};
|
||||
|
||||
void layer_rename_records_changed_name(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_document_layer_rename("Base", "Paint");
|
||||
@@ -724,6 +740,63 @@ void layer_menu_executor_preserves_no_op_actions(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, services.total_calls() == 0);
|
||||
}
|
||||
|
||||
void layer_merge_plan_validates_supported_merge(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto plan = pp::app::plan_document_layer_merge(3, 2, 1, 1);
|
||||
PP_EXPECT(harness, plan);
|
||||
if (plan) {
|
||||
PP_EXPECT(harness, plan.value().from_index == 2);
|
||||
PP_EXPECT(harness, plan.value().to_index == 1);
|
||||
PP_EXPECT(harness, plan.value().create_history);
|
||||
}
|
||||
|
||||
const auto no_history = pp::app::plan_document_layer_merge(3, 2, 0, 1, false);
|
||||
PP_EXPECT(harness, no_history);
|
||||
if (no_history) {
|
||||
PP_EXPECT(harness, !no_history.value().create_history);
|
||||
}
|
||||
}
|
||||
|
||||
void layer_merge_plan_rejects_bad_or_unsupported_state(pp::tests::Harness& harness)
|
||||
{
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(0, 0, 0, 1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 3, 1, 1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 1, 3, 1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 1, 1, 1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 0, 1, 1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 2, 1, -1));
|
||||
PP_EXPECT(harness, !pp::app::plan_document_layer_merge(3, 2, 1, 2));
|
||||
}
|
||||
|
||||
void layer_merge_executor_dispatches_merge(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentLayerMergeServices services;
|
||||
|
||||
const auto plan = pp::app::plan_document_layer_merge(3, 2, 1, 1);
|
||||
PP_EXPECT(harness, plan);
|
||||
if (plan) {
|
||||
PP_EXPECT(harness, pp::app::execute_document_layer_merge_plan(plan.value(), services).ok());
|
||||
PP_EXPECT(harness, services.merge_calls == 1);
|
||||
PP_EXPECT(harness, services.last_from_index == 2);
|
||||
PP_EXPECT(harness, services.last_to_index == 1);
|
||||
PP_EXPECT(harness, services.last_create_history);
|
||||
}
|
||||
}
|
||||
|
||||
void layer_merge_executor_rejects_malformed_plan(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentLayerMergeServices services;
|
||||
|
||||
pp::app::DocumentLayerMergePlan malformed;
|
||||
malformed.from_index = 1;
|
||||
malformed.to_index = 1;
|
||||
|
||||
const auto status = pp::app::execute_document_layer_merge_plan(malformed, services);
|
||||
PP_EXPECT(harness, !status.ok());
|
||||
PP_EXPECT(harness, status.code == pp::foundation::StatusCode::invalid_argument);
|
||||
PP_EXPECT(harness, services.merge_calls == 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -750,5 +823,9 @@ int main()
|
||||
harness.run("layer menu handles missing selection and bad state", layer_menu_handles_missing_selection_and_bad_state);
|
||||
harness.run("layer menu executor dispatches menu actions", layer_menu_executor_dispatches_menu_actions);
|
||||
harness.run("layer menu executor preserves no op actions", layer_menu_executor_preserves_no_op_actions);
|
||||
harness.run("layer merge plan validates supported merge", layer_merge_plan_validates_supported_merge);
|
||||
harness.run("layer merge plan rejects bad or unsupported state", layer_merge_plan_rejects_bad_or_unsupported_state);
|
||||
harness.run("layer merge executor dispatches merge", layer_merge_executor_dispatches_merge);
|
||||
harness.run("layer merge executor rejects malformed plan", layer_merge_executor_rejects_malformed_plan);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user