55#include < libdbc/dbc.hpp>
66
77#include " common.hpp"
8+ #include " defines.hpp"
89
910// Testing of parsing messages
1011
1112TEST_CASE (" Parse Message Unknown ID" ) {
12- libdbc::DbcParser parser;
13-
14- const auto dbcContent = R"( BO_ 234 MSG1: 8 Vector__XXX
13+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 234 MSG1: 8 Vector__XXX
1514 SG_ Msg1Sig1 : 0|8@0+ (1,0) [-3276.8|-3276.7] "C" Vector__XXX
1615 SG_ MsgSig2 : 8|8@0+ (1,0) [-3276.8|-3276.7] "C" Vector__XXX
1716BO_ 123 MSG2: 8 Vector__XXX
1817 SG_ Msg2Sig1 : 0|8@0+ (1,0) [-3276.8|-3276.7] "C" Vector__XXX
1918 SG_ Msg2Sig1 : 8|8@0+ (1,0) [-3276.8|-3276.7] "C" Vector__XXX
2019)" ;
20+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
2121
22- const auto * filename = std::tmpnam (NULL );
23- CHECK (create_tmp_dbc_with (filename, dbcContent));
24-
25- parser.parse_file (filename);
22+ libdbc::DbcParser parser;
23+ parser.parse_file (filename.c_str ());
2624
2725 SECTION (" Evaluating unknown` message id" ) {
2826 std::vector<double > out_values;
@@ -31,9 +29,7 @@ BO_ 123 MSG2: 8 Vector__XXX
3129}
3230
3331TEST_CASE (" Parse Message Big Number not aligned little endian" ) {
34- libdbc::DbcParser parser;
35-
36- const auto dbcContent = R"( BO_ 337 STATUS: 8 Vector__XXX
32+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 337 STATUS: 8 Vector__XXX
3733 SG_ Value6 : 27|3@1+ (1,0) [0|7] "" Vector__XXX
3834 SG_ Value5 : 16|11@1+ (0.1,-102) [-102|102] "%" Vector__XXX
3935 SG_ Value2 : 8|2@1+ (1,0) [0|2] "" Vector__XXX
@@ -42,10 +38,9 @@ TEST_CASE("Parse Message Big Number not aligned little endian") {
4238 SG_ Value4 : 11|4@1+ (1,0) [0|3] "" Vector__XXX
4339 SG_ Value1 : 0|8@1+ (1,0) [0|204] "Km/h" Vector__XXX
4440)" ;
41+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
4542
46- const auto * filename = std::tmpnam (NULL );
47- CHECK (create_tmp_dbc_with (filename, dbcContent));
48-
43+ libdbc::DbcParser parser;
4944 parser.parse_file (filename);
5045
5146 SECTION (" Evaluating first message" ) {
@@ -83,20 +78,19 @@ TEST_CASE("Parse Message Big Number not aligned little endian") {
8378}
8479
8580TEST_CASE (" Parse Message little endian" ) {
86- const auto * filename = std::tmpnam (NULL );
87-
88- create_tmp_dbc_with (filename, R"( BO_ 541 STATUS: 8 DEVICE1
81+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 541 STATUS: 8 DEVICE1
8982 SG_ Temperature : 48|16@1+ (0.01,-40) [-40|125] "C" DEVICE1
9083 SG_ SOH : 0|16@1+ (0.01,0) [0|100] "%" DEVICE1
9184 SG_ SOE : 32|16@1+ (0.01,0) [0|100] "%" DEVICE1
92- SG_ SOC : 16|16@1+ (0.01,0) [0|100] "%" DEVICE1)" );
85+ SG_ SOC : 16|16@1+ (0.01,0) [0|100] "%" DEVICE1)" ;
86+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
9387
94- libdbc::DbcParser p ;
95- p .parse_file (filename);
88+ libdbc::DbcParser parser ;
89+ parser .parse_file (filename);
9690
9791 std::vector<uint8_t > data{0x08 , 0x27 , 0xa3 , 0x22 , 0xe5 , 0x1f , 0x45 , 0x14 }; // little endian
9892 std::vector<double > result_values;
99- REQUIRE (p .parseMessage (0x21d , data, result_values) == libdbc::Message::ParseSignalsStatus::Success);
93+ REQUIRE (parser .parseMessage (0x21d , data, result_values) == libdbc::Message::ParseSignalsStatus::Success);
10094 REQUIRE (result_values.size () == 4 );
10195
10296 REQUIRE (Catch::Approx (result_values.at (0 )) == 11.89 );
@@ -106,8 +100,7 @@ TEST_CASE("Parse Message little endian") {
106100}
107101
108102TEST_CASE (" Parse Message big endian signed values" ) {
109- const auto * filename = std::tmpnam (NULL );
110- create_tmp_dbc_with (filename, R"( BO_ 545 MSG: 8 BMS2
103+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 545 MSG: 8 BMS2
111104 SG_ Sig1 : 62|1@0+ (1,0) [0|0] "" Vector__XXX
112105 SG_ Sig2 : 49|2@0+ (1,0) [0|0] "" Vector__XXX
113106 SG_ Sig3 : 39|16@0- (0.1,0) [0|0] "A" Vector__XXX
@@ -119,10 +112,11 @@ TEST_CASE("Parse Message big endian signed values") {
119112 SG_ Sig9 : 56|1@0+ (1,0) [0|0] "" Vector__XXX
120113 SG_ Sig10 : 61|1@0+ (1,0) [0|0] "" Vector__XXX
121114 SG_ Sig11 : 7|16@0+ (0.001,0) [0|65.535] "V" Vector__XXX
122- SG_ Sig12 : 23|16@0+ (0.1,0) [0|6553.5] "A" Vector__XXX)" );
115+ SG_ Sig12 : 23|16@0+ (0.1,0) [0|6553.5] "A" Vector__XXX)" ;
116+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
123117
124118 libdbc::DbcParser p;
125- p.parse_file (filename);
119+ p.parse_file (filename. c_str () );
126120
127121 std::vector<uint8_t > data{13 , 177 , 0 , 216 , 251 , 180 , 0 , 31 }; // big endian
128122 std::vector<double > result_values;
@@ -143,12 +137,12 @@ TEST_CASE("Parse Message big endian signed values") {
143137}
144138
145139TEST_CASE (" Parse Message with non byte aligned values" ) {
146- const auto * filename = std::tmpnam (NULL );
147- create_tmp_dbc_with (filename, R"( BO_ 403 INFORMATION: 8 Vector__XXX
140+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 403 INFORMATION: 8 Vector__XXX
148141 SG_ Voltage : 30|9@1+ (0.2,0) [0|102.2] "V" Vector__XXX
149142 SG_ Phase_Current : 20|10@1- (1,0) [-512|512] "A" Vector__XXX
150143 SG_ Iq_Current : 10|10@1- (1,0) [-512|512] "A" Vector__XXX
151- SG_ Id_Current : 0|10@1- (1,0) [-512|512] "A" Vector__XXX)" );
144+ SG_ Id_Current : 0|10@1- (1,0) [-512|512] "A" Vector__XXX)" ;
145+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
152146
153147 libdbc::DbcParser p;
154148 p.parse_file (filename);
@@ -164,10 +158,10 @@ TEST_CASE("Parse Message with non byte aligned values") {
164158}
165159
166160TEST_CASE (" Parse Message data length < 8 unsigned" ) {
167- const auto * filename = std::tmpnam (NULL );
168- create_tmp_dbc_with (filename, R"( BO_ 234 MSG1: 8 Vector__XXX
161+ std::string dbc_contents = PRIMITIVE_DBC + R"( BO_ 234 MSG1: 8 Vector__XXX
169162 SG_ Msg1Sig1 : 7|8@0+ (1,0) [-3276.8|-3276.7] "C" Vector__XXX
170- SG_ Msg1Sig2 : 15|8@0+ (1,0) [-3276.8|-3276.7] "km/h" Vector__XXX)" );
163+ SG_ Msg1Sig2 : 15|8@0+ (1,0) [-3276.8|-3276.7] "km/h" Vector__XXX)" ;
164+ const auto filename = create_temporary_dbc_with (dbc_contents.c_str ());
171165
172166 libdbc::DbcParser p;
173167 p.parse_file (filename);
0 commit comments