Added updated unit tests for updateLocation and reverseGeo.
[situare] / tests / testsituareservice / teststringformations / teststringformations.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
27 #include "../../../src/situareservice/situareservice.h"
28 #include "../../../src/situareservice/situarecommon.h"
29
30
31 class testStringFormations : public QObject
32 {
33     Q_OBJECT
34 private:
35     SituareService *situare;
36
37 private slots:
38
39     void testWithNoPublishNoStatus();       // part 1 of testFormUrlParameters
40     void testWithStatusNoPublish();         // part 2 of testFormUrlParameters
41     void testWithPublishTrueNoStatus();     // part 3 of testFormUrlParameters
42     void testWithStatusPublishTrue();       // part 4 of testFormUrlParameters
43     void testWithStatusPublishFalse();      // part 5 of testFormUrlParameters
44     void testWithPublishFalseNoStatus();    // part 6 of testFormUrlParameters
45
46     void testFormUpdateLocationUrl();       // updateLocation url test
47     void testFormReverseGeoUrl();           // reverseGeo url test
48
49 };
50
51 void testStringFormations::testWithNoPublishNoStatus()
52 {
53     QPointF coordinates(65.3, 25.5);
54     QString publish = "";
55     QString status = "";
56     QString params = situare->formUrlParameters(coordinates, status, publish);
57
58     QCOMPARE(QString("?lat=65.3&lon=25.5"), params);
59 }
60
61 void testStringFormations::testWithStatusNoPublish()
62 {
63     QPointF coordinates(65.3, 25.5);
64     QString publish = "";
65     QString status = "testing";
66     QString params = situare->formUrlParameters(coordinates, status, publish);
67
68     QCOMPARE(QString("?lat=65.3&lon=25.5&data=testing"), params);
69 }
70
71 void testStringFormations::testWithPublishTrueNoStatus()
72 {
73     QPointF coordinates(65.3, 25.5);
74     QString publish = "true";
75     QString status = "";
76     QString params = situare->formUrlParameters(coordinates, status, publish);
77
78     QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true"), params);
79 }
80
81 void testStringFormations::testWithStatusPublishTrue()
82 {
83     QPointF coordinates(65.3, 25.5);
84     QString publish = "true";
85     QString status = "testing";
86     QString params = situare->formUrlParameters(coordinates, status, publish);
87
88     QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true&data=testing"), params);
89 }
90
91 void testStringFormations::testWithStatusPublishFalse()
92 {
93     QPointF coordinates(65.3, 25.5);
94     QString publish = "false";
95     QString status = "testing";
96     QString params = situare->formUrlParameters(coordinates, status, publish);
97
98     QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false&data=testing"), params);
99 }
100
101 void testStringFormations::testWithPublishFalseNoStatus()
102 {
103     QPointF coordinates(65.3, 25.5);
104     QString publish = "false";
105     QString status = "";
106     QString params = situare->formUrlParameters(coordinates, status, publish);
107
108     QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false"), params);
109 }
110
111 void testStringFormations::testFormUpdateLocationUrl()
112 {
113     QString urlParameters = "?lat=65.3&lon=25.5&publish=false";
114     QUrl url = situare->formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
115
116     QCOMPARE(QString("http://client.situare.net/updateLocation.php?lat=65.3&lon=25.5&publish=false"), url.toString());
117 }
118
119 void testStringFormations::testFormReverseGeoUrl()
120 {
121     QPointF coordinates(65.3, 25.5);
122
123     QString params = situare->formUrlParameters(coordinates);
124
125     QUrl url = situare->formUrl(SITUARE_URL, REVERSE_GEO, params);
126
127     QCOMPARE(QString("http://client.situare.net/reversegeo.php?lat=65.3&lon=25.5"), url.toString());
128 }
129
130
131 QTEST_MAIN(testStringFormations)
132 #include "teststringformations.moc"