mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
Tests: DWG opens through the DXF Import Options dialog and the CLI worker
- The DXF Import Options dialog test opens a DWG, confirms it at 1:1 in model space and places it. - `vectorcraft-cli info` reads a DWG as the DXF it was written from, and five damaged copies (cut short, overwritten, bytes flipped) end in an error that names DWG or open with warnings, with the process exiting normally. - The engine's DWG and DXF test modules are listed in order.
This commit is contained in:
1 parent
46ee88dbb9
commit
094f60b2fb
6 files changed
+64
-2
No files matched your search
@@ -378,3 +378,40 @@ fn convert_and_run_write_ait_templates() {
|
||||
assert!(!one.status.success());
|
||||
assert!(String::from_utf8_lossy(&one.stderr).contains("every artboard"), "{}", String::from_utf8_lossy(&one.stderr));
|
||||
}
|
||||
|
||||
/// A DWG drawing opens through a worker copy of the program, so a damaged one ends in an error from
|
||||
/// `info`, never in a crash. craft-dwg reads and writes DWG everywhere but wasm32 and FreeBSD on
|
||||
/// aarch64.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
#[test]
|
||||
fn info_reads_a_dwg_and_a_damaged_one_is_an_error_not_a_crash() {
|
||||
let dxf = tmp("plan.dxf");
|
||||
make(&dxf, 120, 80);
|
||||
craft_dwg::allow_in_process();
|
||||
let dwg = craft_dwg::dxf_to_dwg_as(&std::fs::read(&dxf).unwrap(), "AC1018").unwrap();
|
||||
let good = tmp("plan.dwg");
|
||||
std::fs::write(&good, &dwg).unwrap();
|
||||
// The DWG comes in as the DXF it was written from.
|
||||
let (v, from) = (info(&good), info(&dxf));
|
||||
assert!(v["kinds"]["Path"].as_u64().is_some_and(|n| n > 0), "{v}");
|
||||
assert_eq!((&v["kinds"], &v["artboards"][0]["rect"]), (&from["kinds"], &from["artboards"][0]["rect"]), "{v}\n{from}");
|
||||
|
||||
let n = dwg.len();
|
||||
let mut damaged = vec![dwg[..n / 3].to_vec(), dwg[..2 * n / 3].to_vec(), dwg[..16].to_vec()];
|
||||
let mut overwritten = dwg.clone();
|
||||
overwritten[n / 2..(n / 2 + 64).min(n)].fill(0xFF);
|
||||
damaged.push(overwritten);
|
||||
let mut flipped = dwg.clone();
|
||||
flipped.iter_mut().skip(32).step_by(97).for_each(|b| *b ^= 0xA5);
|
||||
damaged.push(flipped);
|
||||
for (i, bytes) in damaged.iter().enumerate() {
|
||||
let path = tmp(&format!("damaged-{i}.dwg"));
|
||||
std::fs::write(&path, bytes).unwrap();
|
||||
let out = Command::new(crate::bin()).args(["info", &path]).output().unwrap();
|
||||
// A process ended by a signal has no exit code.
|
||||
assert!(out.status.code().is_some(), "damaged file {i}: {:?}", out.status);
|
||||
if !out.status.success() {
|
||||
assert!(String::from_utf8_lossy(&out.stderr).contains("DWG"), "damaged file {i}: {}", String::from_utf8_lossy(&out.stderr));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user