Add explicit PPI project writer
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
using pp::assets::parse_ppi_header;
|
||||
using pp::assets::create_ppi_project;
|
||||
using pp::assets::create_minimal_ppi_project;
|
||||
using pp::assets::decode_ppi_project_images;
|
||||
using pp::assets::parse_ppi_project_index;
|
||||
@@ -481,6 +482,64 @@ void creates_minimal_project_with_multiple_frames(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, index.value().body.layers[0].frames[2].duration_ms == 111U);
|
||||
}
|
||||
|
||||
void creates_explicit_project_with_layer_frame_metadata(pp::tests::Harness& h)
|
||||
{
|
||||
const pp::assets::PpiFrameConfig base_frames[] {
|
||||
{ .duration_ms = 100 },
|
||||
{ .duration_ms = 250 },
|
||||
};
|
||||
const pp::assets::PpiFrameConfig paint_frames[] {
|
||||
{ .duration_ms = 333 },
|
||||
};
|
||||
const pp::assets::PpiLayerConfig layers[] {
|
||||
{
|
||||
.name = "Base",
|
||||
.metadata = pp::assets::PpiLayerMetadataConfig {
|
||||
.opacity = 1.0F,
|
||||
.blend_mode = 0,
|
||||
.alpha_locked = false,
|
||||
.visible = true,
|
||||
},
|
||||
.frames = std::span<const pp::assets::PpiFrameConfig>(base_frames, 2),
|
||||
},
|
||||
{
|
||||
.name = "Paint",
|
||||
.metadata = pp::assets::PpiLayerMetadataConfig {
|
||||
.opacity = 0.5F,
|
||||
.blend_mode = 4,
|
||||
.alpha_locked = true,
|
||||
.visible = false,
|
||||
},
|
||||
.frames = std::span<const pp::assets::PpiFrameConfig>(paint_frames, 1),
|
||||
},
|
||||
};
|
||||
|
||||
const auto project = create_ppi_project(pp::assets::PpiProjectConfig {
|
||||
.width = 256,
|
||||
.height = 128,
|
||||
.layers = std::span<const pp::assets::PpiLayerConfig>(layers, 2),
|
||||
.dirty_faces = {},
|
||||
});
|
||||
|
||||
PP_EXPECT(h, project.ok());
|
||||
const auto index = parse_ppi_project_index(project.value());
|
||||
PP_EXPECT(h, index.ok());
|
||||
PP_EXPECT(h, index.value().body.summary.layer_count == 2U);
|
||||
PP_EXPECT(h, index.value().body.summary.declared_frame_count == 3U);
|
||||
PP_EXPECT(h, index.value().body.summary.total_layer_frames == 3U);
|
||||
PP_EXPECT(h, index.value().body.layers[0].name == "Base");
|
||||
PP_EXPECT(h, index.value().body.layers[0].frames.size() == 2U);
|
||||
PP_EXPECT(h, index.value().body.layers[0].frames[0].duration_ms == 100U);
|
||||
PP_EXPECT(h, index.value().body.layers[0].frames[1].duration_ms == 250U);
|
||||
PP_EXPECT(h, index.value().body.layers[1].name == "Paint");
|
||||
PP_EXPECT(h, index.value().body.layers[1].opacity == 0.5F);
|
||||
PP_EXPECT(h, index.value().body.layers[1].blend_mode == 4U);
|
||||
PP_EXPECT(h, index.value().body.layers[1].alpha_locked);
|
||||
PP_EXPECT(h, !index.value().body.layers[1].visible);
|
||||
PP_EXPECT(h, index.value().body.layers[1].frames.size() == 1U);
|
||||
PP_EXPECT(h, index.value().body.layers[1].frames[0].duration_ms == 333U);
|
||||
}
|
||||
|
||||
void creates_minimal_project_with_dirty_face_payload(pp::tests::Harness& h)
|
||||
{
|
||||
const auto png_payload = transparent_png_1x1();
|
||||
@@ -749,6 +808,71 @@ void rejects_invalid_minimal_project_writer_inputs(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, bad_frame_dirty_face.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void rejects_invalid_explicit_project_writer_inputs(pp::tests::Harness& h)
|
||||
{
|
||||
const pp::assets::PpiFrameConfig valid_frames[] {
|
||||
{ .duration_ms = 100 },
|
||||
};
|
||||
const pp::assets::PpiFrameConfig invalid_frames[] {
|
||||
{ .duration_ms = 0 },
|
||||
};
|
||||
const pp::assets::PpiLayerConfig unnamed_layers[] {
|
||||
{
|
||||
.name = "",
|
||||
.metadata = {},
|
||||
.frames = std::span<const pp::assets::PpiFrameConfig>(valid_frames, 1),
|
||||
},
|
||||
};
|
||||
const pp::assets::PpiLayerConfig frameless_layers[] {
|
||||
{
|
||||
.name = "Ink",
|
||||
.metadata = {},
|
||||
.frames = {},
|
||||
},
|
||||
};
|
||||
const pp::assets::PpiLayerConfig invalid_duration_layers[] {
|
||||
{
|
||||
.name = "Ink",
|
||||
.metadata = {},
|
||||
.frames = std::span<const pp::assets::PpiFrameConfig>(invalid_frames, 1),
|
||||
},
|
||||
};
|
||||
|
||||
const auto no_layers = create_ppi_project(pp::assets::PpiProjectConfig {
|
||||
.width = 128,
|
||||
.height = 64,
|
||||
.layers = {},
|
||||
.dirty_faces = {},
|
||||
});
|
||||
const auto unnamed = create_ppi_project(pp::assets::PpiProjectConfig {
|
||||
.width = 128,
|
||||
.height = 64,
|
||||
.layers = std::span<const pp::assets::PpiLayerConfig>(unnamed_layers, 1),
|
||||
.dirty_faces = {},
|
||||
});
|
||||
const auto frameless = create_ppi_project(pp::assets::PpiProjectConfig {
|
||||
.width = 128,
|
||||
.height = 64,
|
||||
.layers = std::span<const pp::assets::PpiLayerConfig>(frameless_layers, 1),
|
||||
.dirty_faces = {},
|
||||
});
|
||||
const auto invalid_duration = create_ppi_project(pp::assets::PpiProjectConfig {
|
||||
.width = 128,
|
||||
.height = 64,
|
||||
.layers = std::span<const pp::assets::PpiLayerConfig>(invalid_duration_layers, 1),
|
||||
.dirty_faces = {},
|
||||
});
|
||||
|
||||
PP_EXPECT(h, !no_layers.ok());
|
||||
PP_EXPECT(h, no_layers.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !unnamed.ok());
|
||||
PP_EXPECT(h, unnamed.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !frameless.ok());
|
||||
PP_EXPECT(h, frameless.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !invalid_duration.ok());
|
||||
PP_EXPECT(h, invalid_duration.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -769,8 +893,10 @@ int main()
|
||||
harness.run("creates_minimal_project_for_roundtrip_load", creates_minimal_project_for_roundtrip_load);
|
||||
harness.run("creates_minimal_project_with_multiple_layers", creates_minimal_project_with_multiple_layers);
|
||||
harness.run("creates_minimal_project_with_multiple_frames", creates_minimal_project_with_multiple_frames);
|
||||
harness.run("creates_explicit_project_with_layer_frame_metadata", creates_explicit_project_with_layer_frame_metadata);
|
||||
harness.run("creates_minimal_project_with_dirty_face_payload", creates_minimal_project_with_dirty_face_payload);
|
||||
harness.run("creates_minimal_project_with_targeted_dirty_face_payloads", creates_minimal_project_with_targeted_dirty_face_payloads);
|
||||
harness.run("rejects_invalid_minimal_project_writer_inputs", rejects_invalid_minimal_project_writer_inputs);
|
||||
harness.run("rejects_invalid_explicit_project_writer_inputs", rejects_invalid_explicit_project_writer_inputs);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user