[SHELL32_APITEST] -Add tests for Control_RunDLLW.
[reactos.git] / rostests / kmtests / rtl / RtlIntSafe.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for ntintsafe.h functions
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #define KMT_EMULATE_KERNEL
9 #include <kmt_test.h>
10 #define ENABLE_INTSAFE_SIGNED_FUNCTIONS
11 #include <ntintsafe.h>
12
13 START_TEST(RtlIntSafe)
14 {
15 NTSTATUS Status;
16 INT8 Int8Result;
17 UINT8 UInt8Result;
18 INT IntResult;
19 UINT UIntResult;
20 USHORT UShortResult;
21 SHORT ShortResult;
22 LONGLONG LongLongResult;
23
24 #define TEST_CONVERSION(FromName, FromType, ToName, ToType, Print, Value, Expected, ExpectedStatus) \
25 do \
26 { \
27 ToName ## Result = (ToType)0xfedcba9876543210; \
28 Status = Rtl ## FromName ## To ## ToName(Value, \
29 &ToName ## Result); \
30 ok_eq_hex(Status, ExpectedStatus); \
31 ok_eq_ ## Print(ToName ## Result, Expected); \
32 } while (0)
33
34 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 0, 0, STATUS_SUCCESS);
35 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 5, 5, STATUS_SUCCESS);
36 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
37 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
38 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, (UINT8)-1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
39
40 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
41 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
42 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS);
43 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
44 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, (ULONG)-1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
45
46 TEST_CONVERSION(ULong, ULONG, Int, INT, int, 0, 0, STATUS_SUCCESS);
47 TEST_CONVERSION(ULong, ULONG, Int, INT, int, 5, 5, STATUS_SUCCESS);
48 TEST_CONVERSION(ULong, ULONG, Int, INT, int, INT_MAX, INT_MAX, STATUS_SUCCESS);
49 TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)INT_MAX + 1, (INT)-1, STATUS_INTEGER_OVERFLOW);
50 TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)-1, (INT)-1, STATUS_INTEGER_OVERFLOW);
51
52 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS);
53 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS);
54 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, UINT_MAX, UINT_MAX, STATUS_SUCCESS);
55 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, (ULONG)-1, (UINT)-1, STATUS_SUCCESS);
56
57 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 0, 0, STATUS_SUCCESS);
58 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 5, 5, STATUS_SUCCESS);
59 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
60 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, -1, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
61 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MIN, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
62
63 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
64 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
65 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
66 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
67 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
68
69 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
70 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
71 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS);
72 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
73 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MAX, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
74 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
75 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
76
77 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS);
78 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS);
79 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MAX, LONG_MAX, STATUS_SUCCESS);
80 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, -1, (UINT)-1, STATUS_INTEGER_OVERFLOW);
81 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MIN, (UINT)-1, STATUS_INTEGER_OVERFLOW);
82
83 TEST_CONVERSION(Int, INT, Int8, INT8, int, 0, 0, STATUS_SUCCESS);
84 TEST_CONVERSION(Int, INT, Int8, INT8, int, 5, 5, STATUS_SUCCESS);
85 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
86 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
87 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MAX, (INT8)-1, STATUS_INTEGER_OVERFLOW);
88 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN, INT8_MIN, STATUS_SUCCESS);
89 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN - 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
90 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MIN, (INT8)-1, STATUS_INTEGER_OVERFLOW);
91
92 TEST_CONVERSION(Int, INT, Short, SHORT, int, 0, 0, STATUS_SUCCESS);
93 TEST_CONVERSION(Int, INT, Short, SHORT, int, 5, 5, STATUS_SUCCESS);
94 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX, SHORT_MAX, STATUS_SUCCESS);
95 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX + 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
96 TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MAX, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
97 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN, SHORT_MIN, STATUS_SUCCESS);
98 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN - 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
99 TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MIN, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
100
101 #define TEST_ADD(_Name, _Type, _Print, _Value1, _Value2, _Expected, _Status) do \
102 { \
103 _Name ## Result = (_Type)0xfedcba9876543210; \
104 Status = Rtl ## _Name ## Add(_Value1, _Value2, & _Name ## Result); \
105 ok_eq_hex(Status, _Status); \
106 ok_eq_ ## _Print(_Name ## Result, _Expected); \
107 } while (0)
108
109 TEST_ADD(UInt8, UINT8, uint, 0, 0, 0, STATUS_SUCCESS);
110 TEST_ADD(UInt8, UINT8, uint, 5, 5, 10, STATUS_SUCCESS);
111 TEST_ADD(UInt8, UINT8, uint, 0, UINT8_MAX, UINT8_MAX, STATUS_SUCCESS);
112 TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, 0, UINT8_MAX, STATUS_SUCCESS);
113 TEST_ADD(UInt8, UINT8, uint, UINT8_MAX - 1, 1, UINT8_MAX, STATUS_SUCCESS);
114 TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, 1, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
115 TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, UINT8_MAX, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
116
117 TEST_ADD(Int8, INT8, int, 0, 0, 0, STATUS_SUCCESS);
118 TEST_ADD(Int8, INT8, int, 5, 5, 10, STATUS_SUCCESS);
119 TEST_ADD(Int8, INT8, int, 0, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
120 TEST_ADD(Int8, INT8, int, INT8_MAX, 0, INT8_MAX, STATUS_SUCCESS);
121 TEST_ADD(Int8, INT8, int, INT8_MAX - 1, 1, INT8_MAX, STATUS_SUCCESS);
122 TEST_ADD(Int8, INT8, int, INT8_MAX, 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
123 TEST_ADD(Int8, INT8, int, INT8_MAX, INT8_MAX, (INT8)-1, STATUS_INTEGER_OVERFLOW);
124 TEST_ADD(Int8, INT8, int, 0, -1, -1, STATUS_SUCCESS);
125 TEST_ADD(Int8, INT8, int, -1, 0, -1, STATUS_SUCCESS);
126 TEST_ADD(Int8, INT8, int, 0, INT8_MIN, INT8_MIN, STATUS_SUCCESS);
127 TEST_ADD(Int8, INT8, int, INT8_MIN, 0, INT8_MIN, STATUS_SUCCESS);
128 TEST_ADD(Int8, INT8, int, INT8_MAX, INT8_MIN, (INT8)-1, STATUS_SUCCESS);
129 TEST_ADD(Int8, INT8, int, INT8_MIN, -1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
130 TEST_ADD(Int8, INT8, int, INT8_MIN, INT8_MIN, (INT8)-1, STATUS_INTEGER_OVERFLOW);
131
132 TEST_ADD(LongLong, LONGLONG, longlong, 0, 0, 0, STATUS_SUCCESS);
133 TEST_ADD(LongLong, LONGLONG, longlong, 5, 5, 10, STATUS_SUCCESS);
134 TEST_ADD(LongLong, LONGLONG, longlong, 0, LONGLONG_MAX, LONGLONG_MAX, STATUS_SUCCESS);
135 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MAX, 0, LONGLONG_MAX, STATUS_SUCCESS);
136 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MAX - 1, 1, LONGLONG_MAX, STATUS_SUCCESS);
137 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MAX, 1, (LONGLONG)-1, STATUS_INTEGER_OVERFLOW);
138 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MAX, INT8_MAX, (LONGLONG)-1, STATUS_INTEGER_OVERFLOW);
139 TEST_ADD(LongLong, LONGLONG, longlong, 0, -1, -1, STATUS_SUCCESS);
140 TEST_ADD(LongLong, LONGLONG, longlong, -1, 0, -1, STATUS_SUCCESS);
141 TEST_ADD(LongLong, LONGLONG, longlong, 0, LONGLONG_MIN, LONGLONG_MIN, STATUS_SUCCESS);
142 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MIN, 0, LONGLONG_MIN, STATUS_SUCCESS);
143 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MAX, LONGLONG_MIN, (LONGLONG)-1, STATUS_SUCCESS);
144 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MIN, -1, (LONGLONG)-1, STATUS_INTEGER_OVERFLOW);
145 TEST_ADD(LongLong, LONGLONG, longlong, LONGLONG_MIN, LONGLONG_MIN, (LONGLONG)-1, STATUS_INTEGER_OVERFLOW);
146 TEST_ADD(LongLong, LONGLONG, longlong, ULONG_MAX, 1, 0x100000000LL, STATUS_SUCCESS);
147 TEST_ADD(LongLong, LONGLONG, longlong, ULONG_MAX, ULONG_MAX, 0x1fffffffeLL, STATUS_SUCCESS);
148 }