22 #include <winpr/comm.h>
23 #include <winpr/tchar.h>
25 static int test_CommDevice(LPCTSTR lpDeviceName, BOOL expectedResult)
27 TCHAR lpTargetPath[MAX_PATH] = { 0 };
29 BOOL result = DefineCommDevice(lpDeviceName, _T(
"/dev/test"));
30 if ((!expectedResult && result) || (expectedResult && !result))
32 _tprintf(_T(
"DefineCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
33 lpDeviceName, (expectedResult ?
"TRUE" :
"FALSE"), (result ?
"TRUE" :
"FALSE"));
38 result = IsCommDevice(lpDeviceName);
39 if ((!expectedResult && result) || (expectedResult && !result))
41 _tprintf(_T(
"IsCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
42 lpDeviceName, (expectedResult ?
"TRUE" :
"FALSE"), (result ?
"TRUE" :
"FALSE"));
47 const size_t tclen = QueryCommDevice(lpDeviceName, lpTargetPath, MAX_PATH);
50 const size_t tlen = _tcsnlen(lpTargetPath, ARRAYSIZE(lpTargetPath) - 1);
53 _tprintf(_T(
"QueryCommDevice failure: didn't find the device name: %s\n"),
58 if (_tcsncmp(_T(
"/dev/test"), lpTargetPath, ARRAYSIZE(lpTargetPath)) != 0)
61 _T(
"QueryCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
62 lpDeviceName, _T(
"/dev/test"), lpTargetPath);
67 if ((tlen >= (ARRAYSIZE(lpTargetPath) - 1)) || (lpTargetPath[tlen + 1] != 0))
69 _tprintf(_T(
"QueryCommDevice failure: device name: %s, the second NULL character is ")
70 _T(
"missing at the end of the buffer\n"),
79 _tprintf(_T(
"QueryCommDevice failure: device name: %s, expected result: <none>, ")
80 _T(
"result: %") _T(PRIuz) _T(
" %s\n"),
81 lpDeviceName, tclen, lpTargetPath);
90 int TestCommDevice(
int argc,
char* argv[])
92 if (!test_CommDevice(_T(
"COM0"), FALSE))
95 if (!test_CommDevice(_T(
"COM1"), TRUE))
98 if (!test_CommDevice(_T(
"COM1"), TRUE))
101 if (!test_CommDevice(_T(
"COM10"), FALSE))
104 if (!test_CommDevice(_T(
"\\\\.\\COM5"), TRUE))
107 if (!test_CommDevice(_T(
"\\\\.\\COM10"), TRUE))
110 if (!test_CommDevice(_T(
"\\\\.COM10"), FALSE))