From 519ee5abb94dac128d4ba9516a257b51f8e41ae0 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 25 Jul 2015 11:54:01 -0700 Subject: [PATCH] Update unit test for new log save behavior --- src/VehicleSetup/SetupViewTest.cc | 5 +---- src/comm/MockLink.h | 6 ++--- src/qgcunittest/MainWindowTest.cc | 3 --- src/qgcunittest/MavlinkLogTest.cc | 47 +++++++++++++++++++++++++++++++-------- src/qgcunittest/MavlinkLogTest.h | 4 +++- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/VehicleSetup/SetupViewTest.cc b/src/VehicleSetup/SetupViewTest.cc index eedcf43..424e8c9 100644 --- a/src/VehicleSetup/SetupViewTest.cc +++ b/src/VehicleSetup/SetupViewTest.cc @@ -110,14 +110,11 @@ void SetupViewTest::_clickThrough_test(void) QTest::qWait(1000); } - // On MainWindow close we should get a message box telling the user to disconnect first. Disconnect will then pop - // the log file save dialog. + // On MainWindow close we should get a message box telling the user to disconnect first. 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/comm/MockLink.h b/src/comm/MockLink.h index 567c56d..f55a2e2 100644 --- a/src/comm/MockLink.h +++ b/src/comm/MockLink.h @@ -144,9 +144,9 @@ private: typedef QMap MissionList_t; MissionList_t _missionItems; - uint8_t _mavBaseMode; - uint8_t _mavCustomMode; - uint8_t _mavState; + uint8_t _mavBaseMode; + uint32_t _mavCustomMode; + uint8_t _mavState; MockConfiguration* _config; MAV_AUTOPILOT _autopilotType; diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index 363bc2e..113e586 100644 --- a/src/qgcunittest/MainWindowTest.cc +++ b/src/qgcunittest/MainWindowTest.cc @@ -100,11 +100,8 @@ void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot) QTest::qWait(1000); // Need to allow signals to move between threads checkExpectedMessageBox(); - // We are going to disconnect the link which is going to pop a save file dialog - setExpectedFileDialog(getSaveFileName, QStringList()); linkMgr->disconnectLink(link); QTest::qWait(1000); // Need to allow signals to move between threads - checkExpectedFileDialog(); } void MainWindowTest::_connectWindowClosePX4_test(void) { diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index a34c699..16482d0 100644 --- a/src/qgcunittest/MavlinkLogTest.cc +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -31,6 +31,7 @@ #include "MockLink.h" #include "QGCTemporaryFile.h" #include "QGCApplication.h" +#include "UAS.h" UT_REGISTER_TEST(MavlinkLogTest) @@ -133,7 +134,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) // Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. } -void MavlinkLogTest::_connectLog_test(void) +void MavlinkLogTest::_connectLogWorker(bool arm) { LinkManager* linkMgr = LinkManager::instance(); Q_CHECK_PTR(linkMgr); @@ -142,20 +143,48 @@ void MavlinkLogTest::_connectLog_test(void) Q_CHECK_PTR(link); LinkManager::instance()->_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)); + // Wait for the uas to work it's way through the various threads + + QSignalSpy spyUas(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*))); + QCOMPARE(spyUas.wait(5000), true); + + UASInterface* uasInterface = UASManager::instance()->getActiveUAS(); + QVERIFY(uasInterface); + UAS* uas = dynamic_cast(uasInterface); + QVERIFY(uas); + + QDir logSaveDir; + + if (arm) { + uas->armSystem(); + QTest::qWait(1500); // Wait long enough for heartbeat to come through + + // On Disconnect: We should get a getSaveFileName dialog. + logSaveDir.setPath(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(); + if (arm) { + checkExpectedFileDialog(); - // Make sure the file is there and delete it - QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + // Make sure the file is there and delete it + QCOMPARE(logSaveDir.remove(_saveLogFilename), true); + } +} + +void MavlinkLogTest::_connectLogNoArm_test(void) +{ + _connectLogWorker(false); +} + +void MavlinkLogTest::_connectLogArm_test(void) +{ + _connectLogWorker(true); } void MavlinkLogTest::_deleteTempLogFiles_test(void) diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h index a97d10b..92b4fd8 100644 --- a/src/qgcunittest/MavlinkLogTest.h +++ b/src/qgcunittest/MavlinkLogTest.h @@ -45,7 +45,8 @@ private slots: void _bootLogDetectionCancel_test(void); void _bootLogDetectionSave_test(void); void _bootLogDetectionZeroLength_test(void); - void _connectLog_test(void); + void _connectLogNoArm_test(void); + void _connectLogArm_test(void); void _deleteTempLogFiles_test(void); signals: @@ -53,6 +54,7 @@ signals: private: void _createTempLogFile(bool zeroLength); + void _connectLogWorker(bool arm); static const char* _tempLogFileTemplate; ///< Template for temporary log file static const char* _logFileExtension; ///< Extension for log files