Add image export roundtrip automation
This commit is contained in:
@@ -283,6 +283,14 @@ if(TARGET pano_cli)
|
||||
LABELS "assets;document;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"import-image\".*\"image\":\\{\"format\":\"png\",\"width\":1,\"height\":1,\"bytes\":4\\}.*\"document\":\\{\"width\":64,\"height\":32,\"layers\":1,\"frames\":1,\"facePayloads\":1\\}.*\"payload\":\\{\"face\":5,\"x\":7,\"y\":11,\"width\":1,\"height\":1,\"bytes\":4\\}")
|
||||
|
||||
add_test(NAME pano_cli_export_image_roundtrip_smoke
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-DPANO_CLI=$<TARGET_FILE:pano_cli>
|
||||
-DOUTPUT_PATH=${CMAKE_CURRENT_BINARY_DIR}/data/generated/export-roundtrip.png
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/pano_cli_export_image_roundtrip.cmake")
|
||||
set_tests_properties(pano_cli_export_image_roundtrip_smoke PROPERTIES
|
||||
LABELS "assets;document;integration;desktop-fast")
|
||||
|
||||
add_test(NAME pano_cli_inspect_project_layout_smoke
|
||||
COMMAND pano_cli inspect-project --path "${CMAKE_CURRENT_SOURCE_DIR}/data/projects/minimal-project.ppi")
|
||||
set_tests_properties(pano_cli_inspect_project_layout_smoke PROPERTIES
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
using pp::assets::decode_png_rgba8;
|
||||
using pp::assets::encode_png_rgba8;
|
||||
using pp::foundation::StatusCode;
|
||||
|
||||
namespace {
|
||||
@@ -56,6 +58,36 @@ void rejects_corrupt_png_payload(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, image.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void encodes_rgba8_pixels_to_decodable_png(pp::tests::Harness& h)
|
||||
{
|
||||
const std::vector<std::uint8_t> pixels {
|
||||
255, 0, 0, 255,
|
||||
0, 255, 0, 128,
|
||||
};
|
||||
|
||||
const auto encoded = encode_png_rgba8(2, 1, pixels);
|
||||
|
||||
PP_EXPECT(h, encoded.ok());
|
||||
const auto decoded = decode_png_rgba8(encoded.value());
|
||||
PP_EXPECT(h, decoded.ok());
|
||||
PP_EXPECT(h, decoded.value().width == 2U);
|
||||
PP_EXPECT(h, decoded.value().height == 1U);
|
||||
PP_EXPECT(h, decoded.value().pixels == pixels);
|
||||
}
|
||||
|
||||
void rejects_invalid_png_encode_inputs(pp::tests::Harness& h)
|
||||
{
|
||||
const std::vector<std::uint8_t> pixels { 0, 0, 0, 0 };
|
||||
|
||||
const auto no_size = encode_png_rgba8(0, 1, pixels);
|
||||
const auto wrong_payload_size = encode_png_rgba8(2, 1, pixels);
|
||||
|
||||
PP_EXPECT(h, !no_size.ok());
|
||||
PP_EXPECT(h, no_size.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !wrong_payload_size.ok());
|
||||
PP_EXPECT(h, wrong_payload_size.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -63,5 +95,7 @@ int main()
|
||||
pp::tests::Harness harness;
|
||||
harness.run("decodes_png_to_rgba8_pixels", decodes_png_to_rgba8_pixels);
|
||||
harness.run("rejects_corrupt_png_payload", rejects_corrupt_png_payload);
|
||||
harness.run("encodes_rgba8_pixels_to_decodable_png", encodes_rgba8_pixels_to_decodable_png);
|
||||
harness.run("rejects_invalid_png_encode_inputs", rejects_invalid_png_encode_inputs);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
68
tests/cmake/pano_cli_export_image_roundtrip.cmake
Normal file
68
tests/cmake/pano_cli_export_image_roundtrip.cmake
Normal file
@@ -0,0 +1,68 @@
|
||||
if(NOT DEFINED PANO_CLI)
|
||||
message(FATAL_ERROR "PANO_CLI must be set")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED OUTPUT_PATH)
|
||||
message(FATAL_ERROR "OUTPUT_PATH must be set")
|
||||
endif()
|
||||
|
||||
get_filename_component(output_dir "${OUTPUT_PATH}" DIRECTORY)
|
||||
file(MAKE_DIRECTORY "${output_dir}")
|
||||
file(REMOVE "${OUTPUT_PATH}")
|
||||
|
||||
execute_process(
|
||||
COMMAND "${PANO_CLI}" export-image
|
||||
--path "${OUTPUT_PATH}"
|
||||
--width 3
|
||||
--height 2
|
||||
RESULT_VARIABLE export_result
|
||||
OUTPUT_VARIABLE export_output
|
||||
ERROR_VARIABLE export_error)
|
||||
|
||||
if(NOT export_result EQUAL 0)
|
||||
message(FATAL_ERROR "export-image failed: ${export_output}${export_error}")
|
||||
endif()
|
||||
|
||||
string(FIND "${export_output}" "\"command\":\"export-image\"" export_command_index)
|
||||
string(FIND "${export_output}" "\"format\":\"png\"" export_format_index)
|
||||
string(FIND "${export_output}" "\"width\":3" export_width_index)
|
||||
string(FIND "${export_output}" "\"height\":2" export_height_index)
|
||||
string(FIND "${export_output}" "\"bytes\":24" export_bytes_index)
|
||||
if(export_command_index LESS 0
|
||||
OR export_format_index LESS 0
|
||||
OR export_width_index LESS 0
|
||||
OR export_height_index LESS 0
|
||||
OR export_bytes_index LESS 0)
|
||||
message(FATAL_ERROR "export-image output did not contain expected summary: ${export_output}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${OUTPUT_PATH}")
|
||||
message(FATAL_ERROR "export-image did not create ${OUTPUT_PATH}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${PANO_CLI}" import-image
|
||||
--path "${OUTPUT_PATH}"
|
||||
--document-width 16
|
||||
--document-height 8
|
||||
--face 1
|
||||
--x 2
|
||||
--y 3
|
||||
RESULT_VARIABLE import_result
|
||||
OUTPUT_VARIABLE import_output
|
||||
ERROR_VARIABLE import_error)
|
||||
|
||||
if(NOT import_result EQUAL 0)
|
||||
message(FATAL_ERROR "import-image failed after export-image: ${import_output}${import_error}")
|
||||
endif()
|
||||
|
||||
string(FIND "${import_output}" "\"command\":\"import-image\"" import_command_index)
|
||||
string(FIND "${import_output}" "\"image\":{\"format\":\"png\",\"width\":3,\"height\":2,\"bytes\":24}" import_image_index)
|
||||
string(FIND "${import_output}" "\"document\":{\"width\":16,\"height\":8,\"layers\":1,\"frames\":1,\"facePayloads\":1}" import_document_index)
|
||||
string(FIND "${import_output}" "\"payload\":{\"face\":1,\"x\":2,\"y\":3,\"width\":3,\"height\":2,\"bytes\":24}" import_payload_index)
|
||||
if(import_command_index LESS 0
|
||||
OR import_image_index LESS 0
|
||||
OR import_document_index LESS 0
|
||||
OR import_payload_index LESS 0)
|
||||
message(FATAL_ERROR "import-image output did not contain expected exported-image summary: ${import_output}")
|
||||
endif()
|
||||
Reference in New Issue
Block a user