Skip to content

Commit

Permalink
test: ✅ improve test, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Apr 12, 2024
1 parent 99910c3 commit e2859fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ The [`syscall!` macro][syscall-macro] provides a type-safe way to invoke a Windo
### Example

```rust
extern "C" {
pub fn NtClose(Handle: HANDLE) -> NTSTATUS;
}
#![feature(asm_const, maybe_uninit_uninit_array, maybe_uninit_array_assume_init)]
use windows_syscall::syscall;
use phnt::ffi::{NTSTATUS, HANDLE, NtClose, NtTestAlert}; // = "0.0.25"

fn main() {
assert_eq!(syscall!(NtClose(HANDLE::new(0xvalid))), STATUS_SUCCESS);
assert_eq!(syscall!(NtClose(HANDLE::default())), STATUS_INVALID_HANDLE);
const INVALID_HANDLE: HANDLE = core::ptr::null_mut();

assert!(syscall!(NtClose(INVALID_HANDLE)).is_err());
assert!(syscall!(NtTestAlert()).is_ok());
}
```

Expand Down
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,13 @@ mod tests {
}

#[test]
fn basic_succeess() {
assert_eq!(syscall!(NtTestAlert()).0, 0);
}
fn basic() {
const STATUS_INVALID_HANDLE: i32 = 0xC0000008u32 as i32;
const INVALID_HANDLE: *mut std::ffi::c_void = core::ptr::null_mut();
assert_eq!(syscall!(NtClose(INVALID_HANDLE)).0, STATUS_INVALID_HANDLE);

#[test]
fn basic_failure() {
assert_eq!(
syscall!(NtClose(core::ptr::null_mut::<std::ffi::c_void>())).0,
-1073741816i32 /* STATUS_INVALID_HANDLE */
);
const STATUS_SUCCESS: i32 = 0x00000000i32;
assert_eq!(syscall!(NtTestAlert()).0, STATUS_SUCCESS);
}

#[test]
Expand Down

0 comments on commit e2859fe

Please sign in to comment.