Commit f96dd460d477613024f1c5a9e449738a676422f4

Authored by Geoffrey Hunter
1 parent 39800085

Added unit tests for testing 'SetTimeout()'.

CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
9 9
10 ### Added 10 ### Added
11 - Sphinx documentation. 11 - Sphinx documentation.
  12 +- Unit tests for testing `SetTimeout()`.
12 13
13 ## [v2.0.1] - 2017-11-27 14 ## [v2.0.1] - 2017-11-27
14 15
include/CppLinuxSerial/SerialPort.hpp
1 /// 1 ///
2 /// \file SerialPort.hpp 2 /// \file SerialPort.hpp
3 -/// \author Geoffrey Hunter <gbmhunter@gmail.com> () 3 +/// \author Geoffrey Hunter <gbmhunter@gmail.com> (www.mbedded.ninja)
4 /// \created 2014-01-07 4 /// \created 2014-01-07
5 -/// \last-modified 2017-11-23 5 +/// \last-modified 2019-05-30
6 /// \brief The main serial port class. 6 /// \brief The main serial port class.
7 /// \details 7 /// \details
8 /// See README.rst in repo root dir for more info. 8 /// See README.rst in repo root dir for more info.
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 #include <vector> 19 #include <vector>
20 20
21 // User headers 21 // User headers
  22 +#include "Exception.hpp"
22 23
23 namespace mn { 24 namespace mn {
24 namespace CppLinuxSerial { 25 namespace CppLinuxSerial {
test/unit/BasicTests.cpp
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 /// \file BasicTests.cpp 2 /// \file BasicTests.cpp
3 /// \author Geoffrey Hunter <gbmhunter@gmail.com> (www.mbedded.ninja) 3 /// \author Geoffrey Hunter <gbmhunter@gmail.com> (www.mbedded.ninja)
4 /// \created 2017-11-24 4 /// \created 2017-11-24
5 -/// \last-modified 2017-11-24 5 +/// \last-modified 2019-05-30
6 /// \brief Basic tests for the SerialPort class. 6 /// \brief Basic tests for the SerialPort class.
7 /// \details 7 /// \details
8 /// See README.rst in repo root dir for more info. 8 /// See README.rst in repo root dir for more info.
@@ -58,7 +58,6 @@ namespace { @@ -58,7 +58,6 @@ namespace {
58 ASSERT_EQ("Hello", readData); 58 ASSERT_EQ("Hello", readData);
59 } 59 }
60 60
61 -  
62 TEST_F(BasicTests, ReadWriteDiffBaudRates) { 61 TEST_F(BasicTests, ReadWriteDiffBaudRates) {
63 SerialPort serialPort0(device0Name_, BaudRate::B_9600); 62 SerialPort serialPort0(device0Name_, BaudRate::B_9600);
64 serialPort0.Open(); 63 serialPort0.Open();
@@ -74,4 +73,26 @@ namespace { @@ -74,4 +73,26 @@ namespace {
74 ASSERT_EQ("Hello", readData); 73 ASSERT_EQ("Hello", readData);
75 } 74 }
76 75
  76 + TEST_F(BasicTests, SetTimeoutCorrectly) {
  77 + SerialPort serialPort0(device0Name_, BaudRate::B_57600);
  78 + serialPort0.SetTimeout(-1); // Infinite timeout
  79 + serialPort0.Open();
  80 +
  81 + SerialPort serialPort1(device1Name_, BaudRate::B_57600);
  82 + serialPort1.Open();
  83 +
  84 + serialPort0.Write("Hello");
  85 +
  86 + std::string readData;
  87 + serialPort1.Read(readData);
  88 +
  89 + ASSERT_EQ("Hello", readData);
  90 + }
  91 +
  92 + TEST_F(BasicTests, SetTimeoutIncorrectly) {
  93 + SerialPort serialPort0(device0Name_, BaudRate::B_57600);
  94 + serialPort0.Open();
  95 + EXPECT_THROW(serialPort0.SetTimeout(-1), mn::CppLinuxSerial::Exception);
  96 + }
  97 +
77 } // namespace 98 } // namespace
78 \ No newline at end of file 99 \ No newline at end of file