ReactOS  0.4.14-dev-1034-g1e60116
SHExplorerParseCmdLine.c
Go to the documentation of this file.
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 {
37 
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 
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
82 _In_ ULONG TestLine,
83 _In_ INT ExpectedRet,
84 _In_ INT ExpectedCsidl,
85 _In_ DWORD ExpectedFlags,
86 _In_ PCWSTR ExpectedFileName,
87 _In_ PCWSTR PidlPath,
88 _Out_opt_ PUINT PWriteEnd)
89 {
91  UINT_PTR Ret;
92  ULONG i;
93  PDWORD InfoWords = (PDWORD) &Info;
94 
95  FillMemory(&Info, sizeof(Info), 0x55);
96  Info.dwFlags = 0x00000000;
98 
99  // Special case for empty cmdline: Ret is the PIDL for the selected folder.
100  if (ExpectedRet == -1)
101  ok((LPITEMIDLIST) Ret == Info.pidl, "Line %lu: Ret = %x, expected %p\n", TestLine, Ret, Info.pidl);
102  else
103  ok(Ret == ExpectedRet, "Line %lu: Ret = %x, expected %08x\n", TestLine, Ret, ExpectedRet);
104 
105  if (ExpectedFileName == NULL)
106  ok(Info.FileName == InvalidPointer, "Line %lu: FileName = %p\n", TestLine, Info.FileName);
107  else
108  {
109  ok(Info.FileName != NULL && Info.FileName != InvalidPointer, "Line %lu: FileName = %p\n", TestLine, Info.FileName);
110  if (Info.FileName != NULL && Info.FileName != InvalidPointer)
111  {
112  ok(!wcscmp(Info.FileName, ExpectedFileName), "Line %lu: FileName = %ls, expected %ls\n", TestLine, Info.FileName, ExpectedFileName);
113  LocalFree(Info.FileName);
114  }
115  }
116 
117  ok(Info.dwFlags == ExpectedFlags, "Line %lu: dwFlags = %08lx, expected %08lx\n", TestLine, Info.dwFlags, ExpectedFlags);
118 
119  if (ExpectedCsidl == PIDL_IS_UNTOUCHED)
120  ok(Info.pidl == InvalidPointer, "Line %lu: pidl = %p\n", TestLine, Info.pidl);
121  else if (ExpectedCsidl == PIDL_IS_NULL)
122  ok(Info.pidl == NULL, "Line %lu: pidl = %p\n", TestLine, Info.pidl);
123  else
124  {
125  PIDLIST_ABSOLUTE ExpectedPidl;
126  HRESULT hr;
127 
128  ok(Info.pidl != NULL, "Line %lu: pidl = %p\n", TestLine, Info.pidl);
129  if (Info.pidl != NULL && Info.pidl != InvalidPointer)
130  {
131  WCHAR pidlPathName[MAX_PATH] = L"";
132  WCHAR pidlPathTest[MAX_PATH] = L"";
133  WCHAR rootDir[MAX_PATH] = L"";
134  WCHAR curDir[MAX_PATH] = L"";
135  WCHAR replaceName[MAX_PATH];
136 
137  GetFullPathNameW(L"\\", _countof(rootDir), rootDir, NULL);
138 
139  GetCurrentDirectoryW(_countof(curDir), curDir);
140  if (wcslen(curDir) != 0 && curDir[wcslen(curDir) - 1] != L'\\')
141  StringCchCatW(curDir, _countof(curDir), L"\\");
142 
143  if (PidlPath)
144  {
145  StringCchCopyW(pidlPathTest, _countof(pidlPathTest), PidlPath);
146 
147  if (wcsstr(pidlPathTest, L"::ROOT::") != NULL && wcslen(rootDir) > 0)
148  {
149  if (ReplaceSubstr(replaceName, _countof(replaceName), pidlPathTest, L"::ROOT::", rootDir))
150  StringCchCopyW(pidlPathTest, _countof(pidlPathTest), replaceName);
151  }
152 
153  if (wcsstr(pidlPathTest, L"::CURDIR::") != NULL && wcslen(curDir) > 0)
154  {
155  if (ReplaceSubstr(replaceName, _countof(replaceName), pidlPathTest, L"::CURDIR::", curDir))
156  StringCchCopyW(pidlPathTest, _countof(pidlPathTest), replaceName);
157  }
158  }
159 
160  if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555)
161  {
162  SHGetPathFromIDListW(Info.pidl, pidlPathName);
163  }
164 
165  if (ExpectedCsidl == PIDL_PATH_EQUALS_PATH)
166  {
167  ok(wcsicmp(pidlPathName, pidlPathTest) == 0, "Line %lu: Path from pidl does not match; pidlPathName=%S\n", TestLine, pidlPathName);
168  }
169  else if (ExpectedCsidl == PIDL_IS_EMPTY)
170  {
171  ok(wcslen(pidlPathName) == 0, "Line %lu: Unexpected non-empty path from pidl; pidlPathName=%S\n", TestLine, pidlPathName);
172  }
173  else
174  {
175  if (ExpectedCsidl == PIDL_IS_PATH)
176  {
177  ExpectedPidl = SHSimpleIDListFromPath(pidlPathTest);
178  hr = ExpectedPidl == NULL ? E_FAIL : S_OK;
179  ok(ExpectedPidl != NULL, "Line %lu: SHSimpleIDListFromPath(%S) failed. pidlPathName=%S\n", TestLine, pidlPathTest, pidlPathName);
180  if (SUCCEEDED(hr))
181  {
182  ok(ILIsEqual(Info.pidl, ExpectedPidl), "Line %lu: Unexpected pidl value %p; pidlPathName=%S pidlPathTest=%S\n", TestLine, Info.pidl, pidlPathName, pidlPathTest);
183  ILFree(ExpectedPidl);
184  }
185  }
186  else
187  {
188  hr = SHGetFolderLocation(NULL, ExpectedCsidl, NULL, 0, &ExpectedPidl);
189  ok(hr == S_OK, "Line %lu: SHGetFolderLocation returned %08lx\n", TestLine, hr);
190  if (SUCCEEDED(hr))
191  {
192  BOOL eq = ILIsEqual(Info.pidl, ExpectedPidl);
193  ILFree(ExpectedPidl);
194 
195  ok(eq, "Line %lu: Unexpected pidl value %p; pidlPathName=%S CSIDL=%d\n", TestLine, Info.pidl, pidlPathName, ExpectedCsidl);
196  }
197  }
198  }
199 
200  if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555)
201  ILFree(Info.pidl);
202  }
203  }
204 
205  for (i = 0; i < sizeof(Info) / sizeof(DWORD); i++)
206  {
207  switch (i*4)
208  {
209  case 0x00: // FileName
210  case 0x04: // pidl
211  case 0x08: // dwFlags
212  case 0x20: // pidlRoot
213  case 0x34: // guidInproc (1/4)
214  case 0x38: // guidInproc (2/4)
215  case 0x3C: // guidInproc (3/4)
216  case 0x40: // guidInproc (4/4)
217  break;
218  default:
219  ok(InfoWords[i] == 0x55555555, "Line %lu: Word 0x%02lx has been set to 0x%08lx\n", TestLine, i * 4, InfoWords[i]);
220  }
221  }
222 
223  if (PWriteEnd)
224  {
225  PBYTE data = (PBYTE)&Info;
226 
227  *PWriteEnd = 0;
228 
229  for (i = sizeof(Info); i > 0; i--)
230  {
231  if (data[i - 1] != 0x55)
232  {
233  *PWriteEnd = i;
234  break;
235  }
236  }
237  }
238 }
239 
241 {
242  static struct
243  {
244  INT TestLine;
245  PCWSTR CommandLine;
246  INT ExpectedRet;
247  INT ExpectedCsidl;
248  DWORD ExpectedFlags;
249  PCWSTR ExpectedFileName;
250  PCWSTR PidlPath;
251  } Tests [] =
252  {
253  { __LINE__, L"", -1, CSIDL_MYDOCUMENTS, 0x00000009 },
254  { __LINE__, L"/e", TRUE, PIDL_IS_UNTOUCHED, 0x00000008 },
255  { __LINE__, L"/n", TRUE, PIDL_IS_UNTOUCHED, 0x00004001 },
256  { __LINE__, L"/x", TRUE, PIDL_IS_NULL, 0x02000000, L"/x" },
257  { __LINE__, L"-e", TRUE, PIDL_IS_NULL, 0x02000000, L"-e" },
258  { __LINE__, L"C:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
259  { __LINE__, L"/e,C:\\", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
260  { __LINE__, L"/select,C:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
261  { __LINE__, L"/e,::{20d04fe0-3aea-1069-a2d8-08002b30309d}", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
262  { __LINE__, L"::{645ff040-5081-101b-9f08-00aa002f954e}", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{645ff040-5081-101b-9f08-00aa002f954e}" },
263  { __LINE__, L"/select,::{450d8fba-ad25-11d0-98a8-0800361b1103}", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}" },
264  { __LINE__, L"=", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
265 // { __LINE__, L".", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Documents and Settings\\gigaherz\\Desktop" },
266 // { __LINE__, L"..", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Documents and Settings\\gigaherz" },
267  { __LINE__, L"wrongpath", TRUE, PIDL_IS_NULL, 0x02000000, L"wrongpath"},
268  { __LINE__, L"%wrongdir%", TRUE, PIDL_IS_NULL, 0x02000000, L"%wrongdir%"},
269  { __LINE__, L"%programfiles#", TRUE, PIDL_IS_NULL, 0x02000000, L"%programfiles#"},
270  { __LINE__, L",", TRUE, PIDL_IS_EMPTY, 0x00000200},
271  { __LINE__, L"\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::ROOT::" }, // disk letter depends on current directory
272  { __LINE__, L"c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
273  { __LINE__, L"c:", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
274  { __LINE__, L"c", TRUE, PIDL_IS_NULL, 0x02000000, L"c"},
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_PATH, 0x00000200, NULL, L"C:\\Program Files" },
277  { __LINE__, L"c:\\Program Files/", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\Program Files/"},
278  { __LINE__, L"c:/Program Files/", TRUE, PIDL_IS_NULL, 0x02000000, L"c:/Program Files/"},
279  { __LINE__, L"fonts", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::fonts" }, // this would not fail if we are in Windows directory
280  { __LINE__, L"winsxs", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::winsxs" },
281  { __LINE__, L"system32", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::CURDIR::system32" },
282  { __LINE__, L"drivers", TRUE, PIDL_IS_NULL, 0x02000000, L"drivers" }, // this would fail since we are not in system32 directory
283  { __LINE__, L"spool", TRUE, PIDL_IS_NULL, 0x02000000, L"spool" },
284  // { __LINE__, L"wbem", TRUE, PIDL_IS_NULL, 0x02000000, L"wbem" },
285  { __LINE__, TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000200, NULL, TEST_PATHW },
286  { __LINE__, L"\"c:\\\"\"program files\"", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\\"program files"},
287  { __LINE__, L"\"c:\\\"program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
288  { __LINE__, L"\"c:\\ \"program files", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\ program files"},
289  { __LINE__, L"\"c:\\\" program files", TRUE, PIDL_IS_NULL, 0x02000000, L"c:\\ program files"},
290  { __LINE__, L"\"c:\\\", \"c:\\program files\"", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
291  { __LINE__, L"c:\\,c:\\program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
292  { __LINE__, L"/root", 0, CSIDL_MYDOCUMENTS, 0x00000000},
293  { __LINE__, L"\"/root\"", 0, CSIDL_MYDOCUMENTS, 0x00000000},
294  { __LINE__, L"/root,", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
295  { __LINE__, L"/root,c", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
296  { __LINE__, L"/root,\"\"", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
297  { __LINE__, L"/root,wrong", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
298  { __LINE__, L"/root,0", TRUE, CSIDL_MYDOCUMENTS, 0x00000000},
299  { __LINE__, L"/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
300  { __LINE__, L"/root,\"c:\\\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
301  { __LINE__, L"/root \"c:\\\"", TRUE, PIDL_IS_NULL, 0x02000000, L"/root c:\\"},
302  { __LINE__, L"/root,\"c:\\\"\"program files\"", TRUE, PIDL_IS_PATH, 0x00000000},
303  { __LINE__, L"/root,\"c:\\\"program files", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\Program Files" },
304  { __LINE__, L"/root,c:\\,c:\\Program Files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
305  { __LINE__, L"/root,c:\\,Program Files", TRUE, PIDL_IS_NULL, 0x02000000, L"Program Files"},
306  { __LINE__, L"/root,\"c:\\\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"c:\\" },
307  { __LINE__, L"c:\\Program Files,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000200, NULL, L"c:\\" },
308 // { __LINE__, L"a:\\,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000200, NULL, L"c:\\" },
309 // { __LINE__, L"a:\\,/root,c", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"A:\\" },
310  { __LINE__, L"c:\\,/root,c", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
311  { __LINE__, L"/select", TRUE, CSIDL_MYDOCUMENTS, 0x00000040},
312  { __LINE__, L"/select,", TRUE, CSIDL_DRIVES, 0x00000240 },
313  { __LINE__, L"/select,c", TRUE, PIDL_IS_NULL, 0x02000040, L"c"},
314  { __LINE__, L"/select,0", TRUE, PIDL_IS_NULL, 0x02000040, L"0"},
315  { __LINE__, L"/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
316  { __LINE__, L"c:\\,/select", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
317  { __LINE__, L"/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
318  { __LINE__, L"/select,c:\\Program Files,c:\\Documents and settings", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\Documents and Settings" },
319  { __LINE__, L"c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000240, TEST_FILENAMEW },
320  { __LINE__, L"c:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
321 // { __LINE__, L"a:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
322  { __LINE__, L"z:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x02000240, L"z:\\", TEST_PATHW },
323  { __LINE__, L"select,c:\\ ", TRUE, PIDL_IS_PATH, 0x02000200, L"select", L"C:\\" },
324  { __LINE__, L"/select c:\\ ", TRUE, PIDL_IS_NULL, 0x02000000, L"/select c:\\"},
325 // { __LINE__, L"a:\\,/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
326  { __LINE__, L"a:\\,/select,c", TRUE, PIDL_IS_NULL, 0x02000040, L"c"},
327  { __LINE__, L"c:\\,/select,c", TRUE, PIDL_IS_NULL, 0x02000240, L"c"},
328  { __LINE__, L"/e", TRUE, CSIDL_MYDOCUMENTS, 0x00000008},
329  { __LINE__, L"/e,", TRUE, CSIDL_DRIVES, 0x00000208 },
330  { __LINE__, L"/e,\"", TRUE, CSIDL_DRIVES, 0x00000208 },
331  { __LINE__, L"/e,\"\"", TRUE, CSIDL_DRIVES, 0x00000208 },
332  { __LINE__, L"/e,c:\\", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
333  { __LINE__, L"c:\\,/e", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
334  { __LINE__, L"/e,c", TRUE, PIDL_IS_NULL, 0x02000008, L"c"},
335  { __LINE__, L"/root,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000040, TEST_FILENAMEW },
336  { __LINE__, L"/select," TEST_FILENAMEW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x02000040, TEST_FILENAMEW, L"c:\\" },
337  { __LINE__, L"/root,c:\\,/select," TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000240, NULL, TEST_PATHW },
338  { __LINE__, L"/select," TEST_PATHW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000240, NULL, L"c:\\" },
339  { __LINE__, L"/e,/select," TEST_FILENAMEW L",/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x02000048, TEST_FILENAMEW, L"c:\\" },
340  { __LINE__, L"/e,/root,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000048, TEST_FILENAMEW },
341  { __LINE__, L"/e,/root,c:\\", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000008, NULL, L"c:\\" },
342  { __LINE__, L"/e,c:\\,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
343  { __LINE__, L"c:\\,/e,/select," TEST_FILENAMEW, TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
344  { __LINE__, L"c:\\,/select," TEST_FILENAMEW L",/e", TRUE, PIDL_IS_NULL, 0x02000248, TEST_FILENAMEW },
345  { __LINE__, L"http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000000, L"http:\\\\www.reactos.org"},
346  { __LINE__, L"/e,http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000008, L"http:\\\\www.reactos.org"},
347  { __LINE__, L"/root,c:\\,http:\\\\www.reactos.org", TRUE, PIDL_IS_NULL, 0x02000000, L"http:\\\\www.reactos.org"},
348  { __LINE__, L"/separate ", TRUE, CSIDL_MYDOCUMENTS, 0x00020000},
349  { __LINE__, L"/separate,c:\\ program files", TRUE, PIDL_IS_NULL, 0x02020000, L"c:\\ program files"},
350  { __LINE__, L"/separate, c:\\program files", TRUE, PIDL_IS_PATH, 0x00020200, NULL, L"C:\\Program Files" },
351  { __LINE__, L"/separate, c:\\program files ,/e", TRUE, PIDL_IS_PATH, 0x00020208, NULL, L"C:\\Program Files" },
352  { __LINE__, L"/separate, c:\\program files ,\\e", TRUE, PIDL_IS_NULL, 0x02020200, L"\\e"},
353  { __LINE__, L"c:\\Documents and settings,/separate,/n,/e,/root,c:\\,/select,c:\\Program files,", TRUE, CSIDL_DRIVES, 0x00024249 },
354  { __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" },
355  { __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" },
356  { __LINE__, L"=", TRUE, CSIDL_DRIVES, 0x00000200 },
357  { __LINE__, L"=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
358  { __LINE__, L"=" TEST_PATHW, TRUE, PIDL_IS_PATH, 0x00000200, NULL, TEST_PATHW },
359  { __LINE__, L"/root,=", TRUE, CSIDL_DRIVES, 0x00000200 },
360  { __LINE__, L"/root=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
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"/root=\"\"c:\\Program files\"\"", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
364  { __LINE__, L"c:\\=/root=\"c:\\Program files\"", TRUE, PIDL_PATH_EQUALS_PATH, 0x00000000, NULL, L"C:\\Program Files" },
365  { __LINE__, L"/select=c:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
366  { __LINE__, L"/select=c:\\Program files", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\Program Files" },
367  { __LINE__, L"=,/select,c:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
368  { __LINE__, L"/select,c:\\,=", TRUE, CSIDL_DRIVES, 0x00000240 },
369  { __LINE__, L"c:\\=/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\WINDOWS\\system32" },
370  { __LINE__, L"/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\WINDOWS\\system32" },
371  { __LINE__, L"=/select=c:\\windows\\system32", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\WINDOWS\\system32" },
372  { __LINE__, L"/e,=", TRUE, CSIDL_DRIVES, 0x00000208 },
373  { __LINE__, L"/e=", TRUE, CSIDL_DRIVES, 0x00000200 },
374  { __LINE__, L"/e=\"", TRUE, CSIDL_DRIVES, 0x00000200 },
375  { __LINE__, L"/e=\"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
376  { __LINE__, L"=\"=\"", TRUE, PIDL_IS_NULL, 0x02000000, L"="},
377  { __LINE__, L"==\"=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"="},
378  { __LINE__, L"===\"=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"="},
379  { __LINE__, L"=\"=\"", TRUE, PIDL_IS_NULL, 0x02000000, L"="},
380  { __LINE__, L"==\"==\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=="},
381  { __LINE__, L"===\"===\"", TRUE, PIDL_IS_NULL, 0x02000200, L"==="},
382  { __LINE__, L"=\"=a\"", TRUE, PIDL_IS_NULL, 0x02000000, L"=a"},
383  { __LINE__, L"==\"=a=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=a="},
384  { __LINE__, L"===\"=a=a=\"", TRUE, PIDL_IS_NULL, 0x02000200, L"=a=a="},
385  { __LINE__, L"=\"=a\"==", TRUE, CSIDL_DRIVES, 0x02000200, L"=a" },
386  { __LINE__, L"==\"=a=\"=", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=" },
387  { __LINE__, L"===\"=a=a=\"===", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=a=" },
388  { __LINE__, L"=,=,=,\"=a=a=\",=,=,=", TRUE, CSIDL_DRIVES, 0x02000200, L"=a=a=" },
389  { __LINE__, L"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
390  { __LINE__, L"\"\"", TRUE, CSIDL_DRIVES, 0x00000200 },
391  { __LINE__, L"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\""},
392  { __LINE__, L"\"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\""},
393  { __LINE__, L"\"\"\"\"\"", TRUE, PIDL_IS_NULL, 0x02000000, L"\"\""},
394  { __LINE__, L"/s", TRUE, CSIDL_MYDOCUMENTS, 0x00000002},
395  { __LINE__, L"/noui", TRUE, CSIDL_MYDOCUMENTS, 0x00001000},
396  { __LINE__, L"/idlist", TRUE, PIDL_IS_UNTOUCHED, 0x00000000},
397  { __LINE__, L"-embedding", TRUE, CSIDL_MYDOCUMENTS, 0x00000080 },
398  { __LINE__, L"/inproc", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
399  { __LINE__, L"/inproc,1", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
400  { __LINE__, L"/inproc,a", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
401  { __LINE__, L"/inproc,c:\\", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
402  { __LINE__, L"/inproc,\"c:\\\"", FALSE, PIDL_IS_UNTOUCHED, 0x00000000 },
403  { __LINE__, L"/inproc,{20d04fe0-3aea-1069-a2d8-08002b30309d}", TRUE, PIDL_IS_UNTOUCHED, 0x00000400 },
404  };
405  const int TestCount = sizeof(Tests) / sizeof(Tests[0]);
406  PWSTR CommandLine;
407  WCHAR OriginalCommandLine[1024];
408  int i;
409  UINT maxWrite = 0;
410  FILE * ff;
411  WCHAR winDir[MAX_PATH];
412 
413  HMODULE browseui = LoadLibraryA("browseui.dll");
416  {
417  skip("SHExplorerParseCmdLine not found, NT 6.0?\n");
418  return;
419  }
420 
421  CommandLine = GetCommandLineW();
422  StringCbCopyW(OriginalCommandLine, sizeof(OriginalCommandLine), CommandLine);
423 
424  ff = fopen(TEST_PATHA, "wb");
425  fclose(ff);
426 
427  GetWindowsDirectoryW(winDir, _countof(winDir));
428  SetCurrentDirectoryW(winDir);
429 
430  for (i = 0; i < TestCount; i++)
431  {
432  UINT cWrite;
433 
434  wcscpy(CommandLine, L"browseui_apitest.exe ");
435  wcscat(CommandLine, Tests[i].CommandLine);
436  trace("Command line (%d): %ls\n", Tests[i].TestLine, CommandLine);
437  TestCommandLine(Tests[i].TestLine,
438  Tests[i].ExpectedRet,
439  Tests[i].ExpectedCsidl,
440  Tests[i].ExpectedFlags,
441  Tests[i].ExpectedFileName,
442  Tests[i].PidlPath,
443  &cWrite);
444 
445  if (cWrite > maxWrite)
446  maxWrite = cWrite;
447  }
448 
449  trace("Writes reached the byte right before 0x%08x\n", maxWrite);
450 
451  wcscpy(CommandLine, OriginalCommandLine);
452 
454 }
PIDLIST_ABSOLUTE pidl
#define PIDL_IS_EMPTY
const uint16_t * PCWSTR
Definition: typedefs.h:56
#define TRUE
Definition: types.h:120
#define PIDL_IS_PATH
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
ULONG Padding[PADDING_SIZE]
HRESULT hr
Definition: shlfolder.c:183
struct _EXPLORER_INFO * PEXPLORER_INFO
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
uint16_t * PWSTR
Definition: typedefs.h:55
#define PIDL_PATH_EQUALS_PATH
#define _countof(array)
Definition: fontsub.cpp:30
static VOID TestCommandLine(_In_ ULONG TestLine, _In_ INT ExpectedRet, _In_ INT ExpectedCsidl, _In_ DWORD ExpectedFlags, _In_ PCWSTR ExpectedFileName, _In_ PCWSTR PidlPath, _Out_opt_ PUINT PWriteEnd)
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:421
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:535
uint16_t * PWCHAR
Definition: typedefs.h:55
#define E_FAIL
Definition: ddrawi.h:102
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
#define eq(received, expected, label, type)
Definition: locale.c:144
int32_t INT
Definition: typedefs.h:57
struct TraceInfo Info
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
#define CSIDL_MYDOCUMENTS
Definition: shlobj.h:2023
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_DRIVES
Definition: shlobj.h:2027
unsigned int BOOL
Definition: ntddk_ex.h:94
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
START_TEST(SHExplorerParseCmdLine)
PIDLIST_ABSOLUTE WINAPI SHSimpleIDListFromPath(PCWSTR)
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
#define InvalidPointer
#define _Out_opt_
Definition: no_sal2.h:339
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define TEST_PATHW
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define __stdcall
Definition: typedefs.h:25
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
UINT_PTR WINAPI SHExplorerParseCmdLine(ExplorerCommandLineParseResults *pInfo)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define PADDING_SIZE
#define PIDL_IS_UNTOUCHED
STRSAFEAPI StringCchCatNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToAppend)
Definition: strsafe.h:407
#define wcsicmp
Definition: string.h:1152
#define _In_
Definition: no_sal2.h:204
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define S_OK
Definition: intsafe.h:59
DWORD ReplaceSubstr(_Out_ PWCHAR OutputStr, _In_ DWORD OutputLen, _In_ PCWSTR InputStr, _In_ PCWSTR ReplaceStr, _In_ PCWSTR ReplaceWith)
PIDLIST_ABSOLUTE pidlRoot
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
#define ok(value,...)
Definition: atltest.h:57
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned int UINT
Definition: ndis.h:50
DWORD * PDWORD
Definition: pedump.c:68
#define skip(...)
Definition: atltest.h:64
UINT_PTR(WINAPI *SHExplorerParseCmdLine)(_Out_ PEXPLORER_INFO Info)
#define PIDL_IS_NULL
#define TEST_FILENAMEW
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:418
HRESULT WINAPI SHGetFolderLocation(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2741
struct _EXPLORER_INFO EXPLORER_INFO
int remove
Definition: msacm.c:1365
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
GLuint64EXT * result
Definition: glext.h:11304
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
struct test_data Tests[]
#define TEST_PATHA
unsigned int * PUINT
Definition: ndis.h:50
#define SUCCEEDED(hr)
Definition: intsafe.h:57