Skip to content

Commit 4366b4e

Browse files
committed
add test
1 parent 7a378f4 commit 4366b4e

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

gui/resultstree.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ static QString getGuideline(ReportType reportType, const std::map<std::string, s
104104
severity));
105105
}
106106

107-
static QString getClassification(ReportType reportType, const QString& guideline) {
108-
return QString::fromStdString(getClassification(guideline.toStdString(), reportType));
107+
static QString getClassification(ReportType reportType, const QString& errorId, const QString& guideline) {
108+
return QString::fromStdString(getClassification(errorId.toStdString(), guideline.toStdString(), reportType));
109109
}
110110

111111
static Severity getSeverityFromClassification(const QString &c) {
@@ -177,7 +177,7 @@ void ResultsTree::setReportType(ReportType reportType) {
177177
const QString& errorId = childdata[ERRORID].toString();
178178
Severity severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(childdata[SEVERITY]));
179179
const QString& guideline = getGuideline(mReportType, mGuideline, errorId, severity);
180-
const QString& classification = getClassification(mReportType, guideline);
180+
const QString& classification = getClassification(mReportType, errorId, guideline);
181181
fileItem->child(j, COLUMN_CERT_LEVEL)->setText(classification);
182182
fileItem->child(j, COLUMN_CERT_RULE)->setText(guideline);
183183
fileItem->child(j, COLUMN_MISRA_CLASSIFICATION)->setText(classification);
@@ -280,7 +280,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
280280
showItem = mShowSeverities.isShown(item.severity);
281281
else {
282282
const QString& guideline = getGuideline(mReportType, mGuideline, item.errorId, item.severity);
283-
const QString& classification = getClassification(mReportType, guideline);
283+
const QString& classification = getClassification(mReportType, item.errorId, guideline);
284284
showItem = !classification.isEmpty() && mShowSeverities.isShown(getSeverityFromClassification(classification));
285285
}
286286
}
@@ -403,7 +403,7 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent,
403403

404404
QMap<int, QStandardItem*> columns;
405405
const QString guideline = getGuideline(mReportType, mGuideline, item.errorId, item.severity);
406-
const QString classification = getClassification(mReportType, guideline);
406+
const QString classification = getClassification(mReportType, item.errorId, guideline);
407407
columns[COLUMN_CERT_LEVEL] = createNormalItem(classification);
408408
columns[COLUMN_CERT_RULE] = createNormalItem(guideline);
409409
columns[COLUMN_CWE] = createNormalItem(QString::number(item.cwe));

test/testerrorlogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TestErrorLogger : public TestFixture {
7878
TEST_CASE(isCriticalErrorId);
7979

8080
TEST_CASE(ErrorMessageReportTypeMisraC);
81+
TEST_CASE(ErrorMessageReportTypeMisraCDirective);
8182
TEST_CASE(ErrorMessageReportTypeCertC);
8283
}
8384

@@ -328,6 +329,19 @@ class TestErrorLogger : public TestFixture {
328329
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
329330
}
330331

332+
void ErrorMessageReportTypeMisraCDirective() const {
333+
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
334+
const auto reportType = ReportType::misraC;
335+
const auto mapping = createGuidelineMapping(reportType);
336+
const std::string format = "{severity} {id}";
337+
ErrorMessage msg(std::move(locs), emptyString, Severity::style, "", "premium-misra-c-2012-dir-4.6", Certainty::normal);
338+
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
339+
msg.classification = getClassification(msg.id, msg.guideline, reportType);
340+
ASSERT_EQUALS("Advisory", msg.classification);
341+
ASSERT_EQUALS("4.6", msg.guideline);
342+
ASSERT_EQUALS("Advisory 4.6", msg.toString(true, format, ""));
343+
}
344+
331345
void ErrorMessageReportTypeCertC() const {
332346
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
333347
const auto reportType = ReportType::certC;

0 commit comments

Comments
 (0)