gdi32: Move the handling of font family fallbacks out of freetype.c.
[wine/zf.git] / dlls / wer / tests / main.c
blob038b29c25a9f1944e2c344eed27859a415fa8d6f
1 /*
2 * Unit test suite for windows error reporting in Vista and above
4 * Copyright 2010,2019 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
30 #include "werapi.h"
31 #include "wine/test.h"
32 static const WCHAR winetest_wer[] = L"winetest_wer.exe";
34 /* ###### */
36 static void test_WerAddExcludedApplication(void)
38 HRESULT hr;
39 WCHAR buffer[MAX_PATH];
40 UINT res;
42 /* clean state */
43 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
44 ok((hr == S_OK) || (hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
45 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
47 hr = WerAddExcludedApplication(NULL, FALSE);
48 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
50 hr = WerAddExcludedApplication(L"", FALSE);
51 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
53 hr = WerAddExcludedApplication(winetest_wer, FALSE);
54 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
55 /* app already in the list */
56 hr = WerAddExcludedApplication(winetest_wer, FALSE);
57 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
60 /* cleanup */
61 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
62 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
64 /* appname has a path */
65 res = GetWindowsDirectoryW(buffer, ARRAY_SIZE(buffer));
66 if (res > 0) {
67 /* the last part from the path is added to the inclusion list */
68 hr = WerAddExcludedApplication(buffer, FALSE);
69 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
70 hr = WerRemoveExcludedApplication(buffer, FALSE);
71 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
73 lstrcatW(buffer, L"\\");
74 hr = WerAddExcludedApplication(buffer, FALSE);
75 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
77 lstrcatW(buffer, winetest_wer);
78 hr = WerAddExcludedApplication(buffer, FALSE);
79 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
80 hr = WerRemoveExcludedApplication(buffer, FALSE);
81 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
86 /* #### */
88 static void test_WerRemoveExcludedApplication(void)
90 HRESULT hr;
91 WCHAR buffer[MAX_PATH];
92 UINT res;
94 /* clean state */
95 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
96 ok((hr == S_OK) || (hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
97 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
99 hr = WerAddExcludedApplication(winetest_wer, FALSE);
100 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
102 hr = WerRemoveExcludedApplication(NULL, FALSE);
103 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
105 hr = WerRemoveExcludedApplication(L"", FALSE);
106 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
108 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
109 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
111 /* app not in the list */
112 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
113 ok((hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
114 "got 0x%x (expected E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
116 /* appname has a path */
117 res = GetWindowsDirectoryW(buffer, ARRAY_SIZE(buffer));
118 if (res > 0) {
119 hr = WerRemoveExcludedApplication(buffer, FALSE);
120 ok((hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
121 "got 0x%x (expected E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
123 /* the last part from the path is added to the inclusion list */
124 hr = WerAddExcludedApplication(buffer, FALSE);
125 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
126 hr = WerRemoveExcludedApplication(buffer, FALSE);
127 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
129 lstrcatW(buffer, L"\\");
130 hr = WerAddExcludedApplication(buffer, FALSE);
131 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
132 hr = WerRemoveExcludedApplication(buffer, FALSE);
133 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
135 lstrcatW(buffer, winetest_wer);
136 hr = WerAddExcludedApplication(buffer, FALSE);
137 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
138 hr = WerRemoveExcludedApplication(buffer, FALSE);
139 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
143 /* #### */
145 static void test_WerReportCloseHandle(void)
147 HRESULT hr;
148 HREPORT report;
150 report = (void *) 0xdeadbeef;
151 hr = WerReportCreate(L"APPCRASH", WerReportCritical, NULL, &report);
152 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
154 if (!report) {
155 skip("Nothing left to test\n");
156 return;
159 /* close the handle */
160 hr = WerReportCloseHandle(report);
161 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
163 /* close the handle again */
164 hr = WerReportCloseHandle(report);
165 ok(hr == E_INVALIDARG, "got 0x%x for %p again (expected E_INVALIDARG)\n", hr, report);
167 hr = WerReportCloseHandle(NULL);
168 ok(hr == E_INVALIDARG, "got 0x%x for NULL(expected E_INVALIDARG)\n", hr);
171 /* #### */
173 static void test_WerReportCreate(void)
175 HRESULT hr;
176 HREPORT report;
177 HREPORT table[8];
178 int i;
180 report = (void *) 0xdeadbeef;
181 /* test a simple valid case */
182 hr = WerReportCreate(L"APPCRASH", WerReportCritical, NULL, &report);
183 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
185 if (!report) {
186 skip("Nothing left to test\n");
187 return;
190 hr = WerReportCloseHandle(report);
191 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
193 /* the ptr to store the created handle is always needed */
194 hr = WerReportCreate(L"APPCRASH", WerReportCritical, NULL, NULL);
195 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
197 /* the event type must be a valid string */
198 report = (void *) 0xdeadbeef;
199 hr = WerReportCreate(NULL, WerReportCritical, NULL, &report);
200 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
202 report = (void *) 0xdeadbeef;
203 hr = WerReportCreate(L"", WerReportCritical, NULL, &report);
204 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
206 /* a valid WER_REPORT_TYPE works */
207 for (i = 0; i < WerReportInvalid; i++) {
208 report = (void *) 0xdeadbeef;
209 hr = WerReportCreate(L"APPCRASH", i, NULL, &report);
210 ok(hr == S_OK, "%d: got 0x%x and %p (expected S_OK)\n", i, hr, report);
212 hr = WerReportCloseHandle(report);
213 ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
217 /* values for WER_REPORT_TYPE are checked and invalid values are rejected since recent win10,
218 but older windows versions did not check the report type and WerReportCreate always succeeded */
220 report = (void *) 0xdeadbeef;
221 hr = WerReportCreate(L"APPCRASH", WerReportInvalid, NULL, &report);
222 ok((hr == E_INVALIDARG) | broken(hr == S_OK),
223 "%d: got 0x%x and %p (expected E_INVALIDARG or a broken S_OK)\n", i, hr, report);
224 if (hr == S_OK) {
225 hr = WerReportCloseHandle(report);
226 ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
229 report = (void *) 0xdeadbeef;
230 hr = WerReportCreate(L"APPCRASH", 42, NULL, &report);
231 ok((hr == E_INVALIDARG) | broken(hr == S_OK),
232 "%d: got 0x%x and %p (expected E_INVALIDARG or a broken S_OK)\n", i, hr, report);
233 if (hr == S_OK) {
234 hr = WerReportCloseHandle(report);
235 ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
238 /* multiple active reports are possible */
239 memset(table, 0, sizeof(table));
240 for (i = 0; i < (ARRAY_SIZE(table) - 1); i++) {
241 report = (void *) 0xdeadbeef;
242 hr = WerReportCreate(L"APPCRASH", WerReportCritical, NULL, &table[i]);
243 ok(hr == S_OK, "%02d: got 0x%x and %p (expected S_OK)\n", i, hr, table[i]);
246 while (i > 0) {
247 i--;
248 hr = WerReportCloseHandle(table[i]);
249 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, table[i]);
254 /* ########################### */
256 START_TEST(main)
258 test_WerAddExcludedApplication();
259 test_WerRemoveExcludedApplication();
260 test_WerReportCloseHandle();
261 test_WerReportCreate();