Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Feb 27, 2024
1 parent cbe82ae commit c5b36f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/tests/variant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ path = "../../libs/windows"
features = [
"Foundation",
"Win32_Foundation",
"Win32_System_Com_Events",
]
33 changes: 32 additions & 1 deletion crates/tests/variant/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use windows::Foundation::Uri;
use windows::Win32::Foundation::TYPE_E_TYPEMISMATCH;
use windows::Win32::Foundation::{E_INVALIDARG, TYPE_E_TYPEMISMATCH};
use windows::Win32::System::Com;
use windows_core::*;

#[test]
fn test_variant() -> Result<()> {
unsafe { Com::CoIncrementMTAUsage()? };

let empty: VARIANT = VARIANT::new();
assert!(empty.is_empty());

Expand Down Expand Up @@ -83,6 +86,19 @@ fn test_variant() -> Result<()> {
TYPE_E_TYPEMISMATCH
);

let dispatch: Com::IDispatch =
unsafe { Com::CoCreateInstance(&Com::Events::CEventSystem, None, Com::CLSCTX_ALL)? };
let v = VARIANT::from(dispatch);
let dispatch = Com::IDispatch::try_from(&v)?;
dispatch.cast::<Com::Events::IEventSystem>()?;
assert_eq!(i32::try_from(&v).unwrap_err().code(), E_INVALIDARG);
assert_eq!(
Com::IDispatch::try_from(&VARIANT::from(3.5f64))
.unwrap_err()
.code(),
TYPE_E_TYPEMISMATCH
);

let v = VARIANT::from(BSTR::from("hello"));
assert_eq!(BSTR::try_from(&v)?, "hello");
assert_eq!(
Expand Down Expand Up @@ -115,6 +131,8 @@ fn test_variant() -> Result<()> {

#[test]
fn test_propvariant() -> Result<()> {
unsafe { Com::CoIncrementMTAUsage()? };

let empty: PROPVARIANT = PROPVARIANT::new();
assert!(empty.is_empty());

Expand Down Expand Up @@ -200,6 +218,19 @@ fn test_propvariant() -> Result<()> {
TYPE_E_TYPEMISMATCH
);

let dispatch: Com::IDispatch =
unsafe { Com::CoCreateInstance(&Com::Events::CEventSystem, None, Com::CLSCTX_ALL)? };
let v = PROPVARIANT::from(dispatch);
let dispatch = Com::IDispatch::try_from(&v)?;
dispatch.cast::<Com::Events::IEventSystem>()?;
assert_eq!(i32::try_from(&v).unwrap_err().code(), E_INVALIDARG);
assert_eq!(
Com::IDispatch::try_from(&PROPVARIANT::from(3.5f64))
.unwrap_err()
.code(),
TYPE_E_TYPEMISMATCH
);

let v = PROPVARIANT::from(BSTR::from("hello"));
assert_eq!(BSTR::try_from(&v)?, "hello");
assert_eq!(
Expand Down

0 comments on commit c5b36f6

Please sign in to comment.