Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 11, 2024
1 parent fc38e08 commit 4a4f632
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 7 deletions.
26 changes: 24 additions & 2 deletions crates/tests/bindgen/src/reference_dependency_flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ impl IMemoryBufferReference {
.map(|| result__)
}
}
pub fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).RemoveClosed)(
windows_core::Interface::as_raw(this),
cookie,
)
.ok()
}
}
pub fn Close(&self) -> windows_core::Result<()> {
let this = &windows_core::Interface::cast::<IClosable>(self)?;
unsafe {
Expand All @@ -97,6 +107,7 @@ impl windows_core::RuntimeName for IMemoryBufferReference {
}
pub trait IMemoryBufferReference_Impl: IClosable_Impl {
fn Capacity(&self) -> windows_core::Result<u32>;
fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()>;
}
impl IMemoryBufferReference_Vtbl {
pub const fn new<Identity: IMemoryBufferReference_Impl, const OFFSET: isize>() -> Self {
Expand All @@ -116,12 +127,22 @@ impl IMemoryBufferReference_Vtbl {
Err(err) => err.into(),
}
}
unsafe extern "system" fn RemoveClosed<
Identity: IMemoryBufferReference_Impl,
const OFFSET: isize,
>(
this: *mut core::ffi::c_void,
cookie: i64,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
IMemoryBufferReference_Impl::RemoveClosed(this, cookie).into()
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<Identity, IMemoryBufferReference, OFFSET>(
),
Capacity: Capacity::<Identity, OFFSET>,
add_Closed: 0,
remove_Closed: 0,
RemoveClosed: RemoveClosed::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
Expand All @@ -134,5 +155,6 @@ pub struct IMemoryBufferReference_Vtbl {
pub Capacity:
unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT,
add_Closed: usize,
remove_Closed: usize,
pub RemoveClosed:
unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT,
}
27 changes: 25 additions & 2 deletions crates/tests/bindgen/src/reference_dependency_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub mod Windows {
.map(|| result__)
}
}
pub fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).RemoveClosed)(
windows_core::Interface::as_raw(this),
cookie,
)
.ok()
}
}
pub fn Close(&self) -> windows_core::Result<()> {
let this = &windows_core::Interface::cast::<IClosable>(self)?;
unsafe {
Expand All @@ -104,6 +114,7 @@ pub mod Windows {
}
pub trait IMemoryBufferReference_Impl: IClosable_Impl {
fn Capacity(&self) -> windows_core::Result<u32>;
fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()>;
}
impl IMemoryBufferReference_Vtbl {
pub const fn new<Identity: IMemoryBufferReference_Impl, const OFFSET: isize>() -> Self {
Expand All @@ -124,6 +135,17 @@ pub mod Windows {
Err(err) => err.into(),
}
}
unsafe extern "system" fn RemoveClosed<
Identity: IMemoryBufferReference_Impl,
const OFFSET: isize,
>(
this: *mut core::ffi::c_void,
cookie: i64,
) -> windows_core::HRESULT {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IMemoryBufferReference_Impl::RemoveClosed(this, cookie).into()
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<
Identity,
Expand All @@ -132,7 +154,7 @@ pub mod Windows {
>(),
Capacity: Capacity::<Identity, OFFSET>,
add_Closed: 0,
remove_Closed: 0,
RemoveClosed: RemoveClosed::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
Expand All @@ -147,7 +169,8 @@ pub mod Windows {
*mut u32,
) -> windows_core::HRESULT,
add_Closed: usize,
remove_Closed: usize,
pub RemoveClosed:
unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT,
}
}
}
27 changes: 25 additions & 2 deletions crates/tests/bindgen/src/reference_dependency_skip_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub mod Windows {
.map(|| result__)
}
}
pub fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).RemoveClosed)(
windows_core::Interface::as_raw(this),
cookie,
)
.ok()
}
}
pub fn Close(&self) -> windows_core::Result<()> {
let this = &windows_core::Interface::cast::<IClosable>(self)?;
unsafe {
Expand All @@ -104,6 +114,7 @@ pub mod Windows {
}
pub trait IMemoryBufferReference_Impl: IClosable_Impl {
fn Capacity(&self) -> windows_core::Result<u32>;
fn RemoveClosed(&self, cookie: i64) -> windows_core::Result<()>;
}
impl IMemoryBufferReference_Vtbl {
pub const fn new<Identity: IMemoryBufferReference_Impl, const OFFSET: isize>() -> Self {
Expand All @@ -124,6 +135,17 @@ pub mod Windows {
Err(err) => err.into(),
}
}
unsafe extern "system" fn RemoveClosed<
Identity: IMemoryBufferReference_Impl,
const OFFSET: isize,
>(
this: *mut core::ffi::c_void,
cookie: i64,
) -> windows_core::HRESULT {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IMemoryBufferReference_Impl::RemoveClosed(this, cookie).into()
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<
Identity,
Expand All @@ -132,7 +154,7 @@ pub mod Windows {
>(),
Capacity: Capacity::<Identity, OFFSET>,
add_Closed: 0,
remove_Closed: 0,
RemoveClosed: RemoveClosed::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
Expand All @@ -147,7 +169,8 @@ pub mod Windows {
*mut u32,
) -> windows_core::HRESULT,
add_Closed: usize,
remove_Closed: usize,
pub RemoveClosed:
unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "test_event"
name = "test_event_core"
version = "0.0.0"
edition = "2021"
publish = false
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions crates/tests/winrt/events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "test_events"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doc = false
doctest = false

[build-dependencies.windows-bindgen]
workspace = true

[dependencies.windows-core]
workspace = true

[dependencies.windows]
workspace = true
features = [
"Foundation",
"Win32_System_WinRT",
]
37 changes: 37 additions & 0 deletions crates/tests/winrt/events/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
fn main() {
println!("cargo:rerun-if-changed=src/metadata.idl");

let mut command = std::process::Command::new("midlrt.exe");
command.args([
"/winrt",
"/nomidl",
"/h",
"nul",
"/metadata_dir",
"../../../libs/bindgen/default",
"/reference",
"../../../libs/bindgen/default/Windows.winmd",
"/winmd",
"metadata.winmd",
"src/metadata.idl",
]);

if !command.status().unwrap().success() {
panic!("Failed to run midlrt");
}

windows_bindgen::bindgen([
"--in",
"metadata.winmd",
"../../../libs/bindgen/default",
"--out",
"src/bindings.rs",
"--filter",
"test_events",
"--implement",
"--no-comment",
"--flat",
"--reference",
"windows,skip-root,Windows",
]);
}
Loading

0 comments on commit 4a4f632

Please sign in to comment.