Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 26, 2024
1 parent c3e2a76 commit b03be53
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/libs/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub struct Error {
pub(crate) info: Option<crate::imp::IErrorInfo>,
}

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 };
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ features = [
"implement",
"Win32_Foundation",
"Win32_System_WinRT",
"Win32_System_Ole",
"Win32_System_Com",
"Win32_Media_Audio",
]

Expand Down
38 changes: 37 additions & 1 deletion crates/tests/core/tests/error.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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::<IErrorInfo>()?)?;

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(())
}
2 changes: 1 addition & 1 deletion crates/tests/implement/tests/data_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<IUnknown>().is_none());

d.DAdvise(&Default::default(), 0, None)?;

Expand Down

0 comments on commit b03be53

Please sign in to comment.