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 #define EXPECT_HR(hr,hr_exp) \
31 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
33 static HRESULT (WINAPI
*pSHGetFolderPathW
)(HWND
, int, HANDLE
, DWORD
, LPWSTR
);
34 static HRESULT (WINAPI
*pSHGetNameFromIDList
)(PCIDLIST_ABSOLUTE
,SIGDN
,PWSTR
*);
35 static HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
36 static DWORD (WINAPI
*pGetLongPathNameW
)(LPCWSTR
, LPWSTR
, DWORD
);
38 static void init_function_pointers(void)
40 HMODULE hshell32
, hkernel32
;
42 hshell32
= GetModuleHandleA("shell32.dll");
43 hkernel32
= GetModuleHandleA("kernel32.dll");
44 pSHGetFolderPathW
= (void*)GetProcAddress(hshell32
, "SHGetFolderPathW");
45 pSHGetNameFromIDList
= (void*)GetProcAddress(hshell32
, "SHGetNameFromIDList");
46 pSHGetSpecialFolderLocation
= (void*)GetProcAddress(hshell32
,
47 "SHGetSpecialFolderLocation");
48 pGetLongPathNameW
= (void*)GetProcAddress(hkernel32
, "GetLongPathNameW");
51 static void test_namespace(void)
53 static const WCHAR winetestW
[] = {'w','i','n','e','t','e','s','t',0};
54 static const WCHAR backslashW
[] = {'\\',0};
55 static const WCHAR clsidW
[] = {
56 ':',':','{','6','4','5','F','F','0','4','0','-','5','0','8','1','-',
57 '1','0','1','B','-','9','F','0','8','-',
58 '0','0','A','A','0','0','2','F','9','5','4','E','}',0};
60 static WCHAR tempW
[MAX_PATH
], curW
[MAX_PATH
];
61 WCHAR
*long_pathW
= NULL
;
68 BSTR title
, item_path
;
71 r
= CoCreateInstance(&CLSID_Shell
, NULL
, CLSCTX_INPROC_SERVER
,
72 &IID_IShellDispatch
, (LPVOID
*)&sd
);
73 if (r
== REGDB_E_CLASSNOTREG
) /* NT4 */
75 win_skip("skipping IShellDispatch tests\n");
78 ok(SUCCEEDED(r
), "CoCreateInstance failed: %08x\n", r
);
83 folder
= (void*)0xdeadbeef;
84 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
85 ok(r
== S_FALSE
, "expected S_FALSE, got %08x\n", r
);
86 ok(folder
== NULL
, "expected NULL, got %p\n", folder
);
90 folder
= (void*)0xdeadbeef;
91 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
93 ok(r
== S_FALSE
, "expected S_FALSE, got %08x\n", r
);
94 ok(folder
== NULL
, "got %p\n", folder
);
97 V_I4(&var
) = ssfPROGRAMFILES
;
98 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
100 broken(r
== S_FALSE
), /* NT4 */
101 "IShellDispatch::NameSpace failed: %08x\n", r
);
104 static WCHAR path
[MAX_PATH
];
106 if (pSHGetFolderPathW
)
108 r
= pSHGetFolderPathW(NULL
, CSIDL_PROGRAM_FILES
, NULL
,
109 SHGFP_TYPE_CURRENT
, path
);
110 ok(r
== S_OK
, "SHGetFolderPath failed: %08x\n", r
);
112 r
= Folder_get_Title(folder
, &title
);
114 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
117 /* On Win2000-2003 title is equal to program files directory name in
118 HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir.
119 On newer Windows it seems constant and is not changed
120 if the program files directory name is changed */
121 if (pSHGetSpecialFolderLocation
&& pSHGetNameFromIDList
)
126 r
= pSHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAM_FILES
, &pidl
);
127 ok(r
== S_OK
, "SHGetSpecialFolderLocation failed: %08x\n", r
);
128 r
= pSHGetNameFromIDList(pidl
, SIGDN_NORMALDISPLAY
, &name
);
129 ok(r
== S_OK
, "SHGetNameFromIDList failed: %08x\n", r
);
131 ok(!lstrcmpW(title
, name
), "expected %s, got %s\n",
132 wine_dbgstr_w(name
), wine_dbgstr_w(title
));
136 else if (pSHGetFolderPathW
)
140 p
= path
+ lstrlenW(path
);
141 while (path
< p
&& *(p
- 1) != '\\')
143 ok(!lstrcmpiW(title
, p
), "expected %s, got %s\n",
144 wine_dbgstr_w(p
), wine_dbgstr_w(title
));
146 else skip("skipping Folder::get_Title test\n");
147 SysFreeString(title
);
149 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
150 ok(r
== S_OK
, "Folder::QueryInterface failed: %08x\n", r
);
153 r
= Folder2_get_Self(folder2
, &item
);
154 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
157 r
= FolderItem_get_Path(item
, &item_path
);
158 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
159 if (pSHGetFolderPathW
)
160 ok(!lstrcmpiW(item_path
, path
), "expected %s, got %s\n",
161 wine_dbgstr_w(path
), wine_dbgstr_w(item_path
));
162 SysFreeString(item_path
);
163 FolderItem_Release(item
);
165 Folder2_Release(folder2
);
167 Folder_Release(folder
);
171 V_I4(&var
) = ssfBITBUCKET
;
172 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
174 broken(r
== S_FALSE
), /* NT4 */
175 "IShellDispatch::NameSpace failed: %08x\n", r
);
178 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
180 broken(r
== E_NOINTERFACE
), /* NT4 */
181 "Folder::QueryInterface failed: %08x\n", r
);
184 r
= Folder2_get_Self(folder2
, &item
);
185 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
188 r
= FolderItem_get_Path(item
, &item_path
);
190 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
192 ok(!lstrcmpW(item_path
, clsidW
), "expected %s, got %s\n",
193 wine_dbgstr_w(clsidW
), wine_dbgstr_w(item_path
));
194 SysFreeString(item_path
);
195 FolderItem_Release(item
);
197 Folder2_Release(folder2
);
199 Folder_Release(folder
);
202 GetTempPathW(MAX_PATH
, tempW
);
203 GetCurrentDirectoryW(MAX_PATH
, curW
);
204 SetCurrentDirectoryW(tempW
);
205 CreateDirectoryW(winetestW
, NULL
);
206 V_VT(&var
) = VT_BSTR
;
207 V_BSTR(&var
) = SysAllocString(winetestW
);
208 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
209 ok(r
== S_FALSE
, "expected S_FALSE, got %08x\n", r
);
210 SysFreeString(V_BSTR(&var
));
212 GetFullPathNameW(winetestW
, MAX_PATH
, tempW
, NULL
);
213 if (pGetLongPathNameW
)
215 len
= pGetLongPathNameW(tempW
, NULL
, 0);
216 long_pathW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
218 pGetLongPathNameW(tempW
, long_pathW
, len
);
220 V_VT(&var
) = VT_BSTR
;
221 V_BSTR(&var
) = SysAllocString(tempW
);
222 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
223 ok(r
== S_OK
, "IShellDispatch::NameSpace failed: %08x\n", r
);
226 r
= Folder_get_Title(folder
, &title
);
227 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
230 ok(!lstrcmpW(title
, winetestW
), "bad title: %s\n",
231 wine_dbgstr_w(title
));
232 SysFreeString(title
);
234 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
236 broken(r
== E_NOINTERFACE
), /* NT4 */
237 "Folder::QueryInterface failed: %08x\n", r
);
240 r
= Folder2_get_Self(folder2
, &item
);
241 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
244 r
= FolderItem_get_Path(item
, &item_path
);
245 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
247 ok(!lstrcmpW(item_path
, long_pathW
),
248 "expected %s, got %s\n", wine_dbgstr_w(long_pathW
),
249 wine_dbgstr_w(item_path
));
250 SysFreeString(item_path
);
251 FolderItem_Release(item
);
253 Folder2_Release(folder2
);
255 Folder_Release(folder
);
257 SysFreeString(V_BSTR(&var
));
259 len
= lstrlenW(tempW
);
260 if (len
< MAX_PATH
- 1)
262 lstrcatW(tempW
, backslashW
);
263 V_VT(&var
) = VT_BSTR
;
264 V_BSTR(&var
) = SysAllocString(tempW
);
265 r
= IShellDispatch_NameSpace(sd
, var
, &folder
);
266 ok(r
== S_OK
, "IShellDispatch::NameSpace failed: %08x\n", r
);
269 r
= Folder_get_Title(folder
, &title
);
270 ok(r
== S_OK
, "Folder::get_Title failed: %08x\n", r
);
273 ok(!lstrcmpW(title
, winetestW
), "bad title: %s\n",
274 wine_dbgstr_w(title
));
275 SysFreeString(title
);
277 r
= Folder_QueryInterface(folder
, &IID_Folder2
, (LPVOID
*)&folder2
);
279 broken(r
== E_NOINTERFACE
), /* NT4 */
280 "Folder::QueryInterface failed: %08x\n", r
);
283 r
= Folder2_get_Self(folder2
, &item
);
284 ok(r
== S_OK
, "Folder::get_Self failed: %08x\n", r
);
287 r
= FolderItem_get_Path(item
, &item_path
);
288 ok(r
== S_OK
, "FolderItem::get_Path failed: %08x\n", r
);
290 ok(!lstrcmpW(item_path
, long_pathW
),
291 "expected %s, got %s\n", wine_dbgstr_w(long_pathW
),
292 wine_dbgstr_w(item_path
));
293 SysFreeString(item_path
);
294 FolderItem_Release(item
);
296 Folder2_Release(folder2
);
298 Folder_Release(folder
);
300 SysFreeString(V_BSTR(&var
));
303 HeapFree(GetProcessHeap(), 0, long_pathW
);
304 RemoveDirectoryW(winetestW
);
305 SetCurrentDirectoryW(curW
);
306 IShellDispatch_Release(sd
);
309 static void test_service(void)
311 static const WCHAR spooler
[] = {'S','p','o','o','l','e','r',0};
312 static const WCHAR dummyW
[] = {'d','u','m','m','y',0};
313 SERVICE_STATUS_PROCESS status
;
314 SC_HANDLE scm
, service
;
321 hr
= CoCreateInstance(&CLSID_Shell
, NULL
, CLSCTX_INPROC_SERVER
,
322 &IID_IShellDispatch2
, (void**)&sd
);
325 win_skip("IShellDispatch2 not supported\n");
331 hr
= IShellDispatch2_IsServiceRunning(sd
, NULL
, &v
);
332 ok(V_VT(&v
) == VT_BOOL
, "got %d\n", V_VT(&v
));
333 ok(V_BOOL(&v
) == VARIANT_FALSE
, "got %d\n", V_BOOL(&v
));
336 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
337 service
= OpenServiceW(scm
, spooler
, SERVICE_QUERY_STATUS
);
338 QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
, (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
);
339 CloseServiceHandle(service
);
340 CloseServiceHandle(scm
);
342 /* service should exist */
343 name
= SysAllocString(spooler
);
345 hr
= IShellDispatch2_IsServiceRunning(sd
, name
, &v
);
347 ok(V_VT(&v
) == VT_BOOL
, "got %d\n", V_VT(&v
));
348 if (status
.dwCurrentState
== SERVICE_RUNNING
)
349 ok(V_BOOL(&v
) == VARIANT_TRUE
, "got %d\n", V_BOOL(&v
));
351 ok(V_BOOL(&v
) == VARIANT_FALSE
, "got %d\n", V_BOOL(&v
));
354 /* service doesn't exist */
355 name
= SysAllocString(dummyW
);
357 hr
= IShellDispatch2_IsServiceRunning(sd
, name
, &v
);
359 ok(V_VT(&v
) == VT_BOOL
, "got %d\n", V_VT(&v
));
360 ok(V_BOOL(&v
) == VARIANT_FALSE
, "got %d\n", V_BOOL(&v
));
363 IShellDispatch2_Release(sd
);
366 START_TEST(shelldispatch
)
370 r
= CoInitialize(NULL
);
371 ok(SUCCEEDED(r
), "CoInitialize failed: %08x\n", r
);
375 init_function_pointers();