diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 2f7dd0de492..e9e6e09181d 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -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) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 731ac9cc1f6..fb22e1520ff 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -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; } diff --git a/gui/test/CMakeLists.txt b/gui/test/CMakeLists.txt index ea868eb97e6..d086e890cb1 100644 --- a/gui/test/CMakeLists.txt +++ b/gui/test/CMakeLists.txt @@ -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 \ No newline at end of file diff --git a/gui/test/resultstree/CMakeLists.txt b/gui/test/resultstree/CMakeLists.txt new file mode 100644 index 00000000000..9c98e8dcf35 --- /dev/null +++ b/gui/test/resultstree/CMakeLists.txt @@ -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 $) +endif() diff --git a/gui/test/resultstree/resultstree.pro b/gui/test/resultstree/resultstree.pro new file mode 100644 index 00000000000..d4677d13eea --- /dev/null +++ b/gui/test/resultstree/resultstree.pro @@ -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 diff --git a/gui/test/resultstree/testresultstree.cpp b/gui/test/resultstree/testresultstree.cpp new file mode 100644 index 00000000000..b8fbb44b36f --- /dev/null +++ b/gui/test/resultstree/testresultstree.cpp @@ -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 . + */ + +#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 + +// 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 ErrorLogger::mCriticalErrorIds; +std::string ErrorMessage::FileLocation::getfile(bool /*unused*/) const { + return std::string(); +} +const char* CppCheck::version() { + return "1.0"; +} +std::pair 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) + diff --git a/gui/test/resultstree/testresultstree.h b/gui/test/resultstree/testresultstree.h new file mode 100644 index 00000000000..acea181ee5b --- /dev/null +++ b/gui/test/resultstree/testresultstree.h @@ -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 . + */ + +#include + +class TestResultsTree : public QObject { + Q_OBJECT + +private slots: + void test1() const; +};