Centralize legacy document image exports
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "app_core/document_export.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeDocumentExportMenuServices final : public pp::app::DocumentExportMenuServices {
|
||||
@@ -33,6 +36,80 @@ public:
|
||||
int license_messages = 0;
|
||||
};
|
||||
|
||||
class FakeDocumentExportServices final : public pp::app::DocumentExportServices {
|
||||
public:
|
||||
bool create_directory(std::string_view directory) override
|
||||
{
|
||||
create_dir_calls += 1;
|
||||
last_directory = std::string(directory);
|
||||
return create_directory_result;
|
||||
}
|
||||
|
||||
void export_equirectangular(const pp::app::DocumentExportFileTarget& target) override
|
||||
{
|
||||
equirectangular_exports += 1;
|
||||
last_path = target.path;
|
||||
call_order += "equirect;";
|
||||
}
|
||||
|
||||
void export_layers_to_stem(const pp::app::DocumentExportStemTarget& target) override
|
||||
{
|
||||
layer_stem_exports += 1;
|
||||
last_stem = target.stem_path;
|
||||
call_order += "layers-stem;";
|
||||
}
|
||||
|
||||
void export_layers_to_collection(const pp::app::DocumentExportCollectionTarget& target) override
|
||||
{
|
||||
layer_collection_exports += 1;
|
||||
last_stem = target.stem_path;
|
||||
call_order += "layers-collection;";
|
||||
}
|
||||
|
||||
void export_animation_frames_to_stem(const pp::app::DocumentExportStemTarget& target) override
|
||||
{
|
||||
frame_stem_exports += 1;
|
||||
last_stem = target.stem_path;
|
||||
call_order += "frames-stem;";
|
||||
}
|
||||
|
||||
void export_animation_frames_to_collection(const pp::app::DocumentExportCollectionTarget& target) override
|
||||
{
|
||||
frame_collection_exports += 1;
|
||||
last_stem = target.stem_path;
|
||||
call_order += "frames-collection;";
|
||||
}
|
||||
|
||||
void export_depth(std::string_view document_name) override
|
||||
{
|
||||
depth_exports += 1;
|
||||
last_name = std::string(document_name);
|
||||
call_order += "depth;";
|
||||
}
|
||||
|
||||
void export_cube_faces(std::string_view document_name) override
|
||||
{
|
||||
cube_exports += 1;
|
||||
last_name = std::string(document_name);
|
||||
call_order += "cube;";
|
||||
}
|
||||
|
||||
bool create_directory_result = true;
|
||||
int create_dir_calls = 0;
|
||||
int equirectangular_exports = 0;
|
||||
int layer_stem_exports = 0;
|
||||
int layer_collection_exports = 0;
|
||||
int frame_stem_exports = 0;
|
||||
int frame_collection_exports = 0;
|
||||
int depth_exports = 0;
|
||||
int cube_exports = 0;
|
||||
std::string last_directory;
|
||||
std::string last_path;
|
||||
std::string last_stem;
|
||||
std::string last_name;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
void equirectangular_export_builds_file_target(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_export_file_target("D:/Paint", "demo", ".png");
|
||||
@@ -253,6 +330,107 @@ void export_menu_executor_preserves_blocked_and_unavailable_actions(pp::tests::H
|
||||
PP_EXPECT(harness, services.total_calls() == 1);
|
||||
}
|
||||
|
||||
void export_executor_dispatches_file_stem_collection_and_named_exports(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentExportServices services;
|
||||
const auto file = pp::app::make_document_export_file_target("D:/Paint", "demo", ".png");
|
||||
const auto collection = pp::app::make_document_export_collection_target("D:/Paint", "demo", "_layers");
|
||||
const auto stem = pp::app::make_document_export_stem_target("D:/Exports", "demo");
|
||||
|
||||
PP_EXPECT(harness, file);
|
||||
PP_EXPECT(harness, collection);
|
||||
PP_EXPECT(harness, stem);
|
||||
PP_EXPECT(harness, pp::app::execute_document_export_file(file.value(), services).ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_stem(
|
||||
pp::app::DocumentExportCollectionKind::layers,
|
||||
stem.value(),
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_stem(
|
||||
pp::app::DocumentExportCollectionKind::animation_frames,
|
||||
stem.value(),
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_collection(
|
||||
pp::app::DocumentExportCollectionKind::layers,
|
||||
collection.value(),
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_collection(
|
||||
pp::app::DocumentExportCollectionKind::animation_frames,
|
||||
collection.value(),
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(harness, pp::app::execute_document_export_depth("demo", services).ok());
|
||||
PP_EXPECT(harness, pp::app::execute_document_export_cube_faces("demo", services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.create_dir_calls == 2);
|
||||
PP_EXPECT(harness, services.equirectangular_exports == 1);
|
||||
PP_EXPECT(harness, services.layer_stem_exports == 1);
|
||||
PP_EXPECT(harness, services.layer_collection_exports == 1);
|
||||
PP_EXPECT(harness, services.frame_stem_exports == 1);
|
||||
PP_EXPECT(harness, services.frame_collection_exports == 1);
|
||||
PP_EXPECT(harness, services.depth_exports == 1);
|
||||
PP_EXPECT(harness, services.cube_exports == 1);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "equirect;layers-stem;frames-stem;layers-collection;frames-collection;depth;cube;");
|
||||
}
|
||||
|
||||
void export_executor_preserves_failed_directory_creation(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentExportServices services;
|
||||
services.create_directory_result = false;
|
||||
const auto collection = pp::app::make_document_export_collection_target("D:/Paint", "demo", "_layers");
|
||||
|
||||
PP_EXPECT(harness, collection);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_export_collection(
|
||||
pp::app::DocumentExportCollectionKind::layers,
|
||||
collection.value(),
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(harness, services.create_dir_calls == 1);
|
||||
PP_EXPECT(harness, services.layer_collection_exports == 0);
|
||||
PP_EXPECT(harness, services.call_order.empty());
|
||||
}
|
||||
|
||||
void export_executor_rejects_malformed_targets(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeDocumentExportServices services;
|
||||
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_file(pp::app::DocumentExportFileTarget {}, services).ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_stem(
|
||||
pp::app::DocumentExportCollectionKind::layers,
|
||||
pp::app::DocumentExportStemTarget {},
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_export_collection(
|
||||
pp::app::DocumentExportCollectionKind::animation_frames,
|
||||
pp::app::DocumentExportCollectionTarget {},
|
||||
services)
|
||||
.ok());
|
||||
PP_EXPECT(harness, !pp::app::execute_document_export_depth("", services).ok());
|
||||
PP_EXPECT(harness, !pp::app::execute_document_export_cube_faces("", services).ok());
|
||||
PP_EXPECT(harness, services.call_order.empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -271,5 +449,10 @@ int main()
|
||||
harness.run("export menu reports missing canvas for unlicensed image exports", export_menu_reports_missing_canvas_for_unlicensed_image_exports);
|
||||
harness.run("export menu executor dispatches all dialog actions", export_menu_executor_dispatches_all_dialog_actions);
|
||||
harness.run("export menu executor preserves blocked and unavailable actions", export_menu_executor_preserves_blocked_and_unavailable_actions);
|
||||
harness.run(
|
||||
"export executor dispatches file stem collection and named exports",
|
||||
export_executor_dispatches_file_stem_collection_and_named_exports);
|
||||
harness.run("export executor preserves failed directory creation", export_executor_preserves_failed_directory_creation);
|
||||
harness.run("export executor rejects malformed targets", export_executor_rejects_malformed_targets);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user