Added networkaccessmanagermock and networkreplymock files.
authorJussi Laitinen <jussi.laitinen@ixonos.com>
Tue, 30 Mar 2010 12:56:36 +0000 (15:56 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 30 Mar 2010 12:56:36 +0000 (15:56 +0300)
Situare.pro
src/main.cpp
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapfetcher.cpp
src/map/mapfetcher.h
tests/testMap/networkaccessmanagermock.cpp [new file with mode: 0644]
tests/testMap/networkreplymock.cpp [new file with mode: 0644]
tests/testMap/testmapfetcher.cpp

index d6c4060..0d2b02e 100644 (file)
@@ -8,11 +8,13 @@ QT += network \
 INCLUDEPATH += . \
     src/tests/testMap/ \
     src/map/
-SOURCES += src/main.cpp \
-    src/ui/mainwindow.cpp \
+SOURCES += src/ui/mainwindow.cpp \
     src/map/mapfetcher.cpp \
-    src/map/mapengine.cpp
-#    tests/testMap/testmapfetcher.cpp
+    src/map/mapengine.cpp \
+    tests/testMap/testmapfetcher.cpp \
+    tests/testMap/networkaccessmanagermock.cpp \
+    tests/testMap/networkreplymock.cpp
+
 # src/main.cpp \
 # tests/testMap/testmapengine.cpp
 HEADERS += src/ui/mainwindow.h \
index bc2ecd5..92e7e87 100644 (file)
@@ -19,7 +19,6 @@
     USA.
  */
 
-
 #include <QtGui/QApplication>
 #include "ui/mainwindow.h"
 #include "mapfetcherqueue.h"
index 90ad48b..ba1151e 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
 #include <QtCore>
 #include <QtGlobal>
 
index 2d8c028..72b0ee1 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
 #ifndef MAPENGINE_H
 #define MAPENGINE_H
 
index 9d3cc9d..fa0c42c 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
 #include <QNetworkAccessManager>
 #include <QNetworkRequest>
 #include <QNetworkReply>
 
 static int MAX_PARALLEL_DOWNLOADS = 2;
 
-MapFetcher::MapFetcher(QObject *parent)
-    : QObject(parent)
+MapFetcher::MapFetcher(QObject *parent, QNetworkAccessManager *manager)
+    : QObject(parent), m_manager(manager)
 {
     QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
+
     diskCache->setCacheDirectory(QDesktopServices::storageLocation(
             QDesktopServices::CacheLocation));
-    m_manager.setCache(diskCache);
 
-    connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
+    m_manager->setCache(diskCache);
+
+    connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
 }
 
 void MapFetcher::fetchMapImage(const QUrl &url)
@@ -47,7 +70,7 @@ void MapFetcher::startNextDownload()
     request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
                                               QNetworkRequest::PreferCache);
 
-    QNetworkReply *reply = m_manager.get(request);
+    QNetworkReply *reply = m_manager->get(request);
 
     currentDownloads.append(reply);
 }
index bbd5284..2874348 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
 #ifndef MAPFETCHER_H
 #define MAPFETCHER_H
 
@@ -27,7 +48,7 @@ public:
     * @fn MapFetcher
     * @param parent parent object
     */
-    MapFetcher(QObject *parent = 0);
+    MapFetcher(QObject *parent = 0, QNetworkAccessManager *manager = 0);
 
     ~MapFetcher();
 
@@ -59,7 +80,7 @@ signals:
     */
     void error(const QString &message);
 
-private slots:
+public slots:
     /**
     * @brief This slot is called when network manager has finished
     * the download.
@@ -68,10 +89,16 @@ private slots:
     * @param reply
     */
     void downloadFinished(QNetworkReply *reply);
-    void startNextDownload();
 
 private:
-    QNetworkAccessManager m_manager;
+    /**
+    * @brief This slot is called when
+    *
+    * @fn startNextDownload
+    */
+    void startNextDownload();
+
+    QNetworkAccessManager *m_manager;
     QList<QNetworkReply *> currentDownloads;
     QQueue<QUrl> downloadQueue;
 };
