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:
dotCooCoo committed 2026-12-03 20:36:08 -08:00
1 parent 46ee88dbb9
commit 094f60b2fb
6 files changed
+64 -2

No files matched your search

Generated
+2
View File
@@ -8699,6 +8699,7 @@ dependencies = [
name = "vectorcraft-cli"
version = "0.25.1"
dependencies = [
"craft-dwg",
"log",
"objc2-core-foundation",
"objc2-core-text",
@@ -9235,6 +9236,7 @@ dependencies = [
"bytemuck",
"chrono",
"craft",
"craft-dwg",
"craft-image-codecs",
"egui",
"egui_extras",
+2
View File
@@ -47,6 +47,8 @@ objc2-core-text = { version = "0.3", default-features = false, features = ["std"
[dev-dependencies]
tempfile = "3"
vectorcraft-testkit = { workspace = true }
# DWG files for the `info` test, written from DXF by craft-dwg.
craft-dwg = { workspace = true }
serde_json = { workspace = true }
# The files of other crates that this crate compiles or its tests read, for CI's test selection.
+37
View File
@@ -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));
}
}
}
+2 -2
View File
@@ -246,11 +246,11 @@ mod tests_svgimport;
#[cfg(test)]
mod tests_eps;
#[cfg(test)]
mod tests_dxfimport;
#[cfg(test)]
mod tests_dwgimport;
#[cfg(test)]
mod tests_dxfimport;
#[cfg(test)]
mod tests_hpgl;
#[cfg(test)]
mod tests_metafile;
+2
View File
@@ -95,6 +95,8 @@ web-time = "1"
rustix = { workspace = true, features = ["std", "process"] }
[dev-dependencies]
# DWG files for the DXF Import Options tests, written from DXF by craft-dwg.
craft-dwg = { workspace = true }
# `Fixture` and the stories sit behind craft-ui's `testing` feature.
craft = { workspace = true, features = ["ui-testing"] }
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
+19
View File
@@ -616,6 +616,25 @@ mod tests {
assert_eq!(w, 100.0, "1 pt = 1 unit");
}
/// 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 a_dwg_drawing_opens_and_places_through_the_dialog() {
vectorcraft_engine::dwg::allow_in_process();
let dwg = craft_dwg::dxf_to_dwg_as(&drawing(), "AC1018").unwrap();
let mut app = host::app();
io::open_bytes(&mut app, "plan.dwg", &dwg, None).unwrap();
let f = host::fields(&app, KIND);
assert_eq!((&f["mode"], &f["layout"], &f["unit"]), (&json!("open"), &json!("Model"), &json!("Millimeters")));
host::confirm(&mut app, KIND).unwrap();
assert!(!host::is_open(&app, KIND));
let w = app.session.doc().unwrap().doc.artboards[0].rect.width();
assert!((w - 100.0 * Unit::Millimeters.points()).abs() < 1e-6, "the model space line at 1:1: {w}");
app.run("file.new", json!({"width": 600, "height": 400})).unwrap();
crate::place::run(&mut app, &json!({"name": "plan.dwg", "dataBase64": vectorcraft_format::base64_encode(&dwg)})).unwrap();
assert_eq!(host::fields(&app, KIND)["mode"], "place");
}
#[test]
fn placing_a_drawing_asks_then_places_one_group() {
let mut app = host::app();