@@ -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+
137201void TestResultsTree::testReportType () const
138202{
139203 TestReport report (" {id},{classification},{guideline}" );
0 commit comments