1 #include <QtTest/QtTest>
4 #include <QNetworkAccessManager>
6 #include "mapfetcher.h"
8 class TestMapFetcher : public QObject
16 void testFetchImage();
17 //void testDownloadFinished();
22 MapFetcher *mapFetcher;
25 TestMapFetcher::TestMapFetcher()
27 mapFetcher = new MapFetcher();
30 void TestMapFetcher::testFetchImage()
33 mapFetcher->fetchMapImage(url);
36 /*void TestMapFetcher::testDownloadFinished()
38 NetworkReplyDummy *reply = new NetworkReplyDummy();
39 reply->setError(QNetworkReply::ConnectionRefusedError, QString("Connection refused"));
41 QSignalSpy errorSpy(mapFetcher, SIGNAL(error(QString)));
42 mapFetcher->downloadFinished(reply);
45 QCOMPARE(errorSpy.count(), 1);
47 QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
48 //QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
51 void TestMapFetcher::testSignals()
53 QSignalSpy imageReceivedSpy(mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)));
54 QSignalSpy imageReceivedErrorSpy(mapFetcher, SIGNAL(error(QString)));
56 QVERIFY(imageReceivedSpy.isValid());
59 QUrl url1("http://tile.openstreetmap.org/7/63/22.gi");
60 mapFetcher->fetchMapImage(url1);
62 QCOMPARE(imageReceivedErrorSpy.count(), 1);
63 QList<QVariant> signalArgs1 = imageReceivedErrorSpy.takeFirst();
64 qDebug() << signalArgs1.at(0).toString();
67 QUrl url2("http://tile.openstreetmap.org/7/63/42.png");
68 mapFetcher->fetchMapImage(url2);
70 QCOMPARE(imageReceivedSpy.count(), 1);
71 QList<QVariant> signalArgs2 = imageReceivedSpy.takeLast();
72 QCOMPARE(url2, signalArgs2.at(0).toUrl());
74 //20 requests immediately
75 for (int i = 1; i < 3; ++i) {
76 for (int j = 0; j < 10; ++j) {
77 QUrl url(QString("http://tile.openstreetmap.org/7/53/%1%2.png").arg(i).arg(j));
78 mapFetcher->fetchMapImage(url);
83 //50 requests immediately
84 for (int i = 1; i < 6; ++i) {
85 for (int j = 0; j < 10; ++j) {
86 QUrl url(QString("http://tile.openstreetmap.org/7/63/%1%2.png").arg(i).arg(j));
87 mapFetcher->fetchMapImage(url);
95 QTEST_MAIN(TestMapFetcher)
96 #include "testmapfetcher.moc"