Hi Wysota,
Thank you very much for your help ,it works now!
attach the codes ,hope will help others:
///////////////////////////////////////////
//head file
///////////////////////////////////////////
#include <QHttp>
#include <QHttpResponseHeader>
#include <QString>
{
Q_OBJECT
public:
hp();
signals:
void ok();
public slots:
void done(bool);
};
///////////////////////////////////////////
//cpp file
///////////////////////////////////////////
#include <QDebug>
#include "hp.h"
hp::hp()
{
connect(this, SIGNAL(done(bool)), this, SLOT(done(bool)));
}
void hp::done( bool)
{
data=readAll().mid(0,10);
qDebug()<<data<<endl;
emit ok();
}
//////////////////////////////////////
// test main
//////////////////////////////////////
#include <QtTest>
#include <QtCore>
#include <QSignalSpy>
#include "hp.h"
{
Q_OBJECT
private slots:
void testValidity();
};
void testDate::testValidity()
{
hp h;
h.setHost("webserver");
h.get("url");
while (spy.count() == 0)
QTest::qWait(200);
QVERIFY( h.data == "expected data" );
}
QTEST_MAIN(testDate)
#include "t.moc"
///////////////////////////////////////////
//head file
///////////////////////////////////////////
#include <QHttp>
#include <QHttpResponseHeader>
#include <QString>
class hp:public QHttp
{
Q_OBJECT
public:
hp();
QString data;
signals:
void ok();
public slots:
void done(bool);
};
///////////////////////////////////////////
//cpp file
///////////////////////////////////////////
#include <QDebug>
#include "hp.h"
hp::hp()
{
connect(this, SIGNAL(done(bool)), this, SLOT(done(bool)));
}
void hp::done( bool)
{
data=readAll().mid(0,10);
qDebug()<<data<<endl;
emit ok();
}
//////////////////////////////////////
// test main
//////////////////////////////////////
#include <QtTest>
#include <QtCore>
#include <QSignalSpy>
#include "hp.h"
class testDate: public QObject
{
Q_OBJECT
private slots:
void testValidity();
};
void testDate::testValidity()
{
hp h;
h.setHost("webserver");
h.get("url");
QSignalSpy spy(&h, SIGNAL(ok()));
while (spy.count() == 0)
QTest::qWait(200);
QVERIFY( h.data == "expected data" );
}
QTEST_MAIN(testDate)
#include "t.moc"
To copy to clipboard, switch view to plain text mode
Best regards,
hb
Bookmarks