From 94dfce4f523bbb61feb31a29b75ef3e8ad748180 Mon Sep 17 00:00:00 2001 From: Emmanuel Ledoux Date: Thu, 3 Jul 2014 19:01:45 +0200 Subject: [PATCH] winpr-comm: made the unit tests to succeed when /dev/ttyS0 is not available --- winpr/libwinpr/comm/test/TestCommConfig.c | 10 +++++++++- winpr/libwinpr/comm/test/TestControlSettings.c | 10 +++++++++- winpr/libwinpr/comm/test/TestGetCommState.c | 9 ++++++++- winpr/libwinpr/comm/test/TestHandflow.c | 9 ++++++++- winpr/libwinpr/comm/test/TestSerialChars.c | 9 ++++++++- winpr/libwinpr/comm/test/TestSetCommState.c | 9 ++++++++- winpr/libwinpr/comm/test/TestTimeouts.c | 9 ++++++++- 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/winpr/libwinpr/comm/test/TestCommConfig.c b/winpr/libwinpr/comm/test/TestCommConfig.c index edb48bd93..093c44e24 100644 --- a/winpr/libwinpr/comm/test/TestCommConfig.c +++ b/winpr/libwinpr/comm/test/TestCommConfig.c @@ -18,6 +18,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -31,6 +33,7 @@ int TestCommConfig(int argc, char* argv[]) BOOL success; LPCSTR lpFileName = "\\\\.\\COM1"; COMMPROP commProp; + struct stat statbuf; hComm = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, @@ -42,7 +45,12 @@ int TestCommConfig(int argc, char* argv[]) return EXIT_FAILURE; } - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + success = DefineCommDevice(lpFileName, "/dev/ttyS0"); if(!success) { diff --git a/winpr/libwinpr/comm/test/TestControlSettings.c b/winpr/libwinpr/comm/test/TestControlSettings.c index dde4c982c..becdae2d0 100644 --- a/winpr/libwinpr/comm/test/TestControlSettings.c +++ b/winpr/libwinpr/comm/test/TestControlSettings.c @@ -19,6 +19,8 @@ #include +#include + #include #include @@ -26,11 +28,17 @@ int TestControlSettings(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; DCB dcb; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) { diff --git a/winpr/libwinpr/comm/test/TestGetCommState.c b/winpr/libwinpr/comm/test/TestGetCommState.c index 1a4df956f..b5cc30423 100644 --- a/winpr/libwinpr/comm/test/TestGetCommState.c +++ b/winpr/libwinpr/comm/test/TestGetCommState.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -72,10 +73,16 @@ static BOOL test_generic(HANDLE hComm) int TestGetCommState(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) { diff --git a/winpr/libwinpr/comm/test/TestHandflow.c b/winpr/libwinpr/comm/test/TestHandflow.c index 098b8b0e6..1e536e7a2 100644 --- a/winpr/libwinpr/comm/test/TestHandflow.c +++ b/winpr/libwinpr/comm/test/TestHandflow.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -34,10 +35,16 @@ static BOOL test_SerialSys(HANDLE hComm) int TestHandflow(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) { diff --git a/winpr/libwinpr/comm/test/TestSerialChars.c b/winpr/libwinpr/comm/test/TestSerialChars.c index d17c2f844..8cd3dc953 100644 --- a/winpr/libwinpr/comm/test/TestSerialChars.c +++ b/winpr/libwinpr/comm/test/TestSerialChars.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -128,10 +129,16 @@ static BOOL test_SerCx2Sys(HANDLE hComm) int TestSerialChars(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) { diff --git a/winpr/libwinpr/comm/test/TestSetCommState.c b/winpr/libwinpr/comm/test/TestSetCommState.c index 9c06263c6..63dbdfda8 100644 --- a/winpr/libwinpr/comm/test/TestSetCommState.c +++ b/winpr/libwinpr/comm/test/TestSetCommState.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -317,10 +318,16 @@ static BOOL test_generic(HANDLE hComm) int TestSetCommState(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) { diff --git a/winpr/libwinpr/comm/test/TestTimeouts.c b/winpr/libwinpr/comm/test/TestTimeouts.c index 4f6c89424..c7d4c226b 100644 --- a/winpr/libwinpr/comm/test/TestTimeouts.c +++ b/winpr/libwinpr/comm/test/TestTimeouts.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -75,10 +76,16 @@ static BOOL test_generic(HANDLE hComm) int TestTimeouts(int argc, char* argv[]) { + struct stat statbuf; BOOL result; HANDLE hComm; - // TMP: FIXME: check if we can proceed with tests on the actual device, skip and warn otherwise but don't fail + if (stat("/dev/ttyS0", &statbuf) < 0) + { + fprintf(stderr, "/dev/ttyS0 not available, making the test to succeed though\n"); + return EXIT_SUCCESS; + } + result = DefineCommDevice("COM1", "/dev/ttyS0"); if (!result) {