Add document selection mask automation

This commit is contained in:
2026-06-02 10:55:12 +02:00
parent 1ab2a9b846
commit ddca24779e
9 changed files with 304 additions and 20 deletions

View File

@@ -334,7 +334,7 @@ if(TARGET pano_cli)
COMMAND pano_cli simulate-document-edits --width 128 --height 64)
set_tests_properties(pano_cli_simulate_document_edits_smoke PROPERTIES
LABELS "document;integration;desktop-fast"
PASS_REGULAR_EXPRESSION "\"command\":\"simulate-document-edits\".*\"document\":\\{\"width\":128,\"height\":64,\"layers\":2,\"frames\":3,\"activeLayer\":0,\"activeFrame\":0,\"animationDurationMs\":683,\"facePayloads\":1\\}.*\"activeLayer\":\\{\"name\":\"Ink\",\"visible\":false,\"alphaLocked\":true,\"opacity\":0.625,\"blendMode\":\"overlay\",\"frames\":3\\}.*\"frames\":\\[250,100,333\\].*\"activeLayerFrameDurations\":\\[250,100,333\\]")
PASS_REGULAR_EXPRESSION "\"command\":\"simulate-document-edits\".*\"document\":\\{\"width\":128,\"height\":64,\"layers\":2,\"frames\":3,\"activeLayer\":0,\"activeFrame\":0,\"animationDurationMs\":683,\"facePayloads\":1,\"selectionMasks\":1\\}.*\"activeLayer\":\\{\"name\":\"Ink\",\"visible\":false,\"alphaLocked\":true,\"opacity\":0.625,\"blendMode\":\"overlay\",\"frames\":3\\}.*\"frames\":\\[250,100,333\\].*\"activeLayerFrameDurations\":\\[250,100,333\\].*\"selectionMask\":\\{\"face\":4,\"x\":3,\"y\":5,\"width\":2,\"height\":2,\"bytes\":4,\"maxAlpha\":255\\}")
add_test(NAME pano_cli_simulate_document_history_smoke
COMMAND pano_cli simulate-document-history --width 64 --height 32 --history 4)

View File

