|
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_CPosTp20.h" |
|
22 #include <EPos_CPosLandmarkDatabase.h> |
|
23 #include <EPos_CPosLmDatabaseManager.h> |
|
24 #include "FT_LandmarkConstants.h" |
|
25 |
|
26 // CONSTANTS |
|
27 // See file eposlmglobalcategories02.rss in testdata for category Bar |
|
28 //_LIT(KICONFILE, "c:\\system\\data\\test2.mbm"); |
|
29 //const TInt KTP20IconIndex = 2; |
|
30 //const TInt KTP20IconMaskIndex = 2; |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 // --------------------------------------------------------- |
|
34 // CPosTp20::CloseTest |
|
35 // |
|
36 // (other items were commented in a header). |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 void CPosTp20::CloseTest() |
|
40 { |
|
41 iLog->Log(_L("CloseTest")); |
|
42 |
|
43 delete iDatabase; |
|
44 iDatabase = NULL; |
|
45 delete iCategoryManager; |
|
46 iCategoryManager = NULL; |
|
47 iGlobalCategoryIds.Close(); |
|
48 iGlobalCategoryNames.Close(); |
|
49 iGlobalCategoryTestNames.Close(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CPosTp20::RemoveAllCategoriesL |
|
54 // |
|
55 // (other items were commented in a header). |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 void CPosTp20::RemoveAllCategoriesL() |
|
59 { |
|
60 iLog->Log(_L("RemoveAllCategoriesL")); |
|
61 CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL(*iDatabase); |
|
62 CleanupStack::PushL(catMan); |
|
63 |
|
64 CPosLmItemIterator* iter = catMan->CategoryIteratorL(); |
|
65 CleanupStack::PushL(iter); |
|
66 |
|
67 RArray<TPosLmItemId> ids; |
|
68 CleanupClosePushL(ids); |
|
69 if (iter->NumOfItemsL() > 0) |
|
70 { |
|
71 iter->GetItemIdsL(ids, 0, iter->NumOfItemsL()); |
|
72 ExecuteAndDeleteLD(catMan->RemoveCategoriesL(ids)); |
|
73 } |
|
74 |
|
75 CleanupStack::PopAndDestroy(&ids); |
|
76 CleanupStack::PopAndDestroy(iter); |
|
77 CleanupStack::PopAndDestroy(catMan); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CPosTp20::StartL |
|
82 // |
|
83 // (other items were commented in a header). |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CPosTp20::StartL() |
|
87 { |
|
88 iLog->Log(_L("**** Testing CPosCategoryManager::ResetGlobalCategories() ********")); |
|
89 /* |
|
90 * Open the default landmark database |
|
91 * By default it is initialized with global categories (Assumption based on global categories API specification) |
|
92 * Test the Reset global categories functionality |
|
93 */ |
|
94 |
|
95 TBuf<150> info; |
|
96 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
97 |
|
98 if (iDatabase->IsInitializingNeeded()) |
|
99 { |
|
100 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
101 } |
|
102 |
|
103 iLog->Log(_L("Default database opened and initialised")); |
|
104 |
|
105 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
106 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
107 |
|
108 // Setup global category info |
|
109 SetupGlobalCategoriesL(); |
|
110 |
|
111 iLog->Log(_L("Execute ResetGlobalCategoriesL() synchronously)")); |
|
112 |
|
113 // Rename some global categories |
|
114 UpdateGlobalCategoriesInDb(); |
|
115 |
|
116 iLog->Log(_L("Global category info updated in database (Renaming category done)")); |
|
117 |
|
118 // Execute synchronously |
|
119 // Reset the global categories (the name and icon info of the global category will be reset) |
|
120 ExecuteAndDeleteLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
121 |
|
122 /* |
|
123 * Verification of 'reset' feature of global categories |
|
124 * Check for global category with name 'Hotel' and it should not exist |
|
125 * Check for global category having name 'Accomodation' |
|
126 */ |
|
127 VerifyGlobalCategoriesL(); |
|
128 |
|
129 iLog->Log(_L("Verification of CPosCategoryManager::ResetGlobalCategories() done)")); |
|
130 |
|
131 |
|
132 iLog->Log(_L("Execute ResetGlobalCategoriesL() asynchronously)")); |
|
133 // Rename some global categories |
|
134 UpdateGlobalCategoriesInDb(); |
|
135 |
|
136 iLog->Log(_L("Global category info updated in database (Renaming category done)")); |
|
137 |
|
138 // Execute asynchronously |
|
139 RunAsyncOperationLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
140 VerifyGlobalCategoriesL(); |
|
141 |
|
142 iLog->Log(_L("Verification of CPosCategoryManager::ResetGlobalCategories() done)")); |
|
143 |
|
144 |
|
145 iLog->Log(_L("Execute ResetGlobalCategoriesL() Asynchronously using User::WaitForRequest())")); |
|
146 |
|
147 // Rename some global categories |
|
148 UpdateGlobalCategoriesInDb(); |
|
149 |
|
150 iLog->Log(_L("Global category info updated in database (Renaming category done)")); |
|
151 |
|
152 // Execute asynchronously using User::WaitForRequest() |
|
153 CPosLmOperation* op = iCategoryManager->ResetGlobalCategoriesL(); |
|
154 CleanupStack::PushL(op); |
|
155 RunAsyncOperationByWaitForReqL(op); |
|
156 CleanupStack::PopAndDestroy(op); |
|
157 VerifyGlobalCategoriesL(); |
|
158 |
|
159 iLog->Log(_L("Verification of CPosCategoryManager::ResetGlobalCategories() done)")); |
|
160 |
|
161 iLog->Log(_L("Execute ResetGlobalCategoriesL() using Cancel immediately, after a while etc...")); |
|
162 // Rename some global categories |
|
163 UpdateGlobalCategoriesInDb(); |
|
164 |
|
165 // Test cancel immediately |
|
166 RunAsyncOperationAndCancelLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
167 |
|
168 // Test cancel after a while |
|
169 RunAsyncOperationAndCancelInCallbackLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
170 |
|
171 ExecuteAndDeleteLD(iCategoryManager->ResetGlobalCategoriesL()); |
|
172 VerifyGlobalCategoriesL(); |
|
173 iLog->Log(_L("Verification of CPosCategoryManager::ResetGlobalCategories() done)")); |
|
174 } |
|
175 |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CPosTp20::UseGlobalCategoriesL |
|
179 // |
|
180 // (other items were commented in a header). |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CPosTp20::UpdateGlobalCategoriesInDb() |
|
184 { |
|
185 /* |
|
186 * Change some properties of the existing global category (changing only the name here) |
|
187 */ |
|
188 |
|
189 TBuf<150>info; |
|
190 // Get sample global category info |
|
191 TPosLmItemId catId(0); |
|
192 TPosLmItemId catId1(0); |
|
193 CPosLandmarkCategory* category = NULL; |
|
194 |
|
195 for (TUint i = 0; i< iGlobalCategoryNames.Count(); i++) |
|
196 { |
|
197 catId = iCategoryManager->GetGlobalCategoryL(iGlobalCategoryIds[i]); |
|
198 category = iCategoryManager->ReadCategoryLC( catId ); |
|
199 category->SetCategoryNameL( iGlobalCategoryTestNames[i] ); |
|
200 iCategoryManager->UpdateCategoryL( *category ); |
|
201 CleanupStack::PopAndDestroy( category ); |
|
202 |
|
203 // Verify whether the added category exists with same global category id or not |
|
204 catId1 = iCategoryManager->GetCategoryL( iGlobalCategoryTestNames[i] ); |
|
205 |
|
206 //Read the landmark from the database |
|
207 category = iCategoryManager->ReadCategoryLC( catId1 ); |
|
208 |
|
209 // verify whether this is a global category or not (Accomodation) |
|
210 |
|
211 if ( category->GlobalCategory() != iGlobalCategoryIds[i] ) |
|
212 {// Error in category updation/verification |
|
213 iLog->Log(_L("Error in global category verification")); |
|
214 info.Zero(); |
|
215 info.Format(_L("Expected global category id %d"), iGlobalCategoryIds[i] ); |
|
216 info.Format(_L("Returned global category id %d"), category->GlobalCategory() ); |
|
217 iLog->Log( info ); |
|
218 info.Zero(); |
|
219 User::Leave(-1); |
|
220 } |
|
221 CleanupStack::PopAndDestroy( category ); |
|
222 } |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CPosTp20::SetupGlobalCategoriesL() |
|
227 // |
|
228 // (other items were commented in a header). |
|
229 // --------------------------------------------------------- |
|
230 // |
|
231 |
|
232 void CPosTp20::SetupGlobalCategoriesL() |
|
233 { |
|
234 // Testing with only 3 global categories |
|
235 ReadGlobalCategoriesFromResourceL( iGlobalCategoryIds, iGlobalCategoryNames, 3 ); |
|
236 |
|
237 iGlobalCategoryTestNames.Append(_L("Housing")); |
|
238 iGlobalCategoryTestNames.Append(_L("Movies")); |
|
239 iGlobalCategoryTestNames.Append(_L("Society")); |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CPosTp20::VerifyGlobalCategoriesL |
|
247 // |
|
248 // (other items were commented in a header). |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CPosTp20::VerifyGlobalCategoriesL(TBool /*aCheck */) |
|
252 { |
|
253 // Search database based on the new names of the global categories |
|
254 TBuf<100> info; |
|
255 info.Zero(); |
|
256 |
|
257 TPosLmItemId catId( 0 ); |
|
258 |
|
259 for ( TUint i = 0; i < iGlobalCategoryNames.Count(); i++ ) |
|
260 { |
|
261 // Search based on the Test names (with which the global category was renamed!) |
|
262 catId = iCategoryManager->GetCategoryL(iGlobalCategoryTestNames[i]); |
|
263 |
|
264 if ( catId != KPosLmNullItemId ) |
|
265 { |
|
266 iLog->Log(_L("Error in global category reset functionality verification")); |
|
267 info.Zero(); |
|
268 info.Format(_L("Expected global category id %d"), KPosLmNullItemId ); |
|
269 info.Format(_L("Returned global category id %d"), catId ); |
|
270 iLog->Log( info ); |
|
271 info.Zero(); |
|
272 User::Leave(-1); |
|
273 } |
|
274 |
|
275 // Search for old names of the global category |
|
276 catId = iCategoryManager->GetCategoryL( *iGlobalCategoryNames[i] ); |
|
277 CPosLandmarkCategory* category = iCategoryManager->ReadCategoryLC( catId ); |
|
278 |
|
279 // Get the global category id |
|
280 if ( category->GlobalCategory() ) |
|
281 { |
|
282 if ( category->GlobalCategory() != iGlobalCategoryIds[i] ) |
|
283 { |
|
284 iLog->Log(_L("Error in global category reset functionality verification")); |
|
285 info.Zero(); |
|
286 info.Format(_L("Expected global category id %d"), iGlobalCategoryIds[i] ); |
|
287 info.Format(_L("Returned global category id %d"), catId ); |
|
288 iLog->Log( info ); |
|
289 info.Zero(); |
|
290 User::Leave(-1); |
|
291 } |
|
292 } |
|
293 CleanupStack::PopAndDestroy(category); |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CPosTp20::RenameAndDeleteGlobalL |
|
299 // |
|
300 // (other items were commented in a header). |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 void CPosTp20::RenameAndDeleteGlobalL() |
|
304 { |
|
305 const TPosLmGlobalCategory KRemoveGlobalId1 = 1; |
|
306 const TPosLmGlobalCategory KRemoveGlobalId2 = 11; |
|
307 |
|
308 const TPosLmGlobalCategory KRenameGlobalId1 = 3; |
|
309 const TPosLmGlobalCategory KRenameGlobalId2 = 12; |
|
310 |
|
311 TBuf<150> buf; |
|
312 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
313 TPosLmItemId id = iCategoryManager->GetGlobalCategoryL(KRemoveGlobalId1); |
|
314 HBufC* name = iCategoryManager->GlobalCategoryNameL(KRemoveGlobalId1); |
|
315 CleanupStack::PushL(name); |
|
316 buf.Format(_L("Removing global category %S"), name); |
|
317 iLog->Log(buf); |
|
318 CleanupStack::PopAndDestroy(name); |
|
319 CPosLmOperation* op = iCategoryManager->RemoveCategoryL(id); |
|
320 ExecuteAndDeleteLD(op); |
|
321 |
|
322 id = iCategoryManager->GetGlobalCategoryL(KRemoveGlobalId2); |
|
323 name = iCategoryManager->GlobalCategoryNameL(KRemoveGlobalId2); |
|
324 CleanupStack::PushL(name); |
|
325 buf.Zero(); |
|
326 buf.Format(_L("Removing global category %S"), name); |
|
327 iLog->Log(buf); |
|
328 CleanupStack::PopAndDestroy(name); |
|
329 op = iCategoryManager->RemoveCategoryL(id); |
|
330 ExecuteAndDeleteLD(op); |
|
331 |
|
332 id = iCategoryManager->GetGlobalCategoryL(KRenameGlobalId1); |
|
333 |
|
334 name = iCategoryManager->GlobalCategoryNameL(KRenameGlobalId1); |
|
335 CleanupStack::PushL(name); |
|
336 buf.Format(_L("Renaming global category %S to Jada jada"), name); |
|
337 iLog->Log(buf); |
|
338 CleanupStack::PopAndDestroy(name); |
|
339 |
|
340 CPosLandmarkCategory* cm = iCategoryManager->ReadCategoryLC(id); |
|
341 cm->SetCategoryNameL(_L("Jada jada")); |
|
342 iCategoryManager->UpdateCategoryL(*cm); |
|
343 CleanupStack::PopAndDestroy(cm); |
|
344 ExecuteAndDeleteLD(iDatabase->CompactL()); |
|
345 |
|
346 id = iCategoryManager->GetGlobalCategoryL(KRenameGlobalId2); |
|
347 name = iCategoryManager->GlobalCategoryNameL(KRenameGlobalId2); |
|
348 CleanupStack::PushL(name); |
|
349 buf.Format(_L("Renaming global category %S to asdfasdas"), name); |
|
350 iLog->Log(buf); |
|
351 CleanupStack::PopAndDestroy(name); |
|
352 cm = iCategoryManager->ReadCategoryLC(id); |
|
353 cm->SetCategoryNameL(_L("asdfasdas")); |
|
354 iCategoryManager->UpdateCategoryL(*cm); |
|
355 CleanupStack::PopAndDestroy(cm); |
|
356 } |
|
357 |
|
358 // End of File |