Files
photocraft/crates/io/tests/it/psd_background.rs
T
aiongg a6428d3dfb Build each crate's integration tests as one binary
Every tests/*.rs file is its own executable that links the whole crate
graph. Move each crate's test files into tests/it/ as modules of one
tests/it/main.rs; helper modules under tests/common move with them.

These keep their own binary (own process):
- engine panic_hunt: a process-wide panic hook counts every panic.
- engine text_gamma: changes the process-wide text gamma.
- engine smart_filter_stages, mask_cache_purge: assert on global caches.
- codecs pnm_peak_memory: reads the process's peak RSS.
- photocraft mac_menu_appkit: harness = false.
2026-10-22 16:55:34 +00:00

40 lines
1.7 KiB
Rust

//! A PSD's Background is recognised by its structure (the bottom record, transparency-protected,
//! stored without a transparency channel), whatever its name in the Photoshop language that
//! saved the file.
use photocraft_io::psd_to_document;
use photocraft_psd::{ColorMode, Compression, PsdFile, TaggedBlock, Version, testgen};
/// `testgen::layered` with its bottom layer turned into a Photoshop Background named `name`.
fn file(name: &str, transparency_channel: bool) -> PsdFile {
let mut f = testgen::layered(Version::Psd, ColorMode::Rgb, 8, Compression::Rle);
let bottom = f.layers_mut().first_mut().unwrap();
bottom.name = name.bytes().filter(u8::is_ascii).collect();
bottom.blocks.retain(|b| &b.key != b"luni" && &b.key != b"lspf");
bottom.blocks.push(TaggedBlock::unicode_name(name));
bottom.flags.set_transparency_protected(true);
if !transparency_channel {
bottom.channels.retain(|c| c.id != -1);
}
f
}
#[test]
fn a_localized_background_is_the_background() {
for name in ["Hintergrund", "背景", "Arrière-plan"] {
let (d, _) = psd_to_document(&file(name, false));
let bg = d.background().unwrap_or_else(|| panic!("{name}: no Background"));
assert_eq!(bg.name, name);
assert!(bg.locks.transparency && bg.locks.position, "{name}");
assert_eq!(bg.id, d.layers[0].id);
}
}
#[test]
fn a_protected_layer_with_transparency_is_not_the_background() {
// Lock Transparent Pixels on an ordinary bottom layer: it keeps its transparency channel.
let (d, _) = psd_to_document(&file("Background", true));
assert!(d.layers[0].locks.transparency);
assert!(d.background().is_none());
}