2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include <QtTest/QtTest>
25 #include <QNetworkAccessManager>
28 #include "mapfetcher.h"
29 #include "networkaccessmanagermock.h"
34 * @class TestMapFetcher testmapfetcher.cpp "tests/testMap/testmapfetcher.cpp"
36 class TestMapFetcher : public QObject
41 * @brief TestMapFetcher is a test class for MapFetcher class.
50 * @brief Tests fetchImage method with empty URL as parameter.
52 * @fn testFetchImageEmptyURL
54 void testFetchImageEmptyURL();
56 * @brief Tests fetchImage method with incorrect URL as parameter.
58 * @fn testFetchImageIncorrectURL
60 void testFetchImageIncorrectURL();
62 * @brief Tests fetchImage method with correct URL as parameter.
64 * @fn testFetchImageCorrectURL
66 void testFetchImageCorrectURL();
68 void testFetchCorruptedImage();
71 * @brief Tests fetchImage method 20 times with correct URLs
74 * @fn testFetchImage20URLs
76 void testFetchImage20URLs();
78 * @brief Tests fetchImage method 50 times with correct URLs
81 * @fn testFetchImage50URLs
83 void testFetchImage50URLs();
86 MapFetcher *mapFetcher;
89 TestMapFetcher::TestMapFetcher()
91 QNetworkAccessManager *manager = new QNetworkAccessManager();
92 NetworkAccessManagerMock *managerMock = new NetworkAccessManagerMock(manager, this);
93 mapFetcher = new MapFetcher(this, managerMock);
96 void TestMapFetcher::testFetchImageEmptyURL()
99 mapFetcher->fetchMapImage(url);
102 void TestMapFetcher::testFetchImageIncorrectURL()
104 // QSignalSpy imageReceivedErrorSpy(mapFetcher, SIGNAL(error(QString)));
106 // QVERIFY(imageReceivedErrorSpy.isValid());
109 // QUrl url1("http://tile.openstreetmap.org/7/63/22.gi");
110 // qDebug() << QTime::currentTime().toString();
111 // mapFetcher->fetchMapImage(url1);
112 // QTest::qWait(5000);
113 // QCOMPARE(imageReceivedErrorSpy.count(), 1);
116 void TestMapFetcher::testFetchImageCorrectURL()
118 // QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
120 // QVERIFY(imageReceivedSpy.isValid());
123 // QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
124 // mapFetcher->fetchMapImage(url2);
125 // QTest::qWait(2000);
126 // QCOMPARE(imageReceivedSpy.count(), 1);
127 // QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
128 // QCOMPARE(url2, signalArgs2.at(0).toUrl());
131 void TestMapFetcher::testFetchCorruptedImage()
133 // QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
135 // QVERIFY(imageReceivedSpy.isValid());
138 // QUrl url2("http://tile.openstreetmap.org/7/63/1.png");
139 // mapFetcher->fetchMapImage(url2);
140 // QTest::qWait(1000);
141 // QCOMPARE(imageReceivedSpy.count(), 1);
142 // QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
143 // QCOMPARE(url2, signalArgs2.at(0).toUrl());
146 void TestMapFetcher::testFetchImage20URLs()
148 // QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
149 // QSignalSpy imageReceivedErrorSpy(mapFetcher, SIGNAL(error(QString)));
151 // QVERIFY(imageReceivedSpy.isValid());
154 // for (int i = 1; i < 3; ++i) {
155 // for (int j = 0; j < 10; ++j) {
156 // QUrl url(QString("http://tile.openstreetmap.org/18/23/%1%2.png").arg(i).arg(j));
157 // mapFetcher->fetchMapImage(url);
160 // QTest::qWait(2000);
161 // int totalCount = imageReceivedSpy.count() + imageReceivedErrorSpy.count();
162 // QCOMPARE(totalCount, 20);
165 void TestMapFetcher::testFetchImage50URLs()
167 // QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
168 // QSignalSpy imageReceivedErrorSpy(mapFetcher, SIGNAL(error(QString)));
170 // QVERIFY(imageReceivedSpy.isValid());
173 // for (int i = 1; i < 6; ++i) {
174 // for (int j = 0; j < 10; ++j) {
175 // QUrl url(QString("http://tile.openstreetmap.org/18/24/%1%2.png").arg(i).arg(j));
176 // mapFetcher->fetchMapImage(url);
180 // QTest::qWait(5000);
181 // int totalCount = imageReceivedSpy.count() + imageReceivedErrorSpy.count();
182 // QCOMPARE(totalCount, 50);
185 QTEST_MAIN(TestMapFetcher)
186 #include "testmapfetcher.moc"