Skip to content

Commit ed1c507

Browse files
committed
Completing test code for all APIs of CanMsg.
1 parent 16c74c1 commit ed1c507

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

Diff for: test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ set(TEST_SRCS
3131
src/CanMsg/test_CanStandardId.cpp
3232
src/CanMsg/test_isExtendedId.cpp
3333
src/CanMsg/test_isStandardId.cpp
34+
src/CanMsg/test_operator_assignment.cpp
35+
src/CanMsg/test_printTo.cpp
3436
src/Common/test_makeWord.cpp
3537
src/Common/test_map.cpp
3638
src/Common/test_max.cpp

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ TEST_CASE ("Test copy constructor", "[CanMsg-CopyCtor-01]")
3434
REQUIRE(msg_1.data[i] == msg_data[i]);
3535
REQUIRE(msg_2.data[i] == msg_data[i]);
3636
}
37-
3837
}

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

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 ("Testing CanMsg::operator = (CanMsg const &)", "[CanMsg-Operator-=-1]")
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 msg_2(CanStandardId(0x21), 0, nullptr);
29+
30+
msg_2 = msg_1;
31+
32+
REQUIRE(msg_1.data_length == msg_2.data_length);
33+
34+
for (size_t i = 0; i < msg_1.data_length; i++)
35+
{
36+
REQUIRE(msg_1.data[i] == msg_data[i]);
37+
REQUIRE(msg_2.data[i] == msg_data[i]);
38+
}
39+
}

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

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#include <PrintMock.h>
13+
14+
/**************************************************************************************
15+
* NAMESPACE
16+
**************************************************************************************/
17+
18+
using namespace arduino;
19+
20+
/**************************************************************************************
21+
* TEST CODE
22+
**************************************************************************************/
23+
24+
TEST_CASE ("Print CAN frame with standard ID", "[CanMsg-printTo-1]")
25+
{
26+
uint8_t const std_msg_data[] = {0xBE, 0xEF};
27+
CanMsg const std_msg(CanStandardId(0x20), sizeof(std_msg_data), std_msg_data);
28+
29+
PrintMock mock;
30+
mock.print(std_msg);
31+
32+
REQUIRE(mock._str == "[020] (2) : BEEF");
33+
}
34+
35+
TEST_CASE ("Print CAN frame with extended ID", "[CanMsg-printTo-1]")
36+
{
37+
uint8_t const ext_msg_data[] = {0xDE, 0xAD, 0xC0, 0xDE};
38+
CanMsg const ext_msg(CanExtendedId(0x20), sizeof(ext_msg_data), ext_msg_data);
39+
40+
PrintMock mock;
41+
mock.print(ext_msg);
42+
43+
REQUIRE(mock._str == "[00000020] (4) : DEADC0DE");
44+
}

0 commit comments

Comments
 (0)