diff --git a/src-tauri/core/src/lib.rs b/src-tauri/core/src/lib.rs index 08610d51..88ebae5a 100644 --- a/src-tauri/core/src/lib.rs +++ b/src-tauri/core/src/lib.rs @@ -147,7 +147,8 @@ pub mod dim_assoc; pub mod opening_slide; #[cfg(feature = "web")] -mod web; +#[doc(hidden)] +pub mod web; pub mod presentation_sheet; pub mod drawing_recognize; pub mod kosten; diff --git a/src-tauri/core/src/web/mod.rs b/src-tauri/core/src/web/mod.rs index 5cfb2e9c..5c51fdba 100644 --- a/src-tauri/core/src/web/mod.rs +++ b/src-tauri/core/src/web/mod.rs @@ -3,53 +3,53 @@ //! Kaputte Eingaben ergeben ein leeres Ergebnis statt eines Panics (ein Panic legt das ganze //! WASM-Modul lahm, [14]). -mod kernel2d; -mod polygon; -mod roof; -mod sun; -mod site_rules; -mod kennzahlen; -mod bulge; -mod stair; -mod room_area; -mod room_boundary; -mod polygon_holes; -mod plan_buf; -mod project_format; -mod gpu_compile; -mod delaunay; -mod document; -mod ops; -mod voids; -mod curves; -mod hatch; -mod skeleton; -mod plan_scene; -mod plan_pick; -mod snap; -mod plan_svg; -mod plan_dxf; -mod plan_print_svg; -mod layers; -mod pens; -mod layout_model; -mod clash_broad; -mod parametric_walls; -mod reorder; -mod text_layout; -mod grips; -mod grip_drag; -mod project_refs; -mod commands; -mod import; -mod cmd_create; -mod area_report; -mod rich_text; -mod geo_mesh; -mod opening_presets; -mod furniture_lib; -mod solid_bool; -mod line_pattern; +pub mod kernel2d; +pub mod polygon; +pub mod roof; +pub mod sun; +pub mod site_rules; +pub mod kennzahlen; +pub mod bulge; +pub mod stair; +pub mod room_area; +pub mod room_boundary; +pub mod polygon_holes; +pub mod plan_buf; +pub mod project_format; +pub mod gpu_compile; +pub mod delaunay; +pub mod document; +pub mod ops; +pub mod voids; +pub mod curves; +pub mod hatch; +pub mod skeleton; +pub mod plan_scene; +pub mod plan_pick; +pub mod snap; +pub mod plan_svg; +pub mod plan_dxf; +pub mod plan_print_svg; +pub mod layers; +pub mod pens; +pub mod layout_model; +pub mod clash_broad; +pub mod parametric_walls; +pub mod reorder; +pub mod text_layout; +pub mod grips; +pub mod grip_drag; +pub mod project_refs; +pub mod commands; +pub mod import; +pub mod cmd_create; +pub mod area_report; +pub mod rich_text; +pub mod geo_mesh; +pub mod opening_presets; +pub mod furniture_lib; +pub mod solid_bool; +pub mod line_pattern; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/src-tauri/core/tests/robustness_web.rs b/src-tauri/core/tests/robustness_web.rs new file mode 100644 index 00000000..e16f4948 --- /dev/null +++ b/src-tauri/core/tests/robustness_web.rs @@ -0,0 +1,568 @@ +//! [258] Robustheit der WASM-Bindungen (`src/web/*.rs`, Feature "web"): jede `#[wasm_bindgen]`-Funktion wird +//! nativ mit kaputten Eingaben aufgerufen (leere/abgeschnittene Flat-Puffer, falsche Zähler, NaN/Inf/±1e300, +//! Zufallsbits, ungültiges JSON, falsche ids/Handles). Erwartung: leeres Ergebnis oder Fehler, nie Panic — +//! ein Panic legt im Browser das ganze WASM-Modul lahm. Deterministisch (fester Seed, eigener PRNG), +//! jeder Aufruf unter `catch_unwind`, alle Panics gesammelt gemeldet. +//! +//! Lauf: `cargo test --release --features web --test robustness_web`. +//! `ROBUST_WEB_N` (Aufrufe je Funktion, Standard 60), `ROBUST_WEB_SEED`, `ROBUST_WEB_ONLY=`, +//! `ROBUST_WEB_TRACE=1` (jeden Aufruf melden). Die Liste `CALLS` bildet jede Bindung ab; +//! `jede_bindung_ist_abgedeckt` prüft sie gegen die Quellen. +#![cfg(feature = "web")] + +use dossier_core::web; +use std::cell::Cell; +use std::collections::BTreeMap; +use std::panic::{catch_unwind, AssertUnwindSafe}; + +const FIXTURE: &str = include_str!("fixtures/robust/beispiel.json"); + +thread_local! { + static HANDLE: Cell = const { Cell::new(0) }; + /// Von Hand (`ROBUST_WEB_DUMP=#`): die erzeugten Puffer/Texte des Aufrufs vor dem Aufruf ausgeben. + static DUMP: Cell = const { Cell::new(false) }; + static LAST: std::cell::RefCell = const { std::cell::RefCell::new(String::new()) }; +} + +pub struct Rng(u64); + +impl Rng { + fn next(&mut self) -> u64 { + self.0 ^= self.0 >> 12; + self.0 ^= self.0 << 25; + self.0 ^= self.0 >> 27; + self.0.wrapping_mul(0x2545_F491_4F6C_DD1D) + } + fn below(&mut self, n: usize) -> usize { + if n == 0 { 0 } else { (self.next() % n as u64) as usize } + } + fn unit(&mut self) -> f64 { + (self.next() >> 11) as f64 / (1u64 << 53) as f64 + } + + /// Einzelne Zahl: Randwerte, kleine Werte, Zufallsbits. + fn f64(&mut self) -> f64 { + let v = self.f64_inner(); + if DUMP.with(|d| d.get()) { + eprintln!("ARG f64 {v:?}"); + } + v + } + + fn f64_inner(&mut self) -> f64 { + const POOL: [f64; 18] = [0.0, -0.0, 1.0, -1.0, 0.5, 1e-9, -1e-9, 1e9, -1e9, 1e300, -1e300, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, f64::MAX, f64::MIN_POSITIVE, 3.0, 2.0]; + match self.below(4) { + 0 => POOL[self.below(POOL.len())], + 1 => f64::from_bits(self.next()), + 2 => self.below(10) as f64, + _ => (self.unit() - 0.5) * 100.0, + } + } + + pub fn id(&mut self) -> u32 { + match self.below(6) { + 0 => 0, + 1 => u32::MAX, + 2 => self.below(5) as u32, + _ => HANDLE.with(|h| h.get()), + } + } + + fn u32s(&mut self) -> Vec { + (0..self.below(12)).map(|_| if self.below(3) == 0 { u32::MAX } else { self.below(40) as u32 }).collect() + } + + fn bytes(&mut self) -> Vec { + let n = if self.below(4) == 0 { 0 } else { self.below(300) }; + let mut v: Vec = (0..n).map(|_| self.next() as u8).collect(); + // Manchmal ein Kopf, der echten Formaten ähnelt (PNG/ZIP/gzip/PDF/DXF/JSON). + if !v.is_empty() && self.below(3) == 0 { + let heads: [&[u8]; 6] = [b"\x89PNG\r\n\x1a\n", b"PK\x03\x04", b"\x1f\x8b\x08", b"%PDF-1.", b" 0\nSECTION\n", b"{\"a\":"]; + let h = heads[self.below(heads.len())]; + for (i, b) in h.iter().enumerate() { + if i < v.len() { + v[i] = *b; + } + } + } + v + } + + fn opt_text(&mut self) -> Option { + if self.below(2) == 0 { None } else { Some(self.text()) } + } + + /// Text: leer, kaputtes/fremdes JSON, Zufallsbytes, das Beispielprojekt (ganz/abgeschnitten/verdorben). + fn text(&mut self) -> String { + let t = self.text_inner(); + if DUMP.with(|d| d.get()) { + eprintln!("ARG text {:?}", &t[..t.len().min(300)]); + } + t + } + + fn text_inner(&mut self) -> String { + const POOL: [&str; 26] = [ + "", " ", "{", "}", "[", "null", "[]", "{}", "0", "-1", "1e999", "NaN", "\"", "\u{0}", "\u{feff}{}", + "{\"id\":\"x\"}", "{\"id\":\"\",\"type\":\"wall\"}", "[{\"id\":\"a\"},{\"id\":\"a\"}]", "{\"floors\":[],\"walls\":[]}", + "{\"floors\":null}", "[1,2,3]", "{\"ops\":[{\"op\":\"remove\",\"id\":\"nix\"}]}", "[{\"op\":\"set\",\"id\":\"w1\",\"patch\":{\"thickness\":1e300}}]", + "{\"kind\":\"wall\",\"points\":[[0,0],[1e300,1e300]]}", "{\"x\":null,\"y\":\"a\"}", "[[0,0],[1,1],[null,2]]", + ]; + match self.below(8) { + 0 => String::new(), + 1..=3 => POOL[self.below(POOL.len())].to_string(), + 4 => { + let n = self.below(80); + let b: Vec = (0..n).map(|_| self.next() as u8).collect(); + String::from_utf8_lossy(&b).into_owned() + } + 5 => FIXTURE.to_string(), + 6 => { + let mut c = self.below(FIXTURE.len()); + while !FIXTURE.is_char_boundary(c) { + c -= 1; + } + FIXTURE[..c].to_string() + } + _ => { + // Beispielprojekt, an Zufallsstellen durch Unsinn ersetzt. + let mut s = FIXTURE.to_string(); + for _ in 0..1 + self.below(4) { + let mut p = self.below(s.len()); + while !s.is_char_boundary(p) { + p -= 1; + } + let mut e = (p + 1 + self.below(6)).min(s.len()); + while !s.is_char_boundary(e) { + e += 1; + } + s.replace_range(p..e, ["null", "-1", "1e300", "\"x\"", "[]", "{}", "NaN"][self.below(7)]); + } + s + } + } + } + + /// Flat-Puffer: leer, gültig kodierte Polygone (dann verdorben), falsche Zähler, NaN/Inf, Zufallsbits, Zufallszahlen. + fn buf(&mut self) -> Vec { + let v = self.buf_inner(); + if DUMP.with(|d| d.get()) { + eprintln!("ARG buf {v:?}"); + } + v + } + + fn buf_inner(&mut self) -> Vec { + match self.below(8) { + 0 => vec![], + 1 => (0..self.below(40)).map(|_| self.f64()).collect(), + 2 => (0..self.below(40)).map(|_| f64::from_bits(self.next())).collect(), + // Kleine ganze Zahlen treffen Zählerfelder oft plausibel. + 3 => (0..self.below(60)).map(|_| self.below(6) as f64).collect(), + _ => { + let mut v = self.valid_flat(); + match self.below(6) { + 0 => { + let keep = self.below(v.len() + 1); + v.truncate(keep); + } + 1 => { + if !v.is_empty() { + let i = self.below(v.len().min(4)); + v[i] = [-1.0, 1e9, 1e18, f64::NAN, f64::INFINITY, 0.5, 4294967296.0][self.below(7)]; + } + } + 2 => { + for _ in 0..1 + self.below(3) { + if !v.is_empty() { + let i = self.below(v.len()); + v[i] = self.f64(); + } + } + } + 3 => { + let extra: Vec = (0..self.below(10)).map(|_| self.f64()).collect(); + v.extend(extra); + } + 4 => { + if !v.is_empty() { + let i = self.below(v.len()); + v[i] = f64::from_bits(self.next()); + } + } + _ => {} + } + v + } + } + } + + /// Gültige Kodierung `[n_polys, (n_rings, (n_pts, x, y …))]` mit zufälligen Ringen. + fn valid_flat(&mut self) -> Vec { + let mut v = vec![]; + let np = self.below(3); + v.push(np as f64); + for _ in 0..np { + let nr = 1 + self.below(2); + v.push(nr as f64); + for _ in 0..nr { + let n = self.below(8); + v.push(n as f64); + for _ in 0..n { + v.push(self.unit() * 10.0); + v.push(self.unit() * 10.0); + } + } + } + v + } +} + +// GENERIERT aus den `#[wasm_bindgen]`-Einstiegen in `src/web/*.rs`: je Zeile Modul::Name, Argumente nach Typ. +// Neue Einstiege von Hand ergänzen; `jede_bindung_ist_abgedeckt` schlägt sonst fehl. +type Call = (&'static str, fn(&mut Rng)); +const CALLS: &[Call] = &[ + ("area_report::area_report_csv", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_csv(&a0, &a1); }), + ("area_report::area_report_parse_csv", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_parse_csv(&a0, &a1); }), + ("area_report::area_report_layout", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_layout(&a0, &a1); }), + ("area_report::area_report_svg", |r: &mut Rng| { let a0 = r.text(); let a1 = r.id(); let a2 = r.text(); let _ = web::area_report::area_report_svg(&a0, a1, &a2); }), + ("bulge::bulge_arc", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::bulge::bulge_arc(a0, a1, a2, a3, a4); }), + ("bulge::bulge_arc_points", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::bulge::bulge_arc_points(a0, a1, a2, a3, a4); }), + ("bulge::bulge_polyline_points", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let _ = web::bulge::bulge_polyline_points(&a0, &a1, a2); }), + ("bulge::bulge_from_sagitta_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::bulge_from_sagitta_point(a0, a1, a2, a3, a4, a5); }), + ("bulge::bulge_point_at", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::bulge_point_at(a0, a1, a2, a3, a4, a5); }), + ("bulge::wall_arc_band", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::wall_arc_band(a0, a1, a2, a3, a4, a5); }), + ("clash_broad::clash_candidate_pairs", |r: &mut Rng| { let a0 = r.buf(); let _ = web::clash_broad::clash_candidate_pairs(&a0); }), + ("cmd_create::doc_create_preview", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let _ = web::cmd_create::doc_create_preview(a0, &a1, &a2); }), + ("cmd_create::doc_create_preview_again", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let _ = web::cmd_create::doc_create_preview_again(a0, &a1); }), + ("cmd_create::doc_create_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::cmd_create::doc_create_query(a0, &a1); }), + ("cmd_create::extruded_solid_spec_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::cmd_create::extruded_solid_spec_json(&a0, a1); }), + ("cmd_create::terrain_from_contours_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::cmd_create::terrain_from_contours_json(&a0, &a1); }), + ("cmd_create::terrain_from_contours_opts_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::cmd_create::terrain_from_contours_opts_json(&a0, &a1, a2, a3, a4); }), + ("cmd_create::terrain_resmooth_grid", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::cmd_create::terrain_resmooth_grid(&a0, a1); }), + ("cmd_create::terrain_smooth_grid", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::cmd_create::terrain_smooth_grid(&a0, a1, a2, a3); }), + ("commands::doc_cmd_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::commands::doc_cmd_commit(a0, &a1, &a2, a3); }), + ("commands::doc_cmd_preview", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::commands::doc_cmd_preview(a0, &a1); }), + ("commands::doc_cmd_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::commands::doc_cmd_query(a0, &a1); }), + ("curves::curves_bezier_chain_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::curves::curves_bezier_chain_flat(&a0, a1); }), + ("curves::curves_catmull_rom_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::curves::curves_catmull_rom_flat(&a0, a1, a2); }), + ("curves::curves_uniform_bspline_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::curves::curves_uniform_bspline_flat(&a0, a1, a2); }), + ("delaunay::delaunay_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::delaunay::delaunay_flat(&a0); }), + ("document::doc_open", |r: &mut Rng| { let a0 = r.text(); let _ = web::document::doc_open(&a0); }), + ("document::doc_load_file", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.f64(); let _ = web::document::doc_load_file(a0, &a1, a2); }), + ("document::doc_load_json", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_load_json(a0, &a1); }), + ("document::doc_close", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_close(a0); }), + ("document::doc_apply", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_apply(a0, &a1); }), + ("document::doc_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::document::doc_commit(a0, &a1, &a2, a3); }), + ("document::doc_undo", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_undo(a0); }), + ("document::doc_redo", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_redo(a0); }), + ("document::doc_jump_quiet", |r: &mut Rng| { let a0 = r.id(); let a1 = r.below(2) == 1; let _ = web::document::doc_jump_quiet(a0, a1); }), + ("document::doc_history_seq", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_seq(a0); }), + ("document::doc_history_state", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_state(a0); }), + ("document::doc_history_label", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_history_label(a0, &a1); }), + ("document::doc_history_labels", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_labels(a0); }), + ("document::doc_history_jump", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let _ = web::document::doc_history_jump(a0, a1); }), + ("document::doc_history_clear", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_clear(a0); }), + ("document::doc_history_limits", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::document::doc_history_limits(a0, a1, a2); }), + ("document::doc_history_index", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_index(a0); }), + ("document::doc_history_step", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::document::doc_history_step(a0, a1, a2); }), + ("document::doc_history_import", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_history_import(a0, &a1); }), + ("document::doc_group_begin", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_group_begin(a0); }), + ("document::doc_group_begin_keyed", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.f64(); let _ = web::document::doc_group_begin_keyed(a0, &a1, a2); }), + ("document::doc_group_end", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_group_end(a0); }), + ("document::doc_json", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_json(a0); }), + ("document::doc_query_args", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.text(); let _ = web::document::doc_query_args(a0, &a1, &a2, &a3); }), + ("document::doc_query_root", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let _ = web::document::doc_query_root(a0, &a1, &a2); }), + ("document::doc_drawing_line_verts", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.text(); let _ = web::document::doc_drawing_line_verts(a0, a1, &a2); }), + ("document::doc_surface_pattern_lines", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.text(); let _ = web::document::doc_surface_pattern_lines(a0, a1, &a2); }), + ("document::doc_serialize", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_serialize(a0); }), + ("document::doc_serialize_with_ui", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_serialize_with_ui(a0, &a1); }), + ("document::doc_query_bin", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.text(); let _ = web::document::doc_query_bin(a0, &a1, &a2, &a3); }), + ("document::doc_last_extra", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_last_extra(a0); }), + ("document::doc_last_hits", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_last_hits(a0); }), + ("document::__debug_panic", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::__debug_panic(a0); }), + ("furniture_lib::furniture_lib_catalog_json", |_r: &mut Rng| { let _ = web::furniture_lib::furniture_lib_catalog_json(); }), + ("furniture_lib::furniture_lib_geometry_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let a3 = r.id(); let _ = web::furniture_lib::furniture_lib_geometry_json(&a0, &a1, &a2, a3); }), + ("geo_mesh::geo_mesh_clip", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::geo_mesh::geo_mesh_clip(&a0, &a1, &a2); }), + ("geo_mesh::geo_mesh_strip_soffits", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::geo_mesh::geo_mesh_strip_soffits(&a0, &a1); }), + ("geo_mesh::geo_mesh_split", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::geo_mesh::geo_mesh_split(&a0, &a1, a2); }), + ("geo_mesh::geo_extrude_footprints", |r: &mut Rng| { let a0 = r.buf(); let _ = web::geo_mesh::geo_extrude_footprints(&a0); }), + ("gpu_compile::gpu_compile_flat", |r: &mut Rng| { let a0 = r.bytes(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.id(); let _ = web::gpu_compile::gpu_compile_flat(&a0, a1, a2, a3, a4, a5); }), + ("gpu_compile::gpu_compile_held", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.id(); let _ = web::gpu_compile::gpu_compile_held(a0, a1, a2, a3, a4, a5); }), + ("gpu_compile::triangulate_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::gpu_compile::triangulate_flat(&a0); }), + ("grip_drag::grip_polar", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::grip_drag::grip_polar(a0, a1, a2, a3, a4, a5); }), + ("grip_drag::grip_polar_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::grip_drag::grip_polar_point(a0, a1, a2, a3, a4, a5); }), + ("grip_drag::grip_arc_wall_target", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_target(a0, a1, a2, a3, a4, a5, a6, a7, a8); }), + ("grip_drag::grip_arc_wall_resize", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_resize(a0, a1, a2, a3, a4, a5, a6, a7, a8); }), + ("grip_drag::grip_arc_wall_radius", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.below(2) == 1; let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_radius(a0, a1, a2, a3, a4, a5, a6, a7, a8); }), + ("grip_drag::grip_axis_lock", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.buf(); let a7 = r.f64(); let a8 = r.below(2) == 1; let _ = web::grip_drag::grip_axis_lock(a0, a1, a2, a3, a4, a5, &a6, a7, a8); }), + ("grip_drag::grip_edge_target", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.f64(); let a6 = r.f64(); let a7 = r.below(2) == 1; let a8 = r.f64(); let a9 = r.f64(); let a10 = r.below(2) == 1; let a11 = r.f64(); let a12 = r.f64(); let a13 = r.f64(); let _ = web::grip_drag::grip_edge_target(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); }), + ("grip_drag::grip_sheet_height", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.below(2) == 1; let _ = web::grip_drag::grip_sheet_height(a0, a1, a2, a3, a4, a5); }), + ("grip_drag::grip_contour_marks", |r: &mut Rng| { let a0 = r.buf(); let _ = web::grip_drag::grip_contour_marks(&a0); }), + ("grip_drag::grip_snap_height", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::grip_drag::grip_snap_height(a0, &a1, a2); }), + ("grip_drag::grip_opening_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let _ = web::grip_drag::grip_opening_point(a0, a1, a2, a3, a4, a5, a6); }), + ("grip_drag::grip_opening_slide_sheet", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let a9 = r.f64(); let _ = web::grip_drag::grip_opening_slide_sheet(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }), + ("grip_drag::grip_clamp_inside", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.buf(); let _ = web::grip_drag::grip_clamp_inside(a0, a1, &a2); }), + ("grip_drag::grip_stair_handle", |r: &mut Rng| { let a0 = r.below(2) == 1; let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let _ = web::grip_drag::grip_stair_handle(a0, a1, a2, a3, a4, a5, a6, a7); }), + ("grip_drag::grip_stair_param_points", |r: &mut Rng| { let a0 = r.buf(); let _ = web::grip_drag::grip_stair_param_points(&a0); }), + ("grip_drag::grip_wall_points", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::grip_drag::grip_wall_points(a0, a1, a2, a3, a4); }), + ("grip_drag::grip_excavation_points", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::grip_drag::grip_excavation_points(&a0, a1); }), + ("grip_drag::grip_coincident", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::grip_drag::grip_coincident(&a0, &a1); }), + ("grips::doc_grip_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::grips::doc_grip_commit(a0, &a1, &a2, a3); }), + ("grips::grip_vertices", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::grips::grip_vertices(&a0, a1); }), + ("grips::camera_grip_points", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::grips::camera_grip_points(&a0, a1); }), + ("grips::grip_vertices_polyline", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let _ = web::grips::grip_vertices_polyline(&a0, &a1, a2); }), + ("grips::edge_grips", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.buf(); let a3 = r.below(2) == 1; let _ = web::grips::edge_grips(&a0, a1, &a2, a3); }), + ("grips::polyline_vertex_info", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let a3 = r.f64(); let _ = web::grips::polyline_vertex_info(&a0, &a1, a2, a3); }), + ("hatch::hatch_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::hatch_runs_flat(&a0, &a1); }), + ("hatch::random_hatch_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::hatch::random_hatch_runs_flat(&a0, &a1, a2); }), + ("hatch::dash_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::dash_runs_flat(&a0, &a1); }), + ("hatch::zigzag_points_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::hatch::zigzag_points_flat(a0, a1, a2, a3, a4, a5); }), + ("hatch::motif_points_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let a5 = r.f64(); let a6 = r.f64(); let _ = web::hatch::motif_points_flat(a0, a1, a2, a3, &a4, a5, a6); }), + ("hatch::clip_line_to_polygon_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let _ = web::hatch::clip_line_to_polygon_flat(a0, a1, a2, a3, &a4); }), + ("hatch::clip_segment_to_polygon_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let _ = web::hatch::clip_segment_to_polygon_flat(a0, a1, a2, a3, &a4); }), + ("hatch::clip_polyline_to_polygon_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::clip_polyline_to_polygon_flat(&a0, &a1); }), + ("hatch::hatch_line_family_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::hatch::hatch_line_family_flat(&a0, a1, a2, a3, a4, a5); }), + ("import::import_drawing_summary", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let _ = web::import::import_drawing_summary(&a0, &a1, &a2); }), + ("import::import_drawing_view", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::import::import_drawing_view(&a0, &a1, &a2, a3); }), + ("import::import_drawing_meshes", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::import::import_drawing_meshes(&a0, &a1, &a2, a3); }), + ("import::doc_import_drawing", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.text(); let a5 = r.text(); let a6 = r.f64(); let _ = web::import::doc_import_drawing(a0, &a1, &a2, &a3, &a4, &a5, a6); }), + ("import::doc_import_ifc", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.u32s(); let a4 = r.buf(); let a5 = r.text(); let a6 = r.text(); let a7 = r.f64(); let _ = web::import::doc_import_ifc(a0, &a1, &a2, &a3, &a4, &a5, &a6, a7); }), + ("import::mesh_import_report", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let _ = web::import::mesh_import_report(&a0, &a1); }), + ("import::doc_import_mesh", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.text(); let a5 = r.f64(); let _ = web::import::doc_import_mesh(a0, &a1, &a2, &a3, &a4, a5); }), + ("import::doc_import_step", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.f64(); let _ = web::import::doc_import_step(a0, &a1, &a2, &a3, a4); }), + ("import::pdf_page_info", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let _ = web::import::pdf_page_info(&a0, &a1); }), + ("kennzahlen::kz_solid_volume", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::kennzahlen::kz_solid_volume(&a0, a1, a2, a3); }), + ("kernel2d::k2_circle_circle_intersect", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::kernel2d::k2_circle_circle_intersect(a0, a1, a2, a3, a4, a5); }), + ("layers::layers_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::layers::layers_call(&a0, &a1, &a2, a3); }), + ("layers::levels_recompute_elevations", |r: &mut Rng| { let a0 = r.text(); let _ = web::layers::levels_recompute_elevations(&a0); }), + ("layout_model::layout_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::layout_model::layout_call(&a0, &a1); }), + ("line_pattern::line_dash_phase", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let _ = web::line_pattern::line_dash_phase(a0, &a1); }), + ("line_pattern::line_dash_fit_closed", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let _ = web::line_pattern::line_dash_fit_closed(a0, &a1); }), + ("line_pattern::plan_arc_path_d", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::line_pattern::plan_arc_path_d(&a0, a1, a2); }), + ("opening_presets::opening_type_presets_json", |_r: &mut Rng| { let _ = web::opening_presets::opening_type_presets_json(); }), + ("ops::ops_validate", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let _ = web::ops::ops_validate(&a0, &a1, &a2); }), + ("ops::project_validate", |r: &mut Rng| { let a0 = r.text(); let _ = web::ops::project_validate(&a0); }), + ("parametric_walls::parametric_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::parametric_walls::parametric_call(&a0, &a1); }), + ("pens::pens_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::pens::pens_call(&a0, &a1); }), + ("plan_buf::plan_buf_round_begin", |_r: &mut Rng| { let _ = web::plan_buf::plan_buf_round_begin(); }), + ("plan_buf::plan_buf_round_end", |_r: &mut Rng| { let _ = web::plan_buf::plan_buf_round_end(); }), + ("plan_buf::plan_buf_touch", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_touch(a0); }), + ("plan_buf::plan_buf_recode", |r: &mut Rng| { let a0 = r.bytes(); let _ = web::plan_buf::plan_buf_recode(&a0); }), + ("plan_buf::plan_buf_hold", |r: &mut Rng| { let a0 = r.bytes(); let _ = web::plan_buf::plan_buf_hold(&a0); }), + ("plan_buf::plan_buf_release", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_release(a0); }), + ("plan_buf::plan_buf_is_held", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_is_held(a0); }), + ("plan_dxf::plan_dxf_flat", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.buf(); let a3 = r.text(); let a4 = r.text(); let _ = web::plan_dxf::plan_dxf_flat(a0, &a1, &a2, &a3, &a4); }), + ("plan_pick::pick_index_build", |r: &mut Rng| { let a0 = r.buf(); let _ = web::plan_pick::pick_index_build(&a0); }), + ("plan_pick::pick_index_release", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_pick::pick_index_release(a0); }), + ("plan_pick::pick_nearest_segment", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_pick::pick_nearest_segment(a0, a1, a2, a3); }), + ("plan_pick::pick_segments_near", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_pick::pick_segments_near(a0, a1, a2, a3); }), + ("plan_pick::pick_polygons_at", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.id(); let _ = web::plan_pick::pick_polygons_at(a0, a1, a2, a3); }), + ("plan_pick::pick_nearest_symbol_px", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let a9 = r.f64(); let a10 = r.f64(); let _ = web::plan_pick::pick_nearest_symbol_px(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); }), + ("plan_pick::pick_rings_near", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::plan_pick::pick_rings_near(a0, a1, a2, a3, a4); }), + ("plan_pick::pick_owned_by", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.text(); let _ = web::plan_pick::pick_owned_by(a0, a1, &a2); }), + ("plan_pick::pick_drawing_text", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::plan_pick::pick_drawing_text(a0, a1, a2); }), + ("plan_pick::pick_drawing_image", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::plan_pick::pick_drawing_image(a0, a1, a2); }), + ("plan_pick::pick_drawing_kind", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::plan_pick::pick_drawing_kind(a0, &a1); }), + ("plan_pick::pick_marquee_polygons", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.buf(); let a3 = r.below(2) == 1; let _ = web::plan_pick::pick_marquee_polygons(a0, a1, &a2, a3); }), + ("plan_pick::pick_marquee_drawings", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.below(2) == 1; let a3 = r.text(); let _ = web::plan_pick::pick_marquee_drawings(a0, &a1, a2, &a3); }), + ("plan_print_svg::plan_print_svg_ops", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_print_svg::plan_print_svg_ops(&a0, &a1); }), + ("plan_scene::plan_scene_bin", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let a3 = r.id(); let _ = web::plan_scene::plan_scene_bin(&a0, &a1, a2, a3); }), + ("plan_scene::plan_scene_texts", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::plan_scene::plan_scene_texts(&a0, &a1, a2); }), + ("plan_scene::plan_screen_texts", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_scene::plan_screen_texts(&a0, &a1, a2, a3); }), + ("plan_scene::plan_scene_f64", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_scene::plan_scene_f64(&a0, &a1); }), + ("plan_svg::plan_svg_string", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_svg::plan_svg_string(&a0, &a1); }), + ("polygon::poly_union", |r: &mut Rng| { let a0 = r.buf(); let _ = web::polygon::poly_union(&a0); }), + ("polygon::poly_difference", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::polygon::poly_difference(&a0, &a1); }), + ("polygon::poly_intersection", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::polygon::poly_intersection(&a0, &a1); }), + ("polygon_holes::polygon_merge_holes", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::polygon_holes::polygon_merge_holes(&a0, &a1, a2); }), + ("project_format::project_format_version", |_r: &mut Rng| { let _ = web::project_format::project_format_version(); }), + ("project_refs::project_warnings", |r: &mut Rng| { let a0 = r.text(); let _ = web::project_refs::project_warnings(&a0); }), + ("reorder::reorder_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let _ = web::reorder::reorder_call(&a0, &a1, &a2); }), + ("rich_text::rich_normalize", |r: &mut Rng| { let a0 = r.text(); let _ = web::rich_text::rich_normalize(&a0); }), + ("rich_text::rich_apply_mark", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let a4 = r.text(); let _ = web::rich_text::rich_apply_mark(&a0, a1, a2, &a3, &a4); }), + ("rich_text::rich_toggle_mark", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_toggle_mark(&a0, a1, a2, &a3); }), + ("rich_text::rich_is_mark_active", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_is_mark_active(&a0, a1, a2, &a3); }), + ("rich_text::rich_common_mark_value", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_common_mark_value(&a0, a1, a2, &a3); }), + ("rich_text::rich_serialize", |r: &mut Rng| { let a0 = r.text(); let _ = web::rich_text::rich_serialize(&a0); }), + ("rich_text::rich_apply_preset", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_apply_preset(&a0, a1, a2, &a3); }), + ("roof::roof_geometry_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::roof::roof_geometry_flat(&a0, a1); }), + ("roof::roof_underside_at", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::roof::roof_underside_at(&a0, a1, a2, a3); }), + ("room_area::room_evaluate", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.buf(); let _ = web::room_area::room_evaluate(&a0, a1, &a2); }), + ("room_area::room_polygon_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_polygon_area(&a0); }), + ("room_area::room_centroid", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_centroid(&a0); }), + ("room_area::room_label_point", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_label_point(&a0); }), + ("room_area::room_balance", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::room_area::room_balance(&a0, &a1); }), + ("room_area::room_sia_categories", |_r: &mut Rng| { let _ = web::room_area::room_sia_categories(); }), + ("room_boundary::rooms_detect", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.below(2) == 1; let _ = web::room_boundary::rooms_detect(&a0, a1, a2, a3); }), + ("site_rules::site_multi_polygon_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::site_rules::site_multi_polygon_area(&a0); }), + ("site_rules::site_allowed_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::site_rules::site_allowed_area(&a0); }), + ("site_rules::doc_site_envelope", |r: &mut Rng| { let a0 = r.id(); let _ = web::site_rules::doc_site_envelope(a0); }), + ("skeleton::straight_skeleton", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::skeleton::straight_skeleton(&a0, &a1, a2); }), + ("snap::doc_snap_hold", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.text(); let a4 = r.f64(); let _ = web::snap::doc_snap_hold(a0, &a1, &a2, &a3, a4); }), + ("snap::snap_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.buf(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.id(); let a8 = r.f64(); let a9 = r.f64(); let _ = web::snap::snap_query(a0, &a1, &a2, a3, a4, a5, a6, a7, a8, a9); }), + ("solid_bool::solid_boolean", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::solid_bool::solid_boolean(a0, &a1, &a2); }), + ("stair::stair_outline_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::stair::stair_outline_flat(&a0); }), + ("sun::sun_position", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::sun::sun_position(a0, a1, a2); }), + ("sun::sun_shadow_of_prism", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::sun::sun_shadow_of_prism(&a0, a1, a2, a3, a4); }), + ("sun::sun_without_holes", |r: &mut Rng| { let a0 = r.buf(); let _ = web::sun::sun_without_holes(&a0); }), + ("text_layout::text_lines", |r: &mut Rng| { let a0 = r.text(); let a1 = r.buf(); let a2 = r.opt_text(); let _ = web::text_layout::text_lines(&a0, &a1, a2); }), + ("text_layout::text_frame", |r: &mut Rng| { let a0 = r.text(); let a1 = r.buf(); let _ = web::text_layout::text_frame(&a0, &a1); }), + ("text_layout::text_stamp_block", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::text_layout::text_stamp_block(&a0, a1, a2, a3); }), + ("text_layout::text_wrap_plain", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::text_layout::text_wrap_plain(&a0, a1, a2); }), + ("voids::voids_subtract_rings_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::voids::voids_subtract_rings_flat(&a0, &a1, &a2); }), + ("voids::wall_spec_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::voids::wall_spec_flat(&a0); }), +]; + +// ── Lauf ───────────────────────────────────────────────────────────────────── + +fn env_num(k: &str, default: u64) -> u64 { + std::env::var(k).ok().and_then(|v| v.parse().ok()).unwrap_or(default) +} + +/// Alle offenen Dokumente schliessen (der Fuzz öffnet laufend neue, `doc_open` mit dem Beispielprojekt) und das +/// Beispielprojekt frisch öffnen: Speicher bleibt klein, und die Aufrufe sehen wieder ein gültiges Handle. +fn reset_docs() { + for h in 1..=64u32 { + web::document::doc_close(h); + } + let h = web::document::doc_open(FIXTURE); + assert!(h != 0, "Beispielprojekt muss sich öffnen lassen"); + HANDLE.with(|c| c.set(h)); +} + +#[test] +fn bindungen_kaputte_eingaben() { + let n = env_num("ROBUST_WEB_N", 60); + let seed = env_num("ROBUST_WEB_SEED", 0x5eed_258) | 1; + let only = std::env::var("ROBUST_WEB_ONLY").ok(); + let trace = std::env::var("ROBUST_WEB_TRACE").is_ok(); + // Von Hand: `ROBUST_WEB_SKIP=a,b` überspringt Bindungen (Teilname), um nach einem Hang weiterzusuchen. + let dump: Option<(String, u64)> = std::env::var("ROBUST_WEB_DUMP").ok().and_then(|v| v.split_once('#').and_then(|(a, b)| Some((a.to_string(), b.parse().ok()?)))); + let skip: Vec = std::env::var("ROBUST_WEB_SKIP").map(|v| v.split(',').filter(|x| !x.is_empty()).map(String::from).collect()).unwrap_or_default(); + // Wächter: ein Aufruf über 30 s (Endlosschleife / Speicherflut) wird gemeldet und beendet den Lauf. + let progress = std::sync::Arc::new(std::sync::atomic::AtomicU64::new(0)); + let label = std::sync::Arc::new(std::sync::Mutex::new(String::new())); + { + let (progress, label) = (progress.clone(), label.clone()); + std::thread::spawn(move || { + let mut seen = u64::MAX; + let mut since = std::time::Instant::now(); + loop { + std::thread::sleep(std::time::Duration::from_millis(250)); + let now = progress.load(std::sync::atomic::Ordering::Relaxed); + if now != seen { + seen = now; + since = std::time::Instant::now(); + } else if now != 0 && since.elapsed().as_secs() >= 30 { + eprintln!("HANG (über 30 s): {}", label.lock().unwrap()); + std::process::exit(3); + } + } + }); + } + let mut counter = 0u64; + reset_docs(); + + let default = std::panic::take_hook(); + let cur = std::sync::Arc::new(std::sync::Mutex::new(false)); + let cur2 = cur.clone(); + std::panic::set_hook(Box::new(move |info| { + if !*cur2.lock().unwrap() { + default(info); + return; + } + let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default(); + let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::().cloned()).unwrap_or_else(|| "?".into()); + LAST.with(|l| *l.borrow_mut() = format!("{msg} @ {loc}")); + })); + + // Panic-Text → (Anzahl, erste Bindung) + let mut fails: BTreeMap = BTreeMap::new(); + for (idx, (name, call)) in CALLS.iter().enumerate() { + // Löst absichtlich einen Panic aus (Test-Haken für den Wiederanlauf [118]) und lässt die Dokumenttabelle geborgt. + if *name == "document::__debug_panic" { + continue; + } + if only.as_ref().is_some_and(|o| !name.contains(o.as_str())) || skip.iter().any(|x| name.contains(x.as_str())) { + continue; + } + let mut rng = Rng(seed ^ ((idx as u64 + 1).wrapping_mul(0x9E37_79B9_7F4A_7C15))); + reset_docs(); + for i in 0..n { + if i % 100 == 99 { + reset_docs(); + } + if trace { + eprintln!("{name} #{i}"); + } + DUMP.with(|d| d.set(dump.as_ref().is_some_and(|(nm, k)| name.contains(nm.as_str()) && *k == i))); + counter += 1; + *label.lock().unwrap() = format!("{name} (Aufruf {i}, Seed {seed})"); + progress.store(counter, std::sync::atomic::Ordering::Relaxed); + *cur.lock().unwrap() = true; + let r = catch_unwind(AssertUnwindSafe(|| call(&mut rng))); + *cur.lock().unwrap() = false; + progress.store(0, std::sync::atomic::Ordering::Relaxed); + if r.is_err() { + let what = LAST.with(|l| l.borrow().clone()); + let e = fails.entry(what).or_insert_with(|| (0, format!("{name} (Aufruf {i}, Seed {seed})"))); + e.0 += 1; + } + } + } + let _ = std::panic::take_hook(); + if !fails.is_empty() { + let mut s = format!("{} verschiedene Panics in den Bindungen:\n", fails.len()); + for (k, (c, ctx)) in &fails { + s += &format!(" {c}x {k}\n erstmals bei: {ctx}\n"); + } + panic!("{s}"); + } +} + +/// Jede `#[wasm_bindgen]`-Funktion in `src/web/*.rs` muss in `CALLS` stehen. +#[test] +fn jede_bindung_ist_abgedeckt() { + let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/src/web"); + let mut missing = vec![]; + let mut total = 0; + for e in std::fs::read_dir(dir).unwrap() { + let p = e.unwrap().path(); + let module = p.file_stem().unwrap().to_string_lossy().to_string(); + if module == "mod" || p.extension().is_none_or(|x| x != "rs") { + continue; + } + let text = std::fs::read_to_string(&p).unwrap(); + let mut pending = false; + for line in text.lines() { + let t = line.trim(); + if t.starts_with("#[wasm_bindgen") && !t.starts_with("#[wasm_bindgen(start") { + pending = true; + } else if pending && t.starts_with("pub fn ") { + pending = false; + let name: String = t["pub fn ".len()..].chars().take_while(|c| c.is_alphanumeric() || *c == '_').collect(); + total += 1; + let key = format!("{module}::{name}"); + if !CALLS.iter().any(|(n, _)| *n == key) { + missing.push(key); + } + } + } + } + assert!(total > 100, "zu wenige Bindungen gefunden ({total})"); + assert!(missing.is_empty(), "Bindungen ohne Robustheits-Aufruf in CALLS: {missing:?}"); +} + +/// [258] Dachparameter aus dem Fuzzlauf, bei denen die Wellenfront des Skeletts in einen Rundungszyklus lief +/// (Ecken wuchsen unbegrenzt, Aufruf hing > 30 s): jetzt Obergrenze für Ecken -> Degeneration -> Rückfall. +#[test] +fn regression_roof_skeleton_rundungszyklus() { + let params = [ + 5.0, 1.0, 3.0, 3.0, 4.0, 3.0, 1.0, 5.0, 5.0, 2.0, 1.0, 1.0, 5.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 3.0, 4.0, 1.0, 4.0, 2.0, 2.0, 3.0, 2.0, 1.0, 4.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, + 2.0, 2.0, 4.0, 3.0, 3.0, + ]; + let t = std::time::Instant::now(); + let _ = web::roof::roof_geometry_flat(¶ms, -2.9986637881230873e-22); + assert!(t.elapsed().as_secs() < 10, "Dachgeometrie hängt"); +} diff --git a/src-tauri/render2d/tests/robustness.rs b/src-tauri/render2d/tests/robustness.rs new file mode 100644 index 00000000..353ff8a4 --- /dev/null +++ b/src-tauri/render2d/tests/robustness.rs @@ -0,0 +1,187 @@ +//! [258] Robustheit der Eingänge von render2d (`web.rs`: `set_scene_bin`, `add_font`, Textzeilen): die GPU-freien +//! Leser und die Tessellierung dürfen auf kaputten Bytes nie paniken — ein Panic legt im Browser das ganze WASM-Modul +//! lahm. Native (Standard-Features, ohne GPU): `decode_scene` auf abgeschnittenen/verdorbenen/zufälligen Szenen +//! (Ausgangspunkt: `tests/fixtures/scene_v1.bin`), bei Erfolg `compile_scene`; `text_lines`, `woff2::to_sfnt`, +//! Zerlegung und Strichphase mit NaN/∞/Zufall. Fester Seed, eigener PRNG, jeder Aufruf unter `catch_unwind`. +//! `ROBUST_N` (Aufrufe je Fall, Standard 400), `ROBUST_SEED`. + +use render2d::scene_bin::decode_scene; +use render2d::tessellate::{arc_screen_params, compile_scene, dash_phase, prepare_arc_dash, triangulate}; +use render2d::text_lines::{lines_from_bytes, lines_from_f64}; +use render2d::types::Point; +use render2d::woff2::to_sfnt; +use std::collections::BTreeMap; +use std::panic::{catch_unwind, AssertUnwindSafe}; +use std::sync::{Arc, Mutex}; + +const FIXTURE: &[u8] = include_bytes!("fixtures/scene_v1.bin"); + +struct Rng(u64); + +impl Rng { + fn next(&mut self) -> u64 { + self.0 ^= self.0 >> 12; + self.0 ^= self.0 << 25; + self.0 ^= self.0 >> 27; + self.0.wrapping_mul(0x2545_F491_4F6C_DD1D) + } + fn below(&mut self, n: usize) -> usize { + if n == 0 { 0 } else { (self.next() % n as u64) as usize } + } + fn f64(&mut self) -> f64 { + const POOL: [f64; 12] = [0.0, -0.0, 1.0, -1.0, 1e-9, 1e9, 1e300, -1e300, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 3.0]; + match self.below(4) { + 0 => POOL[self.below(POOL.len())], + 1 => f64::from_bits(self.next()), + 2 => self.below(10) as f64, + _ => (self.next() >> 11) as f64 / (1u64 << 53) as f64 * 100.0 - 50.0, + } + } + fn f32(&mut self) -> f32 { + self.f64() as f32 + } + fn point(&mut self) -> Point { + [self.f32(), self.f32()] + } + fn bytes(&mut self, max: usize) -> Vec { + let n = self.below(max + 1); + (0..n).map(|_| self.next() as u8).collect() + } + /// Gültige Szene, dann: abschneiden, Bytes verdorben, Zähler-Felder auf Randwerte, Anhang. + fn scene_bytes(&mut self) -> Vec { + let mut v = FIXTURE.to_vec(); + match self.below(6) { + 0 => v.truncate(self.below(v.len() + 1)), + 1 => { + for _ in 0..1 + self.below(4) { + let i = self.below(v.len()); + v[i] = self.next() as u8; + } + } + 2 => { + // 4-Byte-Wort (Zähler/Länge/Gleitkommazahl) auf Randwert. + let words: [[u8; 4]; 7] = [[0xff; 4], [0; 4], [0xff, 0xff, 0xff, 0x7f], [0, 0, 0, 0x80], [0, 0, 0xc0, 0x7f], [0, 0, 0x80, 0x7f], [1, 0, 0, 0]]; + for _ in 0..1 + self.below(3) { + let i = self.below(v.len().saturating_sub(3)); + let w = words[self.below(words.len())]; + v[i..i + 4].copy_from_slice(&w); + } + } + 3 => { + let extra = self.bytes(40); + v.extend(extra); + } + 4 => v = self.bytes(200), + _ => { + // Kopf behalten, Rest zufällig. + let keep = self.below(v.len().min(48) + 1); + v.truncate(keep); + let tail = self.bytes(120); + v.extend(tail); + } + } + v + } +} + +#[derive(Default)] +struct Fails(BTreeMap); + +fn check(fails: &mut Fails, cur: &Arc>, last: &Arc>, ctx: &str, f: impl FnOnce()) { + *cur.lock().unwrap() = true; + let r = catch_unwind(AssertUnwindSafe(f)); + *cur.lock().unwrap() = false; + if r.is_err() { + let what = last.lock().unwrap().clone(); + let e = fails.0.entry(what).or_insert_with(|| (0, ctx.to_string())); + e.0 += 1; + } +} + +#[test] +fn render2d_eingaenge_kaputte_daten() { + let n: u64 = std::env::var("ROBUST_N").ok().and_then(|v| v.parse().ok()).unwrap_or(400); + let seed: u64 = std::env::var("ROBUST_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5eed_258) | 1; + + let default = std::panic::take_hook(); + let cur = Arc::new(Mutex::new(false)); + let last = Arc::new(Mutex::new(String::new())); + { + let (cur, last) = (cur.clone(), last.clone()); + std::panic::set_hook(Box::new(move |info| { + if !*cur.lock().unwrap() { + default(info); + return; + } + let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default(); + let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::().cloned()).unwrap_or_else(|| "?".into()); + *last.lock().unwrap() = format!("{msg} @ {loc}"); + })); + } + + let mut fails = Fails::default(); + let mut rng = Rng(seed); + let mut decoded_ok = 0usize; + for i in 0..n { + // 1. Szene lesen (und bei Erfolg tessellieren). + let bytes = rng.scene_bytes(); + let mut ok = false; + check(&mut fails, &cur, &last, &format!("decode_scene/compile_scene (Aufruf {i}, Seed {seed})"), || { + if let Ok(scene) = decode_scene(&bytes) { + ok = true; + let _ = compile_scene(&scene); + } + }); + decoded_ok += ok as usize; + + // 2. Textzeilen (f64-Puffer der Kern-Bindung und Bytes). + let nf = rng.below(60); + let f: Vec = (0..nf).map(|_| if rng.below(3) == 0 { rng.below(5) as f64 } else { rng.f64() }).collect(); + check(&mut fails, &cur, &last, &format!("lines_from_f64 (Aufruf {i})"), || { + let _ = lines_from_f64(&f); + }); + let tb = rng.bytes(300); + check(&mut fails, &cur, &last, &format!("lines_from_bytes (Aufruf {i})"), || { + let _ = lines_from_bytes(&tb); + }); + + // 3. Schriftdateien: WOFF2-/SFNT-Köpfe mit Zufall. + let mut font = rng.bytes(400); + let head: &[u8] = match rng.below(4) { + 0 => b"wOF2", + 1 => &[0, 1, 0, 0], + _ => &[], + }; + font.splice(0..0, head.iter().copied()); + check(&mut fails, &cur, &last, &format!("woff2::to_sfnt (Aufruf {i})"), || { + let _ = to_sfnt(&font); + }); + + // 4. Zerlegung, Bögen, Strichmuster mit Unsinn. + let pts: Vec = (0..rng.below(14)).map(|_| rng.point()).collect(); + check(&mut fails, &cur, &last, &format!("triangulate (Aufruf {i})"), || { + let _ = triangulate(&pts); + }); + let (c, a, b, r) = (rng.point(), rng.point(), rng.point(), rng.f32()); + check(&mut fails, &cur, &last, &format!("arc_screen_params (Aufruf {i})"), || { + let _ = arc_screen_params(c, a, b, r); + }); + let cyc: Vec = (0..rng.below(8)).map(|_| rng.f32()).collect(); + // (`dash_coverage` ist ein CPU-Spiegel des Shaders nur für Tests, mit `clamp` auf dem Segment: nicht Teil der Eingänge.) + let len = rng.f32(); + check(&mut fails, &cur, &last, &format!("Strichmuster (Aufruf {i})"), || { + let _ = dash_phase(len, &cyc); + let _ = prepare_arc_dash(Some(&cyc)); + let _ = prepare_arc_dash(None); + }); + } + let _ = std::panic::take_hook(); + assert!(decoded_ok > 0, "der Fuzz erreicht nie eine lesbare Szene — Ausgangspunkt prüfen"); + if !fails.0.is_empty() { + let mut s = format!("{} verschiedene Panics in render2d:\n", fails.0.len()); + for (k, (c, ctx)) in &fails.0 { + s += &format!(" {c}x {k}\n erstmals bei: {ctx}\n"); + } + panic!("{s}"); + } +} diff --git a/src-tauri/render3d/tests/robustness.rs b/src-tauri/render3d/tests/robustness.rs new file mode 100644 index 00000000..b85758de --- /dev/null +++ b/src-tauri/render3d/tests/robustness.rs @@ -0,0 +1,196 @@ +//! [258] Robustheit der Eingänge von render3d (`web.rs`: `set_model`, `set_parts`, `cut_section_json`, Ghost-Teile): +//! das GPU-freie Rückgrat (JSON-Modell → `Scene::apply` → `chunk_data`, Schnitt `cut_section`) darf auf Unsinn nie +//! paniken — ein Panic legt im Browser das ganze WASM-Modul lahm. Ausgangspunkt ist ein gültiges Teile-Update +//! (Wand mit Öffnung/Loch/Schichten, Decke, Mesh, Dachschicht), dessen Zahlen/Typen/Felder zufällig verdorben werden +//! (0, ±1, 1e-30, 1e30, 1e300, falscher Typ, null, gelöscht, Array verkürzt/verdoppelt); dazu Zufallstext. +//! Fester Seed, eigener PRNG, jeder Aufruf unter `catch_unwind`. `ROBUST_N` (Standard 1500), `ROBUST_SEED`. + +use render3d::scene::{PartsUpdate, Scene}; +use render3d::section::{cut_section, SectionPlane}; +use serde_json::{json, Value}; +use std::collections::BTreeMap; +use std::panic::{catch_unwind, AssertUnwindSafe}; +use std::sync::{Arc, Mutex}; + +struct Rng(u64); + +impl Rng { + fn next(&mut self) -> u64 { + self.0 ^= self.0 >> 12; + self.0 ^= self.0 << 25; + self.0 ^= self.0 >> 27; + self.0.wrapping_mul(0x2545_F491_4F6C_DD1D) + } + fn below(&mut self, n: usize) -> usize { + if n == 0 { 0 } else { (self.next() % n as u64) as usize } + } + fn f32(&mut self) -> f32 { + const POOL: [f32; 10] = [0.0, -0.0, 1.0, -1.0, 1e-30, 1e30, f32::NAN, f32::INFINITY, f32::NEG_INFINITY, f32::MAX]; + match self.below(3) { + 0 => POOL[self.below(POOL.len())], + 1 => f32::from_bits(self.next() as u32), + _ => (self.next() >> 40) as f32 / (1u64 << 24) as f32 * 20.0 - 10.0, + } + } +} + +fn seed_update() -> Value { + json!({ + "reset": true, + "upsert": [{ + "id": "a", + "walls": [{ + "start": [0.0, 0.0], "end": [6.0, 0.0], "thickness": 0.3, "height": 2.8, "baseElevation": 0.0, + "openings": [{"from": 1.0, "to": 2.0, "sill": 0.8, "height": 1.2}], + "holes": [{"from": 3.0, "to": 4.0, "zBottom": 0.0, "zTop": 2.1}], + "layers": [{"thickness": 0.1, "color": [0.9, 0.9, 0.9]}, {"thickness": 0.2, "color": [0.5, 0.4, 0.3]}] + }, { + "start": [6.0, 0.0], "end": [6.0, 4.0], "thickness": 0.3, "height": 2.8, "topDrop": [0.2, 0.0] + }], + "slabs": [{"outline": [[0.0, 0.0], [6.0, 0.0], [6.0, 4.0], [0.0, 4.0]], "zBottom": -0.2, "zTop": 0.0}], + "meshes": [{"positions": [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0], "indices": [0, 1, 2]}], + "roofLayers": [{"polygon": [[0.0, 2.8, 0.0], [6.0, 2.8, 0.0], [6.0, 3.6, 4.0], [0.0, 3.6, 4.0]], "normal": [0.0, 0.9, -0.4], "thickness": 0.2, "color": [0.6, 0.2, 0.2]}] + }] + }) +} + +/// Zahlen verdorben, Typen vertauscht, Felder gelöscht, Arrays verändert. +fn mutate(v: &mut Value, rng: &mut Rng, budget: &mut u32) { + match v { + Value::Number(_) => { + if *budget > 0 && rng.below(6) == 0 { + *budget -= 1; + *v = match rng.below(9) { + 0 => json!(0), + 1 => json!(-1), + 2 => json!(1e-30), + 3 => json!(1e30), + 4 => json!(1e300), + 5 => json!(4294967296u64), + 6 => json!(-4294967295i64), + 7 => json!(0.5), + _ => Value::Null, + }; + } + } + Value::Array(a) => { + if *budget > 0 && rng.below(10) == 0 { + *budget -= 1; + match rng.below(4) { + 0 => a.clear(), + 1 => { + a.pop(); + } + 2 => { + if let Some(x) = a.first().cloned() { + a.push(x); + } + } + _ => a.push(json!("x")), + } + } + for x in a.iter_mut() { + mutate(x, rng, budget); + } + } + Value::Object(m) => { + if *budget > 0 && rng.below(14) == 0 { + *budget -= 1; + if let Some(k) = m.keys().nth(rng.below(m.len())).cloned() { + m.remove(&k); + } + } + for (_, x) in m.iter_mut() { + mutate(x, rng, budget); + } + } + Value::String(_) => { + if *budget > 0 && rng.below(4) == 0 { + *budget -= 1; + *v = json!(rng.below(100)); + } + } + _ => {} + } +} + +#[test] +fn render3d_eingaenge_kaputte_daten() { + let n: u64 = std::env::var("ROBUST_N").ok().and_then(|v| v.parse().ok()).unwrap_or(1500); + let seed: u64 = std::env::var("ROBUST_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5eed_258) | 1; + + let default = std::panic::take_hook(); + let cur = Arc::new(Mutex::new(false)); + let last = Arc::new(Mutex::new(String::new())); + { + let (cur, last) = (cur.clone(), last.clone()); + std::panic::set_hook(Box::new(move |info| { + if !*cur.lock().unwrap() { + default(info); + return; + } + let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default(); + let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::().cloned()).unwrap_or_else(|| "?".into()); + *last.lock().unwrap() = format!("{msg} @ {loc}"); + })); + } + + let mut fails: BTreeMap = BTreeMap::new(); + let mut run = |ctx: String, f: &mut dyn FnMut()| { + *cur.lock().unwrap() = true; + let r = catch_unwind(AssertUnwindSafe(|| f())); + *cur.lock().unwrap() = false; + if r.is_err() { + let what = last.lock().unwrap().clone(); + fails.entry(what).or_insert_with(|| (0, ctx)).0 += 1; + } + }; + + let mut rng = Rng(seed); + let mut parsed_ok = 0usize; + let mut scene = Scene::new(); + for i in 0..n { + // Teile-Update: gültig verdorben, ab und zu reiner Zufallstext. + let text = if rng.below(12) == 0 { + let junk: Vec = (0..rng.below(60)).map(|_| rng.next() as u8).collect(); + String::from_utf8_lossy(&junk).into_owned() + } else { + let mut v = seed_update(); + let mut budget = 1 + rng.below(4) as u32; + mutate(&mut v, &mut rng, &mut budget); + v.to_string() + }; + let plane_pt = [rng.f32(), rng.f32(), rng.f32()]; + let plane_n = [rng.f32(), rng.f32(), rng.f32()]; + let fresh = rng.below(3) == 0; + run(format!("Teile-Update/Ketten (Aufruf {i}, Seed {seed}): {text}"), &mut || { + let Ok(upd) = serde_json::from_str::(&text) else { return }; + parsed_ok += 1; + if fresh { + scene = Scene::new(); + } + let change = scene.apply(upd); + let _ = scene.bounds(); + let _ = scene.shadow_bounds(); + let _ = scene.terrain(); + let _ = scene.has_edges(); + let _ = scene.edge_adj().count(); + for c in 0..scene.chunk_count() { + let _ = scene.chunk_data(c); + } + let _ = change.dirty_chunks.len(); + let (walls, slabs, roofs) = scene.collect_inputs(); + let plane = SectionPlane::new(plane_pt, plane_n); + let _ = cut_section(&plane, &walls, &slabs, &roofs); + }); + } + let _ = std::panic::take_hook(); + assert!(parsed_ok > (n / 4) as usize, "zu wenige lesbare Updates ({parsed_ok}) — Ausgangspunkt prüfen"); + if !fails.is_empty() { + let mut s = format!("{} verschiedene Panics in render3d:\n", fails.len()); + for (k, (c, ctx)) in &fails { + s += &format!(" {c}x {k}\n erstmals bei: {}\n", &ctx[..ctx.len().min(1500)]); + } + panic!("{s}"); + } +}