mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-01 18:25:32 -06:00
Every craft-libs git dependency (Cargo.toml, its [patch.crates-io] entries and apps/cadcraft-web/Cargo.toml) moves from eleven different revisions to craft-libs main at 3af2280ee3434a2c860012df2f440652621c2c81. Cargo.lock keeps one copy of each craft-libs crate and adds harfrust 0.13.3 and read-fonts 0.43.3, which craft-font-catalog now needs. craft-dwg at this revision refuses to convert DWG when no worker process is configured (storytold/craft-libs#1345). The app and the CLI configure one at startup and are unaffected. The tests that read or write DWG in their own process now call cadcraft_io::dwg_worker::allow_in_process(), which cadcraft-io re-exports. dwg_worker.rs now checks that a worker that cannot start is an error instead of a fallback to this process.
43 lines
2.2 KiB
Rust
43 lines
2.2 KiB
Rust
//! The DWG reader and writer run in a child process, so a decoder that dies ends one open or save,
|
|
//! not the app. The worker setting is process-wide, so everything runs in one test.
|
|
|
|
#![cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
|
|
|
use cadcraft_io::dwg_worker;
|
|
|
|
#[test]
|
|
fn a_real_worker_reads_and_writes_and_its_death_is_an_error_here() {
|
|
let drawing = cadcraft_engine::sample::bracket();
|
|
dwg_worker::allow_in_process();
|
|
let in_process = cadcraft_io::write(&drawing, "a.dwg").unwrap();
|
|
|
|
dwg_worker::use_worker(env!("CARGO_BIN_EXE_cadcraft-cli").into(), vec![dwg_worker::WORKER_ARG.into()]);
|
|
let written = cadcraft_io::write(&drawing, "a.dwg").unwrap();
|
|
assert_eq!(written.get(..6), in_process.get(..6), "the same version of file");
|
|
let read = cadcraft_io::read(&written, "a.dwg").unwrap();
|
|
assert_eq!(read.model.len(), drawing.model.len());
|
|
|
|
// A drawing whose kept objects came from a 2018 file: the worker gets that version with the
|
|
// request and reads the bridge DXF as it, as this process does.
|
|
let mut kept = drawing.clone();
|
|
kept.foreign = std::sync::Arc::new(cadcraft_engine::doc::foreign::Foreign { version: Some("AC1032".into()), ..Default::default() });
|
|
let written = cadcraft_io::write(&kept, "a.dwg").unwrap();
|
|
assert_eq!(cadcraft_io::read(&written, "a.dwg").unwrap().model.len(), drawing.model.len());
|
|
|
|
// A decode error comes back as that error, not as the worker stopping.
|
|
let mut bad = in_process.clone();
|
|
bad.truncate(64);
|
|
let e = cadcraft_io::read(&bad, "a.dwg").unwrap_err().to_string();
|
|
assert!(!e.contains("worker"), "{e}");
|
|
|
|
// The worker aborts as the third-party code can. This process goes on.
|
|
let e = dwg_worker::crash_worker_for_test().unwrap_err();
|
|
assert!(e.contains("worker stopped"), "{e}");
|
|
assert!(cadcraft_io::read(&written, "a.dwg").is_ok(), "the next file gets a new worker");
|
|
|
|
// A worker that cannot start is an error, even where in-process conversion is allowed.
|
|
dwg_worker::use_worker("no-such-program-here".into(), Vec::new());
|
|
let e = cadcraft_io::read(&written, "a.dwg").unwrap_err().to_string();
|
|
assert!(e.contains("could not start"), "{e}");
|
|
}
|