Added project for building all unit tests
[situare] / tests / situareservice / 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
26 #include "../../../src/situareservice/situareservice.h"
27 #include "../../../src/situareservice/situarecommon.h"
28 #include "../../../src/facebookservice/facebookauthentication.h"
29
30
31 class testLocationUpdate : public QObject
32 {
33     Q_OBJECT
34 public:
35     ~testLocationUpdate();
36 private:
37     SituareService *situare;
38     QList<QNetworkReply *> currentRequests;
39     FacebookAuthentication fbAuthentication;
40     FacebookCredentials credentials;
41
42 private slots:
43
44     //void testIncorrectUrl();
45     //void testCorrectUrl();
46     void testLocationUpdateCase();
47 };
48
49 testLocationUpdate::~testLocationUpdate()
50 {
51     delete situare;
52 }
53
54
55 //void testLocationUpdate::testIncorrectUrl()
56 //{
57 //    QNetworkAccessManager *manager = new QNetworkAccessManager();
58 //    managerMock = new NetworkAccessManagerMock(manager, this);
59 //    situare = new SituareService(this, manager);
60 //
61 //    managerMock->setMode(NetworkAccessManagerMock::INCORRECT);
62 //
63 //    QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
64 //
65 //    QVERIFY(receivedErrorSpy.isValid());
66 //
67 //    // incorrect url
68 //
69 //    situare->sendRequest(QUrl("http://client.situare.nett"), COOKIE, QString(""));
70 //    QTest::qWait(1000);
71 //    QCOMPARE(receivedErrorSpy.count(), 1);
72 //
73 //    delete manager;
74 //}
75
76 //void testLocationUpdate::testCorrectUrl()
77 //{
78 //    QNetworkAccessManager *manager = new QNetworkAccessManager();
79 //    managerMock = new NetworkAccessManagerMock(manager, this);
80 //    situare = new SituareService(this, manager);
81 //
82 //    managerMock->setMode(NetworkAccessManagerMock::CORRECT);
83 //
84 //    QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
85 //
86 //    QVERIFY(receivedErrorSpy.isValid());
87 //
88 //    QUrl url = QUrl("http://client.situare.net");
89 //
90 //    situare->sendRequest(url, COOKIE, QString(""));
91 //    QTest::qWait(1000);
92 //
93 //    QCOMPARE(receivedErrorSpy.count(), 0);
94 //
95 //    delete manager;
96 //}
97
98 void testLocationUpdate::testLocationUpdateCase()
99 {
100     situare = new SituareService(this);
101
102     QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
103
104     QPointF coordinates(65.3, 25.5);
105     bool publish = true;
106     QString status = "unit-test";
107
108     situare->updateLocation(coordinates, status, publish);
109     QTest::qWait(1000);
110
111     QCOMPARE(receivedErrorSpy.count(), 0);
112 }
113
114
115 QTEST_MAIN(testLocationUpdate)
116 #include "testlocationupdate.moc"