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 27a7b07

Browse files
Implementing test code for "CanStandardId", "CanExtendedId", "isStandardId", "isExtendedId".
1 parent 36cc4b1 commit 27a7b07

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

‎test/CMakeLists.txt‎

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

2727
set(TEST_SRCS
28+
src/CanMsg/test_CanExtendedId.cpp
29+
src/CanMsg/test_CanStandardId.cpp
30+
src/CanMsg/test_isExtendedId.cpp
31+
src/CanMsg/test_isStandardId.cpp
2832
src/Common/test_makeWord.cpp
2933
src/Common/test_map.cpp
3034
src/Common/test_max.cpp
@@ -95,6 +99,7 @@ set(TEST_SRCS
9599
)
96100

97101
set(TEST_DUT_SRCS
102+
../api/CanMsg.cpp
98103
../api/Common.cpp
99104
../api/IPAddress.cpp
100105
../api/String.cpp
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 ("Verify correct conversion to 29-Bit CAN ID for lowest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-01]")
24+
{
25+
REQUIRE(CanExtendedId(0) == (CanMsg::CAN_EFF_FLAG | 0U));
26+
}
27+
28+
TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for highest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-02]")
29+
{
30+
REQUIRE(CanExtendedId(0x1FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU));
31+
}
32+
33+
TEST_CASE ("Verify capping of CAN IDs exceeding 29-Bit CAN ID range", "[CanMsg-CanExtendedId-03]")
34+
{
35+
REQUIRE(CanExtendedId(0x2FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU));
36+
REQUIRE(CanExtendedId(0x3FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU));
37+
REQUIRE(CanExtendedId(0x4FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU));
38+
REQUIRE(CanExtendedId(0x5FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU));
39+
/* ... */
40+
REQUIRE(CanExtendedId(0xFFFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU));
41+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 ("Verify correct conversion to 11-Bit CAN ID for lowest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-01]")
24+
{
25+
REQUIRE(CanStandardId(0) == 0U);
26+
}
27+
28+
TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for highest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-02]")
29+
{
30+
REQUIRE(CanStandardId(0x7FF) == 0x7FF);
31+
}
32+
33+
TEST_CASE ("Verify capping of CAN IDs exceeding 11-Bit CAN ID range", "[CanMsg-CanStandardId-03]")
34+
{
35+
REQUIRE(CanStandardId(0x800U) == 0x000U);
36+
REQUIRE(CanStandardId(0x801U) == 0x001U);
37+
REQUIRE(CanStandardId(0x8FFU) == 0x0FFU);
38+
REQUIRE(CanStandardId(0x1FFFFFFFU) == 0x7FFU);
39+
REQUIRE(CanStandardId(0xFFFFFFFFU) == 0x7FFU);
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 ("\"isExtendedId\" should return true for extended CAN ID", "[CanMsg-isExtendedId-01]")
24+
{
25+
CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr);
26+
REQUIRE(msg_ext_id.isExtendedId() == true);
27+
}
28+
29+
TEST_CASE ("\"isExtendedId\" should return false for standard CAN ID", "[CanMsg-isExtendedId-02]")
30+
{
31+
CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr);
32+
REQUIRE(msg_std_id.isExtendedId() == false);
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 ("\"isStandardId\" should return true for standard CAN ID", "[CanMsg-isStandardId-01]")
24+
{
25+
CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr);
26+
REQUIRE(msg_std_id.isStandardId() == true);
27+
}
28+
29+
TEST_CASE ("\"isStandardId\" should return false for extended CAN ID", "[CanMsg-isStandardId-02]")
30+
{
31+
CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr);
32+
REQUIRE(msg_ext_id.isStandardId() == false);
33+
}

0 commit comments

Comments
(0)

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