use crate::platform::{get_platform, Platform};
#[test]
fn destroy_widget_is_authoritative_and_idempotent() {
let platform = get_platform();
platform.init();
let window = Platform::create_window(platform, "teardown", 0, 0, 400, 300);
assert_ne!(window, 0, "{} must create a window", platform.backend_name());
assert!(Platform::destroy_widget(platform, window), "first destroy must report true");
assert!(
!Platform::destroy_widget(platform, window),
"destroying an already-destroyed id must report false"
);
assert!(!Platform::destroy_widget(platform, 999_999), "an unknown id must report false");
}
#[test]
fn unsupported_and_unknown_ids_report_absence() {
let platform = get_platform();
platform.init();
let window = Platform::create_window(platform, "w", 0, 0, 400, 300);
assert_ne!(window, 0);
let control = Platform::create_button(platform, window, "b", 10, 10, 80, 30);
assert!(
!Platform::destroy_widget(platform, control),
"destroying an id that was never issued must report false ({})",
platform.backend_name()
);
}
#[test]
fn destroy_widget_keeps_widget_set_stable_across_churn() {
let platform = get_platform();
platform.init();
for round in 0..25 {
let mut ids = Vec::with_capacity(40);
for _ in 0..40 {
ids.push(Platform::create_window(platform, "churn", 0, 0, 200, 150));
}
for id in ids {
assert_ne!(id, 0, "round {round}: window creation must keep succeeding under churn");
assert!(Platform::destroy_widget(platform, id), "round {round}: destroy must succeed");
assert!(
!Platform::destroy_widget(platform, id),
"round {round}: a destroyed id must stay gone"
);
}
}
}
#[test]
fn destroy_widget_does_not_disturb_siblings() {
let platform = get_platform();
platform.init();
let a = Platform::create_window(platform, "a", 0, 0, 300, 200);
let b = Platform::create_window(platform, "b", 30, 30, 300, 200);
let c = Platform::create_window(platform, "c", 60, 60, 300, 200);
assert!(a != 0 && b != 0 && c != 0);
assert!(Platform::destroy_widget(platform, b));
assert!(!Platform::destroy_widget(platform, b), "the destroyed id stays gone");
assert!(
Platform::destroy_widget(platform, a),
"sibling 'a' must still exist after 'b' was destroyed"
);
assert!(
Platform::destroy_widget(platform, c),
"sibling 'c' must still exist after 'b' was destroyed"
);
assert!(!Platform::destroy_widget(platform, b), "the destroyed window 'b' must stay gone");
}