shell32: Try to get file status from FileSystemBindData in UNIXFS_path_to_pidl.
[wine] / dlls / wer / tests / main.c
1 /*
2  * Unit test suite for windows error reporting in Vista and above
3  *
4  * Copyright 2010 Detlef Riekenberg
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
29
30 #include "werapi.h"
31 #include "wine/test.h"
32
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};
37
38 /* ###### */
39
40 static void test_WerAddExcludedApplication(void)
41 {
42     HRESULT hr;
43     WCHAR buffer[MAX_PATH];
44     UINT res;
45
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);
50
51     hr = WerAddExcludedApplication(NULL, FALSE);
52     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
53
54     hr = WerAddExcludedApplication(empty, FALSE);
55     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
56
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);
62
63
64     /* cleanup */
65     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
66     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
67
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);
76
77         lstrcatW(buffer, backslash);
78         hr = WerAddExcludedApplication(buffer, FALSE);
79         ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
80
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);
86     }
87
88 }
89
90 /* #### */
91
92 static void test_WerRemoveExcludedApplication(void)
93 {
94     HRESULT hr;
95     WCHAR buffer[MAX_PATH];
96     UINT res;
97
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);
102
103     hr = WerAddExcludedApplication(winetest_wer, FALSE);
104     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
105
106     hr = WerRemoveExcludedApplication(NULL, FALSE);
107     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
108
109     hr = WerRemoveExcludedApplication(empty, FALSE);
110     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
111
112     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
113     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
114
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);
119
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);
126
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);
132
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);
138
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);
144     }
145 }
146
147 /* #### */
148
149 static void  test_WerReportCloseHandle(void)
150 {
151     HRESULT hr;
152     HREPORT report;
153
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);
157
158     if (!report) {
159         skip("Nothing left to test\n");
160         return;
161     }
162
163     /* close the handle */
164     hr = WerReportCloseHandle(report);
165     ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
166
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);
170
171     hr = WerReportCloseHandle(NULL);
172     ok(hr == E_INVALIDARG, "got 0x%x for NULL(expected E_INVALIDARG)\n", hr);
173 }
174
175 /* #### */
176
177 static void  test_WerReportCreate(void)
178 {
179     HRESULT hr;
180     HREPORT report;
181     HREPORT table[8];
182     int i;
183
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);
188
189     if (!report) {
190         skip("Nothing left to test\n");
191         return;
192     }
193
194     hr = WerReportCloseHandle(report);
195     ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
196
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);
200
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);
205
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);
209
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);
215
216         hr = WerReportCloseHandle(report);
217         ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
218
219     }
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);
223
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]);
230     }
231
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]);
236     }
237
238 }
239
240 /* ########################### */
241
242 START_TEST(main)
243 {
244     test_WerAddExcludedApplication();
245     test_WerRemoveExcludedApplication();
246     test_WerReportCloseHandle();
247     test_WerReportCreate();
248 }