Skip to content

Commit

Permalink
Fix tests to succeed with non-English UI language (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaivol authored Jan 7, 2024
1 parent a4a2241 commit cefdabd
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/tests/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ features = [

[dependencies.windows-targets]
path = "../../libs/targets"

[dev-dependencies]
helpers = { package = "test_helpers", path = "../helpers" }
2 changes: 2 additions & 0 deletions crates/tests/core/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/core/tests/pcstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/core/tests/pcwstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/core/tests/pstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/core/tests/pwstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ features = [
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging",
]

[dev-dependencies]
helpers = { package = "test_helpers", path = "../helpers" }
2 changes: 2 additions & 0 deletions crates/tests/enums/tests/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ features = [
"Foundation",
"Win32_Foundation",
]

[dev-dependencies]
helpers = { package = "test_helpers", path = "../helpers" }
2 changes: 2 additions & 0 deletions crates/tests/error/tests/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/error/tests/trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit cefdabd

Please sign in to comment.