wmp: Add seeking and duration.
[wine.git] / dlls / wer / tests / main.c
blobb10a8191c74e65de4e18dc40cc82401a7d966ba0
1 /*
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
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"
33 static const WCHAR appcrash[] = {'A','P','P','C','R','A','S','H',0};
34 static const WCHAR backslash[] = {'\\',0};
35 static const WCHAR empty[] = {0};
36 static const WCHAR winetest_wer[] = {'w','i','n','e','t','e','s','t','_','w','e','r','.','e','x','e',0};
38 /* ###### */
40 static void test_WerAddExcludedApplication(void)
42 HRESULT hr;
43 WCHAR buffer[MAX_PATH];
44 UINT res;
46 /* clean state */
47 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
48 ok((hr == S_OK) || (hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
49 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
51 hr = WerAddExcludedApplication(NULL, FALSE);
52 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
54 hr = WerAddExcludedApplication(empty, FALSE);
55 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
57 hr = WerAddExcludedApplication(winetest_wer, FALSE);
58 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
59 /* app already in the list */
60 hr = WerAddExcludedApplication(winetest_wer, FALSE);
61 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
64 /* cleanup */
65 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
66 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
68 /* appname has a path */
69 res = GetWindowsDirectoryW(buffer, sizeof(buffer) / sizeof(buffer[0]));
70 if (res > 0) {
71 /* the last part from the path is added to the inclusion list */
72 hr = WerAddExcludedApplication(buffer, FALSE);
73 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
74 hr = WerRemoveExcludedApplication(buffer, FALSE);
75 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
77 lstrcatW(buffer, backslash);
78 hr = WerAddExcludedApplication(buffer, FALSE);
79 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
81 lstrcatW(buffer, winetest_wer);
82 hr = WerAddExcludedApplication(buffer, FALSE);
83 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
84 hr = WerRemoveExcludedApplication(buffer, FALSE);
85 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
90 /* #### */
92 static void test_WerRemoveExcludedApplication(void)
94 HRESULT hr;
95 WCHAR buffer[MAX_PATH];
96 UINT res;
98 /* clean state */
99 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
100 ok((hr == S_OK) || (hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
101 "got 0x%x (expected S_OK, E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
103 hr = WerAddExcludedApplication(winetest_wer, FALSE);
104 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
106 hr = WerRemoveExcludedApplication(NULL, FALSE);
107 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
109 hr = WerRemoveExcludedApplication(empty, FALSE);
110 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
112 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
113 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
115 /* app not in the list */
116 hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
117 ok((hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
118 "got 0x%x (expected E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
120 /* appname has a path */
121 res = GetWindowsDirectoryW(buffer, sizeof(buffer) / sizeof(buffer[0]));
122 if (res > 0) {
123 hr = WerRemoveExcludedApplication(buffer, FALSE);
124 ok((hr == E_FAIL) || (hr == __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND)),
125 "got 0x%x (expected E_FAIL or HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND))\n", hr);
127 /* the last part from the path is added to the inclusion list */
128 hr = WerAddExcludedApplication(buffer, FALSE);
129 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
130 hr = WerRemoveExcludedApplication(buffer, FALSE);
131 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
133 lstrcatW(buffer, backslash);
134 hr = WerAddExcludedApplication(buffer, FALSE);
135 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
136 hr = WerRemoveExcludedApplication(buffer, FALSE);
137 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
139 lstrcatW(buffer, winetest_wer);
140 hr = WerAddExcludedApplication(buffer, FALSE);
141 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
142 hr = WerRemoveExcludedApplication(buffer, FALSE);
143 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
147 /* #### */
149 static void test_WerReportCloseHandle(void)
151 HRESULT hr;
152 HREPORT report;
154 report = (void *) 0xdeadbeef;
155 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
156 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
158 if (!report) {
159 skip("Nothing left to test\n");
160 return;
163 /* close the handle */
164 hr = WerReportCloseHandle(report);
165 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
167 /* close the handle again */
168 hr = WerReportCloseHandle(report);
169 ok(hr == E_INVALIDARG, "got 0x%x for %p again (expected E_INVALIDARG)\n", hr, report);
171 hr = WerReportCloseHandle(NULL);
172 ok(hr == E_INVALIDARG, "got 0x%x for NULL(expected E_INVALIDARG)\n", hr);
175 /* #### */
177 static void test_WerReportCreate(void)
179 HRESULT hr;
180 HREPORT report;
181 HREPORT table[8];
182 int i;
184 report = (void *) 0xdeadbeef;
185 /* test a simple valid case */
186 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
187 ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
189 if (!report) {
190 skip("Nothing left to test\n");
191 return;
194 hr = WerReportCloseHandle(report);
195 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
197 /* the ptr to store the created handle is always needed */
198 hr = WerReportCreate(appcrash, WerReportCritical, NULL, NULL);
199 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
201 /* the event type must be a valid string */
202 report = (void *) 0xdeadbeef;
203 hr = WerReportCreate(NULL, WerReportCritical, NULL, &report);
204 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
206 report = (void *) 0xdeadbeef;
207 hr = WerReportCreate(empty, WerReportCritical, NULL, &report);
208 ok(hr == E_INVALIDARG, "got 0x%x and %p(expected E_INVALIDARG)\n", hr, report);
210 /* WER_REPORT_TYPE is not checked during WerReportCreate */
211 for (i = 0; i <= WerReportInvalid + 1; i++) {
212 report = (void *) 0xdeadbeef;
213 hr = WerReportCreate(appcrash, i, NULL, &report);
214 ok(hr == S_OK, "%d: got 0x%x and %p (expected S_OK)\n", i, hr, report);
216 hr = WerReportCloseHandle(report);
217 ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
220 report = (void *) 0xdeadbeef;
221 hr = WerReportCreate(appcrash, 42, NULL, &report);
222 ok(hr == S_OK, "42: got 0x%x and %p (expected S_OK)\n", hr, report);
224 /* multiple active reports are possible */
225 memset(table, 0, sizeof(table));
226 for (i = 0; i < (sizeof(table) / sizeof(table[0]) -1); i++) {
227 report = (void *) 0xdeadbeef;
228 hr = WerReportCreate(appcrash, WerReportCritical, NULL, &table[i]);
229 ok(hr == S_OK, "%02d: got 0x%x and %p (expected S_OK)\n", i, hr, table[i]);
232 while (i > 0) {
233 i--;
234 hr = WerReportCloseHandle(table[i]);
235 ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, table[i]);
240 /* ########################### */
242 START_TEST(main)
244 test_WerAddExcludedApplication();
245 test_WerRemoveExcludedApplication();
246 test_WerReportCloseHandle();
247 test_WerReportCreate();