1 /* 2 * Tests for special shell folders 3 * 4 * Copyright 2008 Robert Shearman for CodeWeavers 5 * Copyright 2008 Owen Rudge 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 */ 21 22 #include "precomp.h" 23 24 static inline BOOL SHELL_OsIsUnicode(void) 25 { 26 return !(GetVersion() & 0x80000000); 27 } 28 29 /* Tests for My Network Places */ 30 static void test_parse_for_entire_network(void) 31 { 32 static WCHAR my_network_places_path[] = { 33 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-', 34 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 }; 35 static WCHAR entire_network_path[] = { 36 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-', 37 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D', 38 '}','\\','E','n','t','i','r','e','N','e','t','w','o','r','k',0 }; 39 IShellFolder *psfDesktop; 40 HRESULT hr; 41 DWORD eaten = 0xdeadbeef; 42 LPITEMIDLIST pidl; 43 DWORD attr = ~0; 44 DWORD expected_attr; 45 46 hr = SHGetDesktopFolder(&psfDesktop); 47 ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr); 48 49 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, my_network_places_path, &eaten, &pidl, &attr); 50 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); 51 todo_wine 52 ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); 53 expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANRENAME|SFGAO_CANLINK; 54 todo_wine 55 ok((attr == expected_attr) || /* Win9x, NT4 */ 56 (attr == (expected_attr | SFGAO_STREAM)) || /* W2K */ 57 (attr == (expected_attr | SFGAO_CANDELETE)) || /* XP, W2K3 */ 58 (attr == (expected_attr | SFGAO_CANDELETE | SFGAO_NONENUMERATED)), /* Vista */ 59 "Unexpected attributes : %08x\n", attr); 60 61 ILFree(pidl); 62 63 /* Start clean again */ 64 eaten = 0xdeadbeef; 65 attr = ~0; 66 67 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, entire_network_path, &eaten, &pidl, &attr); 68 IShellFolder_Release(psfDesktop); 69 if (hr == HRESULT_FROM_WIN32(ERROR_BAD_NET_NAME) || 70 hr == HRESULT_FROM_WIN32(ERROR_NO_NET_OR_BAD_PATH) || 71 hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)) 72 { 73 win_skip("'EntireNetwork' is not available on Win9x, NT4 and Vista\n"); 74 return; 75 } 76 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); 77 todo_wine 78 ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); 79 expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_HASPROPSHEET|SFGAO_CANLINK; 80 todo_wine 81 ok(attr == expected_attr || /* winme, nt4 */ 82 attr == (expected_attr | SFGAO_STREAM) || /* win2k */ 83 attr == (expected_attr | SFGAO_STORAGEANCESTOR), /* others */ 84 "attr should be 0x%x, not 0x%x\n", expected_attr, attr); 85 86 ILFree(pidl); 87 } 88 89 /* Tests for Control Panel */ 90 static void test_parse_for_control_panel(void) 91 { 92 /* path of My Computer\Control Panel */ 93 static WCHAR control_panel_path[] = { 94 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}','\\', 95 ':',':','{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 }; 96 IShellFolder *psfDesktop; 97 HRESULT hr; 98 DWORD eaten = 0xdeadbeef; 99 LPITEMIDLIST pidl; 100 DWORD attr = ~0; 101 102 hr = SHGetDesktopFolder(&psfDesktop); 103 ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr); 104 105 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, control_panel_path, &eaten, &pidl, &attr); 106 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); 107 todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); 108 todo_wine 109 ok((attr == (SFGAO_CANLINK | SFGAO_FOLDER)) || /* Win9x, NT4 */ 110 (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_STREAM)) || /* W2K */ 111 (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER)) || /* W2K, XP, W2K3 */ 112 (attr == (SFGAO_CANLINK | SFGAO_NONENUMERATED)) || /* Vista */ 113 (attr == SFGAO_CANLINK), /* Vista, W2K8 */ 114 "Unexpected attributes : %08x\n", attr); 115 116 ILFree(pidl); 117 IShellFolder_Release(psfDesktop); 118 } 119 120 static void test_printers_folder(void) 121 { 122 IShellFolder2 *folder; 123 IPersistFolder2 *pf; 124 SHELLDETAILS details; 125 SHCOLSTATEF state; 126 LPITEMIDLIST pidl1, pidl2; 127 HRESULT hr; 128 INT i; 129 130 CoInitialize( NULL ); 131 132 hr = CoCreateInstance(&CLSID_Printers, NULL, CLSCTX_INPROC_SERVER, &IID_IShellFolder2, (void**)&folder); 133 if (hr != S_OK) 134 { 135 win_skip("Failed to created IShellFolder2 for Printers folder\n"); 136 CoUninitialize(); 137 return; 138 } 139 140 if (0) 141 { 142 /* crashes on XP */ 143 IShellFolder2_GetDetailsOf(folder, NULL, 0, NULL); 144 IShellFolder2_GetDefaultColumnState(folder, 0, NULL); 145 IPersistFolder2_GetCurFolder(pf, NULL); 146 } 147 148 /* 5 columns defined */ 149 hr = IShellFolder2_GetDetailsOf(folder, NULL, 6, &details); 150 ok(hr == E_NOTIMPL, "got 0x%08x\n", hr); 151 152 hr = IShellFolder2_GetDefaultColumnState(folder, 6, &state); 153 ok(broken(hr == E_NOTIMPL) || hr == E_INVALIDARG /* Win7 */, "got 0x%08x\n", hr); 154 155 details.str.pOleStr = NULL; 156 hr = IShellFolder2_GetDetailsOf(folder, NULL, 0, &details); 157 ok(hr == S_OK || broken(hr == E_NOTIMPL) /* W2K */, "got 0x%08x\n", hr); 158 if (SHELL_OsIsUnicode()) SHFree(details.str.pOleStr); 159 160 /* test every column if method is implemented */ 161 if (hr == S_OK) 162 { 163 ok(details.str.uType == STRRET_WSTR, "got %d\n", details.str.uType); 164 165 for(i = 0; i < 6; i++) 166 { 167 hr = IShellFolder2_GetDetailsOf(folder, NULL, i, &details); 168 ok(hr == S_OK, "got 0x%08x\n", hr); 169 170 /* all columns are left-aligned */ 171 ok(details.fmt == LVCFMT_LEFT, "got 0x%x\n", details.fmt); 172 /* can't be on w9x at this point, IShellFolder2 unsupported there, 173 check present for running Wine with w9x setup */ 174 if (SHELL_OsIsUnicode()) SHFree(details.str.pOleStr); 175 176 hr = IShellFolder2_GetDefaultColumnState(folder, i, &state); 177 ok(hr == S_OK, "got 0x%08x\n", hr); 178 /* all columns are string except document count */ 179 if (i == 1) 180 ok(state == (SHCOLSTATE_TYPE_INT | SHCOLSTATE_ONBYDEFAULT), "got 0x%x\n", state); 181 else 182 ok(state == (SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT), "got 0x%x\n", state); 183 } 184 } 185 186 /* default pidl */ 187 hr = IShellFolder2_QueryInterface(folder, &IID_IPersistFolder2, (void**)&pf); 188 ok(hr == S_OK, "got 0x%08x\n", hr); 189 190 /* not initialized */ 191 pidl1 = (void*)0xdeadbeef; 192 hr = IPersistFolder2_GetCurFolder(pf, &pidl1); 193 ok(hr == S_FALSE, "got 0x%08x\n", hr); 194 ok(pidl1 == NULL, "got %p\n", pidl1); 195 196 hr = SHGetSpecialFolderLocation(NULL, CSIDL_PRINTERS, &pidl2); 197 ok(hr == S_OK, "got 0x%08x\n", hr); 198 199 hr = IPersistFolder2_Initialize(pf, pidl2); 200 ok(hr == S_OK, "got 0x%08x\n", hr); 201 202 hr = IPersistFolder2_GetCurFolder(pf, &pidl1); 203 ok(hr == S_OK, "got 0x%08x\n", hr); 204 205 ok(ILIsEqual(pidl1, pidl2), "expected same PIDL\n"); 206 IPersistFolder2_Release(pf); 207 208 ILFree(pidl1); 209 ILFree(pidl2); 210 IShellFolder2_Release(folder); 211 212 CoUninitialize(); 213 } 214 215 static void test_desktop_folder(void) 216 { 217 IShellFolder *psf; 218 HRESULT hr; 219 220 hr = SHGetDesktopFolder(&psf); 221 ok(hr == S_OK, "Got %x\n", hr); 222 223 hr = IShellFolder_QueryInterface(psf, &IID_IShellFolder, NULL); 224 ok(hr == E_POINTER, "Got %x\n", hr); 225 226 IShellFolder_Release(psf); 227 } 228 229 START_TEST(shfldr_special) 230 { 231 test_parse_for_entire_network(); 232 test_parse_for_control_panel(); 233 test_printers_folder(); 234 test_desktop_folder(); 235 } 236