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);
let child = Platform::create_button(platform, window, "b", 10, 10, 80, 30);
assert!(Platform::destroy_widget(platform, child), "first destroy must report true");
assert!(
!Platform::destroy_widget(platform, child),
"destroying an already-destroyed widget must report false"
);
assert!(!Platform::destroy_widget(platform, 999_999), "an unknown widget id must report false");
Platform::set_widget_text(platform, child, "after");
assert_eq!(
Platform::get_widget_text(platform, child),
"",
"a destroyed widget must not retain text"
);
}
#[test]
fn destroy_widget_keeps_widget_set_stable_across_churn() {
let platform = get_platform();
platform.init();
let window = Platform::create_window(platform, "churn", 0, 0, 400, 300);
for round in 0..25 {
let mut ids = Vec::with_capacity(100);
for _ in 0..100 {
ids.push(Platform::create_checkbox(platform, window, "c", 0, 0, 20, 20));
}
for id in ids {
assert!(Platform::destroy_widget(platform, id), "round {round}: destroy must succeed");
assert!(
!Platform::is_widget_visible(platform, id),
"round {round}: destroyed widget still reports visible"
);
}
}
}
#[test]
fn destroy_widget_does_not_disturb_siblings() {
let platform = get_platform();
platform.init();
let window = Platform::create_window(platform, "siblings", 0, 0, 400, 300);
let a = Platform::create_button(platform, window, "a", 10, 10, 80, 30);
let b = Platform::create_button(platform, window, "b", 10, 50, 80, 30);
let c = Platform::create_label(platform, window, "c", 10, 90, 80, 30);
assert!(Platform::destroy_widget(platform, b));
Platform::set_widget_text(platform, a, "A!");
assert_eq!(Platform::get_widget_text(platform, a), "A!");
Platform::set_widget_text(platform, c, "C!");
assert_eq!(Platform::get_widget_text(platform, c), "C!");
assert!(!Platform::destroy_widget(platform, b));
assert_eq!(Platform::get_widget_text(platform, b), "");
}