33#include < catch2/catch_approx.hpp>
44#include < catch2/catch_test_macros.hpp>
55#include < catch2/matchers/catch_matchers.hpp>
6+ #include < catch2/matchers/catch_matchers_string.hpp>
67#include < libdbc/dbc.hpp>
78#include < libdbc/exceptions/error.hpp>
89#include < string>
910
11+ using Catch::Matchers::ContainsSubstring;
12+
1013TEST_CASE (" Testing dbc file loading error issues" , " [fileio][error]" ) {
1114 auto parser = std::unique_ptr<Libdbc::DbcParser>(new Libdbc::DbcParser ());
1215
1316 SECTION (" Loading a non dbc file should throw an error" , " [error]" ) {
14- REQUIRE_THROWS_AS (parser->parse_file (TEXT_FILE), Libdbc::ValidityError);
17+ REQUIRE_THROWS_AS (parser->parse_file (TEXT_FILE), Libdbc::NonDbcFileFormatError);
18+ REQUIRE_THROWS_WITH (parser->parse_file (TEXT_FILE), ContainsSubstring (" TextFile.txt" ));
1519 }
1620
17- SECTION (" Loading a dbc with bad headers throws an error" , " [error]" ) {
18- REQUIRE_THROWS_AS (parser->parse_file (MISSING_VERSION_DBC_FILE), Libdbc::ValidityError);
21+ SECTION (" Loading a dbc with missing version header throws an error (VERSION)" , " [error]" ) {
22+ REQUIRE_THROWS_AS (parser->parse_file (MISSING_VERSION_DBC_FILE), Libdbc::DbcFileIsMissingVersion);
23+ REQUIRE_THROWS_WITH (parser->parse_file (MISSING_VERSION_DBC_FILE), ContainsSubstring (" line: (NS_ :)" ));
1924 }
2025
2126 SECTION (" Loading a dbc without the required bit timing section (BS_:)" , " [error]" ) {
22- REQUIRE_THROWS_AS (parser->parse_file (MISSING_BIT_TIMING_DBC_FILE), Libdbc::ValidityError);
27+ REQUIRE_THROWS_AS (parser->parse_file (MISSING_BIT_TIMING_DBC_FILE), Libdbc::DbcFileIsMissingBitTiming);
28+ REQUIRE_THROWS_WITH (parser->parse_file (MISSING_BIT_TIMING_DBC_FILE), ContainsSubstring (" BU_: DBG DRIVER IO MOTOR SENSOR" ));
2329 }
2430
2531 SECTION (" Loading a dbc with some missing namespace section tags (NS_ :)" , " [error]" ) {
2632 // Confusion about this type of error. it appears that the header isn't
2733 // very well standardized for now we ignore this type of error.
28- CHECK_NOTHROW (parser->parse_file (MISSING_NEW_SYMBOLS_DBC_FILE));
34+ REQUIRE_NOTHROW (parser->parse_file (MISSING_NEW_SYMBOLS_DBC_FILE));
2935 }
3036
3137 SECTION (" Verify that what() method is accessible for all exceptions" , " [error]" ) {
@@ -240,7 +246,7 @@ VAL_ 123 State1 123 "Description 3" 0 "Description 4" ;)";
240246 REQUIRE (signal2.value_descriptions .at (1 ).description == " Description 4" );
241247}
242248
243- TEST_CASE (" Should parse DBC with empty BU_" ) {
249+ TEST_CASE (" Should parse DBC with empty BU_" , " [error][optional] " ) {
244250 std::string contents = R"( VERSION ""
245251
246252
@@ -254,15 +260,52 @@ NS_ :
254260BO_ 293 Msg1: 2 Vector__XXX
255261 SG_ Wert7 : 0|16@1- (1,0) [0|0] "" Vector__XXX
256262
257- BO_ 292 Msg2: 8 Vector__XXX
263+ BO_ 292 Msg2: 1 Vector__XXX
258264 SG_ Wert8 : 56|8@1- (1,0) [0|0] "" Vector__XXX
259265)" ;
260266 const auto filename = create_temporary_dbc_with (contents.c_str ());
261267
262268 auto parser = Libdbc::DbcParser ();
263- parser.parse_file (filename.c_str ());
269+ REQUIRE_NOTHROW ( parser.parse_file (filename.c_str () ));
264270
265271 REQUIRE (parser.get_messages ().size () == 2 );
266272 REQUIRE (parser.get_messages ().at (0 ).name () == " Msg1" );
267273 REQUIRE (parser.get_messages ().at (1 ).name () == " Msg2" );
268274}
275+
276+ TEST_CASE (" Should report unused lines since we don't have tracing." , " [parsing]" ) {
277+ std::string contents = R"( VERSION ""
278+
279+ NS_ :
280+
281+ BS_:
282+
283+ BU_:
284+
285+
286+ BO_ 293 Msg1: 2 Vector__XXX
287+ SG_ Whitespace: | 0|16@1- (1,0) [0|0] "" Vector__XXX
288+ SG_ Wert7 : 0|16@1- (1,0) [0|0] "" Vector__XXX
289+ SG_ Wert8 : 0|16@1- (1,0) [0|0] "" Vector__XXX
290+
291+ BO_ 292 Msg2: 1 Vector__XXX
292+ SG_ Wert8 : 56|8@1- (1,0) [0|0] "" Vector__XXX
293+ SB_ not a correct line
294+
295+ BO_ have a issue here:
296+ )" ;
297+
298+ const auto filename = create_temporary_dbc_with (contents.c_str ());
299+
300+ auto parser = Libdbc::DbcParser ();
301+ REQUIRE_NOTHROW (parser.parse_file (filename.c_str ()));
302+
303+ REQUIRE (parser.get_messages ().size () == 2 );
304+ REQUIRE (parser.get_messages ()[0 ].size () == 2 );
305+ REQUIRE (parser.get_messages ()[1 ].size () == 1 );
306+
307+ auto unused = parser.unused_lines ();
308+
309+ // We could match them all here but i think just a check that the size is sufficent.
310+ REQUIRE (unused.size () == 3 );
311+ }
0 commit comments