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 /* copied from libs/wine/string.c */
36 WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
40 const WCHAR *p1 = str, *p2 = sub;
41 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
42 if (!*p2) return (WCHAR *)str;
48 static void test_getstring_bad(void)
53 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, open, NULL, &len);
54 expect_hr(E_INVALIDARG, hr);
55 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, badBad, open, NULL, &len);
56 expect_hr(E_FAIL, hr);
57 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotBad, open, NULL, &len);
58 expect_hr(E_FAIL, hr);
59 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, invalid, NULL,
61 expect_hr(0x80070002, hr); /* NOT FOUND */
62 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, NULL);
63 expect_hr(E_UNEXPECTED, hr);
65 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, open, NULL, &len);
66 expect_hr(E_INVALIDARG, hr);
67 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, badBad, open, NULL,
69 expect_hr(E_FAIL, hr);
70 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotBad, open, NULL,
72 expect_hr(E_FAIL, hr);
73 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, invalid, NULL,
75 expect_hr(0x80070002, hr); /* NOT FOUND */
76 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
78 expect_hr(E_UNEXPECTED, hr);
81 static void test_getstring_basic(void)
85 WCHAR * executableName;
86 DWORD len, len2, slen;
88 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
89 expect_hr(S_FALSE, hr);
92 skip("failed to get initial len\n");
96 executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
100 skip("failed to allocate memory\n");
105 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
106 executableName, &len2);
108 slen = lstrlenW(executableName) + 1;
112 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
114 expect_hr(S_FALSE, hr);
117 HeapFree(GetProcessHeap(), 0, executableName);
118 skip("failed to get initial len\n");
122 friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
123 len * sizeof(WCHAR));
126 HeapFree(GetProcessHeap(), 0, executableName);
127 skip("failed to allocate memory\n");
132 hr = AssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
133 friendlyName, &len2);
135 slen = lstrlenW(friendlyName) + 1;
139 HeapFree(GetProcessHeap(), 0, executableName);
140 HeapFree(GetProcessHeap(), 0, friendlyName);
143 static void test_getstring_no_extra(void)
148 static const WCHAR dotWinetest[] = {
149 '.','w','i','n','e','t','e','s','t',0
151 static const WCHAR winetestfile[] = {
152 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
154 static const WCHAR winetestfileAction[] = {
155 'w','i','n','e','t','e','s','t','f','i','l','e',
156 '\\','s','h','e','l','l',
158 '\\','c','o','m','m','a','n','d',0
160 static const WCHAR action[] = {
161 'n','o','t','e','p','a','d','.','e','x','e',0
164 DWORD len = MAX_PATH;
166 ret = RegCreateKeyW(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
167 if (ret != ERROR_SUCCESS)
168 skip("failed to create dotWinetest key\n");
169 ret = RegSetValueW(hkey, NULL, REG_SZ, winetestfile,
170 lstrlenW(winetestfile));
172 if (ret != ERROR_SUCCESS)
174 RegDeleteTreeW(HKEY_CLASSES_ROOT, dotWinetest);
175 skip("failed to set dotWinetest key\n");
178 ret = RegCreateKeyW(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
179 if (ret != ERROR_SUCCESS)
181 RegDeleteTreeW(HKEY_CLASSES_ROOT, dotWinetest);
182 skip("failed to create winetestfileAction key\n");
184 ret = RegSetValueW(hkey, NULL, REG_SZ, action, lstrlenW(action));
186 if (ret != ERROR_SUCCESS)
188 RegDeleteTreeW(HKEY_CLASSES_ROOT, dotWinetest);
189 RegDeleteTreeW(HKEY_CLASSES_ROOT, winetestfile);
190 skip("failed to set winetestfileAction key\n");
193 hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL,
196 ok(strstrW(buf, action) != NULL, "exe path does not contain notepad\n");
197 RegDeleteTreeW(HKEY_CLASSES_ROOT, dotWinetest);
198 RegDeleteTreeW(HKEY_CLASSES_ROOT, winetestfile);
203 test_getstring_bad();
204 test_getstring_basic();
205 test_getstring_no_extra();