2 * Unit tests for IShellDispatch
4 * Copyright 2010 Alexander Morozov for Etersoft
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.
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.
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
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
28 #include "wine/test.h"
30 static HRESULT (WINAPI *pSHGetFolderPathW)(HWND, int, HANDLE, DWORD, LPWSTR);
31 static HRESULT (WINAPI *pSHGetNameFromIDList)(PCIDLIST_ABSOLUTE,SIGDN,PWSTR*);
32 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
33 static DWORD (WINAPI *pGetLongPathNameW)(LPCWSTR, LPWSTR, DWORD);
35 static void init_function_pointers(void)
37 HMODULE hshell32, hkernel32;
39 hshell32 = GetModuleHandleA("shell32.dll");
40 hkernel32 = GetModuleHandleA("kernel32.dll");
41 pSHGetFolderPathW = (void*)GetProcAddress(hshell32, "SHGetFolderPathW");
42 pSHGetNameFromIDList = (void*)GetProcAddress(hshell32, "SHGetNameFromIDList");
43 pSHGetSpecialFolderLocation = (void*)GetProcAddress(hshell32,
44 "SHGetSpecialFolderLocation");
45 pGetLongPathNameW = (void*)GetProcAddress(hkernel32, "GetLongPathNameW");
48 static void test_namespace(void)
50 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
51 static const WCHAR backslashW[] = {'\\',0};
52 static const WCHAR clsidW[] = {
53 ':',':','{','6','4','5','F','F','0','4','0','-','5','0','8','1','-',
54 '1','0','1','B','-','9','F','0','8','-',
55 '0','0','A','A','0','0','2','F','9','5','4','E','}',0};
57 static WCHAR tempW[MAX_PATH], curW[MAX_PATH];
58 WCHAR *long_pathW = NULL;
65 BSTR title, item_path;
68 r = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
69 &IID_IShellDispatch, (LPVOID*)&sd);
70 if (r == REGDB_E_CLASSNOTREG) /* NT4 */
72 win_skip("skipping IShellDispatch tests\n");
75 ok(SUCCEEDED(r), "CoCreateInstance failed: %08x\n", r);
80 folder = (void*)0xdeadbeef;
81 r = IShellDispatch_NameSpace(sd, var, &folder);
82 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
83 ok(folder == NULL, "expected NULL, got %p\n", folder);
87 folder = (void*)0xdeadbeef;
88 r = IShellDispatch_NameSpace(sd, var, &folder);
90 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
91 ok(folder == NULL, "got %p\n", folder);
94 V_I4(&var) = ssfPROGRAMFILES;
95 r = IShellDispatch_NameSpace(sd, var, &folder);
97 broken(r == S_FALSE), /* NT4 */
98 "IShellDispatch::NameSpace failed: %08x\n", r);
101 static WCHAR path[MAX_PATH];
103 if (pSHGetFolderPathW)
105 r = pSHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL,
106 SHGFP_TYPE_CURRENT, path);
107 ok(r == S_OK, "SHGetFolderPath failed: %08x\n", r);
109 r = Folder_get_Title(folder, &title);
111 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
114 /* On Win2000-2003 title is equal to program files directory name in
115 HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir.
116 On newer Windows it seems constant and is not changed
117 if the program files directory name is changed */
118 if (pSHGetSpecialFolderLocation && pSHGetNameFromIDList)
123 r = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl);
124 ok(r == S_OK, "SHGetSpecialFolderLocation failed: %08x\n", r);
125 r = pSHGetNameFromIDList(pidl, SIGDN_NORMALDISPLAY, &name);
126 ok(r == S_OK, "SHGetNameFromIDList failed: %08x\n", r);
128 ok(!lstrcmpW(title, name), "expected %s, got %s\n",
129 wine_dbgstr_w(name), wine_dbgstr_w(title));
133 else if (pSHGetFolderPathW)
137 p = path + lstrlenW(path);
138 while (path < p && *(p - 1) != '\\')
140 ok(!lstrcmpW(title, p), "expected %s, got %s\n",
141 wine_dbgstr_w(p), wine_dbgstr_w(title));
143 else skip("skipping Folder::get_Title test\n");
144 SysFreeString(title);
146 r = Folder_QueryInterface(folder, &IID_Folder2, (LPVOID*)&folder2);
147 ok(r == S_OK, "Folder::QueryInterface failed: %08x\n", r);
150 r = Folder2_get_Self(folder2, &item);
151 ok(r == S_OK, "Folder::get_Self failed: %08x\n", r);
154 r = FolderItem_get_Path(item, &item_path);
155 ok(r == S_OK, "FolderItem::get_Path failed: %08x\n", r);
156 if (pSHGetFolderPathW)
157 ok(!lstrcmpW(item_path, path), "expected %s, got %s\n",
158 wine_dbgstr_w(path), wine_dbgstr_w(item_path));
159 SysFreeString(item_path);
160 FolderItem_Release(item);
162 Folder2_Release(folder2);
164 Folder_Release(folder);
168 V_I4(&var) = ssfBITBUCKET;
169 r = IShellDispatch_NameSpace(sd, var, &folder);
171 broken(r == S_FALSE), /* NT4 */
172 "IShellDispatch::NameSpace failed: %08x\n", r);
175 r = Folder_QueryInterface(folder, &IID_Folder2, (LPVOID*)&folder2);
177 broken(r == E_NOINTERFACE), /* NT4 */
178 "Folder::QueryInterface failed: %08x\n", r);
181 r = Folder2_get_Self(folder2, &item);
182 ok(r == S_OK, "Folder::get_Self failed: %08x\n", r);
185 r = FolderItem_get_Path(item, &item_path);
187 ok(r == S_OK, "FolderItem::get_Path failed: %08x\n", r);
189 ok(!lstrcmpW(item_path, clsidW), "expected %s, got %s\n",
190 wine_dbgstr_w(clsidW), wine_dbgstr_w(item_path));
191 SysFreeString(item_path);
192 FolderItem_Release(item);
194 Folder2_Release(folder2);
196 Folder_Release(folder);
199 GetTempPathW(MAX_PATH, tempW);
200 GetCurrentDirectoryW(MAX_PATH, curW);
201 SetCurrentDirectoryW(tempW);
202 CreateDirectoryW(winetestW, NULL);
203 V_VT(&var) = VT_BSTR;
204 V_BSTR(&var) = SysAllocString(winetestW);
205 r = IShellDispatch_NameSpace(sd, var, &folder);
206 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
207 SysFreeString(V_BSTR(&var));
209 GetFullPathNameW(winetestW, MAX_PATH, tempW, NULL);
210 if (pGetLongPathNameW)
212 len = pGetLongPathNameW(tempW, NULL, 0);
213 long_pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
215 pGetLongPathNameW(tempW, long_pathW, len);
217 V_VT(&var) = VT_BSTR;
218 V_BSTR(&var) = SysAllocString(tempW);
219 r = IShellDispatch_NameSpace(sd, var, &folder);
220 ok(r == S_OK, "IShellDispatch::NameSpace failed: %08x\n", r);
223 r = Folder_get_Title(folder, &title);
224 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
227 ok(!lstrcmpW(title, winetestW), "bad title: %s\n",
228 wine_dbgstr_w(title));
229 SysFreeString(title);
231 r = Folder_QueryInterface(folder, &IID_Folder2, (LPVOID*)&folder2);
233 broken(r == E_NOINTERFACE), /* NT4 */
234 "Folder::QueryInterface failed: %08x\n", r);
237 r = Folder2_get_Self(folder2, &item);
238 ok(r == S_OK, "Folder::get_Self failed: %08x\n", r);
241 r = FolderItem_get_Path(item, &item_path);
242 ok(r == S_OK, "FolderItem::get_Path failed: %08x\n", r);
244 ok(!lstrcmpW(item_path, long_pathW),
245 "expected %s, got %s\n", wine_dbgstr_w(long_pathW),
246 wine_dbgstr_w(item_path));
247 SysFreeString(item_path);
248 FolderItem_Release(item);
250 Folder2_Release(folder2);
252 Folder_Release(folder);
254 SysFreeString(V_BSTR(&var));
256 len = lstrlenW(tempW);
257 if (len < MAX_PATH - 1)
259 lstrcatW(tempW, backslashW);
260 V_VT(&var) = VT_BSTR;
261 V_BSTR(&var) = SysAllocString(tempW);
262 r = IShellDispatch_NameSpace(sd, var, &folder);
263 ok(r == S_OK, "IShellDispatch::NameSpace failed: %08x\n", r);
266 r = Folder_get_Title(folder, &title);
267 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
270 ok(!lstrcmpW(title, winetestW), "bad title: %s\n",
271 wine_dbgstr_w(title));
272 SysFreeString(title);
274 r = Folder_QueryInterface(folder, &IID_Folder2, (LPVOID*)&folder2);
276 broken(r == E_NOINTERFACE), /* NT4 */
277 "Folder::QueryInterface failed: %08x\n", r);
280 r = Folder2_get_Self(folder2, &item);
281 ok(r == S_OK, "Folder::get_Self failed: %08x\n", r);
284 r = FolderItem_get_Path(item, &item_path);
285 ok(r == S_OK, "FolderItem::get_Path failed: %08x\n", r);
287 ok(!lstrcmpW(item_path, long_pathW),
288 "expected %s, got %s\n", wine_dbgstr_w(long_pathW),
289 wine_dbgstr_w(item_path));
290 SysFreeString(item_path);
291 FolderItem_Release(item);
293 Folder2_Release(folder2);
295 Folder_Release(folder);
297 SysFreeString(V_BSTR(&var));
300 HeapFree(GetProcessHeap(), 0, long_pathW);
301 RemoveDirectoryW(winetestW);
302 SetCurrentDirectoryW(curW);
303 IShellDispatch_Release(sd);
306 START_TEST(shelldispatch)
310 r = CoInitialize(NULL);
311 ok(SUCCEEDED(r), "CoInitialize failed: %08x\n", r);
315 init_function_pointers();