From 859823a975b1e3fa7b9f9dbd782571fb262aade5 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:32:11 -0800 Subject: [PATCH 1/9] Silence noise debug statements This makes unit test output easier to read --- src/comm/MAVLinkProtocol.cc | 2 +- src/uas/UASParameterDataModel.cc | 2 +- src/ui/configuration/terminalconsole.cpp | 2 +- src/ui/linechart/LinechartPlot.cc | 2 +- src/ui/map/QGCMapWidget.cc | 3 +++ src/ui/menuactionhelper.cpp | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 0467e16..1c5e39c 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -220,7 +220,7 @@ void MAVLinkProtocol::linkStatusChanged(bool connected) // Track the links which are connected to the protocol QList _connectedLinks; ///< List of all links connected to protocol - qDebug() << "linkStatusChanged" << connected; + //qDebug() << "linkStatusChanged" << connected; if (link) { diff --git a/src/uas/UASParameterDataModel.cc b/src/uas/UASParameterDataModel.cc index 2cf7b5b..614edbd 100644 --- a/src/uas/UASParameterDataModel.cc +++ b/src/uas/UASParameterDataModel.cc @@ -480,7 +480,7 @@ void UASParameterDataModel::loadParamMetaInfoFromStream(QTextStream& stream) { // tooltip paramDescriptions.insert(parts.at(0).trimmed(), parts.at(6).trimmed()); - qDebug() << "PARAM META:" << parts.at(0).trimmed(); + //qDebug() << "PARAM META:" << parts.at(0).trimmed(); } } } diff --git a/src/ui/configuration/terminalconsole.cpp b/src/ui/configuration/terminalconsole.cpp index 3353fbf..54a090f 100644 --- a/src/ui/configuration/terminalconsole.cpp +++ b/src/ui/configuration/terminalconsole.cpp @@ -118,7 +118,7 @@ void TerminalConsole::fillPortsInfo(QComboBox &comboxBox) << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()); comboxBox.insertItem(0,list.first(), list); - qDebug() << "Inserting " << list.first(); + //qDebug() << "Inserting " << list.first(); } } diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 3916338..1bec2ca 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -471,7 +471,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color) // Change the color of the curve. curve->setPen(QPen(QBrush(color), curveWidth)); - qDebug() << "Setting curve" << id << "to" << color; + //qDebug() << "Setting curve" << id << "to" << color; // And change the color of the symbol, making sure to preserve the symbol style const QwtSymbol *oldSymbol = curve->symbol(); diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 254bd39..156c415 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -260,6 +260,8 @@ void QGCMapWidget::loadSettings(bool changePosition) trailInterval = settings.value("TRAIL_INTERVAL", trailInterval).toFloat(); settings.endGroup(); +#if 0 + // FIXME: NYI // SET CORRECT MENU CHECKBOXES // Set the correct trail interval if (trailType == mapcontrol::UAVTrailType::ByDistance) @@ -272,6 +274,7 @@ void QGCMapWidget::loadSettings(bool changePosition) // XXX qDebug() << "WARNING: Settings loading for trail type (ByTimeElapsed) not implemented"; } +#endif // SET TRAIL TYPE foreach (mapcontrol::UAVItem* uav, GetUAVS()) diff --git a/src/ui/menuactionhelper.cpp b/src/ui/menuactionhelper.cpp index ee75a89..cba136a 100644 --- a/src/ui/menuactionhelper.cpp +++ b/src/ui/menuactionhelper.cpp @@ -31,7 +31,7 @@ void MenuActionHelper::removeDockWidget() QObject *dockWidget = QObject::sender(); Q_ASSERT(dockWidget); - qDebug() << "Dockwidget:" << dockWidget->objectName() << "of type" << dockWidget->metaObject()->className(); + //qDebug() << "Dockwidget:" << dockWidget->objectName() << "of type" << dockWidget->metaObject()->className(); QAction *action = m_menuToDockNameMap.key(dockWidget->objectName()); if(action) { From 0b0323c0cb77f00883d9a030e18be4607f5518d3 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:32:50 -0800 Subject: [PATCH 2/9] Disconnect all links on MainWindow close Previously link were just destroyed --- src/ui/MainWindow.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index d106858..8ed2ee9 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -782,6 +782,8 @@ void MainWindow::closeEvent(QCloseEvent *event) storeSettings(); mavlink->storeSettings(); UASManager::instance()->storeSettings(); + // FIXME: If connected links, should prompt before close + LinkManager::instance()->disconnectAll(); event->accept(); } @@ -1039,7 +1041,7 @@ void MainWindow::enableAutoReconnect(bool enabled) bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style) { - qDebug() << "LOAD STYLE" << style; + //qDebug() << "LOAD STYLE" << style; bool success = true; QString styles; @@ -1587,7 +1589,7 @@ void MainWindow::loadViewState() { if (widgetname != "") { - qDebug() << "Loading widget:" << widgetname; + //qDebug() << "Loading widget:" << widgetname; loadDockWidget(widgetname); } } From 7a211acad64487d7e61c6f4c99ff2741c113ce32 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:33:12 -0800 Subject: [PATCH 3/9] New Mavlink Log collection unit test --- qgroundcontrol.pro | 6 +- src/qgcunittest/MavlinkLogTest.cc | 210 ++++++++++++++++++++++++++++++++++++++ src/qgcunittest/MavlinkLogTest.h | 57 +++++++++++ src/qgcunittest/MockLink.cc | 1 + 4 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 src/qgcunittest/MavlinkLogTest.cc create mode 100644 src/qgcunittest/MavlinkLogTest.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index bcf3fd2..c5e86ff 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -652,7 +652,8 @@ HEADERS += \ src/qgcunittest/QGCUASFileManagerTest.h \ src/qgcunittest/PX4RCCalibrationTest.h \ src/qgcunittest/LinkManagerTest.h \ - src/qgcunittest/MainWindowTest.h + src/qgcunittest/MainWindowTest.h \ + src/qgcunittest/MavlinkLogTest.h SOURCES += \ src/qgcunittest/UnitTest.cc \ @@ -672,7 +673,8 @@ SOURCES += \ src/qgcunittest/QGCUASFileManagerTest.cc \ src/qgcunittest/PX4RCCalibrationTest.cc \ src/qgcunittest/LinkManagerTest.cc \ - src/qgcunittest/MainWindowTest.cc + src/qgcunittest/MainWindowTest.cc \ + src/qgcunittest/MavlinkLogTest.cc } # diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc new file mode 100644 index 0000000..d04d499 --- /dev/null +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -0,0 +1,210 @@ +/*===================================================================== + + 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 +/// @brief Test for mavlink log collection +/// +/// @author Don Gagne + +#include "MavlinkLogTest.h" +#include "MainWindow.h" +#include "MockLink.h" + +UT_REGISTER_TEST(MavlinkLogTest) + +const char* MavlinkLogTest::_tempLogFileTemplate = "FlightDataXXXXXX"; ///< Template for temporary log file +const char* MavlinkLogTest::_logFileExtension = "mavlink"; ///< Extension for log files +const char* MavlinkLogTest::_saveLogFilename = "qgroundcontrol.mavlink.ut"; ///< Filename to save log files to + + +MavlinkLogTest::MavlinkLogTest(void) +{ + +} + +void MavlinkLogTest::init(void) +{ + UnitTest::init(); + + // Make sure temp directory is clear of mavlink logs + QDir tmpDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QStringList logFiles(tmpDir.entryList(QStringList(QString("*.%1").arg(_logFileExtension)), QDir::Files)); + foreach(QString logFile, logFiles) { + bool success = tmpDir.remove(logFile); + Q_UNUSED(success); + Q_ASSERT(success); + } +} + +void MavlinkLogTest::cleanup(void) +{ + UnitTest::cleanup(); + + // Make sure no left over logs in temp directory + QDir tmpDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QStringList logFiles(tmpDir.entryList(QStringList(QString("*.%1").arg(_logFileExtension)), QDir::Files)); + QCOMPARE(logFiles.count(), 0); +} + +void MavlinkLogTest::_bootLogDetectionCancel_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + tempLogFile.open(); + tempLogFile.write("foo"); + tempLogFile.close(); + + // We should get a message box, followed by a getSaveFileName dialog. + setExpectedMessageBox(QMessageBox::Ok); + setExpectedFileDialog(getSaveFileName, QStringList()); + + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + checkExpectedMessageBox(); + checkExpectedFileDialog(); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_bootLogDetectionSave_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + tempLogFile.open(); + tempLogFile.write("foo"); + tempLogFile.close(); + + // We should get a message box, followed by a getSaveFileName dialog. + setExpectedMessageBox(QMessageBox::Ok); + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + checkExpectedMessageBox(); + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + // Zero length file + tempLogFile.open(); + tempLogFile.close(); + + // Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_connectLog_test(void) +{ + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + LinkManager* linkMgr = LinkManager::instance(); + Q_CHECK_PTR(linkMgr); + + MockLink* link = new MockLink(); + Q_CHECK_PTR(link); + // FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work + mainWindow->addLink(link); + linkMgr->connectLink(link); + QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + + // On Disconnect: We should get a getSaveFileName dialog. + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + linkMgr->disconnectLink(link); + QTest::qWait(1000); // Need to allow signals to move between threads + + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + + // MainWindow deletes itself on close + mainWindow->close(); + QTest::qWait(1000); // Need to allow signals to move between threads to shutdown MainWindow +} + +void MavlinkLogTest::_connectLogWindowClose_test(void) +{ + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + LinkManager* linkMgr = LinkManager::instance(); + Q_CHECK_PTR(linkMgr); + + MockLink* link = new MockLink(); + Q_CHECK_PTR(link); + // FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work + mainWindow->addLink(link); + linkMgr->connectLink(link); + QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + + // On Disconnect: We should get a getSaveFileName dialog. + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + // MainWindow deletes itself on close + mainWindow->close(); + QTest::qWait(1000); // Need to allow signals to move between threads + + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); +} diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h new file mode 100644 index 0000000..a9f4e19 --- /dev/null +++ b/src/qgcunittest/MavlinkLogTest.h @@ -0,0 +1,57 @@ +/*===================================================================== + + 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 +/// @brief Test for mavlink log collection +/// +/// @author Don Gagne + +#ifndef MAVLINKLOGTEST_H +#define MAVLINKLOGTEST_H + +#include "UnitTest.h" + +class MavlinkLogTest : public UnitTest +{ + Q_OBJECT + +public: + MavlinkLogTest(void); + +private slots: + void init(void); + void cleanup(void); + + void _bootLogDetectionCancel_test(void); + void _bootLogDetectionSave_test(void); + void _bootLogDetectionZeroLength_test(void); + void _connectLog_test(void); + void _connectLogWindowClose_test(void); + +private: + static const char* _tempLogFileTemplate; ///< Template for temporary log file + static const char* _logFileExtension; ///< Extension for log files + static const char* _saveLogFilename; ///< Filename to save log files to +}; + +#endif diff --git a/src/qgcunittest/MockLink.cc b/src/qgcunittest/MockLink.cc index 6662cb7..73fefbb 100644 --- a/src/qgcunittest/MockLink.cc +++ b/src/qgcunittest/MockLink.cc @@ -382,6 +382,7 @@ void MockLink::_handleParamRequestList(const mavlink_message_t& msg) mavlink_message_t responseMsg; char paramId[MAVLINK_MSG_ID_PARAM_VALUE_LEN]; + Q_ASSERT(param.key().length() <= MAVLINK_MSG_ID_PARAM_VALUE_LEN); strncpy(paramId, param.key().toLocal8Bit().constData(), MAVLINK_MSG_ID_PARAM_VALUE_LEN); mavlink_msg_param_value_pack(_vehicleSystemId, _vehicleComponentId, From b1cb2de2524f168cd4e6e61c8d5cc2e2c8532635 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:32:11 -0800 Subject: [PATCH 4/9] Silence noise debug statements This makes unit test output easier to read --- src/comm/MAVLinkProtocol.cc | 2 +- src/uas/UASParameterDataModel.cc | 2 +- src/ui/configuration/terminalconsole.cpp | 2 +- src/ui/linechart/LinechartPlot.cc | 2 +- src/ui/map/QGCMapWidget.cc | 3 +++ src/ui/menuactionhelper.cpp | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 0467e16..1c5e39c 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -220,7 +220,7 @@ void MAVLinkProtocol::linkStatusChanged(bool connected) // Track the links which are connected to the protocol QList _connectedLinks; ///< List of all links connected to protocol - qDebug() << "linkStatusChanged" << connected; + //qDebug() << "linkStatusChanged" << connected; if (link) { diff --git a/src/uas/UASParameterDataModel.cc b/src/uas/UASParameterDataModel.cc index 2cf7b5b..614edbd 100644 --- a/src/uas/UASParameterDataModel.cc +++ b/src/uas/UASParameterDataModel.cc @@ -480,7 +480,7 @@ void UASParameterDataModel::loadParamMetaInfoFromStream(QTextStream& stream) { // tooltip paramDescriptions.insert(parts.at(0).trimmed(), parts.at(6).trimmed()); - qDebug() << "PARAM META:" << parts.at(0).trimmed(); + //qDebug() << "PARAM META:" << parts.at(0).trimmed(); } } } diff --git a/src/ui/configuration/terminalconsole.cpp b/src/ui/configuration/terminalconsole.cpp index 3353fbf..54a090f 100644 --- a/src/ui/configuration/terminalconsole.cpp +++ b/src/ui/configuration/terminalconsole.cpp @@ -118,7 +118,7 @@ void TerminalConsole::fillPortsInfo(QComboBox &comboxBox) << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()); comboxBox.insertItem(0,list.first(), list); - qDebug() << "Inserting " << list.first(); + //qDebug() << "Inserting " << list.first(); } } diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 3916338..1bec2ca 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -471,7 +471,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color) // Change the color of the curve. curve->setPen(QPen(QBrush(color), curveWidth)); - qDebug() << "Setting curve" << id << "to" << color; + //qDebug() << "Setting curve" << id << "to" << color; // And change the color of the symbol, making sure to preserve the symbol style const QwtSymbol *oldSymbol = curve->symbol(); diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 254bd39..156c415 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -260,6 +260,8 @@ void QGCMapWidget::loadSettings(bool changePosition) trailInterval = settings.value("TRAIL_INTERVAL", trailInterval).toFloat(); settings.endGroup(); +#if 0 + // FIXME: NYI // SET CORRECT MENU CHECKBOXES // Set the correct trail interval if (trailType == mapcontrol::UAVTrailType::ByDistance) @@ -272,6 +274,7 @@ void QGCMapWidget::loadSettings(bool changePosition) // XXX qDebug() << "WARNING: Settings loading for trail type (ByTimeElapsed) not implemented"; } +#endif // SET TRAIL TYPE foreach (mapcontrol::UAVItem* uav, GetUAVS()) diff --git a/src/ui/menuactionhelper.cpp b/src/ui/menuactionhelper.cpp index ee75a89..cba136a 100644 --- a/src/ui/menuactionhelper.cpp +++ b/src/ui/menuactionhelper.cpp @@ -31,7 +31,7 @@ void MenuActionHelper::removeDockWidget() QObject *dockWidget = QObject::sender(); Q_ASSERT(dockWidget); - qDebug() << "Dockwidget:" << dockWidget->objectName() << "of type" << dockWidget->metaObject()->className(); + //qDebug() << "Dockwidget:" << dockWidget->objectName() << "of type" << dockWidget->metaObject()->className(); QAction *action = m_menuToDockNameMap.key(dockWidget->objectName()); if(action) { From 654fe43b80edada7685f207a9926abd1875c5726 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:32:50 -0800 Subject: [PATCH 5/9] Disconnect all links on MainWindow close Previously link were just destroyed --- src/ui/MainWindow.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index d106858..8ed2ee9 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -782,6 +782,8 @@ void MainWindow::closeEvent(QCloseEvent *event) storeSettings(); mavlink->storeSettings(); UASManager::instance()->storeSettings(); + // FIXME: If connected links, should prompt before close + LinkManager::instance()->disconnectAll(); event->accept(); } @@ -1039,7 +1041,7 @@ void MainWindow::enableAutoReconnect(bool enabled) bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style) { - qDebug() << "LOAD STYLE" << style; + //qDebug() << "LOAD STYLE" << style; bool success = true; QString styles; @@ -1587,7 +1589,7 @@ void MainWindow::loadViewState() { if (widgetname != "") { - qDebug() << "Loading widget:" << widgetname; + //qDebug() << "Loading widget:" << widgetname; loadDockWidget(widgetname); } } From 496b8297a7354951b38421de6b55ddf8ad79a307 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 3 Dec 2014 10:33:12 -0800 Subject: [PATCH 6/9] New Mavlink Log collection unit test --- qgroundcontrol.pro | 6 +- src/qgcunittest/MavlinkLogTest.cc | 210 ++++++++++++++++++++++++++++++++++++++ src/qgcunittest/MavlinkLogTest.h | 57 +++++++++++ src/qgcunittest/MockLink.cc | 1 + 4 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 src/qgcunittest/MavlinkLogTest.cc create mode 100644 src/qgcunittest/MavlinkLogTest.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index d63cc0f..638f385 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -654,7 +654,8 @@ HEADERS += \ src/qgcunittest/PX4RCCalibrationTest.h \ src/qgcunittest/LinkManagerTest.h \ src/qgcunittest/MainWindowTest.h \ - src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.h + src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.h \ + src/qgcunittest/MavlinkLogTest.h SOURCES += \ src/qgcunittest/UnitTest.cc \ @@ -675,7 +676,8 @@ SOURCES += \ src/qgcunittest/PX4RCCalibrationTest.cc \ src/qgcunittest/LinkManagerTest.cc \ src/qgcunittest/MainWindowTest.cc \ - src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc + src/AutoPilotPlugins/PX4/Tests/FlightModeConfigTest.cc \ + src/qgcunittest/MavlinkLogTest.cc } # diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc new file mode 100644 index 0000000..d04d499 --- /dev/null +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -0,0 +1,210 @@ +/*===================================================================== + + 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 +/// @brief Test for mavlink log collection +/// +/// @author Don Gagne + +#include "MavlinkLogTest.h" +#include "MainWindow.h" +#include "MockLink.h" + +UT_REGISTER_TEST(MavlinkLogTest) + +const char* MavlinkLogTest::_tempLogFileTemplate = "FlightDataXXXXXX"; ///< Template for temporary log file +const char* MavlinkLogTest::_logFileExtension = "mavlink"; ///< Extension for log files +const char* MavlinkLogTest::_saveLogFilename = "qgroundcontrol.mavlink.ut"; ///< Filename to save log files to + + +MavlinkLogTest::MavlinkLogTest(void) +{ + +} + +void MavlinkLogTest::init(void) +{ + UnitTest::init(); + + // Make sure temp directory is clear of mavlink logs + QDir tmpDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QStringList logFiles(tmpDir.entryList(QStringList(QString("*.%1").arg(_logFileExtension)), QDir::Files)); + foreach(QString logFile, logFiles) { + bool success = tmpDir.remove(logFile); + Q_UNUSED(success); + Q_ASSERT(success); + } +} + +void MavlinkLogTest::cleanup(void) +{ + UnitTest::cleanup(); + + // Make sure no left over logs in temp directory + QDir tmpDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QStringList logFiles(tmpDir.entryList(QStringList(QString("*.%1").arg(_logFileExtension)), QDir::Files)); + QCOMPARE(logFiles.count(), 0); +} + +void MavlinkLogTest::_bootLogDetectionCancel_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + tempLogFile.open(); + tempLogFile.write("foo"); + tempLogFile.close(); + + // We should get a message box, followed by a getSaveFileName dialog. + setExpectedMessageBox(QMessageBox::Ok); + setExpectedFileDialog(getSaveFileName, QStringList()); + + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + checkExpectedMessageBox(); + checkExpectedFileDialog(); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_bootLogDetectionSave_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + tempLogFile.open(); + tempLogFile.write("foo"); + tempLogFile.close(); + + // We should get a message box, followed by a getSaveFileName dialog. + setExpectedMessageBox(QMessageBox::Ok); + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + checkExpectedMessageBox(); + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) +{ + // Create a fake mavlink log + + QTemporaryFile tempLogFile; + tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); + tempLogFile.setAutoRemove(false); + + // Zero length file + tempLogFile.open(); + tempLogFile.close(); + + // Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + mainWindow->close(); + + delete mainWindow; +} + +void MavlinkLogTest::_connectLog_test(void) +{ + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + LinkManager* linkMgr = LinkManager::instance(); + Q_CHECK_PTR(linkMgr); + + MockLink* link = new MockLink(); + Q_CHECK_PTR(link); + // FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work + mainWindow->addLink(link); + linkMgr->connectLink(link); + QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + + // On Disconnect: We should get a getSaveFileName dialog. + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + linkMgr->disconnectLink(link); + QTest::qWait(1000); // Need to allow signals to move between threads + + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + + // MainWindow deletes itself on close + mainWindow->close(); + QTest::qWait(1000); // Need to allow signals to move between threads to shutdown MainWindow +} + +void MavlinkLogTest::_connectLogWindowClose_test(void) +{ + MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); + Q_CHECK_PTR(mainWindow); + + LinkManager* linkMgr = LinkManager::instance(); + Q_CHECK_PTR(linkMgr); + + MockLink* link = new MockLink(); + Q_CHECK_PTR(link); + // FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work + mainWindow->addLink(link); + linkMgr->connectLink(link); + QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through + + // On Disconnect: We should get a getSaveFileName dialog. + QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + QString logSaveFile(logSaveDir.filePath(_saveLogFilename)); + setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); + + // MainWindow deletes itself on close + mainWindow->close(); + QTest::qWait(1000); // Need to allow signals to move between threads + + checkExpectedFileDialog(); + + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); +} diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h new file mode 100644 index 0000000..a9f4e19 --- /dev/null +++ b/src/qgcunittest/MavlinkLogTest.h @@ -0,0 +1,57 @@ +/*===================================================================== + + 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 +/// @brief Test for mavlink log collection +/// +/// @author Don Gagne + +#ifndef MAVLINKLOGTEST_H +#define MAVLINKLOGTEST_H + +#include "UnitTest.h" + +class MavlinkLogTest : public UnitTest +{ + Q_OBJECT + +public: + MavlinkLogTest(void); + +private slots: + void init(void); + void cleanup(void); + + void _bootLogDetectionCancel_test(void); + void _bootLogDetectionSave_test(void); + void _bootLogDetectionZeroLength_test(void); + void _connectLog_test(void); + void _connectLogWindowClose_test(void); + +private: + static const char* _tempLogFileTemplate; ///< Template for temporary log file + static const char* _logFileExtension; ///< Extension for log files + static const char* _saveLogFilename; ///< Filename to save log files to +}; + +#endif diff --git a/src/qgcunittest/MockLink.cc b/src/qgcunittest/MockLink.cc index 6662cb7..73fefbb 100644 --- a/src/qgcunittest/MockLink.cc +++ b/src/qgcunittest/MockLink.cc @@ -382,6 +382,7 @@ void MockLink::_handleParamRequestList(const mavlink_message_t& msg) mavlink_message_t responseMsg; char paramId[MAVLINK_MSG_ID_PARAM_VALUE_LEN]; + Q_ASSERT(param.key().length() <= MAVLINK_MSG_ID_PARAM_VALUE_LEN); strncpy(paramId, param.key().toLocal8Bit().constData(), MAVLINK_MSG_ID_PARAM_VALUE_LEN); mavlink_msg_param_value_pack(_vehicleSystemId, _vehicleComponentId, From f9dc3c0a4129e969976b4226e8eca7923c82f84b Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 5 Dec 2014 09:55:36 -0800 Subject: [PATCH 7/9] Make sure UAS is deleted on correct thread --- src/uas/UASManager.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index b749af1..57ca620 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -279,7 +279,8 @@ UASManager::~UASManager() storeSettings(); // Delete all systems foreach (UASInterface* mav, systems) { - delete mav; + // deleteLater so it ends up on correct thread + mav->deleteLater(); } } From 7127f648ae4292e6642b63650e022589d470b6cf Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 5 Dec 2014 11:59:31 -0800 Subject: [PATCH 8/9] New QTemporaryFile replacement --- src/QGCTemporaryFile.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ src/QGCTemporaryFile.h | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/QGCTemporaryFile.cc create mode 100644 src/QGCTemporaryFile.h diff --git a/src/QGCTemporaryFile.cc b/src/QGCTemporaryFile.cc new file mode 100644 index 0000000..2bbc4a6 --- /dev/null +++ b/src/QGCTemporaryFile.cc @@ -0,0 +1,69 @@ +/*===================================================================== + + 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 +/// @brief This class mimics QTemporaryFile. We have our own implementation due to the fact that +/// QTemporaryFile implemenation differs cross platform making it unusable for our use-case. +/// Look for bug reports on QTemporaryFile keeping the file locked for details. +/// +/// @author Don Gagne + +#include "QGCTemporaryFile.h" + +#include +#include + +QGCTemporaryFile::QGCTemporaryFile(const QString& fileTemplate, QObject* parent) : + QFile(parent), + _template(fileTemplate) +{ + +} + +bool QGCTemporaryFile::open(QFile::OpenMode openMode) +{ + QDir tempDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + + // Generate unique, non-existing filename + + static const char rgDigits[] = "0123456789"; + + QString tempFilename; + + do { + QString uniqueStr; + for (int i=0; i<6; i++) { + uniqueStr += rgDigits[qrand() % 10]; + } + + if (_template.contains("XXXXXX")) { + tempFilename = _template.replace("XXXXXX", uniqueStr, Qt::CaseSensitive); + } else { + tempFilename = _template + uniqueStr; + } + } while (tempDir.exists(tempFilename)); + + setFileName(tempDir.filePath(tempFilename)); + + return QFile::open(openMode); +} diff --git a/src/QGCTemporaryFile.h b/src/QGCTemporaryFile.h new file mode 100644 index 0000000..0dfae41 --- /dev/null +++ b/src/QGCTemporaryFile.h @@ -0,0 +1,55 @@ +/*===================================================================== + + 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 . + + ======================================================================*/ + +#ifndef QGCTemporaryFile_H +#define QGCTemporaryFile_H + +#include + +/// @file +/// @brief This class mimics QTemporaryFile. We have our own implementation due to the fact that +/// QTemporaryFile implemenation differs cross platform making it unusable for our use-case. +/// Look for bug reports on QTemporaryFile keeping the file locked for details. +/// +/// @author Don Gagne + +class QGCTemporaryFile : public QFile { + Q_OBJECT + +public: + /// @brief Creates a new temp file object. QGC temp files are always created in the + // QStandardPaths::TempLocation directory. + // @param template Template for file name following QTemporaryFile rules. Template should NOT include + // directory path, only file name. + QGCTemporaryFile(const QString& fileTemplate, QObject* parent = NULL); + + /// @brief Opens the file in ReadWrite mode. + /// @returns false - open failed + bool open(OpenMode openMode = ReadWrite); + +private: + QString _template; +}; + + +#endif From 505220e0e7cca88dd721b7ddd35093184e01b9ed Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 5 Dec 2014 11:59:45 -0800 Subject: [PATCH 9/9] Change to use QGCTemporaryFile --- qgroundcontrol.pro | 7 +++++-- src/GAudioOutput.cc | 1 - src/LogCompressor.cc | 1 - src/QGCApplication.cc | 6 +++++- src/comm/MAVLinkProtocol.cc | 4 +--- src/comm/MAVLinkProtocol.h | 8 ++++---- src/qgcunittest/MavlinkLogTest.cc | 39 +++++++++++++++------------------------ src/qgcunittest/MavlinkLogTest.h | 2 ++ 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 638f385..7d3cab5 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -478,7 +478,8 @@ HEADERS += \ src/uas/QGXPX4UAS.h \ src/QGCFileDialog.h \ src/QGCMessageBox.h \ - src/QGCComboBox.h + src/QGCComboBox.h \ + src/QGCTemporaryFile.h SOURCES += \ src/main.cc \ @@ -616,7 +617,9 @@ SOURCES += \ src/CmdLineOptParser.cc \ src/uas/QGXPX4UAS.cc \ src/QGCFileDialog.cc \ - src/QGCComboBox.cc + src/QGCComboBox.cc \ + src/QGCTemporaryFile.cc + # # Unit Test specific configuration goes here diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index 5edd1e1..a67d456 100644 --- a/src/GAudioOutput.cc +++ b/src/GAudioOutput.cc @@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project #include #include -#include #include "GAudioOutput.h" #include "MG.h" diff --git a/src/LogCompressor.cc b/src/LogCompressor.cc index 28b73ae..faa55ec 100644 --- a/src/LogCompressor.cc +++ b/src/LogCompressor.cc @@ -30,7 +30,6 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#include #include #include #include diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index fa8540b..469bcee 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -56,6 +56,7 @@ #include "LinkManager.h" #include "UASManager.h" #include "AutoPilotPluginManager.h" +#include "QGCTemporaryFile.h" #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" @@ -309,12 +310,15 @@ void QGCApplication::setSavedFilesLocation(QString& location) bool QGCApplication::validatePossibleSavedFilesLocation(QString& location) { // Make sure we can write to the directory + QString filename = QDir(location).filePath("QGCTempXXXXXXXX.tmp"); - QTemporaryFile tempFile(filename); + QGCTemporaryFile tempFile(filename); if (!tempFile.open()) { return false; } + tempFile.remove(); + return true; } diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 1c5e39c..d6743ff 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -56,15 +56,13 @@ MAVLinkProtocol::MAVLinkProtocol() : _should_exit(false), _logSuspendError(false), _logSuspendReplay(false), + _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)), _protocolStatusMessageConnected(false), _saveTempFlightDataLogConnected(false) { qRegisterMetaType("mavlink_message_t"); - _tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - _tempLogFile.setAutoRemove(false); - m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; loadSettings(); moveToThread(this); diff --git a/src/comm/MAVLinkProtocol.h b/src/comm/MAVLinkProtocol.h index 11b8881..070902b 100644 --- a/src/comm/MAVLinkProtocol.h +++ b/src/comm/MAVLinkProtocol.h @@ -37,12 +37,12 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#include #include "ProtocolInterface.h" #include "LinkInterface.h" #include "QGCMAVLink.h" #include "QGC.h" +#include "QGCTemporaryFile.h" /** * @brief MAVLink micro air vehicle protocol reference implementation. @@ -282,9 +282,9 @@ private: bool _logSuspendError; ///< true: Logging suspended due to error bool _logSuspendReplay; ///< true: Logging suspended due to replay - QTemporaryFile _tempLogFile; ///< File to log to - static const char* _tempLogFileTemplate; ///< Template for temporary log file - static const char* _logFileExtension; ///< Extension for log files + QGCTemporaryFile _tempLogFile; ///< File to log to + static const char* _tempLogFileTemplate; ///< Template for temporary log file + static const char* _logFileExtension; ///< Extension for log files bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index d04d499..d23fbc0 100644 --- a/src/qgcunittest/MavlinkLogTest.cc +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -29,6 +29,7 @@ #include "MavlinkLogTest.h" #include "MainWindow.h" #include "MockLink.h" +#include "QGCTemporaryFile.h" UT_REGISTER_TEST(MavlinkLogTest) @@ -66,17 +67,21 @@ void MavlinkLogTest::cleanup(void) QCOMPARE(logFiles.count(), 0); } -void MavlinkLogTest::_bootLogDetectionCancel_test(void) +void MavlinkLogTest::_createTempLogFile(bool zeroLength) { - // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); + QGCTemporaryFile tempLogFile(QString("%1.%2").arg(_tempLogFileTemplate).arg(_logFileExtension)); tempLogFile.open(); - tempLogFile.write("foo"); + if (!zeroLength) { + tempLogFile.write("foo"); + } tempLogFile.close(); +} + +void MavlinkLogTest::_bootLogDetectionCancel_test(void) +{ + // Create a fake mavlink log + _createTempLogFile(false); // We should get a message box, followed by a getSaveFileName dialog. setExpectedMessageBox(QMessageBox::Ok); @@ -96,14 +101,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void) void MavlinkLogTest::_bootLogDetectionSave_test(void) { // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); - - tempLogFile.open(); - tempLogFile.write("foo"); - tempLogFile.close(); + _createTempLogFile(false); // We should get a message box, followed by a getSaveFileName dialog. setExpectedMessageBox(QMessageBox::Ok); @@ -127,15 +125,8 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void) void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) { - // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); - - // Zero length file - tempLogFile.open(); - tempLogFile.close(); + // Create a fake eempty mavlink log + _createTempLogFile(true); // Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h index a9f4e19..21cde40 100644 --- a/src/qgcunittest/MavlinkLogTest.h +++ b/src/qgcunittest/MavlinkLogTest.h @@ -49,6 +49,8 @@ private slots: void _connectLogWindowClose_test(void); private: + void _createTempLogFile(bool zeroLength); + static const char* _tempLogFileTemplate; ///< Template for temporary log file static const char* _logFileExtension; ///< Extension for log files static const char* _saveLogFilename; ///< Filename to save log files to