Browse Source
Allows for UI unit tests to be written: - Ability to respond to expected message boxes - Ability to fail test if unexpected message boxes occursQGC4.4
22 changed files with 780 additions and 279 deletions
@ -1,83 +0,0 @@
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* @author Rob Caldecott |
||||
* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html
|
||||
* |
||||
*/ |
||||
|
||||
#ifndef AUTOTEST_H |
||||
#define AUTOTEST_H |
||||
|
||||
#include <QTest> |
||||
#include <QList> |
||||
#include <QString> |
||||
#include <QSharedPointer> |
||||
#include "QGCApplication.h" |
||||
|
||||
namespace AutoTest |
||||
{ |
||||
typedef QList<QObject*> TestList; |
||||
|
||||
inline TestList& testList() |
||||
{ |
||||
static TestList list; |
||||
return list; |
||||
} |
||||
|
||||
inline bool findObject(QObject* object) |
||||
{ |
||||
TestList& list = testList(); |
||||
if (list.contains(object)) |
||||
{ |
||||
return true; |
||||
} |
||||
foreach (QObject* test, list) |
||||
{ |
||||
if (test->objectName() == object->objectName()) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
inline void addTest(QObject* object) |
||||
{ |
||||
TestList& list = testList(); |
||||
if (!findObject(object)) |
||||
{ |
||||
list.append(object); |
||||
} |
||||
} |
||||
|
||||
inline int run(int argc, char *argv[], QString& singleTest) |
||||
{
|
||||
int ret = 0; |
||||
foreach (QObject* test, testList()) |
||||
{ |
||||
if (singleTest.isEmpty() || singleTest == test->objectName()) { |
||||
qgcApp()->destroySingletonsForUnitTest(); |
||||
qgcApp()->createSingletonsForUnitTest(); |
||||
ret += QTest::qExec(test, argc, argv); |
||||
} |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
} |
||||
|
||||
template <class T> |
||||
class Test |
||||
{ |
||||
public: |
||||
QSharedPointer<T> child; |
||||
|
||||
Test(const QString& name) : child(new T) |
||||
{ |
||||
child->setObjectName(name); |
||||
AutoTest::addTest(child.data()); |
||||
} |
||||
}; |
||||
|
||||
#define DECLARE_TEST(className) static Test<className> t(#className); |
||||
|
||||
#endif // AUTOTEST_H
|
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief The tests the unit test QGCMessageBox catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include "MessageBoxTest.h" |
||||
#include "QGCMessageBox.h" |
||||
|
||||
UT_REGISTER_TEST(MessageBoxTest) |
||||
|
||||
MessageBoxTest::MessageBoxTest(void) : |
||||
_expectMissedMessageBox(false) |
||||
{ |
||||
|
||||
} |
||||
|
||||
void MessageBoxTest::cleanup(void) |
||||
{ |
||||
if (_expectMissedMessageBox) { |
||||
_expectMissedMessageBox = false; |
||||
QEXPECT_FAIL("", "Supposed to fail in cleanup with a missed message box", Continue); |
||||
} |
||||
UnitTest::cleanup(); |
||||
} |
||||
|
||||
void MessageBoxTest::_messageBoxExpected_test(void) |
||||
{ |
||||
setExpectedMessageBox(QMessageBox::Ok); |
||||
|
||||
QCOMPARE(QGCMessageBox::information(QString(), QString()), QMessageBox::Ok); |
||||
|
||||
checkExpectedMessageBox(); |
||||
} |
||||
|
||||
void MessageBoxTest::_messageBoxUnexpected_test(void) |
||||
{ |
||||
// This should cause the test to fail 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(expectFailNoMessageBox); |
||||
} |
||||
|
||||
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); |
||||
} |
||||
|
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief The tests the unit test QGCMessageBox catching mechanism.
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#ifndef MESSAGEBOXTEST_H |
||||
#define MESSAGEBOXTEST_H |
||||
|
||||
#include "UnitTest.h" |
||||
|
||||
class MessageBoxTest : public UnitTest |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
MessageBoxTest(void); |
||||
|
||||
private slots: |
||||
UT_DECLARE_DEFAULT_initTestCase |
||||
UT_DECLARE_DEFAULT_cleanupTestCase |
||||
UT_DECLARE_DEFAULT_init |
||||
void cleanup(void); |
||||
|
||||
void _messageBoxExpected_test(void); |
||||
void _messageBoxUnexpected_test(void); |
||||
void _previousMessageBox_test(void); |
||||
void _noMessageBox_test(void); |
||||
void _badResponseButton_test(void); |
||||
|
||||
private: |
||||
bool _expectMissedMessageBox; |
||||
}; |
||||
|
||||
#endif |
@ -1,60 +1,60 @@
@@ -1,60 +1,60 @@
|
||||
#ifndef UASUNITTEST_H |
||||
#define UASUNITTEST_H |
||||
|
||||
#include <QObject> |
||||
#include <QtCore/QString> |
||||
#include <QtTest/QtTest> |
||||
#include <QApplication> |
||||
|
||||
#include "UAS.h" |
||||
#include "MAVLinkProtocol.h" |
||||
#include "SerialLink.h" |
||||
#include "UASInterface.h" |
||||
#include "AutoTest.h" |
||||
#include "UnitTest.h" |
||||
#include "LinkManager.h" |
||||
#include "UASWaypointManager.h" |
||||
#include "SerialLink.h" |
||||
#include "LinkInterface.h" |
||||
|
||||
class UASUnitTest : public QObject |
||||
#define UASID 100 |
||||
|
||||
class UASUnitTest : public UnitTest |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
#define UASID 100 |
||||
MAVLinkProtocol* mav; |
||||
UAS* uas; |
||||
UASUnitTest(); |
||||
UASUnitTest(void); |
||||
|
||||
private slots: |
||||
void init(); |
||||
void cleanup(); |
||||
|
||||
void getUASID_test(); |
||||
void getUASName_test(); |
||||
void getUpTime_test(); |
||||
void getCommunicationStatus_test(); |
||||
void filterVoltage_test(); |
||||
void getAutopilotType_test(); |
||||
void setAutopilotType_test(); |
||||
void getStatusForCode_test(); |
||||
void getLocalX_test(); |
||||
void getLocalY_test(); |
||||
void getLocalZ_test(); |
||||
void getLatitude_test(); |
||||
void getLongitude_test(); |
||||
void getAltitudeAMSL_test(); |
||||
void getAltitudeRelative_test(); |
||||
void getRoll_test(); |
||||
void getPitch_test(); |
||||
void getYaw_test(); |
||||
void getSelected_test(); |
||||
void getSystemType_test(); |
||||
void getAirframe_test(); |
||||
void setAirframe_test(); |
||||
void getWaypointList_test(); |
||||
void signalWayPoint_test(); |
||||
void getWaypoint_test(); |
||||
UT_DECLARE_DEFAULT_initTestCase |
||||
UT_DECLARE_DEFAULT_cleanupTestCase |
||||
void init(void); |
||||
void cleanup(void); |
||||
|
||||
void getUASID_test(void); |
||||
void getUASName_test(void); |
||||
void getUpTime_test(void); |
||||
void getCommunicationStatus_test(void); |
||||
void filterVoltage_test(void); |
||||
void getAutopilotType_test(void); |
||||
void setAutopilotType_test(void); |
||||
void getStatusForCode_test(void); |
||||
void getLocalX_test(void); |
||||
void getLocalY_test(void); |
||||
void getLocalZ_test(void); |
||||
void getLatitude_test(void); |
||||
void getLongitude_test(void); |
||||
void getAltitudeAMSL_test(void); |
||||
void getAltitudeRelative_test(void); |
||||
void getRoll_test(void); |
||||
void getPitch_test(void); |
||||
void getYaw_test(void); |
||||
void getSelected_test(void); |
||||
void getSystemType_test(void); |
||||
void getAirframe_test(void); |
||||
void setAirframe_test(void); |
||||
void getWaypointList_test(void); |
||||
void signalWayPoint_test(void); |
||||
void getWaypoint_test(void); |
||||
|
||||
private: |
||||
MAVLinkProtocol* _mavlink; |
||||
UAS* _uas; |
||||
}; |
||||
|
||||
DECLARE_TEST(UASUnitTest) |
||||
#endif // UASUNITTEST_H
|
||||
#endif |
||||
|
@ -0,0 +1,202 @@
@@ -0,0 +1,202 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief Base class for all unit tests
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include "UnitTest.h" |
||||
#include "QGCApplication.h" |
||||
|
||||
bool UnitTest::_messageBoxRespondedTo = false; |
||||
bool UnitTest::_badResponseButton = false; |
||||
QMessageBox::StandardButton UnitTest::_messageBoxResponseButton = QMessageBox::NoButton; |
||||
int UnitTest::_missedMessageBoxCount = 0; |
||||
UnitTest::UnitTestList_t UnitTest::_tests; |
||||
|
||||
UnitTest::UnitTest(void) : |
||||
_unitTestRun(false), |
||||
_initTestCaseCalled(false), |
||||
_cleanupTestCaseCalled(false), |
||||
_initCalled(false), |
||||
_cleanupCalled(false) |
||||
{ |
||||
|
||||
} |
||||
|
||||
UnitTest::~UnitTest() |
||||
{ |
||||
if (_unitTestRun) { |
||||
// Derived classes must call base class implementations
|
||||
Q_ASSERT(_initTestCaseCalled); |
||||
Q_ASSERT(_cleanupTestCaseCalled); |
||||
Q_ASSERT(_initCalled); |
||||
Q_ASSERT(_cleanupCalled); |
||||
} |
||||
} |
||||
|
||||
void UnitTest::_addTest(QObject* test) |
||||
{ |
||||
Q_ASSERT(!_tests.contains(test)); |
||||
|
||||
_tests.append(test); |
||||
} |
||||
|
||||
void UnitTest::_unitTestCalled(void) |
||||
{ |
||||
_unitTestRun = true; |
||||
} |
||||
|
||||
int UnitTest::run(int argc, char *argv[], QString& singleTest) |
||||
{ |
||||
int ret = 0; |
||||
|
||||
foreach (QObject* test, _tests) { |
||||
if (singleTest.isEmpty() || singleTest == test->objectName()) { |
||||
ret += QTest::qExec(test, argc, argv); |
||||
} |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
/// @brief Called at the initialization of the entire unit test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::initTestCase(void) |
||||
{ |
||||
_initTestCaseCalled = true; |
||||
|
||||
_activeUnitTest = this; |
||||
_missedMessageBoxCount = 0; |
||||
_badResponseButton = false; |
||||
} |
||||
|
||||
/// @brief Called at the end of the entire unit test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::cleanupTestCase(void) |
||||
{ |
||||
_cleanupTestCaseCalled = true; |
||||
|
||||
Q_ASSERT(_activeUnitTest != NULL); |
||||
_activeUnitTest = NULL; |
||||
|
||||
int missedMessageBoxCount = _missedMessageBoxCount; |
||||
_missedMessageBoxCount = 0; |
||||
|
||||
// Make sure to reset any needed variables since this can fall and cause the rest of the method to be skipped
|
||||
QCOMPARE(missedMessageBoxCount, 0); |
||||
} |
||||
|
||||
/// @brief Called before each test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::init(void) |
||||
{ |
||||
_initCalled = true; |
||||
|
||||
_messageBoxRespondedTo = false; |
||||
_missedMessageBoxCount = 0; |
||||
_badResponseButton = false; |
||||
_messageBoxResponseButton = QMessageBox::NoButton; |
||||
|
||||
// Each test gets a clean global state
|
||||
qgcApp()->destroySingletonsForUnitTest(); |
||||
qgcApp()->createSingletonsForUnitTest(); |
||||
} |
||||
|
||||
/// @brief Called after each test.
|
||||
/// Make sure to call first in your derived class
|
||||
void UnitTest::cleanup(void) |
||||
{ |
||||
_cleanupCalled = true; |
||||
|
||||
int missedMessageBoxCount = _missedMessageBoxCount; |
||||
_missedMessageBoxCount = 0; |
||||
|
||||
// Make sure to reset any needed variables since this can fall and cause the rest of the method to be skipped
|
||||
QCOMPARE(missedMessageBoxCount, 0); |
||||
} |
||||
|
||||
void UnitTest::setExpectedMessageBox(QMessageBox::StandardButton response) |
||||
{ |
||||
Q_ASSERT(!_messageBoxRespondedTo); |
||||
|
||||
// We use an obsolete StandardButton value to signal that response button has not been set. So you can't use this.
|
||||
Q_ASSERT(response != QMessageBox::NoButton); |
||||
Q_ASSERT(_messageBoxResponseButton == QMessageBox::NoButton); |
||||
|
||||
int missedMessageBoxCount = _missedMessageBoxCount; |
||||
_missedMessageBoxCount = 0; |
||||
|
||||
QCOMPARE(missedMessageBoxCount, 0); |
||||
|
||||
_messageBoxResponseButton = response; |
||||
} |
||||
|
||||
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 & expectFailNoMessageBox) { |
||||
QEXPECT_FAIL("", "Expecting failure due to no message box", Continue); |
||||
} |
||||
QCOMPARE(_messageBoxRespondedTo, 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; |
||||
} |
@ -0,0 +1,160 @@
@@ -0,0 +1,160 @@
|
||||
/*=====================================================================
|
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
/// @file
|
||||
/// @brief Base class for all unit tests
|
||||
///
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#ifndef UNITTEST_H |
||||
#define UNITTEST_H |
||||
|
||||
#include <QObject> |
||||
#include <QtTest> |
||||
#include <QMessageBox> |
||||
|
||||
#define UT_REGISTER_TEST(className) static UnitTestWrapper<className> t(#className); |
||||
|
||||
/// @brief If you don't need you own specific implemenation of the test case setup methods
|
||||
/// you can use these macros to declare the default implementation which just calls
|
||||
/// the base class.
|
||||
|
||||
#define UT_DECLARE_DEFAULT_initTestCase |
||||
//virtual void initTestCase(void) { UnitTest::_initTestCase(); }
|
||||
#define UT_DECLARE_DEFAULT_cleanupTestCase |
||||
// virtual void cleanupTestCase(void) { UnitTest::_cleanupTestCase(); }
|
||||
#define UT_DECLARE_DEFAULT_init |
||||
//virtual void init(void) { UnitTest::_init(); }
|
||||
#define UT_DECLARE_DEFAULT_cleanup |
||||
//virtual void cleanup(void) { UnitTest::_cleanup(); }
|
||||
|
||||
class QGCMessageBox; |
||||
class UnitTest; |
||||
|
||||
static UnitTest* _activeUnitTest = NULL; ///< Currently active unit test
|
||||
|
||||
class UnitTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UnitTest(void); |
||||
virtual ~UnitTest(void); |
||||
|
||||
/// @brief Called to run all the registered unit tests
|
||||
/// @param argc argc from main
|
||||
/// @param argv argv from main
|
||||
/// @param singleTest Name of test to just run a single test
|
||||
static int run(int argc, char *argv[], QString& singleTest); |
||||
|
||||
/// @brief Sets up for an expected QGCMessageBox
|
||||
/// @param response Response to take on message box
|
||||
void setExpectedMessageBox(QMessageBox::StandardButton response); |
||||
|
||||
enum { |
||||
expectFailNoFailure = 1 << 0, ///< not expecting any failures
|
||||
expectFailNoMessageBox = 1 << 1, ///< expecting a failure due to no message box displayed
|
||||
expectFailBadResponseButton = 1 << 2 ///< expecting a failure due to bad button response
|
||||
}; |
||||
|
||||
/// @brief Check whether a message box was displayed and correctly responded to
|
||||
// @param Expected failure response flags
|
||||
void checkExpectedMessageBox(int expectFailFlags = expectFailNoFailure); |
||||
|
||||
// Should only be called by UnitTestWrapper
|
||||
static void _addTest(QObject* test); |
||||
|
||||
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 at the initialization of the entire unit test.
|
||||
/// Make sure to call _initTestCase first in your derived class.
|
||||
virtual void initTestCase(void); |
||||
|
||||
/// @brief Called at the end of the entire unit test.
|
||||
/// Make sure to call _cleanupTestCase first in your derived class.
|
||||
virtual void cleanupTestCase(void); |
||||
|
||||
/// @brief Called before each test.
|
||||
/// Make sure to call _init first in your derived class.
|
||||
virtual void init(void); |
||||
|
||||
/// @brief Called after each test.
|
||||
/// Make sure to call _cleanup first in your derived class.
|
||||
virtual void cleanup(void); |
||||
|
||||
protected: |
||||
/// @brief Must be called first by derived class implementation
|
||||
void _initTestCase(void); |
||||
|
||||
/// @brief Must be called first by derived class implementation
|
||||
void _cleanupTestCase(void); |
||||
|
||||
/// @brief Must be called first by derived class implementation
|
||||
void _init(void); |
||||
|
||||
/// @brief Must be called first by derived class implementation
|
||||
void _cleanup(void); |
||||
|
||||
private: |
||||
// When the app is running in unit test mode the QGCMessageBox methods are re-routed here.
|
||||
static QMessageBox::StandardButton _messageBox(QMessageBox::Icon icon, const QString& title, const QString& text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton); |
||||
|
||||
// This allows the private call to _messageBox
|
||||
friend class QGCMessageBox; |
||||
|
||||
void _unitTestCalled(void); |
||||
|
||||
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
|
||||
|
||||
bool _unitTestRun; ///< true: Unit Test was run
|
||||
bool _initTestCaseCalled; ///< true: UnitTest::_initTestCase was called
|
||||
bool _cleanupTestCaseCalled; ///< true: UnitTest::_cleanupTestCase was called
|
||||
bool _initCalled; ///< true: UnitTest::_init was called
|
||||
bool _cleanupCalled; ///< true: UnitTest::_cleanup was called
|
||||
|
||||
typedef QList<QObject*> UnitTestList_t; |
||||
|
||||
static UnitTestList_t _tests; |
||||
}; |
||||
|
||||
template <class T> |
||||
class UnitTestWrapper { |
||||
public: |
||||
UnitTestWrapper(const QString& name) : |
||||
_unitTest(new T) |
||||
{ |
||||
_unitTest->setObjectName(name); |
||||
UnitTest::_addTest(_unitTest.data()); |
||||
} |
||||
|
||||
private: |
||||
QSharedPointer<T> _unitTest; |
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue