22#include <winpr/comm.h>
23#include <winpr/tchar.h>
25static int test_CommDevice(LPCTSTR lpDeviceName, BOOL expectedResult)
27 TCHAR lpTargetPath[MAX_PATH] = WINPR_C_ARRAY_INIT;
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))
70 _T(
"QueryCommDevice failure: device name: %s, the second nullptr character is ")
71 _T(
"missing at the end of the buffer\n"),
80 _tprintf(_T(
"QueryCommDevice failure: device name: %s, expected result: <none>, ")
81 _T(
"result: %") _T(PRIuz) _T(
" %s\n"),
82 lpDeviceName, tclen, lpTargetPath);
91int TestCommDevice(
int argc,
char* argv[])
93 if (!test_CommDevice(_T(
"COM0"), FALSE))
96 if (!test_CommDevice(_T(
"COM1"), TRUE))
99 if (!test_CommDevice(_T(
"COM1"), TRUE))
102 if (!test_CommDevice(_T(
"COM10"), FALSE))
105 if (!test_CommDevice(_T(
"\\\\.\\COM5"), TRUE))
108 if (!test_CommDevice(_T(
"\\\\.\\COM10"), TRUE))
111 if (!test_CommDevice(_T(
"\\\\.COM10"), FALSE))