Validate snapshot face payloads

This commit is contained in:
2026-06-02 11:14:41 +02:00
parent bad2670f87
commit 7b14c356db
6 changed files with 128 additions and 14 deletions

View File

@@ -311,6 +311,88 @@ void rejects_invalid_snapshot_metadata(pp::tests::Harness& h)
PP_EXPECT(h, bad_layer_frame.status().code == StatusCode::invalid_argument);
}
void rejects_invalid_snapshot_face_pixels(pp::tests::Harness& h)
{
const AnimationFrame frames[] { { .duration_ms = 100, .face_pixels = {} } };
const AnimationFrame bad_byte_count_frames[] {
{
.duration_ms = 100,
.face_pixels = {
LayerFacePixels {
.face_index = 0,
.x = 0,
.y = 0,
.width = 1,
.height = 1,
.rgba8 = {},
},
},
},
};
const AnimationFrame outside_frames[] {
{
.duration_ms = 100,
.face_pixels = {
LayerFacePixels {
.face_index = 0,
.x = 63,
.y = 0,
.width = 2,
.height = 1,
.rgba8 = { 1, 2, 3, 4, 5, 6, 7, 8 },
},
},
},
};
const DocumentLayerConfig bad_byte_count_layers[] {
{
.name = "Ink",
.frames = bad_byte_count_frames,
},
};
const DocumentLayerConfig outside_layers[] {
{
.name = "Ink",
.frames = outside_frames,
},
};
const DocumentLayerConfig layers[] {
{
.name = "Ink",
.frames = {},
},
};
const auto bad_layer_payload = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = bad_byte_count_layers,
.frames = frames,
.selection_masks = {},
});
const auto outside_layer_payload = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = outside_layers,
.frames = frames,
.selection_masks = {},
});
const auto bad_root_payload = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = layers,
.frames = bad_byte_count_frames,
.selection_masks = {},
});
PP_EXPECT(h, !bad_layer_payload.ok());
PP_EXPECT(h, bad_layer_payload.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !outside_layer_payload.ok());
PP_EXPECT(h, outside_layer_payload.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_root_payload.ok());
PP_EXPECT(h, bad_root_payload.status().code == StatusCode::invalid_argument);
}
void manages_animation_frames_and_duration(pp::tests::Harness& h)
{
auto document_result = CanvasDocument::create(
@@ -744,6 +826,7 @@ int main()
harness.run("creates_document_from_snapshot_metadata", creates_document_from_snapshot_metadata);
harness.run("preserves_per_layer_snapshot_timelines", preserves_per_layer_snapshot_timelines);
harness.run("rejects_invalid_snapshot_metadata", rejects_invalid_snapshot_metadata);
harness.run("rejects_invalid_snapshot_face_pixels", rejects_invalid_snapshot_face_pixels);
harness.run("manages_animation_frames_and_duration", manages_animation_frames_and_duration);
harness.run("moves_frames_and_preserves_active_frame_identity", moves_frames_and_preserves_active_frame_identity);
harness.run("rejects_invalid_animation_frame_operations", rejects_invalid_animation_frame_operations);

View File

@@ -122,7 +122,7 @@ void exports_document_metadata_and_face_payloads(pp::tests::Harness& h)
PP_EXPECT(h, imported.value().face_pixel_payload_count() == 2U);
}
void rejects_export_when_document_payload_cannot_encode(pp::tests::Harness& h)
void rejects_snapshot_payload_that_cannot_export(pp::tests::Harness& h)
{
const AnimationFrame root_frames[] {
{ .duration_ms = 100, .face_pixels = {} },
@@ -161,12 +161,8 @@ void rejects_export_when_document_payload_cannot_encode(pp::tests::Harness& h)
.selection_masks = {},
});
PP_EXPECT(h, document.ok());
const auto exported = export_ppi_project_document(document.value());
PP_EXPECT(h, !exported.ok());
PP_EXPECT(h, exported.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !document.ok());
PP_EXPECT(h, document.status().code == StatusCode::invalid_argument);
}
}
@@ -175,6 +171,6 @@ int main()
{
pp::tests::Harness harness;
harness.run("exports_document_metadata_and_face_payloads", exports_document_metadata_and_face_payloads);
harness.run("rejects_export_when_document_payload_cannot_encode", rejects_export_when_document_payload_cannot_encode);
harness.run("rejects_snapshot_payload_that_cannot_export", rejects_snapshot_payload_that_cannot_export);
return harness.finish();
}