ReactOS 0.4.16-dev-1946-g52006dd
cmd.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Test for cmd.exe
5 * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9
10#define TIMEOUT 3000
11
12typedef struct TEST_ENTRY
13{
16 const char *cmdline;
19 const char *OutputContains;
20 const char *ErrorContains;
21 const char *OutputNotContains;
22 const char *ErrorNotContains;
24
25#define TRISTATE 2
26
27static const TEST_ENTRY s_exit_entries[] =
28{
29 { __LINE__, 0, "cmd /c exit" },
30 { __LINE__, 0, "cmd /c exit 0" },
31 { __LINE__, 0, "cmd /c exit \"\"" },
32 { __LINE__, 0, "cmd /c exit ABC" },
33 { __LINE__, 0, "cmd /c exit \"ABC" },
34 { __LINE__, 0, "cmd /c exit \"ABC\"" },
35 { __LINE__, 1234, "cmd /c exit 1234" },
36};
37
38static const TEST_ENTRY s_echo_entries[] =
39{
40// { __LINE__, 0, "cmd /c echo", TRUE, FALSE, NULL, "ECHO" },
41 { __LINE__, 0, "cmd /c echo.", TRUE, FALSE, "\r\n" },
42 { __LINE__, 0, "cmd /c echo ABC", TRUE, FALSE, "ABC\r\n" },
43};
44
45static const TEST_ENTRY s_cd_entries[] =
46{
47 { __LINE__, 0, "cmd /c cd \"C:\\ " },
48 { __LINE__, 0, "cmd /c cd C:/" },
49 { __LINE__, 0, "cmd /c cd \"\"", TRUE, FALSE },
50 { __LINE__, 0, "cmd /c cd", TRUE, FALSE },
51 { __LINE__, 1234, "cmd /c cd C:\\Program Files && exit 1234" },
52 { __LINE__, 1234, "cmd /c cd \"C:\\ \" && exit 1234" },
53 { __LINE__, 1234, "cmd /c cd \"C:\\Program Files\" && exit 1234" },
54 { __LINE__, 1234, "cmd /c cd \"\" && exit 1234", TRUE, FALSE },
55 { __LINE__, 1234, "cmd /c cd \\ && exit 1234" },
56};
57
59{
60 { __LINE__, 0, "cmd /c pushd C:\\ " },
61 { __LINE__, 0, "cmd /c pushd C:\\ \"" },
62 { __LINE__, 0, "cmd /c pushd C:\\ \"\"" },
63 { __LINE__, 0, "cmd /c pushd C:\\ \"\"\"" },
64 { __LINE__, 0, "cmd /c pushd C:\\ \"\"\"\"" },
65 { __LINE__, 0, "cmd /c pushd C:\\ \" " },
66 { __LINE__, 0, "cmd /c pushd C:\\ \"\" " },
67 { __LINE__, 0, "cmd /c pushd C:\\ \"\"\" " },
68 { __LINE__, 0, "cmd /c pushd C:\\ \"\"\"\" " },
69 { __LINE__, 0, "cmd /c pushd C:\\" },
70 { __LINE__, 0, "cmd /c pushd C:\\\"" },
71 { __LINE__, 0, "cmd /c pushd C:\\\"\"" },
72 { __LINE__, 0, "cmd /c pushd C:\\\"\"\"" },
73 { __LINE__, 0, "cmd /c pushd C:\\\"\"\"\"" },
74 { __LINE__, 0, "cmd /c pushd C:\\\" " },
75 { __LINE__, 0, "cmd /c pushd C:\\\"\" " },
76 { __LINE__, 0, "cmd /c pushd C:\\\"\"\" " },
77 { __LINE__, 0, "cmd /c pushd C:\\\"\"\"\" " },
78 { __LINE__, 0, "cmd /c pushd \"C:\\ " },
79 { __LINE__, 0, "cmd /c pushd \"C:\\ \"" },
80 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\"" },
81 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\"\"" },
82 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\"\"\"" },
83 { __LINE__, 0, "cmd /c pushd \"C:\\ \" " },
84 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\" " },
85 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\"\" " },
86 { __LINE__, 0, "cmd /c pushd \"C:\\ \"\"\"\" " },
87 { __LINE__, 0, "cmd /c pushd \"C:\\" },
88 { __LINE__, 0, "cmd /c pushd \"C:\\\"" },
89 { __LINE__, 0, "cmd /c pushd \"C:\\\"\"" },
90 { __LINE__, 0, "cmd /c pushd \"C:\\\"\"\"" },
91 { __LINE__, 0, "cmd /c pushd \"C:\\\"\"\"\"" },
92 { __LINE__, 0, "cmd /c pushd \"C:\\\"" },
93 { __LINE__, 1, "cmd /c pushd \" C:\\ ", FALSE, TRUE },
94 { __LINE__, 1, "cmd /c pushd \" C:\\ \"", FALSE, TRUE },
95 { __LINE__, 1, "cmd /c pushd \" C:\\ \"\"", FALSE, TRUE },
96 { __LINE__, 1, "cmd /c pushd \" C:\\ \"\"\"", FALSE, TRUE },
97 { __LINE__, 1, "cmd /c pushd \" C:\\ \"\"\"\"", FALSE, TRUE },
98 { __LINE__, 1, "cmd /c pushd \"\" C:\\ ", FALSE, TRUE },
99 { __LINE__, 1, "cmd /c pushd \"\" C:\\ \"", FALSE, TRUE },
100 { __LINE__, 1, "cmd /c pushd \"\" C:\\ \"\"", FALSE, TRUE },
101 { __LINE__, 1, "cmd /c pushd \"\" C:\\ \"\"\"", FALSE, TRUE },
102 { __LINE__, 1, "cmd /c pushd \"\" C:\\ \"\"\"\"", FALSE, TRUE },
103 { __LINE__, 1, "cmd /c pushd \"\" C:\\\"", FALSE, TRUE },
104 { __LINE__, 1, "cmd /c popd ABC" },
105 { __LINE__, 1, "cmd /c popd \" " },
106 { __LINE__, 1, "cmd /c popd \"\"" },
107 { __LINE__, 1, "cmd /c popd" },
108 { __LINE__, 1, "cmd /c pushd ABC", FALSE, TRUE },
109 { __LINE__, 1, "cmd /c pushd C:/Program Files && popd && exit 1234", FALSE, TRUE },
110 { __LINE__, 1, "cmd /c pushd C:\\ C:\\ && popd && exit 1234", FALSE, TRUE },
111 { __LINE__, 1, "cmd /c pushd C:\\Invalid Directory && exit 1234", FALSE, TRUE },
112 { __LINE__, 1, "cmd /c pushd C:\\Invalid Directory && popd && exit 1234", FALSE, TRUE },
113 { __LINE__, 1, "cmd /c pushd \" C:\\ ", FALSE, TRUE },
114 { __LINE__, 1, "cmd /c pushd \"C:\\ C:\\\" && popd && exit 1234", FALSE, TRUE },
115 { __LINE__, 1234, "cmd /c pushd && exit 1234 " },
116 { __LINE__, 1234, "cmd /c pushd C:\\ && popd && exit 1234" },
117 { __LINE__, 1234, "cmd /c pushd C:\\ \"\" && popd && exit 1234" },
118 { __LINE__, 1234, "cmd /c pushd C:\\Program Files && popd && exit 1234" },
119// { __LINE__, 1234, "cmd /c pushd \"C:/Program Files/\" && popd && exit 1234" },
120// { __LINE__, 1234, "cmd /c pushd \"C:/Program Files\" && popd && exit 1234" },
121 { __LINE__, 1234, "cmd /c pushd \"C:\\ \" && popd && exit 1234" },
122 { __LINE__, 1234, "cmd /c pushd \"C:\\ \"\"\" && popd && exit 1234" },
123 { __LINE__, 1234, "cmd /c pushd \"C:\\ \"\"\"\"\" && popd && exit 1234" },
124 { __LINE__, 1234, "cmd /c pushd \"C:\\Program Files\" && popd && exit 1234" },
125 { __LINE__, 1234, "cmd /c pushd \"C:\\Program Files\\\" && popd && exit 1234" },
126 { __LINE__, 1234, "cmd /c pushd \"C:\\\" && popd && exit 1234" },
127};
128
130{
131 /* invalid-path.txt */
132 { __LINE__, 0, "attrib invalid-path.txt", TRUE, FALSE },
133 { __LINE__, 0, "attrib +H invalid-path.txt", TRUE, FALSE },
134 { __LINE__, 0, "attrib -H invalid-path.txt", TRUE, FALSE },
135
136 /* attr-test.txt */
137 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
138 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
139 { __LINE__, 0, "cmd /c copy NUL attr-test.txt ", TRUE, FALSE },
140 { __LINE__, 0, "attrib attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
141 { __LINE__, 0, "attrib +H attr-test.txt", FALSE, FALSE },
142 { __LINE__, 0, "attrib attr-test.txt", TRUE, FALSE, " H " },
143 { __LINE__, 0, "attrib -H attr-test.txt", FALSE, FALSE },
144 { __LINE__, 0, "attrib attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
145 { __LINE__, 0, "attrib attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
146 { __LINE__, 0, "attrib +H attr-te*.txt", FALSE, FALSE },
147 { __LINE__, 0, "attrib attr-te*.txt", TRUE, FALSE, " H " },
148 { __LINE__, 0, "attrib -H attr-te*.txt", FALSE, FALSE },
149 { __LINE__, 0, "attrib attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
150 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
151 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
152
153 /* /S attr-test.txt */
154 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
155 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
156 { __LINE__, 0, "cmd /c copy NUL attr-test.txt ", TRUE, FALSE },
157 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
158 { __LINE__, 0, "attrib /S +H attr-test.txt", FALSE, FALSE },
159 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, " H " },
160 { __LINE__, 0, "attrib /S -H attr-test.txt", FALSE, FALSE },
161 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
162 { __LINE__, 0, "attrib /S attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
163 { __LINE__, 0, "attrib /S +H attr-te*.txt", FALSE, FALSE },
164 { __LINE__, 0, "attrib /S attr-te*.txt", TRUE, FALSE, " H " },
165 { __LINE__, 0, "attrib /S -H attr-te*.txt", FALSE, FALSE },
166 { __LINE__, 0, "attrib /S attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
167 { __LINE__, 0, "attrib /S +H", TRISTATE, FALSE },
168 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, " H " },
169 { __LINE__, 0, "attrib /S -H", TRISTATE, FALSE },
170 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
171 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
172 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
173
174 /* /S /D attr-test.txt */
175 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
176 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
177 { __LINE__, 0, "cmd /c copy NUL attr-test.txt ", TRUE, FALSE },
178 { __LINE__, 0, "attrib /S /D attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
179 { __LINE__, 0, "attrib /S /D +H attr-test.txt", FALSE, FALSE },
180 { __LINE__, 0, "attrib /S /D attr-test.txt", TRUE, FALSE, " H " },
181 { __LINE__, 0, "attrib /S /D -H attr-test.txt", FALSE, FALSE },
182 { __LINE__, 0, "attrib /S /D attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
183 { __LINE__, 0, "attrib /S /D attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
184 { __LINE__, 0, "attrib /S /D +H attr-te*.txt", FALSE, FALSE },
185 { __LINE__, 0, "attrib /S /D attr-te*.txt", TRUE, FALSE, " H " },
186 { __LINE__, 0, "attrib /S /D -H attr-te*.txt", FALSE, FALSE },
187 { __LINE__, 0, "attrib /S /D attr-te*.txt", TRUE, FALSE, NULL, NULL, " H " },
188 { __LINE__, 0, "cmd /c if exist attr-test.txt attrib -H attr-test.txt" },
189 { __LINE__, 0, "cmd /c if exist attr-test.txt del /Q attr-test.txt" },
190
191 /* attr-dir, attr-dir/test.txt */
192 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
193 { __LINE__, 0, "cmd /c mkdir attr-dir", FALSE, FALSE },
194 { __LINE__, 0, "cmd /c if exist attr-dir/test.txt attrib -H attr-dir/test.txt" },
195 { __LINE__, 0, "cmd /c if exist attr-dir/test.txt del /Q attr-dir/test.txt" },
196 { __LINE__, 1, "cmd /c copy NUL attr-dir/test.txt ", TRUE, FALSE },
197 { __LINE__, 0, "attrib attr-dir/test.txt", TRUE, FALSE, NULL, NULL, " H " },
198 { __LINE__, 0, "attrib +H attr-dir/test.txt", TRUE, FALSE },
199 { __LINE__, 0, "attrib attr-dir/test.txt", TRUE, FALSE, NULL, NULL, " H " },
200 { __LINE__, 0, "attrib -H attr-dir/test.txt", TRUE, FALSE, "test.txt" },
201 { __LINE__, 0, "attrib attr-dir/test.txt", TRUE, FALSE, NULL, NULL, " H " },
202 { __LINE__, 0, "attrib +H attr-dir", FALSE, FALSE, NULL, NULL, " H " },
203 { __LINE__, 0, "attrib attr-dir", TRUE, FALSE, " H " },
204 { __LINE__, 0, "attrib attr-dir/test.txt", TRUE, FALSE, NULL, NULL, " H " },
205 { __LINE__, 0, "attrib -H attr-dir", FALSE, FALSE, NULL, NULL, " H " },
206 { __LINE__, 0, "attrib attr-dir", TRUE, FALSE, NULL, NULL, " H " },
207 { __LINE__, 0, "cmd /c if exist attr-dir/test.txt attrib -H attr-dir/test.txt" },
208 { __LINE__, 0, "cmd /c if exist attr-dir/test.txt del /Q attr-dir/test.txt" },
209 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
210
211 /* attr-dir, attr-dir\\dir1 */
212 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
213 { __LINE__, 0, "cmd /c mkdir attr-dir", FALSE, FALSE },
214 { __LINE__, 0, "attrib attr-dir", TRUE, FALSE, NULL, NULL, " H " },
215 { __LINE__, 0, "cmd /c if exist attr-dir echo OK", TRUE, FALSE, "OK" },
216 { __LINE__, 0, "cmd /c mkdir attr-dir\\dir1", FALSE, FALSE },
217 { __LINE__, 0, "cmd /c if exist attr-dir\\dir1 echo OK", TRUE, FALSE, "OK" },
218 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
219 { __LINE__, 0, "attrib +H attr-dir\\dir1", FALSE, FALSE },
220 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, " H " },
221 { __LINE__, 0, "attrib -H attr-dir\\dir1", FALSE, FALSE },
222 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
223 { __LINE__, 0, "attrib +H attr-dir", FALSE, FALSE },
224 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
225 { __LINE__, 0, "attrib -H attr-dir", FALSE, FALSE },
226 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
227 { __LINE__, 0, "attrib +H attr-d*", TRUE, FALSE, "attr-d*" },
228 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
229 { __LINE__, 0, "attrib -H attr-d*", TRUE, FALSE, "attr-d*" },
230 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
231 { __LINE__, 0, "attrib +H attr-dir\\d*", TRUE, FALSE, "attr-dir\\d*" },
232 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
233 { __LINE__, 0, "attrib -H attr-dir\\d*", TRUE, FALSE, "attr-dir\\d*" },
234 { __LINE__, 0, "attrib attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
235 { __LINE__, 0, "attrib -H attr-dir\\dir1", FALSE, FALSE },
236 { __LINE__, 0, "attrib -H attr-dir", FALSE, FALSE },
237 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
238
239 /* /S attr-dir, attr-dir\\dir1 */
240 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
241 { __LINE__, 0, "cmd /c mkdir attr-dir", FALSE, FALSE },
242 { __LINE__, 0, "attrib /S attr-dir", TRUE, FALSE, NULL, NULL, " H " },
243 { __LINE__, 0, "cmd /c if exist attr-dir echo OK", TRUE, FALSE, "OK" },
244 { __LINE__, 0, "cmd /c mkdir attr-dir\\dir1", FALSE, FALSE },
245 { __LINE__, 0, "cmd /c if exist attr-dir\\dir1 echo OK", TRUE, FALSE, "OK" },
246 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
247 { __LINE__, 0, "attrib /S +H attr-dir\\dir1", TRUE, FALSE, "attr-dir\\dir1", },
248 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, "attr-dir\\dir1" },
249 { __LINE__, 0, "attrib /S -H attr-dir\\dir1", TRUE, FALSE, "attr-dir\\dir1" },
250 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
251 { __LINE__, 0, "attrib /S +H attr-dir", TRUE, FALSE, "attr-dir" },
252 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
253 { __LINE__, 0, "attrib /S -H attr-dir", TRUE, FALSE, "attr-dir" },
254 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
255 { __LINE__, 0, "attrib /S +H attr-d*", TRUE, FALSE, "attr-d*" },
256 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
257 { __LINE__, 0, "attrib /S -H attr-d*", TRUE, FALSE, "attr-d*" },
258 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
259 { __LINE__, 0, "attrib /S +H attr-dir\\d*", TRUE, FALSE, "attr-dir\\d*" },
260 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
261 { __LINE__, 0, "attrib /S -H attr-dir\\d*", TRUE, FALSE, "attr-dir\\d*" },
262 { __LINE__, 0, "attrib /S attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
263 { __LINE__, 0, "attrib /S -H attr-dir\\dir1", TRUE, FALSE, "attr-dir\\dir1" },
264 { __LINE__, 0, "attrib /S -H attr-dir", TRUE, FALSE, "attr-dir" },
265 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
266
267 /* /S /D attr-dir, attr-dir\\dir1 */
268 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
269 { __LINE__, 0, "cmd /c mkdir attr-dir", FALSE, FALSE },
270 { __LINE__, 0, "attrib /S /D attr-dir", TRUE, FALSE, NULL, NULL, " H " },
271 { __LINE__, 0, "cmd /c if exist attr-dir echo OK", TRUE, FALSE, "OK" },
272 { __LINE__, 0, "cmd /c mkdir attr-dir\\dir1", FALSE, FALSE },
273 { __LINE__, 0, "cmd /c if exist attr-dir\\dir1 echo OK", TRUE, FALSE, "OK" },
274 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
275 { __LINE__, 0, "attrib /S /D +H attr-dir\\dir1", FALSE, FALSE },
276 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, " H " },
277 { __LINE__, 0, "attrib /S /D -H attr-dir\\dir1", FALSE, FALSE },
278 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
279 { __LINE__, 0, "attrib /S /D +H attr-dir", FALSE, FALSE },
280 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
281 { __LINE__, 0, "attrib /S /D -H attr-dir", FALSE, FALSE },
282 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
283 { __LINE__, 0, "attrib /S /D +H attr-d*", FALSE, FALSE },
284 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
285 { __LINE__, 0, "attrib /S /D -H attr-d*", FALSE, FALSE },
286 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
287 { __LINE__, 0, "attrib /S /D +H attr-dir\\d*", FALSE, FALSE },
288 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, " H " },
289 { __LINE__, 0, "attrib /S /D -H attr-dir\\d*", FALSE, FALSE },
290 { __LINE__, 0, "attrib /S /D attr-dir\\dir1", TRUE, FALSE, NULL, NULL, " H " },
291 { __LINE__, 0, "attrib /S /D -H attr-dir\\dir1", FALSE, FALSE },
292 { __LINE__, 0, "attrib /S /D -H attr-dir", FALSE, FALSE },
293 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
294
295 /* /S attr-dir, attr-dir\\dir1\\file.txt */
296 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
297 { __LINE__, 0, "cmd /c mkdir attr-dir", FALSE, FALSE },
298 { __LINE__, 0, "attrib /S /D attr-dir", TRUE, FALSE, NULL, NULL, " H " },
299 { __LINE__, 0, "cmd /c if exist attr-dir echo OK", TRUE, FALSE, "OK" },
300 { __LINE__, 0, "cmd /c mkdir attr-dir\\dir1", FALSE, FALSE },
301 { __LINE__, 0, "cmd /c if exist attr-dir\\dir1 echo OK", TRUE, FALSE, "OK" },
302 { __LINE__, 0, "cmd /c copy NUL attr-dir\\dir1\\attr-test.txt ", TRUE, FALSE },
303 { __LINE__, 0, "attrib attr-dir\\dir1\\attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
304 { __LINE__, 0, "attrib /S +H attr-dir\\dir1\\attr-test.txt", FALSE, FALSE },
305 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, " H " },
306 { __LINE__, 0, "attrib /S -H attr-dir\\dir1\\attr-test.txt", FALSE, FALSE },
307 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
308 { __LINE__, 0, "attrib /S +H attr-test.txt", FALSE, FALSE },
309 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, " H " },
310 { __LINE__, 0, "attrib /S -H attr-test.txt", FALSE, FALSE },
311 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
312 { __LINE__, 0, "attrib /S +H", TRISTATE, FALSE },
313 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, " H " },
314 { __LINE__, 0, "attrib /S attr-tes*.*", TRUE, FALSE, " H " },
315 { __LINE__, 0, "attrib /S -H", TRISTATE, FALSE },
316 { __LINE__, 0, "attrib /S attr-test.txt", TRUE, FALSE, NULL, NULL, " H " },
317 { __LINE__, 0, "attrib /S attr-tes*.*", TRUE, FALSE, NULL, NULL, " H " },
318 { __LINE__, 0, "cmd /c if exist attr-dir/dir1/test.txt attrib -H attr-dir/dir1/test.txt" },
319 { __LINE__, 0, "cmd /c if exist attr-dir/dir1/test.txt del /Q attr-dir/dir1/test.txt" },
320 { __LINE__, 0, "cmd /c if exist attr-dir rmdir /s /q attr-dir" },
321
322};
323
325{
327 return DuplicateHandle(hProcess, hFile, hProcess, phFile, 0,
328 bInherit, DUPLICATE_SAME_ACCESS);
329}
330
331static BOOL PrepareForRedirect(STARTUPINFOA *psi, PHANDLE phInputWrite,
332 PHANDLE phOutputRead, PHANDLE phErrorRead)
333{
334 HANDLE hInputRead = NULL, hInputWriteTmp = NULL;
335 HANDLE hOutputReadTmp = NULL, hOutputWrite = NULL;
336 HANDLE hErrorReadTmp = NULL, hErrorWrite = NULL;
337 SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
338
339 psi->hStdInput = NULL;
340 psi->hStdOutput = NULL;
341 psi->hStdError = NULL;
342
343 if (phInputWrite)
344 {
345 if (CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 0))
346 {
347 if (!MyDuplicateHandle(hInputWriteTmp, phInputWrite, FALSE))
348 goto failed;
349
350 CloseHandle(hInputWriteTmp);
351 }
352 else
353 goto failed;
354 }
355
356 if (phOutputRead)
357 {
358 if (CreatePipe(&hOutputReadTmp, &hOutputWrite, &sa, 0))
359 {
360 if (!MyDuplicateHandle(hOutputReadTmp, phOutputRead, FALSE))
361 goto failed;
362
363 CloseHandle(hOutputReadTmp);
364 }
365 else
366 goto failed;
367 }
368
369 if (phOutputRead && phOutputRead == phErrorRead)
370 {
371 if (!MyDuplicateHandle(hOutputWrite, &hErrorWrite, TRUE))
372 goto failed;
373 }
374 else if (phErrorRead)
375 {
376 if (CreatePipe(&hErrorReadTmp, &hErrorWrite, &sa, 0))
377 {
378 if (!MyDuplicateHandle(hErrorReadTmp, phErrorRead, FALSE))
379 goto failed;
380 CloseHandle(hErrorReadTmp);
381 }
382 else
383 goto failed;
384 }
385
386 if (phInputWrite)
387 psi->hStdInput = hInputRead;
388 if (phOutputRead)
389 psi->hStdOutput = hOutputWrite;
390 if (phErrorRead)
391 psi->hStdError = hErrorWrite;
392
393 return TRUE;
394
395failed:
396 CloseHandle(hInputRead);
397 CloseHandle(hInputWriteTmp);
398 CloseHandle(hOutputReadTmp);
399 CloseHandle(hOutputWrite);
400 CloseHandle(hErrorReadTmp);
401 CloseHandle(hErrorWrite);
402 return FALSE;
403}
404
405static void DoTestEntry(const TEST_ENTRY *pEntry)
406{
407 STARTUPINFOA si;
409 DWORD dwExitCode, dwWait;
410 HANDLE hOutputRead = NULL;
411 HANDLE hErrorRead = NULL;
412 DWORD dwRead;
413 BOOL bStdOutput, bStdError;
414 CHAR szOut[512], szErr[512];
415
416 memset(&si, 0, sizeof(si));
417 si.cb = sizeof(si);
419
420 if (!PrepareForRedirect(&si, NULL, &hOutputRead, &hErrorRead))
421 {
422 skip("PrepareForRedirect failed\n");
423 return;
424 }
425
426 if (CreateProcessA(NULL, (char *)pEntry->cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
427 {
429 dwWait = WaitForSingleObject(pi.hProcess, TIMEOUT);
430 if (dwWait == WAIT_TIMEOUT)
431 {
432 TerminateProcess(pi.hProcess, 9999);
433 }
434 GetExitCodeProcess(pi.hProcess, &dwExitCode);
435 CloseHandle(pi.hThread);
436 CloseHandle(pi.hProcess);
437 }
438 else
439 {
440 dwExitCode = 8888;
441 }
442
443 ZeroMemory(szOut, sizeof(szOut));
444 PeekNamedPipe(hOutputRead, szOut, ARRAYSIZE(szOut), &dwRead, NULL, NULL);
445 szOut[ARRAYSIZE(szOut) - 1] = 0;
446 bStdOutput = dwRead != 0;
447
448 ZeroMemory(szErr, sizeof(szErr));
449 PeekNamedPipe(hErrorRead, szErr, ARRAYSIZE(szErr), &dwRead, NULL, NULL);
450 szErr[ARRAYSIZE(szErr) - 1] = 0;
451 bStdError = dwRead != 0;
452
453 if (si.hStdInput)
455 if (si.hStdOutput)
457 if (si.hStdError)
459
460 ok(pEntry->bStdOutput == bStdOutput || pEntry->bStdOutput == TRISTATE,
461 "Line %u: bStdOutput %d vs %d\n",
462 pEntry->line, pEntry->bStdOutput, bStdOutput);
463
464 ok(pEntry->bStdError == bStdError || pEntry->bStdOutput == TRISTATE,
465 "Line %u: bStdError %d vs %d\n",
466 pEntry->line, pEntry->bStdError, bStdError);
467
468 ok(pEntry->dwExitCode == dwExitCode,
469 "Line %u: dwExitCode %ld vs %ld\n",
470 pEntry->line, pEntry->dwExitCode, dwExitCode);
471
472 if (pEntry->OutputContains)
473 {
474 ok(strstr(szOut, pEntry->OutputContains) != NULL,
475 "Line %u: szOut was '%s'\n",
476 pEntry->line, szOut);
477 }
478
479 if (pEntry->ErrorContains)
480 {
481 ok(strstr(szErr, pEntry->ErrorContains) != NULL,
482 "Line %u: szErr was '%s'\n",
483 pEntry->line, szErr);
484 }
485
486 if (pEntry->OutputNotContains)
487 {
488 ok(strstr(szOut, pEntry->OutputNotContains) == NULL,
489 "Line %u: szOut was '%s'\n",
490 pEntry->line, szOut);
491 }
492
493 if (pEntry->ErrorNotContains)
494 {
495 ok(strstr(szErr, pEntry->ErrorNotContains) == NULL,
496 "Line %u: szErr was '%s'\n",
497 pEntry->line, szErr);
498 }
499}
500
502{
503 SIZE_T i;
504 for (i = 0; i < ARRAYSIZE(s_exit_entries); ++i)
505 {
507 }
508}
509
511{
512 SIZE_T i;
513 for (i = 0; i < ARRAYSIZE(s_echo_entries); ++i)
514 {
516 }
517}
518
520{
521 SIZE_T i;
522 for (i = 0; i < ARRAYSIZE(s_cd_entries); ++i)
523 {
525 }
526}
527
529{
530 SIZE_T i;
531 for (i = 0; i < ARRAYSIZE(s_pushd_entries); ++i)
532 {
534 }
535}
536
538{
539 SIZE_T i;
540 for (i = 0; i < ARRAYSIZE(s_attrib_entries); ++i)
541 {
543 }
544}
InitDirComponents & cd
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
TCHAR szErr[256]
Definition: service.c:38
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4749
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1534
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
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
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define ZeroMemory
Definition: minwinbase.h:31
static const TEST_ENTRY s_pushd_entries[]
Definition: cmd.c:58
static BOOL PrepareForRedirect(STARTUPINFOA *psi, PHANDLE phInputWrite, PHANDLE phOutputRead, PHANDLE phErrorRead)
Definition: cmd.c:331
static const TEST_ENTRY s_attrib_entries[]
Definition: cmd.c:129
static void DoTestEntry(const TEST_ENTRY *pEntry)
Definition: cmd.c:405
#define TIMEOUT
Definition: cmd.c:10
static const TEST_ENTRY s_cd_entries[]
Definition: cmd.c:45
static BOOL MyDuplicateHandle(HANDLE hFile, PHANDLE phFile, BOOL bInherit)
Definition: cmd.c:324
static const TEST_ENTRY s_echo_entries[]
Definition: cmd.c:38
struct TEST_ENTRY TEST_ENTRY
#define TRISTATE
Definition: cmd.c:25
static const TEST_ENTRY s_exit_entries[]
Definition: cmd.c:27
static refpint_t pi[]
Definition: server.c:112
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL WINAPI PeekNamedPipe(HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage)
Definition: npipe.c:1214
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define exit(n)
Definition: config.h:202
#define memset(x, y, z)
Definition: compat.h:39
Definition: cmd.c:13
INT line
Definition: cmd.c:14
const char * OutputContains
Definition: cmd.c:19
BOOL bStdOutput
Definition: cmd.c:17
DWORD dwExitCode
Definition: cmd.c:15
const char * ErrorNotContains
Definition: cmd.c:22
const char * ErrorContains
Definition: cmd.c:20
const char * cmdline
Definition: cmd.c:16
BOOL bStdError
Definition: cmd.c:18
const char * OutputNotContains
Definition: cmd.c:21
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define STARTF_USESTDHANDLES
Definition: winbase.h:476
#define DUPLICATE_SAME_ACCESS
char CHAR
Definition: xmlstorage.h:175