diff --git a/src/qgcunittest/UnitTest.cc b/src/qgcunittest/UnitTest.cc index 29366633c005587d1f83b0a807c1bf5e2b57cedd..1011c99abeeb473cf3cd0c2dfde3e5d362a877f9 100644 --- a/src/qgcunittest/UnitTest.cc +++ b/src/qgcunittest/UnitTest.cc @@ -33,7 +33,6 @@ 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), @@ -58,9 +57,11 @@ UnitTest::~UnitTest() void UnitTest::_addTest(QObject* test) { - Q_ASSERT(!_tests.contains(test)); + QList& tests = _testList(); + + Q_ASSERT(!tests.contains(test)); - _tests.append(test); + tests.append(test); } void UnitTest::_unitTestCalled(void) @@ -68,11 +69,18 @@ void UnitTest::_unitTestCalled(void) _unitTestRun = true; } +/// @brief Returns the list of unit tests. +QList& UnitTest::_testList(void) +{ + static QList tests; + return tests; +} + int UnitTest::run(int argc, char *argv[], QString& singleTest) { int ret = 0; - foreach (QObject* test, _tests) { + foreach (QObject* test, _testList()) { if (singleTest.isEmpty() || singleTest == test->objectName()) { ret += QTest::qExec(test, argc, argv); } @@ -196,3 +204,4 @@ QMessageBox::StandardButton UnitTest::_messageBox(QMessageBox::Icon icon, const return retButton; } + diff --git a/src/qgcunittest/UnitTest.h b/src/qgcunittest/UnitTest.h index 85efe76e8a26162e6018b48b6c2f0ebfe0b30677..ad978ecd2b56f9e30385514a96a6d50b979ac5d5 100644 --- a/src/qgcunittest/UnitTest.h +++ b/src/qgcunittest/UnitTest.h @@ -79,9 +79,9 @@ public: // @param Expected failure response flags void checkExpectedMessageBox(int expectFailFlags = expectFailNoFailure); - // Should only be called by UnitTestWrapper + /// @brief Adds a unit test to the list. 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 @@ -124,7 +124,8 @@ private: friend class QGCMessageBox; void _unitTestCalled(void); - + static QList& _testList(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 @@ -135,10 +136,6 @@ private: bool _cleanupTestCaseCalled; ///< true: UnitTest::_cleanupTestCase was called bool _initCalled; ///< true: UnitTest::_init was called bool _cleanupCalled; ///< true: UnitTest::_cleanup was called - - typedef QList UnitTestList_t; - - static UnitTestList_t _tests; }; template