|
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 #ifndef CLANDMARKTESTPROCEDUREBASE_H |
|
21 #define CLANDMARKTESTPROCEDUREBASE_H |
|
22 |
|
23 // INCLUDES |
|
24 //#include <utfw.h> |
|
25 #include <w32std.h> |
|
26 #include <e32def.h> |
|
27 #include <ss_std.h> |
|
28 |
|
29 #include <EPos_CPosLandmarkDatabase.h> |
|
30 #include <EPos_CPosLmDatabaseManager.h> |
|
31 #include <EPos_CPosLmOperation.h> |
|
32 #include <EPos_CPosLandmarkSearch.h> |
|
33 #include <EPos_CPosLmMultiDbSearch.h> |
|
34 |
|
35 #include "FT_CSearchResult.h" |
|
36 #include "FT_CAreaSearchResult.h" |
|
37 #include "FT_CCategorySearchResult.h" |
|
38 #include "FT_CCategoryLandmarkSearchResult.h" |
|
39 |
|
40 #include <StifLogger.h> |
|
41 #include <StifItemParser.h> |
|
42 |
|
43 // Global category IDs as defined by Global Category API specification |
|
44 // Global category identifier when used for searching |
|
45 const TInt KAccommodation = 3000; //Hotel, Camping site |
|
46 const TInt KBusiness = 6000; //Bank, Factory, Office |
|
47 const TInt KCommunication = 9000; //Internet Access Point, Public Telephone, Wireless LAN Hot Spot |
|
48 const TInt KEducational = 12000;// School, College |
|
49 const TInt KEntertainment = 15000;// Amusement park, Cinema, Concert hall, Night club |
|
50 const TInt KFoodBeverage = 18000; //Fast food, Restaurant, Café, Bar |
|
51 const TInt KGeographicalArea = 21000;//City, City center, Town |
|
52 const TInt KOutdoorActivities = 24000; //Camping site, Fishing place, Hunting, National park, Playground |
|
53 const TInt KPeople = 27000;// My home, My friend's home, Father's summer cottage, Child's school |
|
54 const TInt KPublicService = 30000; //Tourist information office, Government office, Library, Post office, Hospital, Police |
|
55 const TInt KReligiousPlaces = 33000; //Church, Mosque |
|
56 const TInt KShopping = 36000; //Market place, Pharmacy, Shop, Shopping center |
|
57 const TInt KSightseeing = 39000; //Monument, Mountain top, Museum |
|
58 const TInt KSports = 42000 ; //Bowling, Golf course, Ice hockey hall, Stadium |
|
59 const TInt KTransport = 45000; //Airport, Bus stop, Harbor, Railway station, Rest area |
|
60 |
|
61 // CONSTANTS |
|
62 _LIT(KAccessErr, "Access methods should return 'Not initialized' when db has been created"); |
|
63 _LIT(KInitErr, "Method InitializedNeeded should return ETrue after db has been created"); |
|
64 _LIT8(KLmxMimeType, "application/vnd.nokia.landmarkcollection+xml"); |
|
65 _LIT8(KGpxMimeType, "application/gps+xml"); |
|
66 _LIT8(KKmlMimeType,"application/vnd.google-earth.kml+xml"); |
|
67 _LIT8(KKmzMimeType,"application/vnd.google-earth.kmz"); |
|
68 _LIT(KLmxFileExt,".lmx"); |
|
69 _LIT(KGpxFileExt,".gpx"); |
|
70 _LIT(KXmlFileExt,".xml"); |
|
71 |
|
72 const TInt KMsgBufSize = 255; |
|
73 const TInt KMaxLineLength = 1024; |
|
74 |
|
75 // FORWARD DECLARATIONS |
|
76 class CPosLmMultiDbSearch; |
|
77 class CPosLmSearchCriteria; |
|
78 |
|
79 // DATA TYPES |
|
80 typedef RArray<TPosLmItemId> RIdArray; |
|
81 |
|
82 // CLASS DECLARATION |
|
83 class CPosLandmarkCategory; |
|
84 class CActiveLmOperation; |
|
85 |
|
86 class CLandmarkTestProcedureBase :public CBase |
|
87 { |
|
88 public: // Constructors and destructor |
|
89 |
|
90 /** |
|
91 * C++ default constructor. |
|
92 */ |
|
93 CLandmarkTestProcedureBase(TInt aModuleId, CStifLogger* iLog ); |
|
94 |
|
95 /** |
|
96 * Destructor. |
|
97 */ |
|
98 ~CLandmarkTestProcedureBase(); |
|
99 |
|
100 /** |
|
101 * Initialises the test. |
|
102 * By default does nothing. |
|
103 */ |
|
104 virtual void InitTestL(); |
|
105 |
|
106 /** |
|
107 * Executes the test. |
|
108 * By default does nothing. |
|
109 */ |
|
110 virtual void StartL(); |
|
111 |
|
112 /** |
|
113 * Executes the test. |
|
114 * By default does nothing. |
|
115 */ |
|
116 virtual void StartL( CStifItemParser& ) {}; |
|
117 |
|
118 /** |
|
119 * Cleans up after a test. |
|
120 * Always called, even if the test leaves. |
|
121 * By default does nothing. |
|
122 */ |
|
123 virtual void CloseTest(); |
|
124 |
|
125 |
|
126 public: // Functions from base classes |
|
127 |
|
128 |
|
129 static TInt ReadLn(RFile& aFile, TDes& aDes); |
|
130 |
|
131 static void ResetAndDestroyHBufCArray( TAny* aPointer ); |
|
132 |
|
133 protected: // New functions |
|
134 |
|
135 static void Trace(TBuf8<KMsgBufSize> msg) ; |
|
136 |
|
137 /** |
|
138 * Removes the default landmark database if exists |
|
139 */ |
|
140 void RemoveDefaultDbL(); |
|
141 |
|
142 /** |
|
143 * Removes all existing landmark databases |
|
144 */ |
|
145 void RemoveAllLmDatabasesL(); |
|
146 |
|
147 /** |
|
148 * Compare two landmarks. |
|
149 * Should only be used when they are expected to be equal. |
|
150 */ |
|
151 void CompareLandmarksL(const CPosLandmark& aSource, const CPosLandmark& aTarget); |
|
152 |
|
153 /** |
|
154 * Compare two categories. |
|
155 * Should only be used when they are expected to be equal. |
|
156 */ |
|
157 void CompareCategoriesL( |
|
158 const TPosLmItemId& aSourceId, |
|
159 const TPosLmItemId& aTargetId); |
|
160 |
|
161 void CompareCategoriesL( |
|
162 const CPosLandmarkCategory& aSource, |
|
163 const CPosLandmarkCategory& aTarget); |
|
164 |
|
165 |
|
166 TInt CompareXMLCategoriesL( |
|
167 const CPosLandmarkCategory& aSource, |
|
168 const CPosLandmarkCategory& aTarget, TBool aDebug=EFalse); |
|
169 |
|
170 TInt CompareXMLLandmarksL(const CPosLandmark& aSource, const CPosLandmark& aTarget, TBool aDebug=EFalse); |
|
171 |
|
172 /** |
|
173 * Creates a caategory with all attributes set |
|
174 * @param the category name |
|
175 */ |
|
176 CPosLandmarkCategory* CreateCategoryLC(const TDesC& aName); |
|
177 |
|
178 /** |
|
179 * Creates a landmarks with all attributes set |
|
180 * @param the landmark name |
|
181 */ |
|
182 CPosLandmark* CreateLandmarkLC(const TDesC& aName); |
|
183 |
|
184 /** |
|
185 * Opens the landmarks database and initializes it if necearry |
|
186 * @return the landmarks database |
|
187 */ |
|
188 CPosLandmarkDatabase* OpenDatabaseLC(); |
|
189 |
|
190 /** |
|
191 * Creates a category and adds it to the database |
|
192 * @return the category id |
|
193 */ |
|
194 TPosLmItemId CreateCategoryL(const TDesC& aName); |
|
195 |
|
196 /** |
|
197 * Adds some fields to a landmark |
|
198 * @param the landmark |
|
199 */ |
|
200 void AddFieldsL(CPosLandmark* aLandmark); |
|
201 |
|
202 void AddFields2L(CPosLandmark* aLandmark); |
|
203 |
|
204 void AddFields3L(CPosLandmark* aLandmark); |
|
205 |
|
206 TInt CompareL(const TDesC& aFileName); |
|
207 |
|
208 TInt CompareL(const TDesC& aSourceFileName, const TDesC& aTargetFileName); |
|
209 |
|
210 /* |
|
211 * Create landmark with name, coordinate, coverage radius, icon set |
|
212 */ |
|
213 CPosLandmark* CreateXMLLandmarkLC(const TDesC& aName); |
|
214 |
|
215 |
|
216 /** |
|
217 * Add all fields to a landmark that is encoded to XML |
|
218 */ |
|
219 void AddAllXMLFieldsL(CPosLandmark* aLandmark); |
|
220 |
|
221 /** |
|
222 * Add all fields to a landmark that is encoded to XML |
|
223 * All fields are empty (_L("")) |
|
224 */ |
|
225 void AddAllEmptyXMLFieldsL(CPosLandmark* aLandmark); |
|
226 |
|
227 /** |
|
228 * Writes the content of the buffer to the specified file |
|
229 * Removes the file if allready exists |
|
230 */ |
|
231 void WriteBufferToFileL(const CBufBase* aBuffer, const TDesC& aFileName); |
|
232 |
|
233 void CheckDefaultDbExistL(); |
|
234 |
|
235 CPosLandmarkDatabase* BackupDbFileL(); |
|
236 |
|
237 CPosLandmarkDatabase* RestoreDbFileL(); |
|
238 |
|
239 void CopyDbFileL(const TDesC& aFileName); |
|
240 |
|
241 void CopyTestDbFileL(const TDesC& aFileName); |
|
242 |
|
243 CPosLandmarkDatabase* UseGeneratedDbFileL(); |
|
244 |
|
245 /** |
|
246 * Copy the landmarks db used for composite testing |
|
247 * to correct path |
|
248 */ |
|
249 CPosLandmarkDatabase* UseCompositeLandmarksDbFileL(); |
|
250 |
|
251 CPosLandmarkDatabase* UseGlobalCategoriesL(); |
|
252 |
|
253 CPosLandmarkDatabase* UseEmptyDbFileL(); |
|
254 |
|
255 void RemoveGlobalCategoriesL(); |
|
256 |
|
257 void AppendSearchResultsL(); |
|
258 |
|
259 void AppendAreaSearchResultsL(); |
|
260 |
|
261 void AppendCategoryLandmarkSearchResultsL(); |
|
262 |
|
263 void AppendCategorySearchResultsL(); |
|
264 |
|
265 const RPointerArray<CSearchResult>& SearchResults(); |
|
266 |
|
267 const RPointerArray<CAreaSearchResult>& AreaSearchResults(); |
|
268 |
|
269 void PrintLandmark(const CPosLandmark& aLandmark, TDes& aPrint); |
|
270 |
|
271 void LandmarksSortL(RArray<TPosLmItemId>& aArray, const TPosLmSortPref& aSortPref); |
|
272 |
|
273 void CategoriesSortL(RArray<TPosLmItemId>& aArray, CPosLmCategoryManager::TCategorySortPref aSortPref); |
|
274 |
|
275 void LogToFileL(const TDesC& aFileName, TBuf8<KMsgBufSize> aMsg); |
|
276 |
|
277 void RunAsyncOperationLD(CPosLmOperation* aOperation); |
|
278 |
|
279 void RunAsyncOperationL(CPosLmOperation* aOperation); |
|
280 |
|
281 void RunAsyncOperationByWaitForReqL(CPosLmOperation* aOperation); |
|
282 |
|
283 void RunAsyncOperationAndCancelLD(CPosLmOperation* aOperation); |
|
284 |
|
285 void RunAsyncOperationAndCancelInCallbackLD(CPosLmOperation* aOperation, TReal32 aThreshold = 0.3); |
|
286 |
|
287 /** |
|
288 * Deletes a file from the file system |
|
289 * @aFile the file name |
|
290 */ |
|
291 void DeleteFileL(const TDesC& aFile); |
|
292 |
|
293 /** |
|
294 * Makes sure that the empty file ErrRd is created in c:\system\bootdata |
|
295 * if it is not already created. Should be called by all panic tests |
|
296 * before any panic occurs. |
|
297 */ |
|
298 void MakeSurePanicDebugFileExistsL(); |
|
299 |
|
300 /** |
|
301 * Used as a callback method to cancel a operation after some |
|
302 * steps have been executed. |
|
303 * @param self |
|
304 */ |
|
305 TInt static CancelTest(TAny* aSelf); |
|
306 |
|
307 void AssertTrueSecL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode=KErrGeneral); |
|
308 |
|
309 /** |
|
310 * Checks if the server with name aServerName is alive |
|
311 */ |
|
312 TBool ServerAlive(const TDesC& aServerName); |
|
313 |
|
314 CDesCArray* ListLandmarkDbsL(); |
|
315 |
|
316 void ReadGlobalCategoriesFromResourceL( |
|
317 RArray<TUint>& aCatIds, |
|
318 RPointerArray<HBufC>& aCatNames, |
|
319 TInt aMaxNum = 0); |
|
320 |
|
321 void CreateCorrectXmlFileL( const TDesC& aSampleFile, TFileName& aFileName ); |
|
322 |
|
323 HBufC* GetGlobalCategoryFromResourceLC( TPosLmGlobalCategory aGlobalId ); |
|
324 |
|
325 HBufC* ReadDefaultDatabaseNameFromResourceLC(); |
|
326 |
|
327 /** |
|
328 * Escapes the string with characters not supported in XML. |
|
329 * |
|
330 * @param aStrToEscape The string to escape. |
|
331 * @return An escaped string. |
|
332 */ |
|
333 HBufC* EscapeStringToXmlLC( |
|
334 /* IN */ const TDesC& aStrToEscape |
|
335 ); |
|
336 |
|
337 void EscapeString( |
|
338 /* IN/OUT */ TDes& aStrToEscape, |
|
339 /* IN */ const TDesC& aFromStr, |
|
340 /* IN */ const TDesC& aToStr |
|
341 ); |
|
342 |
|
343 TInt CalculateEscapedStringSize( |
|
344 /* IN */ const TDesC& aStrToEscape |
|
345 ); |
|
346 |
|
347 TInt CalculateIncrease( |
|
348 /* IN */ const TDesC& aStrToEscape, |
|
349 /* IN */ const TDesC& aFromStr, |
|
350 /* IN */ const TDesC& aToStr |
|
351 ); |
|
352 |
|
353 |
|
354 public: |
|
355 |
|
356 //RWsSession iWs; |
|
357 TInt iModuleId; |
|
358 |
|
359 protected: // Data |
|
360 |
|
361 class COnTheFlyTester : public CActive |
|
362 { |
|
363 public: |
|
364 |
|
365 static COnTheFlyTester* NewLC(); |
|
366 ~COnTheFlyTester(); |
|
367 void StartSearchCampaignL( |
|
368 CPosLmMultiDbSearch* aSearcher, |
|
369 const RIdArray& aExpectedMatches, |
|
370 CPosLmSearchCriteria* aSearchCriteria); |
|
371 TInt Err() {return iErr;} |
|
372 void GetErrMsg(TPtrC& aErrMsg) {aErrMsg.Set(iBuf);} |
|
373 |
|
374 protected: |
|
375 |
|
376 void RunL(); |
|
377 void DoCancel(); |
|
378 TInt RunError(TInt aError); |
|
379 |
|
380 private: |
|
381 |
|
382 COnTheFlyTester(); |
|
383 void VerifyOnTheFlyDataL(TBool aIsFinished = EFalse); |
|
384 |
|
385 private: // Data |
|
386 |
|
387 CPosLmMultiDbSearch* iSearcher; |
|
388 TInt iErr; |
|
389 TInt iNrOfOldItems; |
|
390 CPosLmOperation* iOperation; |
|
391 TReal32 iProgress; |
|
392 CPosLmDisplayData* iDisplayData; |
|
393 TBuf<200> iBuf; |
|
394 const RIdArray* iExpectedMatches; |
|
395 |
|
396 }; |
|
397 |
|
398 enum TExecutionMode |
|
399 { |
|
400 ESynchronous = 0, |
|
401 EAsynchronous, |
|
402 EWaitForRequest |
|
403 }; |
|
404 |
|
405 const TTimeIntervalMicroSeconds32 KFirstDelayTime; |
|
406 const TTimeIntervalMicroSeconds32 KIntervalTime; |
|
407 |
|
408 CPosLandmarkDatabase* iDatabase; |
|
409 CPosLandmarkSearch* iLandmarkSearch; |
|
410 CPosLmMultiDbSearch* iLmMultiSearch; |
|
411 |
|
412 // Search |
|
413 RPointerArray<CSearchResult> iSearchResults; |
|
414 RPointerArray<CAreaSearchResult> iAreaSearchResults; |
|
415 RPointerArray<CCategoryLandmarkSearchResult> iCategoryLandmarkSearchResults; |
|
416 RPointerArray<CCategorySearchResult> iCategorySearchResults; |
|
417 |
|
418 CPosLmOperation* iOperation; |
|
419 // Use this method when using CActiveLmOperation class from multiple threads |
|
420 // this is due to that it is not possible to use the iLog from different threads |
|
421 // set to ETrue is used from multiple threads |
|
422 |
|
423 TBool iUseLogFromThreadIsDisabled; |
|
424 CStifLogger* iLog; |
|
425 RFs iFileSession; |
|
426 private: // Data |
|
427 |
|
428 //TUint iCallbacks; |
|
429 |
|
430 |
|
431 }; |
|
432 |
|
433 class MProgressObserver |
|
434 { |
|
435 public: // New functions |
|
436 |
|
437 /** |
|
438 * Notifies the progress of the execution of a CPosLmOperation object. |
|
439 * |
|
440 * @param sProgress the progress of the operation |
|
441 */ |
|
442 virtual void NotifyProgress(TReal aProgress) = 0; |
|
443 |
|
444 }; |
|
445 |
|
446 class CActiveLmOperation : public CActive |
|
447 { |
|
448 public: |
|
449 |
|
450 /** |
|
451 * C++ constructor. |
|
452 */ |
|
453 CActiveLmOperation( |
|
454 CStifLogger* aLog, |
|
455 TBool aUseLogFromThreadIsDisabled = EFalse, |
|
456 TReal32 aThreshold = 0.3); |
|
457 |
|
458 /** |
|
459 * Destructor. |
|
460 */ |
|
461 ~CActiveLmOperation(); |
|
462 |
|
463 public: |
|
464 |
|
465 void Start(CPosLmOperation* aOperation, MProgressObserver* aObserver = NULL); |
|
466 |
|
467 void CheckOperationL(); |
|
468 |
|
469 void DeleteOperationD(); |
|
470 |
|
471 TInt Status() const; |
|
472 |
|
473 TReal Progress() const; |
|
474 |
|
475 CPosLmOperation* Operation(); |
|
476 |
|
477 void SetCancelTest(); |
|
478 |
|
479 TReal32 Threshold(); |
|
480 |
|
481 TReal32 DeltaProgress(); |
|
482 |
|
483 /** |
|
484 * From CActive |
|
485 * Handles request completion event. |
|
486 */ |
|
487 void DoCancel(); |
|
488 |
|
489 /** |
|
490 * From CActive. |
|
491 * |
|
492 * Handles request completion event. |
|
493 */ |
|
494 void RunL(); |
|
495 |
|
496 |
|
497 private: |
|
498 |
|
499 |
|
500 private: // data |
|
501 |
|
502 CPosLmOperation* iOperation; |
|
503 |
|
504 TReal32 iPassedProgress; |
|
505 TReal32 iLastProgress; |
|
506 TReal32 iDeltaProgress; |
|
507 TReal32 iThreshold; |
|
508 |
|
509 TBool iAsyncProgressErr; |
|
510 TBool iPassedProgressErr; |
|
511 |
|
512 TBool iCancelTest; |
|
513 |
|
514 TBool iUseLogFromThreadIsDisabled; |
|
515 |
|
516 MProgressObserver* iObserver; |
|
517 CStifLogger* iLog; |
|
518 }; |
|
519 |
|
520 |
|
521 #endif // CLANDMARKTESTPROCEDUREBASE_H |
|
522 |
|
523 // End of File |