ConfigTests.cpp
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
///
/// \file ConfigTests.cpp
/// \author Geoffrey Hunter <gbmhunter@gmail.com> (www.mbedded.ninja)
/// \created 2017-11-24
/// \last-modified 2017-11-24
/// \brief Configuration tests for the SerialPort class.
/// \details
/// See README.rst in repo root dir for more info.
// System includes
#include "gtest/gtest.h"
// 3rd party includes
#include "CppLinuxSerial/SerialPort.hpp"
// User includes
#include "TestUtil.hpp"
using namespace mn::CppLinuxSerial;
namespace {
class ConfigTests : public ::testing::Test {
protected:
ConfigTests() {
}
virtual ~ConfigTests() {
}
std::string device0_ = "/dev/ttyS10";
std::string device1_ = "/dev/ttyS11";
};
TEST_F(ConfigTests, BaudRateSetCorrectly) {
SerialPort serialPort0(device0_, BaudRate::B_57600);
serialPort0.Open();
auto retVal = TestUtil::Exec("stty -a -F " + device0_);
EXPECT_NE(std::string::npos, retVal.find("speed 57600 baud"));
serialPort0.SetBaudRate(BaudRate::B_115200);
retVal = TestUtil::Exec("stty -a -F " + device0_);
EXPECT_NE(std::string::npos, retVal.find("speed 115200 baud"));
}
TEST_F(ConfigTests, CanonicalModeOff) {
SerialPort serialPort0(device0_, BaudRate::B_57600);
serialPort0.Open();
auto retVal = TestUtil::Exec("stty -a -F " + device0_);
EXPECT_NE(std::string::npos, retVal.find("-icanon"));
}
TEST_F(ConfigTests, EchoModeOff) {
SerialPort serialPort0(device0_, BaudRate::B_57600);
serialPort0.Open();
auto retVal = TestUtil::Exec("stty -a -F " + device0_);
EXPECT_NE(std::string::npos, retVal.find("-echo"));
}
} // namespace