Skip to content

Commit f6601c5

Browse files
committed
test
1 parent b6137f6 commit f6601c5

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

gui/resultitem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#ifndef RESULTITEM_H
2020
#define RESULTITEM_H
2121

22-
#include <QStandardItem>
2322
#include "erroritem.h"
23+
#include <QStandardItem>
2424
#include <QSharedPointer>
2525

2626
class ResultItem : public QStandardItem
2727
{
2828
public:
29-
enum class Type {file, message, note};
29+
enum class Type: std::uint8_t {file, message, note};
3030

3131
ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex);
3232
QSharedPointer<ErrorItem> errorItem;

gui/test/resultstree/testresultstree.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,70 @@ void TestResultsTree::test1() const
134134
QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item
135135
}
136136

137+
static QErrorPathItem createErrorPathItem(QString file, int line, int column, QString info) {
138+
QErrorPathItem ret;
139+
ret.file = file;
140+
ret.line = line;
141+
ret.column = column;
142+
ret.info = info;
143+
return ret;
144+
}
145+
146+
static ErrorItem createErrorItem(QString file, int line, Severity sev, QString message, QString id) {
147+
ErrorItem ret;
148+
ret.errorId = id;
149+
ret.severity = sev;
150+
ret.cwe = ret.hash = 0;
151+
ret.file0 = file;
152+
ret.inconclusive = false;
153+
ret.message = ret.summary = message;
154+
ret.errorPath << createErrorPathItem(file, line, 1, message);
155+
return ret;
156+
}
157+
158+
void TestResultsTree::resultsInSameFile() const
159+
{
160+
ResultsTree tree(nullptr);
161+
tree.addErrorItem(createErrorItem("file1.c", 10, Severity::style, "test", "bugId"));
162+
tree.addErrorItem(createErrorItem("file1.c", 20, Severity::style, "test", "bugId"));
163+
QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(tree.model());
164+
QVERIFY(model != nullptr);
165+
QVERIFY(model->rowCount() == 1);
166+
167+
const ResultItem* fileItem = dynamic_cast<ResultItem*>(model->item(0,0));
168+
QVERIFY(fileItem != nullptr);
169+
QCOMPARE(fileItem->getType(), ResultItem::Type::file);
170+
QCOMPARE(fileItem->text(), "file1.c");
171+
QCOMPARE(fileItem->getErrorPathItem().file, "file1.c");
172+
QVERIFY(fileItem->rowCount() == 2);
173+
174+
const ResultItem* res1 = dynamic_cast<ResultItem*>(fileItem->child(0,0));
175+
QVERIFY(res1 != nullptr);
176+
QCOMPARE(res1->text(), "file1.c");
177+
QVERIFY(res1->errorItem != nullptr);
178+
QCOMPARE(res1->errorItem->toString(), "file1.c:10:1:style: test [bugId]");
179+
QVERIFY(res1->rowCount() == 0);
180+
for (int col = 0; col < fileItem->columnCount(); ++col) {
181+
const ResultItem* item = dynamic_cast<ResultItem*>(fileItem->child(0,col));
182+
QVERIFY(item);
183+
QCOMPARE(item->errorItem.get(), res1->errorItem.get());
184+
QCOMPARE(item->getType(), ResultItem::Type::message);
185+
}
186+
187+
const ResultItem* res2 = dynamic_cast<ResultItem*>(fileItem->child(1,0));
188+
QVERIFY(res2 != nullptr);
189+
QCOMPARE(res2->text(), "file1.c");
190+
QVERIFY(res2->errorItem != nullptr);
191+
QCOMPARE(res2->errorItem->toString(), "file1.c:20:1:style: test [bugId]");
192+
QVERIFY(res2->rowCount() == 0);
193+
for (int col = 0; col < fileItem->columnCount(); ++col) {
194+
const ResultItem* item = dynamic_cast<ResultItem*>(fileItem->child(1,col));
195+
QVERIFY(item);
196+
QCOMPARE(item->errorItem.get(), res2->errorItem.get());
197+
QCOMPARE(item->getType(), ResultItem::Type::message);
198+
}
199+
}
200+
137201
void TestResultsTree::testReportType() const
138202
{
139203
TestReport report("{id},{classification},{guideline}");

gui/test/resultstree/testresultstree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TestResultsTree : public QObject {
2323

2424
private slots:
2525
void test1() const;
26+
void resultsInSameFile() const;
2627
void testReportType() const;
2728
void testGetGuidelineError() const;
2829
};

0 commit comments

Comments
 (0)