ReactOS  0.4.14-dev-52-g6116262
shfldr_special.c
Go to the documentation of this file.
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 <stdarg.h>
23 #include <stdio.h>
24 
25 #define COBJMACROS
26 #ifndef __REACTOS__
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #endif
30 
31 #define WIN32_LEAN_AND_MEAN
32 #include <windows.h>
33 #include "shellapi.h"
34 #include "shlobj.h"
35 
36 #include "wine/test.h"
37 
38 static inline BOOL SHELL_OsIsUnicode(void)
39 {
40  return !(GetVersion() & 0x80000000);
41 }
42 
43 /* Tests for My Network Places */
45 {
46  static WCHAR my_network_places_path[] = {
47  ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
48  '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
49  static WCHAR entire_network_path[] = {
50  ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
51  '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D',
52  '}','\\','E','n','t','i','r','e','N','e','t','w','o','r','k',0 };
53  IShellFolder *psfDesktop;
54  HRESULT hr;
55  DWORD eaten = 0xdeadbeef;
56  LPITEMIDLIST pidl;
57  DWORD attr = ~0;
58  DWORD expected_attr;
59 
60  hr = SHGetDesktopFolder(&psfDesktop);
61  ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr);
62 
63  hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, my_network_places_path, &eaten, &pidl, &attr);
64  ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
65  todo_wine
66  ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
67  expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANRENAME|SFGAO_CANLINK;
68  todo_wine
69  ok((attr == expected_attr) || /* Win9x, NT4 */
70  (attr == (expected_attr | SFGAO_STREAM)) || /* W2K */
71  (attr == (expected_attr | SFGAO_CANDELETE)) || /* XP, W2K3 */
72  (attr == (expected_attr | SFGAO_CANDELETE | SFGAO_NONENUMERATED)), /* Vista */
73  "Unexpected attributes : %08x\n", attr);
74 
75  ILFree(pidl);
76 
77  /* Start clean again */
78  eaten = 0xdeadbeef;
79  attr = ~0;
80 
81  hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, entire_network_path, &eaten, &pidl, &attr);
82  IShellFolder_Release(psfDesktop);
86  {
87  win_skip("'EntireNetwork' is not available on Win9x, NT4 and Vista\n");
88  return;
89  }
90  ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
91  todo_wine
92  ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
93  expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_HASPROPSHEET|SFGAO_CANLINK;
94  todo_wine
95  ok(attr == expected_attr || /* winme, nt4 */
96  attr == (expected_attr | SFGAO_STREAM) || /* win2k */
97  attr == (expected_attr | SFGAO_STORAGEANCESTOR), /* others */
98  "attr should be 0x%x, not 0x%x\n", expected_attr, attr);
99 
100  ILFree(pidl);
101 }
102 
103 /* Tests for Control Panel */
105 {
106  /* path of My Computer\Control Panel */
107  static WCHAR control_panel_path[] = {
108  ':',':','{','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','}','\\',
109  ':',':','{','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 };
110  IShellFolder *psfDesktop;
111  HRESULT hr;
112  DWORD eaten = 0xdeadbeef;
113  LPITEMIDLIST pidl;
114  DWORD attr = ~0;
115 
116  hr = SHGetDesktopFolder(&psfDesktop);
117  ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr);
118 
119  hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, control_panel_path, &eaten, &pidl, &attr);
120  ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
121  todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
122  todo_wine
123  ok((attr == (SFGAO_CANLINK | SFGAO_FOLDER)) || /* Win9x, NT4 */
124  (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_STREAM)) || /* W2K */
125  (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER)) || /* W2K, XP, W2K3 */
126  (attr == (SFGAO_CANLINK | SFGAO_NONENUMERATED)) || /* Vista */
127  (attr == SFGAO_CANLINK), /* Vista, W2K8 */
128  "Unexpected attributes : %08x\n", attr);
129 
130  ILFree(pidl);
131  IShellFolder_Release(psfDesktop);
132 }
133 
134 static void test_printers_folder(void)
135 {
137  IPersistFolder2 *pf;
140  LPITEMIDLIST pidl1, pidl2;
141  HRESULT hr;
142  INT i;
143 
144  CoInitialize( NULL );
145 
146  hr = CoCreateInstance(&CLSID_Printers, NULL, CLSCTX_INPROC_SERVER, &IID_IShellFolder2, (void**)&folder);
147  if (hr != S_OK)
148  {
149  win_skip("Failed to created IShellFolder2 for Printers folder\n");
150  CoUninitialize();
151  return;
152  }
153 
154 if (0)
155 {
156  /* crashes on XP */
157  IShellFolder2_GetDetailsOf(folder, NULL, 0, NULL);
158  IShellFolder2_GetDefaultColumnState(folder, 0, NULL);
159  IPersistFolder2_GetCurFolder(pf, NULL);
160 }
161 
162  /* 5 columns defined */
163  hr = IShellFolder2_GetDetailsOf(folder, NULL, 6, &details);
164  ok(hr == E_NOTIMPL, "got 0x%08x\n", hr);
165 
166  hr = IShellFolder2_GetDefaultColumnState(folder, 6, &state);
167  ok(broken(hr == E_NOTIMPL) || hr == E_INVALIDARG /* Win7 */, "got 0x%08x\n", hr);
168 
169  details.str.pOleStr = NULL;
170  hr = IShellFolder2_GetDetailsOf(folder, NULL, 0, &details);
171  ok(hr == S_OK || broken(hr == E_NOTIMPL) /* W2K */, "got 0x%08x\n", hr);
172  if (SHELL_OsIsUnicode()) SHFree(details.str.pOleStr);
173 
174  /* test every column if method is implemented */
175  if (hr == S_OK)
176  {
177  ok(details.str.uType == STRRET_WSTR, "got %d\n", details.str.uType);
178 
179  for(i = 0; i < 6; i++)
180  {
181  hr = IShellFolder2_GetDetailsOf(folder, NULL, i, &details);
182  ok(hr == S_OK, "got 0x%08x\n", hr);
183 
184  /* all columns are left-aligned */
185  ok(details.fmt == LVCFMT_LEFT, "got 0x%x\n", details.fmt);
186  /* can't be on w9x at this point, IShellFolder2 unsupported there,
187  check present for running Wine with w9x setup */
188  if (SHELL_OsIsUnicode()) SHFree(details.str.pOleStr);
189 
190  hr = IShellFolder2_GetDefaultColumnState(folder, i, &state);
191  ok(hr == S_OK, "got 0x%08x\n", hr);
192  /* all columns are string except document count */
193  if (i == 1)
195  else
197  }
198  }
199 
200  /* default pidl */
201  hr = IShellFolder2_QueryInterface(folder, &IID_IPersistFolder2, (void**)&pf);
202  ok(hr == S_OK, "got 0x%08x\n", hr);
203 
204  /* not initialized */
205  pidl1 = (void*)0xdeadbeef;
206  hr = IPersistFolder2_GetCurFolder(pf, &pidl1);
207  ok(hr == S_FALSE, "got 0x%08x\n", hr);
208  ok(pidl1 == NULL, "got %p\n", pidl1);
209 
211  ok(hr == S_OK, "got 0x%08x\n", hr);
212 
213  hr = IPersistFolder2_Initialize(pf, pidl2);
214  ok(hr == S_OK, "got 0x%08x\n", hr);
215 
216  hr = IPersistFolder2_GetCurFolder(pf, &pidl1);
217  ok(hr == S_OK, "got 0x%08x\n", hr);
218 
219  ok(ILIsEqual(pidl1, pidl2), "expected same PIDL\n");
220  IPersistFolder2_Release(pf);
221 
222  ILFree(pidl1);
223  ILFree(pidl2);
224  IShellFolder2_Release(folder);
225 
226  CoUninitialize();
227 }
228 
229 static void test_desktop_folder(void)
230 {
231  IShellFolder *psf;
232  HRESULT hr;
233 
234  hr = SHGetDesktopFolder(&psf);
235  ok(hr == S_OK, "Got %x\n", hr);
236 
237  hr = IShellFolder_QueryInterface(psf, &IID_IShellFolder, NULL);
238  ok(hr == E_POINTER, "Got %x\n", hr);
239 
240  IShellFolder_Release(psf);
241 }
242 
243 START_TEST(shfldr_special)
244 {
249 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
START_TEST(shfldr_special)
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
Definition: fci.c:115
static void test_desktop_folder(void)
HRESULT hr
Definition: shlfolder.c:183
#define ERROR_BAD_NET_NAME
Definition: winerror.h:159
#define LVCFMT_LEFT
Definition: commctrl.h:2570
static void test_parse_for_entire_network(void)
BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:535
int32_t INT
Definition: typedefs.h:56
static BOOL SHELL_OsIsUnicode(void)
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CSIDL_PRINTERS
Definition: shlobj.h:2007
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
struct CFFOLDER folder
Definition: fdi.c:110
#define ERROR_NO_NET_OR_BAD_PATH
Definition: winerror.h:706
static void test_printers_folder(void)
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
__wchar_t WCHAR
Definition: xmlstorage.h:180
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2687
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: cookie.c:170
DWORD SHCOLSTATEF
Definition: shtypes.idl:142
#define todo_wine
Definition: test.h:154
static int state
Definition: maze.c:121
#define broken(x)
Definition: _sntprintf.h:21
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
int details
Definition: msacm.c:1353
#define E_POINTER
Definition: winerror.h:2365
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define win_skip
Definition: test.h:141
static void test_parse_for_control_panel(void)