I am currently testing a Qt application. I have to build a test to check the correct input and output of csv files.
Problem:
The data is being read asynchronously and my test program is ending before the data is loaded and this is the output i get.
QFATAL: Received signal 11
FAIL! : Received a fatal error
Program flow:
There is a class AsyncLoader that loads the data. After the data read is finished, it emits a completed() signal.
So, I modified the test program to include an QEventLoop. The code is shown below
#pragma once
#include <QEventLoop>
#include <QSignalSpy>
#include "asyncloader.h"
#include "alphaevent.h"
#include "mainwindow.h"
#include <QtTest/QtTest>
class Test1: public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void mainWindowTester();
void cleanupTestCase();
};
void Test1::initTestCase()
{
qDebug()<<"hello";
}
void Test1::mainWindowTester()
{
AlphaEvent *fs1 = new AlphaEvent(this);
fs1->setOperation(AlphaEvent::FileOpen);
fs1->setPath(QString("/home/user/PC5.csv"));
MainWindow *mw1 = new MainWindow();
QEventLoop loop;
loop.connect(mw1, SIGNAL(completed(FileEvent*)), SLOT(quit()));
mw1->dataSetIORequest(fs1);
loop.exec();
int pqr = mw1->_package->dataSet->rowCount();
int pqr1 = mw1->_package->dataSet->columnCount();
qDebug() << "pqr== "<< pqr;
qDebug() << "-----------------------------------------------";
QVERIFY(pqr==5);
void Test1::cleanupTestCase()
{
}
QTEST_MAIN(Test1)
#include "test1.moc"
But with this, I get a "subprocess error: FailedToStart"
Is there a way to test an asynchronous unit?
I am using Qt version 5.4.2, QMake version 3.0