[EXPLORER] -Use WM_POPUPSYSTEMMENU to open the system menu of a window. CORE-13400
[reactos.git] / rostests / apitests / crt / tcstoul.h
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for _tcstoul
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6 */
7
8 #define WIN32_NO_STATUS
9 #include <wine/test.h>
10 #include <tchar.h>
11 #include <pseh/pseh2.h>
12 #include <ndk/mmfuncs.h>
13 #include <ndk/rtlfuncs.h>
14
15 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
16 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
17
18 #define ok_ulong(expression, result) \
19 do { \
20 unsigned long _value = (expression); \
21 ok(_value == (result), "Wrong value for '%s', expected: " #result " (%lu), got: %lu\n", \
22 #expression, (unsigned long)(result), _value); \
23 } while (0)
24
25 START_TEST(tcstoul)
26 {
27 NTSTATUS ExceptionStatus;
28 ULONG Result;
29 _TCHAR Dummy;
30 _TCHAR *End;
31 struct
32 {
33 const _TCHAR *Input;
34 int ExpectedLength0;
35 ULONG Expected0;
36 int ExpectedLength10;
37 ULONG Expected10;
38 } Tests[] =
39 {
40 { _T(""), 0, 0, 0, 0 },
41 { _T(" "), 0, 0, 0, 0 },
42 { _T(" 0"), 2, 0, 2, 0 },
43 { _T("0 "), 1, 0, 1, 0 },
44 { _T("0"), 1, 0, 1, 0 },
45 { _T("1"), 1, 1, 1, 1 },
46 { _T("10"), 2, 10, 2, 10 },
47 { _T("01"), 2, 1, 2, 1 },
48 { _T("010"), 3, 8, 3, 10 },
49 { _T("08"), 1, 0, 2, 8 },
50 { _T("008"), 2, 0, 3, 8 },
51 { _T("-1"), 2, -1, 2, -1 },
52 { _T("+1"), 2, 1, 2, 1 },
53 { _T("--1"), 0, 0, 0, 0 },
54 { _T("++1"), 0, 0, 0, 0 },
55 { _T("0a"), 1, 0, 1, 0 },
56 { _T("0x"), 0, 0, 1, 0 },
57 { _T("0x0"), 3, 0, 1, 0 },
58 { _T("0xFFFFFFFF"), 10, -1, 1, 0 },
59 { _T("0xFFFFFFFFF"),11, -1, 1, 0 },
60 { _T("4294967295"), 10, -1, 10, -1 },
61 { _T("4294967296"), 10, -1, 10, -1 },
62 { _T("4294967297"), 10, -1, 10, -1 },
63 { _T("42949672951"),11, -1, 11, -1 },
64 };
65 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
66 INT i;
67
68 StartSeh()
69 Result = _tcstoul(NULL, NULL, 0);
70 EndSeh(STATUS_ACCESS_VIOLATION);
71
72 StartSeh()
73 Result = _tcstoul(_T(""), NULL, 0);
74 ok_ulong(Result, 0);
75 EndSeh(STATUS_SUCCESS);
76
77 StartSeh()
78 Result = _tcstoul(_T("1"), NULL, 0);
79 ok_ulong(Result, 1);
80 EndSeh(STATUS_SUCCESS);
81
82 Result = _tcstoul(_T("1"), &End, 0);
83 ok_ulong(Result, 1);
84
85 for (i = 0; i < TestCount; i++)
86 {
87 #ifdef _UNICODE
88 trace("%d: '%ls'\n", i, Tests[i].Input);
89 #else
90 trace("%d: '%s'\n", i, Tests[i].Input);
91 #endif
92 End = &Dummy;
93 Result = _tcstoul(Tests[i].Input, &End, 0);
94 ok_ulong(Result, Tests[i].Expected0);
95 ok_ptr(End, Tests[i].Input + Tests[i].ExpectedLength0);
96
97 End = &Dummy;
98 Result = _tcstoul(Tests[i].Input, &End, 10);
99 ok_ulong(Result, Tests[i].Expected10);
100 ok_ptr(End, Tests[i].Input + Tests[i].ExpectedLength10);
101 }
102 }