From cd172d1e7728f0fc48fb4e18a81ff4a0c22dddad Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 21:08:00 -0800 Subject: [PATCH] Tests: cover import limits, .af blend fallback and action.batch destinations - PSD slices: a version 7 or 8 descriptor that lists more than 10,000 slices, objects nested 17 deep and lists nested 17 deep are refused with a warning, and 16 levels of either still open. - .pcraft: a 12000 x 12000 canvas leaves the preview with the "too large to combine" note before any layer is read. - .af files: Multiply keeps its blend mode, and Linear Light imports as Normal with one warning however many objects use it. - action.batch: an unknown destination is refused, and destination "folder" without destinationFolder is refused before any file opens. --- crates/engine/src/cmd/fileio/action_batch.rs | 12 ++++++++ .../engine/src/cmd/fileio/affinity/nodes.rs | 29 +++++++++++++++++++ .../engine/src/cmd/fileio/tests_pcraftread.rs | 8 +++++ .../engine/src/cmd/fileio/tests_psdslices.rs | 20 +++++++++++++ 4 files changed, 69 insertions(+) diff --git a/crates/engine/src/cmd/fileio/action_batch.rs b/crates/engine/src/cmd/fileio/action_batch.rs index aa3be78e2a..9beed7e8a2 100644 --- a/crates/engine/src/cmd/fileio/action_batch.rs +++ b/crates/engine/src/cmd/fileio/action_batch.rs @@ -872,6 +872,7 @@ mod tests { ("source", json!(1), "`source` must be a string"), ("source", json!("files"), "`source` must be `folder` or `datasets`"), ("destination", json!(true), "`destination` must be a string"), + ("destination", json!("nowhere"), "`destination` must be `none`, `saveAndClose` or `folder`"), ("folder", json!(5), "`folder` must be a string"), ("label", json!(5), "`label` must be a string"), ("datasetFileNaming", json!(3), "`datasetFileNaming` must be a string"), @@ -895,6 +896,17 @@ mod tests { .to_string(); assert!(e.contains("`destinationFolder` must be a string"), "{e}"); assert!(s.active().is_none(), "no file was opened"); + // Saving to a folder needs the folder. + let e = s + .execute( + "action.batch", + &json!({"folder": src.to_string_lossy(), "destination": "folder", "commands": [{"command": "object.unlockAll"}]}), + ) + .unwrap_err() + .to_string(); + assert!(e.contains("`destinationFolder` is required when destination is `folder`"), "{e}"); + assert!(s.active().is_none(), "no file was opened"); + assert_eq!(std::fs::read_dir(&src).unwrap().count(), 1, "nothing was written next to the source file"); } #[cfg(unix)] diff --git a/crates/engine/src/cmd/fileio/affinity/nodes.rs b/crates/engine/src/cmd/fileio/affinity/nodes.rs index 36734dbe39..a6961c28c2 100644 --- a/crates/engine/src/cmd/fileio/affinity/nodes.rs +++ b/crates/engine/src/cmd/fileio/affinity/nodes.rs @@ -288,4 +288,33 @@ mod tests { assert!(!path_in_range(&path(&[(0.0, 0.0), (f64::NAN, 0.0)]), k)); assert!(!path_in_range(&path(&[(0.0, 0.0), (1.0, 1.0)]), Affine::scale(1.0e9))); } + + fn blended(blend: Blend) -> af::Node { + af::Node { + class: vectorcraft_affinity::stream::Tag::of(b"GrpN"), + name: String::new(), + visible: true, + locked: false, + opacity: 1.0, + blend, + kind: Kind::Group, + mask: None, + pixel_mask: None, + effects: vec![], + children: vec![], + } + } + + /// A blend mode VectorCraft has keeps it; one it lacks imports as Normal with one warning. + #[test] + fn blend_modes_map_or_import_as_normal_with_a_warning() { + let group = || NodeKind::Group { children: vec![], clip: false }; + let mut b = Builder::new(1.0); + assert_eq!(b.base(&blended(Blend::Multiply), group()).blend, BlendMode::Multiply); + assert!(b.warnings.is_empty(), "{:?}", b.warnings); + for _ in 0..2 { + assert_eq!(b.base(&blended(Blend::LinearLight), group()).blend, BlendMode::Normal); + } + assert!(b.warnings.len() == 1 && b.warnings[0].contains("Linear Light"), "{:?}", b.warnings); + } } diff --git a/crates/engine/src/cmd/fileio/tests_pcraftread.rs b/crates/engine/src/cmd/fileio/tests_pcraftread.rs index 444ba06606..ba46f8040b 100644 --- a/crates/engine/src/cmd/fileio/tests_pcraftread.rs +++ b/crates/engine/src/cmd/fileio/tests_pcraftread.rs @@ -215,6 +215,14 @@ fn layers_that_cant_be_combined_leave_the_preview_with_a_note() { assert!(pixels.width() == 30 && w.len() == 1 && w[0].contains(said), "{said}: {w:?}"); } + // A canvas whose combined pixels would take more memory than one image may use leaves the + // preview, saying so before any layer is read. + let mut b = Bundle::new(vec![layer(true, "Multiply", 1.0, &raster(&rgba8([0; 4])), "")]); + b.size = (12_000, 12_000); + let (r, _, pixels) = place(&b.bytes()); + let w = warnings(&r); + assert!(pixels.width() == 30 && w.len() == 1 && w[0].contains("too large to combine"), "{w:?}"); + // A preview of the canvas's own size is not reduced, so nothing is said. let mut b = Bundle::new(vec![layer(true, "Multiply", 1.0, &raster(&rgba8([0; 4])), "")]); b.size = (30, 20); diff --git a/crates/engine/src/cmd/fileio/tests_psdslices.rs b/crates/engine/src/cmd/fileio/tests_psdslices.rs index ded0f137b3..fce524598e 100644 --- a/crates/engine/src/cmd/fileio/tests_psdslices.rs +++ b/crates/engine/src/cmd/fileio/tests_psdslices.rs @@ -374,6 +374,11 @@ fn slices_that_cant_be_read_warn_and_the_file_still_opens() { // The count follows the version, the bounds and the group's name. ([&good[..34], &u32::MAX.to_be_bytes()[..], &good[38..]].concat(), "more than the 10000 read"), (v7(8, vec![D::Long(3)]), "other than a slice"), + // A descriptor's list of more slices than are read, refused before any is looked at. + (v7(7, (0..10_001).map(|_| D::Long(0)).collect()), "more than the 10000 read"), + // Objects, and lists, nested one level deeper than are read. + (deep(17, |d| D::Obj(vec![("in", d)])), "nests too deep"), + (deep(17, |d| D::List(vec![d])), "nests too deep"), // A whole record whose name is longer than a slice's text may be. (v6(&[user("a".repeat(65_537).leak(), [0, 0, 5, 5])], &[]), "more than the 65536 characters read"), ]; @@ -395,6 +400,21 @@ fn slices_that_cant_be_read_warn_and_the_file_still_opens() { // A file without slices opens without a word about them. let (s, r) = open(&psd(true), json!({})); assert!(warnings(&r).is_empty() && slices(&s).is_empty(), "{r}"); + // Objects and lists nested as deep as are read come in. + for data in [deep(16, |d| D::Obj(vec![("in", d)])), deep(16, |d| D::List(vec![d]))] { + let (_, r) = open(&with_resource(&psd(false), 1050, &data), json!({})); + assert!(warnings(&r).is_empty(), "{r}"); + } +} + +/// Resource 1050 in version 7 with no slices, whose descriptor also holds `levels` values nested +/// one in another by `wrap`, around a long. +fn deep(levels: usize, wrap: fn(D) -> D) -> Vec { + let nested = (0..levels).fold(D::Long(0), |d, _| wrap(d)); + let mut b = 7u32.to_be_bytes().to_vec(); + b.extend(16u32.to_be_bytes()); + b.extend(descriptor(&[("deep", nested), ("slices", D::List(vec![]))])); + b } #[test]