From 46b313b585cd365298146d1d685eaea1ac86cda3 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 21 Aug 2022 11:54:50 -0400 Subject: [PATCH] Make networking module be unfeature flagged, added more tests --- src/image/image.rs | 23 +++++++++++++++++------ src/lib.rs | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/image/image.rs b/src/image/image.rs index a3b6c7b..b8c1918 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -141,7 +141,7 @@ impl Image { let file_path = NSString::new(path); Image(unsafe { - let alloc: id = msg_send![class!(NSImage), alloc]; + let alloc: id = msg_send![Self::class(), alloc]; ShareId::from_ptr(msg_send![alloc, initWithContentsOfFile: file_path]) }) } @@ -166,7 +166,7 @@ impl Image { Image(unsafe { ShareId::from_ptr({ let icon = icon.to_id(); - msg_send![class!(NSImage), imageNamed: icon] + msg_send![Self::class(), imageNamed: icon] }) }) } @@ -188,13 +188,13 @@ impl Image { true => { let icon = NSString::new(icon.to_sfsymbol_str()); let desc = NSString::new(accessibility_description); - msg_send![class!(NSImage), imageWithSystemSymbolName:&*icon + msg_send![Self::class(), imageWithSystemSymbolName:&*icon accessibilityDescription:&*desc] }, false => { let icon = icon.to_id(); - msg_send![class!(NSImage), imageNamed: icon] + msg_send![Self::class(), imageNamed: icon] } }) }) @@ -222,7 +222,7 @@ impl Image { true => { let icon = NSString::new(symbol.to_str()); let desc = NSString::new(accessibility_description); - msg_send![class!(NSImage), imageWithSystemSymbolName:&*icon + msg_send![Self::class(), imageWithSystemSymbolName:&*icon accessibilityDescription:&*desc] }, @@ -276,7 +276,7 @@ impl Image { let block = block.copy(); Image(unsafe { - let img: id = msg_send![class!(NSImage), imageWithSize:target_frame.size + let img: id = msg_send![Self::class(), imageWithSize:target_frame.size flipped:YES drawingHandler:block ]; @@ -285,3 +285,14 @@ impl Image { }) } } + +#[test] +fn test_image_from_bytes() { + let image_bytes = include_bytes!("../../test-data/favicon.ico"); + let image = Image::with_data(image_bytes); +} +#[test] +#[cfg(target_os = "macos")] +fn test_image_from_file() { + let image = Image::with_contents_of_file("./test-data/favicon.ico"); +} diff --git a/src/lib.rs b/src/lib.rs index decd711..b2293a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,10 +148,10 @@ pub mod keys; pub mod layer; pub mod layout; +pub mod networking; #[cfg(feature = "appkit")] pub mod listview; -pub mod networking; pub mod notification_center; pub(crate) mod objc_access;