ReactOS 0.4.15-dev-7953-g1f49173
batch.c File Reference
#include <stdio.h>
#include <wine/test.h>
#include <winnls.h>
Include dependency graph for batch.c:

Go to the source code of this file.

Functions

static const charconvert_input_data (const char *data, DWORD size, DWORD *new_size)
 
static BOOL run_cmd (const char *cmd_data, DWORD cmd_size)
 
static DWORD map_file (const char *file_name, const char **ret)
 
static const charcompare_line (const char *out_line, const char *out_end, const char *exp_line, const char *exp_end)
 
static void test_output (const char *out_data, DWORD out_size, const char *exp_data, DWORD exp_size)
 
static void run_test (const char *cmd_data, DWORD cmd_size, const char *exp_data, DWORD exp_size)
 
static void run_from_file (const char *file_name)
 
static DWORD load_resource (const char *name, const char *type, const char **ret)
 
static BOOL WINAPI test_enum_proc (HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param)
 
static int cmd_available (void)
 
 START_TEST (reactos)
 

Variables

static char workdir [MAX_PATH]
 
static DWORD workdir_len
 
static char drive [2]
 
static const DWORD drive_len = ARRAY_SIZE(drive)
 
static char path [MAX_PATH]
 
static DWORD path_len
 
static char shortpath [MAX_PATH]
 
static DWORD shortpath_len
 

Function Documentation

◆ cmd_available()

static int cmd_available ( void  )
static

Definition at line 447 of file batch.c.

448{
449 STARTUPINFOA si;
451 char cmd[] = "cmd /c exit 0";
452
453 memset(&si, 0, sizeof(si));
454 si.cb = sizeof(si);
455 if (CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
456 CloseHandle(pi.hThread);
457 CloseHandle(pi.hProcess);
458 return TRUE;
459 }
460 return FALSE;
461}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
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:4741
static refpint_t pi[]
Definition: server.c:96
#define memset(x, y, z)
Definition: compat.h:39
DWORD cb
Definition: winbase.h:831
Definition: ftp_var.h:139

Referenced by START_TEST().

◆ compare_line()

static const char * compare_line ( const char out_line,
const char out_end,
const char exp_line,
const char exp_end 
)
static

Definition at line 162 of file batch.c.

