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 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
89 ok(r
== S_FALSE
, "expected S_FALSE, got %08x\n", r
);
92 V_I4(&var
) = ssfPROGRAMFILES
;
93 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
95 broken(r
== S_FALSE
), /* NT4 */
96 "IShellDispatch::NameSpace failed: %08x\n", r
);
99 static WCHAR path
[MAX_PATH
];
101 if (pSHGetFolderPathW
)
103 r
= pSHGetFolderPathW(NULL
, CSIDL_PROGRAM_FILES
, NULL
,
104 SHGFP_TYPE_CURRENT
, path
);
105 ok(r
== S_OK
, "SHGetFolderPath failed: %08x\n", r
);
107 r
= Folder_get_Title(folder
, &title
);
109 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
112 /* On Win2000-2003 title is equal to program files directory name in
113 HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir.
114 On newer Windows it seems constant and is not changed
115 if the program files directory name is changed */
116 if (pSHGetSpecialFolderLocation
&& pSHGetNameFromIDList
)
121 r
= pSHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAM_FILES
, &pidl
);
122 ok(r
== S_OK
, "SHGetSpecialFolderLocation failed: %08x\n", r
);
123 r
= pSHGetNameFromIDList(pidl
, SIGDN_NORMALDISPLAY
, &name
);
124 ok(r
== S_OK
, "SHGetNameFromIDList failed: %08x\n", r
);
126 ok(!lstrcmpW(title
, name
), "expected %s, got %s\n",
127 wine_dbgstr_w(name
), wine_dbgstr_w(title
));
131 else if (pSHGetFolderPathW
)
135 p
= path
+ lstrlenW(path
);
136 while (path
< p
&& *(p
- 1) != '\\')
138 ok(!lstrcmpW(title
, p
), "expected %s, got %s\n",
139 wine_dbgstr_w(p
), wine_dbgstr_w(title
));
141 else skip("skipping Folder::get_Title test\n");
142 SysFreeString(title
);
144 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
145 ok(r
== S_OK
, "Folder::QueryInterface failed: %08x\n", r
);
148 r
= Folder2_get_Self(folder2
, &item
);
149 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
152 r
= FolderItem_get_Path(item
, &item_path
);
153 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
154 if (pSHGetFolderPathW
)
155 ok(!lstrcmpW(item_path
, path
), "expected %s, got %s\n",
156 wine_dbgstr_w(path
), wine_dbgstr_w(item_path
));
157 SysFreeString(item_path
);
158 FolderItem_Release(item
);
160 Folder2_Release(folder2
);
162 Folder_Release(folder
);
166 V_I4(&var
) = ssfBITBUCKET
;
167 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
169 broken(r
== S_FALSE
), /* NT4 */
170 "IShellDispatch::NameSpace failed: %08x\n", r
);
173 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
175 broken(r
== E_NOINTERFACE
), /* NT4 */
176 "Folder::QueryInterface failed: %08x\n", r
);
179 r
= Folder2_get_Self(folder2
, &item
);
180 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
183 r
= FolderItem_get_Path(item
, &item_path
);
185 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
187 ok(!lstrcmpW(item_path
, clsidW
), "expected %s, got %s\n",
188 wine_dbgstr_w(clsidW
), wine_dbgstr_w(item_path
));
189 SysFreeString(item_path
);
190 FolderItem_Release(item
);
192 Folder2_Release(folder2
);
194 Folder_Release(folder
);
197 GetTempPathW(MAX_PATH
, tempW
);
198 GetCurrentDirectoryW(MAX_PATH
, curW
);
199 SetCurrentDirectoryW(tempW
);
200 CreateDirectoryW(winetestW
, NULL
);
201 V_VT(&var
) = VT_BSTR
;
202 V_BSTR(&var
) = SysAllocString(winetestW
);
203 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
204 ok(r
== S_FALSE
, "expected S_FALSE, got %08x\n", r
);
205 SysFreeString(V_BSTR(&var
));
207 GetFullPathNameW(winetestW
, MAX_PATH
, tempW
, NULL
);
208 if (pGetLongPathNameW
)
210 len
= pGetLongPathNameW(tempW
, NULL
, 0);
211 long_pathW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
213 pGetLongPathNameW(tempW
, long_pathW
, len
);
215 V_VT(&var
) = VT_BSTR
;
216 V_BSTR(&var
) = SysAllocString(tempW
);
217 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
218 ok(r
== S_OK
, "IShellDispatch::NameSpace failed: %08x\n", r
);
221 r
= Folder_get_Title(folder
, &title
);
222 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
225 ok(!lstrcmpW(title
, winetestW
), "bad title: %s\n",
226 wine_dbgstr_w(title
));
227 SysFreeString(title
);
229 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
231 broken(r
== E_NOINTERFACE
), /* NT4 */
232 "Folder::QueryInterface failed: %08x\n", r
);
235 r
= Folder2_get_Self(folder2
, &item
);
236 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
239 r
= FolderItem_get_Path(item
, &item_path
);
240 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
242 ok(!lstrcmpW(item_path
, long_pathW
),
243 "expected %s, got %s\n", wine_dbgstr_w(long_pathW
),
244 wine_dbgstr_w(item_path
));
245 SysFreeString(item_path
);
246 FolderItem_Release(item
);
248 Folder2_Release(folder2
);
250 Folder_Release(folder
);
252 SysFreeString(V_BSTR(&var
));
254 len
= lstrlenW(tempW
);
255 if (len
< MAX_PATH
- 1)
257 lstrcatW(tempW
, backslashW
);
258 V_VT(&var
) = VT_BSTR
;
259 V_BSTR(&var
) = SysAllocString(tempW
);
260 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
261 ok(r
== S_OK
, "IShellDispatch::NameSpace failed: %08x\n", r
);
264 r
= Folder_get_Title(folder
, &title
);
265 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
268 ok(!lstrcmpW(title
, winetestW
), "bad title: %s\n",
269 wine_dbgstr_w(title
));
270 SysFreeString(title
);
272 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
274 broken(r
== E_NOINTERFACE
), /* NT4 */
275 "Folder::QueryInterface failed: %08x\n", r
);
278 r
= Folder2_get_Self(folder2
, &item
);
279 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
282 r
= FolderItem_get_Path(item
, &item_path
);
283 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
285 ok(!lstrcmpW(item_path
, long_pathW
),
286 "expected %s, got %s\n", wine_dbgstr_w(long_pathW
),
287 wine_dbgstr_w(item_path
));
288 SysFreeString(item_path
);
289 FolderItem_Release(item
);
291 Folder2_Release(folder2
);
293 Folder_Release(folder
);
295 SysFreeString(V_BSTR(&var
));
298 HeapFree(GetProcessHeap(), 0, long_pathW
);
299 RemoveDirectoryW(winetestW
);
300 SetCurrentDirectoryW(curW
);
301 IShellDispatch_Release(sd
);
304 START_TEST(shelldispatch
)
308 r
= CoInitialize(NULL
);
309 ok(SUCCEEDED(r
), "CoInitialize failed: %08x\n", r
);
313 init_function_pointers();