Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 14, 2025
1 parent 2ec6676 commit 1e4c60c
Show file tree
Hide file tree
Showing 20 changed files with 317 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/tests/bindgen/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#[inline]
pub unsafe fn EnableMouseInPointer(fenable: bool) -> windows_core::Result<()> {
windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : windows::Win32::Foundation:: BOOL) -> windows::Win32::Foundation:: BOOL);
windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : windows_core::BOOL) -> windows_core::BOOL);
unsafe { EnableMouseInPointer(fenable.into()).ok() }
}
6 changes: 3 additions & 3 deletions crates/tests/bindgen/src/bool_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub unsafe fn CreateEventW<P3>(
where
P3: windows_core::Param<windows_core::PCWSTR>,
{
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const windows::Win32::Security:: SECURITY_ATTRIBUTES, bmanualreset : windows::Win32::Foundation:: BOOL, binitialstate : windows::Win32::Foundation:: BOOL, lpname : windows_core::PCWSTR) -> windows::Win32::Foundation:: HANDLE);
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const windows::Win32::Security:: SECURITY_ATTRIBUTES, bmanualreset : windows_core::BOOL, binitialstate : windows_core::BOOL, lpname : windows_core::PCWSTR) -> windows::Win32::Foundation:: HANDLE);
let result__ = unsafe {
CreateEventW(
lpeventattributes.unwrap_or(core::mem::zeroed()) as _,
Expand All @@ -40,7 +40,7 @@ pub unsafe fn NtWaitForSingleObject(
}
#[inline]
pub unsafe fn SetEvent(hevent: windows::Win32::Foundation::HANDLE) -> windows_core::Result<()> {
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : windows::Win32::Foundation:: HANDLE) -> windows::Win32::Foundation:: BOOL);
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : windows::Win32::Foundation:: HANDLE) -> windows_core::BOOL);
unsafe { SetEvent(hevent).ok() }
}
#[inline]
Expand All @@ -49,6 +49,6 @@ pub unsafe fn WaitForSingleObjectEx(
dwmilliseconds: u32,
balertable: bool,
) -> windows::Win32::Foundation::WAIT_EVENT {
windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObjectEx(hhandle : windows::Win32::Foundation:: HANDLE, dwmilliseconds : u32, balertable : windows::Win32::Foundation:: BOOL) -> windows::Win32::Foundation:: WAIT_EVENT);
windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObjectEx(hhandle : windows::Win32::Foundation:: HANDLE, dwmilliseconds : u32, balertable : windows_core::BOOL) -> windows::Win32::Foundation:: WAIT_EVENT);
unsafe { WaitForSingleObjectEx(hhandle, dwmilliseconds, balertable.into()) }
}
97 changes: 97 additions & 0 deletions crates/tests/bindgen/src/bool_event_sans_reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn CreateEventW<P3>(
lpeventattributes: Option<*const SECURITY_ATTRIBUTES>,
bmanualreset: bool,
binitialstate: bool,
lpname: P3,
) -> windows_core::Result<HANDLE>
where
P3: windows_core::Param<windows_core::PCWSTR>,
{
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : windows_core::BOOL, binitialstate : windows_core::BOOL, lpname : windows_core::PCWSTR) -> HANDLE);
let result__ = unsafe {
CreateEventW(
lpeventattributes.unwrap_or(core::mem::zeroed()) as _,
bmanualreset.into(),
binitialstate.into(),
lpname.param().abi(),
)
};
(!result__.is_invalid())
.then_some(result__)
.ok_or_else(windows_core::Error::from_win32)
}
#[inline]
pub unsafe fn NtWaitForSingleObject(
handle: HANDLE,
alertable: bool,
timeout: *mut i64,
) -> NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtWaitForSingleObject(handle : HANDLE, alertable : bool, timeout : *mut i64) -> NTSTATUS);
unsafe { NtWaitForSingleObject(handle, alertable, timeout as _) }
}
#[inline]
pub unsafe fn SetEvent(hevent: HANDLE) -> windows_core::Result<()> {
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> windows_core::BOOL);
unsafe { SetEvent(hevent).ok() }
}
#[inline]
pub unsafe fn WaitForSingleObjectEx(
hhandle: HANDLE,
dwmilliseconds: u32,
balertable: bool,
) -> WAIT_EVENT {
windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObjectEx(hhandle : HANDLE, dwmilliseconds : u32, balertable : windows_core::BOOL) -> WAIT_EVENT);
unsafe { WaitForSingleObjectEx(hhandle, dwmilliseconds, balertable.into()) }
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HANDLE(pub *mut core::ffi::c_void);
impl HANDLE {
pub fn is_invalid(&self) -> bool {
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl windows_core::Free for HANDLE {
#[inline]
unsafe fn free(&mut self) {
if !self.is_invalid() {
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : *mut core::ffi::c_void) -> i32);
unsafe {
CloseHandle(self.0);
}
}
}
}
impl Default for HANDLE {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
#[must_use]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct NTSTATUS(pub i32);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SECURITY_ATTRIBUTES {
pub nLength: u32,
pub lpSecurityDescriptor: *mut core::ffi::c_void,
pub bInheritHandle: windows_core::BOOL,
}
impl Default for SECURITY_ATTRIBUTES {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct WAIT_EVENT(pub u32);
9 changes: 9 additions & 0 deletions crates/tests/bindgen/src/bool_sys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : windows_sys::core::BOOL) -> windows_sys::core::BOOL);
10 changes: 10 additions & 0 deletions crates/tests/bindgen/src/bool_sys_no_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : BOOL) -> BOOL);
pub type BOOL = i32;
130 changes: 130 additions & 0 deletions crates/tests/bindgen/src/delegate_cpp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn EnumWindows(lpenumfunc: WNDENUMPROC, lparam: LPARAM) -> windows_core::Result<()> {
windows_targets::link!("user32.dll" "system" fn EnumWindows(lpenumfunc : WNDENUMPROC, lparam : LPARAM) -> windows_core::BOOL);
unsafe { EnumWindows(lpenumfunc, lparam).ok() }
}
#[inline]
pub unsafe fn GetProcAddress<P1>(hmodule: HMODULE, lpprocname: P1) -> FARPROC
where
P1: windows_core::Param<windows_core::PCSTR>,
{
windows_targets::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : windows_core::PCSTR) -> FARPROC);
unsafe { GetProcAddress(hmodule, lpprocname.param().abi()) }
}
pub type FARPROC = Option<unsafe extern "system" fn() -> isize>;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HANDLE(pub *mut core::ffi::c_void);
impl HANDLE {
pub fn is_invalid(&self) -> bool {
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl windows_core::Free for HANDLE {
#[inline]
unsafe fn free(&mut self) {
if !self.is_invalid() {
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : *mut core::ffi::c_void) -> i32);
unsafe {
CloseHandle(self.0);
}
}
}
}
impl Default for HANDLE {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HINSTANCE(pub *mut core::ffi::c_void);
impl HINSTANCE {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
}
}
impl windows_core::Free for HINSTANCE {
#[inline]
unsafe fn free(&mut self) {
if !self.is_invalid() {
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : *mut core::ffi::c_void) -> i32);
unsafe {
FreeLibrary(self.0);
}
}
}
}
impl Default for HINSTANCE {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
impl windows_core::imp::CanInto<HMODULE> for HINSTANCE {}
impl From<HINSTANCE> for HMODULE {
fn from(value: HINSTANCE) -> Self {
Self(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HMODULE(pub *mut core::ffi::c_void);
impl HMODULE {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
}
}
impl windows_core::Free for HMODULE {
#[inline]
unsafe fn free(&mut self) {
if !self.is_invalid() {
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : *mut core::ffi::c_void) -> i32);
unsafe {
FreeLibrary(self.0);
}
}
}
}
impl Default for HMODULE {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
impl windows_core::imp::CanInto<HINSTANCE> for HMODULE {}
impl From<HMODULE> for HINSTANCE {
fn from(value: HMODULE) -> Self {
Self(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HWND(pub *mut core::ffi::c_void);
impl HWND {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
}
}
impl Default for HWND {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
impl windows_core::imp::CanInto<HANDLE> for HWND {}
impl From<HWND> for HANDLE {
fn from(value: HWND) -> Self {
Self(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct LPARAM(pub isize);
pub type WNDENUMPROC =
Option<unsafe extern "system" fn(param0: HWND, param1: LPARAM) -> windows_core::BOOL>;
3 changes: 1 addition & 2 deletions crates/tests/bindgen/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
clippy::all
)]

windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> BOOL);
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> windows_sys::core::BOOL);
windows_targets::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : windows_sys::core::PCSTR) -> FARPROC);
windows_targets::link!("kernel32.dll" "system" fn LoadLibraryExA(lplibfilename : windows_sys::core::PCSTR, hfile : HANDLE, dwflags : LOAD_LIBRARY_FLAGS) -> HMODULE);
pub type BOOL = i32;
pub type FARPROC = Option<unsafe extern "system" fn() -> isize>;
pub type HANDLE = *mut core::ffi::c_void;
pub type HINSTANCE = *mut core::ffi::c_void;
Expand Down
3 changes: 1 addition & 2 deletions crates/tests/bindgen/src/fn_result_void_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
clippy::all
)]

