diff --git a/rostests/kmtests/CMakeLists.txt b/rostests/kmtests/CMakeLists.txt index 4a65798eefa..0abd9fba8da 100644 --- a/rostests/kmtests/CMakeLists.txt +++ b/rostests/kmtests/CMakeLists.txt @@ -12,6 +12,7 @@ list(APPEND COMMON_SOURCE example/GuardedMemory.c rtl/RtlAvlTree.c rtl/RtlException.c + rtl/RtlIntSafe.c rtl/RtlMemory.c rtl/RtlRegistry.c rtl/RtlSplayTree.c diff --git a/rostests/kmtests/kmtest/testlist.c b/rostests/kmtests/kmtest/testlist.c index 6ebbfe8fe4a..f8718d207e6 100644 --- a/rostests/kmtests/kmtest/testlist.c +++ b/rostests/kmtests/kmtest/testlist.c @@ -12,6 +12,7 @@ KMT_TESTFUNC Test_FindFile; KMT_TESTFUNC Test_IoDeviceObject; KMT_TESTFUNC Test_RtlAvlTree; KMT_TESTFUNC Test_RtlException; +KMT_TESTFUNC Test_RtlIntSafe; KMT_TESTFUNC Test_RtlMemory; KMT_TESTFUNC Test_RtlRegistry; KMT_TESTFUNC Test_RtlSplayTree; @@ -25,6 +26,7 @@ const KMT_TEST TestList[] = { "IoDeviceObject", Test_IoDeviceObject }, { "RtlAvlTree", Test_RtlAvlTree }, { "RtlException", Test_RtlException }, + { "RtlIntSafe", Test_RtlIntSafe }, { "RtlMemory", Test_RtlMemory }, { "RtlRegistry", Test_RtlRegistry }, { "RtlSplayTree", Test_RtlSplayTree }, diff --git a/rostests/kmtests/kmtest_drv/testlist.c b/rostests/kmtests/kmtest_drv/testlist.c index cc70db4cebc..0920bdf858d 100644 --- a/rostests/kmtests/kmtest_drv/testlist.c +++ b/rostests/kmtests/kmtest_drv/testlist.c @@ -47,6 +47,7 @@ KMT_TESTFUNC Test_PsNotify; KMT_TESTFUNC Test_SeQueryInfoToken; KMT_TESTFUNC Test_RtlAvlTree; KMT_TESTFUNC Test_RtlException; +KMT_TESTFUNC Test_RtlIntSafe; KMT_TESTFUNC Test_RtlMemory; KMT_TESTFUNC Test_RtlRegistry; KMT_TESTFUNC Test_RtlSplayTree; @@ -97,6 +98,7 @@ const KMT_TEST TestList[] = { "-SeQueryInfoToken", Test_SeQueryInfoToken }, { "RtlAvlTreeKM", Test_RtlAvlTree }, { "RtlExceptionKM", Test_RtlException }, + { "RtlIntSafeKM", Test_RtlIntSafe }, { "RtlMemoryKM", Test_RtlMemory }, { "RtlRegistryKM", Test_RtlRegistry }, { "RtlSplayTreeKM", Test_RtlSplayTree }, diff --git a/rostests/kmtests/rtl/RtlIntSafe.c b/rostests/kmtests/rtl/RtlIntSafe.c new file mode 100644 index 00000000000..91f3491dc63 --- /dev/null +++ b/rostests/kmtests/rtl/RtlIntSafe.c @@ -0,0 +1,98 @@ +/* + * PROJECT: ReactOS kernel-mode tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for ntintsafe.h functions + * PROGRAMMER: Thomas Faber + */ + +#define KMT_EMULATE_KERNEL +#include +#include + +START_TEST(RtlIntSafe) +{ + NTSTATUS Status; + INT8 Int8Result; + UINT8 UInt8Result; + INT IntResult; + UINT UIntResult; + USHORT UShortResult; + SHORT ShortResult; + +#define TEST_CONVERSION(FromName, FromType, ToName, ToType, Print, Value, Expected, ExpectedStatus) \ + do \ + { \ + ToName ## Result = (ToType)0xfedcba9876543210; \ + Status = Rtl ## FromName ## To ## ToName(Value, \ + &ToName ## Result); \ + ok_eq_hex(Status, ExpectedStatus); \ + ok_eq_ ## Print(ToName ## Result, Expected); \ + } while (0) + + TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS); + TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, (UINT8)-1, (INT8)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, (ULONG)-1, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(ULong, ULONG, Int, INT, int, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, Int, INT, int, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, Int, INT, int, INT_MAX, INT_MAX, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)INT_MAX + 1, (INT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)-1, (INT)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, UINT_MAX, UINT_MAX, STATUS_SUCCESS); + TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, (ULONG)-1, (UINT)-1, STATUS_SUCCESS); + + TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, -1, (UINT8)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MIN, (UINT8)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MAX, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MAX, LONG_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Long, LONG, UInt, UINT, uint, -1, (UINT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MIN, (UINT)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(Int, INT, Int8, INT8, int, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Int8, INT8, int, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MAX, (INT8)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN, INT8_MIN, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN - 1, (INT8)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MIN, (INT8)-1, STATUS_INTEGER_OVERFLOW); + + TEST_CONVERSION(Int, INT, Short, SHORT, int, 0, 0, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Short, SHORT, int, 5, 5, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX, SHORT_MAX, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX + 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MAX, (SHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN, SHORT_MIN, STATUS_SUCCESS); + TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN - 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW); + TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MIN, (SHORT)-1, STATUS_INTEGER_OVERFLOW); +}