diff --git a/gui/test/CMakeLists.txt b/gui/test/CMakeLists.txt index b2e63c08f86..eebb883e3f3 100644 --- a/gui/test/CMakeLists.txt +++ b/gui/test/CMakeLists.txt @@ -1,8 +1,12 @@ add_custom_target(gui-tests) +add_subdirectory(codeeditorstyle) add_subdirectory(cppchecklibrarydata) +add_subdirectory(erroritem) add_subdirectory(filelist) +add_subdirectory(platforms) add_subdirectory(projectfile) add_subdirectory(resultstree) +add_subdirectory(showtypes) add_subdirectory(translationhandler) add_subdirectory(xmlreportv2) \ No newline at end of file diff --git a/gui/test/codeeditorstyle/CMakeLists.txt b/gui/test/codeeditorstyle/CMakeLists.txt new file mode 100644 index 00000000000..43204782d19 --- /dev/null +++ b/gui/test/codeeditorstyle/CMakeLists.txt @@ -0,0 +1,23 @@ +qt_wrap_cpp(test-codeeditorstyle_SRC testcodeeditorstyle.h) +add_custom_target(build-testcodeeditorstyle-deps SOURCES ${test-codeeditorstyle_SRC}) +add_dependencies(gui-build-deps build-testcodeeditorstyle-deps) +add_executable(test-codeeditorstyle + ${test-codeeditorstyle_SRC} + testcodeeditorstyle.cpp + ${CMAKE_SOURCE_DIR}/gui/codeeditorstyle.cpp + ) +target_include_directories(test-codeeditorstyle PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-codeeditorstyle ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_TEST_LIB}) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0") + # caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638 + target_compile_options_safe(test-codeeditorstyle -Wno-ctad-maybe-unsupported) + endif() +endif() + +if (REGISTER_GUI_TESTS) + add_test(NAME test-codeeditorstyle COMMAND $ -platform offscreen) +endif() + +add_dependencies(gui-tests test-codeeditorstyle) diff --git a/gui/test/codeeditorstyle/testcodeeditorstyle.cpp b/gui/test/codeeditorstyle/testcodeeditorstyle.cpp new file mode 100644 index 00000000000..a4afba24cdc --- /dev/null +++ b/gui/test/codeeditorstyle/testcodeeditorstyle.cpp @@ -0,0 +1,103 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 "testcodeeditorstyle.h" + +#include "codeeditorstyle.h" + +#include +#include +#include + +QTEST_MAIN(TestCodeEditorStyle) + +void TestCodeEditorStyle::defaultStyles_notEqual() const +{ + QVERIFY(defaultStyleLight != defaultStyleDark); +} + +void TestCodeEditorStyle::equality_sameStyle() const +{ + QVERIFY(defaultStyleLight == defaultStyleLight); + QVERIFY(defaultStyleDark == defaultStyleDark); +} + +void TestCodeEditorStyle::equality_differentColor() const +{ + CodeEditorStyle style(defaultStyleLight); + style.widgetFGColor = QColor(1, 2, 3); + QVERIFY(style != defaultStyleLight); +} + +void TestCodeEditorStyle::getSystemTheme_isSystemTheme() const +{ + const CodeEditorStyle sys = CodeEditorStyle::getSystemTheme(); + QVERIFY(sys.isSystemTheme()); +} + +void TestCodeEditorStyle::getSystemTheme_colorsMatchLight() const +{ + const CodeEditorStyle sys = CodeEditorStyle::getSystemTheme(); + QCOMPARE(sys.widgetFGColor, defaultStyleLight.widgetFGColor); + QCOMPARE(sys.widgetBGColor, defaultStyleLight.widgetBGColor); + QCOMPARE(sys.keywordColor, defaultStyleLight.keywordColor); + QCOMPARE(sys.keywordWeight, defaultStyleLight.keywordWeight); + QCOMPARE(sys.commentColor, defaultStyleLight.commentColor); +} + +void TestCodeEditorStyle::saveLoad_darkRoundtrip() const +{ + const QString settingsFile = QDir::tempPath() + "/test_codeeditorstyle_dark.ini"; + QFile::remove(settingsFile); + + { + QSettings settings(settingsFile, QSettings::IniFormat); + CodeEditorStyle::saveSettings(&settings, defaultStyleDark); + } + + QSettings settings(settingsFile, QSettings::IniFormat); + const CodeEditorStyle loaded = CodeEditorStyle::loadSettings(&settings); + QCOMPARE(loaded, defaultStyleDark); + + QFile::remove(settingsFile); +} + +void TestCodeEditorStyle::saveLoad_customColors() const +{ + // Create a style that differs from both defaults so it is saved as "Custom" + CodeEditorStyle custom(defaultStyleLight); + custom.widgetFGColor = QColor(11, 22, 33); + custom.keywordColor = QColor(44, 55, 66); + custom.commentColor = QColor(77, 88, 99); + + const QString settingsFile = QDir::tempPath() + "/test_codeeditorstyle_custom.ini"; + QFile::remove(settingsFile); + + { + QSettings settings(settingsFile, QSettings::IniFormat); + CodeEditorStyle::saveSettings(&settings, custom); + } + + QSettings settings(settingsFile, QSettings::IniFormat); + const CodeEditorStyle loaded = CodeEditorStyle::loadSettings(&settings); + QCOMPARE(loaded.widgetFGColor, custom.widgetFGColor); + QCOMPARE(loaded.keywordColor, custom.keywordColor); + QCOMPARE(loaded.commentColor, custom.commentColor); + + QFile::remove(settingsFile); +} diff --git a/gui/test/codeeditorstyle/testcodeeditorstyle.h b/gui/test/codeeditorstyle/testcodeeditorstyle.h new file mode 100644 index 00000000000..022c00ebc13 --- /dev/null +++ b/gui/test/codeeditorstyle/testcodeeditorstyle.h @@ -0,0 +1,37 @@ +/* -*- C++ -*- + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 . + */ + +#ifndef TESTCODEEDITORSTYLE_H +#define TESTCODEEDITORSTYLE_H + +#include + +class TestCodeEditorStyle : public QObject { + Q_OBJECT + +private slots: + void defaultStyles_notEqual() const; + void equality_sameStyle() const; + void equality_differentColor() const; + void getSystemTheme_isSystemTheme() const; + void getSystemTheme_colorsMatchLight() const; + void saveLoad_darkRoundtrip() const; + void saveLoad_customColors() const; +}; + +#endif // TESTCODEEDITORSTYLE_H diff --git a/gui/test/erroritem/CMakeLists.txt b/gui/test/erroritem/CMakeLists.txt new file mode 100644 index 00000000000..74d4c903bb3 --- /dev/null +++ b/gui/test/erroritem/CMakeLists.txt @@ -0,0 +1,23 @@ +qt_wrap_cpp(test-erroritem_SRC testerroritem.h) +add_custom_target(build-testerroritem-deps SOURCES ${test-erroritem_SRC}) +add_dependencies(gui-build-deps build-testerroritem-deps) +add_executable(test-erroritem + ${test-erroritem_SRC} + testerroritem.cpp + ${CMAKE_SOURCE_DIR}/gui/erroritem.cpp + ) +target_include_directories(test-erroritem PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-erroritem ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0") + # caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638 + target_compile_options_safe(test-erroritem -Wno-ctad-maybe-unsupported) + endif() +endif() + +if (REGISTER_GUI_TESTS) + add_test(NAME test-erroritem COMMAND $) +endif() + +add_dependencies(gui-tests test-erroritem) diff --git a/gui/test/erroritem/testerroritem.cpp b/gui/test/erroritem/testerroritem.cpp new file mode 100644 index 00000000000..ecc224af6dc --- /dev/null +++ b/gui/test/erroritem/testerroritem.cpp @@ -0,0 +1,162 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 "testerroritem.h" + +#include "erroritem.h" +#include "errortypes.h" + +#include + +QTEST_MAIN(TestErrorItem) + +void TestErrorItem::guiSeverity_toString() const +{ + QCOMPARE(GuiSeverity::toString(Severity::error), QString("error")); + QCOMPARE(GuiSeverity::toString(Severity::warning), QString("warning")); + QCOMPARE(GuiSeverity::toString(Severity::style), QString("style")); + QCOMPARE(GuiSeverity::toString(Severity::performance), QString("performance")); + QCOMPARE(GuiSeverity::toString(Severity::portability), QString("portability")); + QCOMPARE(GuiSeverity::toString(Severity::information), QString("information")); + QCOMPARE(GuiSeverity::toString(Severity::none), QString("")); +} + +void TestErrorItem::guiSeverity_fromString() const +{ + QCOMPARE(GuiSeverity::fromString("error"), Severity::error); + QCOMPARE(GuiSeverity::fromString("warning"), Severity::warning); + QCOMPARE(GuiSeverity::fromString("style"), Severity::style); + QCOMPARE(GuiSeverity::fromString("performance"), Severity::performance); + QCOMPARE(GuiSeverity::fromString("portability"), Severity::portability); + QCOMPARE(GuiSeverity::fromString("information"), Severity::information); + QCOMPARE(GuiSeverity::fromString("none"), Severity::none); + QCOMPARE(GuiSeverity::fromString("unknown"), Severity::none); +} + +void TestErrorItem::errorItem_tool() const +{ + ErrorItem item; + item.errorId = "nullPointer"; + QCOMPARE(item.tool(), QString("cppcheck")); + + item.errorId = "clang-analyzer"; + QCOMPARE(item.tool(), QString("clang-analyzer")); + + item.errorId = "clang-tidy-readability-braces"; + QCOMPARE(item.tool(), QString("clang-tidy")); + + item.errorId = "clang-diagnostic-unused"; + QCOMPARE(item.tool(), QString("clang")); +} + +void TestErrorItem::errorItem_toString() const +{ + ErrorItem item; + item.errorId = "nullPointer"; + item.severity = Severity::error; + item.summary = "Null pointer dereference"; + + QErrorPathItem path; + path.file = "test.cpp"; + path.line = 42; + path.column = 5; + item.errorPath << path; + + const QString result = item.toString(); + QVERIFY(result.startsWith("test.cpp:42:5:")); + QVERIFY(result.contains("[nullPointer]")); + QVERIFY(result.contains("Null pointer dereference")); + QVERIFY(result.contains("error")); +} + +void TestErrorItem::errorItem_same_byHash() const +{ + ErrorItem item1; + item1.hash = 12345; + ErrorItem item2; + item2.hash = 12345; + QVERIFY(ErrorItem::same(item1, item2)); + + item2.hash = 99999; + QVERIFY(!ErrorItem::same(item1, item2)); +} + +void TestErrorItem::errorItem_same_byFields() const +{ + ErrorItem item1; + item1.errorId = "nullPointer"; + item1.severity = Severity::error; + item1.message = "The pointer is null"; + item1.inconclusive = false; + QErrorPathItem p; + p.file = "test.cpp"; + p.line = 10; + p.column = 3; + item1.errorPath << p; + + ErrorItem item2 = item1; + QVERIFY(ErrorItem::same(item1, item2)); +} + +void TestErrorItem::errorItem_same_different() const +{ + ErrorItem item1; + item1.errorId = "nullPointer"; + item1.severity = Severity::error; + + ErrorItem item2; + item2.errorId = "uninitVar"; + item2.severity = Severity::error; + + QVERIFY(!ErrorItem::same(item1, item2)); +} + +void TestErrorItem::errorItem_filterMatch() const +{ + ErrorItem item; + item.errorId = "nullPointer"; + item.summary = "Null pointer dereference"; + item.message = "The pointer is null at this location"; + QErrorPathItem p; + p.file = "main.cpp"; + p.info = "check here"; + item.errorPath << p; + + // empty filter matches everything + QVERIFY(item.filterMatch("")); + + // matches in errorId (case insensitive) + QVERIFY(item.filterMatch("nullPointer")); + QVERIFY(item.filterMatch("NULLpointer")); + + // matches in summary + QVERIFY(item.filterMatch("Null pointer")); + QVERIFY(item.filterMatch("DEREFERENCE")); + + // matches in message + QVERIFY(item.filterMatch("location")); + + // matches in errorPath file + QVERIFY(item.filterMatch("main.cpp")); + + // matches in errorPath info + QVERIFY(item.filterMatch("check here")); + + // no match + QVERIFY(!item.filterMatch("xyz123abc")); +} diff --git a/gui/test/erroritem/testerroritem.h b/gui/test/erroritem/testerroritem.h new file mode 100644 index 00000000000..f74f8805d52 --- /dev/null +++ b/gui/test/erroritem/testerroritem.h @@ -0,0 +1,38 @@ +/* -*- C++ -*- + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 . + */ + +#ifndef TESTERRORITEM_H +#define TESTERRORITEM_H + +#include + +class TestErrorItem : public QObject { + Q_OBJECT + +private slots: + void guiSeverity_toString() const; + void guiSeverity_fromString() const; + void errorItem_tool() const; + void errorItem_toString() const; + void errorItem_same_byHash() const; + void errorItem_same_byFields() const; + void errorItem_same_different() const; + void errorItem_filterMatch() const; +}; + +#endif // TESTERRORITEM_H diff --git a/gui/test/platforms/CMakeLists.txt b/gui/test/platforms/CMakeLists.txt new file mode 100644 index 00000000000..f225b93ce09 --- /dev/null +++ b/gui/test/platforms/CMakeLists.txt @@ -0,0 +1,26 @@ +qt_wrap_cpp(test-platforms_SRC + testplatforms.h + ${CMAKE_SOURCE_DIR}/gui/platforms.h + ) +add_custom_target(build-testplatforms-deps SOURCES ${test-platforms_SRC}) +add_dependencies(gui-build-deps build-testplatforms-deps) +add_executable(test-platforms + ${test-platforms_SRC} + testplatforms.cpp + ${CMAKE_SOURCE_DIR}/gui/platforms.cpp + ) +target_include_directories(test-platforms PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-platforms ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0") + # caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638 + target_compile_options_safe(test-platforms -Wno-ctad-maybe-unsupported) + endif() +endif() + +if (REGISTER_GUI_TESTS) + add_test(NAME test-platforms COMMAND $) +endif() + +add_dependencies(gui-tests test-platforms) diff --git a/gui/test/platforms/testplatforms.cpp b/gui/test/platforms/testplatforms.cpp new file mode 100644 index 00000000000..6f6c5e729be --- /dev/null +++ b/gui/test/platforms/testplatforms.cpp @@ -0,0 +1,80 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 "testplatforms.h" + +#include "platform.h" +#include "platforms.h" + +#include + +QTEST_MAIN(TestPlatforms) + +void TestPlatforms::init_populatesAllPlatforms() const +{ + const Platforms platforms; + QCOMPARE(platforms.getCount(), 6); +} + +void TestPlatforms::get_validPlatform() const +{ + Platforms platforms; + const PlatformData& native = platforms.get(Platform::Type::Native); + QVERIFY(!native.mTitle.isEmpty()); + QCOMPARE(native.mType, Platform::Type::Native); +} + +void TestPlatforms::platformTypes_allPresent() const +{ + Platforms platforms; + const QList expectedTypes = { + Platform::Type::Native, + Platform::Type::Unix32, + Platform::Type::Unix64, + Platform::Type::Win32A, + Platform::Type::Win32W, + Platform::Type::Win64, + }; + for (const Platform::Type type : expectedTypes) { + bool found = false; + for (const PlatformData& pd : platforms.mPlatforms) { + if (pd.mType == type) { + found = true; + break; + } + } + QVERIFY2(found, qPrintable(QString("Platform type %1 not found").arg(static_cast(type)))); + } +} + +void TestPlatforms::platformTitles_nonEmpty() const +{ + const Platforms platforms; + for (const PlatformData& pd : platforms.mPlatforms) { + QVERIFY2(!pd.mTitle.isEmpty(), + qPrintable(QString("Platform type %1 has empty title").arg(static_cast(pd.mType)))); + } +} + +void TestPlatforms::add_increasesCount() const +{ + Platforms platforms; + const int before = platforms.getCount(); + platforms.add("Custom", Platform::Type::Native); + QCOMPARE(platforms.getCount(), before + 1); +} diff --git a/gui/test/platforms/testplatforms.h b/gui/test/platforms/testplatforms.h new file mode 100644 index 00000000000..b8f84864a68 --- /dev/null +++ b/gui/test/platforms/testplatforms.h @@ -0,0 +1,35 @@ +/* -*- C++ -*- + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 . + */ + +#ifndef TESTPLATFORMS_H +#define TESTPLATFORMS_H + +#include + +class TestPlatforms : public QObject { + Q_OBJECT + +private slots: + void init_populatesAllPlatforms() const; + void get_validPlatform() const; + void platformTypes_allPresent() const; + void platformTitles_nonEmpty() const; + void add_increasesCount() const; +}; + +#endif // TESTPLATFORMS_H diff --git a/gui/test/showtypes/CMakeLists.txt b/gui/test/showtypes/CMakeLists.txt new file mode 100644 index 00000000000..a96c8adbafe --- /dev/null +++ b/gui/test/showtypes/CMakeLists.txt @@ -0,0 +1,23 @@ +qt_wrap_cpp(test-showtypes_SRC testshowtypes.h) +add_custom_target(build-testshowtypes-deps SOURCES ${test-showtypes_SRC}) +add_dependencies(gui-build-deps build-testshowtypes-deps) +add_executable(test-showtypes + ${test-showtypes_SRC} + testshowtypes.cpp + ${CMAKE_SOURCE_DIR}/gui/showtypes.cpp + ) +target_include_directories(test-showtypes PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_link_libraries(test-showtypes ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0") + # caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638 + target_compile_options_safe(test-showtypes -Wno-ctad-maybe-unsupported) + endif() +endif() + +if (REGISTER_GUI_TESTS) + add_test(NAME test-showtypes COMMAND $) +endif() + +add_dependencies(gui-tests test-showtypes) diff --git a/gui/test/showtypes/testshowtypes.cpp b/gui/test/showtypes/testshowtypes.cpp new file mode 100644 index 00000000000..19d23fc020d --- /dev/null +++ b/gui/test/showtypes/testshowtypes.cpp @@ -0,0 +1,93 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 "testshowtypes.h" + +#include "errortypes.h" +#include "showtypes.h" + +#include + +QTEST_MAIN(TestShowTypes) + +void TestShowTypes::severityToShowType_allValues() const +{ + QCOMPARE(ShowTypes::SeverityToShowType(Severity::error), ShowTypes::ShowErrors); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::warning), ShowTypes::ShowWarnings); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::style), ShowTypes::ShowStyle); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::performance), ShowTypes::ShowPerformance); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::portability), ShowTypes::ShowPortability); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::information), ShowTypes::ShowInformation); +} + +void TestShowTypes::severityToShowType_noneAndInternal() const +{ + QCOMPARE(ShowTypes::SeverityToShowType(Severity::none), ShowTypes::ShowNone); + QCOMPARE(ShowTypes::SeverityToShowType(Severity::internal), ShowTypes::ShowNone); +} + +void TestShowTypes::setShow_togglesVisibility() +{ + ShowTypes st; + + // hide each type and verify + st.show(ShowTypes::ShowErrors, false); + QVERIFY(!st.isShown(ShowTypes::ShowErrors)); + + // restore and verify + st.show(ShowTypes::ShowErrors, true); + QVERIFY(st.isShown(ShowTypes::ShowErrors)); + + // hide a different type + st.show(ShowTypes::ShowWarnings, false); + QVERIFY(!st.isShown(ShowTypes::ShowWarnings)); + QVERIFY(st.isShown(ShowTypes::ShowErrors)); // others unaffected + + st.show(ShowTypes::ShowStyle, false); + QVERIFY(!st.isShown(ShowTypes::ShowStyle)); + + st.show(ShowTypes::ShowPerformance, false); + QVERIFY(!st.isShown(ShowTypes::ShowPerformance)); + + st.show(ShowTypes::ShowPortability, false); + QVERIFY(!st.isShown(ShowTypes::ShowPortability)); + + st.show(ShowTypes::ShowInformation, false); + QVERIFY(!st.isShown(ShowTypes::ShowInformation)); +} + +void TestShowTypes::isShown_bySeverity() +{ + ShowTypes st; + + // ensure errors are visible, then test severity overload + st.show(ShowTypes::ShowErrors, true); + QVERIFY(st.isShown(Severity::error)); + + // hide errors via ShowType, verify Severity overload reflects it + st.show(ShowTypes::ShowErrors, false); + QVERIFY(!st.isShown(Severity::error)); + + // hide warnings, verify + st.show(ShowTypes::ShowWarnings, false); + QVERIFY(!st.isShown(Severity::warning)); + + // ShowNone severities always return false (array is only indexed 0..ShowNone-1) + // Severity::none maps to ShowNone which is out of bounds for mVisible, + // so we only test mapped severities here +} diff --git a/gui/test/showtypes/testshowtypes.h b/gui/test/showtypes/testshowtypes.h new file mode 100644 index 00000000000..701b2a47bca --- /dev/null +++ b/gui/test/showtypes/testshowtypes.h @@ -0,0 +1,34 @@ +/* -*- C++ -*- + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2026 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 . + */ + +#ifndef TESTSHOWTYPES_H +#define TESTSHOWTYPES_H + +#include + +class TestShowTypes : public QObject { + Q_OBJECT + +private slots: + void severityToShowType_allValues() const; + void severityToShowType_noneAndInternal() const; + void setShow_togglesVisibility(); + void isShown_bySeverity(); +}; + +#endif // TESTSHOWTYPES_H