Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Feb 16, 2024
1 parent 7011478 commit 9805615
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/tests/result/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use windows_result::*;
const S_OK: HRESULT = HRESULT(0);
const E_INVALIDARG: HRESULT = HRESULT(-2147024809i32);
const ERROR_CANCELLED: u32 = 1223;
const ERROR_INVALID_DATA: u32 = 13;
const E_CANCELLED: HRESULT = HRESULT::from_win32(ERROR_CANCELLED);

windows_targets::link!("kernel32.dll" "system" fn SetLastError(code: u32));
Expand Down Expand Up @@ -49,3 +50,15 @@ fn from_win32() {
assert!(e.as_ptr().is_null());
assert_eq!(e.code(), E_CANCELLED);
}

#[test]
fn try_from_int() {
fn call(value: usize) -> Result<u32> {
Ok(value.try_into()?)
}

assert_eq!(call(123), Ok(123));

let e = call(usize::MAX).unwrap_err();
assert_eq!(e.code(), HRESULT::from_win32(ERROR_INVALID_DATA));
}

0 comments on commit 9805615

Please sign in to comment.