ReactOS 0.4.16-dev-1946-g52006dd
SHParseDisplayName.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for SHParseDisplayName
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "shelltest.h"
9
10/* Version masks */
11#define T_ALL 0x0
12#define T_WIN2K 0x1
13#define T_WINXP 0x2
14#define T_WIN2K3 0x4
15#define T_VISTA 0x8
16#define T_WIN7 0x10
17#define T_WIN8 0x20
18#define T_WIN10 0x40
19
20#define T_PRE_VISTA (T_WIN2K | T_WINXP | T_WIN2K3)
21#define T_PRE_WIN7 (T_PRE_VISTA | T_VISTA)
22#define T_PRE_WIN8 (T_PRE_WIN7 | T_WIN7)
23
24#define T_WIN8_PLUS (T_WIN8 | T_WIN10)
25#define T_WIN7_PLUS (T_WIN7 | T_WIN8_PLUS)
26#define T_VISTA_PLUS (T_VISTA | T_WIN7_PLUS)
27
28struct test_data
29{
30 int testline;
36};
37
38struct test_data Tests[] =
39{
40 /* Tests for CDesktopFolder */
41 {__LINE__, NULL, NULL, 0, E_OUTOFMEMORY, T_PRE_VISTA},
42 {__LINE__, NULL, NULL, 0, E_INVALIDARG, T_VISTA_PLUS},
43 {__LINE__, L"", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
45 {__LINE__, L" ", NULL, 0, E_INVALIDARG, T_WIN8_PLUS},
46 {__LINE__, L":", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
47 {__LINE__, L": ", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
48 {__LINE__, L" :", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
49 {__LINE__, L"/", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
50 {__LINE__, L"//", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
51 /* This opens C:\ from Win+R and address bar */
52 {__LINE__, L"\\", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
53 /* These two opens "C:\Program Files" from Win+R and address bar */
54 {__LINE__, L"\\Program Files", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
55 {__LINE__, L"\\Program Files\\", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
56 {__LINE__, L"\\\\?", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
57 {__LINE__, L"\\\\?\\", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
58 /* Tests for the shell: protocol */
59 {__LINE__, L"shell:", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
60 {__LINE__, L"shell::", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
61 {__LINE__, L"shell:::", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
62 {__LINE__, L"shell:::{", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
63 {__LINE__, L"shell:fail", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
64 {__LINE__, L"shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
65 {__LINE__, L"shell:desktop", NULL, CSIDL_DESKTOPDIRECTORY, S_OK, T_PRE_VISTA},
66 {__LINE__, L"shell:windows", NULL, CSIDL_WINDOWS, S_OK, T_PRE_VISTA},
67 {__LINE__, L"shell:system", NULL, CSIDL_SYSTEM, S_OK, T_PRE_VISTA},
68 {__LINE__, L"shell:personal", NULL, CSIDL_MYDOCUMENTS, S_OK, T_PRE_VISTA},
69 {__LINE__, L"shell:programs", NULL, CSIDL_PROGRAMS, S_OK, T_PRE_VISTA},
70 {__LINE__, L"shell:programfiles", NULL, CSIDL_PROGRAM_FILES, S_OK, T_PRE_VISTA},
71 {__LINE__, L"shell:windows\\system32", NULL, CSIDL_SYSTEM, S_OK, T_PRE_VISTA},
72 {__LINE__, L"shell:windows\\fonts", NULL, CSIDL_FONTS, S_OK, T_PRE_VISTA},
73 /* The following tests are confusing. They don't work for SHParseDisplayName but work on psfDesktop->ParseDisplayName */
74 {__LINE__, L"shell:desktop", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
75 {__LINE__, L"shell:windows", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
76 {__LINE__, L"shell:system", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
77 {__LINE__, L"shell:personal", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
78 {__LINE__, L"shell:programs", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
79 {__LINE__, L"shell:programfiles", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
80 {__LINE__, L"shell:windows\\system32", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
81 {__LINE__, L"shell:windows\\fonts", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
82 /* Tests for CInternet */
83 {__LINE__, L"aa:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
84 {__LINE__, L"garbage:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
85 {__LINE__, L"ftp:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
86 {__LINE__, L"ftp:/", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
87 {__LINE__, L"ftp://", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
88 {__LINE__, L"ftp://a", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
89 {__LINE__, L"ftp://ftp.gnu.org/gnu/octave/", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
90 {__LINE__, L"aa:", L"aa:", 0, S_OK, T_WIN10},
91 {__LINE__, L"garbage:", L"garbage:", 0, S_OK, T_WIN10},
92 {__LINE__, L"ftp:", L"ftp:", 0, S_OK, T_WIN10},
93 {__LINE__, L"ftp:/", L"ftp:/", 0, S_OK, T_WIN10},
94 {__LINE__, L"ftp://", L"ftp:///", 0, S_OK, T_WIN10},
95 {__LINE__, L"ftp://a", L"ftp://a/", 0, S_OK, T_WIN10},
96 {__LINE__, L"ftp://ftp.gnu.org/gnu/octave/", L"ftp://ftp.gnu.org/gnu/octave/", 0, S_OK, T_WIN10},
97 /* Tests for CRegFolder */
98 {__LINE__, L"::", NULL, 0, CO_E_CLASSSTRING, 0},
99 {__LINE__, L"::{", NULL, 0, CO_E_CLASSSTRING, 0},
100 {__LINE__, L"::{ ", NULL, 0, CO_E_CLASSSTRING, 0},
101 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
102 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D} ", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
103 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}a", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
104 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}garbage", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
105 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D ", NULL, 0, CO_E_CLASSSTRING, 0},
106 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\", NULL, 0, E_INVALIDARG, 0},
107 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\ ", NULL, 0, E_INVALIDARG, 0},
108 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}", 0, S_OK, 0},
109 /* Tests for CDrivesFolder */
110 {__LINE__, L"c:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
111 {__LINE__, L"c:", L"C:\\", 0, S_OK, T_VISTA_PLUS},
112 {__LINE__, L"c:\\", L"C:\\", 0, S_OK, 0},
113 {__LINE__, L"C:\\", L"C:\\", 0, S_OK, 0},
116 {__LINE__, L"C:\\ ", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), T_PRE_VISTA},
117 {__LINE__, L"C:\\ ", NULL, 0, E_INVALIDARG, T_WIN8_PLUS},
118 /* Tests for CFSFolder */
119 {__LINE__, L"$", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
120 {__LINE__, L"c:\\Program Files", L"C:\\Program Files", 0, S_OK, 0},
121 {__LINE__, L"c:\\Program Files\\", L"C:\\Program Files", 0, S_OK, 0},
122 /* Paths with . are valid for win+r dialog or address bar but not for ParseDisplayName */
123 {__LINE__, L"c:\\Program Files\\.", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
124 {__LINE__, L"c:\\Program Files\\..", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS}, /* This gives C:\ when entered in address bar */
125 {__LINE__, L".", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
126 {__LINE__, L"..", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
127 {__LINE__, L"C:\\.", NULL, 0, E_INVALIDARG, T_PRE_WIN7|T_WIN8_PLUS},
128 {__LINE__, L"fonts", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0}, /* These three work for ShellExecute */
129 {__LINE__, L"winsxs", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
130 {__LINE__, L"system32", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0}
131};
132
134{
135 switch (GetNTVersion())
136 {
137 case _WIN32_WINNT_WIN2K: return T_WIN2K;
138 case _WIN32_WINNT_WINXP: return T_WINXP;
139 case _WIN32_WINNT_WS03: return T_WIN2K3;
140 case _WIN32_WINNT_VISTA: return T_VISTA;
141 case _WIN32_WINNT_WIN7: return T_WIN7;
142 case _WIN32_WINNT_WIN8: return T_WIN8;
143 case _WIN32_WINNT_WINBLUE: return T_WIN8;
144 case _WIN32_WINNT_WIN10: return T_WIN10;
145 }
146
147 return 0;
148}
149
151{
152 HRESULT hr;
153 WCHAR winDir[MAX_PATH];
154 UINT os_flag = get_host_os_flag();
155 ok (os_flag != 0, "Incompatible os version %d!", os_flag);
156 if (os_flag == 0)
157 return;
158
159 IShellFolder *psfDesktop;
160 hr = SHGetDesktopFolder(&psfDesktop);
161 ok(hr == S_OK, "hr = %lx\n", hr);
162
163 GetWindowsDirectoryW(winDir, _countof(winDir));
164 SetCurrentDirectoryW(winDir);
165
166 for (UINT i = 0; i < _countof(Tests); i ++)
167 {
168 if (Tests[i].ValidForVersion && !(Tests[i].ValidForVersion & os_flag))
169 continue;
170
171 PIDLIST_ABSOLUTE pidl;
173 ok(hr == Tests[i].hResult, "%d: Expected error 0x%lx, got 0x%lx\n", Tests[i].testline, Tests[i].hResult, hr);
174
176 {
177 ok(pidl == NULL, "%d: Expected no pidl\n", Tests[i].testline);
178 continue;
179 }
180
181 ok(pidl != NULL, "%d: Expected pidl on success\n", Tests[i].testline);
182 if(!pidl)
183 continue;
184
185 STRRET strret;
186 hr = psfDesktop->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &strret);
187 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
188
189 ok(strret.uType == STRRET_WSTR, "%d: Expected STRRET_WSTR\n", Tests[i].testline);
190
192 {
193 ok(!wcscmp(strret.pOleStr, Tests[i].wszExpectedDisplayName), "%d: expected %S got %S\n", Tests[i].testline, Tests[i].wszExpectedDisplayName, strret.pOleStr);
194 }
195 else
196 {
197 PIDLIST_ABSOLUTE pidlSpecial;
199 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
200
201 STRRET strretSpecial;
202 hr = psfDesktop->GetDisplayNameOf(pidlSpecial, SHGDN_FORPARSING, &strretSpecial);
203 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
204
205 ok(strret.uType == STRRET_WSTR, "%d: Expected STRRET_WSTR\n", Tests[i].testline);
206
207 ok(!wcscmp(strret.pOleStr, strretSpecial.pOleStr), "%d: expected %S got %S\n", Tests[i].testline, strretSpecial.pOleStr, strret.pOleStr);
208 }
209 }
210
212}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#define T_PRE_VISTA
UINT get_host_os_flag()
#define T_WIN8
#define T_WIN10
#define T_WIN8_PLUS
struct test_data Tests[]
#define T_WIN7
#define T_PRE_WIN7
#define T_WINXP
#define T_WIN2K3
#define T_WIN2K
#define T_VISTA
#define T_VISTA_PLUS
#define GetNTVersion()
Definition: apitest.h:17
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:3384
#define L(x)
Definition: resources.c:13
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
HRESULT GetDisplayNameOf([in] PCUITEMID_CHILD pidl, [in] SHGDNF uFlags, [out] STRRET *lpName)
#define S_OK
Definition: intsafe.h:52
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
unsigned int UINT
Definition: ndis.h:50
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1542
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define _WIN32_WINNT_WIN10
Definition: sdkddkver.h:32
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define _WIN32_WINNT_WINXP
Definition: sdkddkver.h:22
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _WIN32_WINNT_WIN2K
Definition: sdkddkver.h:21
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_PROGRAM_FILES
Definition: shlobj.h:2216
#define CSIDL_DESKTOPDIRECTORY
Definition: shlobj.h:2194
#define CSIDL_MYDOCUMENTS
Definition: shlobj.h:2191
#define CSIDL_FONTS
Definition: shlobj.h:2198
#define CSIDL_SYSTEM
Definition: shlobj.h:2215
#define CSIDL_PROGRAMS
Definition: shlobj.h:2181
#define CSIDL_WINDOWS
Definition: shlobj.h:2214
@ STRRET_WSTR
Definition: shtypes.idl:85
#define _countof(array)
Definition: sndvol32.h:70
UINT uType
Definition: shtypes.idl:93
LPWSTR pOleStr
Definition: shtypes.idl:96
PCWSTR wszExpectedDisplayName
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_INVALID_DRIVE
Definition: winerror.h:240
#define CO_E_CLASSSTRING
Definition: winerror.h:3919
__wchar_t WCHAR
Definition: xmlstorage.h:180