From f96dd460d477613024f1c5a9e449738a676422f4 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Thu, 30 May 2019 21:31:18 -0700 Subject: [PATCH] Added unit tests for testing 'SetTimeout()'. --- CHANGELOG.md | 1 + include/CppLinuxSerial/SerialPort.hpp | 5 +++-- test/unit/BasicTests.cpp | 25 +++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea7204..4094786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Sphinx documentation. +- Unit tests for testing `SetTimeout()`. ## [v2.0.1] - 2017-11-27 diff --git a/include/CppLinuxSerial/SerialPort.hpp b/include/CppLinuxSerial/SerialPort.hpp index b12565b..1ece112 100644 --- a/include/CppLinuxSerial/SerialPort.hpp +++ b/include/CppLinuxSerial/SerialPort.hpp @@ -1,8 +1,8 @@ /// /// \file SerialPort.hpp -/// \author Geoffrey Hunter () +/// \author Geoffrey Hunter (www.mbedded.ninja) /// \created 2014-01-07 -/// \last-modified 2017-11-23 +/// \last-modified 2019-05-30 /// \brief The main serial port class. /// \details /// See README.rst in repo root dir for more info. @@ -19,6 +19,7 @@ #include // User headers +#include "Exception.hpp" namespace mn { namespace CppLinuxSerial { diff --git a/test/unit/BasicTests.cpp b/test/unit/BasicTests.cpp index b918c8e..69c8ea3 100644 --- a/test/unit/BasicTests.cpp +++ b/test/unit/BasicTests.cpp @@ -2,7 +2,7 @@ /// \file BasicTests.cpp /// \author Geoffrey Hunter (www.mbedded.ninja) /// \created 2017-11-24 -/// \last-modified 2017-11-24 +/// \last-modified 2019-05-30 /// \brief Basic tests for the SerialPort class. /// \details /// See README.rst in repo root dir for more info. @@ -58,7 +58,6 @@ namespace { ASSERT_EQ("Hello", readData); } - TEST_F(BasicTests, ReadWriteDiffBaudRates) { SerialPort serialPort0(device0Name_, BaudRate::B_9600); serialPort0.Open(); @@ -74,4 +73,26 @@ namespace { ASSERT_EQ("Hello", readData); } + TEST_F(BasicTests, SetTimeoutCorrectly) { + SerialPort serialPort0(device0Name_, BaudRate::B_57600); + serialPort0.SetTimeout(-1); // Infinite timeout + serialPort0.Open(); + + SerialPort serialPort1(device1Name_, BaudRate::B_57600); + serialPort1.Open(); + + serialPort0.Write("Hello"); + + std::string readData; + serialPort1.Read(readData); + + ASSERT_EQ("Hello", readData); + } + + TEST_F(BasicTests, SetTimeoutIncorrectly) { + SerialPort serialPort0(device0Name_, BaudRate::B_57600); + serialPort0.Open(); + EXPECT_THROW(serialPort0.SetTimeout(-1), mn::CppLinuxSerial::Exception); + } + } // namespace \ No newline at end of file -- libgit2 0.21.4