-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit path support to the
interface
macro (#2976)
- Loading branch information
Showing
5 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#![allow(non_snake_case)] | ||
|
||
// This is a variant of the interface_core/no_use.rs test for use with more complex paths provided by the windows crate. | ||
|
||
#[windows::core::interface("BD1AE5E0-A6AE-11CE-BD37-504200C10000")] | ||
unsafe trait ITestPersistMemory: windows::Win32::System::Com::IPersist { | ||
unsafe fn IsDirty(&self) -> windows::core::HRESULT; | ||
} | ||
|
||
#[windows::core::implement(ITestPersistMemory, windows::Win32::System::Com::IPersist)] | ||
struct Test; | ||
|
||
impl windows::Win32::System::Com::IPersist_Impl for Test { | ||
fn GetClassID(&self) -> windows::core::Result<windows::core::GUID> { | ||
Ok("CEE1D356-0860-4262-90D4-C77423F0E352".into()) | ||
} | ||
} | ||
|
||
impl ITestPersistMemory_Impl for Test { | ||
unsafe fn IsDirty(&self) -> windows::core::HRESULT { | ||
windows::Win32::Foundation::S_FALSE | ||
} | ||
} | ||
|
||
#[test] | ||
fn test() -> windows::core::Result<()> { | ||
unsafe { | ||
let p: windows::Win32::System::Com::IPersist = Test.into(); | ||
assert_eq!( | ||
p.GetClassID()?, | ||
"CEE1D356-0860-4262-90D4-C77423F0E352".into() | ||
); | ||
|
||
let m: ITestPersistMemory = windows_core::Interface::cast(&p)?; | ||
assert_eq!(m.IsDirty(), windows::Win32::Foundation::S_FALSE); | ||
|
||
Ok(()) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/tests/interface_core/tests/test.rs → ...ests/interface_core/tests/asterisk_use.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![allow(non_snake_case)] | ||
|
||
// This tests uses `windows_core` explicitly to test that the interface/implement macros support this mode | ||
// as opposed to asterisk_use.rs which tests the opposite. | ||
|
||
#[windows_core::interface("72cd87fa-9c99-42e0-8986-84a76f08fc5a")] | ||
unsafe trait ITest: windows_core::IUnknown { | ||
unsafe fn Test(&self) -> windows_core::HRESULT; | ||
} | ||
|
||
#[windows_core::implement(ITest)] | ||
struct Test; | ||
|
||
impl ITest_Impl for Test { | ||
unsafe fn Test(&self) -> windows_core::HRESULT { | ||
windows_core::HRESULT(123) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
unsafe { | ||
let test: ITest = Test.into(); | ||
assert_eq!(test.Test(), windows_core::HRESULT(123)); | ||
} | ||
} |