31 #include <gtest/gtest.h> 34 TEST(MotorMessageTest, motor_message_commandtype) {
50 TEST(MotorMessageTest, motor_message_commandtype_values) {
53 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xA));
56 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xB));
59 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xC));
62 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xD));
66 TEST(MotorMessageTest, motor_message_commandtype_invalid) {
69 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xF));
73 TEST(MotorMessageTest, motor_message_commandtype_overflow) {
76 mc.
setType(static_cast<MotorMessage::MessageTypes>(0xFFFFFF));
77 ASSERT_NE(0xFFFFFF, mc.
getType());
80 TEST(MotorMessageTest, motor_message_commandtype_neg) {
83 mc.
setType(static_cast<MotorMessage::MessageTypes>(-0xA));
88 TEST(MotorMessageTest, motor_message_register) {
96 TEST(MotorMessageTest, motor_message_register_values) {
99 mc.
setRegister(static_cast<MotorMessage::Registers>(0x01));
102 mc.
setRegister(static_cast<MotorMessage::Registers>(0x10));
105 mc.
setRegister(static_cast<MotorMessage::Registers>(0x0B));
109 TEST(MotorMessageTest, motor_message_register_invalid) {
112 mc.
setRegister(static_cast<MotorMessage::Registers>(0x05));
116 TEST(MotorMessageTest, motor_message_register_overflow) {
119 mc.
setRegister(static_cast<MotorMessage::Registers>(0xFFFFFF));
123 TEST(MotorMessageTest, motor_message_register_neg) {
126 mc.
setRegister(static_cast<MotorMessage::Registers>(-0x07));
131 TEST(MotorMessageTest, motor_message_data_64bit) {
135 ASSERT_EQ(0xABC, mc.
getData());
143 ASSERT_EQ(-0xABC, mc.
getData());
146 TEST(MotorMessageTest, motor_message_data_32bit) {
150 ASSERT_EQ(0xABC, mc.
getData());
158 ASSERT_EQ(-0xABC, mc.
getData());
161 TEST(MotorMessageTest, motor_message_data_16bit) {
165 ASSERT_EQ(0xABC, mc.
getData());
173 ASSERT_EQ(-0xABC, mc.
getData());
176 TEST(MotorMessageTest, motor_message_data_8bit) {
188 ASSERT_EQ(-0x50, mc.
getData());
191 TEST(MotorMessageTest, motor_message_serialize) {
197 RawMotorMessage expect = {0x7E, 0x3B, 0x07, 0x00, 0x00, 0x01, 0x2C, 0x90};
202 TEST(MotorMessageTest, motor_message_deserialize_good) {
206 RawMotorMessage input = {0x7E, 0x3B, 0x07, 0x00, 0x00, 0x01, 0x2C, 0x90};
214 TEST(MotorMessageTest, motor_message_deserialize_delimeter_in_data) {
217 RawMotorMessage input = {0x7E, 0x3B, 0x07, 0x00, 0x00, 0x01, 0x7E, 0x3E};
225 TEST(MotorMessageTest, motor_message_deserialize_bad_delimeter) {
229 RawMotorMessage input = {0x67, 0x3B, 0x07, 0x00, 0x00, 0x00, 0x00, 0xBD};
234 TEST(MotorMessageTest, motor_message_deserialize_bad_protocol) {
238 RawMotorMessage input = {0x7E, 0x2B, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3D};
243 TEST(MotorMessageTest, motor_message_deserialize_bad_checksum) {
247 RawMotorMessage input = {0x7E, 0x3B, 0x07, 0x00, 0x00, 0x01, 0x2C, 0x0F};
252 TEST(MotorMessageTest, motor_message_deserialize_bad_type) {
256 RawMotorMessage input = {0x7E, 0x3F, 0x07, 0x00, 0x00, 0x00, 0x00, 0xB9};
261 TEST(MotorMessageTest, motor_message_deserialize_bad_register) {
265 RawMotorMessage input = {0x7E, 0x3B, 0x60, 0x00, 0x00, 0x00, 0x2C, 0x38};
270 int main(
int argc,
char **argv) {
271 testing::InitGoogleTest(&argc, argv);
272 return RUN_ALL_TESTS();
MotorMessage::MessageTypes getType() const
void setData(int32_t data)
MotorMessage::Registers getRegister() const
boost::array< uint8_t, 8 > RawMotorMessage
TEST(MotorMessageTest, motor_message_commandtype)
RawMotorMessage serialize() const
void setRegister(MotorMessage::Registers reg)
int main(int argc, char **argv)
void setType(MotorMessage::MessageTypes type)
int deserialize(const RawMotorMessage &serialized)