20#include <gtest/gtest.h>
59 }
catch (
const std::exception& e) {
60 FAIL() <<
"SetUp() failed with exception: " << e.what();
84 dataFrame.
data = {0x01, 0x02, 0x03, 0x04,
85 0x05, 0x06, 0x07, 0x08};
86 dataFrame.
dlc = dataFrame.
data.size();
89 canBusConfigurator->sendCANMessage(dataFrame.
id, dataFrame.
data.data(),
94 std::vector<uint8_t> receivedData =
95 canBusConfigurator->readCANMessage(receivedID);
98 ASSERT_EQ(receivedID, dataFrame.
id);
99 ASSERT_EQ(receivedData, dataFrame.
data);
122 remoteFrame.
id = 0x123;
127 canBusConfigurator->sendCANMessage(remoteFrame.
id,
nullptr, 0);
131 std::vector<uint8_t> responseData =
132 canBusConfigurator->readCANMessage(responseID);
135 ASSERT_EQ(responseID, remoteFrame.
id);
136 ASSERT_EQ(responseData.size(), remoteFrame.
dlc);
159 errorFrame.
id = 0x7FF;
161 errorFrame.
data = {0xFF, 0xFF, 0xFF, 0xFF,
163 errorFrame.
dlc = errorFrame.
data.size();
166 canBusConfigurator->sendCANMessage(errorFrame.
id, errorFrame.
data.data(),
171 std::vector<uint8_t> receivedData =
172 canBusConfigurator->readCANMessage(receivedID);
175 ASSERT_EQ(receivedID, errorFrame.
id);
176 ASSERT_EQ(receivedData, errorFrame.
data);
187 canBusConfigurator->sendCANMessage(errorFrame.
id, errorFrame.
data.data(),
206 dataFrame.
id = 0x7FF;
208 dataFrame.
data = {0x01, 0x02, 0x03, 0x04,
209 0x05, 0x06, 0x07, 0x08};
210 dataFrame.
dlc = dataFrame.
data.size();
213 canBusConfigurator->sendCANMessage(dataFrame.
id, dataFrame.
data.data(),
218 std::vector<uint8_t> receivedData =
219 canBusConfigurator->readCANMessage(receivedID);
222 ASSERT_EQ(receivedID, dataFrame.
id);
223 ASSERT_EQ(receivedData, dataFrame.
data);
249 dataFrame.
id = 0x7FF;
251 dataFrame.
data = {0x01, 0x02, 0x03, 0x04,
252 0x05, 0x06, 0x07, 0x08};
253 dataFrame.
dlc = dataFrame.
data.size();
256 canBusConfigurator->sendCANMessage(dataFrame.
id, dataFrame.
data.data(),
261 std::vector<uint8_t> receivedData =
262 canBusConfigurator->readCANMessage(receivedID);
265 ASSERT_EQ(receivedID, dataFrame.
id);
266 ASSERT_EQ(receivedData, dataFrame.
data);
286int main(
int argc,
char **argv) {
287 ::testing::InitGoogleTest(&argc, argv);
288 return RUN_ALL_TESTS();
Definition of the MCP2515Controller class.
Definition of the SPIController class.
Class that configures the MCP2515 CAN controller.
Class to test the integration between the MCP2515 controller and the SPI controller.
MCP2515Configurator * canBusConfigurator
SPIController * spiController
Class that controls the SPI communication. ISPIController.
Structure to represent a CAN frame. following fields needed to represent a CAN frame.
bool crcValid
CRC validity.
uint8_t rtr
Remote Transmission Request.
std::vector< uint8_t > data
Data field.
bool ackReceived
Acknowledgement received.
uint8_t dlc
Data Length Code.
TEST_F(RS485CANTest, DataFrameTest)
Ensures that the MCP2515 controller initializes successfully.
int main(int argc, char **argv)
Ensures that the MCP2515 controller initializes successfully.