@@ -12,6 +12,7 @@ using pp::document::DocumentLayerConfig;
using pp::document::DocumentSnapshotConfig;
using pp::document::AnimationFrame;
using pp::document::LayerFacePixels;
using pp::document::SelectionMask;
using pp::document::max_document_history_entries;
using pp::document::max_canvas_dimension;
using pp::document::max_frame_count;
@@ -196,6 +197,7 @@ void creates_document_from_snapshot_metadata(pp::tests::Harness& h)
.height = 64,
.layers = layers,
.frames = frames,
.selection_masks = {},
});
PP_EXPECT(h, document_result.ok());
@@ -238,6 +240,7 @@ void preserves_per_layer_snapshot_timelines(pp::tests::Harness& h)
.height = 64,
.layers = layers,
.frames = project_frames,
.selection_masks = {},
});
PP_EXPECT(h, document_result.ok());
@@ -265,30 +268,35 @@ void rejects_invalid_snapshot_metadata(pp::tests::Harness& h)
.height = 64,
.layers = {},
.frames = frames,
.selection_masks = {},
});
const auto no_frames = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = layers,
.frames = {},
.selection_masks = {},
});
const auto bad_frame = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = layers,
.frames = bad_frames,
.selection_masks = {},
});
const auto bad_layer = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = bad_layers,
.frames = frames,
.selection_masks = {},
});
const auto bad_layer_frame = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 64,
.layers = bad_layer_frames,
.frames = frames,
.selection_masks = {},
});
PP_EXPECT(h, !no_layers.ok());
@@ -503,6 +511,114 @@ void rejects_invalid_face_pixel_payloads(pp::tests::Harness& h)
PP_EXPECT(h, document.face_pixel_payload_count() == 0U);
}
void manages_selection_masks(pp::tests::Harness& h)
{
auto document_result = CanvasDocument::create(
DocumentConfig { .width = 64, .height = 32, .layer_count = 1 });
PP_EXPECT(h, document_result.ok());
auto document = document_result.value();
PP_EXPECT(h, document.set_selection_mask(SelectionMask {
.face_index = 4,
.x = 3,
.y = 5,
.width = 2,
.height = 2,
.alpha8 = { 0, 64, 128, 255 },
}).ok());
PP_EXPECT(h, document.selection_mask_payload_count() == 1U);
PP_EXPECT(h, document.selection_masks().size() == 1U);
PP_EXPECT(h, document.selection_masks()[0].face_index == 4U);
PP_EXPECT(h, document.selection_masks()[0].x == 3U);
PP_EXPECT(h, document.selection_masks()[0].alpha8[3] == 255U);
PP_EXPECT(h, document.set_selection_mask(SelectionMask {
.face_index = 4,
.x = 7,
.y = 9,
.width = 1,
.height = 1,
.alpha8 = { 200 },
}).ok());
PP_EXPECT(h, document.selection_mask_payload_count() == 1U);
PP_EXPECT(h, document.selection_masks()[0].x == 7U);
PP_EXPECT(h, document.selection_masks()[0].alpha8[0] == 200U);
PP_EXPECT(h, document.clear_selection_mask(4).ok());
PP_EXPECT(h, document.selection_mask_payload_count() == 0U);
}
void rejects_invalid_selection_masks(pp::tests::Harness& h)
{
auto document_result = CanvasDocument::create(
DocumentConfig { .width = 64, .height = 32, .layer_count = 1 });
PP_EXPECT(h, document_result.ok());
auto document = document_result.value();
const auto bad_face = document.set_selection_mask(
SelectionMask { .face_index = 6, .x = 0, .y = 0, .width = 1, .height = 1, .alpha8 = { 1 } });
const auto zero_width = document.set_selection_mask(
SelectionMask { .face_index = 0, .x = 0, .y = 0, .width = 0, .height = 1, .alpha8 = {} });
const auto outside_bounds = document.set_selection_mask(
SelectionMask { .face_index = 0, .x = 63, .y = 0, .width = 2, .height = 1, .alpha8 = { 1, 2 } });
const auto bad_byte_count = document.set_selection_mask(
SelectionMask { .face_index = 0, .x = 0, .y = 0, .width = 2, .height = 1, .alpha8 = { 1 } });
const auto missing_clear = document.clear_selection_mask(2);
const auto bad_clear_face = document.clear_selection_mask(6);
PP_EXPECT(h, !bad_face.ok());
PP_EXPECT(h, bad_face.code == StatusCode::out_of_range);
PP_EXPECT(h, !zero_width.ok());
PP_EXPECT(h, zero_width.code == StatusCode::invalid_argument);
PP_EXPECT(h, !outside_bounds.ok());
PP_EXPECT(h, outside_bounds.code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_byte_count.ok());
PP_EXPECT(h, bad_byte_count.code == StatusCode::invalid_argument);
PP_EXPECT(h, !missing_clear.ok());
PP_EXPECT(h, missing_clear.code == StatusCode::out_of_range);
PP_EXPECT(h, !bad_clear_face.ok());
PP_EXPECT(h, bad_clear_face.code == StatusCode::out_of_range);
PP_EXPECT(h, document.selection_mask_payload_count() == 0U);
}
void preserves_selection_masks_in_snapshots_and_history(pp::tests::Harness& h)
{
const DocumentLayerConfig layers[] { { .name = "Ink", .frames = {} } };
const AnimationFrame frames[] { { .duration_ms = 100, .face_pixels = {} } };
const SelectionMask masks[] {
SelectionMask {
.face_index = 3,
.x = 1,
.y = 2,
.width = 1,
.height = 2,
.alpha8 = { 12, 240 },
},
};
const auto document_result = CanvasDocument::create_from_snapshot(DocumentSnapshotConfig {
.width = 64,
.height = 32,
.layers = layers,
.frames = frames,
.selection_masks = masks,
});
PP_EXPECT(h, document_result.ok());
PP_EXPECT(h, document_result.value().selection_mask_payload_count() == 1U);
PP_EXPECT(h, document_result.value().selection_masks()[0].alpha8[1] == 240U);
auto history_result = DocumentHistory::create(document_result.value(), 3);
PP_EXPECT(h, history_result.ok());
auto history = history_result.value();
auto next = history.current();
PP_EXPECT(h, next.clear_selection_mask(3).ok());
PP_EXPECT(h, history.apply(next).ok());
PP_EXPECT(h, history.undo().ok());
PP_EXPECT(h, history.current().selection_mask_payload_count() == 1U);
}
void records_document_history_and_restores_snapshots(pp::tests::Harness& h)
{
auto document_result = CanvasDocument::create(
@@ -634,6 +750,9 @@ int main()
harness.run("attaches_layer_frame_face_pixels", attaches_layer_frame_face_pixels);
harness.run("replaces_existing_face_pixel_payload", replaces_existing_face_pixel_payload);
harness.run("rejects_invalid_face_pixel_payloads", rejects_invalid_face_pixel_payloads);
harness.run("manages_selection_masks", manages_selection_masks);
harness.run("rejects_invalid_selection_masks", rejects_invalid_selection_masks);
harness.run("preserves_selection_masks_in_snapshots_and_history", preserves_selection_masks_in_snapshots_and_history);
harness.run("records_document_history_and_restores_snapshots", records_document_history_and_restores_snapshots);
harness.run("applying_after_undo_discards_redo_branch", applying_after_undo_discards_redo_branch);
harness.run("bounds_document_history_capacity", bounds_document_history_capacity);