Skip to content

Commit fa6e2cd

Browse files
committed
minimized reproducer
1 parent 8d5aca1 commit fa6e2cd

3 files changed

Lines changed: 20 additions & 247 deletions

File tree

gui/test/resultstree/CMakeLists.txt

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,11 @@
11
qt_wrap_cpp(test-resultstree_SRC
22
testresultstree.h
3-
${CMAKE_SOURCE_DIR}/gui/resultstree.h
4-
${CMAKE_SOURCE_DIR}/gui/applicationlist.h
5-
${CMAKE_SOURCE_DIR}/gui/projectfile.h
6-
${CMAKE_SOURCE_DIR}/gui/threadhandler.h
7-
${CMAKE_SOURCE_DIR}/gui/threadresult.h
83
)
9-
if(USE_BUNDLED_TINYXML2)
10-
list(APPEND test-resultstree_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
11-
endif()
12-
list(APPEND test-resultstree_SRC $<TARGET_OBJECTS:simplecpp_objs> $<TARGET_OBJECTS:cppcheck-core>)
13-
add_custom_target(build-resultstree-deps SOURCES ${test-resultstree_SRC})
14-
add_dependencies(gui-build-deps build-resultstree-deps)
154
add_executable(test-resultstree
165
${test-resultstree_SRC}
176
testresultstree.cpp
18-
${CMAKE_SOURCE_DIR}/gui/resultstree.cpp
19-
${CMAKE_SOURCE_DIR}/gui/erroritem.cpp
20-
${CMAKE_SOURCE_DIR}/gui/showtypes.cpp
21-
${CMAKE_SOURCE_DIR}/gui/report.cpp
22-
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
237
)
24-
target_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
25-
target_externals_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/externals/simplecpp)
26-
if(USE_BUNDLED_TINYXML2)
27-
target_externals_include_directories(test-resultstree PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
28-
else()
29-
target_include_directories(test-resultstree SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
30-
endif()
31-
if (HAVE_RULES)
32-
target_link_libraries(test-resultstree ${PCRE_LIBRARY})
33-
target_include_directories(test-resultstree SYSTEM PRIVATE ${PCRE_INCLUDE})
34-
endif()
35-
target_compile_definitions(test-resultstree PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
368
target_link_libraries(test-resultstree ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})
37-
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
38-
target_link_libraries(test-resultstree ${tinyxml2_LIBRARIES})
39-
endif()
40-
41-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
42-
if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0")
43-
# caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638
44-
target_compile_options_safe(test-resultstree -Wno-ctad-maybe-unsupported)
45-
endif()
46-
# caused by mocs
47-
target_compile_options_safe(test-resultstree -Wno-missing-noreturn)
48-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
49-
# caused by mocs
50-
target_compile_options_safe(test-resultstree -Wno-useless-cast)
51-
endif()
529

5310
if (REGISTER_GUI_TESTS)
5411
add_test(NAME test-resultstree COMMAND $<TARGET_FILE:test-resultstree> -platform offscreen)
Lines changed: 20 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -1,198 +1,34 @@
1-
/*
2-
* Cppcheck - A tool for static C/C++ code analysis
3-
* Copyright (C) 2007-2021 Cppcheck team.
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
191
#include "testresultstree.h"
202

21-
#include "resultstree.h"
22-
23-
// headers that declare mocked functions/variables
24-
#include "applicationlist.h"
25-
#include "common.h"
26-
#include "projectfile.h"
27-
#include "threadhandler.h"
28-
#include "threadresult.h"
29-
30-
#include "application.h"
31-
#include "checkers.h"
32-
#include "erroritem.h"
33-
#include "errorlogger.h"
34-
#include "errortypes.h"
35-
#include "report.h"
36-
#include "showtypes.h"
37-
#include "suppressions.h"
38-
#include "xmlreport.h"
3+
#include <iostream>
394

40-
#include <cstddef>
41-
#include <string>
42-
#include <utility>
43-
44-
#include <QList>
45-
#include <QModelIndex>
46-
#include <QString>
5+
#include <QStandardItemModel>
476
#include <QtTest>
487

49-
class TestReport : public Report {
8+
class QCustomItem : public QStandardItem
9+
{
5010
public:
51-
explicit TestReport(QString format) : Report(QString()), format(std::move(format)) {}
52-
void writeHeader() override {
53-
output.clear();
11+
explicit QCustomItem(QString str)
12+
: mStr(std::move(str))
13+
{}
14+
~QCustomItem() override {
15+
std::cout << "~QCustomItem(" << mStr.toStdString() << ")" << std::endl;
5416
}
55-
void writeFooter() override {}
56-
void writeError(const ErrorItem &error) override {
57-
QString line = format;
58-
line.replace("{id}", error.errorId);
59-
line.replace("{classification}", error.classification);
60-
line.replace("{guideline}", error.guideline);
61-
output += (output.isEmpty() ? "" : "\n") + line;
62-
}
63-
QString format;
64-
QString output;
17+
private:
18+
QString mStr;
6519
};
6620

67-
// Mock GUI...
68-
ProjectFile::ProjectFile(QObject *parent) : QObject(parent) {}
69-
ProjectFile *ProjectFile::mActiveProject;
70-
void ProjectFile::addSuppression(const SuppressionList::Suppression & /*unused*/) {}
71-
QString ProjectFile::getWarningTags(std::size_t /*unused*/) const {
72-
return QString();
73-
}
74-
void ProjectFile::setWarningTags(std::size_t /*unused*/, const QString& /*unused*/) {}
75-
bool ProjectFile::write(const QString & /*unused*/) {
76-
return true;
77-
}
78-
ApplicationList::ApplicationList(QObject *parent) : QObject(parent) {}
79-
ApplicationList::~ApplicationList() = default;
80-
int ApplicationList::getApplicationCount() const {
81-
return 0;
82-
}
83-
ThreadHandler::ThreadHandler(QObject *parent) : QObject(parent) {}
84-
ThreadHandler::~ThreadHandler() = default;
85-
bool ThreadHandler::isChecking() const {
86-
return false;
87-
}
88-
void ThreadHandler::stop() {
89-
throw 1;
90-
}
91-
void ThreadHandler::threadDone() {
92-
throw 1;
93-
}
94-
Application& ApplicationList::getApplication(const int /*unused*/) {
95-
throw 1;
96-
}
97-
const Application& ApplicationList::getApplication(const int index) const {
98-
return mApplications.at(index);
99-
}
100-
QString getPath(const QString &type) {
101-
return "/" + type;
102-
}
103-
void setPath(const QString & /*unused*/, const QString & /*unused*/) {}
104-
QString XmlReport::quoteMessage(const QString &message) {
105-
return message;
106-
}
107-
QString XmlReport::unquoteMessage(const QString &message) {
108-
return message;
109-
}
110-
XmlReport::XmlReport(const QString& filename) : Report(filename) {}
111-
void ThreadResult::fileChecked(const QString & /*unused*/) {
112-
throw 1;
113-
}
114-
void ThreadResult::reportOut(const std::string & /*unused*/, Color /*unused*/) {
115-
throw 1;
116-
}
117-
void ThreadResult::reportErr(const ErrorMessage & /*unused*/) {
118-
throw 1;
119-
}
120-
121-
// Test...
122-
12321
void TestResultsTree::test1() const
12422
{
125-
// #12772 : GUI: information messages are shown even though information tool button is deselected
126-
ResultsTree tree(nullptr);
127-
tree.showResults(ShowTypes::ShowType::ShowInformation, false);
128-
ErrorItem errorItem;
129-
errorItem.errorPath << QErrorPathItem();
130-
errorItem.severity = Severity::information;
131-
tree.addErrorItem(errorItem);
132-
QCOMPARE(tree.isRowHidden(0,QModelIndex()), true); // Added item is hidden
133-
tree.showResults(ShowTypes::ShowType::ShowInformation, true);
134-
QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item
135-
}
136-
137-
void TestResultsTree::testReportType() const
138-
{
139-
TestReport report("{id},{classification},{guideline}");
140-
141-
int msgCount = 0;
142-
auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem {
143-
++msgCount;
144-
ErrorItem errorItem;
145-
errorItem.errorPath << QErrorPathItem(ErrorMessage::FileLocation("file1.c", msgCount, 1));
146-
errorItem.severity = severity;
147-
errorItem.errorId = errorId;
148-
errorItem.summary = "test summary " + QString::number(msgCount);
149-
return errorItem;
150-
};
151-
152-
// normal report with 2 errors
153-
ResultsTree tree(nullptr);
154-
tree.updateSettings(false, false, false, false, false);
155-
tree.addErrorItem(createErrorItem(Severity::style, "id1"));
156-
tree.addErrorItem(createErrorItem(Severity::style, "unusedVariable")); // Misra C 2.8
157-
tree.saveResults(&report);
158-
QCOMPARE(report.output, "id1,,\nunusedVariable,,");
159-
160-
// switch to Misra C report and check that "id1" is not shown
161-
tree.setReportType(ReportType::misraC2012);
162-
tree.saveResults(&report);
163-
QCOMPARE(report.output, "unusedVariable,Advisory,2.8");
164-
165-
// add "missingReturn" and check that it is added properly
166-
tree.addErrorItem(createErrorItem(Severity::warning, "missingReturn")); // Misra C 17.4
167-
tree.saveResults(&report);
168-
QCOMPARE(report.output,
169-
"unusedVariable,Advisory,2.8\n"
170-
"missingReturn,Mandatory,17.4");
171-
}
172-
173-
174-
void TestResultsTree::testGetGuidelineError() const
175-
{
176-
TestReport report("{id},{classification},{guideline}");
177-
178-
int msgCount = 0;
179-
auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem {
180-
++msgCount;
181-
ErrorItem errorItem;
182-
errorItem.errorPath << QErrorPathItem(ErrorMessage::FileLocation("file1.c", msgCount, 1));
183-
errorItem.severity = severity;
184-
errorItem.errorId = errorId;
185-
errorItem.summary = "test summary " + QString::number(msgCount);
186-
return errorItem;
187-
};
188-
189-
// normal report with 2 errors
190-
ResultsTree tree(nullptr);
191-
tree.setReportType(ReportType::misraC2012);
192-
tree.addErrorItem(createErrorItem(Severity::error, "id1")); // error severity => guideline 1.3
193-
tree.saveResults(&report);
194-
QCOMPARE(report.output, "id1,Required,1.3");
23+
auto* model = new QStandardItemModel;
24+
auto *item = new QCustomItem("0");
25+
{
26+
QMap<QString, QVariant> itemdata;
27+
itemdata["file"] = "file1";
28+
item->setData(itemdata);
29+
}
30+
model->appendRow(item);
31+
delete model;
19532
}
19633

19734
QTEST_MAIN(TestResultsTree)
198-
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
/* -*- C++ -*-
2-
* Cppcheck - A tool for static C/C++ code analysis
3-
* Copyright (C) 2007-2021 Cppcheck team.
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
191
#include <QObject>
202

213
class TestResultsTree : public QObject {
224
Q_OBJECT
235

246
private slots:
257
void test1() const;
26-
void testReportType() const;
27-
void testGetGuidelineError() const;
288
};

0 commit comments

Comments
 (0)