| 1 |
/** |
| 2 |
* WinPR: Windows Portable Runtime |
| 3 |
* Serial Communication API |
| 4 |
* |
| 5 |
* Copyright 2014 Hewlett-Packard Development Company, L.P. |
| 6 |
* |
| 7 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the License. |
| 9 |
* You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, software |
| 14 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
* See the License for the specific language governing permissions and |
| 17 |
* limitations under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <sys/stat.h> |
| 22 |
|
| 23 |
#ifndef _WIN32 |
| 24 |
#include <termios.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <winpr/comm.h> |
| 28 |
#include <winpr/crt.h> |
| 29 |
|
| 30 |
#include "../comm.h" |
| 31 |
|
| 32 |
static BOOL test_SerialSys(HANDLE hComm) |
| 33 |
{ |
| 34 |
// TMP: TODO: |
| 35 |
return TRUE; |
| 36 |
} |
| 37 |
|
| 38 |
int TestHandflow(int argc, char* argv[]) |
| 39 |
{ |
| 40 |
struct stat statbuf = WINPR_C_ARRAY_INIT; |
| 41 |
BOOL result = 0; |
| 42 |
HANDLE hComm = nullptr; |
| 43 |
|
| 44 |
if (stat("/dev/ttyS0", &statbuf) < 0) |
| 45 |
{ |
| 46 |
(void)fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); |
| 47 |
return EXIT_SUCCESS; |
| 48 |
} |
| 49 |
|
| 50 |
result = DefineCommDevice("COM1", "/dev/ttyS0"); |
| 51 |
if (!result) |
| 52 |
{ |
| 53 |
(void)fprintf(stderr, "DefineCommDevice failure: 0x%x\n", GetLastError()); |
| 54 |
return EXIT_FAILURE; |
| 55 |
} |
| 56 |
|
| 57 |
hComm = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); |
| 58 |
if (hComm == INVALID_HANDLE_VALUE) |
| 59 |
{ |
| 60 |
(void)fprintf(stderr, "CreateFileA failure: 0x%x\n", GetLastError()); |
| 61 |
return EXIT_FAILURE; |
| 62 |
} |
| 63 |
|
| 64 |
_comm_setServerSerialDriver(hComm, SerialDriverSerialSys); |
| 65 |
if (!test_SerialSys(hComm)) |
| 66 |
{ |
| 67 |
(void)fprintf(stderr, "test_SerCxSys failure\n"); |
| 68 |
return EXIT_FAILURE; |
| 69 |
} |
| 70 |
|
| 71 |
/* _comm_setServerSerialDriver(hComm, SerialDriverSerCxSys); */ |
| 72 |
/* if (!test_SerCxSys(hComm)) */ |
| 73 |
/* { */ |
| 74 |
/* (void)fprintf(stderr, "test_SerCxSys failure\n"); */ |
| 75 |
/* return EXIT_FAILURE; */ |
| 76 |
/* } */ |
| 77 |
|
| 78 |
/* _comm_setServerSerialDriver(hComm, SerialDriverSerCx2Sys); */ |
| 79 |
/* if (!test_SerCx2Sys(hComm)) */ |
| 80 |
/* { */ |
| 81 |
/* (void)fprintf(stderr, "test_SerCxSys failure\n"); */ |
| 82 |
/* return EXIT_FAILURE; */ |
| 83 |
/* } */ |
| 84 |
|
| 85 |
if (!CloseHandle(hComm)) |
| 86 |
{ |
| 87 |
(void)fprintf(stderr, "CloseHandle failure, GetLastError()=%08x\n", GetLastError()); |
| 88 |
return EXIT_FAILURE; |
| 89 |
} |
| 90 |
|
| 91 |
return EXIT_SUCCESS; |
| 92 |
} |