mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 22:19:00 +00:00
Tests: import_fuzz's two regression tests check that their input reaches the export
svg_type_shifted_two_billion_points_exports_to_pdf now checks that the SVG import keeps the type's shift of more than 2,000,000,000 pt, and that the exported PDF leaves the type out, read back with the PDF importer. Before, it checked only that the export returned Ok, so an import that dropped or clamped the shift made it pass without reaching the bound. a_long_thin_shape_with_a_shadow_renders_and_exports now checks that the Affinity import gives exactly one shape with a drop shadow, more than 3,000,000 pt wide, before it renders and exports it. Before, an import that dropped the shadow made it pass without drawing one. The other 66 test-lint hits in import_fuzz.rs are property tests whose claim is that hostile input loads, renders and exports without a panic. Their helpers (survive, survive_library and the others) fail the case through TestCaseError, which the no-assertion rule does not count.
This commit is contained in:
@@ -929,7 +929,20 @@ fn mutate_text(src: &str, cut: usize, edits: &[(usize, char)]) -> String {
|
||||
fn svg_type_shifted_two_billion_points_exports_to_pdf() {
|
||||
let svg = r#"<svg xmlns="http://www.w3.org/2000/svg"><text baseline-shift="-2147483649">f</text></svg>"#;
|
||||
let d = vectorcraft_svg::import(svg).unwrap();
|
||||
assert!(vectorcraft_engine::export_pdf(&d, &vectorcraft_pdf::PdfOptions::default()).is_ok());
|
||||
// The type opens with its shift, so the export below meets a glyph that far out.
|
||||
let mut shifts = Vec::new();
|
||||
d.walk(|n| {
|
||||
if let vectorcraft_doc::NodeKind::Text(t) = &n.kind {
|
||||
shifts.extend(t.runs.iter().map(|r| r.style.baseline_shift));
|
||||
}
|
||||
});
|
||||
assert!(shifts.iter().any(|&s| s.abs() > 2e9), "baseline shifts read: {shifts:?}");
|
||||
let pdf = vectorcraft_engine::export_pdf(&d, &vectorcraft_pdf::PdfOptions::default()).unwrap();
|
||||
// The PDF leaves the type out: reading it back finds no type.
|
||||
let back = vectorcraft_pdf::import(&pdf).unwrap();
|
||||
let mut text = 0;
|
||||
back.walk(|n| text += usize::from(matches!(n.kind, vectorcraft_doc::NodeKind::Text(_))));
|
||||
assert_eq!(text, 0, "type left out of the page");
|
||||
}
|
||||
|
||||
proptest! {
|
||||
@@ -8630,6 +8643,16 @@ fn a_long_thin_shape_with_a_shadow_renders_and_exports() {
|
||||
let stream = canvas_stream(vec![with_effects(rectangle(10, (0.0, 0.0), (3_276_800.0, 50.0)), vec![shadow()])]);
|
||||
let bytes = affinity_sample_file(&stream, None);
|
||||
let doc = vectorcraft_engine::cmd::fileio::load("long.af", &bytes).unwrap().doc;
|
||||
// The shape opens whole, with its shadow, so the exports below draw the shadow that far out.
|
||||
let mut shadowed = Vec::new();
|
||||
doc.walk(|n| {
|
||||
if n.appearance.effects.iter().any(|e| e.id == "stylize.dropShadow") {
|
||||
shadowed.push(n.id);
|
||||
}
|
||||
});
|
||||
assert_eq!(shadowed.len(), 1, "one shape with a drop shadow");
|
||||
let width = doc.bounds_of(&shadowed, false).map(|r| r.width());
|
||||
assert!(width.is_some_and(|w| w > 3_000_000.0), "the shape is {width:?} pt wide");
|
||||
survive("long shape", || Some(doc)).unwrap();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user