1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Testing
5 * COPYRIGHT: Copyright 2019-2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8 #ifndef ATLTEST_H_
9 #define ATLTEST_H_
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #ifndef _INC_WINDOWS
16 #include <windows.h>
17 #endif
18
19 int g_atltest_executed = 0;
20 int g_atltest_failed = 0;
21 int g_atltest_skipped = 0;
22
23 const char *g_atltest_file = NULL;
24 int g_atltest_line = 0;
25
atltest_set_location(const char * file,int line)26 void atltest_set_location(const char *file, int line)
27 {
28 g_atltest_file = file;
29 g_atltest_line = line;
30 }
31
atltest_ok(int value,const char * fmt,...)32 void atltest_ok(int value, const char *fmt, ...)
33 {
34 va_list va;
35 va_start(va, fmt);
36 if (!value)
37 {
38 printf("%s (%d): ", g_atltest_file, g_atltest_line);
39 vprintf(fmt, va);
40 g_atltest_failed++;
41 }
42 g_atltest_executed++;
43 va_end(va);
44 }
45
atltest_skip(const char * fmt,...)46 void atltest_skip(const char *fmt, ...)
47 {
48 va_list va;
49 va_start(va, fmt);
50 printf("%s (%d): test skipped: ", g_atltest_file, g_atltest_line);
51 vprintf(fmt, va);
52 g_atltest_skipped++;
53 va_end(va);
54 }
55
56 #undef ok
57 #define ok(value, ...) do { \
58 atltest_set_location(__FILE__, __LINE__); \
59 atltest_ok(value, __VA_ARGS__); \
60 } while (0)
61 #define ok_(x1,x2) atltest_set_location(x1,x2); atltest_ok
62
63 #undef skip
64 #define skip(...) do { \
65 atltest_set_location(__FILE__, __LINE__); \
66 atltest_skip(__VA_ARGS__); \
67 } while (0)
68
69 #undef trace
70 #define trace printf
71
72 static void atltest_start_test(void);
73 extern const char *g_atltest_name;
74
75 #define START_TEST(x) \
76 const char *g_atltest_name = #x; \
77 static void atltest_start_test(void)
78
main(void)79 int main(void)
80 {
81 atltest_start_test();
82 printf("%s: %d tests executed (0 marked as todo, %d failures), %d skipped.\n",
83 g_atltest_name, g_atltest_executed, g_atltest_failed, g_atltest_skipped);
84 return g_atltest_failed;
85 }
86
wine_dbgstr_w(const wchar_t * wstr)87 char *wine_dbgstr_w(const wchar_t *wstr)
88 {
89 static char buf[512];
90 WideCharToMultiByte(CP_ACP, 0, wstr, -1, buf, _countof(buf), NULL, NULL);
91 return buf;
92 }
93
94 #define ok_hex(expression, result) \
95 do { \
96 int _value = (expression); \
97 ok(_value == (result), "Wrong value for '%s', expected: " #result " (0x%x), got: 0x%x\n", \
98 #expression, (int)(result), _value); \
99 } while (0)
100
101 #define ok_dec(expression, result) \
102 do { \
103 int _value = (expression); \
104 ok(_value == (result), "Wrong value for '%s', expected: " #result " (%d), got: %d\n", \
105 #expression, (int)(result), _value); \
106 } while (0)
107
108 #define ok_ptr(expression, result) \
109 do { \
110 const void *_value = (expression); \
111 ok(_value == (result), "Wrong value for '%s', expected: " #result " (%p), got: %p\n", \
112 #expression, (void*)(result), _value); \
113 } while (0)
114
115 #define ok_size_t(expression, result) \
116 do { \
117 size_t _value = (expression); \
118 ok(_value == (result), "Wrong value for '%s', expected: " #result " (%Ix), got: %Ix\n", \
119 #expression, (size_t)(result), _value); \
120 } while (0)
121
122 #define ok_char(expression, result) ok_hex(expression, result)
123
124 #define ok_err(error) \
125 ok(GetLastError() == (error), "Wrong last error. Expected " #error ", got 0x%lx\n", GetLastError())
126
127 #define ok_str(x, y) \
128 ok(strcmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", y, x)
129
130 #define ok_wstr(x, y) \
131 ok(wcscmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
132
133 #define ok_long(expression, result) ok_hex(expression, result)
134 #define ok_int(expression, result) ok_dec(expression, result)
135 #define ok_ntstatus(status, expected) ok_hex(status, expected)
136 #define ok_hdl ok_ptr
137
wine_dbgstr_point(const POINT * ppt)138 static inline const char *wine_dbgstr_point(const POINT *ppt)
139 {
140 static char s_asz[4][40]; /* Ring buffer */
141 static int s_i = 0;
142 char *buf;
143
144 if (!ppt)
145 return "(null)";
146 if (IS_INTRESOURCE(ppt))
147 return "(invalid ptr)";
148
149 buf = s_asz[s_i];
150 s_i = (s_i + 1) % _countof(s_asz);
151 sprintf_s(buf, _countof(s_asz[0]), "(%ld, %ld)", ppt->x, ppt->y);
152 return buf;
153 }
154
wine_dbgstr_size(const SIZE * psize)155 static inline const char *wine_dbgstr_size(const SIZE *psize)
156 {
157 return wine_dbgstr_point((const POINT *)psize);
158 }
159
wine_dbgstr_rect(const RECT * prc)160 static inline const char *wine_dbgstr_rect(const RECT *prc)
161 {
162 static char s_asz[4][80]; /* Ring buffer */
163 static int s_i = 0;
164 char *buf;
165
166 if (!prc)
167 return "(null)";
168 if (IS_INTRESOURCE(prc))
169 return "(invalid ptr)";
170
171 buf = s_asz[s_i];
172 s_i = (s_i + 1) % _countof(s_asz);
173 sprintf_s(buf, _countof(s_asz[0]), "(%ld, %ld) - (%ld, %ld)",
174 prc->left, prc->top, prc->right, prc->bottom);
175 return buf;
176 }
177
178 #define broken(x) x
179
180 #endif /* ndef ATLTEST_H_ */
181