ReactOS  0.4.14-dev-342-gdc047f9
SHExplorerParseCmdLine.c File Reference
#include <apitest.h>
#include <strsafe.h>
#include <shlobj.h>
Include dependency graph for SHExplorerParseCmdLine.c:

Go to the source code of this file.

Classes

struct  _EXPLORER_INFO
 

Macros

#define _WIDEN(x)   L##x
 
#define WIDEN(x)   _WIDEN(x)
 
#define TEST_FILENAMEA   "SHExplorerParseCmdLine.test"
 
#define TEST_FILENAMEW   WIDEN(TEST_FILENAMEA)
 
#define TEST_PATHA   "C:\\SHExplorerParseCmdLine.test"
 
#define TEST_PATHW   WIDEN(TEST_PATHA)
 
#define PADDING_SIZE   0x100
 
#define PIDL_IS_UNTOUCHED   -1
 
#define PIDL_IS_NULL   -2
 
#define PIDL_IS_PATH   -3
 
#define PIDL_IS_EMPTY   -4
 
#define PIDL_PATH_EQUALS_PATH   -5
 
#define InvalidPointer   ((PVOID)0x5555555555555555ULL)
 

Typedefs

typedef struct _EXPLORER_INFO EXPLORER_INFO
 
typedef struct _EXPLORER_INFOPEXPLORER_INFO
 

Functions

 UINT_PTR (WINAPI *SHExplorerParseCmdLine)(_Out_ PEXPLORER_INFO Info)
 
DWORD ReplaceSubstr (_Out_ PWCHAR OutputStr, _In_ DWORD OutputLen, _In_ PCWSTR InputStr, _In_ PCWSTR ReplaceStr, _In_ PCWSTR ReplaceWith)
 
static VOID TestCommandLine (_In_ INT ExpectedRet, _In_ INT ExpectedCsidl, _In_ DWORD ExpectedFlags, _In_ PCWSTR ExpectedFileName, _In_ PCWSTR PidlPath, _Out_opt_ PUINT PWriteEnd)
 
 START_TEST (SHExplorerParseCmdLine)
 

Macro Definition Documentation

◆ _WIDEN

#define _WIDEN (   x)    L##x

Definition at line 15 of file SHExplorerParseCmdLine.c.

◆ InvalidPointer

#define InvalidPointer   ((PVOID)0x5555555555555555ULL)

Definition at line 46 of file SHExplorerParseCmdLine.c.

◆ PADDING_SIZE

#define PADDING_SIZE   0x100

Definition at line 24 of file SHExplorerParseCmdLine.c.

◆ PIDL_IS_EMPTY

#define PIDL_IS_EMPTY   -4

Definition at line 43 of file SHExplorerParseCmdLine.c.

◆ PIDL_IS_NULL

#define PIDL_IS_NULL   -2

Definition at line 41 of file SHExplorerParseCmdLine.c.

◆ PIDL_IS_PATH

#define PIDL_IS_PATH   -3

Definition at line 42 of file SHExplorerParseCmdLine.c.

◆ PIDL_IS_UNTOUCHED

#define PIDL_IS_UNTOUCHED   -1

Definition at line 40 of file SHExplorerParseCmdLine.c.

◆ PIDL_PATH_EQUALS_PATH

#define PIDL_PATH_EQUALS_PATH   -5

Definition at line 44 of file SHExplorerParseCmdLine.c.

◆ TEST_FILENAMEA

#define TEST_FILENAMEA   "SHExplorerParseCmdLine.test"

Definition at line 18 of file SHExplorerParseCmdLine.c.

◆ TEST_FILENAMEW

#define TEST_FILENAMEW   WIDEN(TEST_FILENAMEA)

Definition at line 19 of file SHExplorerParseCmdLine.c.

◆ TEST_PATHA

#define TEST_PATHA   "C:\\SHExplorerParseCmdLine.test"

Definition at line 21 of file SHExplorerParseCmdLine.c.

◆ TEST_PATHW

#define TEST_PATHW   WIDEN(TEST_PATHA)

Definition at line 22 of file SHExplorerParseCmdLine.c.

◆ WIDEN

#define WIDEN (   x)    _WIDEN(x)

Definition at line 16 of file SHExplorerParseCmdLine.c.

