|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Arduino. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +/************************************************************************************** |
| 6 | + * INCLUDE |
| 7 | + **************************************************************************************/ |
| 8 | + |
| 9 | +#include <catch.hpp> |
| 10 | + |
| 11 | +#include <CanMsg.h> |
| 12 | + |
| 13 | +/************************************************************************************** |
| 14 | + * NAMESPACE |
| 15 | + **************************************************************************************/ |
| 16 | + |
| 17 | +using namespace arduino; |
| 18 | + |
| 19 | +/************************************************************************************** |
| 20 | + * TEST CODE |
| 21 | + **************************************************************************************/ |
| 22 | + |
| 23 | +TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]") |
| 24 | +{ |
| 25 | + CanMsg const msg(CanStandardId(0x20), 0, nullptr); |
| 26 | + |
| 27 | + REQUIRE(msg.data_length == 0); |
| 28 | + for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++) |
| 29 | + REQUIRE(msg.data[i] == 0); |
| 30 | +} |
| 31 | + |
| 32 | +TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]") |
| 33 | +{ |
| 34 | + uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; |
| 35 | + |
| 36 | + CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); |
| 37 | + |
| 38 | + REQUIRE(msg.data_length == 4); |
| 39 | + for (size_t i = 0; i < msg.data_length; i++) |
| 40 | + REQUIRE(msg.data[i] == msg_data[i]); |
| 41 | +} |
| 42 | + |
| 43 | +TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]") |
| 44 | +{ |
| 45 | + uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; |
| 46 | + |
| 47 | + CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); |
| 48 | + |
| 49 | + REQUIRE(msg.data_length == 8); |
| 50 | + for (size_t i = 0; i < msg.data_length; i++) |
| 51 | + REQUIRE(msg.data[i] == msg_data[i]); |
| 52 | +} |
0 commit comments