This commit is contained in:
deeaitch committed 2026-10-07 18:50:11 -04:00
1 parent a0938cb29c
commit 3dd9230fca
21 files changed
+491 -450

No files matched your search

+28 -21
View File
@@ -49,7 +49,7 @@ void DbcDecoderTest::decode_data() {
{"Intel signed regression", ByteOrder::Intel, 0U, 16U, ValueType::Signed, {0xFE, 0xFF}, true, -2, 0.5, 10.0, 9.0},
{"Intel short payload", ByteOrder::Intel, 0U, 16U, ValueType::Unsigned, {0x12}, false, 0, 1.0, 0.0, 0.0}};
for (const auto &test: cases)
for (const DecodeCase &test: cases)
QTest::newRow(test.name) << test;
}
@@ -76,19 +76,25 @@ void DbcDecoderTest::decode() {
frame.canId = definition.canId;
frame.data = test.data;
const DecodedFrameValue result = DbcDecoder().Decode(database, frame);
const bool passed = result.valid &&
(result.definition == &database.frames[0]) &&
(result.signals.size() == 1U) &&
(result.signals[0].definition == &database.frames[0].signals[0]) &&
(result.signals[0].valid == test.valid) &&
(!test.valid || (((test.valueType == ValueType::Signed)
? (std::get_if<std::int64_t>(&result.signals[0].rawValue) &&
std::get<std::int64_t>(result.signals[0].rawValue) == test.rawValue)
: (std::get_if<std::uint64_t>(&result.signals[0].rawValue) &&
std::get<std::uint64_t>(result.signals[0].rawValue) ==
static_cast<std::uint64_t>(test.rawValue))) &&
(result.signals[0].physicalValue == test.physicalValue)));
QVERIFY2(passed, test.name);
QVERIFY2(result.valid, test.name);
QCOMPARE(result.definition, &database.frames[0]);
QCOMPARE(result.signals.size(), std::size_t(1U));
const DecodedSignalValue &decoded = result.signals[0];
QCOMPARE(decoded.definition, &database.frames[0].signals[0]);
QCOMPARE(decoded.valid, test.valid);
if (!test.valid)
return;
if (test.valueType == ValueType::Signed) {
const std::int64_t *raw = std::get_if<std::int64_t>(&decoded.rawValue);
QVERIFY(raw != nullptr);
QCOMPARE(*raw, test.rawValue);
} else {
const std::uint64_t *raw = std::get_if<std::uint64_t>(&decoded.rawValue);
QVERIFY(raw != nullptr);
QCOMPARE(*raw, static_cast<std::uint64_t>(test.rawValue));
}
QCOMPARE(decoded.physicalValue, test.physicalValue);
}
void DbcDecoderTest::boundaries() {
@@ -115,13 +121,13 @@ void DbcDecoderTest::boundaries() {
const unsigned shift = (order == ByteOrder::Intel ? byte : 7U - byte) * 8U;
frame.data.push_back(static_cast<std::uint8_t>(bits >> shift));
}
const auto result = DbcDecoder().Decode(database, frame);
const DecodedFrameValue result = DbcDecoder().Decode(database, frame);
const std::int64_t signedExpected = bits <= 0x7FFFFFFFFFFFFFFFULL
? static_cast<std::int64_t>(bits)
: std::numeric_limits<std::int64_t>::min() +
static_cast<std::int64_t>(bits - 0x8000000000000000ULL);
const auto &decoded = result.signals.at(0U);
const auto expected = type == ValueType::Unsigned
const DecodedSignalValue &decoded = result.signals.at(0U);
const RawSignalValue expected = type == ValueType::Unsigned
? std::variant<std::int64_t, std::uint64_t>(bits)
: std::variant<std::int64_t, std::uint64_t>(signedExpected);
const double physical = (type == ValueType::Unsigned
@@ -131,7 +137,7 @@ void DbcDecoderTest::boundaries() {
10.0;
std::ostringstream actualText;
std::ostringstream expectedText;
if (const auto *signedValue = std::get_if<std::int64_t>(&decoded.rawValue))
if (const std::int64_t *signedValue = std::get_if<std::int64_t>(&decoded.rawValue))
actualText << *signedValue;
else
actualText << std::get<std::uint64_t>(decoded.rawValue);
@@ -139,9 +145,10 @@ void DbcDecoderTest::boundaries() {
expectedText << bits;
else
expectedText << signedExpected;
QVERIFY2(decoded.valid && decoded.rawValue == expected &&
decoded.physicalValue == physical && actualText.str() == expectedText.str(),
expectedText.str().c_str());
QVERIFY(decoded.valid);
QVERIFY(decoded.rawValue == expected);
QCOMPARE(decoded.physicalValue, physical);
QCOMPARE(actualText.str(), expectedText.str());
}
}
}