Go to the documentation of this file.00001
00024 #include "gtest/gtest.h"
00025 #include "serial_communication_mock.h"
00026 #include "eyelids_node.h"
00027
00028 using testing::_;
00029 using testing::DoAll;
00030 using testing::SetArgumentPointee;
00031 using testing::AnyNumber;
00032 using testing::Return;
00033
00034 TEST(Eyelids, MoveFail_OpenPort)
00035 {
00036 MockSerialCommunication mock;
00037
00038 EXPECT_CALL(mock, set_serial_device(_))
00039 .Times(1);
00040 EXPECT_CALL(mock, open_port(_))
00041 .Times(1)
00042 .WillOnce(Return(-1));
00043 EXPECT_CALL(mock, close_port(_))
00044 .Times(1)
00045 .WillOnce(Return(0));
00046 EXPECT_CALL(mock, send_character(_))
00047 .Times(AnyNumber())
00048 .WillRepeatedly(Return(-1));
00049
00050 EyelidsNode eyelids_node(&mock);
00051
00052
00053 ASSERT_EQ(-1, eyelids_node.move(0));
00054 }
00055
00056 TEST(Eyelids, MoveSuccess_ClosePort)
00057 {
00058 MockSerialCommunication mock;
00059
00060 EXPECT_CALL(mock, set_serial_device(_))
00061 .Times(1);
00062 EXPECT_CALL(mock, open_port(_))
00063 .Times(1)
00064 .WillOnce(Return(0));
00065 EXPECT_CALL(mock, close_port(_))
00066 .Times(1)
00067 .WillOnce(Return(-1));
00068 EXPECT_CALL(mock, send_character(_))
00069 .Times(AnyNumber())
00070 .WillRepeatedly(Return(0));
00071
00072 EyelidsNode eyelids_node(&mock);
00073
00074
00075 ASSERT_EQ(0, eyelids_node.move(0));
00076 }
00077
00078 TEST(Eyelids, MoveFail_SendChar)
00079 {
00080 MockSerialCommunication mock;
00081
00082 EXPECT_CALL(mock, set_serial_device(_))
00083 .Times(1);
00084 EXPECT_CALL(mock, open_port(_))
00085 .Times(1)
00086 .WillOnce(Return(0));
00087 EXPECT_CALL(mock, close_port(_))
00088 .Times(1)
00089 .WillOnce(Return(0));
00090 EXPECT_CALL(mock, send_character(_))
00091 .Times(AnyNumber())
00092 .WillRepeatedly(Return(-1));
00093
00094 EyelidsNode eyelids_node(&mock);
00095
00096
00097 ASSERT_EQ(-1, eyelids_node.move(0));
00098 }
00099
00100 TEST(Eyelids, MoveSuccess)
00101 {
00102 MockSerialCommunication mock;
00103
00104 EXPECT_CALL(mock, set_serial_device(_))
00105 .Times(1);
00106 EXPECT_CALL(mock, open_port(_))
00107 .Times(1)
00108 .WillOnce(Return(0));
00109 EXPECT_CALL(mock, close_port(_))
00110 .Times(1)
00111 .WillOnce(Return(0));
00112 EXPECT_CALL(mock, send_character(_))
00113 .Times(AnyNumber())
00114 .WillRepeatedly(Return(0));
00115
00116 EyelidsNode eyelids_node(&mock);
00117
00118
00119 for (int j = 0; j < 255; j += 50) {
00120 ASSERT_EQ(0, eyelids_node.move(j));
00121 }
00122 }
00123
00124 int main(int argc, char **argv)
00125 {
00126 ros::init(argc, argv, "eyelids_tests");
00127
00128 ::testing::InitGoogleMock(&argc, argv);
00129
00130 return RUN_ALL_TESTS();
00131 }