Skip to content

Commit

Permalink
Add tests and fix parentheses+casting.
Browse files Browse the repository at this point in the history
  • Loading branch information
NateD-MSFT committed Jul 18, 2024
1 parent 274ac9e commit 81c2811
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions crates/wdk-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub const fn NT_SUCCESS(nt_status: NTSTATUS) -> bool {
/// See the [NTSTATUS reference](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781) and
/// [Using NTSTATUS values](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values) for details.
pub const fn NT_INFORMATION(nt_status: NTSTATUS) -> bool {
nt_status >> 30 == 1
(nt_status as u32 >> 30) == 1
}

#[must_use]
Expand All @@ -94,7 +94,7 @@ pub const fn NT_INFORMATION(nt_status: NTSTATUS) -> bool {
/// See the [NTSTATUS reference](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781) and
/// [Using NTSTATUS values](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values) for details.
pub const fn NT_WARNING(nt_status: NTSTATUS) -> bool {
nt_status >> 30 == 2
(nt_status as u32 >> 30) == 2
}

#[must_use]
Expand All @@ -106,7 +106,7 @@ pub const fn NT_WARNING(nt_status: NTSTATUS) -> bool {
/// See the [NTSTATUS reference](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781) and
/// [Using NTSTATUS values](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values) for details.
pub const fn NT_ERROR(nt_status: NTSTATUS) -> bool {
nt_status >> 30 == 3
(nt_status as u32 >> 30) == 3
}

#[allow(missing_docs)]
Expand All @@ -117,3 +117,28 @@ macro_rules! PAGED_CODE {
debug_assert!(unsafe { KeGetCurrentIrql() <= APC_LEVEL as u8 });
};
}

#[cfg(test)]
mod tests {
use crate::{
NT_ERROR,
NT_INFORMATION,
NT_SUCCESS,
NT_WARNING,
STATUS_BREAKPOINT,
STATUS_HIBERNATED,
STATUS_PRIVILEGED_INSTRUCTION,
STATUS_SUCCESS,
};
#[test]
pub fn status_tests() {
const {
assert!(NT_SUCCESS(STATUS_SUCCESS));
assert!(NT_SUCCESS(STATUS_HIBERNATED));
assert!(NT_INFORMATION(STATUS_HIBERNATED));
assert!(NT_WARNING(STATUS_BREAKPOINT));
assert!(NT_ERROR(STATUS_PRIVILEGED_INSTRUCTION));
assert!(!(NT_INFORMATION(STATUS_SUCCESS)));
}
}
}

0 comments on commit 81c2811

Please sign in to comment.