1a800fa7bSKatayama Hirofumi MZ /*
2a800fa7bSKatayama Hirofumi MZ * PROJECT: ReactOS api tests
3a800fa7bSKatayama Hirofumi MZ * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4a800fa7bSKatayama Hirofumi MZ * PURPOSE: Testing
586696794SKatayama Hirofumi MZ * COPYRIGHT: Copyright 2019-2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6a800fa7bSKatayama Hirofumi MZ */
7a800fa7bSKatayama Hirofumi MZ
8a800fa7bSKatayama Hirofumi MZ #ifndef ATLTEST_H_
9a800fa7bSKatayama Hirofumi MZ #define ATLTEST_H_
10a800fa7bSKatayama Hirofumi MZ
11a800fa7bSKatayama Hirofumi MZ #include <stdlib.h>
12a800fa7bSKatayama Hirofumi MZ #include <stdio.h>
13a800fa7bSKatayama Hirofumi MZ #include <stdarg.h>
14a800fa7bSKatayama Hirofumi MZ #include <string.h>
15a800fa7bSKatayama Hirofumi MZ #ifndef _INC_WINDOWS
16a800fa7bSKatayama Hirofumi MZ #include <windows.h>
17a800fa7bSKatayama Hirofumi MZ #endif
18a800fa7bSKatayama Hirofumi MZ
19a800fa7bSKatayama Hirofumi MZ int g_atltest_executed = 0;
20a800fa7bSKatayama Hirofumi MZ int g_atltest_failed = 0;
21a800fa7bSKatayama Hirofumi MZ int g_atltest_skipped = 0;
22a800fa7bSKatayama Hirofumi MZ
23a800fa7bSKatayama Hirofumi MZ const char *g_atltest_file = NULL;
24a800fa7bSKatayama Hirofumi MZ int g_atltest_line = 0;
25a800fa7bSKatayama Hirofumi MZ
atltest_set_location(const char * file,int line)26a800fa7bSKatayama Hirofumi MZ void atltest_set_location(const char *file, int line)
27a800fa7bSKatayama Hirofumi MZ {
28a800fa7bSKatayama Hirofumi MZ g_atltest_file = file;
29a800fa7bSKatayama Hirofumi MZ g_atltest_line = line;
30a800fa7bSKatayama Hirofumi MZ }
31a800fa7bSKatayama Hirofumi MZ
atltest_ok(int value,const char * fmt,...)32a800fa7bSKatayama Hirofumi MZ void atltest_ok(int value, const char *fmt, ...)
33a800fa7bSKatayama Hirofumi MZ {
34a800fa7bSKatayama Hirofumi MZ va_list va;
35a800fa7bSKatayama Hirofumi MZ va_start(va, fmt);
36a800fa7bSKatayama Hirofumi MZ if (!value)
37a800fa7bSKatayama Hirofumi MZ {
38a800fa7bSKatayama Hirofumi MZ printf("%s (%d): ", g_atltest_file, g_atltest_line);
39a800fa7bSKatayama Hirofumi MZ vprintf(fmt, va);
40a800fa7bSKatayama Hirofumi MZ g_atltest_failed++;
41a800fa7bSKatayama Hirofumi MZ }
42a800fa7bSKatayama Hirofumi MZ g_atltest_executed++;
43a800fa7bSKatayama Hirofumi MZ va_end(va);
44a800fa7bSKatayama Hirofumi MZ }
45a800fa7bSKatayama Hirofumi MZ
atltest_skip(const char * fmt,...)46a800fa7bSKatayama Hirofumi MZ void atltest_skip(const char *fmt, ...)
47a800fa7bSKatayama Hirofumi MZ {
48a800fa7bSKatayama Hirofumi MZ va_list va;
49a800fa7bSKatayama Hirofumi MZ va_start(va, fmt);
50a800fa7bSKatayama Hirofumi MZ printf("%s (%d): test skipped: ", g_atltest_file, g_atltest_line);
51a800fa7bSKatayama Hirofumi MZ vprintf(fmt, va);
52a800fa7bSKatayama Hirofumi MZ g_atltest_skipped++;
53a800fa7bSKatayama Hirofumi MZ va_end(va);
54a800fa7bSKatayama Hirofumi MZ }
55a800fa7bSKatayama Hirofumi MZ
56a800fa7bSKatayama Hirofumi MZ #undef ok
57a800fa7bSKatayama Hirofumi MZ #define ok(value, ...) do { \
58a800fa7bSKatayama Hirofumi MZ atltest_set_location(__FILE__, __LINE__); \
59a800fa7bSKatayama Hirofumi MZ atltest_ok(value, __VA_ARGS__); \
60a800fa7bSKatayama Hirofumi MZ } while (0)
61a800fa7bSKatayama Hirofumi MZ #define ok_(x1,x2) atltest_set_location(x1,x2); atltest_ok
62a800fa7bSKatayama Hirofumi MZ
63a800fa7bSKatayama Hirofumi MZ #undef skip
64a800fa7bSKatayama Hirofumi MZ #define skip(...) do { \
65a800fa7bSKatayama Hirofumi MZ atltest_set_location(__FILE__, __LINE__); \
66a800fa7bSKatayama Hirofumi MZ atltest_skip(__VA_ARGS__); \
67a800fa7bSKatayama Hirofumi MZ } while (0)
68a800fa7bSKatayama Hirofumi MZ
69a800fa7bSKatayama Hirofumi MZ #undef trace
70a800fa7bSKatayama Hirofumi MZ #define trace printf
71a800fa7bSKatayama Hirofumi MZ
72a800fa7bSKatayama Hirofumi MZ static void atltest_start_test(void);
73a800fa7bSKatayama Hirofumi MZ extern const char *g_atltest_name;
74a800fa7bSKatayama Hirofumi MZ
75a800fa7bSKatayama Hirofumi MZ #define START_TEST(x) \
76a800fa7bSKatayama Hirofumi MZ const char *g_atltest_name = #x; \
77a800fa7bSKatayama Hirofumi MZ static void atltest_start_test(void)
78a800fa7bSKatayama Hirofumi MZ
main(void)79a800fa7bSKatayama Hirofumi MZ int main(void)
80a800fa7bSKatayama Hirofumi MZ {
81a800fa7bSKatayama Hirofumi MZ atltest_start_test();
82a800fa7bSKatayama Hirofumi MZ printf("%s: %d tests executed (0 marked as todo, %d failures), %d skipped.\n",
83a800fa7bSKatayama Hirofumi MZ g_atltest_name, g_atltest_executed, g_atltest_failed, g_atltest_skipped);
84a800fa7bSKatayama Hirofumi MZ return g_atltest_failed;
85a800fa7bSKatayama Hirofumi MZ }
86a800fa7bSKatayama Hirofumi MZ
wine_dbgstr_w(const wchar_t * wstr)87a800fa7bSKatayama Hirofumi MZ char *wine_dbgstr_w(const wchar_t *wstr)
88a800fa7bSKatayama Hirofumi MZ {
89a800fa7bSKatayama Hirofumi MZ static char buf[512];
90a800fa7bSKatayama Hirofumi MZ WideCharToMultiByte(CP_ACP, 0, wstr, -1, buf, _countof(buf), NULL, NULL);
91a800fa7bSKatayama Hirofumi MZ return buf;
92a800fa7bSKatayama Hirofumi MZ }
93a800fa7bSKatayama Hirofumi MZ
94a800fa7bSKatayama Hirofumi MZ #define ok_hex(expression, result) \
95a800fa7bSKatayama Hirofumi MZ do { \
96a800fa7bSKatayama Hirofumi MZ int _value = (expression); \
97a800fa7bSKatayama Hirofumi MZ ok(_value == (result), "Wrong value for '%s', expected: " #result " (0x%x), got: 0x%x\n", \
98a800fa7bSKatayama Hirofumi MZ #expression, (int)(result), _value); \
99a800fa7bSKatayama Hirofumi MZ } while (0)
100a800fa7bSKatayama Hirofumi MZ
101a800fa7bSKatayama Hirofumi MZ #define ok_dec(expression, result) \
102a800fa7bSKatayama Hirofumi MZ do { \
103a800fa7bSKatayama Hirofumi MZ int _value = (expression); \
104a800fa7bSKatayama Hirofumi MZ ok(_value == (result), "Wrong value for '%s', expected: " #result " (%d), got: %d\n", \
105a800fa7bSKatayama Hirofumi MZ #expression, (int)(result), _value); \
106a800fa7bSKatayama Hirofumi MZ } while (0)
107a800fa7bSKatayama Hirofumi MZ
108a800fa7bSKatayama Hirofumi MZ #define ok_ptr(expression, result) \
109a800fa7bSKatayama Hirofumi MZ do { \
1101191bcafSKatayama Hirofumi MZ const void *_value = (expression); \
111a800fa7bSKatayama Hirofumi MZ ok(_value == (result), "Wrong value for '%s', expected: " #result " (%p), got: %p\n", \
112a800fa7bSKatayama Hirofumi MZ #expression, (void*)(result), _value); \
113a800fa7bSKatayama Hirofumi MZ } while (0)
114a800fa7bSKatayama Hirofumi MZ
115a800fa7bSKatayama Hirofumi MZ #define ok_size_t(expression, result) \
116a800fa7bSKatayama Hirofumi MZ do { \
117a800fa7bSKatayama Hirofumi MZ size_t _value = (expression); \
118a800fa7bSKatayama Hirofumi MZ ok(_value == (result), "Wrong value for '%s', expected: " #result " (%Ix), got: %Ix\n", \
119a800fa7bSKatayama Hirofumi MZ #expression, (size_t)(result), _value); \
120a800fa7bSKatayama Hirofumi MZ } while (0)
121a800fa7bSKatayama Hirofumi MZ
122a800fa7bSKatayama Hirofumi MZ #define ok_char(expression, result) ok_hex(expression, result)
123a800fa7bSKatayama Hirofumi MZ
124a800fa7bSKatayama Hirofumi MZ #define ok_err(error) \
125a800fa7bSKatayama Hirofumi MZ ok(GetLastError() == (error), "Wrong last error. Expected " #error ", got 0x%lx\n", GetLastError())
126a800fa7bSKatayama Hirofumi MZ
127a800fa7bSKatayama Hirofumi MZ #define ok_str(x, y) \
128a800fa7bSKatayama Hirofumi MZ ok(strcmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", y, x)
129a800fa7bSKatayama Hirofumi MZ
130a800fa7bSKatayama Hirofumi MZ #define ok_wstr(x, y) \
131a800fa7bSKatayama Hirofumi MZ ok(wcscmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
132a800fa7bSKatayama Hirofumi MZ
133a800fa7bSKatayama Hirofumi MZ #define ok_long(expression, result) ok_hex(expression, result)
134a800fa7bSKatayama Hirofumi MZ #define ok_int(expression, result) ok_dec(expression, result)
135a800fa7bSKatayama Hirofumi MZ #define ok_ntstatus(status, expected) ok_hex(status, expected)
136a800fa7bSKatayama Hirofumi MZ #define ok_hdl ok_ptr
137a800fa7bSKatayama Hirofumi MZ
wine_dbgstr_point(const POINT * ppt)13886696794SKatayama Hirofumi MZ static inline const char *wine_dbgstr_point(const POINT *ppt)
13986696794SKatayama Hirofumi MZ {
14086696794SKatayama Hirofumi MZ static char s_asz[4][40]; /* Ring buffer */
14186696794SKatayama Hirofumi MZ static int s_i = 0;
14286696794SKatayama Hirofumi MZ char *buf;
14386696794SKatayama Hirofumi MZ
14486696794SKatayama Hirofumi MZ if (!ppt)
14586696794SKatayama Hirofumi MZ return "(null)";
14686696794SKatayama Hirofumi MZ if (IS_INTRESOURCE(ppt))
14786696794SKatayama Hirofumi MZ return "(invalid ptr)";
14886696794SKatayama Hirofumi MZ
14986696794SKatayama Hirofumi MZ buf = s_asz[s_i];
15086696794SKatayama Hirofumi MZ s_i = (s_i + 1) % _countof(s_asz);
15186696794SKatayama Hirofumi MZ sprintf_s(buf, _countof(s_asz[0]), "(%ld, %ld)", ppt->x, ppt->y);
15286696794SKatayama Hirofumi MZ return buf;
15386696794SKatayama Hirofumi MZ }
15486696794SKatayama Hirofumi MZ
wine_dbgstr_size(const SIZE * psize)15586696794SKatayama Hirofumi MZ static inline const char *wine_dbgstr_size(const SIZE *psize)
15686696794SKatayama Hirofumi MZ {
15786696794SKatayama Hirofumi MZ return wine_dbgstr_point((const POINT *)psize);
15886696794SKatayama Hirofumi MZ }
15986696794SKatayama Hirofumi MZ
wine_dbgstr_rect(const RECT * prc)16086696794SKatayama Hirofumi MZ static inline const char *wine_dbgstr_rect(const RECT *prc)
16186696794SKatayama Hirofumi MZ {
16286696794SKatayama Hirofumi MZ static char s_asz[4][80]; /* Ring buffer */
16386696794SKatayama Hirofumi MZ static int s_i = 0;
16486696794SKatayama Hirofumi MZ char *buf;
16586696794SKatayama Hirofumi MZ
16686696794SKatayama Hirofumi MZ if (!prc)
16786696794SKatayama Hirofumi MZ return "(null)";
16886696794SKatayama Hirofumi MZ if (IS_INTRESOURCE(prc))
16986696794SKatayama Hirofumi MZ return "(invalid ptr)";
17086696794SKatayama Hirofumi MZ
17186696794SKatayama Hirofumi MZ buf = s_asz[s_i];
17286696794SKatayama Hirofumi MZ s_i = (s_i + 1) % _countof(s_asz);
17386696794SKatayama Hirofumi MZ sprintf_s(buf, _countof(s_asz[0]), "(%ld, %ld) - (%ld, %ld)",
17486696794SKatayama Hirofumi MZ prc->left, prc->top, prc->right, prc->bottom);
17586696794SKatayama Hirofumi MZ return buf;
17686696794SKatayama Hirofumi MZ }
17786696794SKatayama Hirofumi MZ
178*edf02414STimo Kreuzer #define broken(x) x
179*edf02414STimo Kreuzer
180a800fa7bSKatayama Hirofumi MZ #endif /* ndef ATLTEST_H_ */
181