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: location data lookup db unit test cases |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QtGui> |
|
20 #include <QString> |
|
21 |
|
22 #include <locationdatalookupdb.h> |
|
23 #include <locationservicedefines.h> |
|
24 |
|
25 |
|
26 //Lookup db test interface class |
|
27 class LocationDataLookupDbTest: public QObject |
|
28 { |
|
29 Q_OBJECT |
|
30 |
|
31 public: |
|
32 void fillLookupItem( QLookupItem &aItem ); |
|
33 |
|
34 private slots: |
|
35 |
|
36 void testLocationDataLookupDb(); |
|
37 void testNegative(); |
|
38 void testCase1(); |
|
39 void testCase2(); |
|
40 void testFindEntriesByLandmarkId(); |
|
41 void testGetEntries(); |
|
42 }; |
|
43 |
|
44 |
|
45 //Checks whether location data lookup db created. |
|
46 void LocationDataLookupDbTest::testLocationDataLookupDb() |
|
47 { |
|
48 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
49 QVERIFY( lDb != NULL ); |
|
50 delete lDb; |
|
51 } |
|
52 |
|
53 //Checks the create entry function |
|
54 void LocationDataLookupDbTest::testNegative() |
|
55 { |
|
56 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
57 QLookupItem item; |
|
58 QList<QLookupItem> itemArray; |
|
59 lDb->createEntry( item ); |
|
60 lDb->updateEntryById( item ); |
|
61 lDb->updateEntryBySourceIdAndType( item ); |
|
62 lDb->updateMaptileBySourceIdAndType( item.mSourceUid, item.mSourceType, "" ); |
|
63 lDb->deleteEntryBySourceIdAndType( item ); |
|
64 lDb->getEntries( itemArray ); |
|
65 QVERIFY( itemArray.count() == 0 ); |
|
66 lDb->findEntriesByLandmarkId( item.mDestId, itemArray ); |
|
67 QVERIFY( itemArray.count() == 0 ); |
|
68 bool returnFlag = lDb->findEntryBySourceIdAndType( item ); |
|
69 QVERIFY( returnFlag == false ); |
|
70 returnFlag = lDb->findEntryById( item ); |
|
71 QVERIFY( returnFlag == false ); |
|
72 lDb->close(); |
|
73 delete lDb; |
|
74 } |
|
75 |
|
76 // tests open(), createEntry(), findEntryById(), findEntryBySourceIdAndType(), |
|
77 // deleteEntryBySourceIdAndType(), close() apis |
|
78 void LocationDataLookupDbTest::testCase1() |
|
79 { |
|
80 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
81 bool flag = lDb->open(); |
|
82 QVERIFY( flag == true ); |
|
83 |
|
84 flag == false; |
|
85 flag = lDb->open(); |
|
86 QVERIFY( flag == true ); |
|
87 |
|
88 QLookupItem item1, item2; |
|
89 |
|
90 // find a lookup item with invalid id. return value should be false |
|
91 item2.mId = 0; |
|
92 flag = true; |
|
93 flag = lDb->findEntryById( item2 ); |
|
94 QVERIFY( flag == false ); |
|
95 |
|
96 // find a lookup item using source id and type. Item not found condition verified |
|
97 item2.mSourceType = ESourceCalendar; |
|
98 item2.mSourceUid = 0; |
|
99 flag = true; |
|
100 flag = lDb->findEntryBySourceIdAndType( item2 ); |
|
101 QVERIFY( flag == false ); |
|
102 |
|
103 // add an item1, check the mId is valid |
|
104 fillLookupItem( item1 ); |
|
105 lDb->createEntry( item1 ); |
|
106 QVERIFY( item1.mId != 0 ); |
|
107 |
|
108 // Find entry by id. Try to find the entry just added. |
|
109 item2.mId = item1.mId; |
|
110 flag = false; |
|
111 flag = lDb->findEntryById( item2 ); |
|
112 QVERIFY( flag == true ); |
|
113 |
|
114 // Find entry by source id and type. Try to find the entry just added. |
|
115 item2.mSourceType = item1.mSourceType; |
|
116 item2.mSourceUid = item1.mSourceUid; |
|
117 flag = false; |
|
118 flag = lDb->findEntryBySourceIdAndType( item2 ); |
|
119 QVERIFY( flag == true ); |
|
120 |
|
121 // delete the entry just added |
|
122 item2.mSourceType = item1.mSourceType; |
|
123 item2.mSourceUid = item1.mSourceUid; |
|
124 lDb->deleteEntryBySourceIdAndType( item2 ); |
|
125 |
|
126 // verify that the deleted entry is not found. |
|
127 flag = true; |
|
128 flag = lDb->findEntryById( item1 ); |
|
129 QVERIFY( flag == false ); |
|
130 |
|
131 lDb->close(); |
|
132 delete lDb; |
|
133 } |
|
134 |
|
135 // tests updateEntryBySourceIdAndType(), updateEntryById(), |
|
136 // updateMaptileBySourceIdAndType() apis |
|
137 void LocationDataLookupDbTest::testCase2() |
|
138 { |
|
139 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
140 bool flag = lDb->open(); |
|
141 QVERIFY( flag == true ); |
|
142 |
|
143 QLookupItem item1, item2; |
|
144 |
|
145 // add an item1, check the mId is valid |
|
146 fillLookupItem( item1 ); |
|
147 lDb->createEntry( item1 ); |
|
148 QVERIFY( item1.mId != 0 ); |
|
149 |
|
150 // Find entry by id. Try to find the entry just added. |
|
151 item2.mId = item1.mId; |
|
152 item2.mName = "new name"; |
|
153 lDb->updateEntryById( item2 ); |
|
154 flag = false; |
|
155 flag = lDb->findEntryById( item1 ); |
|
156 QVERIFY( flag == true ); |
|
157 QVERIFY( item1.mName == "new name" ); |
|
158 |
|
159 item1.mName = "new name2"; |
|
160 lDb->updateEntryBySourceIdAndType( item1 ); |
|
161 lDb->updateMaptileBySourceIdAndType( item1.mSourceUid, |
|
162 item1.mSourceType, "new maptile" ); |
|
163 |
|
164 flag = false; |
|
165 flag = lDb->findEntryById( item2 ); |
|
166 QVERIFY( flag == true ); |
|
167 QVERIFY( item2.mName == "new name2" ); |
|
168 QVERIFY( item2.mMapTilePath == "new maptile" ); |
|
169 |
|
170 // delete the entry just added |
|
171 lDb->deleteEntryBySourceIdAndType( item2 ); |
|
172 |
|
173 lDb->close(); |
|
174 delete lDb; |
|
175 } |
|
176 |
|
177 // tests findEntriesByLandmarkId() |
|
178 void LocationDataLookupDbTest::testFindEntriesByLandmarkId() |
|
179 { |
|
180 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
181 bool flag = lDb->open(); |
|
182 QVERIFY( flag == true ); |
|
183 |
|
184 QLookupItem item1, item2; |
|
185 |
|
186 // add an item1, check the mId is valid |
|
187 item1.mDestId = 10; |
|
188 item1.mName = "lm1"; |
|
189 item1.mSourceType = ESourceCalendar; |
|
190 item1.mSourceUid = 1; |
|
191 |
|
192 item2.mDestId = 10; |
|
193 item2.mName = "lm2"; |
|
194 item2.mSourceType = ESourceCalendar; |
|
195 item2.mSourceUid = 2; |
|
196 |
|
197 lDb->createEntry( item1 ); |
|
198 lDb->createEntry( item2 ); |
|
199 QVERIFY( item1.mId != 0 ); |
|
200 QVERIFY( item2.mId != 0 ); |
|
201 |
|
202 // Find entry by id. Try to find the entry just added. |
|
203 QList<QLookupItem> itemArray; |
|
204 lDb->findEntriesByLandmarkId( 10, itemArray ); |
|
205 QVERIFY( itemArray.count() == 2 ); |
|
206 QVERIFY( itemArray[0].mName == "lm1" ); |
|
207 QVERIFY( itemArray[1].mName == "lm2" ); |
|
208 |
|
209 // delete the entry just added |
|
210 lDb->deleteEntryBySourceIdAndType( item1 ); |
|
211 lDb->deleteEntryBySourceIdAndType( item2 ); |
|
212 |
|
213 lDb->close(); |
|
214 delete lDb; |
|
215 } |
|
216 |
|
217 // tests getEntries() |
|
218 void LocationDataLookupDbTest::testGetEntries() |
|
219 { |
|
220 LocationDataLookupDb* lDb = new LocationDataLookupDb(); |
|
221 bool flag = lDb->open(); |
|
222 QVERIFY( flag == true ); |
|
223 |
|
224 // Find entry by id. Try to find the entry just added. |
|
225 QList<QLookupItem> itemArray; |
|
226 lDb->getEntries( itemArray ); |
|
227 QVERIFY( itemArray.count() == 0 ); |
|
228 |
|
229 itemArray.clear(); |
|
230 |
|
231 QLookupItem item; |
|
232 |
|
233 // add an item1, check the mId is valid |
|
234 item.mDestId = 10; |
|
235 item.mName = "contact1"; |
|
236 item.mSourceType = ESourceContactsHome; |
|
237 item.mSourceUid = 1; |
|
238 lDb->createEntry( item ); |
|
239 |
|
240 item.mDestId = 11; |
|
241 item.mName = "contact2"; |
|
242 item.mSourceType = ESourceContactsHome; |
|
243 item.mSourceUid = 2; |
|
244 lDb->createEntry( item ); |
|
245 |
|
246 item.mDestId = 12; |
|
247 item.mName = "calendar entry"; |
|
248 item.mSourceType = ESourceCalendar; |
|
249 item.mSourceUid = 2; |
|
250 lDb->createEntry( item ); |
|
251 |
|
252 |
|
253 item.mDestId = 13; |
|
254 item.mName = "landmark"; |
|
255 item.mSourceType = ESourceLandmarks; |
|
256 item.mSourceUid = 13; |
|
257 lDb->createEntry( item ); |
|
258 |
|
259 lDb->getEntries( itemArray, ESourceLandmarksContactsCat ); |
|
260 QVERIFY( itemArray.count() == 2 ); |
|
261 |
|
262 itemArray.clear(); |
|
263 lDb->getEntries( itemArray, ESourceLandmarksCalendarCat ); |
|
264 QVERIFY( itemArray.count() == 1 ); |
|
265 QVERIFY( itemArray[0].mName == "calendar entry" ); |
|
266 |
|
267 itemArray.clear(); |
|
268 lDb->getEntries( itemArray, ESourceLandmarks ); |
|
269 QVERIFY( itemArray.count() == 1 ); |
|
270 QVERIFY( itemArray[0].mName == "landmark" ); |
|
271 |
|
272 itemArray.clear(); |
|
273 lDb->getEntries( itemArray ); |
|
274 QVERIFY( itemArray.count() == 4 ); |
|
275 |
|
276 for( int i = 0; i < itemArray.count(); i++ ) |
|
277 lDb->deleteEntryBySourceIdAndType( itemArray[i] ); |
|
278 |
|
279 lDb->close(); |
|
280 delete lDb; |
|
281 } |
|
282 |
|
283 |
|
284 void LocationDataLookupDbTest::fillLookupItem( QLookupItem &aItem ) |
|
285 { |
|
286 aItem.mId = 0; |
|
287 aItem.mCity = "city"; |
|
288 aItem.mCountry = "country"; |
|
289 aItem.mDestId = 2; |
|
290 aItem.mIconPath = "iconpath"; |
|
291 aItem.mIconType = QLookupItem::EIconTypeDefault; |
|
292 aItem.mIsDuplicate = 0; |
|
293 aItem.mLatitude = 0.1; |
|
294 aItem.mLongitude = 0.2; |
|
295 aItem.mMapTilePath = "maptilepath"; |
|
296 aItem.mName = "name"; |
|
297 aItem.mPostalCode = "postalcode"; |
|
298 aItem.mSourceType = ESourceCalendar; |
|
299 aItem.mSourceUid = 3; |
|
300 aItem.mState = "state"; |
|
301 aItem.mStreet = "street"; |
|
302 } |
|
303 |
|
304 QTEST_MAIN(LocationDataLookupDbTest) |
|
305 #include "ut_locationdatalookupdb.moc" |
|
306 |
|
307 |
|