windows_targets::link!("kernel32.dll" "system" fn SetComputerNameA(lpcomputername : windows_sys::core::PCSTR) -> BOOL);
pub type BOOL = i32;
windows_targets::link!("kernel32.dll" "system" fn SetComputerNameA(lpcomputername : windows_sys::core::PCSTR) -> windows_sys::core::BOOL);
42 changes: 40 additions & 2 deletions crates/tests/bindgen/src/interface_cpp_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ impl IPersistFile {
(windows_core::Interface::vtable(self).IsDirty)(windows_core::Interface::as_raw(self))
}
}
pub unsafe fn Save<P0>(&self, pszfilename: P0, fremember: bool) -> windows_core::Result<()>
where
P0: windows_core::Param<windows_core::PCWSTR>,
{
unsafe {
(windows_core::Interface::vtable(self).Save)(
windows_core::Interface::as_raw(self),
pszfilename.param().abi(),
fremember.into(),
)
.ok()
}
}
pub unsafe fn SaveCompleted<P0>(&self, pszfilename: P0) -> windows_core::Result<()>
where
P0: windows_core::Param<windows_core::PCWSTR>,
Expand Down Expand Up @@ -109,7 +122,11 @@ pub struct IPersistFile_Vtbl {
pub base__: IPersist_Vtbl,
pub IsDirty: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT,
Load: usize,
Save: usize,
pub Save: unsafe extern "system" fn(
*mut core::ffi::c_void,
windows_core::PCWSTR,
windows_core::BOOL,
) -> windows_core::HRESULT,
pub SaveCompleted: unsafe extern "system" fn(
*mut core::ffi::c_void,
windows_core::PCWSTR,
Expand All @@ -121,6 +138,11 @@ pub struct IPersistFile_Vtbl {
}
pub trait IPersistFile_Impl: IPersist_Impl {
fn IsDirty(&self) -> windows_core::HRESULT;
fn Save(
&self,
pszfilename: &windows_core::PCWSTR,
fremember: windows_core::BOOL,
) -> windows_core::Result<()>;
fn SaveCompleted(&self, pszfilename: &windows_core::PCWSTR) -> windows_core::Result<()>;
fn GetCurFile(&self) -> windows_core::Result<windows_core::PWSTR>;
}
Expand All @@ -135,6 +157,22 @@ impl IPersistFile_Vtbl {
IPersistFile_Impl::IsDirty(this)
}
}
unsafe extern "system" fn Save<Identity: IPersistFile_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
pszfilename: windows_core::PCWSTR,
fremember: windows_core::BOOL,
) -> windows_core::HRESULT {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IPersistFile_Impl::Save(
this,
core::mem::transmute(&pszfilename),
core::mem::transmute_copy(&fremember),
)
.into()
}
}
unsafe extern "system" fn SaveCompleted<
Identity: IPersistFile_Impl,
const OFFSET: isize,
Expand Down Expand Up @@ -168,7 +206,7 @@ impl IPersistFile_Vtbl {
base__: IPersist_Vtbl::new::<Identity, OFFSET>(),
IsDirty: IsDirty::<Identity, OFFSET>,
Load: 0,
Save: 0,
Save: Save::<Identity, OFFSET>,
SaveCompleted: SaveCompleted::<Identity, OFFSET>,
GetCurFile: GetCurFile::<Identity, OFFSET>,
}
Expand Down
6 changes: 5 additions & 1 deletion crates/tests/bindgen/src/interface_cpp_derive_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ pub struct IPersistFile_Vtbl {
pub base__: IPersist_Vtbl,
pub IsDirty: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_sys::core::HRESULT,
Load: usize,
Save: usize,
pub Save: unsafe extern "system" fn(
*mut core::ffi::c_void,
windows_sys::core::PCWSTR,
windows_sys::core::BOOL,
) -> windows_sys::core::HRESULT,
pub SaveCompleted: unsafe extern "system" fn(
*mut core::ffi::c_void,
windows_sys::core::PCWSTR,
Expand Down
Loading

0 comments on commit 1e4c60c

Please sign in to comment.