Centralize legacy document file saves
This commit is contained in:
@@ -132,6 +132,44 @@ public:
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
class FakeDocumentFileSaveServices final : public pp::app::DocumentFileSaveServices {
|
||||
public:
|
||||
void save_document_file(const pp::app::DocumentFileSavePlan& plan) override
|
||||
{
|
||||
saves += 1;
|
||||
last_path = plan.target.path;
|
||||
call_order += "save-file;";
|
||||
}
|
||||
|
||||
void prompt_overwrite_document_file(const pp::app::DocumentFileSavePlan& plan) override
|
||||
{
|
||||
overwrite_prompts += 1;
|
||||
last_path = plan.target.path;
|
||||
call_order += "overwrite-file;";
|
||||
}
|
||||
|
||||
int saves = 0;
|
||||
int overwrite_prompts = 0;
|
||||
std::string last_path;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
class FakeDocumentVersionSaveServices final : public pp::app::DocumentVersionSaveServices {
|
||||
public:
|
||||
void save_document_version(const pp::app::DocumentVersionTarget& target) override
|
||||
{
|
||||
saves += 1;
|
||||
last_name = target.name;
|
||||
last_path = target.path;
|
||||
call_order += "save-version;";
|
||||
}
|
||||
|
||||
int saves = 0;
|
||||
std::string last_name;
|
||||
std::string last_path;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
[[nodiscard]] pp::app::DocumentOpenRoute project_route()
|
||||
{
|
||||
return {
|
||||
@@ -506,6 +544,29 @@ void document_file_save_plan_rejects_empty_name(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void document_file_save_executor_dispatches_save_and_overwrite_paths(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentFileSaveServices services;
|
||||
auto save = pp::app::plan_document_file_save(
|
||||
"D:/Paint",
|
||||
"demo",
|
||||
[](const std::string&) { return false; });
|
||||
auto overwrite = pp::app::plan_document_file_save(
|
||||
"D:/Paint",
|
||||
"demo",
|
||||
[](const std::string& path) { return path == "D:/Paint/demo.ppi"; });
|
||||
|
||||
PP_EXPECT(harness, save);
|
||||
PP_EXPECT(harness, overwrite);
|
||||
PP_EXPECT(harness, pp::app::execute_document_file_save_plan(save.value(), services).ok());
|
||||
PP_EXPECT(harness, pp::app::execute_document_file_save_plan(overwrite.value(), services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.saves == 1);
|
||||
PP_EXPECT(harness, services.overwrite_prompts == 1);
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/demo.ppi");
|
||||
PP_EXPECT(harness, services.call_order == "save-file;overwrite-file;");
|
||||
}
|
||||
|
||||
void document_resolution_index_maps_legacy_choices(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto first = pp::app::document_resolution_from_index(0);
|
||||
@@ -654,6 +715,32 @@ void document_version_target_reports_when_no_slots_remain(pp::tests::Harness& ha
|
||||
PP_EXPECT(harness, target.status().code == pp::foundation::StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void document_version_executor_dispatches_and_rejects_empty_targets(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentVersionSaveServices services;
|
||||
const pp::app::DocumentVersionTarget valid {
|
||||
.name = "demo.02",
|
||||
.path = "D:/Paint/demo.02.ppi",
|
||||
};
|
||||
const pp::app::DocumentVersionTarget missing_name {
|
||||
.name = "",
|
||||
.path = "D:/Paint/demo.02.ppi",
|
||||
};
|
||||
const pp::app::DocumentVersionTarget missing_path {
|
||||
.name = "demo.02",
|
||||
.path = "",
|
||||
};
|
||||
|
||||
PP_EXPECT(harness, pp::app::execute_document_version_save(valid, services).ok());
|
||||
PP_EXPECT(harness, !pp::app::execute_document_version_save(missing_name, services).ok());
|
||||
PP_EXPECT(harness, !pp::app::execute_document_version_save(missing_path, services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.saves == 1);
|
||||
PP_EXPECT(harness, services.last_name == "demo.02");
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/demo.02.ppi");
|
||||
PP_EXPECT(harness, services.call_order == "save-version;");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -686,6 +773,7 @@ int main()
|
||||
"document file save plan combines target and write decision",
|
||||
document_file_save_plan_combines_target_and_write_decision);
|
||||
harness.run("document file save plan rejects empty name", document_file_save_plan_rejects_empty_name);
|
||||
harness.run("document file save executor dispatches save and overwrite paths", document_file_save_executor_dispatches_save_and_overwrite_paths);
|
||||
harness.run("document resolution index maps legacy choices", document_resolution_index_maps_legacy_choices);
|
||||
harness.run("document resolution index rejects out of range", document_resolution_index_rejects_out_of_range);
|
||||
harness.run(
|
||||
@@ -701,5 +789,6 @@ int main()
|
||||
"document version target preserves legacy nonnumeric suffix handling",
|
||||
document_version_target_preserves_legacy_nonnumeric_suffix_handling);
|
||||
harness.run("document version target reports when no slots remain", document_version_target_reports_when_no_slots_remain);
|
||||
harness.run("document version executor dispatches and rejects empty targets", document_version_executor_dispatches_and_rejects_empty_targets);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user