Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jun 18, 2024
1 parent 70ef5dd commit c898d58
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 52 deletions.
1 change: 1 addition & 0 deletions crates/tests/handles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ features = [
"Win32_System_Registry",
"Win32_Devices_Bluetooth",
"Win32_System_ApplicationInstallationAndServicing",
"Win32_Security",
]

[dependencies.windows-sys]
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/handles/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use windows::Win32::System::Registry::*;

#[test]
fn handle() {
let handle = HANDLE(0);
let handle = HANDLE(0 as _);
let _clone = handle.clone();
let _copy: HANDLE = handle;
assert!(HANDLE::default() == HANDLE(0));
assert!(HANDLE(0).is_invalid());
assert!(HANDLE(-1).is_invalid());
assert!(HANDLE::default() == HANDLE(0 as _));
assert!(HANDLE(0 as _).is_invalid());
assert!(HANDLE(-1 as _).is_invalid());

assert!(core::mem::size_of::<HANDLE>() == core::mem::size_of::<usize>());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/handles/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn boolean() {
fn hfont() {
unsafe {
let underlying: isize = 123;
let font: HFONT = underlying;
let font: HFONT = underlying as _;
let object: HGDIOBJ = font;

assert!(DeleteObject(font) == 0);
Expand Down
9 changes: 5 additions & 4 deletions crates/tests/handles/tests/win.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use windows::{
Win32::Devices::Bluetooth::*, Win32::Foundation::*, Win32::Graphics::Gdi::*,
Win32::System::ApplicationInstallationAndServicing::*, Win32::System::Registry::*,
Win32::Security::*, Win32::System::ApplicationInstallationAndServicing::*,
Win32::System::Registry::*,
};

#[test]
fn handle() {
let underlying: isize = 123;
let handle: HANDLE = HANDLE(underlying);
let handle: HANDLE = HANDLE(underlying as _);
assert!(!handle.is_invalid());

let copy = handle;
Expand All @@ -18,7 +19,7 @@ fn handle() {
let default = HANDLE::default();
assert!(default.is_invalid());

assert_eq!(format!("{:?}", handle), "HANDLE(123)");
assert_eq!(format!("{:?}", handle), "HANDLE(0x7b)");
}

#[test]
Expand All @@ -43,7 +44,7 @@ fn psid() {
fn hfont() {
unsafe {
let underlying: isize = 123;
let font: HFONT = HFONT(underlying);
let font: HFONT = HFONT(underlying as _);
let object: HGDIOBJ = HGDIOBJ(font.0);

assert!(!DeleteObject(font).as_bool());
Expand Down
24 changes: 22 additions & 2 deletions crates/tests/lib/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ use windows_sys::{
#[test]
fn gdi() {
unsafe {
AlphaBlend(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, std::mem::zeroed());
AlphaBlend(
core::ptr::null_mut(),
0,
0,
0,
0,
core::ptr::null_mut(),
0,
0,
0,
0,
std::mem::zeroed(),
);
}
}

Expand All @@ -20,7 +32,15 @@ fn wait_on_address() {
#[test]
fn browser() {
unsafe {
IECreateFile(std::ptr::null(), 0, 0, std::ptr::null(), 0, 0, 0);
IECreateFile(
std::ptr::null(),
0,
0,
std::ptr::null(),
0,
0,
core::ptr::null_mut(),
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tests/not_dll/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ use windows_sys::Win32::Graphics::Printing::*;
#[test]
fn test() {
unsafe {
GetSpoolFileHandle(0);
GetSpoolFileHandle(core::ptr::null_mut());
}
}
12 changes: 10 additions & 2 deletions crates/tests/reserved/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ fn test() {
assert_eq!(InSendMessageEx(std::ptr::null_mut()), ISMEX_NOSEND);
assert!(CreateThreadpool(std::ptr::null_mut()) != 0);
assert_eq!(
TrackPopupMenu(0, TPM_LEFTBUTTON, 1, 2, 0, 0, std::ptr::null()),
TrackPopupMenu(
core::ptr::null_mut(),
TPM_LEFTBUTTON,
1,
2,
0,
core::ptr::null_mut(),
std::ptr::null()
),
0
);

let mut key = 0;
let mut key = core::ptr::null_mut();
RegOpenKeyExA(HKEY_CLASSES_ROOT, s!(r".txt"), 0, KEY_QUERY_VALUE, &mut key);
let mut len = 0;
RegQueryValueExA(
Expand Down
12 changes: 2 additions & 10 deletions crates/tests/reserved/tests/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ use windows::{
fn test() -> Result<()> {
unsafe {
assert_eq!(InSendMessageEx(None), ISMEX_NOSEND);
assert!(CreateThreadpool(None).0 != 0);
assert!(CreateThreadpool(None).is_ok());

assert_eq!(
TrackPopupMenu(
HMENU(0),
TPM_LEFTBUTTON,
1,
2,
0,
HWND(0),
Default::default(),
),
TrackPopupMenu(None, TPM_LEFTBUTTON, 1, 2, 0, None, Default::default(),),
FALSE
);

Expand Down
10 changes: 8 additions & 2 deletions crates/tests/resources/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ fn sys() {
unsafe {
SetLastError(0);
assert_eq!(IDI_APPLICATION as u16, 32512);
assert_ne!(LoadIconW(0, IDI_APPLICATION), 0);
assert_ne!(
LoadIconW(core::ptr::null_mut(), IDI_APPLICATION),
core::ptr::null_mut()
);
assert_eq!(GetLastError(), 0);

assert_eq!(TD_ERROR_ICON as i16, -2);
assert_eq!(LoadIconW(0, TD_ERROR_ICON), 0);
assert_eq!(
LoadIconW(core::ptr::null_mut(), TD_ERROR_ICON),
core::ptr::null_mut()
);
assert_eq!(GetLastError(), ERROR_RESOURCE_TYPE_NOT_FOUND);

assert_eq!(COLE_DEFAULT_PRINCIPAL as usize, usize::MAX);
Expand Down
6 changes: 3 additions & 3 deletions crates/tests/sys/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ fn types() {
let _: i32 = DBG_APP_NOT_IDLE;

// Handles
let _: HANDLE = 0;
let _: HANDLE = core::ptr::null_mut();
let _: PSTR = b"hello\0".as_ptr() as _;
}

#[test]
fn callback() {
unsafe {
extern "system" fn enum_window(_: isize, _: isize) -> i32 {
extern "system" fn enum_window(_: *mut core::ffi::c_void, _: isize) -> i32 {
0
}

EnumWindows(Some(enum_window), 0);

extern "system" fn wndproc(_: isize, _: u32, _: usize, _: isize) -> isize {
extern "system" fn wndproc(_: *mut core::ffi::c_void, _: u32, _: usize, _: isize) -> isize {
0
}

Expand Down
8 changes: 4 additions & 4 deletions crates/tests/unions/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn test() {
Internal: 1,
InternalHigh: 2,
Anonymous: unsafe { std::mem::zeroed() },
hEvent: Default::default(),
hEvent: core::ptr::null_mut(),
};

assert_eq!(o.Internal, 1);
Expand All @@ -17,9 +17,9 @@ fn test() {
o.InternalHigh = 20;
assert_eq!(o.InternalHigh, 20);

assert_eq!(o.hEvent, 0);
o.hEvent = 1;
assert_eq!(o.hEvent, 1);
assert_eq!(o.hEvent, core::ptr::null_mut());
o.hEvent = 1 as _;
assert_eq!(o.hEvent, 1 as _);

unsafe {
assert_eq!(o.Anonymous.Pointer, core::ptr::null_mut());
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/unions/tests/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fn test() {
o.InternalHigh = 20;
assert_eq!(o.InternalHigh, 20);

assert_eq!(o.hEvent, HANDLE(0));
o.hEvent = HANDLE(1);
assert_eq!(o.hEvent, HANDLE(1));
assert_eq!(o.hEvent, HANDLE(0 as _));
o.hEvent = HANDLE(1 as _);
assert_eq!(o.hEvent, HANDLE(1 as _));

unsafe {
assert_eq!(o.Anonymous.Pointer, core::ptr::null_mut());
Expand Down Expand Up @@ -80,7 +80,7 @@ fn d3d() {
let mut desc = D3D12_INDIRECT_ARGUMENT_DESC {
Type: D3D12_INDIRECT_ARGUMENT_TYPE_VERTEX_BUFFER_VIEW,
Anonymous: D3D12_INDIRECT_ARGUMENT_DESC_0 {
VertexBuffer: D3D12_INDIRECT_ARGUMENT_DESC_0_4 { Slot: 123 },
VertexBuffer: D3D12_INDIRECT_ARGUMENT_DESC_0_5 { Slot: 123 },
},
};

Expand Down
2 changes: 1 addition & 1 deletion crates/tests/wdk/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use windows_sys::Wdk::System::OfflineRegistry::*;
#[test]
fn offline_registry() {
unsafe {
let mut hive = 0;
let mut hive = core::ptr::null_mut();
ORCreateHive(&mut hive);
ORCloseHive(hive);
}
Expand Down
22 changes: 12 additions & 10 deletions crates/tests/win32/tests/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn function() -> windows::core::Result<()> {
fn bool_as_error() {
unsafe {
helpers::set_thread_ui_language();
let error = SetEvent(HANDLE(0)).unwrap_err();
let error = SetEvent(HANDLE(0 as _)).unwrap_err();

assert_eq!(error.code(), windows::core::HRESULT(-2147024890));
let message: String = error.message().try_into().unwrap();
Expand Down Expand Up @@ -176,7 +176,9 @@ fn com_inheritance() {
let factory: IDXGIFactory7 = CreateDXGIFactory1().unwrap();

// IDXGIFactory
assert!(factory.MakeWindowAssociation(HWND(0), 0).is_ok());
assert!(factory
.MakeWindowAssociation(None, DXGI_MWA_FLAGS::default())
.is_ok());

// IDXGIFactory1
assert!(factory.IsCurrent().as_bool());
Expand All @@ -185,12 +187,12 @@ fn com_inheritance() {
_ = factory.IsWindowedStereoEnabled();

// IDXGIFactory3
assert!(factory.GetCreationFlags() == 0);
assert!(factory.GetCreationFlags() == DXGI_CREATE_FACTORY_FLAGS(0));

// IDXGIFactory7 (default)
assert!(
factory
.RegisterAdaptersChangedEvent(HANDLE(0))
.RegisterAdaptersChangedEvent(None)
.unwrap_err()
.code()
== DXGI_ERROR_INVALID_CALL
Expand Down Expand Up @@ -232,25 +234,25 @@ fn interface() -> windows::core::Result<()> {
fn callback() {
unsafe {
let a: PROPENUMPROCA = Some(callback_a);
assert!(BOOL(789) == a.unwrap()(HWND(123), s!("hello a"), HANDLE(456)));
assert!(BOOL(789) == a.unwrap()(HWND(123 as _), s!("hello a"), HANDLE(456 as _)));

let a: PROPENUMPROCW = Some(callback_w);
assert!(BOOL(789) == a.unwrap()(HWND(123), w!("hello w").into(), HANDLE(456)));
assert!(BOOL(789) == a.unwrap()(HWND(123 as _), w!("hello w").into(), HANDLE(456 as _)));
}
}

extern "system" fn callback_a(param0: HWND, param1: PCSTR, param2: HANDLE) -> BOOL {
assert!(param0.0 == 123);
assert!(param2.0 == 456);
assert!(param0.0 == 123 as _);
assert!(param2.0 == 456 as _);

let s = unsafe { param1.to_string().unwrap() };
assert!(s == "hello a");
BOOL(789)
}

extern "system" fn callback_w(param0: HWND, param1: PCWSTR, param2: HANDLE) -> BOOL {
assert!(param0.0 == 123);
assert!(param2.0 == 456);
assert!(param0.0 == 123 as _);
assert!(param2.0 == 456 as _);
let s = unsafe { param1.to_string().unwrap() };
assert!(s == "hello w");
BOOL(789)
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/window_long/tests/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use windows_sys::Win32::UI::WindowsAndMessaging::*;
#[test]
fn test() {
unsafe {
SetWindowLongPtrA(0, GWLP_USERDATA, 0);
GetWindowLongPtrA(0, GWLP_USERDATA);
SetWindowLongPtrW(0, GWLP_USERDATA, 0);
GetWindowLongPtrW(0, GWLP_USERDATA);
SetWindowLongPtrA(core::ptr::null_mut(), GWLP_USERDATA, 0);
GetWindowLongPtrA(core::ptr::null_mut(), GWLP_USERDATA);
SetWindowLongPtrW(core::ptr::null_mut(), GWLP_USERDATA, 0);
GetWindowLongPtrW(core::ptr::null_mut(), GWLP_USERDATA);
}
}

0 comments on commit c898d58

Please sign in to comment.