ReactOS 0.4.15-dev-5664-g3bf4ef6
fc.c File Reference
#include "precomp.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <shlwapi.h>
Include dependency graph for fc.c:

Go to the source code of this file.

Classes

struct  TEST_ENTRY
 

Macros

#define FILE1   "fc-test1.txt"
 
#define FILE2   "fc-test2.txt"
 
#define FILES   " " FILE1 " " FILE2
 
#define COMPARING   "Comparing files fc-test1.txt and FC-TEST2.TXT\n"
 
#define NO_DIFF   "FC: no differences encountered\n"
 
#define RESYNC_FAILED   "Resync Failed. Files are too different.\n"
 
#define TIMEOUT   (10 * 1000)
 
#define ENGLISH_CP   437 /* English codepage */
 

Typedefs

typedef struct TEST_ENTRY TEST_ENTRY
 

Functions

BOOL DoDuplicateHandle (HANDLE hFile, PHANDLE phFile, BOOL bInherit)
 
static BOOL PrepareForRedirect (STARTUPINFOA *psi, PHANDLE phInputWrite, PHANDLE phOutputRead, PHANDLE phErrorRead)
 
static void ConvertOutput (LPSTR psz)
 
static void DoTestEntry (const TEST_ENTRY *pEntry)
 
 START_TEST (fc)
 

Variables

static const TEST_ENTRY s_entries []
 

Macro Definition Documentation

◆ COMPARING

#define COMPARING   "Comparing files fc-test1.txt and FC-TEST2.TXT\n"

Definition at line 29 of file fc.c.

◆ ENGLISH_CP

#define ENGLISH_CP   437 /* English codepage */

Definition at line 601 of file fc.c.

◆ FILE1

#define FILE1   "fc-test1.txt"

Definition at line 26 of file fc.c.

◆ FILE2

#define FILE2   "fc-test2.txt"

Definition at line 27 of file fc.c.

◆ FILES

#define FILES   " " FILE1 " " FILE2

Definition at line 28 of file fc.c.

◆ NO_DIFF

#define NO_DIFF   "FC: no differences encountered\n"

Definition at line 30 of file fc.c.

◆ RESYNC_FAILED

#define RESYNC_FAILED   "Resync Failed. Files are too different.\n"

Definition at line 31 of file fc.c.

◆ TIMEOUT

#define TIMEOUT   (10 * 1000)

Typedef Documentation

◆ TEST_ENTRY

Function Documentation

◆ ConvertOutput()

static void ConvertOutput ( LPSTR  psz)
static

Definition at line 497 of file fc.c.

498{
499 LPSTR pch1, pch2;
500 pch1 = pch2 = psz;
501 while (*pch1)
502 {
503 if (*pch1 != '\r')
504 {
505 *pch2++ = *pch1;
506 }
507 ++pch1;
508 }
509 *pch2 = 0;
510}
char * LPSTR
Definition: xmlstorage.h:182

Referenced by DoTestEntry().

◆ DoDuplicateHandle()

BOOL DoDuplicateHandle ( HANDLE  hFile,
PHANDLE  phFile,
BOOL  bInherit 
)

Definition at line 409 of file fc.c.

410{
412 return DuplicateHandle(hProcess, hFile, hProcess, phFile, 0,
413 bInherit, DUPLICATE_SAME_ACCESS);
414}
#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
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
_In_ HANDLE hFile
Definition: mswsock.h:90
#define DUPLICATE_SAME_ACCESS

Referenced by PrepareForRedirect().

◆ DoTestEntry()

static void DoTestEntry ( const TEST_ENTRY pEntry)
static

Definition at line 512 of file fc.c.

