Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 20, 2024
1 parent e806024 commit 49cda87
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/tests/class_hierarchy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_class_hierarchy"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
doc = false
doctest = false

[dependencies.windows]
path = "../../libs/windows"
features = [
"Foundation",
]
1 change: 1 addition & 0 deletions crates/tests/class_hierarchy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

38 changes: 38 additions & 0 deletions crates/tests/class_hierarchy/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use windows::{core::*, Foundation::*};

#[test]
fn test() -> Result<()> {
let class: MemoryBuffer = MemoryBuffer::Create(10)?;

call_class(&class)?;
call_interface((&class).into())?;
as_class(&class)?;
as_interface(&class)?;

// `IMemoryBuffer` is `MemoryBuffer`'s default interface, even though it is not an exclusive interface.
// So this `into` cast should succeed without requiring a call to `QueryInterface`.
let interface: IMemoryBuffer = class.into();

call_interface(&interface)?;
as_interface(&interface)?;

Ok(())
}

fn call_class(b: &MemoryBuffer) -> Result<()> {
assert_eq!(10, b.CreateReference()?.Capacity()?);
Ok(())
}

fn call_interface(b: &IMemoryBuffer) -> Result<()> {
assert_eq!(10, b.CreateReference()?.Capacity()?);
Ok(())
}

fn as_class<P: Param<MemoryBuffer>>(b: P) -> Result<()> {
unsafe { call_class(&b.param().borrow().as_ref().unwrap()) }
}

fn as_interface<P: Param<IMemoryBuffer>>(b: P) -> Result<()> {
unsafe { call_interface(&b.param().borrow().as_ref().unwrap()) }
}

0 comments on commit 49cda87

Please sign in to comment.