[BROWSEUI_APITEST] Improve tests for relative paths
[reactos.git] / modules / rostests / apitests / browseui / SHExplorerParseCmdLine.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for SHExplorerParseCmdLine
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org
6 */
7
8 #include <apitest.h>
9
10 //#define UNICODE
11 #include <strsafe.h>
12 #include <shlobj.h>
13
14 // Macro parameters are only expanded in the second nesting...
15 #define _WIDEN(x) L##x
16 #define WIDEN(x) _WIDEN(x)
17
18 #define TEST_FILENAMEA "SHExplorerParseCmdLine.test"
19 #define TEST_FILENAMEW WIDEN(TEST_FILENAMEA)
20
21 #define TEST_PATHA "C:\\SHExplorerParseCmdLine.test"
22 #define TEST_PATHW WIDEN(TEST_PATHA)
23
24 #define PADDING_SIZE 0x100
25
26 typedef struct _EXPLORER_INFO
27 {
28 PWSTR FileName;
29 PIDLIST_ABSOLUTE pidl;
30 DWORD dwFlags;
31 ULONG Unknown1[5];
32 PIDLIST_ABSOLUTE pidlRoot;
33 ULONG Unknown3[4];
34 GUID guidInproc;
35 ULONG Padding[PADDING_SIZE];
36 } EXPLORER_INFO, *PEXPLORER_INFO;
37
38 UINT (WINAPI *SHExplorerParseCmdLine)(_Out_ PEXPLORER_INFO Info);
39
40 #define PIDL_IS_UNTOUCHED -1
41 #define PIDL_IS_NULL -2
42 #define PIDL_IS_PATH -3
43 #define PIDL_IS_EMPTY -4
44 #define PIDL_PATH_EQUALS_PATH -5
45
46 #define InvalidPointer ((PVOID)0x5555555555555555ULL)
47
48 DWORD ReplaceSubstr(
49 _Out_ PWCHAR OutputStr,
50 _In_ DWORD OutputLen,
51 _In_ PCWSTR InputStr,
52 _In_ PCWSTR ReplaceStr,
53 _In_ PCWSTR ReplaceWith)
54 {
55 DWORD result = 0;
56 PCWSTR pos;
57 PCWSTR pwc;
58
59 if (!OutputLen)
60 return result;
61
62 OutputStr[0] = 0;
63 pos = InputStr;
64 pwc = wcsstr(pos, ReplaceStr);
65 while (pwc)
66 {
67 if (StringCchCatNW(OutputStr, OutputLen, pos, pwc - pos) == STRSAFE_E_INSUFFICIENT_BUFFER)
68 break;
69 if (StringCchCatW(OutputStr, OutputLen, ReplaceWith) == STRSAFE_E_INSUFFICIENT_BUFFER)
70 break;
71 result++;
72 pos = pwc + wcslen(ReplaceStr);
73 pwc = wcsstr(pos, ReplaceStr);
74 }
75 StringCchCatW(OutputStr, OutputLen, pos);
76 return result;
77 }
78
79 static
80 VOID
81 TestCommandLine(
82 _In_ INT ExpectedRet,
83 _In_ INT ExpectedCsidl,
84 _In_ DWORD ExpectedFlags,
85 _In_ PCWSTR ExpectedFileName,
86 _In_ PCWSTR PidlPath,
87 _Out_opt_ PUINT PWriteEnd)
88 {
89 EXPLORER_INFO Info;
90 UINT Ret;
91 ULONG i;
92 PDWORD InfoWords = (PDWORD) &Info;
93
94 FillMemory(&Info, sizeof(Info), 0x55);
95 Info.dwFlags = 0x00000000;
96 Ret = SHExplorerParseCmdLine(&Info);
97
98 // Special case for empty cmdline: Ret is the PIDL for the selected folder.
99 if (ExpectedRet == -1)
100 ok((LPITEMIDLIST) Ret == Info.pidl, "Ret = %x, expected %p\n", Ret, Info.pidl);
101 else
102 ok(Ret == ExpectedRet, "Ret = %x, expected %p\n", Ret, (PVOID) ExpectedRet);
103
104 if (ExpectedFileName == NULL)
105 ok(Info.FileName == InvalidPointer, "FileName = %p\n", Info.FileName);
106 else
107 {
108 ok(Info.FileName != NULL && Info.FileName != InvalidPointer, "FileName = %p\n", Info.FileName);
109 if (Info.FileName != NULL && Info.FileName != InvalidPointer)
110 {
111 ok(!wcscmp(Info.FileName, ExpectedFileName), "FileName = %ls, expected %ls\n", Info.FileName, ExpectedFileName);
112 LocalFree(Info.FileName);
113 }
114 }
115
116 ok(Info.dwFlags == ExpectedFlags, "dwFlags = %08lx, expected %08lx\n", Info.dwFlags, ExpectedFlags);
117
118 if (ExpectedCsidl == PIDL_IS_UNTOUCHED)
119 ok(Info.pidl == InvalidPointer, "pidl = %p\n", Info.pidl);
120 else if (ExpectedCsidl == PIDL_IS_NULL)
121 ok(Info.pidl == NULL, "pidl = %p\n", Info.pidl);
122 else
123 {
124 PIDLIST_ABSOLUTE ExpectedPidl;
125 HRESULT hr;
126
127 ok(Info.pidl != NULL, "pidl = %p\n", Info.pidl);
128 if (Info.pidl != NULL && Info.pidl != InvalidPointer)
129 {
130 WCHAR pidlPathName[MAX_PATH] = L"";
131 WCHAR pidlPathTest[MAX_PATH] = L"";
132 WCHAR rootDir[MAX_PATH] = L"";
133 WCHAR curDir[MAX_PATH] = L"";
134 WCHAR replaceName[MAX_PATH];
135
136 GetFullPathNameW(L"\\", _countof(rootDir), rootDir, NULL);
137
138 GetCurrentDirectoryW(_countof(curDir), curDir);
139 if (wcslen(curDir) != 0 && curDir[wcslen(curDir) - 1] != L'\\')
140 StringCchCatW(curDir, _countof(curDir), L"\\");
141
142 if (PidlPath)
143 {
144 StringCchCopyW(pidlPathTest, _countof(pidlPathTest), PidlPath);
145
146 if (wcsstr(pidlPathTest, L"::ROOT::") != NULL && wcslen(rootDir) > 0)
147 {
148 if (ReplaceSubstr(replaceName, _countof(replaceName), pidlPathTest, L"::ROOT::", rootDir))
149 StringCchCopyW(pidlPathTest, _countof(pidlPathTest), replaceName);
150 }
151
152 if (wcsstr(pidlPathTest, L"::CURDIR::") != NULL && wcslen(curDir) > 0)
153 {
154 if (ReplaceSubstr(replaceName, _countof(replaceName), pidlPathTest, L"::CURDIR::", curDir))
155 StringCchCopyW(pidlPathTest, _countof(pidlPathTest), replaceName);
156 }
157 }
158
159 if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555)
160 {
161 SHGetPathFromIDListW(Info.pidl, pidlPathName);
162 }
163
164 if (ExpectedCsidl == PIDL_PATH_EQUALS_PATH)
165 {
166 ok(wcsicmp(pidlPathName, pidlPathTest) == 0, "Path from pidl does not match; pidlPathName=%S\n", pidlPathName);
167 }
168 else if (ExpectedCsidl == PIDL_IS_EMPTY)
169 {
170 ok(wcslen(pidlPathName) == 0, "Unexpected non-empty path from pidl; pidlPathName=%S\n", pidlPathName);
171 }
172 else
173 {
174 if (ExpectedCsidl == PIDL_IS_PATH)
175 {
176 ExpectedPidl = SHSimpleIDListFromPath(pidlPathTest);
177 hr = ExpectedPidl == NULL ? E_FAIL : S_OK;
178 ok(ExpectedPidl != NULL, "SHSimpleIDListFromPath(%S) failed. pidlPathName=%S\n", pidlPathTest, pidlPathName);
179 if (SUCCEEDED(hr))
180 {
181 ok(ILIsEqual(Info.pidl, ExpectedPidl), "Unexpected pidl value %p; pidlPathName=%S pidlPathTest=%S\n", Info.pidl, pidlPathName, pidlPathTest);
182 ILFree(ExpectedPidl);
183 }
184 }
185 else
186 {
187 hr = SHGetFolderLocation(NULL, ExpectedCsidl, NULL, 0, &ExpectedPidl);
188 ok(hr == S_OK, "SHGetFolderLocation returned %08lx\n", hr);
189 if (SUCCEEDED(hr))
190 {
191 BOOL eq = ILIsEqual(Info.pidl, ExpectedPidl);
192 ILFree(ExpectedPidl);
193
194 ok(eq, "Unexpected pidl value %p; pidlPathName=%S CSIDL=%d\n", Info.pidl, pidlPathName, ExpectedCsidl);
195 }
196 }
197 }
198
199 if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555)
200 ILFree(Info.pidl);
201 }
202 }
203
204 for (i = 0; i < sizeof(Info) / sizeof(DWORD); i++)
205 {
206 switch (i*4)
207 {
208 case 0x00: // FileName
209 case 0x04: // pidl
210 case 0x08: // dwFlags
211 case 0x20: // pidlRoot
212 case 0x34: // guidInproc (1/4)
213 case 0x38: // guidInproc (2/4)
214 case 0x3C: // guidInproc (3/4)
215 case 0x40: // guidInproc (4/4)
216 break;
217 default:
218 ok(InfoWords[i] == 0x55555555, "Word 0x%02lx has been set to 0x%08lx\n", i * 4, InfoWords[i]);
219 }
220 }
221
222 if (PWriteEnd)
223 {
224 PBYTE data = (PBYTE)&Info;
225
226 *PWriteEnd = 0;
227
228 for (i = sizeof(Info); i > 0; i--)
229 {
230 if (data[i - 1] != 0x55)
231 {
232 *PWriteEnd = i;
233 break;
234 }
235 }
236 }
237 }
238
239 START_TEST(SHExplorerParseCmdLine)
240 {
241 static struct
242 {
243 INT TestLine;
244 PCWSTR CommandLine;
245 INT ExpectedRet;
246 INT ExpectedCsidl;
247 DWORD ExpectedFlags;
248 PCWSTR ExpectedFileName;
249 PCWSTR PidlPath;
250 } Tests [] =
251 {
252 { __LINE__, L"", -1, CSIDL_MYDOCUMENTS, 0x00000009 },
253 { __LINE__, L"/e", TRUE, PIDL_IS_UNTOUCHED, 0x00000008 },
254 { __LINE__, L"/n", TRUE, PIDL_IS_UNTOUCHED, 0x00004001 },
255 { __LINE__, L"/x", TRUE, PIDL_IS_NULL, 0x02000000, L"/x" },
256 { __LINE__, L"-e", TRUE, PIDL_IS_NULL, 0x02000000, L"-e" },
257 { __LINE__, L"C:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
258 { __LINE__, L"/e,C:\\", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
259 { __LINE__, L"/select,C:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
260 { __LINE__, L"/e,::{20d04fe0-3aea-1069-a2d8-08002b30309d}", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
261 { __LINE__, L"::{645ff040-5081-101b-9f08-00aa002f954e}", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{645ff040-5081-101b-9f08-00aa002f954e}" },
262 { __LINE__, L"/select,::{450d8fba-ad25-11d0-98a8-0800361b1103}", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}" },
263 { __LINE__, L"=", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
264 { __LINE__, L".", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Documents and Settings\\gigaherz\\Desktop" },
265 { __LINE__, L"..", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Documents and Settings\\gigaherz" },
266 { __LINE__, L"wrongpath", TRUE, PIDL_IS_NULL, 0x02000000, L"wrongpath"},
267 { __LINE__, L"%wrongdir%", TRUE, PIDL_IS_NULL, 0x02000000, L"%wrongdir%"},
268 { __LINE__, L"%programfiles#", TRUE, PIDL_IS_NULL, 0x02000000, L"%programfiles#"},
269 { __LINE__, L",", TRUE, PIDL_IS_EMPTY, 0x00000200},
270 { __LINE__, L"\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::ROOT::" }, // disk letter depends on current directory
271 { __LINE__, L"c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
272 { __LINE__, L"c:", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
273 { __LINE__, L"c", TRUE, PIDL_IS_NULL, 0x02000000, L"c"},
274 { __LINE__, L"c:\\Program Files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
275 { __LINE__, L"c:\\Program Files\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
276 { __LINE__, L"c:\\Program Files/", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\Program Files/"},
277 { __LINE__, L"c:/Program Files/", TRUE, PIDL_IS_NULL, 0x02000000, L"c:/Program Files/"},
278 { __LINE__, L"fonts", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::fonts" }, // this would not fail if we are in Windows directory
279 { __LINE__, L"winsxs", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::winsxs" },
280 { __LINE__, L"system32", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::system32" },
281 { __LINE__, L"drivers", TRUE, PIDL_IS_NULL, 0x02000000, L"drivers" }, // this would fail since we are not in system32 directory
282 { __LINE__, L"spool", TRUE, PIDL_IS_NULL, 0x02000000, L"spool" },
283 { __LINE__, L"wbem", TRUE, PIDL_IS_NULL, 0x02000000, L"wbem" },
284 { __LINE__, TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000200, NULL, TEST_PATHW },
285 { __LINE__, L"\"c:\\\"\"program files\"", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\\"program files"},
286 { __LINE__, L"\"c:\\\"program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
287 { __LINE__, L"\"c:\\ \"program files", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\ program files"},
288 { __LINE__, L"\"c:\\\" program files", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\ program files"},
289 { __LINE__, L"\"c:\\\", \"c:\\program files\"", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
290 { __LINE__, L"c:\\,c:\\program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
291 { __LINE__, L"/root", 0, CSIDL_MYDOCUMENTS, 0x00000000},
292 { __LINE__, L"\"/root\"", 0, CSIDL_MYDOCUMENTS, 0x00000000},
293 { __LINE__, L"/root,", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
294 { __LINE__, L"/root,c", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
295 { __LINE__, L"/root,\"\"", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
296 { __LINE__, L"/root,wrong", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
297 { __LINE__, L"/root,0", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
298 { __LINE__, L"/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
299 { __LINE__, L"/root,\"c:\\\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
300 { __LINE__, L"/root \"c:\\\"", TRUE, PIDL_IS_NULL, 0x02000000, L"/root c:\\"},
301 { __LINE__, L"/root,\"c:\\\"\"program files\"", TRUE, PIDL_IS_PATH, 0x00000000},
302 { __LINE__, L"/root,\"c:\\\"program files", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\Program Files" },
303 { __LINE__, L"/root,c:\\,c:\\Program Files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
304 { __LINE__, L"/root,c:\\,Program Files", TRUE, PIDL_IS_NULL, 0x02000000, L"Program Files"},
305 { __LINE__, L"/root,\"c:\\\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
306 { __LINE__, L"c:\\Program Files,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000200, NULL, L"c:\\" },
307 { __LINE__, L"a:\\,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000200, NULL, L"c:\\" },
308 { __LINE__, L"a:\\,/root,c", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"A:\\" },
309 { __LINE__, L"c:\\,/root,c", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
310 { __LINE__, L"/select", TRUE, CSIDL_MYDOCUMENTS, 0x00000040},
311 { __LINE__, L"/select,", TRUE, CSIDL_DRIVES, 0x00000240 },
312 { __LINE__, L"/select,c", TRUE, PIDL_IS_NULL, 0x02000040, L"c"},
313 { __LINE__, L"/select,0", TRUE, PIDL_IS_NULL, 0x02000040, L"0"},
314 { __LINE__, L"/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
315 { __LINE__, L"c:\\,/select", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
316 { __LINE__, L"/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
317 { __LINE__, L"/select,c:\\Program Files,c:\\Documents and settings", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\Documents and Settings" },
318 { __LINE__, L"c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000240, TEST_FILENAMEW },
319 { __LINE__, L"c:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
320 { __LINE__, L"a:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
321 { __LINE__, L"z:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x02000240, L"z:\\", TEST_PATHW },
322 { __LINE__, L"select,c:\\ ", TRUE, PIDL_IS_PATH, 0x02000200, L"select", L"C:\\" },
323 { __LINE__, L"/select c:\\ ", TRUE, PIDL_IS_NULL, 0x02000000, L"/select c:\\"},
324 { __LINE__, L"a:\\,/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
325 { __LINE__, L"a:\\,/select,c", TRUE, PIDL_IS_NULL, 0x02000240, L"c"},
326 { __LINE__, L"c:\\,/select,c", TRUE, PIDL_IS_NULL, 0x02000240, L"c"},
327 { __LINE__, L"/e", TRUE, CSIDL_MYDOCUMENTS, 0x00000008},
328 { __LINE__, L"/e,", TRUE, CSIDL_DRIVES, 0x00000208 },
329 { __LINE__, L"/e,\"", TRUE, CSIDL_DRIVES, 0x00000208 },
330 { __LINE__, L"/e,\"\"", TRUE, CSIDL_DRIVES, 0x00000208 },
331 { __LINE__, L"/e,c:\\", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
332 { __LINE__, L"c:\\,/e", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
333 { __LINE__, L"/e,c", TRUE, PIDL_IS_NULL, 0x02000008, L"c"},
334 { __LINE__, L"/root,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000040, TEST_FILENAMEW },
335 { __LINE__, L"/select," TEST_FILENAMEW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x02000040, TEST_FILENAMEW, L"c:\\" },
336 { __LINE__, L"/root,c:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
337 { __LINE__, L"/select," TEST_PATHW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000240, NULL, L"c:\\" },
338 { __LINE__, L"/e,/select," TEST_FILENAMEW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x02000048, TEST_FILENAMEW, L"c:\\" },
339 { __LINE__, L"/e,/root,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000048, TEST_FILENAMEW },
340 { __LINE__, L"/e,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000008, NULL, L"c:\\" },
341 { __LINE__, L"/e,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
342 { __LINE__, L"c:\\,/e,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
343 { __LINE__, L"c:\\,/select," TEST_FILENAMEW L",/e", TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
344 { __LINE__, L"http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000000, L"http:\\\\www.reactos.org"},
345 { __LINE__, L"/e,http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000008, L"http:\\\\www.reactos.org"},
346 { __LINE__, L"/root,c:\\,http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000000, L"http:\\\\www.reactos.org"},
347 { __LINE__, L"/separate ", TRUE, CSIDL_MYDOCUMENTS, 0x00020000},
348 { __LINE__, L"/separate,c:\\ program files", TRUE, PIDL_IS_NULL, 0x02020000, L"c:\\ program files"},
349 { __LINE__, L"/separate, c:\\program files", TRUE, PIDL_IS_PATH, 0x00020200, NULL, L"C:\\Program Files" },
350 { __LINE__, L"/separate, c:\\program files ,/e", TRUE, PIDL_IS_PATH, 0x00020208, NULL, L"C:\\Program Files" },
351 { __LINE__, L"/separate, c:\\program files ,\\e", TRUE, PIDL_IS_NULL, 0x02020200, L"\\e"},
352 { __LINE__, L"c:\\Documents and settings,/separate,/n,/e,/root,c:\\,/select,c:\\Program files,", TRUE, CSIDL_DRIVES, 0x00024249 },
353 { __LINE__, L"c:\\Documents and settings,/separate,/n,/e,/root,{450D8FBA-AD25-11D0-98A8-0800361B1103, 0},test,/select,c:\\Program files,", TRUE, CSIDL_DRIVES, 0x02024249, L"test" },
354 { __LINE__, L"c:\\Documents and settings,/inproc,/noui,/s,/separate,/n,/e,/root,{450D8FBA-AD25-11D0-98A8-0800361B1103, 0},test,/select,c:\\Program files,", FALSE, PIDL_PATH_EQUALS_PATH, 0x00000200, NULL, L"C:\\Documents and Settings" },
355 { __LINE__, L"=", TRUE, CSIDL_DRIVES, 0x00000200 },
356 { __LINE__, L"=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
357 { __LINE__, L"=" TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000200, NULL, TEST_PATHW },
358 { __LINE__, L"/root,=", TRUE, CSIDL_DRIVES, 0x00000200 },
359 { __LINE__, L"/root=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
360 { __LINE__, L"/root=c:\\Program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
361 { __LINE__, L"/root=\"c:\\Program files\"", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
362 { __LINE__, L"/root=\"\"c:\\Program files\"\"", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
363 { __LINE__, L"c:\\=/root=\"c:\\Program files\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"C:\\Program Files" },
364 { __LINE__, L"/select=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
365 { __LINE__, L"/select=c:\\Program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
366 { __LINE__, L"=,/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
367 { __LINE__, L"/select,c:\\,=", TRUE, CSIDL_DRIVES, 0x00000240 },
368 { __LINE__, L"c:\\=/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\WINDOWS\\system32" },
369 { __LINE__, L"/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\WINDOWS\\system32" },
370 { __LINE__, L"=/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\WINDOWS\\system32" },
371 { __LINE__, L"/e,=", TRUE, CSIDL_DRIVES, 0x00000208 },
372 { __LINE__, L"/e=", TRUE, CSIDL_DRIVES, 0x00000200 },
373 { __LINE__, L"/e=\"", TRUE, CSIDL_DRIVES, 0x00000200 },
374 { __LINE__, L"/e=\"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
375 { __LINE__, L"=\"=\"", TRUE, PIDL_IS_NULL, 0x02000000, L"="},
376 { __LINE__, L"==\"=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"="},
377 { __LINE__, L"===\"=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"="},
378 { __LINE__, L"=\"=\"", TRUE, PIDL_IS_NULL, 0x02000000, L"="},
379 { __LINE__, L"==\"==\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=="},
380 { __LINE__, L"===\"===\"", TRUE, PIDL_IS_NULL, 0x02000200, L"==="},
381 { __LINE__, L"=\"=a\"", TRUE, PIDL_IS_NULL, 0x02000000, L"=a"},
382 { __LINE__, L"==\"=a=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=a="},
383 { __LINE__, L"===\"=a=a=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=a=a="},
384 { __LINE__, L"=\"=a\"==", TRUE, CSIDL_DRIVES, 0x02000200, L"=a" },
385 { __LINE__, L"==\"=a=\"=", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=" },
386 { __LINE__, L"===\"=a=a=\"===", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=a=" },
387 { __LINE__, L"=,=,=,\"=a=a=\",=,=,=", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=a=" },
388 { __LINE__, L"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
389 { __LINE__, L"\"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
390 { __LINE__, L"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\""},
391 { __LINE__, L"\"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\""},
392 { __LINE__, L"\"\"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\"\""},
393 { __LINE__, L"/s", TRUE, CSIDL_MYDOCUMENTS, 0x00000002},
394 { __LINE__, L"/noui", TRUE, CSIDL_MYDOCUMENTS, 0x00001000},
395 { __LINE__, L"/idlist", TRUE, PIDL_IS_UNTOUCHED, 0x00000000},
396 { __LINE__, L"-embedding", TRUE, CSIDL_MYDOCUMENTS, 0x00000080 },
397 { __LINE__, L"/inproc", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
398 { __LINE__, L"/inproc,1", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
399 { __LINE__, L"/inproc,a", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
400 { __LINE__, L"/inproc,c:\\", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
401 { __LINE__, L"/inproc,\"c:\\\"", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
402 { __LINE__, L"/inproc,{20d04fe0-3aea-1069-a2d8-08002b30309d}", TRUE, PIDL_IS_UNTOUCHED, 0x00000400 },
403 };
404 const int TestCount = sizeof(Tests) / sizeof(Tests[0]);
405 PWSTR CommandLine;
406 WCHAR OriginalCommandLine[1024];
407 int i;
408 UINT maxWrite = 0;
409 FILE * ff;
410 WCHAR winDir[MAX_PATH];
411
412 HMODULE browseui = LoadLibraryA("browseui.dll");
413 SHExplorerParseCmdLine = (UINT (__stdcall *)(PEXPLORER_INFO))GetProcAddress(browseui, MAKEINTRESOURCEA(107));
414 if (!SHExplorerParseCmdLine)
415 {
416 skip("SHExplorerParseCmdLine not found, NT 6.0?\n");
417 return;
418 }
419
420 CommandLine = GetCommandLineW();
421 StringCbCopyW(OriginalCommandLine, sizeof(OriginalCommandLine), CommandLine);
422
423 ff = fopen(TEST_PATHA, "wb");
424 fclose(ff);
425
426 GetWindowsDirectoryW(winDir, _countof(winDir));
427 SetCurrentDirectoryW(winDir);
428
429 for (i = 0; i < TestCount; i++)
430 {
431 UINT cWrite;
432
433 wcscpy(CommandLine, L"browseui_apitest.exe ");
434 wcscat(CommandLine, Tests[i].CommandLine);
435 trace("Command line (%d): %ls\n", Tests[i].TestLine, CommandLine);
436 TestCommandLine(Tests[i].ExpectedRet,
437 Tests[i].ExpectedCsidl,
438 Tests[i].ExpectedFlags,
439 Tests[i].ExpectedFileName,
440 Tests[i].PidlPath,
441 &cWrite);
442
443 if (cWrite > maxWrite)
444 maxWrite = cWrite;
445 }
446
447 trace("Writes reached the byte right before 0x%08x\n", maxWrite);
448
449 wcscpy(CommandLine, OriginalCommandLine);
450
451 remove(TEST_PATHA);
452 }