2014-04-18 19:18:08 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Serial Communication API
|
|
|
|
*
|
|
|
|
* Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <winpr/comm.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
|
|
|
|
static int test_CommDevice(LPCTSTR lpDeviceName, BOOL expectedResult)
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
TCHAR lpTargetPath[MAX_PATH];
|
|
|
|
DWORD tcslen;
|
|
|
|
|
|
|
|
result = DefineCommDevice(lpDeviceName, _T("/dev/test"));
|
|
|
|
if ((!expectedResult && result) || (expectedResult && !result)) /* logical XOR */
|
|
|
|
{
|
|
|
|
_tprintf(_T("DefineCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
|
2014-06-16 21:18:45 +04:00
|
|
|
lpDeviceName,
|
|
|
|
(expectedResult ? "TRUE" : "FALSE"),
|
|
|
|
(result ? "TRUE" : "FALSE"));
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = IsCommDevice(lpDeviceName);
|
|
|
|
if ((!expectedResult && result) || (expectedResult && !result)) /* logical XOR */
|
|
|
|
{
|
|
|
|
_tprintf(_T("IsCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
|
2014-06-16 21:18:45 +04:00
|
|
|
lpDeviceName,
|
|
|
|
(expectedResult ? "TRUE" : "FALSE"),
|
|
|
|
(result ? "TRUE" : "FALSE"));
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcslen = QueryCommDevice(lpDeviceName, lpTargetPath, MAX_PATH);
|
|
|
|
if (expectedResult)
|
|
|
|
{
|
2014-07-04 14:24:41 +04:00
|
|
|
if (tcslen <= _tcslen(lpTargetPath)) /* at least 2 more TCHAR are expected */
|
2014-04-18 19:18:08 +04:00
|
|
|
{
|
|
|
|
_tprintf(_T("QueryCommDevice failure: didn't found the device name: %s\n"), lpDeviceName);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_tcscmp(_T("/dev/test"), lpTargetPath) != 0)
|
|
|
|
{
|
2014-06-16 21:18:45 +04:00
|
|
|
_tprintf(_T("QueryCommDevice failure: device name: %s, expected result: %s, result: %s\n"),
|
|
|
|
lpDeviceName, _T("/dev/test"), lpTargetPath);
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-18 21:25:25 +04:00
|
|
|
if (lpTargetPath[_tcslen(lpTargetPath) + 1] != 0)
|
2014-04-18 19:18:08 +04:00
|
|
|
{
|
|
|
|
_tprintf(_T("QueryCommDevice failure: device name: %s, the second NULL character is missing at the end of the buffer\n"), lpDeviceName);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tcslen > 0)
|
|
|
|
{
|
2014-06-16 21:18:45 +04:00
|
|
|
_tprintf(_T("QueryCommDevice failure: device name: %s, expected result: <none>, result: %d %s\n"),
|
|
|
|
lpDeviceName, tcslen, lpTargetPath);
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TestCommDevice(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
if (!test_CommDevice(_T("COM0"), FALSE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("COM1"), TRUE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("COM1"), TRUE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("COM10"), FALSE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("\\\\.\\COM5"), TRUE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("\\\\.\\COM10"), TRUE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
if (!test_CommDevice(_T("\\\\.COM10"), FALSE))
|
2014-04-18 21:25:25 +04:00
|
|
|
return EXIT_FAILURE;
|
2014-04-18 19:18:08 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|