Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bba303d

Browse files
Adding test code for CanMsg::CanMsg.
1 parent 70d3939 commit bba303d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
2525
##########################################################################
2626

2727
set(TEST_SRCS
28+
src/CanMsg/test_CanMsg.cpp
2829
src/CanMsg/test_CanExtendedId.cpp
2930
src/CanMsg/test_CanStandardId.cpp
3031
src/CanMsg/test_isExtendedId.cpp

‎test/src/CanMsg/test_CanMsg.cpp‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /