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 *);
34 static void init_function_pointers(void)
38 hmod = GetModuleHandleA("shell32.dll");
39 pSHGetFolderPathW = (void*)GetProcAddress(hmod, "SHGetFolderPathW");
40 pSHGetNameFromIDList = (void*)GetProcAddress(hmod, "SHGetNameFromIDList");
41 pSHGetSpecialFolderLocation = (void*)GetProcAddress(hmod,
42 "SHGetSpecialFolderLocation");
45 static void test_namespace(void)
47 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
48 static const WCHAR backslashW[] = {'\\',0};
50 static WCHAR tempW[MAX_PATH], curW[MAX_PATH];
58 r = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
59 &IID_IShellDispatch, (LPVOID*)&sd);
60 if (r == REGDB_E_CLASSNOTREG) /* NT4 */
62 win_skip("skipping IShellDispatch tests\n");
65 ok(SUCCEEDED(r), "CoCreateInstance failed: %08x\n", r);
70 folder = (void*)0xdeadbeef;
71 r = IShellDispatch_NameSpace(sd, var, &folder);
72 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
73 ok(folder == NULL, "expected NULL, got %p\n", folder);
77 r = IShellDispatch_NameSpace(sd, var, &folder);
79 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
82 V_I4(&var) = ssfPROGRAMFILES;
83 r = IShellDispatch_NameSpace(sd, var, &folder);
85 broken(r == S_FALSE), /* NT4 */
86 "IShellDispatch::NameSpace failed: %08x\n", r);
89 r = Folder_get_Title(folder, &title);
91 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
94 /* On Win2000-2003 title is equal to program files directory name in
95 HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir.
96 On newer Windows it seems constant and is not changed
97 if the program files directory name is changed */
98 if (pSHGetSpecialFolderLocation && pSHGetNameFromIDList)
103 r = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl);
104 ok(r == S_OK, "SHGetSpecialFolderLocation failed: %08x\n", r);
105 r = pSHGetNameFromIDList(pidl, SIGDN_NORMALDISPLAY, &name);
106 ok(r == S_OK, "SHGetNameFromIDList failed: %08x\n", r);
108 ok(!lstrcmpW(title, name), "expected %s, got %s\n",
109 wine_dbgstr_w(name), wine_dbgstr_w(title));
113 else if (pSHGetFolderPathW)
115 static WCHAR path[MAX_PATH];
118 r = pSHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL,
119 SHGFP_TYPE_CURRENT, path);
120 ok(r == S_OK, "SHGetFolderPath failed: %08x\n", r);
121 p = path + lstrlenW(path);
122 while (path < p && *(p - 1) != '\\')
124 ok(!lstrcmpW(title, p), "expected %s, got %s\n",
125 wine_dbgstr_w(p), wine_dbgstr_w(title));
127 else skip("skipping Folder::get_Title test\n");
128 SysFreeString(title);
130 Folder_Release(folder);
133 GetTempPathW(MAX_PATH, tempW);
134 GetCurrentDirectoryW(MAX_PATH, curW);
135 SetCurrentDirectoryW(tempW);
136 CreateDirectoryW(winetestW, NULL);
137 V_VT(&var) = VT_BSTR;
138 V_BSTR(&var) = SysAllocString(winetestW);
139 r = IShellDispatch_NameSpace(sd, var, &folder);
140 ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
141 SysFreeString(V_BSTR(&var));
143 GetFullPathNameW(winetestW, MAX_PATH, tempW, NULL);
144 V_VT(&var) = VT_BSTR;
145 V_BSTR(&var) = SysAllocString(tempW);
146 r = IShellDispatch_NameSpace(sd, var, &folder);
147 ok(r == S_OK, "IShellDispatch::NameSpace failed: %08x\n", r);
150 r = Folder_get_Title(folder, &title);
152 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
156 ok(!lstrcmpW(title, winetestW), "bad title: %s\n",
157 wine_dbgstr_w(title));
158 SysFreeString(title);
160 Folder_Release(folder);
162 SysFreeString(V_BSTR(&var));
164 len = lstrlenW(tempW);
165 if (len < MAX_PATH - 1)
167 lstrcatW(tempW, backslashW);
168 V_VT(&var) = VT_BSTR;
169 V_BSTR(&var) = SysAllocString(tempW);
170 r = IShellDispatch_NameSpace(sd, var, &folder);
171 ok(r == S_OK, "IShellDispatch::NameSpace failed: %08x\n", r);
174 r = Folder_get_Title(folder, &title);
176 ok(r == S_OK, "Folder::get_Title failed: %08x\n", r);
180 ok(!lstrcmpW(title, winetestW), "bad title: %s\n",
181 wine_dbgstr_w(title));
182 SysFreeString(title);
184 Folder_Release(folder);
186 SysFreeString(V_BSTR(&var));
189 RemoveDirectoryW(winetestW);
190 SetCurrentDirectoryW(curW);
191 IShellDispatch_Release(sd);
194 START_TEST(shelldispatch)
198 r = CoInitialize(NULL);
199 ok(SUCCEEDED(r), "CoInitialize failed: %08x\n", r);
203 init_function_pointers();