|
1 /* |
|
2 * Copyright (c) 2007 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: Test Module DLL to Geocoding API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <mngeocoder.h> |
|
21 #include <w32std.h> |
|
22 #include <coemain.h> |
|
23 #include <eikon.hrh> |
|
24 |
|
25 #include <mnproviderfinder.h> |
|
26 #include <mnprovider.h> |
|
27 #include <mngeocoder.h> |
|
28 #include <EPos_CPosLandmark.h> |
|
29 #include <LbsPosition.h> |
|
30 #include <LbsFieldIds.h> |
|
31 |
|
32 // User Includes |
|
33 #include "testmngeocoder.h" |
|
34 |
|
35 |
|
36 // Constant Declarations |
|
37 |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // C++ Default Constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CTestMnGeocoder* CTestMnGeocoder::NewL(CStifLogger* aLog) |
|
46 { |
|
47 CTestMnGeocoder* self = new(ELeave) CTestMnGeocoder(aLog); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // C++ Default Constructor |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CTestMnGeocoder::ConstructL() |
|
59 { |
|
60 MnProviderFinder::FindProvidersL(iProviderArray); |
|
61 iUid.iUid = KProviderUid; |
|
62 iLmk = CPosLandmark::NewL(); |
|
63 |
|
64 int i; |
|
65 for( i=0; i<iProviderArray.Count(); i++ ) |
|
66 { |
|
67 if((iProviderArray.operator[](i))->Uid() == iUid) |
|
68 iMnProvider = iProviderArray.operator[](i); |
|
69 } |
|
70 iLog->Log(_L("B4 Create")); |
|
71 iMnGeocoder = CMnGeocoder::NewL(*iMnProvider); |
|
72 iLog->Log(_L("After Create")); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // C++ Default Constructor |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CTestMnGeocoder::CTestMnGeocoder(CStifLogger* aLog) |
|
80 :CActive(0),iLog(aLog) |
|
81 { |
|
82 CActiveScheduler::Add(this); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // C++ Destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CTestMnGeocoder::~CTestMnGeocoder() |
|
90 { |
|
91 if( IsActive() ) |
|
92 { |
|
93 Cancel(); |
|
94 } |
|
95 |
|
96 if(iMnGeocoder) |
|
97 { |
|
98 delete iMnGeocoder; |
|
99 iMnGeocoder = NULL; |
|
100 } |
|
101 |
|
102 if(iLmk) |
|
103 { |
|
104 delete iLmk; |
|
105 iLmk = NULL; |
|
106 } |
|
107 |
|
108 iProviderArray.ResetAndDestroy(); |
|
109 iProviderArray.Close(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CTestMnGeocoder::RunL |
|
114 // |
|
115 // RunL to Handle Completed Request |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 void CTestMnGeocoder::RunL() |
|
119 { |
|
120 iLog->Log(_L("RunL %d"),iStatus.Int()); |
|
121 CActiveScheduler::Stop(); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CTestMnGeocoder::DoCancel |
|
126 // |
|
127 // To Handle Cancel Request |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CTestMnGeocoder::DoCancel() |
|
131 { |
|
132 iMnGeocoder->Cancel(); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------- |
|
136 // CTestMnGeocoder::RunError |
|
137 // |
|
138 // To Handle Error in RunL |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 TInt CTestMnGeocoder::RunError(TInt aError) |
|
142 { |
|
143 iLog->Log(_L("Leave in RunError %d"),aError); |
|
144 CActiveScheduler::Stop(); |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CTestMnGeocoder::TestNewL |
|
150 // |
|
151 // (other items are commented in a header). |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 TInt CTestMnGeocoder::TestNewL() |
|
155 { |
|
156 iLog->Log(_L("B4 Create")); |
|
157 CMnGeocoder* MnGeocoder = CMnGeocoder::NewL(*iMnProvider); |
|
158 delete MnGeocoder; |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CTestMnGeocoder::TestNewLC |
|
164 // |
|
165 // (other items are commented in a header). |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 TInt CTestMnGeocoder::TestNewChainedL() |
|
169 { |
|
170 CMnGeocoder* MnGeocoder = NULL; |
|
171 iLog->Log(_L("B4 Create")); |
|
172 TRAPD(err, MnGeocoder = CMnGeocoder::NewChainedL(*iMnProvider)); |
|
173 iLog->Log(_L("TestNewChainedL Error Code - %d"),err); |
|
174 if( KErrNone == err ) |
|
175 delete MnGeocoder; |
|
176 return err; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // CTestMnGeocoder::TestGetSetOptionsL |
|
181 // |
|
182 // (other items are commented in a header). |
|
183 // --------------------------------------------------------- |
|
184 // |
|
185 TInt CTestMnGeocoder::TestGetSetOptionsL( CStifItemParser& aItem ) |
|
186 { |
|
187 TInt opt; |
|
188 User::LeaveIfError(aItem.GetNextInt(opt)); |
|
189 if( 0 == opt ) |
|
190 { |
|
191 iMnGeocoder->SetOptions(CMnGeocoder::EOptionNone); |
|
192 if( CMnGeocoder::EOptionNone == iMnGeocoder->Options() ) |
|
193 return KErrNone; |
|
194 else |
|
195 return KErrGeneral; |
|
196 } |
|
197 else |
|
198 { |
|
199 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
200 if( CMnGeocoder::EOptionDialogDisabled == iMnGeocoder->Options() ) |
|
201 return KErrNone; |
|
202 else |
|
203 return KErrGeneral; |
|
204 } |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------- |
|
208 // CTestMnGeocoder::TestFindCoordinateByAddressL |
|
209 // |
|
210 // (other items are commented in a header). |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 TInt CTestMnGeocoder::TestFindAddressByCoordinateL( CStifItemParser& aItem ) |
|
214 { |
|
215 TPtrC city; |
|
216 TPtrC latPtr; |
|
217 TPtrC longPtr; |
|
218 User::LeaveIfError(aItem.GetNextString(city)); |
|
219 User::LeaveIfError(aItem.GetNextString(latPtr)); |
|
220 User::LeaveIfError(aItem.GetNextString(longPtr)); |
|
221 TLex lex1( latPtr ); |
|
222 TLex lex2( longPtr ); |
|
223 TReal64 latitude = 12.98; |
|
224 TReal64 longitude = 77.67; |
|
225 lex1.Val( latitude ); |
|
226 lex2.Val( longitude ); |
|
227 |
|
228 TLocality position; |
|
229 position.SetCoordinate( latitude, longitude ); |
|
230 iLmk->SetPositionL( position ); |
|
231 |
|
232 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
233 iMnGeocoder->FindAddressByCoordinateL(*iLmk, iStatus); |
|
234 SetActive(); |
|
235 |
|
236 CActiveScheduler::Start(); |
|
237 |
|
238 if(iStatus.Int() != KErrNone) |
|
239 { |
|
240 iLog->Log(_L("FindAddressByCoordinateL Failed with %d"),iStatus.Int()); |
|
241 return KErrGeneral; |
|
242 } |
|
243 |
|
244 CPosLandmark* lmk = CPosLandmark::NewL(); |
|
245 CleanupStack::PushL( lmk ); |
|
246 |
|
247 TRAPD(err, iMnGeocoder->RetrieveGeocodingResultL(*lmk)); |
|
248 |
|
249 if(err != KErrNone) |
|
250 { |
|
251 CleanupStack::PopAndDestroy(lmk); |
|
252 iLog->Log(_L("RetrieveGeocodingResultL Leave with %d"),err); |
|
253 return err; |
|
254 } |
|
255 |
|
256 TPtrC getCity; |
|
257 TInt error = lmk->GetPositionField( EPositionFieldCity, getCity ); |
|
258 |
|
259 if(error != KErrNone) |
|
260 { |
|
261 CleanupStack::PopAndDestroy(lmk); |
|
262 iLog->Log(_L("GetPositionField Failed with %d"),error); |
|
263 return error; |
|
264 } |
|
265 |
|
266 if( 0 != getCity.Compare(city) ) |
|
267 { |
|
268 CleanupStack::PopAndDestroy(lmk); |
|
269 iLog->Log(_L("RetrieveGeocodingResultL Failed to Match")); |
|
270 return KErrGeneral; |
|
271 } |
|
272 |
|
273 TBuf<100> msg; |
|
274 msg.Copy(_L("RetrieveGeocodingResultL City :")); |
|
275 msg.Append(getCity); |
|
276 iLog->Log(msg); |
|
277 |
|
278 CleanupStack::PopAndDestroy(lmk); |
|
279 return KErrNone; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CTestMnGeocoder::TestFindCoordinateByAddressL |
|
284 // |
|
285 // (other items are commented in a header). |
|
286 // --------------------------------------------------------- |
|
287 // |
|
288 TInt CTestMnGeocoder::TestFindCoordinateByAddressL( CStifItemParser& aItem ) |
|
289 { |
|
290 TPtrC city; |
|
291 TPtrC latPtr; |
|
292 TPtrC longPtr; |
|
293 User::LeaveIfError(aItem.GetNextString(city)); |
|
294 User::LeaveIfError(aItem.GetNextString(latPtr)); |
|
295 User::LeaveIfError(aItem.GetNextString(longPtr)); |
|
296 TLex lex1( latPtr ); |
|
297 TLex lex2( longPtr ); |
|
298 TReal64 latitude = 12.98; |
|
299 TReal64 longitude = 77.67; |
|
300 lex1.Val( latitude ); |
|
301 lex2.Val( longitude ); |
|
302 |
|
303 iLmk->SetPositionFieldL( EPositionFieldCity, city ); |
|
304 |
|
305 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
306 iMnGeocoder->FindCoordinateByAddressL(*iLmk, iStatus); |
|
307 SetActive(); |
|
308 |
|
309 CActiveScheduler::Start(); |
|
310 |
|
311 if(iStatus.Int() != KErrNone) |
|
312 { |
|
313 iLog->Log(_L("FindAddressByCoordinateL Failed with %d"),iStatus.Int()); |
|
314 return KErrGeneral; |
|
315 } |
|
316 |
|
317 CPosLandmark* lmk = CPosLandmark::NewL(); |
|
318 CleanupStack::PushL( lmk ); |
|
319 |
|
320 TRAPD(err, iMnGeocoder->RetrieveGeocodingResultL(*lmk)); |
|
321 |
|
322 if(err != KErrNone) |
|
323 { |
|
324 CleanupStack::PopAndDestroy(lmk); |
|
325 iLog->Log(_L("RetrieveGeocodingResultL Leave with %d"),err); |
|
326 return err; |
|
327 } |
|
328 |
|
329 TLocality getPosition; |
|
330 TInt error = lmk->GetPosition( getPosition ); |
|
331 |
|
332 if(error != KErrNone) |
|
333 { |
|
334 CleanupStack::PopAndDestroy(lmk); |
|
335 iLog->Log(_L("GetPositionField Failed with %d"),error); |
|
336 return error; |
|
337 } |
|
338 |
|
339 if( getPosition.Latitude() != latitude && |
|
340 getPosition.Longitude() != longitude ) |
|
341 { |
|
342 CleanupStack::PopAndDestroy(lmk); |
|
343 iLog->Log(_L("RetrieveGeocodingResultL Failed to Match")); |
|
344 return KErrGeneral; |
|
345 } |
|
346 |
|
347 TRealFormat real; |
|
348 TBuf<100> msg; |
|
349 msg.Copy(_L("RetrieveGeocodingResultL Latitude :")); |
|
350 msg.AppendNum(getPosition.Longitude(), real); |
|
351 iLog->Log(msg); |
|
352 |
|
353 CleanupStack::PopAndDestroy(lmk); |
|
354 return KErrNone; |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------- |
|
358 // CTestMnGeocoder::TestFindCoordinateByAddressL |
|
359 // |
|
360 // (other items are commented in a header). |
|
361 // --------------------------------------------------------- |
|
362 // |
|
363 TInt CTestMnGeocoder::TestFindCoordinateByAddressDescL( CStifItemParser& aItem ) |
|
364 { |
|
365 TPtrC city; |
|
366 TPtrC latPtr; |
|
367 TPtrC longPtr; |
|
368 User::LeaveIfError(aItem.GetNextString(city)); |
|
369 User::LeaveIfError(aItem.GetNextString(latPtr)); |
|
370 User::LeaveIfError(aItem.GetNextString(longPtr)); |
|
371 TLex lex1( latPtr ); |
|
372 TLex lex2( longPtr ); |
|
373 TReal64 latitude = 12.98; |
|
374 TReal64 longitude = 77.67; |
|
375 lex1.Val( latitude ); |
|
376 lex2.Val( longitude ); |
|
377 |
|
378 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
379 iMnGeocoder->FindCoordinateByAddressL(city, iStatus); |
|
380 SetActive(); |
|
381 |
|
382 CActiveScheduler::Start(); |
|
383 |
|
384 if(iStatus.Int() != KErrNone) |
|
385 { |
|
386 iLog->Log(_L("FindAddressByCoordinateL Failed with %d"),iStatus.Int()); |
|
387 return KErrGeneral; |
|
388 } |
|
389 |
|
390 CPosLandmark* lmk = CPosLandmark::NewL(); |
|
391 CleanupStack::PushL( lmk ); |
|
392 |
|
393 TRAPD(err, iMnGeocoder->RetrieveGeocodingResultL(*lmk)); |
|
394 |
|
395 if(err != KErrNone) |
|
396 { |
|
397 CleanupStack::PopAndDestroy(lmk); |
|
398 iLog->Log(_L("RetrieveGeocodingResultL Leave with %d"),err); |
|
399 return err; |
|
400 } |
|
401 |
|
402 TLocality getPosition; |
|
403 TInt error = lmk->GetPosition( getPosition ); |
|
404 |
|
405 if(error != KErrNone) |
|
406 { |
|
407 CleanupStack::PopAndDestroy(lmk); |
|
408 iLog->Log(_L("GetPositionField Failed with %d"),error); |
|
409 return error; |
|
410 } |
|
411 |
|
412 if( getPosition.Latitude() != latitude && |
|
413 getPosition.Longitude() != longitude ) |
|
414 { |
|
415 CleanupStack::PopAndDestroy(lmk); |
|
416 iLog->Log(_L("RetrieveGeocodingResultL Failed to Match")); |
|
417 return KErrGeneral; |
|
418 } |
|
419 |
|
420 iLog->Log(_L("RetrieveGeocodingResultL Matches")); |
|
421 |
|
422 CleanupStack::PopAndDestroy(lmk); |
|
423 return KErrNone; |
|
424 } |
|
425 |
|
426 // --------------------------------------------------------- |
|
427 // CTestMnGeocoder::TestSetExitObserverL |
|
428 // |
|
429 // (other items are commented in a header). |
|
430 // --------------------------------------------------------- |
|
431 // |
|
432 TInt CTestMnGeocoder::TestSetExitObserverL( ) |
|
433 { |
|
434 // Set exit observer |
|
435 TRAPD(err, iMnGeocoder->SetExitObserverL( *this )); |
|
436 if(err != KErrNone) |
|
437 { |
|
438 iLog->Log(_L("TestSetExitObserverL Fails")); |
|
439 return KErrGeneral; |
|
440 } |
|
441 iLog->Log(_L("TestSetExitObserverL Passes")); |
|
442 return KErrNone; |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CTestMnGeocoder::TestRemoveExitObserverL |
|
447 // |
|
448 // (other items are commented in a header). |
|
449 // --------------------------------------------------------- |
|
450 // |
|
451 TInt CTestMnGeocoder::TestRemoveExitObserverL( ) |
|
452 { |
|
453 // Set exit observer |
|
454 TRAPD(err, iMnGeocoder->SetExitObserverL( *this )); |
|
455 if(err != KErrNone) |
|
456 { |
|
457 iLog->Log(_L("TestRemoveExitObserverL Fails")); |
|
458 return KErrGeneral; |
|
459 } |
|
460 iMnGeocoder->RemoveExitObserver( ); |
|
461 iLog->Log(_L("TestRemoveExitObserverL Passes")); |
|
462 return KErrNone; |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------- |
|
466 // CTestMnGeocoder::HandleServerAppExit |
|
467 // |
|
468 // (other items are commented in a header). |
|
469 // --------------------------------------------------------- |
|
470 // |
|
471 void CTestMnGeocoder::HandleServerAppExit( TInt /*aReason*/ ) |
|
472 { |
|
473 iLog->Log(_L("Provider exits")); |
|
474 } |
|
475 |
|
476 // --------------------------------------------------------- |
|
477 // CTestMnGeocoder::TestCancelRequestL |
|
478 // |
|
479 // (other items are commented in a header). |
|
480 // --------------------------------------------------------- |
|
481 // |
|
482 TInt CTestMnGeocoder::TestCancelRequestL( CStifItemParser& aItem ) |
|
483 { |
|
484 TInt choice; |
|
485 User::LeaveIfError(aItem.GetNextInt(choice)); |
|
486 |
|
487 TPtrC city; |
|
488 TPtrC latPtr; |
|
489 TPtrC longPtr; |
|
490 User::LeaveIfError(aItem.GetNextString(city)); |
|
491 User::LeaveIfError(aItem.GetNextString(latPtr)); |
|
492 User::LeaveIfError(aItem.GetNextString(longPtr)); |
|
493 TLex lex1( latPtr ); |
|
494 TLex lex2( longPtr ); |
|
495 TReal64 latitude = 12.98; |
|
496 TReal64 longitude = 77.67; |
|
497 lex1.Val( latitude ); |
|
498 lex2.Val( longitude ); |
|
499 |
|
500 TLocality position; |
|
501 position.SetCoordinate( latitude, longitude ); |
|
502 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
503 |
|
504 switch(choice) |
|
505 { |
|
506 case EFindAddressByCoordinateL: |
|
507 iLmk->SetPositionL( position ); |
|
508 iMnGeocoder->FindAddressByCoordinateL(*iLmk, iStatus); |
|
509 break; |
|
510 case EFindCoordinateByAddressL: |
|
511 iLmk->SetPositionFieldL( EPositionFieldCity, city ); |
|
512 iMnGeocoder->FindCoordinateByAddressL(*iLmk, iStatus); |
|
513 break; |
|
514 case EFindCoordinateByAddressDescL: |
|
515 iMnGeocoder->FindCoordinateByAddressL(city, iStatus); |
|
516 break; |
|
517 } |
|
518 SetActive(); |
|
519 iLog->Log(_L("Started RunSession with status %d"),iStatus.Int()); |
|
520 |
|
521 Cancel(); |
|
522 |
|
523 TBuf<100> msg; |
|
524 msg.Copy(_L("In TestCancelRequest: TestCancelRequest returned with :")); |
|
525 msg.AppendNum(iStatus.Int()); |
|
526 iLog->Log(msg); |
|
527 |
|
528 if(KErrNone == iStatus.Int() || KErrCancel == iStatus.Int() ) |
|
529 return KErrCancel; |
|
530 else |
|
531 return KErrGeneral; |
|
532 |
|
533 } |
|
534 |
|
535 // --------------------------------------------------------- |
|
536 // CTestMnGeocoder::TestRequestPanicL |
|
537 // |
|
538 // (other items are commented in a header). |
|
539 // --------------------------------------------------------- |
|
540 // |
|
541 TInt CTestMnGeocoder::TestRequestPanicL( CStifItemParser& aItem ) |
|
542 { |
|
543 TInt choice; |
|
544 User::LeaveIfError(aItem.GetNextInt(choice)); |
|
545 |
|
546 TPtrC city; |
|
547 TPtrC latPtr; |
|
548 TPtrC longPtr; |
|
549 User::LeaveIfError(aItem.GetNextString(city)); |
|
550 User::LeaveIfError(aItem.GetNextString(latPtr)); |
|
551 User::LeaveIfError(aItem.GetNextString(longPtr)); |
|
552 TLex lex1( latPtr ); |
|
553 TLex lex2( longPtr ); |
|
554 TReal64 latitude = 12.98; |
|
555 TReal64 longitude = 77.67; |
|
556 lex1.Val( latitude ); |
|
557 lex2.Val( longitude ); |
|
558 |
|
559 TLocality position; |
|
560 position.SetCoordinate( latitude, longitude ); |
|
561 iMnGeocoder->SetOptions(CMnGeocoder::EOptionDialogDisabled); |
|
562 |
|
563 switch(choice) |
|
564 { |
|
565 case EFindAddressByCoordinateL: |
|
566 iLmk->SetPositionL( position ); |
|
567 iMnGeocoder->FindAddressByCoordinateL(*iLmk, iStatus); |
|
568 iMnGeocoder->FindAddressByCoordinateL(*iLmk, iStatus); |
|
569 break; |
|
570 case EFindCoordinateByAddressL: |
|
571 iLmk->SetPositionFieldL( EPositionFieldCity, city ); |
|
572 iMnGeocoder->FindCoordinateByAddressL(*iLmk, iStatus); |
|
573 iMnGeocoder->FindCoordinateByAddressL(*iLmk, iStatus); |
|
574 break; |
|
575 case EFindCoordinateByAddressDescL: |
|
576 iMnGeocoder->FindCoordinateByAddressL(city, iStatus); |
|
577 iMnGeocoder->FindCoordinateByAddressL(city, iStatus); |
|
578 break; |
|
579 } |
|
580 |
|
581 return KErrNone; |
|
582 } |
|
583 |