23 #include <winpr/comm.h>
24 #include <winpr/crt.h>
28 static BOOL test_generic(HANDLE hComm)
34 ZeroMemory(&dcb,
sizeof(
DCB));
35 result = GetCommState(hComm, &dcb);
38 printf(
"GetCommState failure, should have returned false because dcb.DCBlength has been "
39 "let uninitialized\n");
43 ZeroMemory(&dcb,
sizeof(
DCB));
44 dcb.DCBlength =
sizeof(
DCB) / 2;
45 result = GetCommState(hComm, &dcb);
48 printf(
"GetCommState failure, should have return false because dcb.DCBlength was not "
49 "correctly initialized\n");
53 ZeroMemory(&dcb,
sizeof(
DCB));
54 dcb.DCBlength =
sizeof(
DCB);
55 result = GetCommState(hComm, &dcb);
58 printf(
"GetCommState failure: Ox%x, with adjusted DCBlength\n", GetLastError());
62 pDcb = (
DCB*)calloc(2,
sizeof(
DCB));
65 pDcb->DCBlength =
sizeof(
DCB) * 2;
66 result = GetCommState(hComm, pDcb);
67 result = result && (pDcb->DCBlength ==
sizeof(
DCB) * 2);
71 printf(
"GetCommState failure: 0x%x, with bigger DCBlength\n", GetLastError());
78 int TestGetCommState(
int argc,
char* argv[])
80 struct stat statbuf = { 0 };
84 if (stat(
"/dev/ttyS0", &statbuf) < 0)
86 (void)fprintf(stderr,
"/dev/ttyS0 not available, making the test to succeed though\n");
90 result = DefineCommDevice(
"COM1",
"/dev/ttyS0");
93 printf(
"DefineCommDevice failure: 0x%x\n", GetLastError());
97 hComm = CreateFileA(
"COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
99 if (hComm == INVALID_HANDLE_VALUE)
101 printf(
"CreateFileA failure: 0x%x\n", GetLastError());
105 if (!test_generic(hComm))
107 printf(
"test_generic failure (SerialDriverUnknown)\n");
111 _comm_setServerSerialDriver(hComm, SerialDriverSerialSys);
112 if (!test_generic(hComm))
114 printf(
"test_generic failure (SerialDriverSerialSys)\n");
118 _comm_setServerSerialDriver(hComm, SerialDriverSerCxSys);
119 if (!test_generic(hComm))
121 printf(
"test_generic failure (SerialDriverSerCxSys)\n");
125 _comm_setServerSerialDriver(hComm, SerialDriverSerCx2Sys);
126 if (!test_generic(hComm))
128 printf(
"test_generic failure (SerialDriverSerCx2Sys)\n");
132 if (!CloseHandle(hComm))
134 (void)fprintf(stderr,
"CloseHandle failure, GetLastError()=%08x\n", GetLastError());