Integrate QmuParserTests in main testing set.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-28 19:57:34 +02:00
parent ba89a2856d
commit a4bc4a75c0
4 changed files with 32 additions and 19 deletions

View File

@ -23,6 +23,7 @@
#include <QString>
#include <QDebug>
#include <QCoreApplication>
#include "qmuparsererror.h"
#include <QtCore/qmath.h>
#include <stdexcept>
@ -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

View File

@ -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<testfun_type> 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

View File

@ -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

View File

@ -28,10 +28,12 @@
#include <QCoreApplication>
#include <QDebug>
#include <QTimer>
#include <QtGlobal>
#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();
}