-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_CanMsg.cpp
66 lines (48 loc) · 2.03 KB
/
test_CanMsg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <api/CanMsg.h>
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
using namespace arduino;
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]")
{
CanMsg const msg(CanStandardId(0x20), 0, nullptr);
REQUIRE(msg.data_length == 0);
for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++)
REQUIRE(msg.data[i] == 0);
}
TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]")
{
uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE};
CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data);
REQUIRE(msg.data_length == 4);
for (size_t i = 0; i < msg.data_length; i++)
REQUIRE(msg.data[i] == msg_data[i]);
}
TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]")
{
uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data);
REQUIRE(msg.data_length == 8);
for (size_t i = 0; i < msg.data_length; i++)
REQUIRE(msg.data[i] == msg_data[i]);
}
TEST_CASE ("Test constructor constructing a CAN frame with standard ID", "[CanMsg-CanMsg-04]")
{
CanMsg const msg(CanStandardId(0x20), 0, nullptr);
REQUIRE(msg.id == 0x20);
}
TEST_CASE ("Test constructor constructing a CAN frame with extended ID", "[CanMsg-CanMsg-05]")
{
CanMsg const msg(CanExtendedId(0x20), 0, nullptr);
REQUIRE(msg.id == (CanMsg::CAN_EFF_FLAG | 0x20));
}