diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index eef9282e9..393a9fdfc 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -217,12 +217,6 @@ namespace BlackGui return nullptr; } - CAircraft CMainKeypadAreaComponent::getOwnAircraft() const - { - if (!this->getIContextOwnAircraft()) { return CAircraft(); } - return this->getIContextOwnAircraft()->getOwnAircraft(); - } - void CMainKeypadAreaComponent::unsetInfoAreaButtons() { ui->pb_MainAircrafts->setChecked(false); @@ -241,8 +235,9 @@ namespace BlackGui CIdentifier CMainKeypadAreaComponent::keypadIdentifier() { if (m_identifier.getName().isEmpty()) + { m_identifier = CIdentifier(QStringLiteral("KEYPADAREACOMPONENT")); - + } return m_identifier; } diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index acfd43b8d..9787edc05 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -95,9 +95,6 @@ namespace BlackGui //! Main info area to corresponding button QPushButton *mainInfoAreaToButton(CMainInfoAreaComponent::InfoArea area) const; - //! Own aircraft - BlackMisc::Aviation::CAircraft getOwnAircraft() const; - //! Info area buttons void unsetInfoAreaButtons(); diff --git a/src/blackgui/guiutility.cpp b/src/blackgui/guiutility.cpp index 02fefbf1d..979660cab 100644 --- a/src/blackgui/guiutility.cpp +++ b/src/blackgui/guiutility.cpp @@ -91,6 +91,25 @@ namespace BlackGui a.installTranslator(&translator); } + bool CGuiUtility::lenientTitleComparison(const QString &title, const QString &comparison) + { + if (title == comparison) { return true; } + + QString t(title.trimmed().toLower().simplified()); + QString c(comparison.trimmed().toLower().simplified()); + Q_ASSERT_X(!t.isEmpty(), Q_FUNC_INFO, "missing value"); + Q_ASSERT_X(!c.isEmpty(), Q_FUNC_INFO, "missing value"); + if (t == c) { return true; } + + // further unify + static QThreadStorage tsRegex; + if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("[^a-z0-9\\s]")); } + const QRegularExpression ®exp = tsRegex.localData(); + t = t.remove(regexp); + c = c.remove(regexp); + return t == c; + } + QWidgetList CGuiUtility::topLevelApplicationWidgetsWithName() { QWidgetList tlw = QApplication::topLevelWidgets(); diff --git a/src/blackgui/guiutility.h b/src/blackgui/guiutility.h index 39734f6cb..2235b6c87 100644 --- a/src/blackgui/guiutility.h +++ b/src/blackgui/guiutility.h @@ -64,6 +64,9 @@ namespace BlackGui //! Standard initialization for a swift GUI application static void initSwiftGuiApplication(QApplication &a, const QString &applicationName, const QPixmap &icon = BlackMisc::CIcons::swift24()); + //! Leninet / relaxed + static bool lenientTitleComparison(const QString &title, const QString &comparison); + private: //! Constructor, use static methods only CGuiUtility() {} diff --git a/src/blackgui/infoarea.cpp b/src/blackgui/infoarea.cpp index b72888366..0591773ff 100644 --- a/src/blackgui/infoarea.cpp +++ b/src/blackgui/infoarea.cpp @@ -649,7 +649,7 @@ namespace BlackGui Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "No title"); for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas) { - if (dw->windowTitleOrBackup() == title) { return dw; } + if (CGuiUtility::lenientTitleComparison(dw->windowTitleOrBackup(), title)) { return dw; } } return nullptr; } @@ -659,7 +659,7 @@ namespace BlackGui Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "No title"); for (int i = 0; i < m_dockWidgetInfoAreas.size(); i++) { - if (title == m_dockWidgetInfoAreas.at(i)->windowTitleOrBackup()) { return i; } + if (CGuiUtility::lenientTitleComparison(m_dockWidgetInfoAreas.at(i)->windowTitleOrBackup(), title)) { return i; } } Q_ASSERT_X(false, Q_FUNC_INFO, "No area for title"); return -1; @@ -671,7 +671,7 @@ namespace BlackGui if (m_tabBar->count() < 1) { return -1;} for (int i = 0; i < m_tabBar->count(); i++) { - if (m_tabBar->tabText(i) == title) { return i; } + if (CGuiUtility::lenientTitleComparison(m_tabBar->tabText(i), title)) { return i; } } Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "Wrong title"); return -1; diff --git a/src/blackmisc/aviation/aircrafticaocode.cpp b/src/blackmisc/aviation/aircrafticaocode.cpp index 9d87c9099..0c5f9b7a8 100644 --- a/src/blackmisc/aviation/aircrafticaocode.cpp +++ b/src/blackmisc/aviation/aircrafticaocode.cpp @@ -150,14 +150,14 @@ namespace BlackMisc bool CAircraftIcaoCode::isValidDesignator(const QString &designator) { - static QRegularExpression regexp("^[A-Z]+[A-Z0-9]*$"); + static const QRegularExpression regexp("^[A-Z]+[A-Z0-9]*$"); if (designator.length() < 2 || designator.length() > 5) { return false; } return (regexp.match(designator).hasMatch()); } bool CAircraftIcaoCode::isValidCombinedType(const QString &combinedType) { - static QRegularExpression regexp("^[A-Z][0-9][A-Z]$"); + static const QRegularExpression regexp("^[A-Z][0-9][A-Z]$"); if (combinedType.length() != 3) return false; return (regexp.match(combinedType).hasMatch()); } diff --git a/swift.pro b/swift.pro index f36a45aab..69ccf0ace 100644 --- a/swift.pro +++ b/swift.pro @@ -61,6 +61,7 @@ contains(BLACK_CONFIG, Samples) { contains(BLACK_CONFIG, Unittests) { SUBDIRS += tests/blackmisc/test_blackmisc.pro SUBDIRS += tests/blackcore/test_blackcore.pro + SUBDIRS += tests/blackgui/test_blackgui.pro } contains(BLACK_CONFIG, Doxygen) { diff --git a/tests/blackcore/blackcoretest.h b/tests/blackcore/blackcoretest.h index 8f2534db8..bce563b30 100644 --- a/tests/blackcore/blackcoretest.h +++ b/tests/blackcore/blackcoretest.h @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* Copyright (C) 2013 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ #ifndef BLACKCORETEST_H #define BLACKCORETEST_H diff --git a/tests/blackgui/blackguitest.h b/tests/blackgui/blackguitest.h new file mode 100644 index 000000000..8084d5d53 --- /dev/null +++ b/tests/blackgui/blackguitest.h @@ -0,0 +1,20 @@ +/* Copyright (C) 2013 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUITEST_H +#define BLACKGUITEST_H + +/*! + * \namespace BlackGuiTest + * Unit tests for BlackGui. Unit tests do have their own namespace, so + * the regular namespace BlackGui is completely free of unit tests. + * Add any new tests to TestMain::unitMain as shown there. + */ + +#endif // guard diff --git a/tests/blackgui/main.cpp b/tests/blackgui/main.cpp new file mode 100644 index 000000000..ee951ced6 --- /dev/null +++ b/tests/blackgui/main.cpp @@ -0,0 +1,23 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "testblackguimain.h" +#include +#include + +using namespace BlackCoreTest; + +//! Starter for test cases +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + Q_UNUSED(a); + + return CBlackGuiTestMain::unitMain(argc, argv); +} diff --git a/tests/blackgui/test_blackgui.pro b/tests/blackgui/test_blackgui.pro new file mode 100644 index 000000000..0d6985453 --- /dev/null +++ b/tests/blackgui/test_blackgui.pro @@ -0,0 +1,22 @@ +include ($$SourceRoot/config.pri) +include ($$SourceRoot/build.pri) + +QT += core testlib dbus network gui svg +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = test_blackgui +TEMPLATE = app + +CONFIG -= app_bundle +CONFIG += blackmisc blackcore blackgui +CONFIG += testcase + +DEPENDPATH += . $$SourceRoot/src +INCLUDEPATH += . $$SourceRoot/src + +HEADERS += *.h +SOURCES += *.cpp + +DESTDIR = $$BuildRoot/bin + +include ($$SourceRoot/libraries.pri) diff --git a/tests/blackgui/testblackguimain.cpp b/tests/blackgui/testblackguimain.cpp new file mode 100644 index 000000000..ecb14fbd3 --- /dev/null +++ b/tests/blackgui/testblackguimain.cpp @@ -0,0 +1,27 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "testblackguimain.h" +#include "testutils.h" + +namespace BlackCoreTest +{ + /* + * Starting main, equivalent to QTEST_APPLESS_MAIN for multiple test classes. + */ + int CBlackGuiTestMain::unitMain(int argc, char *argv[]) + { + int status = 0; + { + CTestGuiUtilities utilityTests; + status |= QTest::qExec(&utilityTests, argc, argv); + } + return status; + } +} // namespace diff --git a/tests/blackgui/testblackguimain.h b/tests/blackgui/testblackguimain.h new file mode 100644 index 000000000..8c5269de8 --- /dev/null +++ b/tests/blackgui/testblackguimain.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORETEST_TESTMAIN_H +#define BLACKCORETEST_TESTMAIN_H + +#include "blackmisc/valueobject.h" // for qHash overload, include before Qt stuff due GCC issue +#include + +namespace BlackCoreTest +{ + + /*! + * Class firing all unit tests in this namespace. + * Avoids clashes with other main(..) functions and allows to fire the test cases + * simply from any other main. + */ + class CBlackGuiTestMain + { + public: + //! Unit tests + static int unitMain(int argc, char *argv[]); + }; +} + +#endif // guard diff --git a/tests/blackgui/testutils.cpp b/tests/blackgui/testutils.cpp new file mode 100644 index 000000000..5af58569f --- /dev/null +++ b/tests/blackgui/testutils.cpp @@ -0,0 +1,28 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "testutils.h" +#include "blackgui/guiutility.h" + +using namespace BlackGui; + +namespace BlackCoreTest +{ + + CTestGuiUtilities::CTestGuiUtilities(QObject *parent) : + QObject(parent) + { } + + void CTestGuiUtilities::utilityFunctions() + { + QVERIFY2(CGuiUtility::lenientTitleComparison("foo", "foo"), "wrong title match"); + QVERIFY2(CGuiUtility::lenientTitleComparison("foo&", "&Foo"), "wrong title match"); + QVERIFY2(!CGuiUtility::lenientTitleComparison("foo", "bar"), "wrong title mismatch"); + } +} // ns diff --git a/tests/blackgui/testutils.h b/tests/blackgui/testutils.h new file mode 100644 index 000000000..89e50b7d8 --- /dev/null +++ b/tests/blackgui/testutils.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2015 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORETEST_TESTUTILS_H +#define BLACKCORETEST_TESTUTILS_H + +#include "blackgui/guiutility.h" +#include + +namespace BlackCoreTest +{ + /** + * Test GUI utilities + */ + class CTestGuiUtilities : public QObject + { + Q_OBJECT + + public: + //! Constructor. + explicit CTestGuiUtilities(QObject *parent = nullptr); + + private slots: + //! Test the utility functions + void utilityFunctions(); + }; + +} //namespace + +#endif // guard