~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to winpr/libwinpr/pipe/test/TestPipeCreatePipe.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20141111122050-7z628f4ab38qxad5
Tags: upstream-1.1.0~git20140921.1.440916e+dfsg1
ImportĀ upstreamĀ versionĀ 1.1.0~git20140921.1.440916e+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdio.h>
 
3
#include <winpr/crt.h>
 
4
#include <winpr/pipe.h>
 
5
#include <winpr/tchar.h>
 
6
#include <winpr/winpr.h>
 
7
 
 
8
#define BUFFER_SIZE     16
 
9
 
 
10
int TestPipeCreatePipe(int argc, char* argv[])
 
11
{
 
12
        BOOL status;
 
13
        DWORD dwRead;
 
14
        DWORD dwWrite;
 
15
        HANDLE hReadPipe;
 
16
        HANDLE hWritePipe;
 
17
        BYTE readBuffer[BUFFER_SIZE];
 
18
        BYTE writeBuffer[BUFFER_SIZE];
 
19
 
 
20
        status = CreatePipe(&hReadPipe, &hWritePipe, NULL, BUFFER_SIZE * 2);
 
21
 
 
22
        if (!status)
 
23
        {
 
24
                _tprintf(_T("CreatePipe failed\n"));
 
25
                return -1;
 
26
        }
 
27
 
 
28
        FillMemory(writeBuffer, sizeof(writeBuffer), 0xAA);
 
29
        status = WriteFile(hWritePipe, &writeBuffer, sizeof(writeBuffer), &dwWrite, NULL);
 
30
 
 
31
        if (!status)
 
32
        {
 
33
                _tprintf(_T("WriteFile failed\n"));
 
34
                return -1;
 
35
        }
 
36
 
 
37
        if (dwWrite != sizeof(writeBuffer))
 
38
        {
 
39
                _tprintf(_T("WriteFile: unexpected number of bytes written: Actual: %ld, Expected: %ld\n"),
 
40
                        dwWrite, (long int)sizeof(writeBuffer));
 
41
                return -1;
 
42
        }
 
43
 
 
44
        ZeroMemory(readBuffer, sizeof(readBuffer));
 
45
        status = ReadFile(hReadPipe, &readBuffer, sizeof(readBuffer), &dwRead, NULL);
 
46
 
 
47
        if (!status)
 
48
        {
 
49
                _tprintf(_T("ReadFile failed\n"));
 
50
                return -1;
 
51
        }
 
52
 
 
53
        if (dwRead != sizeof(readBuffer))
 
54
        {
 
55
                _tprintf(_T("ReadFile: unexpected number of bytes read: Actual: %ld, Expected: %ld\n"),
 
56
                        dwWrite, (long int)sizeof(readBuffer));
 
57
                return -1;
 
58
        }
 
59
 
 
60
        if (memcmp(readBuffer, writeBuffer, BUFFER_SIZE) != 0)
 
61
        {
 
62
                _tprintf(_T("ReadFile: read buffer is different from write buffer\n"));
 
63
                return -1;
 
64
        }
 
65
 
 
66
        CloseHandle(hReadPipe);
 
67
        CloseHandle(hWritePipe);
 
68
 
 
69
        return 0;
 
70
}