use super::*;
use windows_core::Interface;
fn with_com_initialized<F: FnOnce()>(f: F) {
use windows::Win32::System::Com::{COINIT_MULTITHREADED, CoInitializeEx, CoUninitialize};
unsafe {
let _ = CoInitializeEx(None, COINIT_MULTITHREADED);
}
f();
unsafe {
CoUninitialize();
}
}
#[test]
fn test_wic_core_creation() {
with_com_initialized(|| {
let result = WicCore::new();
assert!(result.is_ok(), "WicCore creation should succeed");
});
}
#[test]
fn test_wic_core_factory_access() {
with_com_initialized(|| {
let wic_core = WicCore::new().expect("WicCore creation failed");
let factory = wic_core.factory();
assert!(!factory.as_raw().is_null(), "factory should not be null");
});
}
#[test]
fn test_wic_core_clone() {
with_com_initialized(|| {
let wic_core = WicCore::new().expect("WicCore creation failed");
let cloned = wic_core.clone();
assert!(
!wic_core.factory().as_raw().is_null(),
"original factory should be valid"
);
assert!(
!cloned.factory().as_raw().is_null(),
"cloned factory should be valid"
);
});
}
#[test]
fn test_wic_core_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<WicCore>();
}
#[test]
fn test_wintf_task_pool_creation() {
let task_pool = WintfTaskPool::new();
assert!(
task_pool.is_empty(),
"new task pool should have empty queue"
);
}
#[test]
fn test_wintf_task_pool_drain_empty() {
use bevy_ecs::prelude::*;
let task_pool = WintfTaskPool::new();
let mut world = World::new();
task_pool.drain_and_apply(&mut world);
}
#[test]
fn test_wintf_task_pool_command_send_receive() {
use bevy_ecs::prelude::*;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
let task_pool = WintfTaskPool::new();
let executed = Arc::new(AtomicBool::new(false));
let executed_clone = executed.clone();
task_pool.send_command(Box::new(move |_world: &mut World| {
executed_clone.store(true, Ordering::SeqCst);
}));
let mut world = World::new();
task_pool.drain_and_apply(&mut world);
assert!(
executed.load(Ordering::SeqCst),
"command should be executed"
);
}
#[test]
fn test_bitmap_source_creation() {
let bitmap_source = BitmapSource::new("test/path.png");
assert_eq!(bitmap_source.path, "test/path.png");
}
#[test]
fn test_bitmap_source_from_string() {
let path = String::from("assets/image.png");
let bitmap_source = BitmapSource::new(path);
assert_eq!(bitmap_source.path, "assets/image.png");
}
#[test]
fn test_bitmap_source_resource_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<BitmapSourceResource>();
}
#[test]
fn test_bitmap_source_graphics_new() {
let graphics = BitmapSourceGraphics::new();
assert!(!graphics.is_valid(), "new graphics should not be valid");
assert!(graphics.bitmap().is_none(), "bitmap should be None");
}
#[test]
fn test_bitmap_source_graphics_invalidate() {
let mut graphics = BitmapSourceGraphics::new();
graphics.invalidate();
assert!(
!graphics.is_valid(),
"invalidated graphics should not be valid"
);
}
#[test]
fn test_bitmap_source_graphics_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<BitmapSourceGraphics>();
}
#[test]
fn test_resolve_path_absolute_is_returned_unchanged() {
use super::systems::resolve_path;
use std::path::Path;
let abs = r"C:\some\absolute\image.png";
let resolved = resolve_path(abs).expect("absolute path resolves");
assert!(resolved.is_absolute(), "result should stay absolute");
assert_eq!(resolved, Path::new(abs));
}
#[test]
fn test_resolve_path_relative_is_joined_under_exe_dir() {
use super::systems::resolve_path;
let resolved = resolve_path("assets/logo.png").expect("relative path resolves");
let exe = std::env::current_exe().expect("current_exe available in tests");
let exe_dir = exe.parent().expect("exe has a parent dir");
let expected = exe_dir.join("assets/logo.png");
assert_eq!(resolved, expected);
assert!(resolved.is_absolute());
assert!(resolved.starts_with(exe_dir));
assert!(resolved.ends_with("logo.png"));
}
#[test]
fn test_resolve_path_relative_preserves_subdirectories() {
use super::systems::resolve_path;
let resolved = resolve_path("a/b/c.png").expect("nested relative path resolves");
let exe = std::env::current_exe().expect("current_exe available in tests");
let exe_dir = exe.parent().expect("exe has a parent dir");
assert_eq!(resolved, exe_dir.join("a/b/c.png"));
}