uxtheme: Fixed the todo blocks in the IsThemed tests when theming is inactive.
[wine] / dlls / shlwapi / tests / assoc.c
1 /* Unit test suite for SHLWAPI IQueryAssociations functions
2  *
3  * Copyright 2008 Google (Lei Zhang)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include <stdarg.h>
21
22 #include "wine/test.h"
23 #include "shlwapi.h"
24
25 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
26 #define expect_hr(expected, got) ok ( expected == got, "Expected %08x, got %08x\n", expected, got)
27
28 /* Every version of Windows with IE should have this association? */
29 static const WCHAR dotHtml[] = { '.','h','t','m','l',0 };
30 static const WCHAR badBad[] = { 'b','a','d','b','a','d',0 };
31 static const WCHAR dotBad[] = { '.','b','a','d',0 };
32 static const WCHAR open[] = { 'o','p','e','n',0 };
33 static const WCHAR invalid[] = { 'i','n','v','a','l','i','d',0 };
34
35 static void test_getstring_bad(void)
36 {
37     HRESULT hr;
38     DWORD len;
39
40     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, open, NULL, &len);
41     expect_hr(E_INVALIDARG, hr);
42     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, badBad, open, NULL, &len);
43     ok(hr == E_FAIL ||
44        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
45        "Unexpected result : %08x\n", hr);
46     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotBad, open, NULL, &len);
47     ok(hr == E_FAIL ||
48        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
49        "Unexpected result : %08x\n", hr);
50     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, invalid, NULL,
51                            &len);
52     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
53        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
54        "Unexpected result : %08x\n", hr);
55     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, NULL);
56     ok(hr == E_UNEXPECTED ||
57        hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
58        "Unexpected result : %08x\n", hr);
59
60     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, open, NULL, &len);
61     expect_hr(E_INVALIDARG, hr);
62     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, badBad, open, NULL,
63                            &len);
64     ok(hr == E_FAIL ||
65        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
66        "Unexpected result : %08x\n", hr);
67     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotBad, open, NULL,
68                            &len);
69     ok(hr == E_FAIL ||
70        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
71        "Unexpected result : %08x\n", hr);
72     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, invalid, NULL,
73                            &len);
74     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
75        hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || /* W2K/Vista/W2K8 */
76        hr == E_FAIL, /* Win9x/WinMe/NT4 */
77        "Unexpected result : %08x\n", hr);
78     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
79                            NULL);
80     ok(hr == E_UNEXPECTED ||
81        hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
82        "Unexpected result : %08x\n", hr);
83 }
84
85 static void test_getstring_basic(void)
86 {
87     HRESULT hr;
88     WCHAR * friendlyName;
89     WCHAR * executableName;
90     DWORD len, len2, slen;
91
92     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
93     expect_hr(S_FALSE, hr);
94     if (hr != S_FALSE)
95     {
96         skip("failed to get initial len\n");
97         return;
98     }
99
100     executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
101                                len * sizeof(WCHAR));
102     if (!executableName)
103     {
104         skip("failed to allocate memory\n");
105         return;
106     }
107
108     len2 = len;
109     hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
110                            executableName, &len2);
111     expect_hr(S_OK, hr);
112     slen = lstrlenW(executableName) + 1;
113     expect(len, len2);
114     expect(len, slen);
115
116     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
117                            &len);
118     expect_hr(S_FALSE, hr);
119     if (hr != S_FALSE)
120     {
121         HeapFree(GetProcessHeap(), 0, executableName);
122         skip("failed to get initial len\n");
123         return;
124     }
125
126     friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
127                                len * sizeof(WCHAR));
128     if (!friendlyName)
129     {
130         HeapFree(GetProcessHeap(), 0, executableName);
131         skip("failed to allocate memory\n");
132         return;
133     }
134
135     len2 = len;
136     hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
137                            friendlyName, &len2);
138     expect_hr(S_OK, hr);
139     slen = lstrlenW(friendlyName) + 1;
140     expect(len, len2);
141     expect(len, slen);
142
143     HeapFree(GetProcessHeap(), 0, executableName);
144     HeapFree(GetProcessHeap(), 0, friendlyName);
145 }
146
147 static void test_getstring_no_extra(void)
148 {
149     LONG ret;
150     HKEY hkey;
151     HRESULT hr;
152     static const CHAR dotWinetest[] = {
153         '.','w','i','n','e','t','e','s','t',0
154     };
155     static const CHAR winetestfile[] = {
156         'w','i','n','e','t','e','s','t', 'f','i','l','e',0
157     };
158     static const CHAR winetestfileAction[] = {
159         'w','i','n','e','t','e','s','t','f','i','l','e',
160         '\\','s','h','e','l','l',
161         '\\','f','o','o',
162         '\\','c','o','m','m','a','n','d',0
163     };
164     static const CHAR action[] = {
165         'n','o','t','e','p','a','d','.','e','x','e',0
166     };
167     CHAR buf[MAX_PATH];
168     DWORD len = MAX_PATH;
169
170     buf[0] = '\0';
171     ret = RegCreateKeyA(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
172     if (ret != ERROR_SUCCESS) {
173         skip("failed to create dotWinetest key\n");
174         return;
175     }
176
177     ret = RegSetValueA(hkey, NULL, REG_SZ, winetestfile, lstrlenA(winetestfile));
178     RegCloseKey(hkey);
179     if (ret != ERROR_SUCCESS)
180     {
181         skip("failed to set dotWinetest key\n");
182         goto cleanup;
183     }
184
185     ret = RegCreateKeyA(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
186     if (ret != ERROR_SUCCESS)
187     {
188         skip("failed to create winetestfileAction key\n");
189         goto cleanup;
190     }
191
192     ret = RegSetValueA(hkey, NULL, REG_SZ, action, lstrlenA(action));
193     RegCloseKey(hkey);
194     if (ret != ERROR_SUCCESS)
195     {
196         skip("failed to set winetestfileAction key\n");
197         goto cleanup;
198     }
199
200     hr = AssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL, buf, &len);
201     expect_hr(S_OK, hr);
202     ok(strstr(buf, action) != NULL,
203         "got '%s' (Expected result to include 'notepad.exe')\n", buf);
204
205 cleanup:
206     SHDeleteKeyA(HKEY_CLASSES_ROOT, dotWinetest);
207     SHDeleteKeyA(HKEY_CLASSES_ROOT, winetestfile);
208
209 }
210
211 START_TEST(assoc)
212 {
213     test_getstring_bad();
214     test_getstring_basic();
215     test_getstring_no_extra();
216 }