Commit efaea75e9e0f4624d7c17abfd173f71962bed130

Authored by Geoffrey Hunter
1 parent 2ad09c14

Tidied up serial port config unit tests.

test/unit/BasicTests.cpp
@@ -31,7 +31,6 @@ namespace { @@ -31,7 +31,6 @@ namespace {
31 31
32 std::string device0Name_ = TestUtil::GetInstance().GetDevice0Name(); 32 std::string device0Name_ = TestUtil::GetInstance().GetDevice0Name();
33 std::string device1Name_ = TestUtil::GetInstance().GetDevice1Name(); 33 std::string device1Name_ = TestUtil::GetInstance().GetDevice1Name();
34 -  
35 }; 34 };
36 35
37 TEST_F(BasicTests, CanBeConstructed) { 36 TEST_F(BasicTests, CanBeConstructed) {
test/unit/ConfigTests.cpp
@@ -24,37 +24,33 @@ namespace { @@ -24,37 +24,33 @@ namespace {
24 protected: 24 protected:
25 25
26 ConfigTests() { 26 ConfigTests() {
  27 + serialPort_ = SerialPort(TestUtil::GetInstance().GetDevice0Name(), BaudRate::B_57600);
  28 + serialPort_.Open();
  29 + sttyOutput_ = TestUtil::GetInstance().Exec("stty -a -F " + TestUtil::GetInstance().GetDevice0Name());
27 } 30 }
28 31
29 virtual ~ConfigTests() { 32 virtual ~ConfigTests() {
30 } 33 }
31 34
32 - std::string device0Name_ = TestUtil::GetInstance().GetDevice0Name(); 35 + SerialPort serialPort_;
  36 + std::string sttyOutput_;
33 }; 37 };
34 38
35 TEST_F(ConfigTests, BaudRateSetCorrectly) { 39 TEST_F(ConfigTests, BaudRateSetCorrectly) {
36 - SerialPort serialPort0(device0Name_, BaudRate::B_57600);  
37 - serialPort0.Open();  
38 - auto retVal = TestUtil::GetInstance().Exec("stty -a -F " + device0Name_);  
39 - EXPECT_NE(std::string::npos, retVal.find("speed 57600 baud"));  
40 -  
41 - serialPort0.SetBaudRate(BaudRate::B_115200);  
42 - retVal = TestUtil::GetInstance().Exec("stty -a -F " + device0Name_);  
43 - EXPECT_NE(std::string::npos, retVal.find("speed 115200 baud")); 40 + EXPECT_NE(std::string::npos, sttyOutput_.find("speed 57600 baud"));
  41 + serialPort_.SetBaudRate(BaudRate::B_115200);
  42 + sttyOutput_ = TestUtil::GetInstance().Exec("stty -a -F " + TestUtil::GetInstance().GetDevice0Name());
  43 + EXPECT_NE(std::string::npos, sttyOutput_.find("speed 115200 baud"));
44 } 44 }
45 45
46 TEST_F(ConfigTests, CanonicalModeOff) { 46 TEST_F(ConfigTests, CanonicalModeOff) {
47 - SerialPort serialPort0(device0Name_, BaudRate::B_57600);  
48 - serialPort0.Open();  
49 - auto retVal = TestUtil::GetInstance().Exec("stty -a -F " + device0Name_);  
50 - EXPECT_NE(std::string::npos, retVal.find("-icanon")); 47 + EXPECT_NE(std::string::npos, sttyOutput_.find("-icanon"));
51 } 48 }
52 49
53 TEST_F(ConfigTests, EchoModeOff) { 50 TEST_F(ConfigTests, EchoModeOff) {
54 - SerialPort serialPort0(device0Name_, BaudRate::B_57600);  
55 - serialPort0.Open();  
56 - auto retVal = TestUtil::GetInstance().Exec("stty -a -F " + device0Name_);  
57 - EXPECT_NE(std::string::npos, retVal.find("-echo")); 51 + EXPECT_NE(std::string::npos, sttyOutput_.find("-echo"));
  52 + EXPECT_NE(std::string::npos, sttyOutput_.find("-echoe"));
  53 + EXPECT_NE(std::string::npos, sttyOutput_.find("-echonl"));
58 } 54 }
59 55
60 } // namespace 56 } // namespace
61 \ No newline at end of file 57 \ No newline at end of file