diff --git a/tests/testMap/networkaccessmanagermock.cpp b/tests/testMap/networkaccessmanagermock.cpp
new file mode 100644 (file)
index 0000000..e36d895
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QNetworkAccessManager>
+
+class NetworkAccessManagerMock : public QNetworkAccessManager
+{
+    Q_OBJECT
+
+public:
+    NetworkAccessManagerMock();
+
+    void get(const QNetworkRequest &request);
+};
+
+NetworkAccessManagerMock::NetworkAccessManagerMock()
+    : QNetworkAccessManager()
+{
+
+}
+
+void NetworkAccessManagerMock::get(const QNetworkRequest &request)
+{
+    QNetworkReply *reply = new QNetworkReply();
+}
+
+
diff --git a/tests/testMap/networkreplymock.cpp b/tests/testMap/networkreplymock.cpp
new file mode 100644 (file)
index 0000000..ca55c4d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QNetworkReply>
+
+class NetworkReplyMock : public QNetworkReply
+{
+    Q_OBJECT
+
+public:
+    NetworkReplyMock();
+};
+
+NetworkReplyMock::NetworkReplyMock()
+    : QNetworkReply()
+{
+
+}
index 820ac0e..7dbb366 100644 (file)
@@ -1,8 +1,9 @@
 #include <QtTest/QtTest>
 #include <QUrl>
 #include <QImage>
+#include <QNetworkAccessManager>
 
-#include "mapfetcherqueue.h"
+#include "mapfetcher.h"
 
 class TestMapFetcher : public QObject
 {
@@ -13,6 +14,7 @@ public:
 
 private slots:
     void testFetchImage();
+    //void testDownloadFinished();
     void testSignals();
 
 
@@ -31,6 +33,20 @@ void TestMapFetcher::testFetchImage()
     mapFetcher->fetchMapImage(url);
 }
 
+/*void TestMapFetcher::testDownloadFinished()
+{
+    NetworkReplyDummy *reply = new NetworkReplyDummy();
+    reply->setError(QNetworkReply::ConnectionRefusedError, QString("Connection refused"));
+
+    QSignalSpy errorSpy(mapFetcher, SIGNAL(error(QString)));
+    mapFetcher->downloadFinished(reply);
+    QTest::qWait(500);
+
+    QCOMPARE(errorSpy.count(), 1);
+
+    QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
+    //QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
+}*/
 
 void TestMapFetcher::testSignals()
 {
@@ -40,23 +56,23 @@ void TestMapFetcher::testSignals()
     QVERIFY(imageReceivedSpy.isValid());
 
     //Incorrect URL
-    /*QUrl url1("http://tile.openstreetmap.org/7/63/22.gi");
+    QUrl url1("http://tile.openstreetmap.org/7/63/22.gi");
     mapFetcher->fetchMapImage(url1);
     QTest::qWait(1000);
     QCOMPARE(imageReceivedErrorSpy.count(), 1);
     QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
     qDebug() << signalArgs1.at(0).toString();
 
-    //Correct URL
+    /*//Correct URL
     QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
     mapFetcher->fetchMapImage(url2);
     QTest::qWait(1000);
     QCOMPARE(imageReceivedSpy.count(), 1);
     QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
-    QCOMPARE(url2, signalArgs2.at(0).toUrl());*/
+    QCOMPARE(url2, signalArgs2.at(0).toUrl());
 
     //20 requests immediately
-    /*for (int i = 1; i < 3; ++i) {
+    for (int i = 1; i < 3; ++i) {
         for (int j = 0; j < 10; ++j) {
             QUrl url(QString("http://tile.openstreetmap.org/7/53/%1%2.png").arg(i).arg(j));
             mapFetcher->fetchMapImage(url);
@@ -74,13 +90,6 @@ void TestMapFetcher::testSignals()
 
     QTest::qWait(2000);*/
 
-    for (int i = 0; i < 10; ++i) {
-        QUrl url(QString("http://tile.openstreetmap.org/7/53/%1%2.png").arg(i));
-        mapFetcher->fetchMapImage(url);
-    }
-
-    QTest::qWait(1000);
-
 }
 
 QTEST_MAIN(TestMapFetcher)