|
1 /* |
|
2 * Copyright (c) 2005 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 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "FT_CPosTp37.h" |
|
22 #include <EPos_CPosLandmarkDatabase.h> |
|
23 #include <EPos_CPosLmCompositeCriteria.h> |
|
24 #include <EPos_CPosLmCategoryCriteria.h> |
|
25 #include <EPos_CPosLmCatNameCriteria.h> |
|
26 #include <EPos_CPosLmTextCriteria.h> |
|
27 #include <EPos_CPosLmIdListCriteria.h> |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // CPosTp37::CloseTest |
|
32 // |
|
33 // (other items were commented in a header). |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 void CPosTp37::CloseTest() |
|
37 { |
|
38 iLog->Log(_L("CloseTest")); |
|
39 delete iDatabase; |
|
40 iDatabase=NULL; |
|
41 |
|
42 delete iLandmarkSearch; |
|
43 iLandmarkSearch = NULL; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // CPosTp37::StartL |
|
48 // |
|
49 // (other items were commented in a header). |
|
50 // --------------------------------------------------------- |
|
51 // |
|
52 void CPosTp37::StartL() |
|
53 { |
|
54 TTime startTime; |
|
55 TTime stopTime; |
|
56 |
|
57 startTime.UniversalTime(); |
|
58 // Delete "c:\\system\\data\\eposlm.ldb" |
|
59 RemoveDefaultDbL(); |
|
60 |
|
61 iDatabase = UseGeneratedDbFileL(); |
|
62 |
|
63 if (iDatabase->IsInitializingNeeded()) |
|
64 { |
|
65 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
66 } |
|
67 |
|
68 TInt err = KErrNone; |
|
69 |
|
70 TRAP(err, DoErrorTestL(0)); |
|
71 if (err != KErrArgument) {iLog->Log(_L("Wrong error1"));iErrorsFound++;} |
|
72 delete iLandmarkSearch; |
|
73 iLandmarkSearch = NULL; |
|
74 err = KErrNone; |
|
75 TRAP(err, DoErrorTestL(1)); |
|
76 if (err != KErrNotSupported) {iLog->Log(_L("Wrong error2")); iErrorsFound++;}; |
|
77 delete iLandmarkSearch; |
|
78 iLandmarkSearch = NULL; |
|
79 err = KErrNone; |
|
80 TRAP(err, DoErrorTestL(2)); |
|
81 if (err != KErrNotSupported) {iLog->Log(_L("Wrong error3"));iErrorsFound++;} |
|
82 delete iLandmarkSearch; |
|
83 iLandmarkSearch = NULL; |
|
84 err = KErrNone; |
|
85 |
|
86 TRAP(err, DoErrorTest3L(0)); |
|
87 if (err != KErrArgument) {iLog->Log(_L("Wrong error5"));iErrorsFound++;} |
|
88 delete iLandmarkSearch; |
|
89 iLandmarkSearch = NULL; |
|
90 err = KErrNone; |
|
91 TRAP(err, DoErrorTest3L(1)); |
|
92 if (err != KErrNotSupported) {iLog->Log(_L("Wrong error6"));iErrorsFound++;} |
|
93 delete iLandmarkSearch; |
|
94 iLandmarkSearch = NULL; |
|
95 err = KErrNone; |
|
96 TRAP(err, DoErrorTest3L(2)); |
|
97 if (err != KErrArgument) {iLog->Log(_L("Wrong error7"));iErrorsFound++;} |
|
98 delete iLandmarkSearch; |
|
99 iLandmarkSearch = NULL; |
|
100 err = KErrNone; |
|
101 TRAP(err, DoErrorTest3L(3)); |
|
102 if (err != KErrNotSupported) {iLog->Log(_L("Wrong error8"));iErrorsFound++;} |
|
103 delete iLandmarkSearch; |
|
104 iLandmarkSearch = NULL; |
|
105 err = KErrNone; |
|
106 |
|
107 TRAP(err, DoErrorTest3L(4)); |
|
108 if (err != KErrArgument) {iLog->Log(_L("Wrong error9"));iErrorsFound++;} |
|
109 delete iLandmarkSearch; |
|
110 iLandmarkSearch = NULL; |
|
111 err = KErrNone; |
|
112 |
|
113 TRAP(err, DoErrorTest4L(0)); |
|
114 if (err != KErrArgument) {iLog->Log(_L("Wrong error10"));iErrorsFound++;} |
|
115 delete iLandmarkSearch; |
|
116 iLandmarkSearch = NULL; |
|
117 err = KErrNone; |
|
118 |
|
119 TRAP(err, DoErrorTest4L(1)); |
|
120 if (err != KErrNotSupported) {iLog->Log(_L("Wrong error11"));iErrorsFound++;} |
|
121 delete iLandmarkSearch; |
|
122 iLandmarkSearch = NULL; |
|
123 err = KErrNone; |
|
124 |
|
125 stopTime.UniversalTime(); |
|
126 TTimeIntervalMicroSeconds executionTime = |
|
127 stopTime.MicroSecondsFrom(startTime); |
|
128 |
|
129 TInt resse = executionTime.Int64()/1000000; |
|
130 TBuf<100> buf; |
|
131 buf.Format(_L("TP37 took %d seconds"), resse); |
|
132 iLog->Log(buf); |
|
133 |
|
134 if (iErrorsFound != KErrNone) |
|
135 { |
|
136 iLog->Log(_L("Errors found in TP37")); |
|
137 User::Leave(-1); |
|
138 } |
|
139 |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CPosTp37::DoErrorTestL |
|
144 // |
|
145 // (other items were commented in a header). |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 void CPosTp37::DoErrorTestL(TInt aTestNr) |
|
149 { |
|
150 TBuf<100> buf; |
|
151 buf.Format(_L("DoErrorTestL %d"), aTestNr); |
|
152 iLog->Log(buf); |
|
153 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
154 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
155 |
|
156 CPosLmCompositeCriteria::TCompositionType type = composite->CompositionType(); |
|
157 if (type != CPosLmCompositeCriteria::ECompositionAND) |
|
158 { |
|
159 iLog->Log( _L("Error1: Wrong type returned")); |
|
160 User::Leave(-1); |
|
161 } |
|
162 |
|
163 TInt nr = composite->NumOfArguments(); |
|
164 if (nr != 0) |
|
165 { |
|
166 iLog->Log(_L("Wrong number of arguments returned")); |
|
167 User::Leave(-1); |
|
168 |
|
169 } |
|
170 |
|
171 if (aTestNr == 0) |
|
172 { |
|
173 // Test that it is not possible to perform a composite search without any search arguments attached to |
|
174 // the composite object |
|
175 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
176 iLog->Log(_L("Should leave here")); |
|
177 ExecuteAndDeleteLD(iOperation); |
|
178 } |
|
179 else if (aTestNr == 1) |
|
180 { |
|
181 // Test that it is not possible to perform a composite search without any search arguments attached to |
|
182 // the composite object |
|
183 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
184 iLog->Log(_L("Should leave here")); |
|
185 ExecuteAndDeleteLD(iOperation); |
|
186 } |
|
187 else if (aTestNr == 2) |
|
188 { |
|
189 // Test that it is not possible to attach a category search attribute to |
|
190 // a composite object |
|
191 CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
192 nameCriteria->SetSearchPatternL(_L("*")); |
|
193 TInt err = composite->AddArgument(nameCriteria); |
|
194 if (err != KErrNotSupported) |
|
195 { |
|
196 iLog->Log(_L("Wrong error when adding CPosLmCatNameCriteria to composite")); |
|
197 User::Leave(err); |
|
198 } |
|
199 User::Leave(KErrNotSupported); |
|
200 } |
|
201 |
|
202 |
|
203 iLog->Log(_L("Did not leave!!!")); |
|
204 User::Leave(-1); |
|
205 |
|
206 iLog->Log(_L("ClearArguments")); |
|
207 composite->ClearArguments(); |
|
208 iLog->Log(_L("PopAndDestroy")); |
|
209 CleanupStack::PopAndDestroy(composite); |
|
210 delete iLandmarkSearch; |
|
211 iLandmarkSearch = NULL; |
|
212 iLog->Log(_L("Done")); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CPosTp37::DoErrorTest3L |
|
217 // |
|
218 // (other items were commented in a header). |
|
219 // --------------------------------------------------------- |
|
220 // |
|
221 void CPosTp37::DoErrorTest3L(TInt aTestNr) |
|
222 { |
|
223 TBuf<100> buf; |
|
224 buf.Format(_L("DoErrorTest3L %d"), aTestNr); |
|
225 iLog->Log(buf); |
|
226 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
227 TInt err = KErrNone; |
|
228 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
229 |
|
230 if (aTestNr == 0) |
|
231 { |
|
232 // add empty ID List |
|
233 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
234 err = composite->AddArgument(idList); |
|
235 CleanupStack::Pop(idList); |
|
236 if (err != KErrNone) |
|
237 { |
|
238 iLog->Log(_L("Error from AddArgument(idList);")); |
|
239 User::Leave(err); |
|
240 } |
|
241 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
242 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
243 iLog->Log(_L("Should leave here")); |
|
244 ExecuteAndDeleteLD(iOperation); |
|
245 } |
|
246 else if (aTestNr == 1) |
|
247 { |
|
248 // add empty ID List |
|
249 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
250 TInt err = composite->AddArgument(idList); |
|
251 CleanupStack::Pop(idList); |
|
252 if (err != KErrNone) |
|
253 { |
|
254 iLog->Log(_L("Error from AddArgument(idList);")); |
|
255 User::Leave(err); |
|
256 |
|
257 } |
|
258 |
|
259 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
260 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
261 iLog->Log(_L("Should leave here")); |
|
262 ExecuteAndDeleteLD(iOperation); |
|
263 |
|
264 } |
|
265 else if (aTestNr == 2) |
|
266 { |
|
267 // Test with list that contain items |
|
268 RArray<TPosLmItemId> list; |
|
269 CleanupClosePushL(list); |
|
270 |
|
271 list.Append(0); |
|
272 list.Append(1); |
|
273 list.Append(2); |
|
274 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
275 idList->SetLandmarkIdsL(list); |
|
276 err = composite->AddArgument(idList); |
|
277 CleanupStack::Pop(idList); |
|
278 if (err != KErrNone) |
|
279 { |
|
280 iLog->Log(_L("Error from AddArgument(idList);")); |
|
281 User::Leave(err); |
|
282 } |
|
283 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
284 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
285 iLog->Log(_L("Should leave here")); |
|
286 ExecuteAndDeleteLD(iOperation); |
|
287 |
|
288 CleanupStack::PopAndDestroy(&list); |
|
289 } |
|
290 else if (aTestNr == 3) |
|
291 { |
|
292 // Test with list that contain items |
|
293 RArray<TPosLmItemId> list; |
|
294 CleanupClosePushL(list); |
|
295 |
|
296 list.Append(0); |
|
297 list.Append(1); |
|
298 list.Append(2); |
|
299 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
300 idList->SetLandmarkIdsL(list); |
|
301 err = composite->AddArgument(idList); |
|
302 CleanupStack::Pop(idList); |
|
303 if (err != KErrNone) |
|
304 { |
|
305 iLog->Log(_L("Error from AddArgument(idList);")); |
|
306 User::Leave(err); |
|
307 } |
|
308 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
309 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
310 iLog->Log(_L("Should leave here")); |
|
311 ExecuteAndDeleteLD(iOperation); |
|
312 |
|
313 CleanupStack::PopAndDestroy(&list); |
|
314 } |
|
315 else if (aTestNr == 4) |
|
316 { |
|
317 // Test with list that contain valid and invalid items |
|
318 RArray<TPosLmItemId> list; |
|
319 CleanupClosePushL(list); |
|
320 |
|
321 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
322 textCriteria->SetTextL(_L("")); |
|
323 |
|
324 err = composite->AddArgument(textCriteria); |
|
325 CleanupStack::Pop(textCriteria); |
|
326 if (err != KErrNone) |
|
327 { |
|
328 iLog->Log(_L("Error from AddArgument(idList);")); |
|
329 User::Leave(err); |
|
330 } |
|
331 |
|
332 list.Append(1); |
|
333 list.Append(2); |
|
334 list.Append(2000); |
|
335 list.Append(2001); |
|
336 |
|
337 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
338 idList->SetLandmarkIdsL(list); |
|
339 err = composite->AddArgument(idList); |
|
340 CleanupStack::Pop(idList); |
|
341 CleanupStack::PopAndDestroy(&list); |
|
342 if (err != KErrNone) |
|
343 { |
|
344 iLog->Log(_L("Error from AddArgument(idList);")); |
|
345 User::Leave(err); |
|
346 } |
|
347 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
348 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
349 |
|
350 ExecuteAndDeleteLD(iOperation); |
|
351 // We should never come here |
|
352 iLog->Log(_L("Should leave here")); |
|
353 |
|
354 CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL(); |
|
355 CleanupStack::PushL(iter); |
|
356 CleanupStack::PopAndDestroy(iter); |
|
357 } |
|
358 else |
|
359 { |
|
360 |
|
361 iLog->Log(_L("Error in testcode, we should never come here")); |
|
362 User::Leave(-1); |
|
363 } |
|
364 |
|
365 CleanupStack::PopAndDestroy(composite); |
|
366 delete iLandmarkSearch; |
|
367 iLandmarkSearch = NULL; |
|
368 iLog->Log(_L("Done")); |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------- |
|
372 // CPosTp37::DoErrorTest4L |
|
373 // |
|
374 // (other items were commented in a header). |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CPosTp37::DoErrorTest4L(TInt aTestNr) |
|
378 { |
|
379 TBuf<100> buf; |
|
380 buf.Format(_L("DoErrorTest4L %d"), aTestNr); |
|
381 iLog->Log(buf); |
|
382 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
383 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
384 |
|
385 if (aTestNr == 0) |
|
386 { |
|
387 // Test with several lists |
|
388 RArray<TPosLmItemId> list1; |
|
389 CleanupClosePushL(list1); |
|
390 |
|
391 list1.Append(0); |
|
392 list1.Append(1); |
|
393 list1.Append(2); |
|
394 |
|
395 RArray<TPosLmItemId> list2; |
|
396 CleanupClosePushL(list2); |
|
397 |
|
398 list2.Append(3); |
|
399 list2.Append(4); |
|
400 list2.Append(5); |
|
401 |
|
402 CPosLmIdListCriteria* idList1 = CPosLmIdListCriteria::NewLC(); |
|
403 CPosLmIdListCriteria* idList2 = CPosLmIdListCriteria::NewLC(); |
|
404 |
|
405 idList1->SetLandmarkIdsL(list1); |
|
406 idList2->SetLandmarkIdsL(list2); |
|
407 TInt err = composite->AddArgument(idList2); |
|
408 if (err != KErrNone) |
|
409 { |
|
410 iLog->Log(_L("Error from AddArgument(idList2);")); |
|
411 User::Leave(err); |
|
412 } |
|
413 CleanupStack::Pop(idList2); |
|
414 err = composite->AddArgument(idList1); |
|
415 if (err != KErrNone) |
|
416 { |
|
417 iLog->Log(_L("Error from AddArgument(idList2);")); |
|
418 User::Leave(err); |
|
419 |
|
420 } |
|
421 CleanupStack::Pop(idList1); |
|
422 iLog->Log(_L("iLandmarkSearch->StartLandmarkSearchL")); |
|
423 iOperation = iLandmarkSearch->StartLandmarkSearchL(*composite, EFalse); |
|
424 iLog->Log(_L("Should leave here")); |
|
425 ExecuteAndDeleteLD(iOperation); |
|
426 } |
|
427 else if (aTestNr == 1) |
|
428 { |
|
429 // Test with several lists |
|
430 RArray<TPosLmItemId> list1; |
|
431 CleanupClosePushL(list1); |
|
432 |
|
433 list1.Append(0); |
|
434 list1.Append(1); |
|
435 list1.Append(2); |
|
436 |
|
437 RArray<TPosLmItemId> list2; |
|
438 CleanupClosePushL(list2); |
|
439 |
|
440 list2.Append(3); |
|
441 list2.Append(4); |
|
442 list2.Append(5); |
|
443 |
|
444 CPosLmIdListCriteria* idList1 = CPosLmIdListCriteria::NewLC(); |
|
445 CPosLmIdListCriteria* idList2 = CPosLmIdListCriteria::NewLC(); |
|
446 |
|
447 idList1->SetLandmarkIdsL(list1); |
|
448 idList2->SetLandmarkIdsL(list2); |
|
449 |
|
450 TInt err = composite->AddArgument(idList2); |
|
451 if (err != KErrNone) |
|
452 { |
|
453 iLog->Log(_L("Error from AddArgument(idList2);")); |
|
454 User::Leave(err); |
|
455 } |
|
456 CleanupStack::Pop(idList2); |
|
457 err = composite->AddArgument(idList1); |
|
458 if (err != KErrNone) |
|
459 { |
|
460 iLog->Log(_L("Error from AddArgument(idList2);")); |
|
461 User::Leave(err); |
|
462 |
|
463 } |
|
464 CleanupStack::Pop(idList1); |
|
465 |
|
466 iLog->Log(_L("iLandmarkSearch->StartCategorySearchL")); |
|
467 iOperation = iLandmarkSearch->StartCategorySearchL(*composite, CPosLmCategoryManager::ECategorySortOrderNone); |
|
468 iLog->Log(_L("Should leave here")); |
|
469 ExecuteAndDeleteLD(iOperation); |
|
470 } |
|
471 else |
|
472 { |
|
473 |
|
474 iLog->Log(_L("Error in testcode, we should never come here")); |
|
475 User::Leave(-1); |
|
476 |
|
477 } |
|
478 |
|
479 |
|
480 iLog->Log(_L("Did not leave!!!")); |
|
481 User::Leave(-1); |
|
482 |
|
483 |
|
484 CleanupStack::PopAndDestroy(composite); |
|
485 delete iLandmarkSearch; |
|
486 iLandmarkSearch = NULL; |
|
487 iLog->Log(_L("Done")); |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------- |
|
491 // CPosTp37::TestCompositeAndCategoryL |
|
492 // |
|
493 // (other items were commented in a header). |
|
494 // --------------------------------------------------------- |
|
495 // |
|
496 void CPosTp37::TestCompositeAndCategoryL(TInt /*aTestNr*/) |
|
497 { |
|
498 iLog->Log(_L("TestCompositeAndCategoryL")); |
|
499 |
|
500 iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase); |
|
501 CPosLmCompositeCriteria* composite = CPosLmCompositeCriteria::NewLC(CPosLmCompositeCriteria::ECompositionAND); |
|
502 |
|
503 // Test with list that contain items |
|
504 RArray<TPosLmItemId> list; |
|
505 CleanupClosePushL(list); |
|
506 |
|
507 list.Append(0); |
|
508 list.Append(1); |
|
509 list.Append(2); |
|
510 |
|
511 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC(); |
|
512 idList->SetLandmarkIdsL(list); |
|
513 TInt err = composite->AddArgument(idList); |
|
514 if (err != KErrNone) |
|
515 { |
|
516 iLog->Log(_L("Error from AddArgument(idList);")); |
|
517 User::Leave(err); |
|
518 |
|
519 } |
|
520 CleanupStack::Pop(idList); |
|
521 |
|
522 CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC(); |
|
523 nameCriteria->SetSearchPatternL(_L("*")); |
|
524 err = composite->AddArgument(nameCriteria); |
|
525 if (err != KErrNotSupported) |
|
526 { |
|
527 iLog->Log(_L("Wrong error from AddArgument(nameCriteria); should be KErrNotSupported")); |
|
528 User::Leave(err); |
|
529 |
|
530 } |
|
531 CleanupStack::PopAndDestroy(nameCriteria); |
|
532 User::Leave(KErrNotSupported); |
|
533 |
|
534 |
|
535 CleanupStack::PopAndDestroy(composite); |
|
536 delete iLandmarkSearch; |
|
537 iLandmarkSearch = NULL; |
|
538 iLog->Log(_L("Done")); |
|
539 } |
|
540 |
|
541 // End of File |