Tests: cover script DOM range checks, PrintOptions groups and evalFile refusals

- The text attribute test has rows one step past the bounds of
  baselineShift, horizontalScale, verticalScale and rotation.
- A new print test prints each PrintOptions group (overprints, page
  marks, orientation, separations, custom and transverse paper, emulsion,
  negative and position) through Document.print and compares the
  PostScript with what file.print writes for the matching settings,
  leaving out the CreationDate comment. Each case also checks that its
  settings change the file. The color intent is compared in PDF, by the
  art the printed file opens as.
- A new include test reads a refused absolute path whose URI-decoded form
  is not read either, and checks that $.evalFile keeps the refusal.
This commit is contained in:
dotCooCoo committed 2026-12-02 22:13:01 -08:00
1 parent 15cc3b048f
commit b32285d451
3 files changed
+107

No files matched your search

+15
View File
@@ -461,6 +461,21 @@ fn script_eval_file_outside_scope_refused() {
let _ = std::fs::remove_dir_all(base);
}
/// A refused absolute path whose URI form is read by no candidate either keeps the refusal of
/// the path as written, not a missing file.
#[cfg(not(windows))]
#[test]
fn script_eval_file_keeps_the_refusal_when_no_uri_form_is_read() {
let base = folder("evaluri");
write(&base.join("out%20side.jsx"), "1;");
let absolute = base.join("out%20side.jsx").to_string_lossy().into_owned();
let script = format!("try {{ $.evalFile('{absolute}'); }} catch (e) {{ vc.log(String(e)); }}");
let r = run(&base, &script).unwrap();
let e = r["log"][0].as_str().unwrap_or_default().to_string();
assert!(e.starts_with(&format!("Error: script file read refused: {absolute}")), "{e}");
let _ = std::fs::remove_dir_all(base);
}
#[test]
fn script_directives_in_strings_and_block_comments_are_inert() {
let mut s = Session::new();
+88
View File
@@ -622,6 +622,94 @@ fn assigned_job_and_scale_options_apply_over_the_saved_settings() {
let _ = std::fs::remove_dir_all(base);
}
/// Each option group prints the PostScript `file.print` writes for the settings it maps to, and
/// each of those settings changes the file.
#[test]
fn option_groups_print_what_their_settings_print() {
let base = folder("groups");
let mut s = session(&base);
// A red rectangle whose fill overprints, printed through a CMYK printer profile: the intent
// decides its inks and the overprint option whether it keeps overprinting.
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
s.execute("attributes.set", &json!({"overprintFill": true})).unwrap();
let profile = vectorcraft_color::cms::GENERIC_CMYK;
let saved =
json!({"media": "letter", "autoRotate": false, "orientation": "portrait", "artboards": "range", "range": "1", "color": {"profile": profile}});
s.execute("print.setup", &json!({"settings": saved})).unwrap();
let dir = data_folder(&mut s, &base);
// The jobs print to PostScript, whose only line that depends on the clock is its
// `%%CreationDate` comment.
let undated = |path: &Path| {
let text = std::fs::read_to_string(path).unwrap();
assert!(text.starts_with("%!PS"), "{}: {}", path.display(), &text[..text.len().min(40)]);
text.lines().filter(|l| !l.starts_with("%%CreationDate:")).collect::<Vec<_>>().join("\n")
};
s.execute("file.print", &json!({"format": "postscript", "path": dir.join("plain.ps").to_string_lossy()})).unwrap();
let plain = undated(&dir.join("plain.ps"));
let mut wrong = Vec::new();
let cases = [
("o.flattenerOptions.overprint = PDFOverprint.DISCARDPDFOVERPRINT;", json!({"advanced": {"overprints": "discard"}})),
(
"o.pageMarksOptions.pageMarksType = PageMarksTypes.Japanese; o.pageMarksOptions.trimMarks = true;",
json!({"marks": {"kind": "japanese", "trim": true}}),
),
("o.coordinateOptions.orientation = PrintOrientation.LANDSCAPE;", json!({"autoRotate": false, "orientation": "landscape"})),
("o.colorSeparationOptions.colorSeparationMode = PrintColorSeparationMode.HOSTBASEDSEPARATION;", json!({"output": {"mode": "separations"}})),
(
"var m = o.pageMarksOptions; m.trimMarks = true; m.registrationMarks = true; m.trimMarksWeight = 1;",
json!({"marks": {"trim": true, "registration": true, "weight": 1.0}}),
),
("o.paperOptions.width = 400; o.paperOptions.height = 300;", json!({"media": "custom", "width": 400.0, "height": 300.0})),
("o.paperOptions.transverse = true;", json!({"transverse": true})),
("o.coordinateOptions.emulsion = true;", json!({"output": {"emulsion": "down"}})),
("o.postScriptOptions.negativePrinting = true;", json!({"output": {"image": "negative"}})),
("o.coordinateOptions.position = PrintPosition.TRANSLATETOPLEFT;", json!({"placement": {"origin": "topLeft"}})),
];
for (i, (body, settings)) in cases.iter().enumerate() {
let [want, got] = ["want", "got"].map(|name| dir.join(format!("{name}{i}.ps")));
s.execute("file.print", &json!({"format": "postscript", "settings": settings, "path": want.to_string_lossy()})).unwrap();
logged(
&mut s,
&base,
&format!(
"Folder.userData; var o = new PrintOptions(); o.jobOptions.file = new File({}); {body} app.activeDocument.print(o);",
quoted(&got)
),
);
let want = undated(&want);
if want == plain {
wrong.push(format!("{i}: {settings} does not change the printed file"));
}
if undated(&got) != want {
wrong.push(format!("{i}: {body} does not print as {settings}"));
}
}
assert!(wrong.is_empty(), "{wrong:#?}");
let page_count = |path: &Path| undated(path).lines().filter(|l| l.starts_with("%%Page:")).count();
assert!(page_count(&dir.join("want3.ps")) > page_count(&dir.join("plain.ps")), "a page for each ink");
// PostScript leaves the printer profile out, so the intent is compared in PDF, by the art the
// printed file opens as, which leaves out the file's date.
let art = |name: &str| {
let doc = vectorcraft_pdf::import(&std::fs::read(dir.join(name)).unwrap()).unwrap();
serde_json::to_string(&doc.layers).unwrap()
};
let perceptual = json!({"color": {"intent": "perceptual"}});
s.execute("file.print", &json!({"path": dir.join("plain.pdf").to_string_lossy()})).unwrap();
s.execute("file.print", &json!({"settings": perceptual, "path": dir.join("want.pdf").to_string_lossy()})).unwrap();
logged(
&mut s,
&base,
&format!(
"Folder.userData; var o = new PrintOptions(); o.jobOptions.file = new File({});\n\
o.colorManagementOptions.intent = PrintColorIntent.PERCEPTUALINTENT; app.activeDocument.print(o);",
quoted(&dir.join("got.pdf"))
),
);
assert!(art("want.pdf") != art("plain.pdf"), "the intent changes the inks");
assert_eq!(art("got.pdf"), art("want.pdf"), "PrintColorIntent.PERCEPTUALINTENT prints as {perceptual}");
let _ = std::fs::remove_dir_all(base);
}
/// The format follows the name `jobOptions.file` gives, not the extension of the file a link in the
/// granted folder leads to.
#[cfg(unix)]
+4
View File
@@ -224,6 +224,10 @@ fn bad_attribute_values_are_refused_without_a_change() {
("r.size = NaN;", "not a finite number"),
("r.leading = 0;", "leading must be from 0.1"),
("r.characterAttributes.tracking = 1e9;", "tracking"),
("r.baselineShift = -1297;", "baselineShift must be from -1296 to 1296"),
("r.horizontalScale = 0.9;", "horizontalScale must be from 1 to 10000"),
("r.characterAttributes.verticalScale = 10001;", "verticalScale must be from 1 to 10000"),
("r.rotation = 361;", "rotation must be from -360 to 360"),
("r.underline = 1;", "underline must be true or false"),
("r.textFont = 'Arial';", "textFont must be a TextFont"),
("r.paragraphAttributes.justification = 'LEFT';", "Justification value"),