[KMTESTS:RTL]
authorThomas Faber <thomas.faber@reactos.org>
Thu, 14 Nov 2013 09:19:16 +0000 (09:19 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Thu, 14 Nov 2013 09:19:16 +0000 (09:19 +0000)
- Add RtlIntSafe test for ntintsafe.h functions
CORE-7578

svn path=/trunk/; revision=60991

rostests/kmtests/CMakeLists.txt
rostests/kmtests/kmtest/testlist.c
rostests/kmtests/kmtest_drv/testlist.c
rostests/kmtests/rtl/RtlIntSafe.c [new file with mode: 0644]

index 4a65798..0abd9fb 100644 (file)
@@ -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
index 6ebbfe8..f8718d2 100644 (file)
@@ -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 },
index cc70db4..0920bdf 100644 (file)
@@ -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 (file)
index 0000000..91f3491
--- /dev/null
@@ -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 <thomas.faber@reactos.org>
+ */
+
+#define KMT_EMULATE_KERNEL
+#include <kmt_test.h>
+#include <ntintsafe.h>
+
+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);
+}