#![allow(deprecated)]
use crate::platform::macos::MacOSPlatform;
use crate::platform::Platform;
#[test]
fn macos_create_window_succeeds_off_main_thread() {
let platform = MacOSPlatform::new();
assert!(!crate::platform::macos::types::is_main_thread(), "test harness runs off-main");
let window = platform.create_window("Off-main", 10, 20, 320, 240);
assert_ne!(window, 0, "create_window must return a usable id off-main");
let handle = platform.get_handle(window).expect("handle must be registered");
assert_eq!(handle.ptr, 0, "no native NSWindow may be constructed off the main thread");
}
#[test]
fn macos_reports_no_native_controls() {
let platform = MacOSPlatform::new();
let window = platform.create_window("W", 0, 0, 320, 240);
assert_eq!(
platform.create_button(window, "ok", 0, 0, 80, 24),
0,
"this host creates no native button"
);
assert_eq!(platform.create_checkbox(window, "on", 0, 0, 80, 24), 0);
assert_eq!(platform.create_label(window, "text", 0, 0, 80, 24), 0);
assert_eq!(platform.widget_value(window), None, "a window has no numeric value to report");
}
#[test]
fn macos_window_state_round_trips_without_a_native_handle() {
use crate::platform::WindowStateFlag;
let platform = MacOSPlatform::new();
let window = platform.create_window("Stateful", 0, 0, 320, 240);
assert!(platform.set_window_state(window, WindowStateFlag::Maximized, true));
assert_eq!(platform.is_window_in_state(window, WindowStateFlag::Maximized), Some(true));
assert!(platform.set_window_state(window, WindowStateFlag::Maximized, false));
assert_eq!(platform.is_window_in_state(window, WindowStateFlag::Maximized), Some(false));
assert!(!platform.set_window_state(window + 1000, WindowStateFlag::Maximized, true));
assert_eq!(platform.is_window_in_state(window + 1000, WindowStateFlag::Maximized), None);
}
#[test]
fn macos_widget_text_and_geometry_round_trip() {
let platform = MacOSPlatform::new();
let window = platform.create_window("Original", 10, 20, 320, 240);
assert_eq!(platform.get_widget_text(window), "Original");
platform.set_widget_text(window, "Renamed");
assert_eq!(platform.get_widget_text(window), "Renamed");
platform.set_widget_geometry(window, 5, 6, 100, 50);
assert!(platform.is_widget_visible(window));
assert!(platform.is_widget_enabled(window));
platform.set_widget_enabled(window, false);
assert!(!platform.is_widget_enabled(window));
}
#[test]
fn macos_destroy_widget_releases_the_record() {
let platform = MacOSPlatform::new();
let window = platform.create_window("Temp", 0, 0, 100, 100);
assert!(platform.destroy_widget(window));
assert!(!platform.destroy_widget(window), "second destroy must report absence");
assert_eq!(platform.get_widget_text(window), "");
}
#[cfg(feature = "advanced-widgets")]
#[test]
fn config_dir_uses_application_support_not_xdg() {
let Some(base) = dirs::config_dir() else {
return; };
let text = base.to_string_lossy();
assert!(
text.contains("Library/Application Support"),
"macOS config dir must use Application Support, got {text}"
);
assert!(!text.contains("/.config/"), "macOS must not use the Linux XDG path: {text}");
}