File tree 5 files changed +152
-0
lines changed
5 files changed +152
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
25
25
##########################################################################
26
26
27
27
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
28
32
src/Common/test_makeWord.cpp
29
33
src/Common/test_map.cpp
30
34
src/Common/test_max.cpp
@@ -95,6 +99,7 @@ set(TEST_SRCS
95
99
)
96
100
97
101
set (TEST_DUT_SRCS
102
+ ../api/CanMsg.cpp
98
103
../api/Common.cpp
99
104
../api/IPAddress.cpp
100
105
../api/String .cpp
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments