Skip to content

Commit 4544aec

Browse files
committed
add tests
1 parent 20298d2 commit 4544aec

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎gui/test/resultstree/testresultstree.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,31 @@ void TestResultsTree::resultsInSameFile() const
265265
}
266266
}
267267

268+
void TestResultsTree::clearRecheckFile() const
269+
{
270+
// #14893 - rechecking a file removes its results, the results of the other files are kept
271+
ResultsTree tree(nullptr);
272+
QVERIFY(tree.addErrorItem(createErrorItem("file1.c", 10, Severity::style, "test", "bugId")));
273+
QVERIFY(tree.addErrorItem(createErrorItem("file1.c", 20, Severity::style, "test", "bugId")));
274+
QVERIFY(tree.addErrorItem(createErrorItem("file2.c", 10, Severity::style, "test", "bugId")));
275+
276+
const auto* model = dynamic_cast<QStandardItemModel*>(tree.model());
277+
QVERIFY(model != nullptr);
278+
QCOMPARE(model->rowCount(), 2);
279+
280+
tree.clearRecheckFile("file1.c");
281+
QCOMPARE(model->rowCount(), 1);
282+
QCOMPARE(model->item(0,0)->text(), "file2.c");
283+
284+
// the recheck reports the results of the rechecked file again, they must not be treated as duplicates
285+
QVERIFY(tree.addErrorItem(createErrorItem("file1.c", 10, Severity::style, "test", "bugId")));
286+
QVERIFY(tree.addErrorItem(createErrorItem("file1.c", 20, Severity::style, "test", "bugId")));
287+
QCOMPARE(model->rowCount(), 2);
288+
289+
// the results of the other files are still known
290+
QVERIFY(!tree.addErrorItem(createErrorItem("file2.c", 10, Severity::style, "test", "bugId")));
291+
}
292+
268293
void TestResultsTree::testReportType() const
269294
{
270295
TestReport report("{id},{classification},{guideline}");

‎gui/test/resultstree/testresultstree.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private slots:
2626
void duplicateResults() const;
2727
void multiLineResult() const;
2828
void resultsInSameFile() const;
29+
void clearRecheckFile() const;
2930
void testReportType() const;
3031
void testReportTypeIcon() const;
3132
void testGetGuidelineError() const;

‎test/testanalyzerinformation.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,41 @@ class TestAnalyzerInformation : public TestFixture {
5353
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f, "file1.c", "", 0));
5454
f.str(filesTxt);
5555
ASSERT_EQUALS("file1.a4", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f, "./file1.c", "", 0));
56+
57+
// an exact match wins over a suffix match - "executor.cpp" is a suffix of
58+
// "processexecutor.cpp" so both used to resolve to the same analyzer info file
59+
{
60+
constexpr char suffixTxt[] = "executor.a1:::executor.cpp\n"
61+
"processexecutor.a2:::processexecutor.cpp\n";
62+
std::istringstream f1(suffixTxt);
63+
ASSERT_EQUALS("executor.a1", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f1, "executor.cpp", "", 0));
64+
std::istringstream f2(suffixTxt);
65+
ASSERT_EQUALS("processexecutor.a2", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f2, "processexecutor.cpp", "", 0));
66+
}
67+
68+
// the same, with the exact match on the first line
69+
{
70+
constexpr char suffixTxt[] = "processexecutor.a1:::processexecutor.cpp\n"
71+
"executor.a2:::executor.cpp\n";
72+
std::istringstream f1(suffixTxt);
73+
ASSERT_EQUALS("processexecutor.a1", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f1, "processexecutor.cpp", "", 0));
74+
std::istringstream f2(suffixTxt);
75+
ASSERT_EQUALS("executor.a2", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f2, "executor.cpp", "", 0));
76+
}
77+
78+
// a suffix match is still used when there is no exact match
79+
{
80+
constexpr char relTxt[] = "a.a1:::src/a.c\n";
81+
std::istringstream f1(relTxt);
82+
ASSERT_EQUALS("a.a1", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f1, "/home/proj/src/a.c", "", 0));
83+
}
84+
85+
// no match at all
86+
{
87+
constexpr char noneTxt[] = "a.a1:::a.c\n";
88+
std::istringstream f1(noneTxt);
89+
ASSERT_EQUALS("", AnalyzerInformationTest::getAnalyzerInfoFileFromFilesTxt(f1, "b.c", "", 0));
90+
}
5691
}
5792

5893
void getAnalyzerInfoFile() const {

0 commit comments

Comments
 (0)