This commit is contained in:
deeaitch committed 2026-10-23 20:10:39 -04:00
1 parent c43222939f
commit a258abf7be
7 files changed
+148 -5

No files matched your search

+80
View File
@@ -89,6 +89,8 @@ private:
}
private Q_SLOTS:
void attributes();
void multilineAttributes();
void invalidMultilineAttributes();
void invalidAttributes();
void attributeNumbers();
void invalidAttributeNumbers_data();
@@ -186,6 +188,84 @@ void DbcParserTest::attributes() {
QCOMPARE(std::get<std::int64_t>(*boundaries.attributeDefinitions.at("State").defaultValue), std::int64_t(1));
}
void DbcParserTest::multilineAttributes() {
Fixture fixture;
fixture.Write(R"DBC(BA_
"GenMsgCycleTime" BO_ 1
25;
BA_DEF_ BO_ "VFrameFormat" ENUM
"StandardCAN",
"StandardCAN_FD";
BA_DEF_DEF_
"VFrameFormat"
"StandardCAN_FD";
BA_DEF_ BO_ "GenMsgCycleTime"
INT 0 100;
BA_DEF_DEF_ "GenMsgCycleTime"
50;
BA_DEF_ SG_ "Label" STRING;
BA_ "Label" SG_ 1 Value
"first; \"quoted\"
second\\path";
BA_ "VFrameFormat" BO_ 1
0;
BO_ 1 F: 1 ECU
SG_ Value : 0|8@1+ (1,0) [0|255] "" ECU
BO_ 2 Default: 0 ECU
)DBC");
const DbcParseResult result = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
QVERIFY(!result.HasErrors());
QCOMPARE(result.database.frames.size(), std::size_t(2));
QCOMPARE(result.database.frames[0].cycleTimeMs.value(), 25U);
QCOMPARE(result.database.frames[1].cycleTimeMs.value(), 50U);
QCOMPARE(result.database.frames[0].frameFormat.value(), std::string("StandardCAN"));
QCOMPARE(result.database.frames[1].frameFormat.value(), std::string("StandardCAN_FD"));
QCOMPARE(std::get<std::string>(result.database.frames[0].signals[0].attributes.at("Label")),
std::string("first; \"quoted\"\nsecond\\path"));
QCOMPARE(result.diagnostics.size(), std::size_t(1));
QCOMPARE(result.diagnostics[0].code, DbcDiagnosticCode::UnsupportedAttribute);
QCOMPARE(result.diagnostics[0].lineNumber, std::size_t(7));
fixture.Write("BA_DEF_ BO_ \"VFrameFormat\" ENUM\r\n \"StandardCAN\",\r\n \"ExtendedCAN_FD\";\r\n"
"BA_\r\n \"VFrameFormat\" BO_ 1\r\n 1;\r\nBO_ 1 F: 0 ECU\r\n");
const DbcParseResult explicitFormat = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
QVERIFY(!explicitFormat.HasErrors());
QCOMPARE(explicitFormat.diagnostics.size(), std::size_t(1));
QCOMPARE(explicitFormat.diagnostics[0].code, DbcDiagnosticCode::UnsupportedAttribute);
QCOMPARE(explicitFormat.diagnostics[0].lineNumber, std::size_t(4));
QCOMPARE(explicitFormat.database.frames[0].frameFormat.value(), std::string("ExtendedCAN_FD"));
fixture.Write("BA_DEF_ \"Text\" STRING;\n BA_ \"Text\" \"first \nsecond\";\n"
"UnsupportedStatement\n");
const DbcParseResult whitespace = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
QVERIFY(!whitespace.HasErrors());
QCOMPARE(std::get<std::string>(whitespace.database.attributes.at("Text")), std::string("first \nsecond"));
QCOMPARE(whitespace.diagnostics.size(), std::size_t(1));
QCOMPARE(whitespace.diagnostics[0].code, DbcDiagnosticCode::UnsupportedStatement);
QCOMPARE(whitespace.diagnostics[0].lineNumber, std::size_t(4));
}
void DbcParserTest::invalidMultilineAttributes() {
Fixture fixture;
const std::vector<std::string> invalid = {
"BA_DEF_\n BO_ \"A\" INT\n 10 0;\n",
"BA_DEF_ BO_ \"A\" ENUM\n \"one\",\n;\n",
"BA_DEF_ BO_ \"A\" STRING\n",
"BA_DEF_ BO_ \"A\" ENUM\n \"unterminated;\n",
"BA_DEF_DEF_\n \"Unknown\"\n 0;\n",
"BA_\n \"Unknown\" BO_ 1\n 0;\n",
"BA_DEF_ BO_ \"A\" STRING\n ; trailing\n"};
for (const std::string &statement: invalid) {
fixture.Write("BO_ 1 F: 0 ECU\n" + statement);
const DbcParseResult result = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
QVERIFY2(result.HasErrors(), statement.c_str());
QVERIFY(result.database.frames.empty());
QCOMPARE(result.diagnostics.back().code, DbcDiagnosticCode::InvalidAttribute);
QCOMPARE(result.diagnostics.back().lineNumber, std::size_t(2));
QVERIFY_THROWS_EXCEPTION(std::runtime_error, DbcParser().ParseFile(fixture.path.string()));
}
}
void DbcParserTest::invalidAttributes() {
Fixture fixture;
const std::vector<std::string> invalid = {