Skip to content

Commit 16c74c1

Browse files
committed
Test CanMsg copy constructor.
1 parent 39aa684 commit 16c74c1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
2626

2727
set(TEST_SRCS
2828
src/CanMsg/test_CanMsg.cpp
29+
src/CanMsg/test_CanMsg_CopyCtor.cpp
2930
src/CanMsg/test_CanExtendedId.cpp
3031
src/CanMsg/test_CanStandardId.cpp
3132
src/CanMsg/test_isExtendedId.cpp

Diff for: test/src/CanMsg/test_CanMsg_CopyCtor.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 copy constructor", "[CanMsg-CopyCtor-01]")
24+
{
25+
uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE};
26+
27+
CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data);
28+
CanMsg const msg_2(msg_1);
29+
30+
REQUIRE(msg_1.data_length == msg_2.data_length);
31+
32+
for (size_t i = 0; i < msg_1.data_length; i++)
33+
{
34+
REQUIRE(msg_1.data[i] == msg_data[i]);
35+
REQUIRE(msg_2.data[i] == msg_data[i]);
36+
}
37+
38+
}

0 commit comments

Comments
 (0)