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