Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
test_CANMessageProcessor.cpp
Go to the documentation of this file.
1
14
16#include <gtest/gtest.h>
17#include <stdexcept>
18#include <vector>
19
27class CANMessageProcessorTest : public ::testing::Test {
28protected:
30};
31
39TEST_F(CANMessageProcessorTest, RegisterHandlerSuccess) {
40 ASSERT_NO_THROW(
41 processor.registerHandler(0x123, [](const std::vector<uint8_t> &) {}));
42}
43
51TEST_F(CANMessageProcessorTest, RegisterHandlerNullThrowsException) {
52 ASSERT_THROW(processor.registerHandler(0x123, nullptr),
53 std::invalid_argument);
54}
55
63TEST_F(CANMessageProcessorTest, ProcessMessageWithRegisteredHandler) {
64 bool handlerCalled = false;
65 processor.registerHandler(0x123, [&](const std::vector<uint8_t> &data) {
66 handlerCalled = true;
67 ASSERT_EQ(data.size(), 2);
68 ASSERT_EQ(data[0], 0xA0);
69 ASSERT_EQ(data[1], 0xB1);
70 });
71
72 std::vector<uint8_t> message = {0xA0, 0xB1};
73 processor.processMessage(0x123, message);
74 ASSERT_TRUE(handlerCalled);
75}
76
86 ProcessMessageWithUnregisteredHandlerThrowsException) {
87 std::vector<uint8_t> message = {0xA0, 0xB1};
88 ASSERT_THROW(processor.processMessage(0x456, message), std::runtime_error);
89}
90
99TEST_F(CANMessageProcessorTest, OverwriteHandlerForSameFrameID) {
100 bool firstHandlerCalled = false;
101 bool secondHandlerCalled = false;
102
103 processor.registerHandler(
104 0x123, [&](const std::vector<uint8_t> &) { firstHandlerCalled = true; });
105
106 processor.registerHandler(
107 0x123, [&](const std::vector<uint8_t> &) { secondHandlerCalled = true; });
108
109 std::vector<uint8_t> message = {0xA0, 0xB1};
110 processor.processMessage(0x123, message);
111
112 ASSERT_FALSE(firstHandlerCalled);
113 ASSERT_TRUE(secondHandlerCalled);
114}
Definition of the CANMessageProcessor class.
Test fixture for testing the CANMessageProcessor class.
CANMessageProcessor processor
CANMessageProcessor object.
Class that processes CAN messages.
TEST_F(CANMessageProcessorTest, RegisterHandlerSuccess)
Ensures that registerHandler() does not throw an exception.