hlink: Site data should only be set if the hlink has an HlinkSite.
[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 empty[] = {0};
35 static const WCHAR winetest_wer[] = {'w','i','n','e','t','e','s','t','_','w','e','r','.','e','x','e',0};
36
37 /* ###### */
38
39 static void test_WerAddExcludedApplication(void)
40 {
41     HRESULT hr;
42
43     /* clean state */
44     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
45     if (hr == E_NOTIMPL) {
46         skip("Wer*ExcludedApplication not implemented\n");
47         return;
48     }
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);
51
52     hr = WerAddExcludedApplication(NULL, FALSE);
53     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
54
55     hr = WerAddExcludedApplication(empty, FALSE);
56     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
57
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);
63
64
65     /* cleanup */
66     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
67     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
68 }
69
70 /* #### */
71
72 static void test_WerRemoveExcludedApplication(void)
73 {
74     HRESULT hr;
75
76     /* clean state */
77     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
78     if (hr == E_NOTIMPL) {
79         skip("Wer*ExcludedApplication not implemented\n");
80         return;
81     }
82
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);
85
86     hr = WerAddExcludedApplication(winetest_wer, FALSE);
87     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
88
89     hr = WerRemoveExcludedApplication(NULL, FALSE);
90     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
91
92     hr = WerRemoveExcludedApplication(empty, FALSE);
93     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
94
95     hr = WerRemoveExcludedApplication(winetest_wer, FALSE);
96     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
97
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);
102
103 }
104
105 /* #### */
106
107 static void  test_WerReportCloseHandle(void)
108 {
109     HRESULT hr;
110     HREPORT report;
111
112     report = (void *) 0xdeadbeef;
113     hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
114     todo_wine
115     ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
116
117     if (!report) {
118         skip("Nothing left to test\n");
119         return;
120     }
121
122     /* close the handle */
123     hr = WerReportCloseHandle(report);
124     ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
125
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);
129
130     hr = WerReportCloseHandle(NULL);
131     ok(hr == E_INVALIDARG, "got 0x%x for NULL(expected E_INVALIDARG)\n", hr);
132 }
133
134 /* #### */
135
136 static void  test_WerReportCreate(void)
137 {
138     HRESULT hr;
139     HREPORT report;
140     HREPORT table[8];
141     int i;
142
143     report = (void *) 0xdeadbeef;
144     /* test a simple valid case */
145     hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report);
146
147     todo_wine
148     ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report);
149
150     if (!report) {
151         skip("Nothing left to test\n");
152         return;
153     }
154
155     hr = WerReportCloseHandle(report);
156     ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, report);
157
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);
161
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);
166
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);
170
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);
176
177         hr = WerReportCloseHandle(report);
178         ok(hr == S_OK, "%d: got 0x%x for %p (expected S_OK)\n", i, hr, report);
179
180     }
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);
184
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]);
191     }
192
193     while (i > 0) {
194         i--;
195         hr = WerReportCloseHandle(table[i]);
196         ok(hr == S_OK, "got 0x%x for %p (expected S_OK)\n", hr, table[i]);
197     }
198
199 }
200
201 /* ########################### */
202
203 START_TEST(main)
204 {
205     test_WerAddExcludedApplication();
206     test_WerRemoveExcludedApplication();
207     test_WerReportCloseHandle();
208     test_WerReportCreate();
209 }