From c43598e62e5e2a596508cd951c26efd55ed9b99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 1 Jul 2024 22:21:26 +0200 Subject: [PATCH] Fixup #12410 (GUI: misra c report, errors/warnings violate 1.3) --- gui/resultstree.cpp | 21 ++++++++++++++------- gui/test/resultstree/testresultstree.cpp | 24 ++++++++++++++++++++++++ gui/test/resultstree/testresultstree.h | 1 + 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index e31388893f1..d8a5ca02f66 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -95,7 +95,7 @@ static constexpr int COLUMN_SINCE_DATE = 10; static constexpr int COLUMN_TAGS = 11; static constexpr int COLUMN_CWE = 12; -static QString getGuideline(ReportType reportType, const QMap& guidelines, const QString& errorId) { +static QString getGuideline(ReportType reportType, const QMap& guidelines, const QString& errorId, Severity severity) { if (reportType == ReportType::autosar) { if (errorId.startsWith("premium-autosar-")) return errorId.mid(16); @@ -107,14 +107,19 @@ static QString getGuideline(ReportType reportType, const QMap& return errorId.mid(13).toUpper(); } if (errorId.startsWith("premium-")) - return getGuideline(reportType, guidelines, errorId.mid(8)); + return getGuideline(reportType, guidelines, errorId.mid(8), severity); if (reportType == ReportType::misraC && (errorId.startsWith("misra-c20") || errorId.startsWith("misra-c-20"))) return errorId.mid(errorId.lastIndexOf("-") + 1); if (reportType == ReportType::misraCpp2008 && errorId.startsWith("misra-cpp-2008-")) return errorId.mid(15); if (reportType == ReportType::misraCpp2023 && errorId.startsWith("misra-cpp-2023-")) return errorId.mid(15); - return guidelines.value(errorId); + const QString& guideline = guidelines.value(errorId); + if (!guideline.isEmpty()) + return guideline; + if (severity == Severity::error || severity == Severity::warning) + return guidelines.value("error"); + return QString(); } static QString getClassification(ReportType reportType, const QString& guideline) { @@ -293,8 +298,10 @@ void ResultsTree::setReportType(ReportType reportType) { if (!fileItem) continue; for (int j = 0; j < fileItem->rowCount(); ++j) { - const QString& errorId = fileItem->child(j, COLUMN_ID)->text(); - const QString& guideline = getGuideline(mReportType, mGuideline, errorId); + const auto& data = fileItem->child(j,0)->data().toMap(); + const QString& errorId = data[ERRORID].toString(); + Severity severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data[SEVERITY])); + const QString& guideline = getGuideline(mReportType, mGuideline, errorId, severity); const QString& classification = getClassification(mReportType, guideline); fileItem->child(j, COLUMN_CERT_LEVEL)->setText(classification); fileItem->child(j, COLUMN_CERT_RULE)->setText(guideline); @@ -397,7 +404,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item) if (mReportType == ReportType::normal) showItem = mShowSeverities.isShown(item.severity); else { - const QString& guideline = getGuideline(mReportType, mGuideline, item.errorId); + const QString& guideline = getGuideline(mReportType, mGuideline, item.errorId, item.severity); const QString& classification = getClassification(mReportType, guideline); showItem = !classification.isEmpty() && mShowSeverities.isShown(getSeverityFromClassification(classification)); } @@ -520,7 +527,7 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent, } QMap columns; - const QString guideline = getGuideline(mReportType, mGuideline, item.errorId); + const QString guideline = getGuideline(mReportType, mGuideline, item.errorId, item.severity); const QString classification = getClassification(mReportType, guideline); columns[COLUMN_CERT_LEVEL] = createNormalItem(classification); columns[COLUMN_CERT_RULE] = createNormalItem(guideline); diff --git a/gui/test/resultstree/testresultstree.cpp b/gui/test/resultstree/testresultstree.cpp index b00b244cd73..0c83d52c6a9 100644 --- a/gui/test/resultstree/testresultstree.cpp +++ b/gui/test/resultstree/testresultstree.cpp @@ -156,5 +156,29 @@ void TestResultsTree::testReportType() const "missingReturn,Mandatory,17.4"); } + +void TestResultsTree::testGetGuidelineError() const +{ + TestReport report("{id},{classification},{guideline}"); + + int msgCount = 0; + auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem { + ++msgCount; + ErrorItem errorItem; + errorItem.errorPath << QErrorPathItem(ErrorMessage::FileLocation("file1.c", msgCount, 1)); + errorItem.severity = severity; + errorItem.errorId = errorId; + errorItem.summary = "test summary " + QString::number(msgCount); + return errorItem; + }; + + // normal report with 2 errors + ResultsTree tree(nullptr); + tree.setReportType(ReportType::misraC); + tree.addErrorItem(createErrorItem(Severity::error, "id1")); // error severity => guideline 1.3 + tree.saveResults(&report); + QCOMPARE(report.output, "id1,Required,1.3"); +} + QTEST_MAIN(TestResultsTree) diff --git a/gui/test/resultstree/testresultstree.h b/gui/test/resultstree/testresultstree.h index ddd68555e06..8f0b4f56df6 100644 --- a/gui/test/resultstree/testresultstree.h +++ b/gui/test/resultstree/testresultstree.h @@ -24,4 +24,5 @@ class TestResultsTree : public QObject { private slots: void test1() const; void testReportType() const; + void testGetGuidelineError() const; };