From b82c8e78663f15a3afc968fcda44c23a80fb2f84 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 4 Mar 2015 18:06:38 -0800 Subject: [PATCH 1/5] Add parent in constructor --- src/ui/toolbar/MainToolBar.cc | 5 +++-- src/ui/toolbar/MainToolBar.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ui/toolbar/MainToolBar.cc b/src/ui/toolbar/MainToolBar.cc index c443554..2091dac 100644 --- a/src/ui/toolbar/MainToolBar.cc +++ b/src/ui/toolbar/MainToolBar.cc @@ -35,8 +35,9 @@ This file is part of the QGROUNDCONTROL project #include "UASMessageHandler.h" #include "UASMessageView.h" -MainToolBar::MainToolBar() - : _mav(NULL) +MainToolBar::MainToolBar(QWidget* parent) + : QGCQmlWidgetHolder(parent) + , _mav(NULL) , _toolBar(NULL) , _currentView(ViewNone) , _batteryVoltage(0.0) diff --git a/src/ui/toolbar/MainToolBar.h b/src/ui/toolbar/MainToolBar.h index 3764b1b..9d9fab3 100644 --- a/src/ui/toolbar/MainToolBar.h +++ b/src/ui/toolbar/MainToolBar.h @@ -42,7 +42,7 @@ class MainToolBar : public QGCQmlWidgetHolder Q_ENUMS(ViewType_t) Q_ENUMS(MessageType_t) public: - MainToolBar(); + MainToolBar(QWidget* parent = NULL); ~MainToolBar(); typedef enum { From 8ee51d3497c7e7ae02da81a84c5e127161e200c6 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 4 Mar 2015 18:06:55 -0800 Subject: [PATCH 2/5] Add getMainToolBar for unit test writing --- src/ui/MainWindow.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 237e317..eab3977 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -125,6 +125,11 @@ public: /// @brief Restore (and connects) the last used connection (if any) void restoreLastUsedConnection(); + +#ifdef UNITTEST_BUILD + // Returns a pointer to the MainToolBar so that unit tests can change views. + MainToolBar* getMainToolBar(void) { return _mainToolBar; } +#endif public slots: From 05bd92734072e1b38a4fcb4b464ba76666a56d23 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 4 Mar 2015 18:08:08 -0800 Subject: [PATCH 3/5] Don't force visibility of toolbar Although this should theoretically be a no-op it causes a crash in Windows when running unit tests. Also parent toolbar in constructor. --- src/ui/MainWindow.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 117913f..d86f53a 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -171,9 +171,7 @@ MainWindow::MainWindow(QSplashScreen* splashScreen) QDockWidget* widget = new QDockWidget(this); widget->setObjectName("ToolBarDockWidget"); qmlRegisterType("QGroundControl.MainToolBar", 1, 0, "MainToolBar"); - _mainToolBar = new MainToolBar(); - _mainToolBar->setParent(widget); - _mainToolBar->setVisible(true); + _mainToolBar = new MainToolBar(widget); widget->setWidget(_mainToolBar); widget->setFeatures(QDockWidget::NoDockWidgetFeatures); widget->setTitleBarWidget(new QWidget(this)); // Disables the title bar From 92c0b53cad1fa267205fb0aa6613b314e1eff439 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 4 Mar 2015 18:08:39 -0800 Subject: [PATCH 4/5] Update tests for new toolbar Also turn them back on --- src/VehicleSetup/SetupViewTest.cc | 32 ++++++++++---------------------- src/VehicleSetup/SetupViewTest.h | 4 +++- src/qgcunittest/MainWindowTest.cc | 34 +++++++++++++++++----------------- src/qgcunittest/MainWindowTest.h | 5 ++++- 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/VehicleSetup/SetupViewTest.cc b/src/VehicleSetup/SetupViewTest.cc index c1f6647..113072e 100644 --- a/src/VehicleSetup/SetupViewTest.cc +++ b/src/VehicleSetup/SetupViewTest.cc @@ -28,10 +28,11 @@ #include "MockLink.h" #include "QGCMessageBox.h" -// TODO: This is not working in Windows. Needs to be updated for new tool bar any way. -//UT_REGISTER_TEST(SetupViewTest) +UT_REGISTER_TEST(SetupViewTest) -SetupViewTest::SetupViewTest(void) +SetupViewTest::SetupViewTest(void) : + _mainWindow(NULL), + _mainToolBar(NULL) { } @@ -42,6 +43,9 @@ void SetupViewTest::init(void) _mainWindow = MainWindow::_create(NULL); Q_CHECK_PTR(_mainWindow); + + _mainToolBar = _mainWindow->getMainToolBar(); + Q_ASSERT(_mainToolBar); } void SetupViewTest::cleanup(void) @@ -64,26 +68,10 @@ void SetupViewTest::_clickThrough_test(void) 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 - - // Tool Bar is now a QQuickWidget and cannot be manipulated like below -#if 0 - 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); + // Switch to the Setup view + _mainToolBar->onSetupView(); QTest::qWait(1000); -#endif + // Click through all the setup buttons // FIXME: NYI diff --git a/src/VehicleSetup/SetupViewTest.h b/src/VehicleSetup/SetupViewTest.h index 8a1b86a..0868149 100644 --- a/src/VehicleSetup/SetupViewTest.h +++ b/src/VehicleSetup/SetupViewTest.h @@ -29,6 +29,7 @@ #include "UnitTest.h" #include "MainWindow.h" +#include "MainToolBar.h" /// Click through test for Setup View buttons class SetupViewTest : public UnitTest @@ -45,7 +46,8 @@ private slots: void _clickThrough_test(void); private: - MainWindow* _mainWindow; + MainWindow* _mainWindow; + MainToolBar* _mainToolBar; }; #endif diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index bff4829..2b007bb 100644 --- a/src/qgcunittest/MainWindowTest.cc +++ b/src/qgcunittest/MainWindowTest.cc @@ -31,10 +31,11 @@ #include "MockLink.h" #include "QGCMessageBox.h" -// TODO: This needs to be changed to accomodate the new QML based tool bar -// UT_REGISTER_TEST(MainWindowTest) +UT_REGISTER_TEST(MainWindowTest) -MainWindowTest::MainWindowTest(void) +MainWindowTest::MainWindowTest(void) : + _mainWindow(NULL), + _mainToolBar(NULL) { } @@ -45,6 +46,9 @@ void MainWindowTest::init(void) _mainWindow = MainWindow::_create(NULL); Q_CHECK_PTR(_mainWindow); + + _mainToolBar = _mainWindow->getMainToolBar(); + Q_ASSERT(_mainToolBar); } void MainWindowTest::cleanup(void) @@ -67,21 +71,17 @@ 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 - // Tool Bar is now a QQuickWidget and cannot be manipulated like below -#if 0 - // Click through all top level toolbar buttons - QGCToolBar* toolbar = _mainWindow->findChild(); - Q_ASSERT(toolbar); + // Cycle through all the top level views + + _mainToolBar->onSetupView(); + QTest::qWait(1000); + _mainToolBar->onPlanView(); + QTest::qWait(1000); + _mainToolBar->onFlyView(); + QTest::qWait(1000); + _mainToolBar->onAnalyzeView(); + QTest::qWait(1000); - QList buttons = toolbar->findChildren(); - foreach(QToolButton* button, buttons) { - if (!button->menu()) { - QTest::mouseClick(button, Qt::LeftButton); - QTest::qWait(1000); - } - } -#endif - // 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 517c3ad..488b435 100644 --- a/src/qgcunittest/MainWindowTest.h +++ b/src/qgcunittest/MainWindowTest.h @@ -31,6 +31,7 @@ #include "UnitTest.h" #include "MainWindow.h" +#include "MainToolBar.h" class MainWindowTest : public UnitTest { @@ -48,7 +49,9 @@ private slots: private: void _connectWindowClose_test(MAV_AUTOPILOT autopilot); - MainWindow* _mainWindow; + + MainWindow* _mainWindow; + MainToolBar* _mainToolBar; }; #endif From e278b23b9e3f9793433645fc14117846805cdb52 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 4 Mar 2015 18:09:11 -0800 Subject: [PATCH 5/5] Turn off due to singleton shutdown problem Will rewrite singleton shutdown in separate pull --- src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc b/src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc index a563cc1..c8a10ed 100644 --- a/src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc +++ b/src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc @@ -31,7 +31,9 @@ /// /// @author Don Gagne -UT_REGISTER_TEST(FlightModeConfigTest) +// Turned off due to signletonn shutdown sequencing problem. Also since FlightMode config is +// being re-written this test will need to be re-written as well. +//UT_REGISTER_TEST(FlightModeConfigTest) FlightModeConfigTest::FlightModeConfigTest(void) : _mockUASManager(NULL),