From cefdabd15e4a7a7f71b7a2d8b12d5dc148c99adb Mon Sep 17 00:00:00 2001 From: kaivol Date: Sun, 7 Jan 2024 15:34:16 +0100 Subject: [PATCH] Fix tests to succeed with non-English UI language (#2776) --- crates/tests/core/Cargo.toml | 3 +++ crates/tests/core/tests/error.rs | 2 ++ crates/tests/core/tests/pcstr.rs | 2 ++ crates/tests/core/tests/pcwstr.rs | 2 ++ crates/tests/core/tests/pstr.rs | 2 ++ crates/tests/core/tests/pwstr.rs | 2 ++ crates/tests/enums/Cargo.toml | 3 +++ crates/tests/enums/tests/win.rs | 2 ++ crates/tests/error/Cargo.toml | 3 +++ crates/tests/error/tests/std.rs | 2 ++ crates/tests/error/tests/trim.rs | 2 ++ 11 files changed, 25 insertions(+) diff --git a/crates/tests/core/Cargo.toml b/crates/tests/core/Cargo.toml index 8f36005f8e..0c105caa45 100644 --- a/crates/tests/core/Cargo.toml +++ b/crates/tests/core/Cargo.toml @@ -15,3 +15,6 @@ features = [ [dependencies.windows-targets] path = "../../libs/targets" + +[dev-dependencies] +helpers = { package = "test_helpers", path = "../helpers" } diff --git a/crates/tests/core/tests/error.rs b/crates/tests/core/tests/error.rs index b9d4385eb6..00d3cb6503 100644 --- a/crates/tests/core/tests/error.rs +++ b/crates/tests/core/tests/error.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*, Win32::Media::Audio::*}; #[test] fn display_debug() { + assert!(helpers::set_thread_ui_language()); + let e = Error::from(ERROR_NO_UNICODE_TRANSLATION); let display = format!("{e}"); let debug = format!("{e:?}"); diff --git a/crates/tests/core/tests/pcstr.rs b/crates/tests/core/tests/pcstr.rs index 9dbaa4fda5..32982cb27f 100644 --- a/crates/tests/core/tests/pcstr.rs +++ b/crates/tests/core/tests/pcstr.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*}; #[test] fn test() -> Result<()> { + assert!(helpers::set_thread_ui_language()); + let p: PCSTR = s!("hello"); let s: String = unsafe { p.to_string()? }; assert_eq!("hello", s); diff --git a/crates/tests/core/tests/pcwstr.rs b/crates/tests/core/tests/pcwstr.rs index c8e6de7ebe..89a9b86730 100644 --- a/crates/tests/core/tests/pcwstr.rs +++ b/crates/tests/core/tests/pcwstr.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*}; #[test] fn test() -> Result<()> { + assert!(helpers::set_thread_ui_language()); + let p: PCWSTR = w!("hello"); let s: String = unsafe { p.to_string()? }; assert_eq!("hello", s); diff --git a/crates/tests/core/tests/pstr.rs b/crates/tests/core/tests/pstr.rs index 876a8956a8..1462968e6b 100644 --- a/crates/tests/core/tests/pstr.rs +++ b/crates/tests/core/tests/pstr.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*}; #[test] fn test() -> Result<()> { + assert!(helpers::set_thread_ui_language()); + let p = PSTR::from_raw(s!("hello").as_ptr() as *mut _); let s: String = unsafe { p.to_string()? }; assert_eq!("hello", s); diff --git a/crates/tests/core/tests/pwstr.rs b/crates/tests/core/tests/pwstr.rs index dcd7cad431..c1c651b08c 100644 --- a/crates/tests/core/tests/pwstr.rs +++ b/crates/tests/core/tests/pwstr.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*}; #[test] fn test() -> Result<()> { + assert!(helpers::set_thread_ui_language()); + let p = PWSTR::from_raw(w!("hello").as_ptr() as *mut _); let s: String = unsafe { p.to_string()? }; assert_eq!("hello", s); diff --git a/crates/tests/enums/Cargo.toml b/crates/tests/enums/Cargo.toml index 4e46d3df9c..be2d0d4cc6 100644 --- a/crates/tests/enums/Cargo.toml +++ b/crates/tests/enums/Cargo.toml @@ -18,3 +18,6 @@ features = [ "Win32_Foundation", "Win32_UI_WindowsAndMessaging", ] + +[dev-dependencies] +helpers = { package = "test_helpers", path = "../helpers" } diff --git a/crates/tests/enums/tests/win.rs b/crates/tests/enums/tests/win.rs index 9072435dbf..cd43cd1fc6 100644 --- a/crates/tests/enums/tests/win.rs +++ b/crates/tests/enums/tests/win.rs @@ -36,6 +36,8 @@ fn const_pattern() { #[test] fn win32_error() { + assert!(helpers::set_thread_ui_language()); + let e: WIN32_ERROR = ERROR_ACCESS_DENIED; assert!(e.0 == 5); let h: HRESULT = ERROR_ACCESS_DENIED.into(); diff --git a/crates/tests/error/Cargo.toml b/crates/tests/error/Cargo.toml index 6d5d9eedc3..d3dfa790d6 100644 --- a/crates/tests/error/Cargo.toml +++ b/crates/tests/error/Cargo.toml @@ -11,3 +11,6 @@ features = [ "Foundation", "Win32_Foundation", ] + +[dev-dependencies] +helpers = { package = "test_helpers", path = "../helpers" } diff --git a/crates/tests/error/tests/std.rs b/crates/tests/error/tests/std.rs index 2568e30360..891c8782f8 100644 --- a/crates/tests/error/tests/std.rs +++ b/crates/tests/error/tests/std.rs @@ -2,6 +2,8 @@ use windows::Win32::Foundation::*; #[test] fn conversions() { + assert!(helpers::set_thread_ui_language()); + // Baseline HRESULT assert_eq!(E_INVALIDARG.message(), "The parameter is incorrect."); assert_eq!(E_INVALIDARG.0, -2147024809); diff --git a/crates/tests/error/tests/trim.rs b/crates/tests/error/tests/trim.rs index 32de1a341a..c6c37d53c9 100644 --- a/crates/tests/error/tests/trim.rs +++ b/crates/tests/error/tests/trim.rs @@ -2,6 +2,8 @@ use windows::{core::*, Win32::Foundation::*}; #[test] fn test() { + assert!(helpers::set_thread_ui_language()); + assert_eq!(E_FAIL.message(), "Unspecified error"); assert_eq!(Error::new(E_FAIL, "Test \t\n\r".into()).message(), "Test");