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 \
USA.
*/
-
#include <QtGui/QApplication>
#include "ui/mainwindow.h"
#include "mapfetcherqueue.h"
+/*
+ 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>
+/*
+ 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
+/*
+ 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)
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
- QNetworkReply *reply = m_manager.get(request);
+ QNetworkReply *reply = m_manager->get(request);
currentDownloads.append(reply);
}
+/*
+ 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
* @fn MapFetcher
* @param parent parent object
*/
- MapFetcher(QObject *parent = 0);
+ MapFetcher(QObject *parent = 0, QNetworkAccessManager *manager = 0);
~MapFetcher();
*/
void error(const QString &message);
-private slots:
+public slots:
/**
* @brief This slot is called when network manager has finished
* the download.
* @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;
};
--- /dev/null
+/*
+ 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();
+}
+
+
--- /dev/null
+/*
+ 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()
+{
+
+}
#include <QtTest/QtTest>
#include <QUrl>
#include <QImage>
+#include <QNetworkAccessManager>
-#include "mapfetcherqueue.h"
+#include "mapfetcher.h"
class TestMapFetcher : public QObject
{
private slots:
void testFetchImage();
+ //void testDownloadFinished();
void testSignals();
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()
{
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);
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)