164{
165 const char *out_ptr = out_line, *exp_ptr = exp_line;
166 const char *err = NULL;
167
168 static const char pwd_cmd[] = {'@','p','w','d','@'};
169 static const char drive_cmd[] = {'@','d','r','i','v','e','@'};
170 static const char path_cmd[] = {'@','p','a','t','h','@'};
171 static const char shortpath_cmd[] = {'@','s','h','o','r','t','p','a','t','h','@'};
172 static const char space_cmd[] = {'@','s','p','a','c','e','@'};
173 static const char spaces_cmd[] = {'@','s','p','a','c','e','s','@'};
174 static const char tab_cmd[] = {'@','t','a','b','@'};
175 static const char or_broken_cmd[] = {'@','o','r','_','b','r','o','k','e','n','@'};
176
177 while(exp_ptr < exp_end) {
178 if(*exp_ptr == '@') {
179 if(exp_ptr+sizeof(pwd_cmd) <= exp_end
180 && !memcmp(exp_ptr, pwd_cmd, sizeof(pwd_cmd))) {
181 exp_ptr += sizeof(pwd_cmd);
182 if(out_end-out_ptr < workdir_len
185 err = out_ptr;
186 }else {
187 out_ptr += workdir_len;
188 continue;
189 }
190 } else if(exp_ptr+sizeof(drive_cmd) <= exp_end
191 && !memcmp(exp_ptr, drive_cmd, sizeof(drive_cmd))) {
192 exp_ptr += sizeof(drive_cmd);
193 if(out_end-out_ptr < drive_len
195 out_ptr, drive_len, drive, drive_len) != CSTR_EQUAL)) {
196 err = out_ptr;
197 }else {
198 out_ptr += drive_len;
199 continue;
200 }
201 } else if(exp_ptr+sizeof(path_cmd) <= exp_end
202 && !memcmp(exp_ptr, path_cmd, sizeof(path_cmd))) {
203 exp_ptr += sizeof(path_cmd);
204 if(out_end-out_ptr < path_len
206 out_ptr, path_len, path, path_len) != CSTR_EQUAL)) {
207 err = out_ptr;
208 }else {
209 out_ptr += path_len;
210 continue;
211 }
212 } else if(exp_ptr+sizeof(shortpath_cmd) <= exp_end
213 && !memcmp(exp_ptr, shortpath_cmd, sizeof(shortpath_cmd))) {
214 exp_ptr += sizeof(shortpath_cmd);
215 if(out_end-out_ptr < shortpath_len
218 err = out_ptr;
219 }else {
220 out_ptr += shortpath_len;
221 continue;
222 }
223 }else if(exp_ptr+sizeof(space_cmd) <= exp_end
224 && !memcmp(exp_ptr, space_cmd, sizeof(space_cmd))) {
225 exp_ptr += sizeof(space_cmd);
226 if(out_ptr < out_end && *out_ptr == ' ') {
227 out_ptr++;
228 continue;
229 } else {
230 err = out_end;
231 }
232 }else if(exp_ptr+sizeof(spaces_cmd) <= exp_end
233 && !memcmp(exp_ptr, spaces_cmd, sizeof(spaces_cmd))) {
234 exp_ptr += sizeof(spaces_cmd);
235 if(out_ptr < out_end && *out_ptr == ' ') {
236 while (out_ptr < out_end && *out_ptr == ' ') out_ptr++;
237 continue;
238 } else {
239 err = out_end;
240 }
241 }else if(exp_ptr+sizeof(tab_cmd) <= exp_end
242 && !memcmp(exp_ptr, tab_cmd, sizeof(tab_cmd))) {
243 exp_ptr += sizeof(tab_cmd);
244 if(out_ptr < out_end && *out_ptr == '\t') {
245 out_ptr++;
246 continue;
247 } else {
248 err = out_end;
249 }
250 }else if(exp_ptr+sizeof(or_broken_cmd) <= exp_end
251 && !memcmp(exp_ptr, or_broken_cmd, sizeof(or_broken_cmd))) {
252 if(out_ptr == out_end)
253 return NULL;
254 else
255 err = out_ptr;
256 }else if(out_ptr == out_end || *out_ptr != *exp_ptr)
257 err = out_ptr;
258 }else if(out_ptr == out_end || *out_ptr != *exp_ptr) {
259 err = out_ptr;
260 }
261
262 if(err) {
263 if(!broken(1))
264 return err;
265
266 while(exp_ptr+sizeof(or_broken_cmd) <= exp_end && memcmp(exp_ptr, or_broken_cmd, sizeof(or_broken_cmd)))
267 exp_ptr++;
268 exp_ptr += sizeof(or_broken_cmd);
269 if (exp_ptr > exp_end) return err;
270 out_ptr = out_line;
271 err = NULL;
272 continue;
273 }
274
275 exp_ptr++;
276 out_ptr++;
277 }
278
279 if(exp_ptr != exp_end)
280 return out_ptr;
281 else if(out_ptr != out_end)
282 return exp_end;
283
284 return NULL;
285}
#define broken(x)
Definition: _sntprintf.h:21
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
INT WINAPI CompareStringA(LCID lcid, DWORD flags, LPCSTR str1, INT len1, LPCSTR str2, INT len2)
Definition: lang.c:2695
static const DWORD drive_len
Definition: batch.c:29
static char workdir[MAX_PATH]
Definition: batch.c:26
static DWORD workdir_len
Definition: batch.c:27
static DWORD path_len
Definition: batch.c:31
static DWORD shortpath_len
Definition: batch.c:33
static char shortpath[MAX_PATH]
Definition: batch.c:32
#define LOCALE_SYSTEM_DEFAULT
#define err(...)
#define NORM_IGNORECASE
Definition: winnls.h:176
#define CSTR_EQUAL
Definition: winnls.h:456

