From a4bc4a75c00de73148f4303c9862777e98136f3b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 28 Oct 2015 19:57:34 +0200 Subject: [PATCH] Integrate QmuParserTests in main testing set. --HG-- branch : develop --- src/libs/qmuparser/qmuparsertest.cpp | 19 +++++++++++++++---- src/libs/qmuparser/qmuparsertest.h | 11 ++++++++--- src/test/ParserTest/ParserTest.pro | 5 +++++ src/test/ParserTest/main.cpp | 16 ++++------------ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index 5922d48ef..f814d14d2 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "qmuparsererror.h" #include #include @@ -41,8 +42,8 @@ namespace Test int QmuParserTester::c_iCount = 0; //--------------------------------------------------------------------------------------------------------------------- -QmuParserTester::QmuParserTester() - : m_vTestFun() +QmuParserTester::QmuParserTester(QObject *parent) + : QObject(parent), m_vTestFun() { AddTest ( &QmuParserTester::TestNames ); AddTest ( &QmuParserTester::TestSyntax ); @@ -1098,6 +1099,9 @@ void QmuParserTester::AddTest ( testfun_type a_pFun ) // cppcheck-suppress unusedFunction void QmuParserTester::Run() { + qWarning() << "-----------------------------------------------------------"; + qWarning() << "Running test suite:\n"; + int iStat = 0; try { @@ -1111,16 +1115,19 @@ void QmuParserTester::Run() qWarning() << "\n" << e.GetMsg(); qWarning() << e.GetToken(); Abort(); + return; } catch ( std::exception &e ) { qWarning() << e.what(); Abort(); + return; } catch ( ... ) { qWarning() << "Internal error"; Abort(); + return; } if ( iStat == 0 ) @@ -1133,7 +1140,11 @@ void QmuParserTester::Run() << " errors (" << QmuParserTester::c_iCount << " expressions)"; } + QCoreApplication::exit(iStat); QmuParserTester::c_iCount = 0; + + qWarning() << "Done."; + qWarning() << "-----------------------------------------------------------"; } @@ -1498,11 +1509,11 @@ int QmuParserTester::EqnTestBulk(const QString &a_str, double a_fRes[4], bool a_ /** * @brief Internal error in test class Test is going to be aborted. */ -void Q_NORETURN QmuParserTester::Abort() +void QmuParserTester::Abort() { qWarning() << "Test failed (internal error in test class)"; while ( getchar() == false); - exit ( -1 ); + QCoreApplication::exit ( -1 ); } } // namespace test } // namespace qmu diff --git a/src/libs/qmuparser/qmuparsertest.h b/src/libs/qmuparser/qmuparsertest.h index 006fa4edb..220de68fe 100644 --- a/src/libs/qmuparser/qmuparsertest.h +++ b/src/libs/qmuparser/qmuparsertest.h @@ -44,14 +44,19 @@ namespace Test * * (C) 2004-2011 Ingo Berg */ -class QMUPARSERSHARED_EXPORT QmuParserTester // final +class QMUPARSERSHARED_EXPORT QmuParserTester : public QObject // final { + Q_OBJECT public: typedef int ( QmuParserTester::*testfun_type ) (); - QmuParserTester(); + QmuParserTester(QObject *parent = nullptr); + +public slots: void Run(); + private: + Q_DISABLE_COPY(QmuParserTester) QVector m_vTestFun; static int c_iCount; @@ -307,7 +312,7 @@ private: // cppcheck-suppress functionStatic int TestBulkMode(); - static void Q_NORETURN Abort(); + static void Abort(); }; } // namespace Test } // namespace qmu diff --git a/src/test/ParserTest/ParserTest.pro b/src/test/ParserTest/ParserTest.pro index 1e3b745af..d54585f8d 100644 --- a/src/test/ParserTest/ParserTest.pro +++ b/src/test/ParserTest/ParserTest.pro @@ -21,6 +21,11 @@ TARGET = ParserTest # Console application, we use C++11 standard. CONFIG += console c++11 +# CONFIG += testcase adds a 'make check' which is great. But by default it also +# adds a 'make install' that installs the test cases, which we do not want. +# Can configure it not to do that with 'no_testcase_installs' +CONFIG += testcase no_testcase_installs + # Use out-of-source builds (shadow builds) CONFIG -= app_bundle debug_and_release debug_and_release_target diff --git a/src/test/ParserTest/main.cpp b/src/test/ParserTest/main.cpp index 01bc56f2d..14f522ee1 100644 --- a/src/test/ParserTest/main.cpp +++ b/src/test/ParserTest/main.cpp @@ -28,10 +28,12 @@ #include #include +#include #include #include "../qmuparser/qmuparsertest.h" using namespace qmu; +using namespace Test; //--------------------------------------------------------------------------------------------------------------------- void testMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -62,18 +64,8 @@ void testMessageOutput(QtMsgType type, const QMessageLogContext &context, const int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - qInstallMessageHandler(testMessageOutput); - - qWarning() << "-----------------------------------------------------------"; - qWarning() << "Running test suite:\n"; - - - qmu::Test::QmuParserTester pt; - pt.Run(); - - qWarning() << "Done."; - qWarning() << "-----------------------------------------------------------"; - + QmuParserTester pt; + QTimer::singleShot(0, &pt, SLOT(Run())); return a.exec(); }