Typedef Documentation

◆ EXPLORER_INFO

◆ PEXPLORER_INFO

Function Documentation

◆ ReplaceSubstr()

DWORD ReplaceSubstr ( _Out_ PWCHAR  OutputStr,
_In_ DWORD  OutputLen,
_In_ PCWSTR  InputStr,
_In_ PCWSTR  ReplaceStr,
_In_ PCWSTR  ReplaceWith 
)

Definition at line 48 of file SHExplorerParseCmdLine.c.

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 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
unsigned long DWORD
Definition: ntddk_ex.h:95
STRSAFEAPI StringCchCatNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToAppend)
Definition: strsafe.h:407
GLuint64EXT * result
Definition: glext.h:11304
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by TestCommandLine().

◆ START_TEST()

START_TEST ( SHExplorerParseCmdLine  )

Definition at line 239 of file SHExplorerParseCmdLine.c.

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");
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 
452 }
#define PIDL_IS_EMPTY
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
#define PIDL_IS_PATH
struct _EXPLORER_INFO * PEXPLORER_INFO
uint16_t * PWSTR
Definition: typedefs.h:54
#define PIDL_PATH_EQUALS_PATH
#define _countof(array)
Definition: fontsub.cpp:30
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
int32_t INT
Definition: typedefs.h:56
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
#define CSIDL_MYDOCUMENTS
Definition: shlobj.h:2015
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:2019
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
smooth NULL
Definition: ftsmooth.c:416
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define TEST_PATHW
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define __stdcall
Definition: typedefs.h:25
UINT_PTR WINAPI SHExplorerParseCmdLine(ExplorerCommandLineParseResults *pInfo)
_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 PIDL_IS_UNTOUCHED
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
_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
#define skip(...)
Definition: atltest.h:64
UINT_PTR(WINAPI *SHExplorerParseCmdLine)(_Out_ PEXPLORER_INFO Info)
#define PIDL_IS_NULL
#define TEST_FILENAMEW
#define GetProcAddress(x, y)
Definition: compat.h:418
int remove
Definition: msacm.c:1365
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
struct test_data Tests[]
#define TEST_PATHA
static VOID TestCommandLine(_In_ INT ExpectedRet, _In_ INT ExpectedCsidl, _In_ DWORD ExpectedFlags, _In_ PCWSTR ExpectedFileName, _In_ PCWSTR PidlPath, _Out_opt_ PUINT PWriteEnd)

◆ TestCommandLine()

static VOID TestCommandLine ( _In_ INT  ExpectedRet,
_In_ INT  ExpectedCsidl,
_In_ DWORD  ExpectedFlags,
_In_ PCWSTR  ExpectedFileName,
_In_ PCWSTR  PidlPath,
_Out_opt_ PUINT  PWriteEnd 
)
static

Definition at line 81 of file SHExplorerParseCmdLine.c.

88 {
90  UINT_PTR Ret;
91  ULONG i;
92  PDWORD InfoWords = (PDWORD) &Info;
93 
94  FillMemory(&Info, sizeof(Info), 0x55);
95  Info.dwFlags = 0x00000000;
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 %08x\n", Ret, 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 }
#define PIDL_IS_EMPTY
#define PIDL_IS_PATH
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define PIDL_PATH_EQUALS_PATH
#define _countof(array)
Definition: fontsub.cpp:30
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
BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:535
#define E_FAIL
Definition: ddrawi.h:102
#define eq(received, expected, label, type)
Definition: locale.c:144
struct TraceInfo Info
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
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
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
smooth NULL
Definition: ftsmooth.c:416
#define InvalidPointer
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
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
static const WCHAR L[]
Definition: oid.c:1250
#define PIDL_IS_UNTOUCHED
#define wcsicmp
Definition: string.h:1152
_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)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPITEMIDLIST WINAPI SHSimpleIDListFromPath(LPCWSTR)
#define ok(value,...)
Definition: atltest.h:57
DWORD * PDWORD
Definition: pedump.c:68
#define PIDL_IS_NULL
unsigned int ULONG
Definition: retypes.h:1
HRESULT WINAPI SHGetFolderLocation(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2672
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ UINT_PTR()

UINT_PTR ( WINAPI SHExplorerParseCmdLine)

Referenced by START_TEST().