Tests: Remove old irrelevant tests
This commit is contained in:
@@ -71,18 +71,11 @@ 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);
|
||||
setExpectedFileDialog(getSaveFileName, QStringList());
|
||||
|
||||
// Kick the protocol to check for lost log files and wait for signals to move through
|
||||
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
|
||||
emit checkForLostLogFiles();
|
||||
QTest::qWait(1000);
|
||||
|
||||
checkExpectedMessageBox();
|
||||
checkExpectedFileDialog();
|
||||
}
|
||||
|
||||
void MavlinkLogTest::_bootLogDetectionSave_test(void)
|
||||
@@ -91,19 +84,13 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void)
|
||||
_createTempLogFile(false);
|
||||
|
||||
// We should get a message box, followed by a getSaveFileName dialog.
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
|
||||
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
|
||||
|
||||
// Kick the protocol to check for lost log files and wait for signals to move through
|
||||
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
|
||||
emit checkForLostLogFiles();
|
||||
QTest::qWait(1000);
|
||||
|
||||
checkExpectedMessageBox();
|
||||
checkExpectedFileDialog();
|
||||
|
||||
// Make sure the file is there and delete it
|
||||
QCOMPARE(logSaveDir.remove(_saveLogFilename), true);
|
||||
}
|
||||
@@ -133,15 +120,11 @@ void MavlinkLogTest::_connectLogWorker(bool arm)
|
||||
|
||||
// On Disconnect: We should get a getSaveFileName dialog.
|
||||
logSaveDir.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
|
||||
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
|
||||
}
|
||||
|
||||
_disconnectMockLink();
|
||||
|
||||
if (arm) {
|
||||
checkExpectedFileDialog();
|
||||
|
||||
// Make sure the file is there and delete it
|
||||
QCOMPARE(logSaveDir.remove(_saveLogFilename), true);
|
||||
}
|
||||
|
||||
@@ -247,9 +247,6 @@ void RadioConfigTest::cleanup(void)
|
||||
Q_ASSERT(_calWidget);
|
||||
delete _calWidget;
|
||||
|
||||
// Disconnecting the link will prompt for log file save
|
||||
setExpectedFileDialog(getSaveFileName, QStringList());
|
||||
|
||||
UnitTest::cleanup();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,6 @@ void ParameterManagerTest::_requestListMissingParamSuccess(void)
|
||||
// Test no response to param_request_list
|
||||
void ParameterManagerTest::_requestListNoResponse(void)
|
||||
{
|
||||
// Will pop error about request failure
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
|
||||
Q_ASSERT(!_mockLink);
|
||||
_mockLink = MockLink::startPX4MockLink(false, MockConfiguration::FailParamNoReponseToRequestList);
|
||||
|
||||
@@ -96,18 +93,12 @@ void ParameterManagerTest::_requestListNoResponse(void)
|
||||
// We should not get any progress bar updates, nor a parameter ready signal
|
||||
QCOMPARE(spyProgress.wait(500), false);
|
||||
QCOMPARE(spyParamsReady.wait(40000), false);
|
||||
|
||||
// User should have been notified
|
||||
checkExpectedMessageBox();
|
||||
}
|
||||
|
||||
// MockLink will fail to send a param on initial request, it will also fail to send it on subsequent
|
||||
// param_read requests.
|
||||
void ParameterManagerTest::_requestListMissingParamFail(void)
|
||||
{
|
||||
// Will pop error about missing params
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
|
||||
Q_ASSERT(!_mockLink);
|
||||
_mockLink = MockLink::startPX4MockLink(false, MockConfiguration::FailMissingParamOnAllRequests);
|
||||
|
||||
@@ -137,9 +128,6 @@ void ParameterManagerTest::_requestListMissingParamFail(void)
|
||||
// We should get a parameters ready signal, but Vehicle should indicate missing params
|
||||
QCOMPARE(spyParamsReady.wait(40000), true);
|
||||
QCOMPARE(vehicle->parameterManager()->missingParameters(), true);
|
||||
|
||||
// User should have been notified
|
||||
checkExpectedMessageBox();
|
||||
}
|
||||
|
||||
void ParameterManagerTest::_FTPnoFailure()
|
||||
|
||||
@@ -74,8 +74,6 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
|
||||
if (shouldFail) {
|
||||
// This should be a failed run
|
||||
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
|
||||
// Wait for write sequence to complete. We should get:
|
||||
// inProgressChanged(false) signal
|
||||
// error(errorCode, QString) signal
|
||||
@@ -89,9 +87,7 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
|
||||
QSignalSpy* spy = _multiSpyMissionManager->getSpyByIndex(errorSignalIndex);
|
||||
QList<QVariant> signalArgs = spy->takeFirst();
|
||||
QCOMPARE(signalArgs.count(), 2);
|
||||
qDebug() << signalArgs[1].toString();
|
||||
|
||||
checkExpectedMessageBox();
|
||||
qCDebug(UnitTestLog) << signalArgs[1].toString();
|
||||
} else {
|
||||
// This should be clean run
|
||||
|
||||
@@ -137,8 +133,6 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
|
||||
if (shouldFail) {
|
||||
// This should be a failed run
|
||||
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
|
||||
// Wait for read sequence to complete. We should get:
|
||||
// inProgressChanged(false) signal to signal completion
|
||||
// error(errorCode, QString) signal
|
||||
@@ -153,9 +147,7 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
|
||||
QSignalSpy* spy = _multiSpyMissionManager->getSpyByIndex(errorSignalIndex);
|
||||
QList<QVariant> signalArgs = spy->takeFirst();
|
||||
QCOMPARE(signalArgs.count(), 2);
|
||||
qDebug() << signalArgs[1].toString();
|
||||
|
||||
checkExpectedMessageBox();
|
||||
qCDebug(UnitTestLog) << signalArgs[1].toString();
|
||||
} else {
|
||||
// This should be clean run
|
||||
|
||||
@@ -203,7 +195,7 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
|
||||
|
||||
MissionItem* actual = _missionManager->missionItems()[actualItemIndex];
|
||||
|
||||
qDebug() << "Test case" << testCaseIndex;
|
||||
qCDebug(UnitTestLog) << "Test case" << testCaseIndex;
|
||||
QCOMPARE(actual->sequenceNumber(), expectedSequenceNumber);
|
||||
QCOMPARE(actual->coordinate().latitude(), testCase->expectedItem.coordinate.latitude());
|
||||
QCOMPARE(actual->coordinate().longitude(), testCase->expectedItem.coordinate.longitude());
|
||||
@@ -256,7 +248,7 @@ void MissionManagerTest::_testWriteFailureHandlingWorker(void)
|
||||
|
||||
for (size_t i=0; i<sizeof(rgTestCases)/sizeof(rgTestCases[0]); i++) {
|
||||
const WriteTestCase_t* pCase = &rgTestCases[i];
|
||||
qDebug() << "TEST CASE _testWriteFailureHandlingWorker" << pCase->failureText;
|
||||
qCDebug(UnitTestLog) << "TEST CASE _testWriteFailureHandlingWorker" << pCase->failureText;
|
||||
_writeItems(pCase->failureMode, MAV_MISSION_ERROR, pCase->shouldFail);
|
||||
_mockLink->resetMissionItemHandler();
|
||||
}
|
||||
@@ -301,7 +293,7 @@ void MissionManagerTest::_testReadFailureHandlingWorker(void)
|
||||
|
||||
for (size_t i=0; i<sizeof(rgTestCases)/sizeof(rgTestCases[0]); i++) {
|
||||
const ReadTestCase_t* pCase = &rgTestCases[i];
|
||||
qDebug() << "TEST CASE _testReadFailureHandlingWorker" << pCase->failureText;
|
||||
qCDebug(UnitTestLog) << "TEST CASE _testReadFailureHandlingWorker" << pCase->failureText;
|
||||
_roundTripItems(pCase->failureMode, MAV_MISSION_ERROR, pCase->shouldFail);
|
||||
_mockLink->resetMissionItemHandler();
|
||||
_multiSpyMissionManager->clearAllSignals();
|
||||
@@ -357,7 +349,7 @@ void MissionManagerTest::_testErrorAckFailureStrings(void)
|
||||
|
||||
for (size_t i=0; i<sizeof(rgTestCases)/sizeof(rgTestCases[0]); i++) {
|
||||
const ErrorStringTestCase_t* pCase = &rgTestCases[i];
|
||||
qDebug() << "TEST CASE _testErrorAckFailureStrings" << pCase->ackResultStr;
|
||||
qCDebug(UnitTestLog) << "TEST CASE _testErrorAckFailureStrings" << pCase->ackResultStr;
|
||||
_writeItems(MockLinkMissionItemHandler::FailWriteRequest1ErrorAck, pCase->ackResult, true /* shouldFail */);
|
||||
_mockLink->resetMissionItemHandler();
|
||||
}
|
||||
|
||||
@@ -210,17 +210,11 @@ void QGCMapPolygonTest::_testKMLLoad(void)
|
||||
{
|
||||
QVERIFY(_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonGood.kml")));
|
||||
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
QVERIFY(!_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonBadXml.kml")));
|
||||
checkExpectedMessageBox();
|
||||
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
QVERIFY(!_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonMissingNode.kml")));
|
||||
checkExpectedMessageBox();
|
||||
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
QVERIFY(!_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonBadCoordinatesNode.kml")));
|
||||
checkExpectedMessageBox();
|
||||
}
|
||||
|
||||
void QGCMapPolygonTest::_testSelectVertex(void)
|
||||
|
||||
@@ -79,9 +79,6 @@
|
||||
// qgcunittest
|
||||
#include "ComponentInformationCacheTest.h"
|
||||
#include "ComponentInformationTranslationTest.h"
|
||||
// #include "FileDialogTest.h"
|
||||
// #include "MainWindowTest.h"
|
||||
// #include "MessageBoxTest.h"
|
||||
|
||||
// QmlControls
|
||||
|
||||
@@ -183,9 +180,6 @@ int runTests(bool stress, QStringView unitTestOptions)
|
||||
// UT_REGISTER_TEST(VisualMissionItemTest)
|
||||
|
||||
// qgcunittest
|
||||
// UT_REGISTER_TEST(FileDialogTest)
|
||||
// UT_REGISTER_TEST(MainWindowTest)
|
||||
// UT_REGISTER_TEST(MessageBoxTest)
|
||||
|
||||
// QmlControls
|
||||
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Positioning Test Widgets)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Positioning Test)
|
||||
|
||||
qt_add_library(qgcunittest
|
||||
STATIC
|
||||
# FileDialogTest.cc
|
||||
# FileDialogTest.h
|
||||
# MainWindowTest.cc
|
||||
# MainWindowTest.h
|
||||
# MessageBoxTest.cc
|
||||
# MessageBoxTest.h
|
||||
MultiSignalSpy.cc
|
||||
MultiSignalSpy.h
|
||||
MultiSignalSpyV2.cc
|
||||
@@ -27,7 +21,6 @@ target_link_libraries(qgcunittest
|
||||
Qt6::Core
|
||||
Qt6::Positioning
|
||||
Qt6::Test
|
||||
Qt6::Widgets
|
||||
MAVLink
|
||||
MockLink
|
||||
)
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Unit test for QGCQFileDialog catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include "FileDialogTest.h"
|
||||
#include "QGCQFileDialog.h"
|
||||
|
||||
FileDialogTest::FileDialogTest(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FileDialogTest::_fileDialogExpected_test(void)
|
||||
{
|
||||
QStringList response;
|
||||
response << "" << "response";
|
||||
|
||||
for (int i=0; i<response.count(); i++) {
|
||||
setExpectedFileDialog(getExistingDirectory, QStringList(response[i]));
|
||||
QCOMPARE(QGCQFileDialog::getExistingDirectory(), response[i]);
|
||||
checkExpectedFileDialog();
|
||||
}
|
||||
|
||||
for (int i=0; i<response.count(); i++) {
|
||||
setExpectedFileDialog(getOpenFileName, QStringList(response[i]));
|
||||
QCOMPARE(QGCQFileDialog::getOpenFileName(), response[i]);
|
||||
checkExpectedFileDialog();
|
||||
}
|
||||
|
||||
for (int i=0; i<response.count(); i++) {
|
||||
setExpectedFileDialog(getSaveFileName, QStringList(response[i]));
|
||||
QCOMPARE(QGCQFileDialog::getSaveFileName(), response[i]);
|
||||
checkExpectedFileDialog();
|
||||
}
|
||||
|
||||
QList<QStringList> responseList;
|
||||
QStringList list;
|
||||
|
||||
responseList.append(QStringList());
|
||||
responseList.append(QStringList("response1"));
|
||||
list << "response1" << "response2";
|
||||
responseList.append(list);
|
||||
|
||||
for (int i=0; i<responseList.count(); i++) {
|
||||
setExpectedFileDialog(getOpenFileNames, responseList[i]);
|
||||
QStringList retResponse = QGCQFileDialog::getOpenFileNames();
|
||||
checkExpectedFileDialog();
|
||||
QCOMPARE(retResponse.count(), responseList[i].count());
|
||||
for (int j=0; j<retResponse.count(); j++) {
|
||||
QCOMPARE(retResponse[j], responseList[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileDialogTest::_fileDialogUnexpected_test(void)
|
||||
{
|
||||
// This should cause an expected failure in the cleanup method
|
||||
QGCQFileDialog::getOpenFileName();
|
||||
_expectMissedFileDialog = true;
|
||||
}
|
||||
|
||||
void FileDialogTest::_previousFileDialog_test(void)
|
||||
{
|
||||
// This is the previous unexpected file dialog
|
||||
QGCQFileDialog::getOpenFileName();
|
||||
|
||||
// Setup for an expected message box.
|
||||
QEXPECT_FAIL("", "Expecting failure due to previous file dialog", Continue);
|
||||
setExpectedFileDialog(getOpenFileName, QStringList());
|
||||
}
|
||||
|
||||
void FileDialogTest::_noFileDialog_test(void)
|
||||
{
|
||||
setExpectedFileDialog(getOpenFileName, QStringList());
|
||||
checkExpectedFileDialog(expectFailNoDialog);
|
||||
}
|
||||
|
||||
void FileDialogTest::_fileDialogExpectedIncorrect_test(void)
|
||||
{
|
||||
// Expecting save but get open dialog
|
||||
setExpectedFileDialog(getSaveFileName, QStringList());
|
||||
QGCQFileDialog::getOpenFileName();
|
||||
checkExpectedFileDialog(expectFailWrongFileDialog);
|
||||
|
||||
// This is going to fail in cleanup as well since we have a missed file dialog
|
||||
_expectMissedFileDialog = true;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Unit test for QGCQFileDialog catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "UnitTest.h"
|
||||
|
||||
class FileDialogTest : public UnitTest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FileDialogTest(void);
|
||||
|
||||
private slots:
|
||||
void _fileDialogExpected_test(void);
|
||||
void _fileDialogUnexpected_test(void);
|
||||
void _previousFileDialog_test(void);
|
||||
void _noFileDialog_test(void);
|
||||
void _fileDialogExpectedIncorrect_test(void);
|
||||
};
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Simple MainWindow unit test
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include "MainWindowTest.h"
|
||||
#include "MainWindow.h"
|
||||
#include "QGCMessageBox.h"
|
||||
#include "MultiVehicleManager.h"
|
||||
|
||||
void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot)
|
||||
{
|
||||
_createMainWindow();
|
||||
_connectMockLink(autopilot);
|
||||
|
||||
// On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing.
|
||||
setExpectedMessageBox(QGCMessageBox::Cancel);
|
||||
_closeMainWindow(true /* cancelExpected */);
|
||||
checkExpectedMessageBox();
|
||||
}
|
||||
|
||||
void MainWindowTest::_connectWindowClosePX4_test(void) {
|
||||
_connectWindowClose_test(MAV_AUTOPILOT_PX4);
|
||||
}
|
||||
|
||||
void MainWindowTest::_connectWindowCloseGeneric_test(void) {
|
||||
_connectWindowClose_test(MAV_AUTOPILOT_ARDUPILOTMEGA);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Simple MainWindow unit test
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "UnitTest.h"
|
||||
#include "MAVLinkLib.h"
|
||||
|
||||
class MainWindowTest : public UnitTest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void _connectWindowClosePX4_test(void);
|
||||
void _connectWindowCloseGeneric_test(void);
|
||||
|
||||
private:
|
||||
void _connectWindowClose_test(MAV_AUTOPILOT autopilot);
|
||||
};
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Unit test for QGCMessageBox catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include "MessageBoxTest.h"
|
||||
#include "QGCMessageBox.h"
|
||||
|
||||
MessageBoxTest::MessageBoxTest(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MessageBoxTest::_messageBoxExpected_test(void)
|
||||
{
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
|
||||
QCOMPARE(QGCMessageBox::information(QString(), QString()), QMessageBox::Ok);
|
||||
|
||||
checkExpectedMessageBox();
|
||||
}
|
||||
|
||||
void MessageBoxTest::_messageBoxUnexpected_test(void)
|
||||
{
|
||||
// This should cause an expected failure in the cleanup method
|
||||
QGCMessageBox::information(QString(), QString());
|
||||
_expectMissedMessageBox = true;
|
||||
}
|
||||
|
||||
void MessageBoxTest::_previousMessageBox_test(void)
|
||||
{
|
||||
// This is the previous unexpected message box
|
||||
QGCMessageBox::information(QString(), QString());
|
||||
|
||||
// Setup for an expected message box.
|
||||
QEXPECT_FAIL("", "Expecting failure due to previous message boxes", Continue);
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
}
|
||||
|
||||
void MessageBoxTest::_noMessageBox_test(void)
|
||||
{
|
||||
setExpectedMessageBox(QMessageBox::Ok);
|
||||
checkExpectedMessageBox(expectFailNoDialog);
|
||||
}
|
||||
|
||||
void MessageBoxTest::_badResponseButton_test(void)
|
||||
{
|
||||
setExpectedMessageBox(QMessageBox::Cancel);
|
||||
|
||||
// Will return Ok even though Cancel was specified, since that was wrong
|
||||
QCOMPARE(QGCMessageBox::information(QString(), QString()), QMessageBox::Ok);
|
||||
|
||||
checkExpectedMessageBox(expectFailBadResponseButton);
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
*
|
||||
* QGroundControl is licensed according to the terms in the file
|
||||
* COPYING.md in the root of the source code directory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/// @file
|
||||
/// @brief Unit test for QGCMessageBox catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "UnitTest.h"
|
||||
|
||||
class MessageBoxTest : public UnitTest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MessageBoxTest(void);
|
||||
|
||||
private slots:
|
||||
void _messageBoxExpected_test(void);
|
||||
void _messageBoxUnexpected_test(void);
|
||||
void _previousMessageBox_test(void);
|
||||
void _noMessageBox_test(void);
|
||||
void _badResponseButton_test(void);
|
||||
};
|
||||
|
||||
+33
-298
@@ -17,24 +17,17 @@
|
||||
#include "QGC.h"
|
||||
#include "Fact.h"
|
||||
#include "MissionItem.h"
|
||||
#include "QGCLoggingCategory.h"
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <QtTest/QSignalSpy>
|
||||
|
||||
bool UnitTest::_messageBoxRespondedTo = false;
|
||||
bool UnitTest::_badResponseButton = false;
|
||||
QMessageBox::StandardButton UnitTest::_messageBoxResponseButton = QMessageBox::NoButton;
|
||||
int UnitTest::_missedMessageBoxCount = 0;
|
||||
QGC_LOGGING_CATEGORY(UnitTestLog, "qgc.test.qgcunittest.unittest")
|
||||
|
||||
bool UnitTest::_fileDialogRespondedTo = false;
|
||||
bool UnitTest::_fileDialogResponseSet = false;
|
||||
QStringList UnitTest::_fileDialogResponse;
|
||||
enum UnitTest::FileDialogType UnitTest::_fileDialogExpectedType = getOpenFileName;
|
||||
int UnitTest::_missedFileDialogCount = 0;
|
||||
|
||||
UnitTest::UnitTest(void)
|
||||
UnitTest::UnitTest(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
// qCDebug(UnitTestLog) << Q_FUNC_INFO << this;
|
||||
}
|
||||
|
||||
UnitTest::~UnitTest()
|
||||
@@ -44,24 +37,20 @@ UnitTest::~UnitTest()
|
||||
Q_ASSERT(_initCalled);
|
||||
Q_ASSERT(_cleanupCalled);
|
||||
}
|
||||
|
||||
// qCDebug(UnitTestLog) << Q_FUNC_INFO << this;
|
||||
}
|
||||
|
||||
void UnitTest::_addTest(UnitTest* test)
|
||||
void UnitTest::_addTest(UnitTest *test)
|
||||
{
|
||||
QList<UnitTest*>& tests = _testList();
|
||||
QList<UnitTest*> &tests = _testList();
|
||||
|
||||
Q_ASSERT(!tests.contains(test));
|
||||
|
||||
tests.append(test);
|
||||
}
|
||||
|
||||
void UnitTest::_unitTestCalled(void)
|
||||
{
|
||||
_unitTestRun = true;
|
||||
}
|
||||
|
||||
/// @brief Returns the list of unit tests.
|
||||
QList<UnitTest*>& UnitTest::_testList(void)
|
||||
QList<UnitTest*> &UnitTest::_testList()
|
||||
{
|
||||
static QList<UnitTest*> tests;
|
||||
return tests;
|
||||
@@ -71,7 +60,7 @@ int UnitTest::run(QStringView singleTest)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
for (UnitTest* test: _testList()) {
|
||||
for (UnitTest *test: _testList()) {
|
||||
if (singleTest.isEmpty() || singleTest == test->objectName()) {
|
||||
if (test->standalone() && singleTest.isEmpty()) {
|
||||
continue;
|
||||
@@ -85,53 +74,26 @@ int UnitTest::run(QStringView singleTest)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// @brief Called before each test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::init(void)
|
||||
void UnitTest::init()
|
||||
{
|
||||
_initCalled = true;
|
||||
|
||||
LinkManager::instance()->setConnectionsAllowed();
|
||||
|
||||
// Force offline vehicle back to defaults
|
||||
AppSettings* appSettings = SettingsManager::instance()->appSettings();
|
||||
AppSettings *const appSettings = SettingsManager::instance()->appSettings();
|
||||
appSettings->offlineEditingFirmwareClass()->setRawValue(appSettings->offlineEditingFirmwareClass()->rawDefaultValue());
|
||||
appSettings->offlineEditingVehicleClass()->setRawValue(appSettings->offlineEditingVehicleClass()->rawDefaultValue());
|
||||
|
||||
_messageBoxRespondedTo = false;
|
||||
_missedMessageBoxCount = 0;
|
||||
_badResponseButton = false;
|
||||
_messageBoxResponseButton = QMessageBox::NoButton;
|
||||
|
||||
_fileDialogRespondedTo = false;
|
||||
_missedFileDialogCount = 0;
|
||||
_fileDialogResponseSet = false;
|
||||
_fileDialogResponse.clear();
|
||||
|
||||
_expectMissedFileDialog = false;
|
||||
_expectMissedMessageBox = false;
|
||||
|
||||
MAVLinkProtocol::deleteTempLogFiles();
|
||||
}
|
||||
|
||||
/// @brief Called after each test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::cleanup(void)
|
||||
void UnitTest::cleanup()
|
||||
{
|
||||
_cleanupCalled = true;
|
||||
|
||||
_disconnectMockLink();
|
||||
|
||||
// Keep in mind that any code below these QCOMPARE may be skipped if the compare fails
|
||||
if (_expectMissedMessageBox) {
|
||||
QEXPECT_FAIL("", "Expecting failure due internal testing", Continue);
|
||||
}
|
||||
QCOMPARE(_missedMessageBoxCount, 0);
|
||||
if (_expectMissedFileDialog) {
|
||||
QEXPECT_FAIL("", "Expecting failure due internal testing", Continue);
|
||||
}
|
||||
QCOMPARE(_missedFileDialogCount, 0);
|
||||
|
||||
// Don't let any lingering signals or events cross to the next unit test.
|
||||
// If you have a failure whose stack trace points to this then
|
||||
// your test is leaking signals or events. It could cause use-after-free or
|
||||
@@ -139,233 +101,6 @@ void UnitTest::cleanup(void)
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
void UnitTest::setExpectedMessageBox(QMessageBox::StandardButton response)
|
||||
{
|
||||
//-- TODO
|
||||
#if 0
|
||||
// This means that there was an expected message box but no call to checkExpectedMessageBox
|
||||
Q_ASSERT(!_messageBoxRespondedTo);
|
||||
|
||||
Q_ASSERT(response != QMessageBox::NoButton);
|
||||
Q_ASSERT(_messageBoxResponseButton == QMessageBox::NoButton);
|
||||
|
||||
// Make sure we haven't missed any previous message boxes
|
||||
int missedMessageBoxCount = _missedMessageBoxCount;
|
||||
QCOMPARE(missedMessageBoxCount, 0);
|
||||
#endif
|
||||
_missedMessageBoxCount = 0;
|
||||
_messageBoxResponseButton = response;
|
||||
}
|
||||
|
||||
void UnitTest::setExpectedFileDialog(enum FileDialogType type, QStringList response)
|
||||
{
|
||||
//-- TODO
|
||||
#if 0
|
||||
// This means that there was an expected file dialog but no call to checkExpectedFileDialog
|
||||
Q_ASSERT(!_fileDialogRespondedTo);
|
||||
|
||||
// Multiple responses must be expected getOpenFileNames
|
||||
Q_ASSERT(response.count() <= 1 || type == getOpenFileNames);
|
||||
|
||||
// Make sure we haven't missed any previous file dialogs
|
||||
int missedFileDialogCount = _missedFileDialogCount;
|
||||
_missedFileDialogCount = 0;
|
||||
QCOMPARE(missedFileDialogCount, 0);
|
||||
#endif
|
||||
_fileDialogResponseSet = true;
|
||||
_fileDialogResponse = response;
|
||||
_fileDialogExpectedType = type;
|
||||
}
|
||||
|
||||
void UnitTest::checkExpectedMessageBox(int expectFailFlags)
|
||||
{
|
||||
// Previous call to setExpectedMessageBox should have already checked this
|
||||
Q_ASSERT(_missedMessageBoxCount == 0);
|
||||
|
||||
// Check for a valid response
|
||||
|
||||
if (expectFailFlags & expectFailBadResponseButton) {
|
||||
QEXPECT_FAIL("", "Expecting failure due to bad button response", Continue);
|
||||
}
|
||||
QCOMPARE(_badResponseButton, false);
|
||||
|
||||
if (expectFailFlags & expectFailNoDialog) {
|
||||
QEXPECT_FAIL("", "Expecting failure due to no message box", Continue);
|
||||
}
|
||||
|
||||
// Clear this flag before QCOMPARE since anything after QCOMPARE will be skipped on failure
|
||||
|
||||
//-- TODO
|
||||
// bool messageBoxRespondedTo = _messageBoxRespondedTo;
|
||||
// QCOMPARE(messageBoxRespondedTo, true);
|
||||
_messageBoxRespondedTo = false;
|
||||
}
|
||||
|
||||
void UnitTest::checkMultipleExpectedMessageBox(int messageCount)
|
||||
{
|
||||
int missedMessageBoxCount = _missedMessageBoxCount;
|
||||
_missedMessageBoxCount = 0;
|
||||
QCOMPARE(missedMessageBoxCount, messageCount);
|
||||
}
|
||||
|
||||
void UnitTest::checkExpectedFileDialog(int expectFailFlags)
|
||||
{
|
||||
// Internal testing
|
||||
|
||||
if (expectFailFlags & expectFailNoDialog) {
|
||||
QEXPECT_FAIL("", "Expecting failure due to no file dialog", Continue);
|
||||
}
|
||||
if (expectFailFlags & expectFailWrongFileDialog) {
|
||||
QEXPECT_FAIL("", "Expecting failure due to incorrect file dialog", Continue);
|
||||
} else {
|
||||
// Previous call to setExpectedFileDialog should have already checked this
|
||||
Q_ASSERT(_missedFileDialogCount == 0);
|
||||
}
|
||||
|
||||
// Clear this flag before QCOMPARE since anything after QCOMPARE will be skipped on failure
|
||||
bool fileDialogRespondedTo = _fileDialogRespondedTo;
|
||||
_fileDialogRespondedTo = false;
|
||||
|
||||
QCOMPARE(fileDialogRespondedTo, true);
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton UnitTest::_messageBox(QMessageBox::Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
|
||||
{
|
||||
QMessageBox::StandardButton retButton;
|
||||
|
||||
Q_UNUSED(icon);
|
||||
Q_UNUSED(title);
|
||||
Q_UNUSED(text);
|
||||
|
||||
if (_messageBoxResponseButton == QMessageBox::NoButton) {
|
||||
// If no response button is set it means we were not expecting this message box. Response with default
|
||||
_missedMessageBoxCount++;
|
||||
retButton = defaultButton;
|
||||
} else {
|
||||
if (_messageBoxResponseButton & buttons) {
|
||||
// Everything is correct, use the specified response
|
||||
retButton = _messageBoxResponseButton;
|
||||
} else {
|
||||
// Trying to respond with a button not in the dialog. This is an error. Respond with default
|
||||
_badResponseButton = true;
|
||||
retButton = defaultButton;
|
||||
}
|
||||
_messageBoxRespondedTo = true;
|
||||
}
|
||||
|
||||
// Clear response for next message box
|
||||
_messageBoxResponseButton = QMessageBox::NoButton;
|
||||
|
||||
return retButton;
|
||||
}
|
||||
|
||||
/// @brief Response to a file dialog which returns a single file
|
||||
QString UnitTest::_fileDialogResponseSingle(enum FileDialogType type)
|
||||
{
|
||||
QString retFile;
|
||||
|
||||
if (!_fileDialogResponseSet || _fileDialogExpectedType != type) {
|
||||
// If no response is set or the type does not match what we expected it means we were not expecting this file dialog.
|
||||
// Respond with no selection.
|
||||
_missedFileDialogCount++;
|
||||
} else {
|
||||
Q_ASSERT(_fileDialogResponse.count() <= 1);
|
||||
if (_fileDialogResponse.count() == 1) {
|
||||
retFile = _fileDialogResponse[0];
|
||||
}
|
||||
_fileDialogRespondedTo = true;
|
||||
}
|
||||
|
||||
// Clear response for next message box
|
||||
_fileDialogResponse.clear();
|
||||
_fileDialogResponseSet = false;
|
||||
|
||||
return retFile;
|
||||
}
|
||||
|
||||
QString UnitTest::_getExistingDirectory(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_UNUSED(caption);
|
||||
Q_UNUSED(dir);
|
||||
Q_UNUSED(options);
|
||||
|
||||
return _fileDialogResponseSingle(getExistingDirectory);
|
||||
}
|
||||
|
||||
QString UnitTest::_getOpenFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_UNUSED(caption);
|
||||
Q_UNUSED(dir);
|
||||
Q_UNUSED(filter);
|
||||
Q_UNUSED(options);
|
||||
|
||||
return _fileDialogResponseSingle(getOpenFileName);
|
||||
}
|
||||
|
||||
QStringList UnitTest::_getOpenFileNames(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_UNUSED(caption);
|
||||
Q_UNUSED(dir);
|
||||
Q_UNUSED(filter);
|
||||
Q_UNUSED(options);
|
||||
|
||||
QStringList retFiles;
|
||||
|
||||
if (!_fileDialogResponseSet || _fileDialogExpectedType != getOpenFileNames) {
|
||||
// If no response is set or the type does not match what we expected it means we were not expecting this file dialog.
|
||||
// Respond with no selection.
|
||||
_missedFileDialogCount++;
|
||||
retFiles.clear();
|
||||
} else {
|
||||
retFiles = _fileDialogResponse;
|
||||
_fileDialogRespondedTo = true;
|
||||
}
|
||||
|
||||
// Clear response for next message box
|
||||
_fileDialogResponse.clear();
|
||||
_fileDialogResponseSet = false;
|
||||
|
||||
return retFiles;
|
||||
}
|
||||
|
||||
QString UnitTest::_getSaveFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
const QString& defaultSuffix,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_UNUSED(caption);
|
||||
Q_UNUSED(dir);
|
||||
Q_UNUSED(filter);
|
||||
Q_UNUSED(options);
|
||||
|
||||
if(!defaultSuffix.isEmpty()) {
|
||||
Q_ASSERT(defaultSuffix.startsWith(".") == false);
|
||||
}
|
||||
|
||||
return _fileDialogResponseSingle(getSaveFileName);
|
||||
}
|
||||
|
||||
void UnitTest::_connectMockLink(MAV_AUTOPILOT autopilot, MockConfiguration::FailureMode_t failureMode)
|
||||
{
|
||||
Q_ASSERT(!_mockLink);
|
||||
@@ -386,7 +121,7 @@ void UnitTest::_connectMockLink(MAV_AUTOPILOT autopilot, MockConfiguration::Fail
|
||||
_mockLink = MockLink::startNoInitialConnectMockLink(false);
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Type not supported";
|
||||
qCWarning(UnitTestLog) << "Type not supported";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -402,7 +137,7 @@ void UnitTest::_connectMockLink(MAV_AUTOPILOT autopilot, MockConfiguration::Fail
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTest::_disconnectMockLink(void)
|
||||
void UnitTest::_disconnectMockLink()
|
||||
{
|
||||
if (_mockLink) {
|
||||
QSignalSpy spyVehicle(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged);
|
||||
@@ -417,29 +152,29 @@ void UnitTest::_disconnectMockLink(void)
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTest::_linkDeleted(LinkInterface* link)
|
||||
void UnitTest::_linkDeleted(const LinkInterface *link)
|
||||
{
|
||||
if (link == _mockLink) {
|
||||
_mockLink = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool UnitTest::fileCompare(const QString& file1, const QString& file2)
|
||||
bool UnitTest::fileCompare(const QString &file1, const QString &file2)
|
||||
{
|
||||
QFile f1(file1);
|
||||
QFile f2(file2);
|
||||
|
||||
if (QFileInfo(file1).size() != QFileInfo(file2).size()) {
|
||||
qWarning() << "UnitTest::fileCompare file sizes differ size1:size2" << QFileInfo(file1).size() << QFileInfo(file2).size();
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare file sizes differ size1:size2" << QFileInfo(file1).size() << QFileInfo(file2).size();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!f1.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "UnitTest::fileCompare unable to open file1:" << f1.errorString();
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare unable to open file1:" << f1.errorString();
|
||||
return false;
|
||||
}
|
||||
if (!f2.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "UnitTest::fileCompare unable to open file1:" << f1.errorString();
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare unable to open file1:" << f1.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -448,19 +183,19 @@ bool UnitTest::fileCompare(const QString& file1, const QString& file2)
|
||||
while (bytesRemaining) {
|
||||
uint8_t b1, b2;
|
||||
|
||||
qint64 bytesRead = f1.read((char*)&b1, 1);
|
||||
qint64 bytesRead = f1.read(reinterpret_cast<char*>(&b1), 1);
|
||||
if (bytesRead != 1) {
|
||||
qWarning() << "UnitTest::fileCompare file1 read failed:" << f1.errorString();
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare file1 read failed:" << f1.errorString();
|
||||
return false;
|
||||
}
|
||||
bytesRead = f2.read((char*)&b2, 1);
|
||||
bytesRead = f2.read(reinterpret_cast<char*>(&b2), 1);
|
||||
if (bytesRead != 1) {
|
||||
qWarning() << "UnitTest::fileCompare file2 read failed:" << f2.errorString();
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare file2 read failed:" << f2.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (b1 != b2) {
|
||||
qWarning() << "UnitTest::fileCompare mismatch offset:b1:b2" << offset << b1 << b2;
|
||||
qCWarning(UnitTestLog) << "UnitTest::fileCompare mismatch offset:b1:b2" << offset << b1 << b2;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -471,7 +206,7 @@ bool UnitTest::fileCompare(const QString& file1, const QString& file2)
|
||||
return true;
|
||||
}
|
||||
|
||||
void UnitTest::changeFactValue(Fact* fact,double increment)
|
||||
void UnitTest::changeFactValue(Fact *fact, double increment)
|
||||
{
|
||||
if (fact->typeIsBool()) {
|
||||
fact->setRawValue(!fact->rawValue().toBool());
|
||||
@@ -483,11 +218,11 @@ void UnitTest::changeFactValue(Fact* fact,double increment)
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTest::_missionItemsEqual(MissionItem& actual, MissionItem& expected)
|
||||
void UnitTest::_missionItemsEqual(const MissionItem &actual, const MissionItem &expected)
|
||||
{
|
||||
QCOMPARE(static_cast<int>(actual.command()), static_cast<int>(expected.command()));
|
||||
QCOMPARE(static_cast<int>(actual.frame()), static_cast<int>(expected.frame()));
|
||||
QCOMPARE(actual.autoContinue(), expected.autoContinue());
|
||||
QCOMPARE(static_cast<int>(actual.command()), static_cast<int>(expected.command()));
|
||||
QCOMPARE(static_cast<int>(actual.frame()), static_cast<int>(expected.frame()));
|
||||
QCOMPARE(actual.autoContinue(), expected.autoContinue());
|
||||
|
||||
QVERIFY(QGC::fuzzyCompare(actual.param1(), expected.param1()));
|
||||
QVERIFY(QGC::fuzzyCompare(actual.param2(), expected.param2()));
|
||||
@@ -498,12 +233,12 @@ void UnitTest::_missionItemsEqual(MissionItem& actual, MissionItem& expected)
|
||||
QVERIFY(QGC::fuzzyCompare(actual.param7(), expected.param7()));
|
||||
}
|
||||
|
||||
bool UnitTest::fuzzyCompareLatLon(const QGeoCoordinate& coord1, const QGeoCoordinate& coord2)
|
||||
bool UnitTest::fuzzyCompareLatLon(const QGeoCoordinate &coord1, const QGeoCoordinate &coord2)
|
||||
{
|
||||
return coord1.distanceTo(coord2) < 1.0;
|
||||
}
|
||||
|
||||
QGeoCoordinate UnitTest::changeCoordinateValue(const QGeoCoordinate& coordinate)
|
||||
QGeoCoordinate UnitTest::changeCoordinateValue(const QGeoCoordinate &coordinate)
|
||||
{
|
||||
return coordinate.atDistanceAndAzimuth(1, 0);
|
||||
}
|
||||
|
||||
+30
-126
@@ -12,16 +12,15 @@
|
||||
#include "MockLink.h"
|
||||
#include "MAVLinkLib.h"
|
||||
|
||||
#include <QtCore/QLoggingCategory>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtPositioning/QGeoCoordinate>
|
||||
|
||||
#define UT_REGISTER_TEST(className) static UnitTestWrapper<className> className(#className, false);
|
||||
#define UT_REGISTER_TEST_STANDALONE(className) static UnitTestWrapper<className> className(#className, true); // Test will only be run with specifically called to from command line
|
||||
#define UT_REGISTER_TEST(className) static UnitTestWrapper<className> className(#className, false);
|
||||
#define UT_REGISTER_TEST_STANDALONE(className) static UnitTestWrapper<className> className(#className, true); // Test will only be run with specifically called to from command line
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(UnitTestLog)
|
||||
|
||||
class QGCMessageBox;
|
||||
class QGCQFileDialog;
|
||||
class Vehicle;
|
||||
class Fact;
|
||||
class LinkInterface;
|
||||
@@ -32,169 +31,74 @@ class UnitTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UnitTest(void);
|
||||
virtual ~UnitTest(void);
|
||||
UnitTest(QObject *parent = nullptr);
|
||||
virtual ~UnitTest();
|
||||
|
||||
/// @brief Called to run all the registered unit tests
|
||||
/// @param singleTest Name of test to just run a single test
|
||||
static int run(QStringView singleTest);
|
||||
|
||||
/// @brief Sets up for an expected QGCMessageBox
|
||||
/// @param response Response to take on message box
|
||||
void setExpectedMessageBox(QMessageBox::StandardButton response);
|
||||
|
||||
/// @brief Types for UnitTest::setExpectedFileDialog
|
||||
enum FileDialogType {
|
||||
getExistingDirectory,
|
||||
getOpenFileName,
|
||||
getOpenFileNames,
|
||||
getSaveFileName
|
||||
};
|
||||
|
||||
/// @brief Sets up for an expected QGCQFileDialog
|
||||
/// @param type Type of expected file dialog
|
||||
/// @param response Files to return from call. Multiple files only supported by getOpenFileNames
|
||||
void setExpectedFileDialog(enum FileDialogType type, QStringList response);
|
||||
|
||||
enum {
|
||||
expectFailNoFailure = 1 << 0, ///< not expecting any failures
|
||||
expectFailNoDialog = 1 << 1, ///< expecting a failure due to no dialog displayed
|
||||
expectFailBadResponseButton = 1 << 2, ///< expecting a failure due to bad button response (QGCMessageBox only)
|
||||
expectFailWrongFileDialog = 1 << 3 ///< expecting one dialog type, got the wrong type (QGCQFileDialog ony)
|
||||
};
|
||||
|
||||
/// @brief Check whether a message box was displayed and correctly responded to
|
||||
// @param Expected failure response flags
|
||||
void checkExpectedMessageBox(int expectFailFlags = expectFailNoFailure);
|
||||
|
||||
/// Checks that the specified number of message boxes where shown. Do not call setExpectedMessageBox when using this method.
|
||||
void checkMultipleExpectedMessageBox(int messageCount);
|
||||
|
||||
/// @brief Check whether a message box was displayed and correctly responded to
|
||||
// @param Expected failure response flags
|
||||
void checkExpectedFileDialog(int expectFailFlags = expectFailNoFailure);
|
||||
|
||||
bool standalone(void) const{ return _standalone; }
|
||||
bool standalone() const { return _standalone; }
|
||||
void setStandalone(bool standalone) { _standalone = standalone; }
|
||||
|
||||
/// @brief Adds a unit test to the list. Should only be called by UnitTestWrapper.
|
||||
static void _addTest(UnitTest* test);
|
||||
static void _addTest(UnitTest *test);
|
||||
|
||||
/// Will throw qWarning at location where files differ
|
||||
/// @return true: files are alike, false: files differ
|
||||
static bool fileCompare(const QString& file1, const QString& file2);
|
||||
static bool fileCompare(const QString &file1, const QString &file2);
|
||||
|
||||
/// Changes the Facts rawValue such that it emits a valueChanged signal.
|
||||
/// @param increment 0 use standard increment, other increment by specified amount if double value
|
||||
void changeFactValue(Fact* fact, double increment = 0);
|
||||
void changeFactValue(Fact *fact, double increment = 0);
|
||||
|
||||
QGeoCoordinate changeCoordinateValue(const QGeoCoordinate& coordinate);
|
||||
QGeoCoordinate changeCoordinateValue(const QGeoCoordinate &coordinate);
|
||||
|
||||
/// Returns true is the position of the two coordinates is less then a meter from each other.
|
||||
/// Does not check altitude.
|
||||
static bool fuzzyCompareLatLon(const QGeoCoordinate& coord1, const QGeoCoordinate& coord2);
|
||||
static bool fuzzyCompareLatLon(const QGeoCoordinate &coord1, const QGeoCoordinate &coord2);
|
||||
|
||||
protected slots:
|
||||
|
||||
// These are all pure virtuals to force the derived class to implement each one and in turn
|
||||
// call the UnitTest private implementation.
|
||||
|
||||
/// @brief Called before each test.
|
||||
/// Make sure to call UnitTest::init first in your derived class.
|
||||
virtual void init(void);
|
||||
virtual void init();
|
||||
|
||||
/// @brief Called after each test.
|
||||
/// Make sure to call UnitTest::cleanup last in your derived class.
|
||||
virtual void cleanup(void);
|
||||
virtual void cleanup();
|
||||
|
||||
protected:
|
||||
void _connectMockLink(MAV_AUTOPILOT autopilot = MAV_AUTOPILOT_PX4, MockConfiguration::FailureMode_t failureMode = MockConfiguration::FailNone);
|
||||
void _connectMockLinkNoInitialConnectSequence(void) { _connectMockLink(MAV_AUTOPILOT_INVALID); }
|
||||
void _disconnectMockLink(void);
|
||||
void _missionItemsEqual(MissionItem& actual, MissionItem& expected);
|
||||
void _connectMockLinkNoInitialConnectSequence() { _connectMockLink(MAV_AUTOPILOT_INVALID); }
|
||||
void _disconnectMockLink();
|
||||
static void _missionItemsEqual(const MissionItem &actual, const MissionItem &expected);
|
||||
|
||||
MockLink* _mockLink = nullptr;
|
||||
Vehicle* _vehicle = nullptr;
|
||||
|
||||
bool _expectMissedFileDialog = false; // true: expect a missed file dialog, used for internal testing
|
||||
bool _expectMissedMessageBox = false; // true: expect a missed message box, used for internal testing
|
||||
MockLink *_mockLink = nullptr;
|
||||
Vehicle *_vehicle = nullptr;
|
||||
|
||||
private slots:
|
||||
void _linkDeleted(LinkInterface* link);
|
||||
void _linkDeleted(const LinkInterface *link);
|
||||
|
||||
private:
|
||||
// When the app is running in unit test mode the QGCMessageBox methods are re-routed here.
|
||||
void _unitTestCalled() { _unitTestRun = true; }
|
||||
|
||||
static QMessageBox::StandardButton _messageBox(QMessageBox::Icon icon,
|
||||
const QString& title,
|
||||
const QString& text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
QMessageBox::StandardButton defaultButton);
|
||||
/// @brief Returns the list of unit tests.
|
||||
static QList<UnitTest*> &_testList();
|
||||
|
||||
// This allows the private call to _messageBox
|
||||
friend class QGCMessageBox;
|
||||
|
||||
// When the app is running in unit test mode the QGCQFileDialog methods are re-routed here.
|
||||
|
||||
static QString _getExistingDirectory(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
QFileDialog::Options options);
|
||||
|
||||
static QString _getOpenFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QFileDialog::Options options);
|
||||
|
||||
static QStringList _getOpenFileNames(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QFileDialog::Options options);
|
||||
|
||||
static QString _getSaveFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
const QString& defaultSuffix,
|
||||
QFileDialog::Options options);
|
||||
|
||||
static QString _fileDialogResponseSingle(enum FileDialogType type);
|
||||
|
||||
// This allows the private calls to the file dialog methods
|
||||
friend class QGCQFileDialog;
|
||||
|
||||
void _unitTestCalled(void);
|
||||
static QList<UnitTest*>& _testList(void);
|
||||
|
||||
// Catch QGCMessageBox calls
|
||||
static bool _messageBoxRespondedTo; ///< Message box was responded to
|
||||
static bool _badResponseButton; ///< Attempt to repond to expected message box with button not being displayed
|
||||
static QMessageBox::StandardButton _messageBoxResponseButton; ///< Response to next message box
|
||||
static int _missedMessageBoxCount; ///< Count of message box not checked with call to messageBoxWasDisplayed
|
||||
|
||||
// Catch QGCQFileDialog calls
|
||||
static bool _fileDialogRespondedTo; ///< File dialog was responded to
|
||||
static bool _fileDialogResponseSet; ///< true: _fileDialogResponse was set by a call to UnitTest::setExpectedFileDialog
|
||||
static QStringList _fileDialogResponse; ///< Response to next file dialog
|
||||
static enum FileDialogType _fileDialogExpectedType; ///< type of file dialog expected to show
|
||||
static int _missedFileDialogCount; ///< Count of file dialogs not checked with call to UnitTest::fileDialogWasDisplayed
|
||||
|
||||
bool _unitTestRun = false; ///< true: Unit Test was run
|
||||
bool _initCalled = false; ///< true: UnitTest::_init was called
|
||||
bool _unitTestRun = false; ///< true: Unit Test was run
|
||||
bool _initCalled = false; ///< true: UnitTest::_init was called
|
||||
bool _cleanupCalled = false; ///< true: UnitTest::_cleanup was called
|
||||
bool _standalone = false; ///< true: Only run when requested specifically from command line
|
||||
bool _standalone = false; ///< true: Only run when requested specifically from command line
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class UnitTestWrapper {
|
||||
class UnitTestWrapper
|
||||
{
|
||||
public:
|
||||
UnitTestWrapper(const QString& name, bool standalone)
|
||||
UnitTestWrapper(const QString &name, bool standalone)
|
||||
: _unitTest(new T)
|
||||
{
|
||||
_unitTest->setObjectName(name);
|
||||
|
||||
@@ -5,7 +5,6 @@ MAVLinkProtocolLog.debug=false
|
||||
MockLinkLog.debug=false
|
||||
FirmwareUpgradeLog.debug=false
|
||||
FileManagerLog.debug=false
|
||||
UASLog.debug=false
|
||||
PX4AirframeLoaderLog.debug=false
|
||||
SerialLinkLog.debug=false
|
||||
RadioConfigTestLog.debug=false
|
||||
|
||||
Reference in New Issue
Block a user