21 #include "gtest/gtest.h"
23 #include <boost/bind.hpp>
32 #if defined(__linux__)
44 class SerialTests :
public ::testing::Test {
46 virtual void SetUp() {
47 if (openpty(&master_fd, &slave_fd, name, NULL, NULL) == -1) {
52 ASSERT_TRUE(master_fd > 0);
53 ASSERT_TRUE(slave_fd > 0);
54 ASSERT_TRUE(
string(name).
length() > 0);
59 virtual void TearDown() {
70 TEST_F(SerialTests, readWorks) {
71 write(master_fd,
"abc\n", 4);
72 string r = port1->read(4);
73 EXPECT_EQ(
r,
string(
"abc\n"));
76 TEST_F(SerialTests, writeWorks) {
78 port1->write(
"abc\n");
79 read(master_fd, buf, 4);
80 EXPECT_EQ(
string(buf, 4),
string(
"abc\n"));
83 TEST_F(SerialTests, timeoutWorks) {
85 string empty = port1->read();
86 EXPECT_EQ(empty,
string(
""));
89 write(master_fd,
"abc\n", 4);
90 string r = port1->read(4);
91 EXPECT_EQ(
r,
string(
"abc\n"));
94 TEST_F(SerialTests, partialRead) {
96 write(master_fd,
"abc\n", 4);
99 string empty = port1->read(10);
100 EXPECT_EQ(empty,
string(
"abc\n"));
103 write(master_fd,
"abc\n", 4);
104 string r = port1->read(4);
105 EXPECT_EQ(
r,
string(
"abc\n"));
110 int main(
int argc,
char **argv) {
112 ::testing::InitGoogleTest(&argc, argv);
113 return RUN_ALL_TESTS();
114 }
catch (std::exception &e) {
115 std::cerr <<
"Unhandled Exception: " << e.what() << std::endl;