This commit is contained in:
deeaitch committed 2026-10-23 20:53:05 -04:00
1 parent f60faea2e7
commit f03882d3f4
86 files changed
+3539 -2688

No files matched your search

+50 -4
View File
@@ -99,6 +99,8 @@ private Q_SLOTS:
void diagnostics();
void diagnosticErrors();
void diagnosticUnsupportedStatements();
void unsupportedSignalValueTypes_data();
void unsupportedSignalValueTypes();
void diagnosticNamespaceBoundaries();
void diagnosticFormatting();
void multiplexing();
@@ -427,7 +429,7 @@ void DbcParserTest::diagnostics() {
"BU_: ECU\n"
"BO_ 1 Frame: 1 ECU\n"
"SG_ Value : 0|8@1+ (1,0) [0|255] \"\" ECU\n"
"SIG_VALTYPE_ 1 Value : 1;\n"
"SIG_TYPE_REF_ 1 Value : Custom;\n"
"BA_REL_ \"SignalType\" SG_ 1 Value 1;\n"
"VENDOR_EXTENSION_ data;\n");
const DbcParseResult result = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
@@ -564,7 +566,6 @@ void DbcParserTest::diagnosticUnsupportedStatements() {
"BO_ 1 Frame: 1 ECU\nSG_ Value : 0|8@1+ (2,10) [10|520] \"V\" ECU\n"
"CM_ SG_ 1 Value \"Signal comment\";\nVAL_ 1 Value 1 \"On\";\n";
const std::vector<std::string> statements = {
"SIG_VALTYPE_ 1 Value : 1;", "SIG_VALTYPE_ 1 Value : 2;",
"BA_REL_ \"SignalType\" SG_ 1 Value 1;",
"BA_DEF_REL_ BU_SG_REL_ \"Relation\" INT 0 1;",
"BA_REL_ \"Relation\" BU_SG_REL_ ECU SG_ 1 Value 1;",
@@ -602,6 +603,51 @@ void DbcParserTest::diagnosticUnsupportedStatements() {
}
}
void DbcParserTest::unsupportedSignalValueTypes_data() {
QTest::addColumn<std::string>("statement");
QTest::addColumn<bool>("beforeDefinitions");
QTest::newRow("float32") << std::string("SIG_VALTYPE_ 1 Value : 1;") << false;
QTest::newRow("float64") << std::string("SIG_VALTYPE_ 1 Value : 2;") << false;
QTest::newRow("float32-before-definitions") << std::string("SIG_VALTYPE_ 1 Value : 1;") << true;
QTest::newRow("float64-before-definitions") << std::string("SIG_VALTYPE_ 1 Value : 2;") << true;
QTest::newRow("extended-frame") << std::string("SIG_VALTYPE_ 2147483649 Value : 1;") << false;
QTest::newRow("tabs-crlf") << std::string("\tSIG_VALTYPE_\t1\tValue : 2;\r") << false;
QTest::newRow("integer-declaration") << std::string("SIG_VALTYPE_ 1 Value : 0;") << false;
QTest::newRow("unknown-type") << std::string("SIG_VALTYPE_ 1 Value : 3;") << false;
QTest::newRow("malformed") << std::string("SIG_VALTYPE_") << false;
}
void DbcParserTest::unsupportedSignalValueTypes() {
QFETCH(std::string, statement);
QFETCH(bool, beforeDefinitions);
const std::string definitions = "BO_ 1 Frame: 8 ECU\n"
"SG_ Value : 0|64@1+ (1,0) [0|100] \"\" ECU\n";
Fixture fixture;
fixture.Write("VERSION \"\"\nNS_:\n\tSIG_VALTYPE_\nBS_:\nVENDOR_EXTENSION_ data;\n" +
(beforeDefinitions ? statement + "\n" + definitions : definitions + statement));
const std::size_t expectedLine = beforeDefinitions ? 6U : 8U;
const DbcParser parser;
const DbcParseResult result = parser.ParseFileWithDiagnostics(fixture.path.string());
QVERIFY(result.HasErrors());
QVERIFY(result.database.frames.empty());
QCOMPARE(result.diagnostics.size(), std::size_t(2));
QCOMPARE(result.diagnostics[0].severity, DbcDiagnosticSeverity::Warning);
QCOMPARE(result.diagnostics[0].code, DbcDiagnosticCode::UnsupportedStatement);
const DbcDiagnostic &error = result.diagnostics[1];
QCOMPARE(error.severity, DbcDiagnosticSeverity::Error);
QCOMPARE(error.code, DbcDiagnosticCode::UnsupportedSignalType);
QCOMPARE(error.lineNumber, expectedLine);
QCOMPARE(error.filePath, fixture.path.string());
QVERIFY(error.message.find("SIG_VALTYPE_") != std::string::npos);
try {
parser.ParseFile(fixture.path.string());
QFAIL("ParseFile must reject explicit signal value types");
} catch (const std::runtime_error &exception) {
QCOMPARE(std::string(exception.what()), fixture.path.string() + ":" +
std::to_string(expectedLine) + ": " + error.message);
}
}
void DbcParserTest::diagnosticNamespaceBoundaries() {
Fixture fixture;
const std::vector<std::string> endings = {
@@ -609,13 +655,13 @@ void DbcParserTest::diagnosticNamespaceBoundaries() {
"BO_ 1 Frame: 1 ECU\n", "VENDOR_EXTENSION_ data;\n"
};
for (const std::string &ending : endings) {
fixture.Write("NS_ :\n\tSG_MUL_VAL_\n\nBA_\n" + ending + "SIG_VALTYPE_\n");
fixture.Write("NS_ :\n\tSG_MUL_VAL_\n\nBA_\n" + ending + "SIG_TYPE_REF_\n");
const DbcParseResult result = DbcParser().ParseFileWithDiagnostics(fixture.path.string());
CHECK(!result.HasErrors(), ending);
const std::size_t expectedWarnings = ending.find("VENDOR_") == 0U ? 2U : 1U;
QCOMPARE(result.diagnostics.size(), expectedWarnings);
QCOMPARE(result.diagnostics.back().lineNumber, std::size_t(6U));
CHECK(result.diagnostics.back().message.find("SIG_VALTYPE_") != std::string::npos,
CHECK(result.diagnostics.back().message.find("SIG_TYPE_REF_") != std::string::npos,
"Unsupported keyword outside NS_ must produce a warning");
}
for (const std::string &definition : {std::string("BO_"), std::string("SG_")}) {