2 * Unit test suite for windows error reporting in Vista and above
4 * Copyright 2010 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
31 #include "wine/test.h"
33 static const WCHAR appcrash[] = {'A','P','P','C','R','A','S','H',0};
34 static const WCHAR empty[] = {0};
35 static const WCHAR winetest_wer[] = {'w','i','n','e','t','e','s','t','_','w','e','r','.','e','x','e',0};
39 static void test_WerAddExcludedApplication(void)
44 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
45 if (hr == E_NOTIMPL) {
46 skip("Wer*ExcludedApplication not implemented\n");
49 ok((hr == S_OK) || (hr == E_FAIL) || __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND),
50 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
52 hr = WerAddExcludedApplication(NULL, FALSE);
53 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
55 hr = WerAddExcludedApplication(empty, FALSE);
56 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
58 hr = WerAddExcludedApplication(winetest_wer, FALSE);
59 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
60 /* app already in the list */
61 hr = WerAddExcludedApplication(winetest_wer, FALSE);
62 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
66 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
67 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
72 static void test_WerRemoveExcludedApplication(void)
77 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
78 if (hr == E_NOTIMPL) {
79 skip("Wer*ExcludedApplication not implemented\n");
83 ok((hr == S_OK) || (hr == E_FAIL) || __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND),
84 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
86 hr = WerAddExcludedApplication(winetest_wer, FALSE);
87 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
89 hr = WerRemoveExcludedApplication(NULL, FALSE);
90 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
92 hr = WerRemoveExcludedApplication(empty, FALSE);
93 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
95 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
96 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
98 /* app not in the list */
99 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
100 ok((hr == E_FAIL) || __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND),
101 "got 0x%x (expected E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
107 static void test_WerReportCloseHandle(void)
112 report = (void *) 0xdeadbeef;
113 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
115 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
118 skip("Nothing left to test\n");
122 /* close the handle */
123 hr = WerReportCloseHandle(report);
124 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
126 /* close the handle again */
127 hr = WerReportCloseHandle(report);
128 ok(hr == E_INVALIDARG, "got 0x%x for %p again (expected E_INVALIDARG)\n", hr, report);
130 hr = WerReportCloseHandle(NULL);
131 ok(hr == E_INVALIDARG, "got 0x%x for NULL(expected E_INVALIDARG)\n", hr);
136 static void test_WerReportCreate(void)
143 report = (void *) 0xdeadbeef;
144 /* test a simple valid case */
145 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
148 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
151 skip("Nothing left to test\n");
155 hr = WerReportCloseHandle(report);
156 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
158 /* the ptr to store the created handle is always needed */
159 hr = WerReportCreate(appcrash, WerReportCritical, NULL, NULL);
160 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
162 /* the event type must be a valid string */
163 report = (void *) 0xdeadbeef;
164 hr = WerReportCreate(NULL, WerReportCritical, NULL, &report);
165 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
167 report = (void *) 0xdeadbeef;
168 hr = WerReportCreate(empty, WerReportCritical, NULL, &report);
169 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
171 /* WER_REPORT_TYPE is not checked during WerReportCreate */
172 for (i = 0; i <= WerReportInvalid + 1; i++) {
173 report = (void *) 0xdeadbeef;
174 hr = WerReportCreate(appcrash, i, NULL, &report);
175 ok(hr == S_OK, "%d: got 0x%x and %p (expected S_OK)\n", i, hr, report);
177 hr = WerReportCloseHandle(report);
178 ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
181 report = (void *) 0xdeadbeef;
182 hr = WerReportCreate(appcrash, 42, NULL, &report);
183 ok(hr == S_OK, "42: got 0x%x and %p (expected S_OK)\n", hr, report);
185 /* multiple active reports are possible */
186 memset(table, 0, sizeof(table));
187 for (i = 0; i < (sizeof(table) / sizeof(table[0]) -1); i++) {
188 report = (void *) 0xdeadbeef;
189 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &table[i]);
190 ok(hr == S_OK, "%02d: got 0x%x and %p (expected S_OK)\n", i, hr, table[i]);
195 hr = WerReportCloseHandle(table[i]);
196 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, table[i]);
201 /* ########################### */
205 test_WerAddExcludedApplication();
206 test_WerRemoveExcludedApplication();
207 test_WerReportCloseHandle();
208 test_WerReportCreate();