27 #include <winpr/comm.h>
28 #include <winpr/crt.h>
32 static BOOL test_generic(HANDLE hComm)
37 timeouts.ReadIntervalTimeout = 1;
38 timeouts.ReadTotalTimeoutMultiplier = 2;
39 timeouts.ReadTotalTimeoutConstant = 3;
40 timeouts.WriteTotalTimeoutMultiplier = 4;
41 timeouts.WriteTotalTimeoutConstant = 5;
43 if (!SetCommTimeouts(hComm, &timeouts))
45 (void)fprintf(stderr,
"SetCommTimeouts failure, GetLastError: 0x%08x\n", GetLastError());
49 if (!GetCommTimeouts(hComm, &timeouts2))
51 (void)fprintf(stderr,
"GetCommTimeouts failure, GetLastError: 0x%08x\n", GetLastError());
55 if (memcmp(&timeouts, &timeouts2,
sizeof(
COMMTIMEOUTS)) != 0)
57 (void)fprintf(stderr,
"TestTimeouts failure, didn't get back the same timeouts.\n");
62 timeouts.ReadIntervalTimeout = MAXULONG;
63 timeouts.ReadTotalTimeoutConstant = MAXULONG;
64 if (SetCommTimeouts(hComm, &timeouts))
68 "SetCommTimeouts succeeded with ReadIntervalTimeout and ReadTotalTimeoutConstant "
69 "set to MAXULONG. GetLastError: 0x%08x\n",
74 if (GetLastError() != ERROR_INVALID_PARAMETER)
78 "SetCommTimeouts failure, expected GetLastError to return ERROR_INVALID_PARAMETER "
87 int TestTimeouts(
int argc,
char* argv[])
93 if (stat(
"/dev/ttyS0", &statbuf) < 0)
95 (void)fprintf(stderr,
"/dev/ttyS0 not available, making the test to succeed though\n");
99 result = DefineCommDevice(
"COM1",
"/dev/ttyS0");
102 (void)fprintf(stderr,
"DefineCommDevice failure: 0x%x\n", GetLastError());
106 hComm = CreateFile(
"COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
107 if (hComm == INVALID_HANDLE_VALUE)
109 (void)fprintf(stderr,
"CreateFileA failure: 0x%x\n", GetLastError());
113 _comm_setServerSerialDriver(hComm, SerialDriverSerialSys);
114 if (!test_generic(hComm))
116 (void)fprintf(stderr,
"test_SerialSys failure\n");
120 _comm_setServerSerialDriver(hComm, SerialDriverSerCxSys);
121 if (!test_generic(hComm))
123 (void)fprintf(stderr,
"test_SerCxSys failure\n");
127 _comm_setServerSerialDriver(hComm, SerialDriverSerCx2Sys);
128 if (!test_generic(hComm))
130 (void)fprintf(stderr,
"test_SerCx2Sys failure\n");
134 if (!CloseHandle(hComm))
136 (void)fprintf(stderr,
"CloseHandle failure, GetLastError()=%08x\n", GetLastError());