From b03be53f02cf1f7fe88a22a31382254b26f2159a Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 26 Jan 2024 14:52:12 -0600 Subject: [PATCH] tests --- crates/libs/core/src/error.rs | 3 ++ crates/tests/core/Cargo.toml | 2 ++ crates/tests/core/tests/error.rs | 38 ++++++++++++++++++++- crates/tests/implement/tests/data_object.rs | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/crates/libs/core/src/error.rs b/crates/libs/core/src/error.rs index c4d30f446a..ef798193ff 100644 --- a/crates/libs/core/src/error.rs +++ b/crates/libs/core/src/error.rs @@ -9,6 +9,9 @@ pub struct Error { pub(crate) info: Option, } +unsafe impl Send for Error {} +unsafe impl Sync for Error {} + impl Error { /// An error object without any failure information. pub const OK: Self = Self { code: HRESULT(0), info: None }; diff --git a/crates/tests/core/Cargo.toml b/crates/tests/core/Cargo.toml index 0c105caa45..1cedb18ed3 100644 --- a/crates/tests/core/Cargo.toml +++ b/crates/tests/core/Cargo.toml @@ -10,6 +10,8 @@ features = [ "implement", "Win32_Foundation", "Win32_System_WinRT", + "Win32_System_Ole", + "Win32_System_Com", "Win32_Media_Audio", ] diff --git a/crates/tests/core/tests/error.rs b/crates/tests/core/tests/error.rs index 00d3cb6503..baa5ad44a1 100644 --- a/crates/tests/core/tests/error.rs +++ b/crates/tests/core/tests/error.rs @@ -1,4 +1,7 @@ -use windows::{core::*, Win32::Foundation::*, Win32::Media::Audio::*}; +use windows::{ + core::*, Win32::Foundation::*, Win32::Media::Audio::*, Win32::System::Com::*, + Win32::System::Ole::*, Win32::System::WinRT::*, +}; #[test] fn display_debug() { @@ -29,3 +32,36 @@ fn hresult_last_error() { assert_eq!(e.code(), CRYPT_E_NOT_FOUND); } } + +// Checks that non-restricted error info is reported. +#[test] +fn set_error_info() -> Result<()> { + unsafe { + let creator = CreateErrorInfo()?; + creator.SetDescription(w!("message"))?; + SetErrorInfo(0, &creator.cast::()?)?; + + assert_eq!(Error::from(E_FAIL).message(), "message"); + SetErrorInfo(0, None)?; + assert_eq!(Error::from(E_FAIL).message(), "Unspecified error"); + + Ok(()) + } +} + +// https://github.com/microsoft/cppwinrt/pull/1386 +#[test] +fn suppressed_error_info() -> Result<()> { + unsafe { RoSetErrorReportingFlags(RO_ERROR_REPORTING_SUPPRESSSETERRORINFO.0 as u32)? }; + + assert_eq!( + Error::new(E_FAIL, "message".into()).message(), + "Unspecified error" + ); + + unsafe { RoSetErrorReportingFlags(RO_ERROR_REPORTING_USESETERRORINFO.0 as u32)? }; + + assert_eq!(Error::new(E_FAIL, "message".into()).message(), "message"); + + Ok(()) +} diff --git a/crates/tests/implement/tests/data_object.rs b/crates/tests/implement/tests/data_object.rs index 6c7ea48636..8d28433f9d 100644 --- a/crates/tests/implement/tests/data_object.rs +++ b/crates/tests/implement/tests/data_object.rs @@ -100,7 +100,7 @@ fn test() -> Result<()> { assert!(r.is_err()); let e = r.unwrap_err(); assert!(e.code() == S_OK); - assert!(e.info().is_none()); + assert!(e.info::().is_none()); d.DAdvise(&Default::default(), 0, None)?;