some fixes

* as of slack discussion with MG, made area finding a bit more robust
* removed unused function in keypadarea
* added unit test subproject for GUI
This commit is contained in:
Klaus Basan
2015-07-13 19:20:31 +02:00
committed by Mathew Sutcliffe
parent 03e16e37e7
commit f8c83ce2a3
15 changed files with 230 additions and 19 deletions

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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<QRegularExpression> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("[^a-z0-9\\s]")); }
const QRegularExpression &regexp = tsRegex.localData();
t = t.remove(regexp);
c = c.remove(regexp);
return t == c;
}
QWidgetList CGuiUtility::topLevelApplicationWidgetsWithName()
{
QWidgetList tlw = QApplication::topLevelWidgets();

View File

@@ -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() {}

View File

@@ -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;

View File

@@ -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());
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

23
tests/blackgui/main.cpp Normal file
View File

@@ -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 <QCoreApplication>
#include <QDebug>
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);
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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 <QtTest/QtTest>
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

View File

@@ -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

View File

@@ -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 <QtTest/QtTest>
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