Commit 3332ec2f authored by Don Gagne's avatar Don Gagne

Merge pull request #1030 from DonLakeFlyer/MainWindowTest

Simple MainWindow Unit Test
parents a494d27b c7e17869
......@@ -650,7 +650,8 @@ HEADERS += \
src/qgcunittest/TCPLoopBackServer.h \
src/qgcunittest/QGCUASFileManagerTest.h \
src/qgcunittest/PX4RCCalibrationTest.h \
src/qgcunittest/LinkManagerTest.h
src/qgcunittest/LinkManagerTest.h \
src/qgcunittest/MainWindowTest.h
SOURCES += \
src/qgcunittest/UnitTest.cc \
......@@ -668,7 +669,8 @@ SOURCES += \
src/qgcunittest/TCPLoopBackServer.cc \
src/qgcunittest/QGCUASFileManagerTest.cc \
src/qgcunittest/PX4RCCalibrationTest.cc \
src/qgcunittest/LinkManagerTest.cc
src/qgcunittest/LinkManagerTest.cc \
src/qgcunittest/MainWindowTest.cc
}
#
......
......@@ -143,22 +143,13 @@ QGCApplication::~QGCApplication()
}
void QGCApplication::_initCommon(void)
{
}
bool QGCApplication::_initForNormalAppBoot(void)
{
QSettings settings;
_createSingletons();
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
// Show user an upgrade message if the settings version has been bumped up
bool settingsUpgraded = false;
enum MainWindow::CUSTOM_MODE mode = MainWindow::CUSTOM_MODE_PX4;
if (settings.contains(_settingsVersionKey)) {
if (settings.value(_settingsVersionKey).toInt() != QGC_SETTINGS_VERSION) {
settingsUpgraded = true;
......@@ -171,6 +162,9 @@ bool QGCApplication::_initForNormalAppBoot(void)
if (settingsUpgraded) {
settings.clear();
settings.setValue(_settingsVersionKey, QGC_SETTINGS_VERSION);
QGCMessageBox::information(tr("Settings Cleared"),
tr("The format for QGroundControl saved settings has been modified. "
"Your saved settings have been reset to defaults."));
}
// Load saved files location and validate
......@@ -190,7 +184,6 @@ bool QGCApplication::_initForNormalAppBoot(void)
Q_UNUSED(pathCreated);
Q_ASSERT(pathCreated);
savedFilesLocation = documentsDir.filePath(_defaultSavedFileDirectoryName);
settings.setValue(_savedFilesLocationKey, savedFilesLocation);
}
if (!savedFilesLocation.isEmpty()) {
......@@ -198,10 +191,24 @@ bool QGCApplication::_initForNormalAppBoot(void)
savedFilesLocation.clear();
}
}
settings.setValue(_savedFilesLocationKey, savedFilesLocation);
// Load application font
QFontDatabase fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
//const QString fontFamilyName = "Bitstream Vera Sans";
if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str());
fontDatabase.addApplicationFont(fontFileName);
// Avoid Using setFont(). In the Qt docu you can read the following:
// "Warning: Do not use this function in conjunction with Qt Style Sheets."
// setFont(fontDatabase.font(fontFamilyName, "Roman", 12));
}
bool QGCApplication::_initForNormalAppBoot(void)
{
QSettings settings;
mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt();
settings.sync();
enum MainWindow::CUSTOM_MODE mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt();
// Show splash screen
QPixmap splashImage(":/files/images/splash.png");
......@@ -212,21 +219,24 @@ bool QGCApplication::_initForNormalAppBoot(void)
processEvents();
splashScreen->showMessage(tr("Loading application fonts"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
// Load application font
QFontDatabase fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
//const QString fontFamilyName = "Bitstream Vera Sans";
if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str());
fontDatabase.addApplicationFont(fontFileName);
// Avoid Using setFont(). In the Qt docu you can read the following:
// "Warning: Do not use this function in conjunction with Qt Style Sheets."
// setFont(fontDatabase.font(fontFamilyName, "Roman", 12));
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
// Start the user interface
splashScreen->showMessage(tr("Starting user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
MainWindow* mainWindow = new MainWindow(splashScreen, mode);
MainWindow* mainWindow = MainWindow::_create(splashScreen, mode);
Q_CHECK_PTR(mainWindow);
// If we made it this far and we still don't have a location. Either the specfied location was invalid
// or we coudn't create a default location. Either way, we need to let the user know and prompt for a new
/// settings.
QString savedFilesLocation = settings.value(_savedFilesLocationKey).toString();
if (savedFilesLocation.isEmpty()) {
QGCMessageBox::warning(tr("Bad save location"),
tr("The location to save files to is invalid, or cannot be written to. Please provide a new one."));
mainWindow->showSettings();
}
UDPLink* udpLink = NULL;
if (mainWindow->getCustomMode() == MainWindow::CUSTOM_MODE_WIFI)
......@@ -252,20 +262,6 @@ bool QGCApplication::_initForNormalAppBoot(void)
splashScreen->finish(mainWindow);
mainWindow->splashScreenFinished();
// If we made it this far and we still don't have a location. Either the specfied location was invalid
// or we coudn't create a default location. Either way, we need to let the user know and prompt for a new
/// settings.
if (savedFilesLocation.isEmpty()) {
QGCMessageBox::warning(tr("Bad save location"),
tr("The location to save files to is invalid, or cannot be written to. Please provide a new one."));
mainWindow->showSettings();
}
if (settingsUpgraded) {
mainWindow->showInfoMessage(tr("Settings Cleared"),
tr("The format for QGroundControl saved settings has been modified. "
"Your saved settings have been reset to defaults."));
}
// Check if link could be connected
if (udpLink && LinkManager::instance()->connectLink(udpLink))
......
......@@ -61,8 +61,6 @@ TCPLink::~TCPLink()
quit();
// Wait for it to exit
wait();
deleteLater();
}
void TCPLink::run()
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @brief Simple MainWindow unit test
///
/// @author Don Gagne <don@thegagnes.com>
#include "MainWindowTest.h"
#include "MainWindow.h"
UT_REGISTER_TEST(MainWindowTest)
MainWindowTest::MainWindowTest(void)
{
}
void MainWindowTest::init(void)
{
UnitTest::init();
}
void MainWindowTest::cleanup(void)
{
UnitTest::cleanup();
}
void MainWindowTest::_simpleDisplay_test(void)
{
MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4);
Q_CHECK_PTR(mainWindow);
mainWindow->close();
delete mainWindow;
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @brief Simple MainWindow unit test
///
/// @author Don Gagne <don@thegagnes.com>
#ifndef MAINWINDOWTEST_H
#define MAINWINDOWTEST_H
#include "UnitTest.h"
class MainWindowTest : public UnitTest
{
Q_OBJECT
public:
MainWindowTest(void);
private slots:
UT_DECLARE_DEFAULT_initTestCase
UT_DECLARE_DEFAULT_cleanupTestCase
void init(void);
void cleanup(void);
void _simpleDisplay_test(void);
};
#endif
......@@ -22,7 +22,7 @@
======================================================================*/
/// @file
/// @brief The tests the unit test QGCMessageBox catching mechanism.
/// @brief Unit test for QGCMessageBox catching mechanism.
///
/// @author Don Gagne <don@thegagnes.com>
......
......@@ -22,7 +22,7 @@
======================================================================*/
/// @file
/// @brief The tests the unit test QGCMessageBox catching mechanism.
/// @brief Unit test for QGCMessageBox catching mechanism.
///
/// @author Don Gagne <don@thegagnes.com>
......
......@@ -34,6 +34,35 @@
///
/// @author Don Gagne <don@thegagnes.com>
enum PX4_CUSTOM_MAIN_MODE {
PX4_CUSTOM_MAIN_MODE_MANUAL = 1,
PX4_CUSTOM_MAIN_MODE_ALTCTL,
PX4_CUSTOM_MAIN_MODE_POSCTL,
PX4_CUSTOM_MAIN_MODE_AUTO,
PX4_CUSTOM_MAIN_MODE_ACRO,
PX4_CUSTOM_MAIN_MODE_OFFBOARD,
};
enum PX4_CUSTOM_SUB_MODE_AUTO {
PX4_CUSTOM_SUB_MODE_AUTO_READY = 1,
PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF,
PX4_CUSTOM_SUB_MODE_AUTO_LOITER,
PX4_CUSTOM_SUB_MODE_AUTO_MISSION,
PX4_CUSTOM_SUB_MODE_AUTO_RTL,
PX4_CUSTOM_SUB_MODE_AUTO_LAND,
PX4_CUSTOM_SUB_MODE_AUTO_RTGS
};
union px4_custom_mode {
struct {
uint16_t reserved;
uint8_t main_mode;
uint8_t sub_mode;
};
uint32_t data;
float data_float;
};
MockLink::MockLink(void) :
_linkId(getNextLinkId()),
_name("MockLink"),
......@@ -42,9 +71,15 @@ MockLink::MockLink(void) :
_vehicleComponentId(200), // FIXME: magic number?
_inNSH(false),
_mavlinkStarted(false),
_mavMode(MAV_MODE_FLAG_MANUAL_INPUT_ENABLED),
_mavBaseMode(MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_CUSTOM_MODE_ENABLED),
_mavState(MAV_STATE_STANDBY)
{
union px4_custom_mode px4_cm;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL;
_mavCustomMode = px4_cm.data;
_missionItemHandler = new MockLinkMissionItemHandler(_vehicleSystemId, this);
Q_CHECK_PTR(_missionItemHandler);
......@@ -56,7 +91,6 @@ MockLink::MockLink(void) :
MockLink::~MockLink(void)
{
_disconnect();
deleteLater();
}
void MockLink::readBytes(void)
......@@ -184,8 +218,8 @@ void MockLink::_sendHeartBeat(void)
&msg,
MAV_TYPE_QUADROTOR, // MAV_TYPE
MAV_AUTOPILOT_PX4, // MAV_AUTOPILOT
_mavMode, // MAV_MODE
0, // custom mode
_mavBaseMode, // MAV_MODE
_mavCustomMode, // custom mode
_mavState); // MAV_STATE
int cBuffer = mavlink_msg_to_send_buffer(buffer, &msg);
......@@ -323,7 +357,8 @@ void MockLink::_handleSetMode(const mavlink_message_t& msg)
mavlink_msg_set_mode_decode(&msg, &request);
if (request.target_system == _vehicleSystemId) {
_mavMode = request.base_mode;
_mavBaseMode = request.base_mode;
_mavCustomMode = request.custom_mode;
} else {
_errorInvalidTargetSystem(request.target_system);
}
......
......@@ -118,7 +118,8 @@ private:
typedef QMap<uint16_t, mavlink_mission_item_t> MissionList_t;
MissionList_t _missionItems;
uint8_t _mavMode;
uint8_t _mavBaseMode;
uint8_t _mavCustomMode;
uint8_t _mavState;
};
......
......@@ -88,7 +88,6 @@ const QString MainWindow::defaultLightStyle = ":files/styles/style-light.css";
MainWindow* MainWindow::_create(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode)
{
Q_ASSERT(_instance == NULL);
Q_ASSERT(splashScreen);
new MainWindow(splashScreen, mode);
......@@ -125,12 +124,12 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE
menuActionHelper(new MenuActionHelper()),
_splashScreen(splashScreen)
{
Q_ASSERT(splashScreen);
Q_ASSERT(_instance == NULL);
_instance = this;
connect(this, &MainWindow::initStatusChanged, splashScreen, &QSplashScreen::showMessage);
if (splashScreen) {
connect(this, &MainWindow::initStatusChanged, splashScreen, &QSplashScreen::showMessage);
}
this->setAttribute(Qt::WA_DeleteOnClose);
connect(menuActionHelper, SIGNAL(needToShowDockWidget(QString,bool)),SLOT(showDockWidget(QString,bool)));
......
......@@ -468,14 +468,9 @@ private slots:
void _saveTempFlightDataLog(QString tempLogfile);
private:
/// Constructor is private since all creation should be through MainWindow::instance.
/// Constructor is private since all creation should be through MainWindow::_create
MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode);
/// @brief Two phase construction such that MainWindow::instance is available to code
void _init(void);
friend class QGCApplication;
void _hideSplashScreen(void);
void _openUrl(const QString& url, const QString& errorMessage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment