From e0fed930e97e6b2d50f768fdf5b8ebf57c3a477f Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 11 Feb 2015 18:06:54 -0800 Subject: [PATCH] Fix SetupView to work with latest mavlink headers - Updated MainWindowTest to catch this problem - Also implemented initial pass at SetupView unit test --- qgroundcontrol.pro | 2 + src/AutoPilotPlugins/PX4/AirframeComponent.cc | 13 ++- src/VehicleSetup/SetupViewTest.cc | 97 +++++++++++++++++++ src/VehicleSetup/SetupViewTest.h | 51 ++++++++++ src/qgcunittest/MainWindowTest.cc | 27 +++--- src/qgcunittest/MainWindowTest.h | 1 - src/qgcunittest/MockLink.param | 6 +- 7 files changed, 177 insertions(+), 20 deletions(-) create mode 100644 src/VehicleSetup/SetupViewTest.cc create mode 100644 src/VehicleSetup/SetupViewTest.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 65b6242a4..e80135e7c 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -681,6 +681,7 @@ HEADERS += \ src/FactSystem/FactSystemTestPX4.h \ src/FactSystem/FactSystemTestGeneric.h \ src/QmlControls/QmlTestWidget.h \ + src/VehicleSetup/SetupViewTest.h \ SOURCES += \ src/qgcunittest/UnitTest.cc \ @@ -706,6 +707,7 @@ SOURCES += \ src/FactSystem/FactSystemTestPX4.cc \ src/FactSystem/FactSystemTestGeneric.cc \ src/QmlControls/QmlTestWidget.cc \ + src/VehicleSetup/SetupViewTest.cc \ } diff --git a/src/AutoPilotPlugins/PX4/AirframeComponent.cc b/src/AutoPilotPlugins/PX4/AirframeComponent.cc index 1f0fefcf2..2442e371f 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponent.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponent.cc @@ -30,6 +30,9 @@ /// @brief Parameters which signal a change in setupComplete state static const char* triggerParams[] = { "SYS_AUTOSTART", NULL }; +#if 0 +// Broken by latest mavlink module changes. Not used yet. Comment out for now. +// Discussing mavlink fix. struct mavType { int type; const char* description; @@ -58,17 +61,23 @@ static const struct mavType mavTypeInfo[] = { { MAV_TYPE_ONBOARD_CONTROLLER, "Onbard companion controller" }, { MAV_TYPE_VTOL_DUOROTOR, "Two-rotor VTOL" }, { MAV_TYPE_VTOL_QUADROTOR, "Quad-rotor VTOL" }, + { MAV_TYPE_GIMBAL, "Gimbal" }, }; static size_t cMavTypes = sizeof(mavTypeInfo) / sizeof(mavTypeInfo[0]); +#endif AirframeComponent::AirframeComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent) : PX4Component(uas, autopilot, parent), _name(tr("Airframe")) { +#if 0 + // Broken by latest mavlink module changes. Not used yet. Comment out for now. + // Discussing mavlink fix. Q_UNUSED(mavTypeInfo); // Keeping this around for later use // Validate that our mavTypeInfo array hasn't gotten out of sync + qDebug() << cMavTypes << MAV_TYPE_ENUM_END; Q_ASSERT(cMavTypes == MAV_TYPE_ENUM_END); static const int mavTypes[] = { @@ -92,13 +101,15 @@ AirframeComponent::AirframeComponent(UASInterface* uas, AutoPilotPlugin* autopil MAV_TYPE_KITE, MAV_TYPE_ONBOARD_CONTROLLER, MAV_TYPE_VTOL_DUOROTOR, - MAV_TYPE_VTOL_QUADROTOR + MAV_TYPE_VTOL_QUADROTOR, + MAV_TYPE_GIMBAL, }; Q_UNUSED(mavTypes); // Keeping this around for later use for (size_t i=0; i + + 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 . + + ======================================================================*/ + +/// @file +/// @author Don Gagne + +#include "SetupViewTest.h" +#include "MockLink.h" +#include "QGCMessageBox.h" + +UT_REGISTER_TEST(SetupViewTest) + +SetupViewTest::SetupViewTest(void) +{ + +} + +void SetupViewTest::init(void) +{ + UnitTest::init(); + + _mainWindow = MainWindow::_create(NULL); + Q_CHECK_PTR(_mainWindow); +} + +void SetupViewTest::cleanup(void) +{ + _mainWindow->close(); + delete _mainWindow; + + UnitTest::cleanup(); +} + +void SetupViewTest::_clickThrough_test(void) +{ + LinkManager* linkMgr = LinkManager::instance(); + Q_CHECK_PTR(linkMgr); + + MockLink* link = new MockLink(); + Q_CHECK_PTR(link); + link->setAutopilotType(MAV_AUTOPILOT_PX4); + LinkManager::instance()->addLink(link); + linkMgr->connectLink(link); + QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + + // Find the Setup button and click it + + QGCToolBar* toolbar = _mainWindow->findChild(); + Q_ASSERT(toolbar); + + QList buttons = toolbar->findChildren(); + QToolButton* setupButton = NULL; + foreach(QToolButton* button, buttons) { + if (button->text() == "Setup") { + setupButton = button; + break; + } + } + + Q_ASSERT(setupButton); + QTest::mouseClick(setupButton, Qt::LeftButton); + QTest::qWait(1000); + + // Click through all the setup buttons + // FIXME: NYI + + // On MainWindow close we should get a message box telling the user to disconnect first. Disconnect will then pop + // the log file save dialog. + + setExpectedMessageBox(QGCMessageBox::Yes); + setExpectedFileDialog(getSaveFileName, QStringList()); + + _mainWindow->close(); + QTest::qWait(1000); // Need to allow signals to move between threads + checkExpectedMessageBox(); + checkExpectedFileDialog(); +} diff --git a/src/VehicleSetup/SetupViewTest.h b/src/VehicleSetup/SetupViewTest.h new file mode 100644 index 000000000..8a1b86ad2 --- /dev/null +++ b/src/VehicleSetup/SetupViewTest.h @@ -0,0 +1,51 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + 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 . + + ======================================================================*/ + +/// @file +/// @author Don Gagne + +#ifndef SetupViewTest_H +#define SetupViewTest_H + +#include "UnitTest.h" +#include "MainWindow.h" + +/// Click through test for Setup View buttons +class SetupViewTest : public UnitTest +{ + Q_OBJECT + +public: + SetupViewTest(void); + +private slots: + void init(void); + void cleanup(void); + + void _clickThrough_test(void); + +private: + MainWindow* _mainWindow; +}; + +#endif diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index d618097ae..68d610f46 100644 --- a/src/qgcunittest/MainWindowTest.cc +++ b/src/qgcunittest/MainWindowTest.cc @@ -54,21 +54,6 @@ void MainWindowTest::cleanup(void) UnitTest::cleanup(); } -void MainWindowTest::_clickThrough_test(void) -{ - QGCToolBar* toolbar = _mainWindow->findChild(); - Q_ASSERT(toolbar); - - QList buttons = toolbar->findChildren(); - foreach(QToolButton* button, buttons) { - if (!button->menu()) { - QTest::mouseClick(button, Qt::LeftButton); - QTest::qWait(1000); - } - } - -} - void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot) { LinkManager* linkMgr = LinkManager::instance(); @@ -81,6 +66,18 @@ void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot) linkMgr->connectLink(link); QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + // Click through all top level toolbar buttons + QGCToolBar* toolbar = _mainWindow->findChild(); + Q_ASSERT(toolbar); + + QList buttons = toolbar->findChildren(); + foreach(QToolButton* button, buttons) { + if (!button->menu()) { + QTest::mouseClick(button, Qt::LeftButton); + QTest::qWait(1000); + } + } + // On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing. setExpectedMessageBox(QGCMessageBox::Cancel); _mainWindow->close(); diff --git a/src/qgcunittest/MainWindowTest.h b/src/qgcunittest/MainWindowTest.h index e37cf9e33..517c3adf7 100644 --- a/src/qgcunittest/MainWindowTest.h +++ b/src/qgcunittest/MainWindowTest.h @@ -43,7 +43,6 @@ private slots: void init(void); void cleanup(void); - void _clickThrough_test(void); void _connectWindowClosePX4_test(void); void _connectWindowCloseGeneric_test(void); diff --git a/src/qgcunittest/MockLink.param b/src/qgcunittest/MockLink.param index 920dda714..ecceac191 100644 --- a/src/qgcunittest/MockLink.param +++ b/src/qgcunittest/MockLink.param @@ -381,7 +381,7 @@ 1 50 RTL_RETURN_ALT 100 9 1 50 SDLOG_EXT -1 6 1 50 SDLOG_RATE -1 6 -1 50 SENS_ACC_XOFF 0 9 +1 50 SENS_ACC_XOFF 1 9 1 50 SENS_ACC_XSCALE 1 9 1 50 SENS_ACC_YOFF 0 9 1 50 SENS_ACC_YSCALE 1 9 @@ -396,13 +396,13 @@ 1 50 SENS_DPRES_OFF 0 9 1 50 SENS_EXT_MAG 0 6 1 50 SENS_EXT_MAG_ROT 0 6 -1 50 SENS_GYRO_XOFF 0 9 +1 50 SENS_GYRO_XOFF 1 9 1 50 SENS_GYRO_XSCALE 1 9 1 50 SENS_GYRO_YOFF 0 9 1 50 SENS_GYRO_YSCALE 1 9 1 50 SENS_GYRO_ZOFF 0 9 1 50 SENS_GYRO_ZSCALE 1 9 -1 50 SENS_MAG_XOFF 0 9 +1 50 SENS_MAG_XOFF 1 9 1 50 SENS_MAG_XSCALE 1 9 1 50 SENS_MAG_YOFF 0 9 1 50 SENS_MAG_YSCALE 1 9 -- 2.22.0