[SHELL32_APITEST] SHParseDisplayName: More tests for relative paths
[reactos.git] / modules / rostests / apitests / shell32 / SHParseDisplayName.cpp
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 #include "apitest.h"
10 #include <ndk/umtypes.h>
11 #include <strsafe.h>
12
13 /* Version masks */
14 #define T_ALL 0x0
15 #define T_WIN2K 0x1
16 #define T_WINXP 0x2
17 #define T_WIN2K3 0x4
18 #define T_VISTA 0x8
19 #define T_WIN7 0x10
20 #define T_WIN8 0x20
21 #define T_WIN10 0x40
22
23 #define T_PRE_VISTA T_WIN2K|T_WINXP|T_WIN2K3
24 #define T_VISTA_PLUS T_VISTA|T_WIN7|T_WIN8|T_WIN10
25
26 struct test_data
27 {
28 int testline;
29 PCWSTR wszPathToParse;
30 PCWSTR wszExpectedDisplayName;
31 INT nExpectedCSIDL;
32 HRESULT hResult;
33 UINT ValidForVersion;
34 };
35
36 struct test_data Tests[] =
37 {
38 /* Tests for CDesktopFolder */
39 {__LINE__, NULL, NULL, 0, E_OUTOFMEMORY, T_PRE_VISTA},
40 {__LINE__, NULL, NULL, 0, E_INVALIDARG, T_VISTA_PLUS},
41 {__LINE__, L"", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
42 {__LINE__, L" ", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), T_PRE_VISTA},
43 {__LINE__, L" ", NULL, 0, E_INVALIDARG, T_VISTA_PLUS},
44 {__LINE__, L":", NULL, 0, E_INVALIDARG, 0},
45 {__LINE__, L": ", NULL, 0, E_INVALIDARG, 0},
46 {__LINE__, L" :", NULL, 0, E_INVALIDARG, 0},
47 {__LINE__, L"/", NULL, 0, E_INVALIDARG, 0},
48 {__LINE__, L"//", NULL, 0, E_INVALIDARG, 0},
49 /* This opens C:\ from Win+R and address bar */
50 {__LINE__, L"\\", NULL, 0, E_INVALIDARG, 0},
51 /* These two opens "C:\Program Files" from Win+R and address bar */
52 {__LINE__, L"\\Program Files", NULL, 0, E_INVALIDARG, 0},
53 {__LINE__, L"\\Program Files\\", NULL, 0, E_INVALIDARG, 0},
54 {__LINE__, L"\\\\?", NULL, 0, E_INVALIDARG, 0},
55 {__LINE__, L"\\\\?\\", NULL, 0, E_INVALIDARG, 0},
56 /* Tests for the shell: protocol */
57 {__LINE__, L"shell:", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
58 {__LINE__, L"shell::", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
59 {__LINE__, L"shell:::", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
60 {__LINE__, L"shell:::{", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
61 {__LINE__, L"shell:fail", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), 0},
62 {__LINE__, L"shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
63 {__LINE__, L"shell:desktop", NULL, CSIDL_DESKTOPDIRECTORY, S_OK, T_PRE_VISTA},
64 {__LINE__, L"shell:windows", NULL, CSIDL_WINDOWS, S_OK, T_PRE_VISTA},
65 {__LINE__, L"shell:system", NULL, CSIDL_SYSTEM, S_OK, T_PRE_VISTA},
66 {__LINE__, L"shell:personal", NULL, CSIDL_MYDOCUMENTS, S_OK, T_PRE_VISTA},
67 {__LINE__, L"shell:programs", NULL, CSIDL_PROGRAMS, S_OK, T_PRE_VISTA},
68 {__LINE__, L"shell:programfiles", NULL, CSIDL_PROGRAM_FILES, S_OK, T_PRE_VISTA},
69 /* The following tests are confusing. They don't work for SHParseDisplayName but work on psfDesktop->ParseDisplayName */
70 {__LINE__, L"shell:desktop", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
71 {__LINE__, L"shell:windows", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
72 {__LINE__, L"shell:system", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
73 {__LINE__, L"shell:personal", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
74 {__LINE__, L"shell:programs", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
75 {__LINE__, L"shell:programfiles", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_VISTA_PLUS},
76 /* Tests for CInternet */
77 {__LINE__, L"aa:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
78 {__LINE__, L"garbage:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
79 {__LINE__, L"ftp:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
80 {__LINE__, L"ftp:/", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
81 {__LINE__, L"ftp://", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
82 {__LINE__, L"ftp://a", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
83 {__LINE__, L"ftp://ftp.gnu.org/gnu/octave/", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
84 {__LINE__, L"aa:", L"aa:", 0, S_OK, T_VISTA_PLUS},
85 {__LINE__, L"garbage:", L"garbage:", 0, S_OK, T_VISTA_PLUS},
86 {__LINE__, L"ftp:", L"ftp:", 0, S_OK, T_VISTA_PLUS},
87 {__LINE__, L"ftp:/", L"ftp:/", 0, S_OK, T_VISTA_PLUS},
88 {__LINE__, L"ftp://", L"ftp:///", 0, S_OK, T_VISTA_PLUS},
89 {__LINE__, L"ftp://a", L"ftp://a/", 0, S_OK, T_VISTA_PLUS},
90 {__LINE__, L"ftp://ftp.gnu.org/gnu/octave/", L"ftp://ftp.gnu.org/gnu/octave/", 0, S_OK, T_VISTA_PLUS},
91 /* Tests for CRegFolder */
92 {__LINE__, L"::", NULL, 0, CO_E_CLASSSTRING, 0},
93 {__LINE__, L"::{", NULL, 0, CO_E_CLASSSTRING, 0},
94 {__LINE__, L"::{ ", NULL, 0, CO_E_CLASSSTRING, 0},
95 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
96 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D} ", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
97 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}a", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
98 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}garbage", L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, S_OK, 0},
99 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D ", NULL, 0, CO_E_CLASSSTRING, 0},
100 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\", NULL, 0, E_INVALIDARG, 0},
101 {__LINE__, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\ ", NULL, 0, E_INVALIDARG, 0},
102 {__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},
103 /* Tests for CDrivesFolder */
104 {__LINE__, L"c:", NULL, 0, E_INVALIDARG, T_PRE_VISTA},
105 {__LINE__, L"c:", L"C:\\", 0, S_OK, T_VISTA_PLUS},
106 {__LINE__, L"c:\\", L"C:\\", 0, S_OK, 0},
107 {__LINE__, L"C:\\", L"C:\\", 0, S_OK, 0},
108 {__LINE__, L"y:\\", NULL, 0, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), T_PRE_VISTA},
109 {__LINE__, L"y:\\", NULL, 0, HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE), T_VISTA_PLUS},
110 {__LINE__, L"C:\\ ", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), T_PRE_VISTA},
111 {__LINE__, L"C:\\ ", NULL, 0, E_INVALIDARG, T_VISTA_PLUS},
112 /* Tests for CFSFolder */
113 {__LINE__, L"$", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
114 {__LINE__, L"c:\\Program Files", L"C:\\Program Files", 0, S_OK, 0},
115 {__LINE__, L"c:\\Program Files\\", L"C:\\Program Files", 0, S_OK, 0},
116 /* Paths with . are valid for win+r dialog or address bar but not for ParseDisplayName */
117 {__LINE__, L"c:\\Program Files\\.", NULL, 0, E_INVALIDARG, 0},
118 {__LINE__, L"c:\\Program Files\\..", NULL, 0, E_INVALIDARG, 0}, /* This gives C:\ when entered in address bar */
119 {__LINE__, L".", NULL, 0, E_INVALIDARG, 0},
120 {__LINE__, L"..", NULL, 0, E_INVALIDARG, 0},
121 {__LINE__, L"C:\\.", NULL, 0, E_INVALIDARG, 0},
122 {__LINE__, L"fonts", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0}, /* These three work for ShellExecute */
123 {__LINE__, L"winsxs", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0},
124 {__LINE__, L"system32", NULL, 0, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 0}
125 };
126
127 UINT get_host_os_flag()
128 {
129 switch (LOWORD(GetVersion()))
130 {
131 case 5: return T_WIN2K;
132 case (5 | (1 << 8)): return T_WINXP;
133 case (5 | (2 << 8)): return T_WIN2K3;
134 case 6: return T_VISTA;
135 case (6 | (1 << 8)): return T_WIN7;
136 case (6 | (2 << 8)): return T_WIN8;
137 case 10: return T_WIN10;
138 }
139
140 return 0;
141 }
142
143 START_TEST(SHParseDisplayName)
144 {
145 HRESULT hr;
146 WCHAR winDir[MAX_PATH];
147 UINT os_flag = get_host_os_flag();
148 ok (os_flag != 0, "Incompatible os version %d!", os_flag);
149 if (os_flag == 0)
150 return;
151
152 IShellFolder *psfDesktop;
153 hr = SHGetDesktopFolder(&psfDesktop);
154 ok(hr == S_OK, "hr = %lx\n", hr);
155
156 GetWindowsDirectoryW(winDir, _countof(winDir));
157 SetCurrentDirectoryW(winDir);
158
159 for (UINT i = 0; i < _countof(Tests); i ++)
160 {
161 if (Tests[i].ValidForVersion && !(Tests[i].ValidForVersion & os_flag))
162 continue;
163
164 PIDLIST_ABSOLUTE pidl;
165 HRESULT hr = SHParseDisplayName(Tests[i].wszPathToParse, NULL, &pidl, 0, NULL);
166 ok(hr == Tests[i].hResult, "%d: Expected error 0x%lx, got 0x%lx\n", Tests[i].testline, Tests[i].hResult, hr);
167
168 if (Tests[i].wszExpectedDisplayName == NULL && Tests[i].nExpectedCSIDL == 0)
169 {
170 ok(pidl == NULL, "%d: Expected no pidl\n", Tests[i].testline);
171 continue;
172 }
173
174 ok(pidl != NULL, "%d: Expected pidl on success\n", Tests[i].testline);
175 if(!pidl)
176 continue;
177
178 STRRET strret;
179 hr = psfDesktop->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &strret);
180 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
181
182 ok(strret.uType == STRRET_WSTR, "%d: Expected STRRET_WSTR\n", Tests[i].testline);
183
184 if (Tests[i].wszExpectedDisplayName)
185 {
186 ok(!wcscmp(strret.pOleStr, Tests[i].wszExpectedDisplayName), "%d: expected %S got %S\n", Tests[i].testline, Tests[i].wszExpectedDisplayName, strret.pOleStr);
187 }
188 else
189 {
190 PIDLIST_ABSOLUTE pidlSpecial;
191 hr = SHGetSpecialFolderLocation(NULL, Tests[i].nExpectedCSIDL, &pidlSpecial);
192 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
193
194 STRRET strretSpecial;
195 hr = psfDesktop->GetDisplayNameOf(pidlSpecial, SHGDN_FORPARSING, &strretSpecial);
196 ok(hr == S_OK, "%d: hr = %lx\n", Tests[i].testline, hr);
197
198 ok(strret.uType == STRRET_WSTR, "%d: Expected STRRET_WSTR\n", Tests[i].testline);
199
200 ok(!wcscmp(strret.pOleStr, strretSpecial.pOleStr), "%d: expected %S got %S\n", Tests[i].testline, strretSpecial.pOleStr, strret.pOleStr);
201 }
202 }
203
204 CoUninitialize();
205 }