[KMTESTS]
[reactos.git] / 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 #define UNKNOWN_SIZE 0x100
15
16 typedef struct _EXPLORER_INFO
17 {
18 PWSTR FileName;
19 PIDLIST_ABSOLUTE pidl;
20 DWORD dwFlags; /* TODO: make some constants */
21 ULONG Unknown[UNKNOWN_SIZE]; /* TODO: find out more */
22 } EXPLORER_INFO, *PEXPLORER_INFO;
23
24 PVOID
25 WINAPI
26 SHExplorerParseCmdLine(
27 _Out_ PEXPLORER_INFO Info);
28
29 #define PIDL_IS_UNTOUCHED -1
30 #define PIDL_IS_NULL -2
31 #define PIDL_IS_PATH -3
32
33 #define InvalidPointer ((PVOID)0x5555555555555555ULL)
34
35 static
36 VOID
37 TestCommandLine(
38 _In_ INT ExpectedRet,
39 _In_ INT ExpectedCsidl,
40 _In_ DWORD ExpectedFlags,
41 _In_ PCWSTR ExpectedFileName,
42 _In_ PCWSTR PidlPath)
43 {
44 EXPLORER_INFO Info;
45 PVOID Ret;
46 ULONG i;
47
48 FillMemory(&Info, sizeof(Info), 0x55);
49 Info.dwFlags = 0x00000000;
50 Ret = SHExplorerParseCmdLine(&Info);
51
52 if (ExpectedRet == -1)
53 ok(Ret == Info.pidl, "Ret = %p, expected %p\n", Ret, Info.pidl);
54 else
55 ok(Ret == (PVOID)ExpectedRet, "Ret = %p, expected %p\n", Ret, (PVOID)ExpectedRet);
56
57 if (ExpectedFileName == NULL)
58 ok(Info.FileName == InvalidPointer, "FileName = %p\n", Info.FileName);
59 else
60 {
61 ok(Info.FileName != NULL && Info.FileName != InvalidPointer, "FileName = %p\n", Info.FileName);
62 if (Info.FileName != NULL && Info.FileName != InvalidPointer)
63 {
64 ok(!wcscmp(Info.FileName, ExpectedFileName), "FileName = %ls, expected %ls\n", Info.FileName, ExpectedFileName);
65 LocalFree(Info.FileName);
66 }
67 }
68
69 if (ExpectedCsidl == PIDL_IS_UNTOUCHED)
70 ok(Info.pidl == InvalidPointer, "pidl = %p\n", Info.pidl);
71 else if (ExpectedCsidl == PIDL_IS_NULL)
72 ok(Info.pidl == NULL, "pidl = %p\n", Info.pidl);
73 else
74 {
75 PIDLIST_ABSOLUTE ExpectedPidl;
76 HRESULT hr;
77
78 ok(Info.pidl != NULL, "pidl = %p\n", Info.pidl);
79 if (Info.pidl != NULL && Info.pidl != InvalidPointer)
80 {
81 if (ExpectedCsidl == PIDL_IS_PATH)
82 {
83 ExpectedPidl = SHSimpleIDListFromPath(PidlPath);
84 hr = ExpectedPidl == NULL ? E_FAIL : S_OK;
85 ok(ExpectedPidl != NULL, "SHSimpleIDListFromPath failed\n");
86 }
87 else
88 {
89 hr = SHGetFolderLocation(NULL, ExpectedCsidl, NULL, 0, &ExpectedPidl);
90 ok(hr == S_OK, "SHGetFolderLocation returned %08lx\n", hr);
91 }
92 if (SUCCEEDED(hr))
93 {
94 ok(ILIsEqual(Info.pidl, ExpectedPidl), "Unexpected pidl value\n");
95 ILFree(ExpectedPidl);
96 }
97 ILFree(Info.pidl);
98 }
99 }
100
101 ok(Info.dwFlags == ExpectedFlags, "dwFlags = %08lx, expected %08lx\n", Info.dwFlags, ExpectedFlags);
102 for (i = 0; i < sizeof(Info.Unknown) / sizeof(Info.Unknown[0]); i++)
103 ok(Info.Unknown[i] == 0x55555555, "Unknown[%lu] = %08lx\n", i, Info.Unknown[i]);
104 }
105
106 START_TEST(SHExplorerParseCmdLine)
107 {
108 struct
109 {
110 PCWSTR CommandLine;
111 INT ExpectedRet;
112 INT ExpectedCsidl;
113 DWORD ExpectedFlags;
114 PCWSTR ExpectedFileName;
115 PCWSTR PidlPath;
116 } Tests[] =
117 {
118 { L"", -1, CSIDL_MYDOCUMENTS, 0x00000009 },
119 { L"/e", TRUE, PIDL_IS_UNTOUCHED, 0x00000008 },
120 { L"/n", TRUE, PIDL_IS_UNTOUCHED, 0x00004001 },
121 { L"/x", TRUE, PIDL_IS_NULL, 0x02000000, L"/x" },
122 { L"-e", TRUE, PIDL_IS_NULL, 0x02000000, L"-e" },
123 { L"C:\\", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"C:\\" },
124 { L"/e,C:\\", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"C:\\" },
125 { L"/select,C:\\", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"C:\\" },
126 { L"/e,::{20d04fe0-3aea-1069-a2d8-08002b30309d}", TRUE, PIDL_IS_PATH, 0x00000208, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
127 { L"::{645ff040-5081-101b-9f08-00aa002f954e}", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{645ff040-5081-101b-9f08-00aa002f954e}" },
128 { L"/select,::{450d8fba-ad25-11d0-98a8-0800361b1103}", TRUE, PIDL_IS_PATH, 0x00000240, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}" },
129 { L"=", TRUE, PIDL_IS_PATH, 0x00000200, NULL, L"::{20d04fe0-3aea-1069-a2d8-08002b30309d}" },
130 /* TODO: needs a lot more testcases */
131 };
132 const int TestCount = sizeof(Tests) / sizeof(Tests[0]);
133 PWSTR CommandLine;
134 WCHAR OriginalCommandLine[1024];
135 int i;
136
137 CommandLine = GetCommandLineW();
138 StringCbCopyW(OriginalCommandLine, sizeof(OriginalCommandLine), CommandLine);
139
140 for (i = 0; i < TestCount; i++)
141 {
142 wcscpy(CommandLine, L"browseui_apitest.exe ");
143 wcscat(CommandLine, Tests[i].CommandLine);
144 trace("Command line: %ls\n", CommandLine);
145 TestCommandLine(Tests[i].ExpectedRet,
146 Tests[i].ExpectedCsidl,
147 Tests[i].ExpectedFlags,
148 Tests[i].ExpectedFileName,
149 Tests[i].PidlPath);
150 }
151
152 wcscpy(CommandLine, OriginalCommandLine);
153 }