1 /* Unit test suite for SHLWAPI IQueryAssociations functions
3 * Copyright 2008 Google (Lei Zhang)
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.
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.
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
22 #include "wine/test.h"
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)
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 };
35 static void test_getstring_bad(void)
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);
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);
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,
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);
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,
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,
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,
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,
80 ok(hr == E_UNEXPECTED ||
81 hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
82 "Unexpected result : %08x\n", hr);
85 static void test_getstring_basic(void)
89 WCHAR * executableName;
90 DWORD len, len2, slen;
92 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
93 expect_hr(S_FALSE, hr);
96 skip("failed to get initial len\n");
100 executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
101 len * sizeof(WCHAR));
104 skip("failed to allocate memory\n");
109 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
110 executableName, &len2);
112 slen = lstrlenW(executableName) + 1;
116 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
118 expect_hr(S_FALSE, hr);
121 HeapFree(GetProcessHeap(), 0, executableName);
122 skip("failed to get initial len\n");
126 friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
127 len * sizeof(WCHAR));
130 HeapFree(GetProcessHeap(), 0, executableName);
131 skip("failed to allocate memory\n");
136 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
137 friendlyName, &len2);
139 slen = lstrlenW(friendlyName) + 1;
143 HeapFree(GetProcessHeap(), 0, executableName);
144 HeapFree(GetProcessHeap(), 0, friendlyName);
147 static void test_getstring_no_extra(void)
152 static const CHAR dotWinetest[] = {
153 '.','w','i','n','e','t','e','s','t',0
155 static const CHAR winetestfile[] = {
156 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
158 static const CHAR winetestfileAction[] = {
159 'w','i','n','e','t','e','s','t','f','i','l','e',
160 '\\','s','h','e','l','l',
162 '\\','c','o','m','m','a','n','d',0
164 static const CHAR action[] = {
165 'n','o','t','e','p','a','d','.','e','x','e',0
168 DWORD len = MAX_PATH;
171 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
172 if (ret != ERROR_SUCCESS) {
173 skip("failed to create dotWinetest key\n");
177 ret = RegSetValueA(hkey, NULL, REG_SZ, winetestfile, lstrlenA(winetestfile));
179 if (ret != ERROR_SUCCESS)
181 skip("failed to set dotWinetest key\n");
185 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
186 if (ret != ERROR_SUCCESS)
188 skip("failed to create winetestfileAction key\n");
192 ret = RegSetValueA(hkey, NULL, REG_SZ, action, lstrlenA(action));
194 if (ret != ERROR_SUCCESS)
196 skip("failed to set winetestfileAction key\n");
200 hr = AssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL, buf, &len);
202 ok(strstr(buf, action) != NULL,
203 "got '%s' (Expected result to include 'notepad.exe')\n", buf);
206 SHDeleteKeyA(HKEY_CLASSES_ROOT, dotWinetest);
207 SHDeleteKeyA(HKEY_CLASSES_ROOT, winetestfile);
213 test_getstring_bad();
214 test_getstring_basic();
215 test_getstring_no_extra();