Referenced by test_output().

◆ convert_input_data()

static const char * convert_input_data ( const char data,
DWORD  size,
DWORD new_size 
)
static

Definition at line 36 of file batch.c.

37{
38 static const char escaped_space[] = {'@','s','p','a','c','e','@'};
39 static const char escaped_tab[] = {'@','t','a','b','@'};
40 DWORD i, eol_count = 0;
41 char *ptr, *new_data;
42
43 for (i = 0; i < size; i++)
44 if (data[i] == '\n') eol_count++;
45
46 ptr = new_data = HeapAlloc(GetProcessHeap(), 0, size + eol_count + 1);
47
48 for (i = 0; i < size; i++) {
49 switch (data[i]) {
50 case '\n':
51 if (data[i-1] != '\r')
52 *ptr++ = '\r';
53 *ptr++ = '\n';
54 break;
55 case '@':
56 if (data + i + sizeof(escaped_space) - 1 < data + size
57 && !memcmp(data + i, escaped_space, sizeof(escaped_space))) {
58 *ptr++ = ' ';
59 i += sizeof(escaped_space) - 1;
60 } else if (data + i + sizeof(escaped_tab) - 1 < data + size
61 && !memcmp(data + i, escaped_tab, sizeof(escaped_tab))) {
62 *ptr++ = '\t';
63 i += sizeof(escaped_tab) - 1;
64 } else {
65 *ptr++ = data[i];
66 }
67 break;
68 default:
69 *ptr++ = data[i];
70 }
71 }
72 *ptr = '\0';
73
74#ifdef __REACTOS__
75 *new_size = lstrlenA(new_data);
76#else
77 *new_size = strlen(new_data);
78#endif
79 return new_data;
80}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
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
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static PVOID ptr
Definition: dispmode.c:27

Referenced by run_test().

◆ load_resource()

static DWORD load_resource ( const char name,
const char type,
const char **  ret 
)
static

Definition at line 406 of file batch.c.

407{
408 const char *res;
409 HRSRC src;
410 DWORD size;
411
413 ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError());
414 if(!src)
415 return 0;
416
419 while(size && !res[size-1])
420 size--;
421
422 *ret = res;
423 return size;
424}
#define ok(value,...)
Definition: atltest.h:57
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLenum src
Definition: glext.h:6340
Definition: name.c:39
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by test_enum_proc().

◆ map_file()

static DWORD map_file ( const char file_name,
const char **  ret 
)
static

Definition at line 135 of file batch.c.

136{
137 HANDLE file, map;
138 DWORD size;
139
141 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %08x\n", GetLastError());
143 return 0;
144
146
149 ok(map != NULL, "CreateFileMappingA(%s) failed: %u\n", file_name, GetLastError());
150 if(!map)
151 return 0;
152
153 *ret = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
154 ok(*ret != NULL, "MapViewOfFile failed: %u\n", GetLastError());
156 if(!*ret)
157 return 0;
158
159 return size;
160}
Definition: _map.h:48
#define PAGE_READONLY
Definition: compat.h:138
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
static LPCWSTR file_name
Definition: protocol.c:147
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
Definition: fci.c:127

Referenced by run_from_file(), and run_test().

◆ run_cmd()

static BOOL run_cmd ( const char cmd_data,
DWORD  cmd_size 
)
static

Definition at line 82 of file batch.c.

