[SNMPAPI_WINETEST]
[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 #include <ntintsafe.h>
11
12 START_TEST(RtlIntSafe)
13 {
14 NTSTATUS Status;
15 INT8 Int8Result;
16 UINT8 UInt8Result;
17 INT IntResult;
18 UINT UIntResult;
19 USHORT UShortResult;
20 SHORT ShortResult;
21
22 #define TEST_CONVERSION(FromName, FromType, ToName, ToType, Print, Value, Expected, ExpectedStatus) \
23 do \
24 { \
25 ToName ## Result = (ToType)0xfedcba9876543210; \
26 Status = Rtl ## FromName ## To ## ToName(Value, \
27 &ToName ## Result); \
28 ok_eq_hex(Status, ExpectedStatus); \
29 ok_eq_ ## Print(ToName ## Result, Expected); \
30 } while (0)
31
32 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 0, 0, STATUS_SUCCESS);
33 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, 5, 5, STATUS_SUCCESS);
34 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
35 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
36 TEST_CONVERSION(UInt8, UINT8, Int8, INT8, int, (UINT8)-1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
37
38 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
39 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
40 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS);
41 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
42 TEST_CONVERSION(ULong, ULONG, UShort, USHORT, uint, (ULONG)-1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
43
44 TEST_CONVERSION(ULong, ULONG, Int, INT, int, 0, 0, STATUS_SUCCESS);
45 TEST_CONVERSION(ULong, ULONG, Int, INT, int, 5, 5, STATUS_SUCCESS);
46 TEST_CONVERSION(ULong, ULONG, Int, INT, int, INT_MAX, INT_MAX, STATUS_SUCCESS);
47 TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)INT_MAX + 1, (INT)-1, STATUS_INTEGER_OVERFLOW);
48 TEST_CONVERSION(ULong, ULONG, Int, INT, int, (ULONG)-1, (INT)-1, STATUS_INTEGER_OVERFLOW);
49
50 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS);
51 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS);
52 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, UINT_MAX, UINT_MAX, STATUS_SUCCESS);
53 TEST_CONVERSION(ULong, ULONG, UInt, UINT, uint, (ULONG)-1, (UINT)-1, STATUS_SUCCESS);
54
55 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 0, 0, STATUS_SUCCESS);
56 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, 5, 5, STATUS_SUCCESS);
57 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
58 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, -1, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
59 TEST_CONVERSION(Int8, INT8, UInt8, UINT8, uint, INT8_MIN, (UINT8)-1, STATUS_INTEGER_OVERFLOW);
60
61 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
62 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
63 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
64 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
65 TEST_CONVERSION(Int8, INT8, UShort, USHORT, uint, INT8_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
66
67 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 0, 0, STATUS_SUCCESS);
68 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, 5, 5, STATUS_SUCCESS);
69 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX, USHORT_MAX, STATUS_SUCCESS);
70 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, USHORT_MAX + 1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
71 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MAX, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
72 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, -1, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
73 TEST_CONVERSION(Long, LONG, UShort, USHORT, uint, LONG_MIN, (USHORT)-1, STATUS_INTEGER_OVERFLOW);
74
75 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 0, 0, STATUS_SUCCESS);
76 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, 5, 5, STATUS_SUCCESS);
77 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MAX, LONG_MAX, STATUS_SUCCESS);
78 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, -1, (UINT)-1, STATUS_INTEGER_OVERFLOW);
79 TEST_CONVERSION(Long, LONG, UInt, UINT, uint, LONG_MIN, (UINT)-1, STATUS_INTEGER_OVERFLOW);
80
81 TEST_CONVERSION(Int, INT, Int8, INT8, int, 0, 0, STATUS_SUCCESS);
82 TEST_CONVERSION(Int, INT, Int8, INT8, int, 5, 5, STATUS_SUCCESS);
83 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX, INT8_MAX, STATUS_SUCCESS);
84 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MAX + 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
85 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MAX, (INT8)-1, STATUS_INTEGER_OVERFLOW);
86 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN, INT8_MIN, STATUS_SUCCESS);
87 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT8_MIN - 1, (INT8)-1, STATUS_INTEGER_OVERFLOW);
88 TEST_CONVERSION(Int, INT, Int8, INT8, int, INT_MIN, (INT8)-1, STATUS_INTEGER_OVERFLOW);
89
90 TEST_CONVERSION(Int, INT, Short, SHORT, int, 0, 0, STATUS_SUCCESS);
91 TEST_CONVERSION(Int, INT, Short, SHORT, int, 5, 5, STATUS_SUCCESS);
92 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX, SHORT_MAX, STATUS_SUCCESS);
93 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MAX + 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
94 TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MAX, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
95 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN, SHORT_MIN, STATUS_SUCCESS);
96 TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN - 1, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
97 TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MIN, (SHORT)-1, STATUS_INTEGER_OVERFLOW);
98 }