Implemented Route class and unit tests for it
[situare] / tests / user / testuser.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 <QPointer>
25 #include <QUrl>
26 #include <QDebug>
27
28
29 #include "../../src/user/user.h"
30
31
32 class TestUser : public QObject
33 {
34     Q_OBJECT
35 public:
36     TestUser();
37     ~TestUser();
38 private:
39     User *user;
40
41 private slots:
42
43     void testAddress();
44     void testCoordinates();
45     void testName();
46     void testNote();
47     void testImageUrl();
48     void testTimestamp();
49     void testUserType();
50     void testDistance();
51     void testUserId();
52 };
53
54 TestUser::TestUser()
55 {
56     const QString address = "Kuja 3 A, 90560 Oulu, Finland";
57     const QPointF coordinates(65.3, 25.5);
58     const QString name = "Jukka Kukka";
59     const QString note = "Testing";
60     const QUrl imageUrl = QUrl("http://profile.ak.fbcdn.net/v225/874/99/q100000139211584_3252.jpg");
61     const QString timestamp = "1 minute ago";
62     const bool userType = false;
63     const QString units = "km";
64     const QString userId = "111000222";
65     const double value = 12.1;
66
67     user = new User(address, coordinates, name, note, imageUrl, timestamp, userType, userId, units, value);
68 }
69
70 TestUser::~TestUser()
71 {
72     delete user;
73 }
74
75 void TestUser::testAddress()
76 {
77     QString newValue = "Kalmakuja 6 B, 90650 Oulu, Finland";
78     QString oldValue = user->address();
79
80     qDebug() << oldValue;
81
82     user->setAddress(newValue);
83
84     QString currentValue = user->address();
85
86     qDebug() << currentValue;
87
88     QCOMPARE(currentValue, newValue);
89 }
90
91 void TestUser::testCoordinates()
92 {
93     QPointF oldValue = user->coordinates();
94
95     qDebug() << oldValue;
96
97     QPointF newValue(64.3, 25.8);
98
99     user->setCoordinates(newValue);
100
101     QPointF currentValue = user->coordinates();
102
103     qDebug() << currentValue;
104
105     QCOMPARE(currentValue, newValue);
106 }
107
108 void TestUser::testName()
109 {
110     QString currentValue = user->name();
111
112     qDebug() << currentValue;
113
114     QCOMPARE(currentValue, QString("Jukka Kukka"));
115 }
116
117 void TestUser::testNote()
118 {
119     QString oldValue = user->note();
120
121     qDebug() << oldValue;
122
123     QString newValue = "Still testing";
124
125     user->setNote(newValue);
126
127     QString currentValue = user->note();
128
129     qDebug() << currentValue;
130
131     QCOMPARE(currentValue, newValue);
132 }
133
134 void TestUser::testImageUrl()
135 {
136     QUrl oldValue = user->profileImageUrl();
137
138     qDebug() << oldValue;
139
140     QUrl newValue = QUrl("http://profile.ak.fbcdn.net/v225/874/99/xxxxxxx.jpg");
141
142     user->setProfileImageUrl(newValue);
143
144     QUrl currentValue = user->profileImageUrl();
145
146     qDebug() << currentValue;
147
148     QCOMPARE(currentValue, newValue);
149 }
150
151 void TestUser::testTimestamp()
152 {
153     QString oldValue = user->timestamp();
154
155     qDebug() << oldValue;
156
157     QString newValue = "2 minutes ago";
158
159     user->setTimestamp(newValue);
160
161     QString currentValue = user->timestamp();
162
163     qDebug() << currentValue;
164
165     QCOMPARE(currentValue, newValue);
166 }
167
168 void TestUser::testUserType()
169 {
170     bool currentValue = user->type();
171
172     qDebug() << currentValue;
173
174     QCOMPARE(currentValue, false);
175 }
176
177 void TestUser::testDistance()
178 {
179     QString oldUnitValue;
180     double oldDistanceValue;
181
182     user->distance(oldDistanceValue, oldUnitValue);
183
184     qDebug() << oldDistanceValue  << oldUnitValue;
185
186     QString newUnitValue = "miles";
187     double newDistanceValue = 2.13;
188
189     user->setDistance(newDistanceValue, newUnitValue);
190
191     QString currentUnitValue;
192     double currentDistanceValue;
193
194     user->distance(currentDistanceValue, currentUnitValue);
195
196     qDebug() << currentDistanceValue << currentUnitValue;
197
198     QCOMPARE(currentDistanceValue, newDistanceValue);
199     QCOMPARE(currentUnitValue, newUnitValue);
200 }
201
202 void TestUser::testUserId()
203 {
204     QString currentValue = user->userId();
205
206     qDebug() << currentValue;
207
208     QCOMPARE(currentValue, QString("111000222"));
209 }
210
211 QTEST_MAIN(TestUser)
212 #include "testuser.moc"