Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
test_CanBusManager.cpp
Go to the documentation of this file.
1
16
17#include "CanBusManager.hpp"
19#include <QSignalSpy>
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
22
23using ::testing::_;
24using ::testing::Return;
25
33class CanBusManagerTest : public ::testing::Test {
34protected:
45
52 void TearDown() override {
53 if (manager != nullptr) {
54 delete manager;
55 }
56 if (mockMcpController != nullptr) {
57 delete mockMcpController;
58 }
59 }
60
65};
66
76TEST_F(CanBusManagerTest, SpeedSignalEmitsCorrectly) {
77 QSignalSpy speedSpy(manager, &CanBusManager::speedUpdated);
78
79 float expectedSpeed = 150.0F;
80 emit mockMcpController->speedUpdated(expectedSpeed);
81
82 ASSERT_EQ(speedSpy.count(), 1);
83 ASSERT_EQ(speedSpy.takeFirst().at(0).toFloat(), expectedSpeed);
84}
85
95TEST_F(CanBusManagerTest, RpmSignalEmitsCorrectly) {
96 QSignalSpy rpmSpy(manager, &CanBusManager::rpmUpdated);
97
98 int expectedRpm = 2500;
99 emit mockMcpController->rpmUpdated(expectedRpm);
100
101 ASSERT_EQ(rpmSpy.count(), 1);
102 ASSERT_EQ(rpmSpy.takeFirst().at(0).toInt(), expectedRpm);
103}
104
115TEST_F(CanBusManagerTest, InitializeFailsWhenControllerFails) {
116 EXPECT_CALL(*static_cast<MockMCP2515Controller *>(mockMcpController), init())
117 .WillOnce(Return(false));
118
119 ASSERT_FALSE(manager->initialize());
120}
121
132TEST_F(CanBusManagerTest, InitializeSucceedsWhenControllerSucceeds) {
133 EXPECT_CALL(*static_cast<MockMCP2515Controller *>(mockMcpController), init())
134 .WillOnce(Return(true));
135
136 ASSERT_TRUE(manager->initialize());
137}
138
152TEST_F(CanBusManagerTest, DestructorCallsStopReading) {
153 EXPECT_CALL(*static_cast<MockMCP2515Controller *>(mockMcpController), init())
154 .WillOnce(Return(true));
155 EXPECT_CALL(*static_cast<MockMCP2515Controller *>(mockMcpController),
156 stopReading())
157 .Times(1);
158
159 ASSERT_TRUE(manager->initialize());
160
161 delete manager;
162 manager = nullptr;
163
164 SUCCEED();
165}
Definition of the CanBusManager class.
File containing Mock classes to test the controller of the MCP2515 module.
Class to test the integration between the CanBusManager and the MCP2515 controller.
IMCP2515Controller * mockMcpController
Mocked MCP2515 controller.
void TearDown() override
Tear down the test environment.
void SetUp() override
Set up the test environment.
CanBusManager * manager
CanBusManager object.
Class that manages the CAN bus communication. QObject.
void rpmUpdated(int newRpm)
Signal emitted when the RPM is updated.
void speedUpdated(float newSpeed)
Signal emitted when the speed is updated.
Interface for the MCP2515 CAN controller. QObject.
Class to emulate the behavior of the MCP2515 controller.
TEST_F(CanBusManagerTest, SpeedSignalEmitsCorrectly)
Ensures that the speed signal is emitted with the correct value.