Skip to content

Commit

Permalink
Fix #12772 (GUI: information messages are shown even though informati…
Browse files Browse the repository at this point in the history
…on tool button is deselected) (#6440)
  • Loading branch information
danmar committed May 25, 2024
1 parent a858a0b commit d8ee51d
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ jobs:
make -j$(nproc)
./test-projectfile
popd
pushd gui/test/resultstree
qmake CONFIG+=debug CONFIG+=ccache
make -j$(nproc)
export QT_QPA_PLATFORM=offscreen
./test-resultstree
popd
pushd gui/test/translationhandler
qmake CONFIG+=debug CONFIG+=ccache
make -j$(nproc)
Expand Down
11 changes: 9 additions & 2 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,16 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
}

// Partially refresh the tree: Unhide file item if necessary
if (!hide) {
setRowHidden(fileItem->row(), QModelIndex(), !mShowSeverities.isShown(item.severity));
setRowHidden(stditem->row(), fileItem->index(), hide || !mShowSeverities.isShown(item.severity));

bool hideFile = true;
for (int i = 0; i < fileItem->rowCount(); ++i) {
if (!isRowHidden(i, fileItem->index())) {
hideFile = false;
}
}
setRowHidden(fileItem->row(), QModelIndex(), hideFile);

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions gui/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_subdirectory(cppchecklibrarydata)
add_subdirectory(filelist)
add_subdirectory(projectfile)
# FIXME does not work in CI
#add_subdirectory(resultstree)
add_subdirectory(translationhandler)
add_subdirectory(xmlreportv2)
# TODO: add all tests to CTest
24 changes: 24 additions & 0 deletions gui/test/resultstree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
qt_wrap_cpp(test-resultstree_SRC testresultstree.h ${CMAKE_SOURCE_DIR}/gui/resultstree.h)
add_custom_target(build-resultstree-deps SOURCES ${test-resultstree_SRC})
add_dependencies(gui-build-deps build-resultstree-deps)
add_executable(test-resultstree
${test-resultstree_SRC}
testresultstree.cpp
${CMAKE_SOURCE_DIR}/gui/resultstree.cpp
${CMAKE_SOURCE_DIR}/gui/erroritem.cpp
${CMAKE_SOURCE_DIR}/gui/showtypes.cpp
${CMAKE_SOURCE_DIR}/gui/report.cpp
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
)
target_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(test-resultstree PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-resultstree ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(test-resultstree -Wno-extra-semi-stmt)
endif()

if (REGISTER_GUI_TESTS)
add_test(NAME test-resultstree COMMAND $<TARGET_FILE:test-resultstree>)
endif()
28 changes: 28 additions & 0 deletions gui/test/resultstree/resultstree.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TEMPLATE = app
TARGET = test-resultstree
DEPENDPATH += .
INCLUDEPATH += . ../../../lib
OBJECTS_DIR = ../../temp
MOC_DIR = ../../temp

QT += widgets core
QT += testlib

include(../common.pri)

DEFINES += SRCDIR=\\\"$$PWD\\\"

# tests
SOURCES += testresultstree.cpp \
../../resultstree.cpp \
../../erroritem.cpp \
../../showtypes.cpp \
../../report.cpp \
../../xmlreportv2.cpp

HEADERS += testresultstree.h \
../../resultstree.h \
../../erroritem.h \
../../showtypes.h \
../../report.h \
../../xmlreportv2.h
108 changes: 108 additions & 0 deletions gui/test/resultstree/testresultstree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2021 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "testresultstree.h"
#include "resultstree.h"

// headers that declare mocked functions/variables
#include "applicationlist.h"
#include "common.h"
#include "threadhandler.h"
#include "projectfile.h"
#include "xmlreportv2.h"

#include "cppcheck.h"
#include "errorlogger.h"
#include "path.h"
#include "settings.h"

#include <QtTest>

// Mock GUI...
ProjectFile *ProjectFile::mActiveProject;
void ProjectFile::addSuppression(const SuppressionList::Suppression & /*unused*/) {}
QString ProjectFile::getWarningTags(std::size_t /*unused*/) const {
return QString();
}
void ProjectFile::setWarningTags(std::size_t /*unused*/, const QString& /*unused*/) {}
bool ProjectFile::write(const QString & /*unused*/) {
return true;
}
std::string severityToString(Severity severity) {
return std::to_string((int)severity);
}
int ApplicationList::getApplicationCount() const {
return 0;
}
bool ThreadHandler::isChecking() const {
return false;
}
Application& ApplicationList::getApplication(const int /*unused*/) {
throw 1;
}
const Application& ApplicationList::getApplication(const int index) const {
return mApplications.at(index);
}
QString getPath(const QString &type) {
return "/" + type;
}
void setPath(const QString & /*unused*/, const QString & /*unused*/) {}
QString XmlReport::quoteMessage(const QString &message) {
return message;
}
QString XmlReport::unquoteMessage(const QString &message) {
return message;
}
XmlReport::XmlReport(const QString& filename) : Report(filename) {}

// Mock LIB...
bool Path::isHeader(std::string const& /*unused*/) {
return false;
}
const std::set<std::string> ErrorLogger::mCriticalErrorIds;
std::string ErrorMessage::FileLocation::getfile(bool /*unused*/) const {
return std::string();
}
const char* CppCheck::version() {
return "1.0";
}
std::pair<std::string, std::string> Settings::getNameAndVersion(const std::string& /*unused*/) {
throw 1;
}
Severity severityFromString(const std::string& severity) {
return (Severity)std::stoi(severity);
}

// Test...

void TestResultsTree::test1() const
{
// #12772 : GUI: information messages are shown even though information tool button is deselected
ResultsTree tree(nullptr);
tree.showResults(ShowTypes::ShowType::ShowInformation, false);
ErrorItem errorItem;
errorItem.errorPath << QErrorPathItem();
errorItem.severity = Severity::information;
tree.addErrorItem(errorItem);
QCOMPARE(tree.isRowHidden(0,QModelIndex()), true); // Added item is hidden
tree.showResults(ShowTypes::ShowType::ShowInformation, true);
QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item
}

QTEST_MAIN(TestResultsTree)

26 changes: 26 additions & 0 deletions gui/test/resultstree/testresultstree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2021 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QObject>

class TestResultsTree : public QObject {
Q_OBJECT

private slots:
void test1() const;
};

0 comments on commit d8ee51d

Please sign in to comment.