|
1 /* |
|
2 * Copyright (c) 2010 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 <qvaluespacepublisher.h> |
|
18 #include <qvaluespacesubscriber.h> |
|
19 |
|
20 #include "cntmaptiledblookuptable.h" |
|
21 #include "ut_cntmaptileservice.h" |
|
22 |
|
23 //Maximum maptile processing time |
|
24 const int KMapTileFetchTime = 60000; |
|
25 |
|
26 QTM_USE_NAMESPACE |
|
27 |
|
28 |
|
29 void T_MaptileServiceTest::init() |
|
30 { |
|
31 maptileService = new CntMapTileService; |
|
32 } |
|
33 |
|
34 void T_MaptileServiceTest::cleanup() |
|
35 { |
|
36 delete maptileService; |
|
37 } |
|
38 |
|
39 //Checks whether location feature enabled or disabled |
|
40 void T_MaptileServiceTest::checkLocationFeature() |
|
41 { |
|
42 QVERIFY( maptileService->isLocationFeatureEnabled() == 1 ); |
|
43 } |
|
44 |
|
45 //Checks the maptile path retrieval for preferred address |
|
46 void T_MaptileServiceTest::getPreferredAddressMapTilePath() |
|
47 { |
|
48 |
|
49 QContact* contact = new QContact(); |
|
50 |
|
51 //Add contact name |
|
52 QContactName* name = new QContactName(); |
|
53 name->setFirstName("Raj"); |
|
54 contact->saveDetail( name ); |
|
55 |
|
56 //Add address |
|
57 QContactAddress* address = new QContactAddress(); |
|
58 address->setPostOfficeBox("87640"); |
|
59 address->setStreet("Torstrasse"); |
|
60 address->setPostcode("12345"); |
|
61 address->setLocality("Berlin"); |
|
62 address->setCountry("Germany"); |
|
63 contact->saveDetail(address); |
|
64 |
|
65 //Save the contact |
|
66 QContactManager* contactManager = NULL; |
|
67 contactManager = new QContactManager("symbian"); |
|
68 contactManager->saveContact( contact ); |
|
69 |
|
70 //Wait till maptile operation complete |
|
71 QTest::qWait( KMapTileFetchTime ); |
|
72 |
|
73 |
|
74 //Get the saved id |
|
75 QContactId savedId = contact->id(); |
|
76 TUint32 contactId = savedId.localId(); |
|
77 QString string; |
|
78 |
|
79 //Get the maptile |
|
80 int error = maptileService->getMapTileImage( |
|
81 contactId, CntMapTileService::AddressPreference, string ); |
|
82 |
|
83 //Construct the QPimap from reference bitmap |
|
84 QImage referenceBitmap( "c:\\maptiletest\\preferredaddressmap.png" ); |
|
85 |
|
86 //Construct the QPixmap from new retrieved bitmap |
|
87 QImage retrievedBitmap( string ); |
|
88 |
|
89 |
|
90 //delete the contact |
|
91 contactManager->removeContact( contactId ); |
|
92 |
|
93 delete contact; |
|
94 delete name; |
|
95 delete address; |
|
96 delete contactManager; |
|
97 |
|
98 } |
|
99 |
|
100 //Checks the maptile path retrieval for work address |
|
101 void T_MaptileServiceTest::getWorkAddressMapTilePath() |
|
102 { |
|
103 QContact* contact = new QContact(); |
|
104 //Set name |
|
105 QContactName* name = new QContactName(); |
|
106 name->setFirstName("Mike"); |
|
107 contact->saveDetail(name); |
|
108 |
|
109 //Set address |
|
110 QContactAddress* address = new QContactAddress(); |
|
111 address->setPostOfficeBox("2345"); |
|
112 address->setPostcode("29834"); |
|
113 address->setStreet("Domlur"); |
|
114 address->setLocality("Bangalore"); |
|
115 address->setCountry("India"); |
|
116 address->setContexts(QContactDetail::ContextWork); |
|
117 contact->saveDetail(address); |
|
118 |
|
119 //Save the contact |
|
120 QContactManager* contactManager = NULL; |
|
121 contactManager = new QContactManager("symbian"); |
|
122 contactManager->saveContact( contact ); |
|
123 |
|
124 //Wait till maptile operation complete |
|
125 QTest::qWait( KMapTileFetchTime ); |
|
126 |
|
127 |
|
128 //Get the saved id |
|
129 QContactId savedId = contact->id(); |
|
130 TUint32 contactId = savedId.localId(); |
|
131 QString string; |
|
132 |
|
133 //Get the maptile |
|
134 int error = maptileService->getMapTileImage( |
|
135 contactId, CntMapTileService::AddressWork, string ); |
|
136 |
|
137 //Construct the QPimap from already stored bitmap |
|
138 QImage referenceBitmap( "c:\\maptiletest\\workaddressmap.png" ); |
|
139 |
|
140 //Construct the QPixmap from new retrieved bitmap |
|
141 QImage retrievedBitmap( string ); |
|
142 |
|
143 //check results are same |
|
144 QVERIFY( retrievedBitmap == referenceBitmap ); |
|
145 |
|
146 |
|
147 contactManager->removeContact( contactId ); |
|
148 |
|
149 delete contact; |
|
150 delete name; |
|
151 delete address; |
|
152 delete contactManager; |
|
153 } |
|
154 |
|
155 //Checks the maptile path retrieval for home address |
|
156 void T_MaptileServiceTest::getHomeAddressMapTilePath() |
|
157 { |
|
158 QContact* contact = new QContact(); |
|
159 |
|
160 QContactName* name = new QContactName(); |
|
161 name->setFirstName("first"); |
|
162 contact->saveDetail(name); |
|
163 |
|
164 QContactAddress* address = new QContactAddress(); |
|
165 address->setContexts(QContactDetail::ContextHome); |
|
166 address->setPostOfficeBox("81282"); |
|
167 address->setStreet("Keilalahdentie"); |
|
168 address->setPostcode("67890"); |
|
169 address->setLocality("Espoo"); |
|
170 address->setCountry("Finland"); |
|
171 contact->saveDetail(address); |
|
172 |
|
173 //Save the contact |
|
174 QContactManager* contactManager = NULL; |
|
175 contactManager = new QContactManager("symbian"); |
|
176 contactManager->saveContact( contact ); |
|
177 |
|
178 //Wait till maptile operation complete |
|
179 QTest::qWait( KMapTileFetchTime ); |
|
180 |
|
181 //Get the saved id |
|
182 QContactId savedId = contact->id(); |
|
183 TUint32 contactId = savedId.localId(); |
|
184 QString string; |
|
185 |
|
186 //Get the maptile |
|
187 int error = maptileService->getMapTileImage( |
|
188 contactId, CntMapTileService::AddressHome, string ); |
|
189 |
|
190 //Construct the QPimap from already stored bitmap |
|
191 QImage referenceBitmap( "c:\\maptiletest\\homeaddressmap.png" ); |
|
192 |
|
193 //Construct the QPixmap from new retrieved bitmap |
|
194 QImage retrievedBitmap( string ); |
|
195 |
|
196 //comapre the bitmaps |
|
197 QVERIFY( retrievedBitmap == referenceBitmap ); |
|
198 |
|
199 |
|
200 contactManager->removeContact( contactId ); |
|
201 |
|
202 delete contact; |
|
203 delete name; |
|
204 delete address; |
|
205 delete contactManager; |
|
206 } |
|
207 |
|
208 //Checks the maptile path retrieval returns NULL for invalid address |
|
209 void T_MaptileServiceTest::checkInvalidContactId() |
|
210 { |
|
211 |
|
212 QContact* contact = new QContact(); |
|
213 |
|
214 QContactName* name = new QContactName(); |
|
215 name->setFirstName("first"); |
|
216 contact->saveDetail(name); |
|
217 |
|
218 //Add some invalid address |
|
219 QContactAddress* address = new QContactAddress(); |
|
220 address->setPostOfficeBox("11111"); |
|
221 address->setStreet("htrtfdsk"); |
|
222 address->setPostcode("98989"); |
|
223 address->setLocality("ghwdxnkwnn"); |
|
224 address->setCountry("Fbsjwskws"); |
|
225 contact->saveDetail(address); |
|
226 |
|
227 //Save the contact |
|
228 QContactManager* contactManager = NULL; |
|
229 contactManager = new QContactManager("symbian"); |
|
230 contactManager->saveContact( contact ); |
|
231 |
|
232 //Wait till maptile operation complete |
|
233 QTest::qWait( KMapTileFetchTime ); |
|
234 |
|
235 |
|
236 //Get the saved id |
|
237 QContactId savedId = contact->id(); |
|
238 TUint32 contactId = savedId.localId(); |
|
239 QString string; |
|
240 |
|
241 //Get the maptile |
|
242 int error = maptileService->getMapTileImage( |
|
243 contactId, CntMapTileService::AddressPreference, string ); |
|
244 |
|
245 contactManager->removeContact( contactId ); |
|
246 |
|
247 //Maptile path should be NULL for invalid address |
|
248 QVERIFY( string.isEmpty() ); |
|
249 |
|
250 delete contact; |
|
251 delete name; |
|
252 delete address; |
|
253 delete contactManager; |
|
254 } |
|
255 |
|
256 void T_MaptileServiceTest::publishForMaptileFetching() |
|
257 { |
|
258 int addressCount = 1; |
|
259 int contactId = 10; |
|
260 |
|
261 maptileService->publishValue( contactId, CntMapTileService::AddressPreference, addressCount ); |
|
262 QVERIFY( maptileService->mContactEntryInfo == QString("10-3-1")); |
|
263 |
|
264 maptileService->publishValue( contactId, CntMapTileService::AddressHome, addressCount ); |
|
265 QVERIFY( maptileService->mContactEntryInfo == QString("10-4-1")); |
|
266 |
|
267 maptileService->publishValue( contactId, CntMapTileService::AddressWork, addressCount ); |
|
268 QVERIFY( maptileService->mContactEntryInfo == QString("10-5-1")); |
|
269 } |
|
270 |
|
271 void T_MaptileServiceTest::readInvalidContactInfotmation() |
|
272 { |
|
273 int contactId = -1; |
|
274 TLookupItem lookupItem; |
|
275 int numberOfaddress = 0; |
|
276 |
|
277 int error = maptileService->readEntryFromMaptileDataBase( |
|
278 contactId, |
|
279 CntMapTileService::AddressPreference, |
|
280 lookupItem, |
|
281 numberOfaddress ); |
|
282 QVERIFY( error == KErrNotFound ); |
|
283 |
|
284 |
|
285 } |
|
286 |
|
287 |