From 8ebef12cf50c71cf4b0054fbc4b74cc8c37bc72f Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 4 Dec 2024 07:21:46 -0600 Subject: [PATCH] More tests for interface references --- crates/tests/bindgen/src/lib.rs | 3 +- ...erence_async_action_reference_namespace.rs | 173 ++++++++++++++++++ ... reference_async_action_reference_type.rs} | 0 crates/tools/bindgen/src/main.rs | 5 +- 4 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 crates/tests/bindgen/src/reference_async_action_reference_namespace.rs rename crates/tests/bindgen/src/{reference_async_action_reference.rs => reference_async_action_reference_type.rs} (100%) diff --git a/crates/tests/bindgen/src/lib.rs b/crates/tests/bindgen/src/lib.rs index 82e001b990..e64b6e6398 100644 --- a/crates/tests/bindgen/src/lib.rs +++ b/crates/tests/bindgen/src/lib.rs @@ -60,7 +60,8 @@ pub mod interface_sys_no_core; pub mod multi; pub mod multi_sys; pub mod reference_async_action; -pub mod reference_async_action_reference; +pub mod reference_async_action_reference_namespace; +pub mod reference_async_action_reference_type; pub mod reference_async_info_no_status; pub mod reference_async_info_status_filter; pub mod reference_async_info_status_reference; diff --git a/crates/tests/bindgen/src/reference_async_action_reference_namespace.rs b/crates/tests/bindgen/src/reference_async_action_reference_namespace.rs new file mode 100644 index 0000000000..7ca8c8eae3 --- /dev/null +++ b/crates/tests/bindgen/src/reference_async_action_reference_namespace.rs @@ -0,0 +1,173 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +windows_core::imp::define_interface!( + IAsyncAction, + IAsyncAction_Vtbl, + 0x5a648006_843a_4da9_865b_9d26e5dfad7b +); +impl windows_core::RuntimeType for IAsyncAction { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IAsyncAction, + windows_core::IUnknown, + windows_core::IInspectable +); +windows_core::imp::required_hierarchy!(IAsyncAction, windows::Foundation::IAsyncInfo); +impl IAsyncAction { + pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).SetCompleted)( + windows_core::Interface::as_raw(this), + handler.param().abi(), + ) + .ok() + } + } + pub fn Completed( + &self, + ) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Completed)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn GetResults(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + pub fn Id(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Id)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Status(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Status)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ErrorCode(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ErrorCode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Cancel(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn Close(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)) + .ok() + } + } +} +unsafe impl Send for IAsyncAction {} +unsafe impl Sync for IAsyncAction {} +impl windows_core::RuntimeName for IAsyncAction { + const NAME: &'static str = "Windows.Foundation.IAsyncAction"; +} +pub trait IAsyncAction_Impl: windows::Foundation::IAsyncInfo_Impl { + fn SetCompleted( + &self, + handler: Option<&windows::Foundation::AsyncActionCompletedHandler>, + ) -> windows_core::Result<()>; + fn Completed(&self) -> windows_core::Result; + fn GetResults(&self) -> windows_core::Result<()>; +} +impl IAsyncAction_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn SetCompleted( + this: *mut core::ffi::c_void, + handler: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncAction_Impl::SetCompleted(this, windows_core::from_raw_borrowed(&handler)).into() + } + unsafe extern "system" fn Completed( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IAsyncAction_Impl::Completed(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn GetResults( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncAction_Impl::GetResults(this).into() + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + SetCompleted: SetCompleted::, + Completed: Completed::, + GetResults: GetResults::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IAsyncAction_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub SetCompleted: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Completed: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, +} diff --git a/crates/tests/bindgen/src/reference_async_action_reference.rs b/crates/tests/bindgen/src/reference_async_action_reference_type.rs similarity index 100% rename from crates/tests/bindgen/src/reference_async_action_reference.rs rename to crates/tests/bindgen/src/reference_async_action_reference_type.rs diff --git a/crates/tools/bindgen/src/main.rs b/crates/tools/bindgen/src/main.rs index e5adda9f7f..2f79efdf2f 100644 --- a/crates/tools/bindgen/src/main.rs +++ b/crates/tools/bindgen/src/main.rs @@ -124,9 +124,10 @@ fn main() { // Tests for external references e.g. references to other crates test("--out reference_async_info_no_status.rs --filter IAsyncInfo"); test("--out reference_async_info_status_filter.rs --filter IAsyncInfo AsyncStatus"); - test("--out reference_async_info_status_reference.rs --filter IAsyncInfo --reference windows,skip-root,AsyncStatus"); + test("--out reference_async_info_status_reference.rs --filter IAsyncInfo --reference windows,skip-root,Windows"); test("--out reference_async_action.rs --filter IAsyncAction"); - test("--out reference_async_action_reference.rs --filter IAsyncAction --reference windows,skip-root,IAsyncInfo"); + test("--out reference_async_action_reference_type.rs --filter IAsyncAction --reference windows,skip-root,IAsyncInfo"); + test("--out reference_async_action_reference_namespace.rs --filter IAsyncAction --reference windows,skip-root,Windows"); // Tests for struct references test("--out reference_struct_filter.rs --filter InkTrailPoint");