Dispatch cube export writes through app core
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "app_core/document_export.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
@@ -149,6 +152,55 @@ public:
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
class FakeDocumentCubeFaceExportWriteServices final : public pp::app::DocumentCubeFaceExportWriteServices {
|
||||
public:
|
||||
pp::foundation::Status write_binary_file(
|
||||
std::string_view path,
|
||||
std::span<const std::byte> bytes) override
|
||||
{
|
||||
write_calls += 1;
|
||||
last_path = std::string(path);
|
||||
total_bytes += bytes.size();
|
||||
call_order += "write:";
|
||||
call_order += path;
|
||||
call_order += ";";
|
||||
if (fail_on_write_call == write_calls) {
|
||||
return pp::foundation::Status::invalid_argument("write failed");
|
||||
}
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
void publish_exported_image(std::string_view path) override
|
||||
{
|
||||
publish_calls += 1;
|
||||
last_published_path = std::string(path);
|
||||
call_order += "publish:";
|
||||
call_order += path;
|
||||
call_order += ";";
|
||||
}
|
||||
|
||||
int write_calls = 0;
|
||||
int publish_calls = 0;
|
||||
int fail_on_write_call = -1;
|
||||
std::size_t total_bytes = 0;
|
||||
std::string last_path;
|
||||
std::string last_published_path;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
std::array<pp::app::DocumentCubeFaceExportPayload, 6> make_test_cube_face_payloads(
|
||||
const std::array<std::array<std::byte, 4>, 6>& bytes)
|
||||
{
|
||||
return {
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[0]) },
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[1]) },
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[2]) },
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[3]) },
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[4]) },
|
||||
pp::app::DocumentCubeFaceExportPayload { .bytes = std::span<const std::byte>(bytes[5]) },
|
||||
};
|
||||
}
|
||||
|
||||
void equirectangular_export_builds_file_target(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_export_file_target("D:/Paint", "demo", ".png");
|
||||
@@ -212,6 +264,89 @@ void cube_face_export_rejects_invalid_target_inputs(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, missing_name.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void cube_face_export_writer_writes_and_publishes_faces_in_order(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_cube_face_export_target("D:/Paint", "demo");
|
||||
const std::array<std::array<std::byte, 4>, 6> bytes {};
|
||||
const auto payloads = make_test_cube_face_payloads(bytes);
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_document_cube_face_export_write(target.value(), payloads, services).ok());
|
||||
PP_EXPECT(harness, services.write_calls == 6);
|
||||
PP_EXPECT(harness, services.publish_calls == 6);
|
||||
PP_EXPECT(harness, services.total_bytes == 24U);
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/demo-bottom.png");
|
||||
PP_EXPECT(harness, services.last_published_path == "D:/Paint/demo-bottom.png");
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "write:D:/Paint/demo-front.png;publish:D:/Paint/demo-front.png;"
|
||||
"write:D:/Paint/demo-right.png;publish:D:/Paint/demo-right.png;"
|
||||
"write:D:/Paint/demo-back.png;publish:D:/Paint/demo-back.png;"
|
||||
"write:D:/Paint/demo-left.png;publish:D:/Paint/demo-left.png;"
|
||||
"write:D:/Paint/demo-top.png;publish:D:/Paint/demo-top.png;"
|
||||
"write:D:/Paint/demo-bottom.png;publish:D:/Paint/demo-bottom.png;");
|
||||
}
|
||||
|
||||
void cube_face_export_writer_stops_before_publish_on_write_failure(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::make_document_cube_face_export_target("D:/Paint", "demo");
|
||||
const std::array<std::array<std::byte, 4>, 6> bytes {};
|
||||
const auto payloads = make_test_cube_face_payloads(bytes);
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
services.fail_on_write_call = 2;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
const auto status = pp::app::execute_document_cube_face_export_write(target.value(), payloads, services);
|
||||
PP_EXPECT(harness, !status.ok());
|
||||
PP_EXPECT(harness, services.write_calls == 2);
|
||||
PP_EXPECT(harness, services.publish_calls == 1);
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
services.call_order
|
||||
== "write:D:/Paint/demo-front.png;publish:D:/Paint/demo-front.png;"
|
||||
"write:D:/Paint/demo-right.png;");
|
||||
}
|
||||
|
||||
void cube_face_export_writer_rejects_malformed_inputs(pp::tests::Harness& harness)
|
||||
{
|
||||
auto target = pp::app::make_document_cube_face_export_target("D:/Paint", "demo");
|
||||
const std::array<std::array<std::byte, 4>, 6> bytes {};
|
||||
auto payloads = make_test_cube_face_payloads(bytes);
|
||||
FakeDocumentCubeFaceExportWriteServices services;
|
||||
|
||||
PP_EXPECT(harness, target);
|
||||
auto malformed_target = target.value();
|
||||
malformed_target.face_count = 5U;
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_cube_face_export_write(malformed_target, payloads, services).ok());
|
||||
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_cube_face_export_write(
|
||||
target.value(),
|
||||
std::span<const pp::app::DocumentCubeFaceExportPayload>(payloads.data(), payloads.size() - 1U),
|
||||
services)
|
||||
.ok());
|
||||
|
||||
auto empty_path_target = target.value();
|
||||
empty_path_target.faces[0].path.clear();
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_cube_face_export_write(empty_path_target, payloads, services).ok());
|
||||
|
||||
payloads[0].bytes = {};
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
!pp::app::execute_document_cube_face_export_write(target.value(), payloads, services).ok());
|
||||
PP_EXPECT(harness, services.write_calls == 0);
|
||||
PP_EXPECT(harness, services.publish_calls == 0);
|
||||
}
|
||||
|
||||
void video_export_builds_suggested_name(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto timelapse = pp::app::make_document_export_suggested_name("demo", "-timelapse");
|
||||
@@ -749,6 +884,13 @@ int main()
|
||||
harness.run("picked directory export builds stem", picked_directory_export_builds_stem);
|
||||
harness.run("cube face export builds legacy work paths", cube_face_export_builds_legacy_work_paths);
|
||||
harness.run("cube face export rejects invalid target inputs", cube_face_export_rejects_invalid_target_inputs);
|
||||
harness.run(
|
||||
"cube face export writer writes and publishes faces in order",
|
||||
cube_face_export_writer_writes_and_publishes_faces_in_order);
|
||||
harness.run(
|
||||
"cube face export writer stops before publish on write failure",
|
||||
cube_face_export_writer_stops_before_publish_on_write_failure);
|
||||
harness.run("cube face export writer rejects malformed inputs", cube_face_export_writer_rejects_malformed_inputs);
|
||||
harness.run("video export builds suggested name", video_export_builds_suggested_name);
|
||||
harness.run("collection export target plan selects platform destination", collection_export_target_plan_selects_platform_destination);
|
||||
harness.run("export success dialog plans image destinations", export_success_dialog_plans_image_destinations);
|
||||
|
||||
Reference in New Issue
Block a user