513{
514 FILE *fp;
515 STARTUPINFOA si = { sizeof(si) };
517 INT file1_size, file2_size;
518 HANDLE hOutputRead;
519 DWORD cbAvail, cbRead;
520 CHAR szOutput[1024];
521 BOOL ret;
522 DWORD dwExitCode;
523 LPSTR psz;
524
525 file1_size = pEntry->file1_size;
526 file2_size = pEntry->file2_size;
527 if (file1_size == -1)
528 file1_size = strlen(pEntry->file1_data);
529 if (file2_size == -1)
530 file2_size = strlen(pEntry->file2_data);
531
532 fp = fopen(FILE1, "wb");
533 fwrite(pEntry->file1_data, file1_size, 1, fp);
534 fclose(fp);
535
536 fp = fopen(FILE2, "wb");
537 fwrite(pEntry->file2_data, file2_size, 1, fp);
538 fclose(fp);
539
540 ok(PathFileExistsA(FILE1), "Line %d: PathFileExistsA(FILE1) failed\n", pEntry->lineno);
541 ok(PathFileExistsA(FILE2), "Line %d: PathFileExistsA(FILE2) failed\n", pEntry->lineno);
542
546
547 PrepareForRedirect(&si, NULL, &hOutputRead, &hOutputRead);
548
549 psz = _strdup(pEntry->cmdline);
550 ret = CreateProcessA(NULL, psz, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
551 free(psz);
552
553 ok(ret, "Line %d: CreateProcessA failed\n", pEntry->lineno);
554
555#define TIMEOUT (10 * 1000)
556 WaitForSingleObject(pi.hProcess, TIMEOUT);
557
558 ZeroMemory(szOutput, sizeof(szOutput));
559 if (PeekNamedPipe(hOutputRead, NULL, 0, NULL, &cbAvail, NULL))
560 {
561 if (cbAvail > 0)
562 {
563 if (cbAvail > sizeof(szOutput))
564 cbAvail = sizeof(szOutput) - 1;
565
566 ReadFile(hOutputRead, szOutput, cbAvail, &cbRead, NULL);
567 }
568 }
569 ConvertOutput(szOutput);
570
571 GetExitCodeProcess(pi.hProcess, &dwExitCode);
572 ok(dwExitCode == pEntry->ret, "Line %d: dwExitCode was 0x%lx\n", pEntry->lineno, dwExitCode);
573
574 if (StrCmpNIA(pEntry->output, szOutput, strlen(pEntry->output)) != 0)
575 {
576 ok(FALSE, "Line %d: Output was wrong\n", pEntry->lineno);
577 printf("---FROM HERE\n");
578 printf("%s\n", szOutput);
579 printf("---UP TO HERE\n");
580 }
581 else
582 {
583 ok_int(TRUE, TRUE);
584 }
585
586 CloseHandle(pi.hProcess);
587 CloseHandle(pi.hThread);
588
589 CloseHandle(hOutputRead);
596
599}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#define ok_int(expression, result)
Definition: atltest.h:134
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define free
Definition: debug_ros.c:5
#define _strdup
Definition: debug_ros.c:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
Definition: string.c:300
#define CloseHandle
Definition: compat.h:739
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
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:4742
BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
Definition: path.c:1754
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:94
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define FILE2
Definition: fc.c:27
static BOOL PrepareForRedirect(STARTUPINFOA *psi, PHANDLE phInputWrite, PHANDLE phOutputRead, PHANDLE phErrorRead)
Definition: fc.c:417
#define TIMEOUT
static void ConvertOutput(LPSTR psz)
Definition: fc.c:497
#define FILE1
Definition: fc.c:26
static refpint_t pi[]
Definition: server.c:96
BOOL WINAPI PeekNamedPipe(HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage)
Definition: npipe.c:1214
HANDLE hStdOutput
Definition: winbase.h:847
HANDLE hStdError
Definition: winbase.h:848
HANDLE hStdInput
Definition: winbase.h:846
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
int32_t INT
Definition: typedefs.h:58
int ret
#define ZeroMemory
Definition: winbase.h:1670
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define STD_ERROR_HANDLE
Definition: winbase.h:269
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ PrepareForRedirect()

static BOOL PrepareForRedirect ( STARTUPINFOA psi,
PHANDLE  phInputWrite,
PHANDLE  phOutputRead,
PHANDLE  phErrorRead 
)
static

Definition at line 417 of file fc.c.

419{
421 HANDLE hInputRead = NULL, hInputWriteTmp = NULL;
422 HANDLE hOutputReadTmp = NULL, hOutputWrite = NULL;
423 HANDLE hErrorReadTmp = NULL, hErrorWrite = NULL;
424
425 sa.nLength = sizeof(sa);
426 sa.lpSecurityDescriptor = NULL;
427 sa.bInheritHandle = TRUE;
428
429 if (phInputWrite)
430 {
431 if (CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 0))
432 {
433 if (!DoDuplicateHandle(hInputWriteTmp, phInputWrite, FALSE))
434 return FALSE;
435 CloseHandle(hInputWriteTmp);
436 }
437 else
438 goto failure;
439 }
440
441 if (phOutputRead)
442 {
443 if (CreatePipe(&hOutputReadTmp, &hOutputWrite, &sa, 0))
444 {
445 if (!DoDuplicateHandle(hOutputReadTmp, phOutputRead, FALSE))
446 return FALSE;
447 CloseHandle(hOutputReadTmp);
448 }
449 else
450 goto failure;
451 }
452
453 if (phOutputRead && phOutputRead == phErrorRead)
454 {
455 if (!DoDuplicateHandle(hOutputWrite, &hErrorWrite, TRUE))
456 return FALSE;
457 }
458 else if (phErrorRead)
459 {
460 if (CreatePipe(&hErrorReadTmp, &hErrorWrite, &sa, 0))
461 {
462 if (!DoDuplicateHandle(hErrorReadTmp, phErrorRead, FALSE))
463 return FALSE;
464 CloseHandle(hErrorReadTmp);
465 }
466 else
467 goto failure;
468 }
469
470 if (phInputWrite)
471 {
472 psi->hStdInput = hInputRead;
474 }
475 if (phOutputRead)
476 {
477 psi->hStdOutput = hOutputWrite;
479 }
480 if (phErrorRead)
481 {
482 psi->hStdOutput = hErrorWrite;
484 }
485 return TRUE;
486
487failure:
488 CloseHandle(hInputRead);
489 CloseHandle(hInputWriteTmp);
490 CloseHandle(hOutputReadTmp);
491 CloseHandle(hOutputWrite);
492 CloseHandle(hErrorReadTmp);
493 CloseHandle(hErrorWrite);
494 return FALSE;
495}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
BOOL DoDuplicateHandle(HANDLE hFile, PHANDLE phFile, BOOL bInherit)
Definition: fc.c:409
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
DWORD dwFlags
Definition: winbase.h:842
#define STARTF_USESTDHANDLES
Definition: winbase.h:499

Referenced by DoTestEntry().

◆ START_TEST()

START_TEST ( fc  )

Definition at line 603 of file fc.c.

604{
605 UINT i;
606 UINT uOldCP = GetConsoleCP(), uOldOutputCP = GetConsoleOutputCP();
609
610 for (i = 0; i < _countof(s_entries); ++i)
611 {
613 }
614
615 SetConsoleCP(uOldCP);
616 SetConsoleOutputCP(uOldOutputCP);
617}
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
Definition: console.c:695
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2451
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCP(UINT wCodePageID)
Definition: console.c:2420
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
Definition: console.c:2391
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 ENGLISH_CP
Definition: fc.c:601
static void DoTestEntry(const TEST_ENTRY *pEntry)
Definition: fc.c:512
static const TEST_ENTRY s_entries[]
Definition: fc.c:33
unsigned int UINT
Definition: ndis.h:50
#define _countof(array)
Definition: sndvol32.h:68

Variable Documentation

◆ s_entries

const TEST_ENTRY s_entries[]
static

Definition at line 33 of file fc.c.

Referenced by START_TEST().