From: Jari Jarvi Date: Mon, 28 Jun 2010 13:09:44 +0000 (+0300) Subject: Unit test for RemoteDBMgr and some stubs X-Git-Url: http://git.maemo.org/git/?p=irwi;a=commitdiff_plain;h=7a63d12e6e02600ec30205f9004f3766733dd244 Unit test for RemoteDBMgr and some stubs --- diff --git a/src/remote.h b/src/remote.h index 3c2720f..5adcabd 100644 --- a/src/remote.h +++ b/src/remote.h @@ -3,12 +3,13 @@ #include #include -#include -#include #include #include "rating.h" +class QNetworkReply; +class QNetworkAccessManager; + class Remote : public QObject { Q_OBJECT diff --git a/src/remotedbmgr.h b/src/remotedbmgr.h index 8bb607a..11765d8 100644 --- a/src/remotedbmgr.h +++ b/src/remotedbmgr.h @@ -30,7 +30,6 @@ private: RemoteDB db; QNetworkAccessManager netAM; - }; #endif diff --git a/ut/ut.pri b/ut/ut.pri index 41eaa15..aa8ad01 100644 --- a/ut/ut.pri +++ b/ut/ut.pri @@ -17,6 +17,7 @@ STUBDIR = ../stubs DEPENDPATH += INCLUDEPATH += $$SRCDIR +INCLUDEPATH += . VPATH = $$SRCDIR VPATH += $$STUBDIR diff --git a/ut/ut_remotedbmgr/QNetworkReply b/ut/ut_remotedbmgr/QNetworkReply new file mode 100644 index 0000000..e6ebfbe --- /dev/null +++ b/ut/ut_remotedbmgr/QNetworkReply @@ -0,0 +1 @@ +#include "qnetworkreply.h" diff --git a/ut/ut_remotedbmgr/qnetworkaccessmanager_stub.cpp b/ut/ut_remotedbmgr/qnetworkaccessmanager_stub.cpp new file mode 100644 index 0000000..fbe93cb --- /dev/null +++ b/ut/ut_remotedbmgr/qnetworkaccessmanager_stub.cpp @@ -0,0 +1,11 @@ +#include "qnetworkreply.h" +#include +#include + +QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) +{ + QNetworkReply *reply = new QNetworkReply(); + emit finished(reply); + return reply; +} + diff --git a/ut/ut_remotedbmgr/qnetworkreply.cpp b/ut/ut_remotedbmgr/qnetworkreply.cpp new file mode 100644 index 0000000..553bf9e --- /dev/null +++ b/ut/ut_remotedbmgr/qnetworkreply.cpp @@ -0,0 +1,34 @@ +#include +#include "qnetworkreply.h" + +QNetworkReply::QNetworkReply() +{ +} + +QNetworkReply::~QNetworkReply() +{ +} + +QByteArray QNetworkReply::readAll() +{ + return QByteArray(); +} + +int QNetworkReply::error() const +{ + return 0; +} + +void QNetworkReply::close() +{ +} + +void QNetworkReply::deleteLater() +{ +} + +QByteArray QNetworkReply::readLine(qint64 maxlen) +{ + return QByteArray(); +} + diff --git a/ut/ut_remotedbmgr/qnetworkreply.h b/ut/ut_remotedbmgr/qnetworkreply.h new file mode 100644 index 0000000..3d3d85b --- /dev/null +++ b/ut/ut_remotedbmgr/qnetworkreply.h @@ -0,0 +1,27 @@ +#ifndef QNETWORKREPLY_H +#define QNETWORKREPLY_H +//#define QNETWORKREPLY_H + +#warning("oma headeri") + +#include + +class QNetworkReply +{ +public: + enum NetworkError { + NoError = 0 + }; + + QNetworkReply(); + ~QNetworkReply(); + QByteArray readAll(); + int error() const; + void close(); + void deleteLater(); + QByteArray readLine(qint64 maxlen = 0); + +}; + +#endif // QNETWORKREPLY_H + diff --git a/ut/ut_remotedbmgr/ut_remotedbmgr.cpp b/ut/ut_remotedbmgr/ut_remotedbmgr.cpp new file mode 100644 index 0000000..072eb2b --- /dev/null +++ b/ut/ut_remotedbmgr/ut_remotedbmgr.cpp @@ -0,0 +1,33 @@ +#include "qnetworkreply.h" +#include "ut_remotedbmgr.h" + +#include +#include +#include + +void Ut_RemoteDBMgr::initTestCase() +{ + dbVerified = false; + connect(&subject, SIGNAL(dbReady(RemoteDB *)), + this, SLOT(verifyDB(RemoteDB *))); + subject.getDBAsync(); +} + +void Ut_RemoteDBMgr::cleanupTestCase() +{ +} + +void Ut_RemoteDBMgr::testGetDBAsync() +{ + QCOMPARE(dbVerified, true); +} + +void Ut_RemoteDBMgr::verifyDB(RemoteDB *db) +{ + dbVerified = true; +} + + +QTEST_MAIN(Ut_RemoteDBMgr) + + diff --git a/ut/ut_remotedbmgr/ut_remotedbmgr.h b/ut/ut_remotedbmgr/ut_remotedbmgr.h new file mode 100644 index 0000000..a86e356 --- /dev/null +++ b/ut/ut_remotedbmgr/ut_remotedbmgr.h @@ -0,0 +1,35 @@ +#ifndef _UT_REMOTEDBMGR_H_ +#define _UT_REMOTEDBMGR_H_ + +#include "qnetworkreply.h" +#include +#include +#include +#include +#include + +#include "remotedb.h" +#include "remotedbmgr.h" + +class Ut_RemoteDBMgr : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + void testGetDBAsync(); + +public slots: // public slots are not called by Qt Test framework + void verifyDB(RemoteDB *db); + +private: + RemoteDBMgr subject; + RemoteDB validDB; + bool dbVerified; + +}; + +#endif // _UT_REMOTEDBMGR_H_ + + diff --git a/ut/ut_remotedbmgr/ut_remotedbmgr.pro b/ut/ut_remotedbmgr/ut_remotedbmgr.pro new file mode 100644 index 0000000..c1bcd54 --- /dev/null +++ b/ut/ut_remotedbmgr/ut_remotedbmgr.pro @@ -0,0 +1,22 @@ +!include( ../ut.pri ) { + error( Could not find the ut.pri file ) +} + +QT += xml +QT += network + +HEADERS += qnetworkreply.h +HEADERS += ut_remotedbmgr.h +HEADERS += remotedbmgr.h +HEADERS += remotedb.h +HEADERS += remote.h +HEADERS += rating.h + +SOURCES += qnetworkreply.cpp +SOURCES += ut_remotedbmgr.cpp +SOURCES += qnetworkaccessmanager_stub.cpp +SOURCES += remotedbmgr.cpp +SOURCES += remote.cpp +SOURCES += rating.cpp + +