File indexing completed on 2024-05-19 05:42:25

0001 // ct_lvtqtw_configurationdialog.t.cpp                               -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include "ct_lvtplg_pluginmanager.h"
0021 #include <ct_lvtqtw_configurationdialog.h>
0022 #include <ct_lvtqtw_modifierhelpers.h>
0023 #include <ct_lvttst_fixture_qt.h>
0024 #include <preferences.h>
0025 
0026 #include <catch2-local-includes.h>
0027 #ifdef KDE_FRAMEWORKS_IS_OLD
0028 #include <ui_ct_lvtqtw_configurationdialog_oldkf5.h>
0029 #else
0030 #include <ui_ct_lvtqtw_configurationdialog.h>
0031 #endif
0032 
0033 #include <QObject>
0034 
0035 using namespace Codethink::lvtqtw;
0036 
0037 TEST_CASE_METHOD(QTApplicationFixture, "Smoke Test ConfigurationDialog class")
0038 {
0039     Codethink::lvtplg::PluginManager manager;
0040 
0041     SECTION("Test load function")
0042     {
0043         ConfigurationDialog configDialog(&manager, nullptr);
0044         REQUIRE_NOTHROW(configDialog.load());
0045     }
0046 
0047     SECTION("Test save static function")
0048     {
0049         REQUIRE_NOTHROW(ConfigurationDialog::save());
0050     }
0051 
0052     SECTION("Test restoreDefaults function")
0053     {
0054         ConfigurationDialog configDialog(&manager, nullptr);
0055         REQUIRE_NOTHROW(configDialog.restoreDefaults());
0056     }
0057 
0058     SECTION("Test changeCurrentWidgetByString function")
0059     {
0060         ConfigurationDialog configDialog(&manager, nullptr);
0061         auto *listWidget = configDialog.findChild<QListWidget *>("listWidget");
0062         REQUIRE_NOTHROW(configDialog.changeCurrentWidgetByString("Test Sample"));
0063 
0064         for (int i = 0; i < listWidget->count(); i++) {
0065             const QString t = listWidget->item(i)->text();
0066             configDialog.changeCurrentWidgetByString(t);
0067             REQUIRE(listWidget->currentItem()->text() == t);
0068         }
0069 
0070         listWidget->item(0)->setText(QString());
0071         REQUIRE_NOTHROW(listWidget->setCurrentRow(0));
0072     }
0073 
0074     SECTION("Test entityNamePos ")
0075     {
0076         ConfigurationDialog configDialog(&manager, nullptr);
0077 
0078         auto *entityNamePos = configDialog.findChild<QComboBox *>("entityNamePos");
0079         for (int i = 0; i < entityNamePos->count(); i++) {
0080             REQUIRE_NOTHROW(entityNamePos->setCurrentIndex(i));
0081         }
0082     }
0083 
0084     SECTION("Test comboPanModifier")
0085     {
0086         ConfigurationDialog configDialog(&manager, nullptr);
0087         auto *comboPanModifier = configDialog.findChild<QComboBox *>("comboPanModifier");
0088         REQUIRE_NOTHROW(comboPanModifier->setCurrentIndex(0));
0089         REQUIRE_NOTHROW(comboPanModifier->setCurrentIndex(comboPanModifier->count() - 1));
0090     }
0091 
0092     SECTION("Test showLevelNumbers")
0093     {
0094         ConfigurationDialog configDialog(&manager, nullptr);
0095         auto *showLevelNumbers = configDialog.findChild<QCheckBox *>("showLevelNumbers");
0096         REQUIRE_NOTHROW(showLevelNumbers->setCheckState(Qt::Checked));
0097         REQUIRE_NOTHROW(showLevelNumbers->setCheckState(Qt::Unchecked));
0098     }
0099 
0100     SECTION("Test backgroundColor")
0101     {
0102         ConfigurationDialog configDialog(&manager, nullptr);
0103         auto *backgroundColor = configDialog.findChild<KColorButton *>("backgroundColor");
0104         REQUIRE_NOTHROW(backgroundColor->setColor(Qt::red));
0105         REQUIRE_NOTHROW(backgroundColor->setColor(Qt::blue));
0106     }
0107 
0108     SECTION("Test entityBackgroundColor")
0109     {
0110         ConfigurationDialog configDialog(&manager, nullptr);
0111         auto *entityBackgroundColor = configDialog.findChild<KColorButton *>("entityBackgroundColor");
0112         REQUIRE_NOTHROW(entityBackgroundColor->setColor(Qt::red));
0113         REQUIRE_NOTHROW(entityBackgroundColor->setColor(Qt::blue));
0114     }
0115     SECTION("Test selectedEntityBackgroundColor")
0116     {
0117         ConfigurationDialog configDialog(&manager, nullptr);
0118         auto *selectedEntityBackgroundColor = configDialog.findChild<KColorButton *>("selectedEntityBackgroundColor");
0119         REQUIRE_NOTHROW(selectedEntityBackgroundColor->setColor(Qt::red));
0120         REQUIRE_NOTHROW(selectedEntityBackgroundColor->setColor(Qt::blue));
0121     }
0122 
0123     SECTION("Test chkSelectedEntityHasGradient")
0124     {
0125         ConfigurationDialog configDialog(&manager, nullptr);
0126         auto *chkSelectedEntityHasGradient = configDialog.findChild<QCheckBox *>("chkSelectedEntityHasGradient");
0127         REQUIRE_NOTHROW(chkSelectedEntityHasGradient->setCheckState(Qt::Checked));
0128         REQUIRE_NOTHROW(chkSelectedEntityHasGradient->setCheckState(Qt::Unchecked));
0129     }
0130 
0131     SECTION("Test edgeColor")
0132     {
0133         ConfigurationDialog configDialog(&manager, nullptr);
0134         auto *edgeColor = configDialog.findChild<KColorButton *>("edgeColor");
0135         REQUIRE_NOTHROW(edgeColor->setColor(Qt::red));
0136         REQUIRE_NOTHROW(edgeColor->setColor(Qt::blue));
0137     }
0138     SECTION("Test highlightEdgeColor")
0139     {
0140         ConfigurationDialog configDialog(&manager, nullptr);
0141         auto *highlightEdgeColor = configDialog.findChild<KColorButton *>("highlightEdgeColor");
0142         REQUIRE_NOTHROW(highlightEdgeColor->setColor(Qt::red));
0143         REQUIRE_NOTHROW(highlightEdgeColor->setColor(Qt::blue));
0144     }
0145 
0146     SECTION("Test comboZoomModifier")
0147     {
0148         ConfigurationDialog configDialog(&manager, nullptr);
0149         auto *comboZoomModifier = configDialog.findChild<QComboBox *>("comboZoomModifier");
0150         REQUIRE_NOTHROW(comboZoomModifier->setCurrentIndex(0));
0151         REQUIRE_NOTHROW(comboZoomModifier->setCurrentIndex(comboZoomModifier->count() - 1));
0152     }
0153 }
0154 
0155 TEST_CASE_METHOD(QTApplicationFixture, "Test ConfigurationDialog class Functionality")
0156 {
0157     Codethink::lvtplg::PluginManager manager;
0158     ConfigurationDialog configDialog(&manager, nullptr);
0159 
0160     auto *toolBox = configDialog.findChild<QCheckBox *>("toolBox");
0161     REQUIRE(toolBox != nullptr);
0162     SECTION("Test load function")
0163     {
0164         const bool t = Preferences::showLegend();
0165         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0166         Preferences::setShowLegend(!t);
0167         REQUIRE((bool) toolBox->checkState() != Preferences::showLegend());
0168         configDialog.load();
0169         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0170     }
0171 
0172     SECTION("Test UI effect on Preferences")
0173     {
0174         toolBox->setCheckState(Qt::Unchecked);
0175         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0176 
0177         toolBox->setCheckState(Qt::Checked);
0178         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0179 
0180         toolBox->setCheckState(Qt::Unchecked);
0181         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0182     }
0183 
0184     SECTION("Test restoreDefaults function")
0185     {
0186         const bool t = Preferences::showLegend();
0187         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0188         Preferences::setShowLegend(!t);
0189         REQUIRE((bool) toolBox->checkState() != Preferences::showLegend());
0190         configDialog.restoreDefaults();
0191         REQUIRE((bool) toolBox->checkState() == Preferences::showLegend());
0192     }
0193 }