Skip to content

Commit

Permalink
feat(parsing): Adding a way to push and read all of the unused lines …
Browse files Browse the repository at this point in the history
…since we don't error out on unused
  • Loading branch information
LinuxDevon committed Mar 18, 2024
1 parent 64477fd commit be9f576
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/libdbc/dbc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DbcParser : public Parser {

Message::ParseSignalsStatus parse_message(uint32_t message_id, const std::vector<uint8_t>& data, std::vector<double>& out_values);

std::vector<std::string> unused_lines() const;
private:
std::string version;
std::vector<std::string> nodes;
Expand All @@ -44,6 +45,8 @@ class DbcParser : public Parser {
std::regex value_re;
std::regex signal_re;

std::vector<std::string> missed_lines;

void parse_dbc_header(std::istream& file_stream);
void parse_dbc_nodes(std::istream& file_stream);
void parse_dbc_messages(const std::vector<std::string>& lines);
Expand Down
8 changes: 8 additions & 0 deletions src/dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ void DbcParser::parse_dbc_messages(const std::vector<std::string>& lines) {
signal_value.push_back(val);
continue;
}

if (line.length() > 0) {
missed_lines.push_back(line);
}
}

for (const auto& signal : signal_value) {
Expand All @@ -236,4 +240,8 @@ void DbcParser::parse_dbc_messages(const std::vector<std::string>& lines) {
}
}

std::vector<std::string> DbcParser::unused_lines() const {
return missed_lines;
}

}
39 changes: 38 additions & 1 deletion test/test_dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ NS_ :
BO_ 293 Msg1: 2 Vector__XXX
SG_ Wert7 : 0|16@1- (1,0) [0|0] "" Vector__XXX
BO_ 292 Msg2: 8 Vector__XXX
BO_ 292 Msg2: 1 Vector__XXX
SG_ Wert8 : 56|8@1- (1,0) [0|0] "" Vector__XXX
)";
const auto filename = create_temporary_dbc_with(contents.c_str());
Expand All @@ -272,3 +272,40 @@ BO_ 292 Msg2: 8 Vector__XXX
REQUIRE(parser.get_messages().at(0).name() == "Msg1");
REQUIRE(parser.get_messages().at(1).name() == "Msg2");
}

TEST_CASE("Should report unused lines since we don't have tracing.", "[parsing]") {
std::string contents = R"(VERSION ""
NS_ :
BS_:
BU_:
BO_ 293 Msg1: 2 Vector__XXX
SG_ Whitespace: | 0|16@1- (1,0) [0|0] "" Vector__XXX
SG_ Wert7 : 0|16@1- (1,0) [0|0] "" Vector__XXX
SG_ Wert8 : 0|16@1- (1,0) [0|0] "" Vector__XXX
BO_ 292 Msg2: 1 Vector__XXX
SG_ Wert8 : 56|8@1- (1,0) [0|0] "" Vector__XXX
SB_ not a correct line
BO_ have a issue here:
)";

const auto filename = create_temporary_dbc_with(contents.c_str());

auto parser = Libdbc::DbcParser();
REQUIRE_NOTHROW(parser.parse_file(filename.c_str()));

REQUIRE(parser.get_messages().size() == 2);
REQUIRE(parser.get_messages()[0].size() == 2);
REQUIRE(parser.get_messages()[1].size() == 1);

auto unused = parser.unused_lines();

// We could match them all here but i think just a check that the size is sufficent.
REQUIRE(unused.size() == 3);
}

0 comments on commit be9f576

Please sign in to comment.