From ec3495b767d9f6852541c02d9c17889568ef3f51 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Tue, 11 Jun 2024 12:41:52 -0700 Subject: [PATCH] add test coverage for non-Windows platforms --- crates/tests/linux/tests/hresult.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 crates/tests/linux/tests/hresult.rs diff --git a/crates/tests/linux/tests/hresult.rs b/crates/tests/linux/tests/hresult.rs new file mode 100644 index 0000000000..9eef4b7f32 --- /dev/null +++ b/crates/tests/linux/tests/hresult.rs @@ -0,0 +1,34 @@ +// This tests code paths in `windows-result` that are different on non-Windows platforms. +#![cfg(not(windows))] + +use windows::core::Error; +use windows::Win32::Foundation::{E_FAIL, S_OK}; + +#[test] +fn basic_hresult() { + assert!(E_FAIL.is_err()); + assert!(S_OK.is_ok()); + + let ok_message = S_OK.message(); + assert_eq!(ok_message, "0x00000000"); +} + +#[test] +fn error_message_is_not_supported() { + let e = Error::new(S_OK, "this gets ignored"); + let message = e.message(); + assert_eq!(message, "0x00000000"); +} + +#[test] +#[should_panic] +fn from_win32_panics() { + // from_win32() is not implemented on non-Windows platforms. + let _e = Error::from_win32(); +} + +#[test] +fn error_from_hresult() { + let e = Error::from(E_FAIL); + assert_eq!(e.code(), E_FAIL); +}