31 #include <gtest/gtest.h>
39 #if defined(__linux__)
69 TEST(MotorSerialNoFixtureTests, badPortnameException) {
70 ASSERT_THROW(
MotorSerial motors(std::string(
"foo"), 9600),
75 ASSERT_EQ(
true, motors->motors.isOpen());
76 motors->serial_thread.interrupt();
78 ASSERT_EQ(
false, motors->motors.isOpen());
82 uint8_t
test[] = {0x7E, 0x3B, 0x2A, 0x00, 0x00, 0x01, 0x2C, 0x6D};
84 ASSERT_NE(-1, write(master_fd,
test, 8));
86 while (!motors->commandAvailable()) {
90 mm = motors->receiveCommand();
97 uint8_t
test[] = {0x00, 0x7E, 0x3B, 0x2A, 0x00, 0x00, 0x01, 0x2C, 0x6D};
99 ASSERT_NE(-1, write(master_fd,
test, 9));
101 while (!motors->commandAvailable()) {
105 mm = motors->receiveCommand();
112 uint8_t
test[] = {0x01, 0x2C, 0x0E, 0x7E, 0x3B, 0x2A,
113 0x00, 0x00, 0x01, 0x2C, 0x6D};
115 ASSERT_NE(-1, write(master_fd,
test, 11));
117 while (!motors->commandAvailable()) {
121 mm = motors->receiveCommand();
128 uint8_t
test[] = {0x7E, 0x3D, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x98};
130 ASSERT_NE(-1, write(master_fd,
test, 8));
132 while (!motors->commandAvailable()) {
136 mm = motors->receiveCommand();
141 uint8_t
test[] = {0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
143 ASSERT_NE(-1, write(master_fd,
test, 9));
147 while (!motors->commandAvailable()) {
163 uint8_t
test[] = {0x00, 0x7d, 0x3B, 0x2A, 0x00, 0x00, 0x01, 0x2C, 0x6D};
165 ASSERT_NE(-1, write(master_fd,
test, 9));
169 while (!motors->commandAvailable()) {
185 uint8_t
test[] = {0x7E, 0x3B, 0x00};
187 ASSERT_NE(-1, write(master_fd,
test, 3));
191 while (!motors->commandAvailable()) {
207 uint8_t
test[] = {0x0f, 0x7E, 0x3B, 0x00};
209 ASSERT_NE(-1, write(master_fd,
test, 4));
213 while (!motors->commandAvailable()) {
229 uint8_t
test[] = {0x7E, 0xFB, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFB};
231 ASSERT_NE(-1, write(master_fd,
test, 8));
235 while (!motors->commandAvailable()) {
251 uint8_t
test[] = {0x7E, 0x2E, 0x07, 0x00, 0x00, 0x00, 0x00, 0xCA};
253 ASSERT_NE(-1, write(master_fd,
test, 8));
257 while (!motors->commandAvailable()) {
277 motors->transmitCommand(
version);
281 ASSERT_NE(-1, ioctl(master_fd,
TIOCINQ, &count));
286 EXPECT_EQ(input.size(), read(master_fd, input.c_array(), input.size()));
288 ASSERT_EQ(input,
version.serialize());
292 std::vector<MotorMessage> commands;
298 commands.push_back(left_odom);
304 commands.push_back(right_odom);
310 commands.push_back(left_vel);
316 commands.push_back(right_vel);
318 motors->transmitCommands(commands);
322 FD_SET(master_fd, &fds);
323 struct timeval
timeout = { 10, 0 };
330 int ret = select(master_fd+1, &fds, NULL, NULL, &
timeout);
335 ASSERT_NE(-1, ioctl(master_fd,
TIOCINQ, &avail));
338 EXPECT_EQ(avail, read(master_fd, arr+count, avail));
342 ASSERT_EQ(32, count);
344 std::vector<uint8_t> input(arr, arr +
sizeof(arr) /
sizeof(uint8_t));
346 std::vector<uint8_t> expected(0);
347 for (std::vector<MotorMessage>::iterator i = commands.begin();
348 i != commands.end(); ++i) {
350 expected.insert(expected.end(), serialized.begin(), serialized.end());
353 ASSERT_EQ(expected, input);
356 int main(
int argc,
char **argv) {
357 testing::InitGoogleTest(&argc, argv);
358 return RUN_ALL_TESTS();