-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve core string type testing (#2074)
- Loading branch information
Showing
7 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use windows::{core::*, Win32::Foundation::*}; | ||
|
||
#[test] | ||
fn test() -> Result<()> { | ||
let p: PCSTR = s!("hello"); | ||
let s: String = unsafe { p.to_string()? }; | ||
assert_eq!("hello", s); | ||
assert_eq!("hello", format!("{}", unsafe { p.display() })); | ||
|
||
let invalid = &[0xc0, 0x80]; | ||
let p = PCSTR::from_raw(invalid.as_ptr()); | ||
let e: Error = unsafe { p.to_string().unwrap_err().into() }; | ||
assert_eq!(e.code(), ERROR_NO_UNICODE_TRANSLATION.into()); | ||
assert_eq!(e.message(), "No mapping for the Unicode character exists in the target multi-byte code page."); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use windows::{core::*, Win32::Foundation::*}; | ||
|
||
#[test] | ||
fn test() -> Result<()> { | ||
// `w!` returns a `&HSTRING` so `into()` is needed to convert it to a `PCWSTR` | ||
let p: PCWSTR = w!("hello").into(); | ||
let s: String = unsafe { p.to_string()? }; | ||
assert_eq!("hello", s); | ||
assert_eq!("hello", format!("{}", unsafe { p.display() })); | ||
|
||
let invalid = &[0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063]; | ||
let p = PCWSTR::from_raw(invalid.as_ptr()); | ||
let e: Error = unsafe { p.to_string().unwrap_err().into() }; | ||
assert_eq!(e.code(), ERROR_NO_UNICODE_TRANSLATION.into()); | ||
assert_eq!(e.message(), "No mapping for the Unicode character exists in the target multi-byte code page."); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use windows::{core::*, Win32::Foundation::*}; | ||
|
||
#[test] | ||
fn test() -> Result<()> { | ||
let p = PSTR::from_raw(s!("hello").as_ptr() as *mut _); | ||
let s: String = unsafe { p.to_string()? }; | ||
assert_eq!("hello", s); | ||
assert_eq!("hello", format!("{}", unsafe { p.display() })); | ||
|
||
let invalid = &mut [0xc0, 0x80]; | ||
let p = PSTR::from_raw(invalid.as_mut_ptr()); | ||
let e: Error = unsafe { p.to_string().unwrap_err().into() }; | ||
assert_eq!(e.code(), ERROR_NO_UNICODE_TRANSLATION.into()); | ||
assert_eq!(e.message(), "No mapping for the Unicode character exists in the target multi-byte code page."); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use windows::{core::*, Win32::Foundation::*}; | ||
|
||
#[test] | ||
fn test() -> Result<()> { | ||
let p = PWSTR::from_raw(w!("hello").as_ptr() as *mut _); | ||
let s: String = unsafe { p.to_string()? }; | ||
assert_eq!("hello", s); | ||
assert_eq!("hello", format!("{}", unsafe { p.display() })); | ||
|
||
let invalid = &mut [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063]; | ||
let p = PWSTR::from_raw(invalid.as_mut_ptr()); | ||
let e: Error = unsafe { p.to_string().unwrap_err().into() }; | ||
assert_eq!(e.code(), ERROR_NO_UNICODE_TRANSLATION.into()); | ||
assert_eq!(e.message(), "No mapping for the Unicode character exists in the target multi-byte code page."); | ||
|
||
Ok(()) | ||
} |