Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jun 30, 2024
1 parent a75ae44 commit 12519a0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gui/erroritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ErrorItem {
QList<QErrorPathItem> errorPath;
QString symbolNames;
QString remark;
QString classification; // misra/cert/etc: classification/level
QString guideline; // misra/cert/etc: guideline/rule

// Special GUI properties
QString sinceDate;
Expand Down
2 changes: 2 additions & 0 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,8 @@ void ResultsTree::readErrorItem(const QStandardItem *error, ErrorItem *item) con
item->sinceDate = data[SINCEDATE].toString();
item->tags = data[TAGS].toString();
item->remark = data[REMARK].toString();
item->classification = error->parent()->child(error->row(), COLUMN_MISRA_CLASSIFICATION)->text();
item->guideline = error->parent()->child(error->row(), COLUMN_MISRA_GUIDELINE)->text();

if (error->rowCount() == 0) {
QErrorPathItem e;
Expand Down
52 changes: 52 additions & 0 deletions gui/test/resultstree/testresultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@

#include <QtTest>

class TestReport: public Report {
public:
TestReport(QString format) : Report(QString()), format(format) {}
void writeHeader() override { output.clear(); }
void writeFooter() override {}
void writeError(const ErrorItem &error) override {
QString line = format;
line.replace("{id}", error.errorId);
line.replace("{classification}", error.classification);
line.replace("{guideline}", error.guideline);
output += (output.isEmpty() ? "" : "\n") + line;
}
QString format;
QString output;
};

// Mock GUI...
ProjectFile *ProjectFile::mActiveProject;
void ProjectFile::addSuppression(const SuppressionList::Suppression & /*unused*/) {}
Expand Down Expand Up @@ -104,5 +120,41 @@ void TestResultsTree::test1() const
QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item
}

void TestResultsTree::testReportType() 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.updateSettings(false, false, false, false, false);
tree.addErrorItem(createErrorItem(Severity::style, "id1"));
tree.addErrorItem(createErrorItem(Severity::style, "unusedVariable")); // Misra C 2.8
tree.saveResults(&report);
QCOMPARE(report.output, "id1,,\nunusedVariable,,");

// switch to Misra C report and check that "id1" is not shown
tree.setReportType(ReportType::misraC);
tree.saveResults(&report);
QCOMPARE(report.output, "unusedVariable,Advisory,2.8");

// add "missingReturn" and check that it is added properly
tree.addErrorItem(createErrorItem(Severity::warning, "missingReturn")); // Misra C 17.4
tree.saveResults(&report);
QCOMPARE(report.output,
"unusedVariable,Advisory,2.8\n"
"missingReturn,Mandatory,17.4");
}

QTEST_MAIN(TestResultsTree)

1 change: 1 addition & 0 deletions gui/test/resultstree/testresultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class TestResultsTree : public QObject {

private slots:
void test1() const;
void testReportType() const;
};

0 comments on commit 12519a0

Please sign in to comment.