Validate PPI project layout
This commit is contained in:
@@ -230,6 +230,12 @@ if(TARGET pano_cli)
|
||||
LABELS "assets;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"format\":\"png\".*\"width\":320.*\"height\":240.*\"components\":4.*\"colorType\":\"rgba\"")
|
||||
|
||||
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
|
||||
LABELS "assets;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"thumbnail\":\\{\"width\":128,\"height\":128,\"components\":4,\"bytes\":65536\\}.*\"body\":\\{\"offset\":65576,\"bytes\":7\\}")
|
||||
|
||||
add_test(NAME pano_cli_parse_layout_smoke
|
||||
COMMAND pano_cli parse-layout --path "${CMAKE_CURRENT_SOURCE_DIR}/data/layouts/simple-layout.xml")
|
||||
set_tests_properties(pano_cli_parse_layout_smoke PROPERTIES
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#include <vector>
|
||||
|
||||
using pp::assets::parse_ppi_header;
|
||||
using pp::assets::parse_ppi_project_layout;
|
||||
using pp::assets::ppi_header_size;
|
||||
using pp::assets::ppi_thumbnail_byte_size;
|
||||
using pp::foundation::StatusCode;
|
||||
|
||||
namespace {
|
||||
@@ -96,6 +98,33 @@ void rejects_unsupported_document_versions(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, minor_result.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void parses_project_layout_with_thumbnail_and_body(pp::tests::Harness& h)
|
||||
{
|
||||
auto bytes = valid_header();
|
||||
const auto thumbnail_size = ppi_thumbnail_byte_size(parse_ppi_header(bytes).value().thumbnail);
|
||||
PP_EXPECT(h, thumbnail_size.ok());
|
||||
bytes.resize(ppi_header_size + thumbnail_size.value() + 7U, std::byte { 0xaa });
|
||||
|
||||
const auto layout = parse_ppi_project_layout(bytes);
|
||||
|
||||
PP_EXPECT(h, layout.ok());
|
||||
PP_EXPECT(h, layout.value().thumbnail_offset == ppi_header_size);
|
||||
PP_EXPECT(h, layout.value().thumbnail_bytes == 128U * 128U * 4U);
|
||||
PP_EXPECT(h, layout.value().body_offset == ppi_header_size + (128U * 128U * 4U));
|
||||
PP_EXPECT(h, layout.value().body_bytes == 7U);
|
||||
}
|
||||
|
||||
void rejects_project_layout_with_truncated_thumbnail(pp::tests::Harness& h)
|
||||
{
|
||||
auto bytes = valid_header();
|
||||
bytes.resize(ppi_header_size + (128U * 128U * 4U) - 1U, std::byte { 0 });
|
||||
|
||||
const auto layout = parse_ppi_project_layout(bytes);
|
||||
|
||||
PP_EXPECT(h, !layout.ok());
|
||||
PP_EXPECT(h, layout.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -104,5 +133,7 @@ int main()
|
||||
harness.run("parses_legacy_ppi_header", parses_legacy_ppi_header);
|
||||
harness.run("rejects_truncated_invalid_magic_and_bad_thumbnail", rejects_truncated_invalid_magic_and_bad_thumbnail);
|
||||
harness.run("rejects_unsupported_document_versions", rejects_unsupported_document_versions);
|
||||
harness.run("parses_project_layout_with_thumbnail_and_body", parses_project_layout_with_thumbnail_and_body);
|
||||
harness.run("rejects_project_layout_with_truncated_thumbnail", rejects_project_layout_with_truncated_thumbnail);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
BIN
tests/data/projects/minimal-project.ppi
Normal file
BIN
tests/data/projects/minimal-project.ppi
Normal file
Binary file not shown.
Reference in New Issue
Block a user