17#include <gmock/gmock.h>
18#include <gtest/gtest.h>
21using ::testing::Return;
22using ::testing::Throw;
33TEST(PeripheralControllerTest, TestServoPWM) {
36 EXPECT_CALL(mockController, set_servo_pwm(0, 1024, 2048)).Times(1);
37 EXPECT_CALL(mockController, set_servo_pwm(1, 0, 4096)).Times(1);
52TEST(PeripheralControllerTest, TestMotorPWM) {
55 EXPECT_CALL(mockController, set_motor_pwm(0, 1500)).Times(1);
56 EXPECT_CALL(mockController, set_motor_pwm(1, 3000)).Times(1);
70TEST(PeripheralControllerTest, TestInitServo) {
73 EXPECT_CALL(mockController, init_servo()).Times(1);
86TEST(PeripheralControllerTest, TestInitMotors) {
89 EXPECT_CALL(mockController, init_motors()).Times(1);
104TEST(PeripheralControllerTest, TestI2CWriteByteData) {
107 EXPECT_CALL(mockController, i2c_smbus_write_byte_data(1, 0x10, 0x20))
108 .WillOnce(Return(0));
112 EXPECT_EQ(result, 0);
125TEST(PeripheralControllerTest, TestI2CReadByteData) {
128 EXPECT_CALL(mockController, i2c_smbus_read_byte_data(1, 0x10))
129 .WillOnce(Return(0x30));
133 EXPECT_EQ(result, 0x30);
145TEST(PeripheralControllerTest, TestWriteByteDataException) {
148 EXPECT_CALL(mockController, write_byte_data(_, _, _))
149 .WillOnce(Throw(std::runtime_error(
"I2C write failed")));
164TEST(PeripheralControllerTest, TestReadByteDataException) {
167 EXPECT_CALL(mockController, read_byte_data(_, _))
168 .WillOnce(Throw(std::runtime_error(
"I2C read failed")));
170 EXPECT_THROW(mockController.
read_byte_data(1, 0x10), std::runtime_error);
File containing Mock classes to test the peripheral controller.
virtual void set_servo_pwm(int channel, int on_value, int off_value)=0
virtual void write_byte_data(int fd, int reg, int value)=0
virtual int i2c_smbus_write_byte_data(int file, uint8_t command, uint8_t value)=0
virtual void init_servo()=0
virtual void set_motor_pwm(int channel, int value)=0
virtual int read_byte_data(int fd, int reg)=0
virtual int i2c_smbus_read_byte_data(int file, uint8_t command)=0
virtual void init_motors()=0
Class to emulate the behavior of the peripheral controller.
TEST(PeripheralControllerTest, TestServoPWM)
Ensures that set_servo_pwm() is called with the correct parameters.