|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <QtTest/QtTest> |
|
18 #include <QtGui> |
|
19 #include <QString> |
|
20 #include <qtcontacts.h> |
|
21 #include <qcontactmanager.h> |
|
22 |
|
23 |
|
24 #include "maptileservice.h" |
|
25 |
|
26 |
|
27 //Maximum maptile processing time |
|
28 const int KMapTileFetchTime = 150000; |
|
29 |
|
30 QTM_USE_NAMESPACE |
|
31 |
|
32 |
|
33 //Maptile test interface class |
|
34 class MaptileServiceTest: public QObject |
|
35 { |
|
36 Q_OBJECT |
|
37 |
|
38 private slots: |
|
39 |
|
40 void checkLocationFeature(); |
|
41 void getPreferredAddressMapTilePath(); |
|
42 void getWorkAddressMapTilePath(); |
|
43 void getHomeAddressMapTilePath(); |
|
44 void checkInvalidContactId(); |
|
45 |
|
46 }; |
|
47 |
|
48 |
|
49 //Checks whether location feature enabled or disabled |
|
50 void MaptileServiceTest::checkLocationFeature() |
|
51 { |
|
52 |
|
53 QVERIFY( CntMapTileService::isLocationFeatureEnabled() == 1 ); |
|
54 } |
|
55 |
|
56 //Checks the maptile path retrieval for preferred address |
|
57 void MaptileServiceTest::getPreferredAddressMapTilePath() |
|
58 { |
|
59 |
|
60 QContact* contact = new QContact(); |
|
61 |
|
62 //Add contact name |
|
63 QContactName* name = new QContactName(); |
|
64 name->setFirst("Raj"); |
|
65 contact->saveDetail( name ); |
|
66 |
|
67 //Add address |
|
68 QContactAddress* address = new QContactAddress(); |
|
69 address->setPostOfficeBox("87640"); |
|
70 address->setStreet("Torstrasse"); |
|
71 address->setPostcode("12345"); |
|
72 address->setLocality("Berlin"); |
|
73 address->setCountry("Germany"); |
|
74 contact->saveDetail(address); |
|
75 |
|
76 //Save the contact |
|
77 QContactManager* contactManager = NULL; |
|
78 contactManager = new QContactManager("symbian"); |
|
79 contactManager->saveContact( contact ); |
|
80 |
|
81 //Wait till maptile operation complete |
|
82 QTest::qWait( KMapTileFetchTime ); |
|
83 |
|
84 |
|
85 //Get the saved id |
|
86 QContactId savedId = contact->id(); |
|
87 TUint32 contactId = savedId.localId(); |
|
88 |
|
89 //Get the maptile |
|
90 QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressPreference ); |
|
91 |
|
92 //Construct the QPimap from reference bitmap |
|
93 QImage referenceBitmap( "c:\\maptiletest\\preferredaddressmap.png" ); |
|
94 |
|
95 //Construct the QPixmap from new retrieved bitmap |
|
96 QImage retrievedBitmap( string ); |
|
97 |
|
98 |
|
99 //delete the contact |
|
100 contactManager->removeContact( contactId ); |
|
101 |
|
102 delete contact; |
|
103 delete name; |
|
104 delete address; |
|
105 delete contactManager; |
|
106 |
|
107 } |
|
108 |
|
109 //Checks the maptile path retrieval for work address |
|
110 void MaptileServiceTest::getWorkAddressMapTilePath() |
|
111 { |
|
112 |
|
113 QContact* contact = new QContact(); |
|
114 |
|
115 //Set name |
|
116 QContactName* name = new QContactName(); |
|
117 name->setFirst("Mike"); |
|
118 contact->saveDetail(name); |
|
119 |
|
120 //Set address |
|
121 QContactAddress* address = new QContactAddress(); |
|
122 address->setPostOfficeBox("2345"); |
|
123 address->setPostcode("29834"); |
|
124 address->setStreet("Domlur"); |
|
125 address->setLocality("Bangalore"); |
|
126 address->setCountry("India"); |
|
127 address->setContexts(QContactDetail::ContextWork); |
|
128 contact->saveDetail(address); |
|
129 |
|
130 //Save the contact |
|
131 QContactManager* contactManager = NULL; |
|
132 contactManager = new QContactManager("symbian"); |
|
133 contactManager->saveContact( contact ); |
|
134 |
|
135 //Wait till maptile operation complete |
|
136 QTest::qWait( KMapTileFetchTime ); |
|
137 |
|
138 |
|
139 //Get the saved id |
|
140 QContactId savedId = contact->id(); |
|
141 TUint32 contactId = savedId.localId(); |
|
142 |
|
143 //Get the maptile |
|
144 QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressWork ); |
|
145 |
|
146 //Construct the QPimap from already stored bitmap |
|
147 QImage referenceBitmap( "c:\\maptiletest\\workaddressmap.png" ); |
|
148 |
|
149 //Construct the QPixmap from new retrieved bitmap |
|
150 QImage retrievedBitmap( string ); |
|
151 |
|
152 //check results are same |
|
153 QVERIFY( retrievedBitmap == referenceBitmap ); |
|
154 |
|
155 |
|
156 contactManager->removeContact( contactId ); |
|
157 |
|
158 delete contact; |
|
159 delete name; |
|
160 delete address; |
|
161 delete contactManager; |
|
162 |
|
163 } |
|
164 |
|
165 //Checks the maptile path retrieval for home address |
|
166 void MaptileServiceTest::getHomeAddressMapTilePath() |
|
167 { |
|
168 |
|
169 QContact* contact = new QContact(); |
|
170 |
|
171 QContactName* name = new QContactName(); |
|
172 name->setFirst("first"); |
|
173 contact->saveDetail(name); |
|
174 |
|
175 QContactAddress* address = new QContactAddress(); |
|
176 address->setContexts(QContactDetail::ContextHome); |
|
177 address->setPostOfficeBox("81282"); |
|
178 address->setStreet("Keilalahdentie"); |
|
179 address->setPostcode("67890"); |
|
180 address->setLocality("Espoo"); |
|
181 address->setCountry("Finland"); |
|
182 contact->saveDetail(address); |
|
183 |
|
184 //Save the contact |
|
185 QContactManager* contactManager = NULL; |
|
186 contactManager = new QContactManager("symbian"); |
|
187 contactManager->saveContact( contact ); |
|
188 |
|
189 //Wait till maptile operation complete |
|
190 QTest::qWait( KMapTileFetchTime ); |
|
191 |
|
192 //Get the saved id |
|
193 QContactId savedId = contact->id(); |
|
194 TUint32 contactId = savedId.localId(); |
|
195 |
|
196 //Get the maptile |
|
197 QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressHome ); |
|
198 |
|
199 //Construct the QPimap from already stored bitmap |
|
200 QImage referenceBitmap( "c:\\maptiletest\\homeaddressmap.png" ); |
|
201 |
|
202 //Construct the QPixmap from new retrieved bitmap |
|
203 QImage retrievedBitmap( string ); |
|
204 |
|
205 //comapre the bitmaps |
|
206 QVERIFY( retrievedBitmap == referenceBitmap ); |
|
207 |
|
208 |
|
209 contactManager->removeContact( contactId ); |
|
210 |
|
211 delete contact; |
|
212 delete name; |
|
213 delete address; |
|
214 delete contactManager; |
|
215 |
|
216 } |
|
217 |
|
218 //Checks the maptile path retrieval returns NULL for invalid address |
|
219 void MaptileServiceTest::checkInvalidContactId() |
|
220 { |
|
221 |
|
222 QContact* contact = new QContact(); |
|
223 |
|
224 QContactName* name = new QContactName(); |
|
225 name->setFirst("first"); |
|
226 contact->saveDetail(name); |
|
227 |
|
228 //Add some invalid address |
|
229 QContactAddress* address = new QContactAddress(); |
|
230 address->setPostOfficeBox("11111"); |
|
231 address->setStreet("htrtfdsk"); |
|
232 address->setPostcode("98989"); |
|
233 address->setLocality("ghwdxnkwnn"); |
|
234 address->setCountry("Fbsjwskws"); |
|
235 contact->saveDetail(address); |
|
236 |
|
237 //Save the contact |
|
238 QContactManager* contactManager = NULL; |
|
239 contactManager = new QContactManager("symbian"); |
|
240 contactManager->saveContact( contact ); |
|
241 |
|
242 //Wait till maptile operation complete |
|
243 QTest::qWait( KMapTileFetchTime ); |
|
244 |
|
245 |
|
246 //Get the saved id |
|
247 QContactId savedId = contact->id(); |
|
248 TUint32 contactId = savedId.localId(); |
|
249 |
|
250 //Get the maptile |
|
251 QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressPreference ); |
|
252 |
|
253 contactManager->removeContact( contactId ); |
|
254 |
|
255 //Maptile path should be NULL for invalid address |
|
256 QVERIFY( string.isNull() ); |
|
257 |
|
258 delete contact; |
|
259 delete name; |
|
260 delete address; |
|
261 delete contactManager; |
|
262 |
|
263 |
|
264 } |
|
265 |
|
266 |
|
267 QTEST_MAIN(MaptileServiceTest) |
|
268 #include "ut_maptileservice.moc" |
|
269 |
|
270 |