83{
84 SECURITY_ATTRIBUTES sa = {sizeof(sa), 0, TRUE};
85 char command[] = "test.cmd";
86 STARTUPINFOA si = {sizeof(si)};
88 HANDLE file,fileerr;
89 DWORD size;
90 BOOL bres;
91
94 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
96 return FALSE;
97
98 bres = WriteFile(file, cmd_data, cmd_size, &size, NULL);
100 ok(bres, "Could not write to file: %u\n", GetLastError());
101 if(!bres)
102 return FALSE;
103
106 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
108 return FALSE;
109
112 ok(fileerr != INVALID_HANDLE_VALUE, "CreateFile stderr failed\n");
113 if(fileerr == INVALID_HANDLE_VALUE)
114 return FALSE;
115
117 si.hStdOutput = file;
118 si.hStdError = fileerr;
119 bres = CreateProcessA(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
120 ok(bres, "CreateProcess failed: %u\n", GetLastError());
121 if(!bres) {
122 DeleteFileA("test.out");
123 return FALSE;
124 }
125
127 CloseHandle(pi.hThread);
128 CloseHandle(pi.hProcess);
130 CloseHandle(fileerr);
131 DeleteFileA("test.cmd");
132 return TRUE;
133}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
HANDLE hStdOutput
Definition: winbase.h:847
HANDLE hStdError
Definition: winbase.h:848
DWORD dwFlags
Definition: winbase.h:842
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define STARTF_USESTDHANDLES
Definition: winbase.h:499

Referenced by run_test().

◆ run_from_file()

static void run_from_file ( const char file_name)
static

Definition at line 380 of file batch.c.

381{
382 char out_name[MAX_PATH];
383 const char *test_data, *out_data;
385
387 if(!test_size) {
388 ok(0, "Could not map file %s: %u\n", file_name, GetLastError());
389 return;
390 }
391
392 sprintf(out_name, "%s.exp", file_name);
393 out_size = map_file(out_name, &out_data);
394 if(!out_size) {
395 ok(0, "Could not map file %s: %u\n", out_name, GetLastError());
397 return;
398 }
399
401
403 UnmapViewOfFile(out_data);
404}
#define UnmapViewOfFile
Definition: compat.h:746
#define MAX_PATH
Definition: compat.h:34
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static DWORD map_file(const char *file_name, const char **ret)
Definition: batch.c:135
static void test_size(void)
Definition: monthcal.c:1559
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK ULONG PVOID ULONG PVOID ULONG out_size
Definition: file.c:100
#define run_test(test)
Definition: ms_seh.c:71

Referenced by START_TEST().

◆ run_test()

static void run_test ( const char cmd_data,
DWORD  cmd_size,
const char exp_data,
DWORD  exp_size 
)
static

Definition at line 356 of file batch.c.

357{
358 const char *out_data, *actual_cmd_data;
359 DWORD out_size, actual_cmd_size;
360
361 actual_cmd_data = convert_input_data(cmd_data, cmd_size, &actual_cmd_size);
362 if(!actual_cmd_size || !actual_cmd_data)
363 goto cleanup;
364
365 if(!run_cmd(actual_cmd_data, actual_cmd_size))
366 goto cleanup;
367
368 out_size = map_file("test.out", &out_data);
369 if(out_size) {
370 test_output(out_data, out_size, exp_data, exp_size);
371 UnmapViewOfFile(out_data);
372 }
373 DeleteFileA("test.out");
374 DeleteFileA("test.err");
375
376cleanup:
377 HeapFree(GetProcessHeap(), 0, (LPVOID)actual_cmd_data);
378}
#define HeapFree(x, y, z)
Definition: compat.h:735
static void cleanup(void)
Definition: main.c:1335
static BOOL run_cmd(const char *cmd_data, DWORD cmd_size)
Definition: batch.c:82
static const char * convert_input_data(const char *data, DWORD size, DWORD *new_size)
Definition: batch.c:36
static void test_output(const char *out_data, DWORD out_size, const char *exp_data, DWORD exp_size)
Definition: batch.c:287
struct ChNotifyTest * exp_data
Definition: shlfolder.c:4868

◆ START_TEST()

START_TEST ( reactos  )

Definition at line 463 of file batch.c.

464{
465 int argc;
466 char **argv;
467
468 if (!cmd_available()) {
469 win_skip("cmd not installed, skipping cmd tests\n");
470 return;
471 }
472
474 drive[0] = workdir[0];
475 drive[1] = workdir[1]; /* Should be ':' */
476 memcpy(path, workdir + drive_len, (workdir_len - drive_len) * sizeof(drive[0]));
477
478 /* Only add trailing backslash to 'path' for non-root directory */
479 if (workdir_len - drive_len > 1) {
480 path[workdir_len - drive_len] = '\\';
482 } else {
483 path_len = 1; /* \ */
484 }
486
488 if(argc > 2)
490 else
491 EnumResourceNamesA(NULL, "TESTCMD", test_enum_proc, 0);
492}
static int argc
Definition: ServiceArgs.c:12
#define ARRAY_SIZE(A)
Definition: main.h:33
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
DWORD WINAPI GetShortPathNameA(IN LPCSTR lpszLongPath, OUT LPSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1752
BOOL WINAPI EnumResourceNamesA(HMODULE hmod, LPCSTR type, ENUMRESNAMEPROCA lpfun, LONG_PTR lparam)
Definition: res.c:285
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static int cmd_available(void)
Definition: batch.c:447
static void run_from_file(const char *file_name)
Definition: batch.c:380
static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param)
Definition: batch.c:426
#define argv
Definition: mplay32.c:18
#define win_skip
Definition: test.h:160
int winetest_get_mainargs(char ***pargv)

◆ test_enum_proc()

static BOOL WINAPI test_enum_proc ( HMODULE  module,
LPCSTR  type,
LPSTR  name,
LONG_PTR  param 
)
static

Definition at line 426 of file batch.c.

427{
428 const char *cmd_data, *out_data;
429 DWORD cmd_size, out_size;
430 char res_name[100];
431
432 trace("running %s test...\n", name);
433
434 cmd_size = load_resource(name, type, &cmd_data);
435 if(!cmd_size)
436 return TRUE;
437
438 sprintf(res_name, "%s.exp", name);
439 out_size = load_resource(res_name, "TESTOUT", &out_data);
440 if(!out_size)
441 return TRUE;
442
443 run_test(cmd_data, cmd_size, out_data, out_size);
444 return TRUE;
445}
#define trace
Definition: atltest.h:70
static DWORD load_resource(const char *name, const char *type, const char **ret)
Definition: batch.c:406

Referenced by START_TEST().

◆ test_output()

static void test_output ( const char out_data,
DWORD  out_size,
const char exp_data,
DWORD  exp_size 
)
static

Definition at line 287 of file batch.c.

288{
289 const char *out_ptr = out_data, *exp_ptr = exp_data, *out_nl, *exp_nl, *err = NULL;
290 DWORD line = 0;
291 static const char todo_wine_cmd[] = {'@','t','o','d','o','_','w','i','n','e','@'};
292 static const char resync_cmd[] = {'-','-','-'};
293 BOOL is_todo_wine, is_out_resync = FALSE, is_exp_resync = FALSE;
294
295 while(out_ptr < out_data+out_size && exp_ptr < exp_data+exp_size) {
296 line++;
297
298 for(exp_nl = exp_ptr; exp_nl < exp_data+exp_size && *exp_nl != '\r' && *exp_nl != '\n'; exp_nl++);
299 for(out_nl = out_ptr; out_nl < out_data+out_size && *out_nl != '\r' && *out_nl != '\n'; out_nl++);
300
301 is_todo_wine = (exp_ptr+sizeof(todo_wine_cmd) <= exp_nl &&
302 !memcmp(exp_ptr, todo_wine_cmd, sizeof(todo_wine_cmd)));
303 if (is_todo_wine)
304 exp_ptr += sizeof(todo_wine_cmd);
305
306 todo_wine_if(is_todo_wine)
307 {
308 is_exp_resync=(exp_ptr+sizeof(resync_cmd) <= exp_nl &&
309 !memcmp(exp_ptr, resync_cmd, sizeof(resync_cmd)));
310 is_out_resync=(out_ptr+sizeof(resync_cmd) <= out_nl &&
311 !memcmp(out_ptr, resync_cmd, sizeof(resync_cmd)));
312
313 err = compare_line(out_ptr, out_nl, exp_ptr, exp_nl);
314 if(err == out_nl)
315 ok(0, "unexpected end of line %d (got '%.*s', wanted '%.*s')\n",
316 line, (int)(out_nl-out_ptr), out_ptr, (int)(exp_nl-exp_ptr), exp_ptr);
317 else if(err == exp_nl)
318 ok(0, "excess characters on line %d (got '%.*s', wanted '%.*s')\n",
319 line, (int)(out_nl-out_ptr), out_ptr, (int)(exp_nl-exp_ptr), exp_ptr);
320 else if (!err && is_todo_wine && is_out_resync && is_exp_resync)
321 /* Consider that the todo_wine was to deal with extra lines,
322 * not for the resync line itself
323 */
324 err = NULL;
325 else
326 ok(!err, "unexpected char 0x%x position %d in line %d (got '%.*s', wanted '%.*s')\n",
327 (err ? *err : 0), (err ? (int)(err-out_ptr) : -1), line, (int)(out_nl-out_ptr), out_ptr, (int)(exp_nl-exp_ptr), exp_ptr);
328 }
329
330 if (is_exp_resync && err && is_todo_wine)
331 {
332 exp_ptr -= sizeof(todo_wine_cmd);
333 /* If we rewind to the beginning of the line, don't increment line number */
334 line--;
335 }
336 else if (!is_exp_resync || !err ||
337 (is_exp_resync && is_out_resync && err))
338 {
339 exp_ptr = exp_nl+1;
340 if(exp_nl+1 < exp_data+exp_size && exp_nl[0] == '\r' && exp_nl[1] == '\n')
341 exp_ptr++;
342 }
343
344 if (!is_out_resync || !err)
345 {
346 out_ptr = out_nl+1;
347 if(out_nl+1 < out_data+out_size && out_nl[0] == '\r' && out_nl[1] == '\n')
348 out_ptr++;
349 }
350 }
351
352 ok(exp_ptr >= exp_data+exp_size, "unexpected end of output in line %d, missing %s\n", line, exp_ptr);
353 ok(out_ptr >= out_data+out_size, "too long output, got additional %s\n", out_ptr);
354}
static const char * compare_line(const char *out_line, const char *out_end, const char *exp_line, const char *exp_end)
Definition: batch.c:162
#define todo_wine_if(is_todo)
Definition: custom.c:76
Definition: parser.c:49

Referenced by run_test().

Variable Documentation

◆ drive

char drive[2]
static

Definition at line 28 of file batch.c.

◆ drive_len

const DWORD drive_len = ARRAY_SIZE(drive)
static

Definition at line 29 of file batch.c.

Referenced by compare_line(), and START_TEST().

◆ path

char path[MAX_PATH]
static

Definition at line 30 of file batch.c.

◆ path_len

◆ shortpath

char shortpath[MAX_PATH]
static

Definition at line 32 of file batch.c.

Referenced by compare_line(), get_long_path_name(), START_TEST(), and test_GetLongPathNameW().

◆ shortpath_len

DWORD shortpath_len
static

Definition at line 33 of file batch.c.

Referenced by compare_line(), and START_TEST().

◆ workdir

◆ workdir_len

DWORD workdir_len
static

Definition at line 27 of file batch.c.

Referenced by compare_line(), and START_TEST().