Files
lightgui_rust/crates/xframe-layout/tests/script.rs
T
cnmcdee 3254127571 Add xframe apps: generic demo, palette, layout, test runner + shared x11/registry/stub crate
xframe-common: registry (547 widgets, 11 sections, 6 families) + palette
(583 entries) code-generated at build time from data/*.json; ICO decoder
(port of ico.h); palette<->layout file IPC (port of ipc.h); style manager
with the exact default/dark styles; Widget trait (port of IWidget) plus a
TEMPORARY StubWidget until xframe-widgets lands (see SEAM docs in
widget.rs); small x11rb helpers (windows, colours, core fonts, text,
GetImage screenshots, window lookup, WM_DELETE).
xframe-demo: ONE generic demo binary replacing the 547 C++ demo mains
(800x600, default+dark styles, event loop, --list/--dark/--hold/--geometry).
xframe-palette: port of widgets/palette/main_palette.cpp (547 entries in
11 sections, 16x16 icons, collapse, selection file, --selftest 547/547).
xframe-layout: port of widgets/layout/main_layout.cpp (place/move/resize/
delete, 8 resize handles, script mode incl. PLACE_ALL + CHECKDRAW).
xframe-test-runner: port of widgets/test-driver/run_tests.py — runs every
registry widget through xframe-demo under Xvfb, hover/click/key/exit
pixel-diff checks, same CSV columns. Tests: common 10, demo 3,
palette 1 (selftest 547/547), layout 1 (incl. PLACE_ALL 547/547),
runner 3 (incl. --limit 3 end-to-end). Clippy clean, cargo fmt clean.
2026-11-29 06:10:38 +00:00

114 lines
3.8 KiB
Rust

//! Layout script-mode test under Xvfb on display :92 (kept clear of
//! the demo :98, palette :93 and runner :91 tests). Exercises the
//! full script command set, including PLACE_ALL (547 stubs) and the
//! GtkInvisible BLANK-EXPECTED CHECKDRAW path.
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::time::{Duration, Instant};
fn layout_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_xframe-layout"))
}
fn start_xvfb(display: &str) -> Option<Child> {
// A SIGKILLed Xvfb leaves its socket behind; a stale socket makes
// the wait below return at once and the X client then fails to
// connect. Remove it when no server for this display is alive.
let sock_path = format!("/tmp/.X11-unix/X{}", display.trim_start_matches(':'));
let server_running = Command::new("pgrep")
.args(["-f", &format!("Xvfb {}", display)])
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !server_running && PathBuf::from(&sock_path).exists() {
let _ = std::fs::remove_file(&sock_path);
}
let child = Command::new("Xvfb")
.args([display, "-screen", "0", "1280x1024x24"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.ok()?;
let sock = format!("/tmp/.X11-unix/X{}", display.trim_start_matches(':'));
let t0 = Instant::now();
while !PathBuf::from(&sock).exists() {
if t0.elapsed() > Duration::from_secs(10) {
return None;
}
std::thread::sleep(Duration::from_millis(100));
}
Some(child)
}
#[test]
fn layout_script_full_command_set() {
let mut xvfb = match start_xvfb(":92") {
Some(c) => c,
None => {
eprintln!("Xvfb unavailable; skipping X test");
return;
}
};
let dir = std::env::temp_dir().join("xframe-layout-test");
let _ = std::fs::create_dir_all(&dir);
let script = dir.join("cmds.txt");
let log = dir.join("out.log");
let saved = dir.join("saved.txt");
let state = dir.join("layout-state.txt");
let _ = std::fs::remove_file(&log);
std::fs::write(
&script,
format!(
"# layout script test\nPLACE GtkButton 40 40 340 200\nPLACE GtkInvisible 11 11 10 10\nCHECKDRAW 1\nCHECKDRAW 2\nMOVE 1 10 5\nRESIZE 1 400 220\nSELECT 1\nDBLCLICK 1\nHANDLE se 20 10\nSAVE {}\nDELETE 2\nLOAD {}\nCOUNT\nLIST\nPLACE_ALL\nCOUNT\nQUIT\n",
saved.display(),
saved.display()
),
)
.unwrap();
let out = Command::new(layout_bin())
.args(["--script"])
.arg(&script)
.args(["--log"])
.arg(&log)
.env("DISPLAY", ":92")
.env("LIGHTGUI_LAYOUT_STATE", &state)
.output()
.expect("run layout --script");
let log_text = std::fs::read_to_string(&log).unwrap_or_default();
let _ = xvfb.kill();
let _ = xvfb.wait();
assert!(
out.status.success(),
"layout script rc={:?}\nlog:\n{}",
out.status.code(),
log_text
);
assert!(
log_text.contains("OK CHECKDRAW 1 GtkButton nonwhite="),
"log:\n{}",
log_text
);
assert!(
log_text.contains("BLANK-EXPECTED"),
"GtkInvisible should be BLANK-EXPECTED\nlog:\n{}",
log_text
);
assert!(
log_text.contains("OK PLACE_ALL 547/547"),
"log:\n{}",
log_text
);
assert!(
log_text.contains("SCRIPT 17 commands, 0 failures"),
"log:\n{}",
log_text
);
// State file must hold 2 loaded + 547 PLACE_ALL widgets.
let state_text = std::fs::read_to_string(&state).unwrap_or_default();
assert_eq!(state_text.lines().count(), 549, "state lines");
let _ = std::fs::remove_file(&script);
let _ = std::fs::remove_file(&log);
let _ = std::fs::remove_file(&saved);
let _ = std::fs::remove_file(&state);
}