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 ed1c507

Browse files
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

‎test/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
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

‎test/src/CanMsg/test_CanMsg_CopyCtor.cpp‎

Lines changed: 0 additions & 1 deletion
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
}
Lines changed: 39 additions & 0 deletions
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+
}

‎test/src/CanMsg/test_printTo.cpp‎

Lines changed: 44 additions & 0 deletions
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)

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