|
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 |
|
22 #include "FT_CPosTp16.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkSearch.h> |
|
25 #include <EPos_CPosLmTextCriteria.h> |
|
26 |
|
27 #include "FT_LandmarkConstants.h" |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CPosTp16::GetName |
|
33 // |
|
34 // (other items were commented in a header). |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 void CPosTp16::GetName(TDes& aName) const |
|
38 { |
|
39 _LIT(KTestName, "TP16 - Initialize corrupt database"); |
|
40 aName = KTestName; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // CPosTp16::CloseTest |
|
45 // |
|
46 // (other items were commented in a header). |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 void CPosTp16::CloseTest() |
|
50 { |
|
51 delete iDatabase; |
|
52 iDatabase = NULL; |
|
53 |
|
54 iGlobalCategoryIds.Close(); |
|
55 iGlobalCategoryNames.Close(); |
|
56 RemoveGlobalCategoriesL(); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CPosTp16::StartL |
|
61 // |
|
62 // (other items were commented in a header). |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CPosTp16::StartL() |
|
66 { |
|
67 _LIT(KAccessErr, "Access method is not returning KErrPosLmNotInitialized when expected"); |
|
68 _LIT(KInitializedErr, "Method InitializedNeeded is not returning ETrue when expected"); |
|
69 |
|
70 SetupGlobalCategoriesL(); |
|
71 |
|
72 iDatabase=UseCorruptDbL(); |
|
73 delete iDatabase; |
|
74 iDatabase = NULL; |
|
75 |
|
76 iDatabase = UseGlobalCategoriesL(); |
|
77 |
|
78 CPosLmItemIterator* iter = NULL; |
|
79 TRAPD(err, iter = iDatabase->LandmarkIteratorL()); |
|
80 delete iter; |
|
81 AssertTrueSecL(err == KErrPosLmNotInitialized, KAccessErr); |
|
82 AssertTrueSecL(iDatabase->IsInitializingNeeded(), KInitializedErr); |
|
83 |
|
84 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
85 |
|
86 iter = iDatabase->LandmarkIteratorL(); |
|
87 delete iter; |
|
88 iter=NULL; |
|
89 |
|
90 // check that global categories are automatically inserter into lm db |
|
91 // when recovering database |
|
92 CheckGlobalCategoriesL(); |
|
93 |
|
94 delete iDatabase; |
|
95 iDatabase = NULL; |
|
96 |
|
97 iDatabase=UseCorruptDbL(); |
|
98 TRAP(err, iter = iDatabase->LandmarkIteratorL()); |
|
99 delete iter; |
|
100 AssertTrueSecL(err == KErrPosLmNotInitialized, KAccessErr); |
|
101 AssertTrueSecL(iDatabase->IsInitializingNeeded(), KInitializedErr); |
|
102 |
|
103 RunAsyncOperationLD(iDatabase->InitializeL()); |
|
104 |
|
105 iter = iDatabase->LandmarkIteratorL(); |
|
106 delete iter; |
|
107 |
|
108 // check that global categories are automatically inserter into lm db |
|
109 // when recovering database |
|
110 CheckGlobalCategoriesL(); |
|
111 |
|
112 delete iDatabase; |
|
113 iDatabase = NULL; |
|
114 |
|
115 iDatabase = UseTextDbL(); |
|
116 |
|
117 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
118 |
|
119 iter = iDatabase->LandmarkIteratorL(); |
|
120 delete iter; |
|
121 iter=NULL; |
|
122 |
|
123 // check that global categories are automatically inserter into lm db |
|
124 // when recovering database |
|
125 CheckGlobalCategoriesL(); |
|
126 |
|
127 delete iDatabase; |
|
128 iDatabase = NULL; |
|
129 |
|
130 iDatabase = UseContactDbL(); |
|
131 |
|
132 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
133 |
|
134 iter = iDatabase->LandmarkIteratorL(); |
|
135 delete iter; |
|
136 iter=NULL; |
|
137 |
|
138 // check that global categories are automatically inserter into lm db |
|
139 // when recovering database |
|
140 CheckGlobalCategoriesL(); |
|
141 |
|
142 delete iDatabase; |
|
143 iDatabase = NULL; |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CPosTp16::CheckGlobalCategoriesL |
|
149 // |
|
150 // (other items were commented in a header). |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 void CPosTp16::CheckGlobalCategoriesL() |
|
154 { |
|
155 iLog->Put(_L("CheckGlobalCategoriesL")); |
|
156 |
|
157 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*iDatabase); |
|
158 CleanupStack::PushL(cm); |
|
159 |
|
160 iLog->Put(_L("using CategoryIteratorL")); |
|
161 CPosLmItemIterator* catIter = cm->CategoryIteratorL(); |
|
162 CleanupStack::PushL(catIter); |
|
163 |
|
164 AssertTrueSecL(catIter->NumOfItemsL() == (TUint)iGlobalCategoryIds.Count(), _L("Wrong number of global categories")); |
|
165 |
|
166 TPosLmItemId id = catIter->NextL(); |
|
167 TInt i=0; |
|
168 while (id != KPosLmNullItemId) |
|
169 { |
|
170 /* |
|
171 // For debugging purposes |
|
172 TBuf<100> buf; |
|
173 buf.Format(_L("Id %d Exp Id %d"),id, iGlobalCategoryIds[i]); |
|
174 iLog->Put(buf); |
|
175 if (id != iGlobalCategoryIds[i]) LogErrorAndLeave(_L("Wrong id")); |
|
176 else iLog->Put(_L("++")); |
|
177 */ |
|
178 id = catIter->NextL(); |
|
179 i++; |
|
180 } |
|
181 CleanupStack::PopAndDestroy(catIter); |
|
182 CleanupStack::PopAndDestroy(cm); |
|
183 |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CPosTp16::UseCorruptDbL |
|
188 // |
|
189 // (other items were commented in a header). |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 CPosLandmarkDatabase* CPosTp16::UseCorruptDbL() |
|
193 { |
|
194 RemoveDefaultDbL(); |
|
195 |
|
196 #ifdef __WINS__ |
|
197 _LIT(KCorruptDbFile, "z:\\system\\test\\testdata\\SRVeposdamaged.ldb"); |
|
198 #else |
|
199 _LIT(KCorruptDbFile, "c:\\system\\test\\testdata\\SRVeposdamaged.ldb"); |
|
200 #endif |
|
201 |
|
202 _LIT(KCorruptDbFileOld, "c:\\system\\data\\SRVeposdamaged.ldb"); |
|
203 |
|
204 RFs fs; |
|
205 User::LeaveIfError(fs.Connect()); |
|
206 CleanupClosePushL(fs); |
|
207 |
|
208 CFileMan* fileMan = CFileMan::NewL(fs); |
|
209 CleanupStack::PushL(fileMan); |
|
210 |
|
211 User::LeaveIfError(fileMan->Copy(KCorruptDbFile, KDefaultDbPath, CFileMan::EOverWrite)); |
|
212 User::LeaveIfError(fileMan->Rename(KCorruptDbFileOld, KDefaultDb, CFileMan::EOverWrite)); |
|
213 |
|
214 CleanupStack::PopAndDestroy(2, &fs); |
|
215 |
|
216 return CPosLandmarkDatabase::OpenL(); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------- |
|
220 // CPosTp16::UseTextDbL |
|
221 // |
|
222 // (other items were commented in a header). |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 CPosLandmarkDatabase* CPosTp16::UseTextDbL() |
|
226 { |
|
227 RemoveDefaultDbL(); |
|
228 |
|
229 #ifdef __WINS__ |
|
230 _LIT(KCorruptDbFile, "z:\\system\\test\\testdata\\SRVepostext.ldb"); |
|
231 #else |
|
232 _LIT(KCorruptDbFile, "c:\\system\\test\\testdata\\SRVepostext.ldb"); |
|
233 #endif |
|
234 |
|
235 _LIT(KCorruptDbFileOld, "c:\\system\\data\\SRVepostext.ldb"); |
|
236 |
|
237 RFs fs; |
|
238 User::LeaveIfError(fs.Connect()); |
|
239 CleanupClosePushL(fs); |
|
240 |
|
241 CFileMan* fileMan = CFileMan::NewL(fs); |
|
242 CleanupStack::PushL(fileMan); |
|
243 |
|
244 User::LeaveIfError(fileMan->Copy(KCorruptDbFile, KDefaultDbPath, CFileMan::EOverWrite)); |
|
245 User::LeaveIfError(fileMan->Rename(KCorruptDbFileOld, KDefaultDb, CFileMan::EOverWrite)); |
|
246 |
|
247 CleanupStack::PopAndDestroy(2, &fs); |
|
248 |
|
249 return CPosLandmarkDatabase::OpenL(); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------- |
|
253 // CPosTp16::UseContactDbL |
|
254 // |
|
255 // (other items were commented in a header). |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 CPosLandmarkDatabase* CPosTp16::UseContactDbL() |
|
259 { |
|
260 RemoveDefaultDbL(); |
|
261 |
|
262 #ifdef __WINS__ |
|
263 _LIT(KCorruptDbFile, "z:\\system\\test\\testdata\\SRVeposcontact.ldb"); |
|
264 #else |
|
265 _LIT(KCorruptDbFile, "c:\\system\\test\\testdata\\SRVeposcontact.ldb"); |
|
266 #endif |
|
267 |
|
268 _LIT(KCorruptDbFileOld, "c:\\system\\data\\SRVeposcontact.ldb"); |
|
269 |
|
270 RFs fs; |
|
271 User::LeaveIfError(fs.Connect()); |
|
272 CleanupClosePushL(fs); |
|
273 |
|
274 CFileMan* fileMan = CFileMan::NewL(fs); |
|
275 CleanupStack::PushL(fileMan); |
|
276 |
|
277 User::LeaveIfError(fileMan->Copy(KCorruptDbFile, KDefaultDbPath, CFileMan::EOverWrite)); |
|
278 User::LeaveIfError(fileMan->Rename(KCorruptDbFileOld, KDefaultDb, CFileMan::EOverWrite)); |
|
279 |
|
280 CleanupStack::PopAndDestroy(2, &fs); |
|
281 |
|
282 return CPosLandmarkDatabase::OpenL(); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CPosTp16::SetupGlobalCategoriesL |
|
287 // |
|
288 // (other items were commented in a header). |
|
289 // --------------------------------------------------------- |
|
290 // |
|
291 void CPosTp16::SetupGlobalCategoriesL() |
|
292 { |
|
293 iGlobalCategoryNames.Reset(); |
|
294 iGlobalCategoryIds.Reset(); |
|
295 |
|
296 iGlobalCategoryNames.Append(_L("Restaurant")); |
|
297 iGlobalCategoryIds.Append(1); |
|
298 |
|
299 iGlobalCategoryNames.Append(_L("Bar")); |
|
300 iGlobalCategoryIds.Append(2); |
|
301 |
|
302 iGlobalCategoryNames.Append(_L("Gas station")); |
|
303 iGlobalCategoryIds.Append(3); |
|
304 |
|
305 iGlobalCategoryNames.Append(_L("Hotel")); |
|
306 iGlobalCategoryIds.Append(4); |
|
307 |
|
308 iGlobalCategoryNames.Append(_L("Shop")); |
|
309 iGlobalCategoryIds.Append(5); |
|
310 |
|
311 iGlobalCategoryNames.Append(_L("Sight")); |
|
312 iGlobalCategoryIds.Append(6); |
|
313 |
|
314 iGlobalCategoryNames.Append(_L("Car park")); |
|
315 iGlobalCategoryIds.Append(7); |
|
316 |
|
317 iGlobalCategoryNames.Append(_L("Bus stop")); |
|
318 iGlobalCategoryIds.Append(8); |
|
319 |
|
320 iGlobalCategoryNames.Append(_L("Pools")); |
|
321 iGlobalCategoryIds.Append(9); |
|
322 |
|
323 iGlobalCategoryNames.Append(_L("Shopping streets")); |
|
324 iGlobalCategoryIds.Append(10); |
|
325 } |
|
326 |
|
327 // End of File |