4 #include <winpr/pipe.h>
5 #include <winpr/tchar.h>
6 #include <winpr/winpr.h>
10 int TestPipeCreatePipe(
int argc,
char* argv[])
15 HANDLE hReadPipe = NULL;
16 HANDLE hWritePipe = NULL;
17 BYTE readBuffer[BUFFER_SIZE] = { 0 };
18 BYTE writeBuffer[BUFFER_SIZE] = { 0 };
21 status = CreatePipe(&hReadPipe, &hWritePipe, NULL, BUFFER_SIZE * 2);
25 _tprintf(_T(
"CreatePipe failed\n"));
29 FillMemory(writeBuffer,
sizeof(writeBuffer), 0xAA);
30 status = WriteFile(hWritePipe, &writeBuffer,
sizeof(writeBuffer), &dwWrite, NULL);
34 _tprintf(_T(
"WriteFile failed\n"));
38 if (dwWrite !=
sizeof(writeBuffer))
40 _tprintf(_T(
"WriteFile: unexpected number of bytes written: Actual: %") _T(
41 PRIu32) _T(
", Expected: %") _T(PRIuz) _T(
"\n"),
42 dwWrite,
sizeof(writeBuffer));
46 status = ReadFile(hReadPipe, &readBuffer,
sizeof(readBuffer), &dwRead, NULL);
50 _tprintf(_T(
"ReadFile failed\n"));
54 if (dwRead !=
sizeof(readBuffer))
56 _tprintf(_T(
"ReadFile: unexpected number of bytes read: Actual: %") _T(
57 PRIu32) _T(
", Expected: %") _T(PRIuz) _T(
"\n"),
58 dwWrite,
sizeof(readBuffer));
62 if (memcmp(readBuffer, writeBuffer, BUFFER_SIZE) != 0)
64 _tprintf(_T(
"ReadFile: read buffer is different from write buffer\n"));
68 (void)CloseHandle(hReadPipe);
69 (void)CloseHandle(hWritePipe);