New Archetype::Monitor (MonitorWidget, kind-dispatched draw) for XHistoryGraph, XCoreGrid, XNetGraph, XTempHistory, XUsageBar, XStackBar, XVerticalBar, XTachometer, XArcGauge, XDonutGauge, XProcessList, XLoadBadge, XMonitorButton, XMonitorGrid, XSysBox. - data/registry.json + data/palette.json: 15 entries, registry kept in sorted order (the C extractor requires it); palette Misc/X group re-sorted, other sections untouched, registry_index refreshed (XGraph 545->548, XSpreadsheet 546->555). - crates/xframe-widgets/src/monitor.rs: stdlib-only live checks (/proc scan, systemctl is-active, TcpStream::connect_timeout), poll()/update() with a 2s staleness guard, deterministic demo seeding; unit tests incl. headless Canvas draw for all kinds. - Placeholder 16x16 icons (assets/PROVENANCE.md notes they are placeholders pending the C port) + 15 demo examples + README monitor-family section (547 -> 562). - xframe-common ico test tolerates the 15 monitor icons as pending until the C icons land (matched by name, not index). cargo build --workspace: clean, warning-free. xframe-common lib 8/8, xframe-widgets lib 28/28, widget_tests 24/24, demo smoke 3/3, designer palette/seam 4/4 + 4/4 pass.
100 lines
3.2 KiB
Rust
100 lines
3.2 KiB
Rust
//! Smoke tests for xframe-demo. The Xvfb test uses display :98 so it
|
|
//! cannot collide with the palette (:97), layout (:96) or runner (:95)
|
|
//! tests when cargo runs test binaries in parallel.
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::process::{Child, Command, Stdio};
|
|
use std::time::{Duration, Instant};
|
|
|
|
fn demo_bin() -> PathBuf {
|
|
PathBuf::from(env!("CARGO_BIN_EXE_xframe-demo"))
|
|
}
|
|
|
|
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 list_has_562_names() {
|
|
let out = Command::new(demo_bin())
|
|
.arg("--list")
|
|
.output()
|
|
.expect("run demo --list");
|
|
assert!(out.status.success());
|
|
let text = String::from_utf8(out.stdout).unwrap();
|
|
let names: Vec<&str> = text.lines().collect();
|
|
assert_eq!(names.len(), 562);
|
|
assert!(names.contains(&"GtkButton"));
|
|
assert!(names.contains(&"IndRSI"));
|
|
assert!(names.contains(&"InstPressureGauge"));
|
|
assert!(names.contains(&"XSpreadsheet"));
|
|
assert!(names.contains(&"XHistoryGraph"));
|
|
assert!(names.contains(&"XMonitorButton"));
|
|
assert!(names.contains(&"GtkInvisible"));
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_name_exits_2() {
|
|
let out = Command::new(demo_bin())
|
|
.arg("NoSuchWidget")
|
|
.output()
|
|
.expect("run demo");
|
|
assert_eq!(out.status.code(), Some(2));
|
|
}
|
|
|
|
#[test]
|
|
fn demo_opens_and_exits_on_hold_under_xvfb() {
|
|
let mut xvfb = match start_xvfb(":98") {
|
|
Some(c) => c,
|
|
None => {
|
|
eprintln!("Xvfb unavailable; skipping X test");
|
|
return;
|
|
}
|
|
};
|
|
let r = (|| {
|
|
let mut log = std::fs::File::create("/tmp/xframe-demo-smoke.log").ok()?;
|
|
writeln!(log, "smoke").ok()?;
|
|
let out = Command::new(demo_bin())
|
|
.args(["GtkButton", "--hold", "2"])
|
|
.env("DISPLAY", ":98")
|
|
.output()
|
|
.ok()?;
|
|
assert!(
|
|
out.status.success(),
|
|
"demo exit: {:?} stderr: {}",
|
|
out.status,
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
Some(())
|
|
})();
|
|
let _ = xvfb.kill();
|
|
let _ = xvfb.wait();
|
|
assert!(r.is_some(), "demo run failed");
|
|
}
|