Files
panopainter/tests/app_core/document_session_tests.cpp

167 lines
6.5 KiB
C++

#include "app_core/document_session.h"
#include "test_harness.h"
namespace {
void project_open_clean_document_executes_immediately(pp::tests::Harness& harness)
{
PP_EXPECT(harness, pp::app::plan_project_open(false) == pp::app::ProjectOpenDecision::open_now);
}
void project_open_dirty_document_prompts_for_discard(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_project_open(true) == pp::app::ProjectOpenDecision::prompt_discard_unsaved);
}
void close_clean_document_executes_immediately(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_close_request(false, false) == pp::app::CloseRequestDecision::close_now);
PP_EXPECT(
harness,
pp::app::plan_close_request(false, true) == pp::app::CloseRequestDecision::close_now);
}
void close_dirty_document_opens_one_prompt(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_close_request(true, false) == pp::app::CloseRequestDecision::show_unsaved_prompt);
PP_EXPECT(
harness,
pp::app::plan_close_request(true, true) == pp::app::CloseRequestDecision::wait_for_existing_prompt);
}
void save_clean_existing_document_is_no_op(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_save(false, false, pp::app::DocumentSaveIntent::save)
== pp::app::DocumentSaveDecision::no_op);
}
void save_new_or_dirty_document_has_user_visible_work(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_save(true, false, pp::app::DocumentSaveIntent::save)
== pp::app::DocumentSaveDecision::show_save_dialog);
PP_EXPECT(
harness,
pp::app::plan_document_save(false, true, pp::app::DocumentSaveIntent::save)
== pp::app::DocumentSaveDecision::save_existing);
}
void save_as_always_shows_save_dialog(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_save(false, false, pp::app::DocumentSaveIntent::save_as)
== pp::app::DocumentSaveDecision::show_save_dialog);
PP_EXPECT(
harness,
pp::app::plan_document_save(false, true, pp::app::DocumentSaveIntent::save_as)
== pp::app::DocumentSaveDecision::show_save_dialog);
}
void save_version_respects_menu_and_hotkey_behaviors(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_save(false, false, pp::app::DocumentSaveIntent::save_version)
== pp::app::DocumentSaveDecision::save_version);
PP_EXPECT(
harness,
pp::app::plan_document_save(false, false, pp::app::DocumentSaveIntent::save_dirty_version)
== pp::app::DocumentSaveDecision::no_op);
PP_EXPECT(
harness,
pp::app::plan_document_save(false, true, pp::app::DocumentSaveIntent::save_dirty_version)
== pp::app::DocumentSaveDecision::save_version);
PP_EXPECT(
harness,
pp::app::plan_document_save(true, false, pp::app::DocumentSaveIntent::save_version)
== pp::app::DocumentSaveDecision::show_save_dialog);
}
void workflow_without_canvas_is_unavailable(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_workflow(false, false)
== pp::app::DocumentWorkflowDecision::unavailable);
PP_EXPECT(
harness,
pp::app::plan_document_workflow(false, true)
== pp::app::DocumentWorkflowDecision::unavailable);
}
void workflow_with_clean_canvas_continues_now(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_workflow(true, false)
== pp::app::DocumentWorkflowDecision::continue_now);
}
void workflow_with_dirty_canvas_prompts_for_save(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_workflow(true, true)
== pp::app::DocumentWorkflowDecision::prompt_save_before_continue);
}
void document_file_target_rejects_empty_name(pp::tests::Harness& harness)
{
const auto target = pp::app::make_document_file_target("D:/Paint", "");
PP_EXPECT(harness, !target);
PP_EXPECT(harness, target.status().code == pp::foundation::StatusCode::invalid_argument);
}
void document_file_target_builds_legacy_ppi_path(pp::tests::Harness& harness)
{
const auto target = pp::app::make_document_file_target("D:/Paint", "demo");
PP_EXPECT(harness, target);
PP_EXPECT(harness, target.value().name == "demo");
PP_EXPECT(harness, target.value().directory == "D:/Paint");
PP_EXPECT(harness, target.value().path == "D:/Paint/demo.ppi");
}
void document_file_write_prompts_only_for_existing_targets(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::plan_document_file_write(false)
== pp::app::DocumentFileWriteDecision::save_now);
PP_EXPECT(
harness,
pp::app::plan_document_file_write(true)
== pp::app::DocumentFileWriteDecision::prompt_overwrite);
}
}
int main()
{
pp::tests::Harness harness;
harness.run("project open clean document executes immediately", project_open_clean_document_executes_immediately);
harness.run("project open dirty document prompts for discard", project_open_dirty_document_prompts_for_discard);
harness.run("close clean document executes immediately", close_clean_document_executes_immediately);
harness.run("close dirty document opens one prompt", close_dirty_document_opens_one_prompt);
harness.run("save clean existing document is no op", save_clean_existing_document_is_no_op);
harness.run("save new or dirty document has user visible work", save_new_or_dirty_document_has_user_visible_work);
harness.run("save as always shows save dialog", save_as_always_shows_save_dialog);
harness.run("save version respects menu and hotkey behaviors", save_version_respects_menu_and_hotkey_behaviors);
harness.run("workflow without canvas is unavailable", workflow_without_canvas_is_unavailable);
harness.run("workflow with clean canvas continues now", workflow_with_clean_canvas_continues_now);
harness.run("workflow with dirty canvas prompts for save", workflow_with_dirty_canvas_prompts_for_save);
harness.run("document file target rejects empty name", document_file_target_rejects_empty_name);
harness.run("document file target builds legacy ppi path", document_file_target_builds_legacy_ppi_path);
harness.run("document file write prompts only for existing targets", document_file_write_prompts_only_for_existing_targets);
return harness.finish();
}