03445dc85582005d77128b664425dcd038ffbd24
[situare] / tests / testsituareservice / testlocationupdate / testlocationupdate.cpp
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Henri Lampela - henri.lampela@ixonos.com
6
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.
10
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.
15
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,
19     USA.
20  */
21
22 #include <QtTest/QtTest>
23 #include <QtCore>
24 #include <QPointF>
25 #include <QNetworkAccessManager>
26
27
28 #include "../../../src/situareservice/situareservice.h"
29 #include "../../../src/situareservice/situarecommon.h"
30 #include "networkaccessmanagermock.h"
31 #include "networkreplymock.h"
32
33
34 class testLocationUpdate : public QObject
35 {
36     Q_OBJECT
37 private:
38     SituareService *situare;
39     NetworkAccessManagerMock *managerMock;
40     QList<QNetworkReply *> currentRequests;
41
42 private slots:
43
44     void testIncorrectUrl();
45     void testCorrectUrl();
46 };
47
48
49 void testLocationUpdate::testIncorrectUrl()
50 {
51     QNetworkAccessManager *manager = new QNetworkAccessManager();
52     managerMock = new NetworkAccessManagerMock(manager, this);
53     situare = new SituareService(this, manager);
54
55     managerMock->setMode(NetworkAccessManagerMock::INCORRECT);
56
57     QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
58
59     QVERIFY(receivedErrorSpy.isValid());
60
61     // incorrect url
62
63     situare->sendRequest(QUrl("http://client.situare.nett"), COOKIE, QString(";2;1"));
64     QTest::qWait(1000);
65     QCOMPARE(receivedErrorSpy.count(), 1);
66
67     delete manager;
68     //delete situare;
69 }
70
71 void testLocationUpdate::testCorrectUrl()
72 {
73     QNetworkAccessManager *manager = new QNetworkAccessManager();
74     managerMock = new NetworkAccessManagerMock(manager, this);
75     situare = new SituareService(this, manager);
76
77     managerMock->setMode(NetworkAccessManagerMock::CORRECT);
78
79     QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
80
81     QVERIFY(receivedErrorSpy.isValid());
82
83     QUrl url = QUrl("http://client.situare.net");
84
85     situare->sendRequest(url, COOKIE, QString(";2;1"));
86     QTest::qWait(1000);
87
88     QCOMPARE(receivedErrorSpy.count(), 0);
89
90     delete manager;
91     delete situare;
92 }
93
94 void testLocationUpdate::testLocationUpdateUnPublishWithStatus()
95 {
96     manager = new NetworkAccessManagerMock();
97     situare = new SituareService(this, manager);
98
99     QPointF coordinates(65, 25.5);
100     bool publish = false;
101     QString status = "test - no publish";
102     situare->updateLocation(coordinates, status, publish);
103
104     delete manager;
105     delete situare;
106 }
107
108 void testLocationUpdate::testLocationUpdateUnPublishWithoutStatus()
109 {
110     manager = new NetworkAccessManagerMock();
111     situare = new SituareService(this, manager);
112
113     QPointF coordinates(65, 25.5);
114     bool publish = false;
115     QString status = "";
116     situare->updateLocation(coordinates, status, publish);
117
118     delete manager;
119     delete situare;
120 }
121
122
123
124
125 QTEST_MAIN(testLocationUpdate)
126 #include "testlocationupdate.moc"