|
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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-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_CPosTp102.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLmDatabaseManager.h> |
|
25 #include "FT_DatabaseUtility.h" |
|
26 #include <EPos_CPosLmTextCriteria.h> |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // CPosTp102::CloseTest |
|
32 // |
|
33 // (other items were commented in a header). |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 void CPosTp102::CloseTest() |
|
37 { |
|
38 iLog->Log(_L("CloseTest")); |
|
39 |
|
40 TRAPD(err, RemoveAllLmDatabasesL()); |
|
41 if (err != KErrNone) iLog->Log(_L("RemoveAllLmDatabasesL() leaved")); |
|
42 |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CPosTp102::StartL |
|
47 // |
|
48 // (other items were commented in a header). |
|
49 // --------------------------------------------------------- |
|
50 // |
|
51 void CPosTp102::StartL() |
|
52 { |
|
53 _LIT(KDatabase1, "Tp102_Database1.ldb"); |
|
54 _LIT(KDatabaseUri1, "file://C:Tp102_Database1.ldb"); |
|
55 _LIT(KDatabase1MissingProtocol, "C:Tp102_Database1.ldb"); |
|
56 _LIT(KDatabase1MissingDrive, "Tp102_Database1.ldb"); |
|
57 _LIT(KDatabase1MissingExtension, "C:Tp102_Database1"); |
|
58 _LIT(KDatabase1FullPath, "c:\\private\\100012a5\\DBS_101FE978_Tp102_Database1.ldb"); |
|
59 _LIT(KRemoteDatabaseUri, "http://c:eposlm.ldb"); |
|
60 _LIT(KDatabase3, "C:Tp102_DBMS_Database3.ldb"); |
|
61 _LIT(KDatabaseUri3, "file://C:Tp102_DBMS_Database3.ldb"); |
|
62 // Change here if path to private area ever changes |
|
63 _LIT(KDatabase4FullPath, "c:\\private\\100012a5\\DBS_101FE978_Tp102_DefaultDatabase.ldb"); |
|
64 _LIT(KDatabase4, "Tp102_DefaultDatabase.ldb"); |
|
65 _LIT(KDatabaseUri4, "file://C:Tp102_DefaultDatabase.ldb"); |
|
66 |
|
67 _LIT(KDatabaseUri5, "file://R:NonExistingDrive.ldb"); |
|
68 |
|
69 #ifdef __WINS__ |
|
70 // D on wins |
|
71 _LIT(KDbOnMedia, "D:TP102EPOSLM.LDB"); |
|
72 _LIT(KDbOnMediaUri, "file://D:TP102EPOSLM.LDB"); |
|
73 |
|
74 _LIT(KDbOnMedia2, "D:TP102EPOSLM_2.LDB"); |
|
75 _LIT(KDbOnMedia2Uri, "file://D:TP102EPOSLM_2.LDB"); |
|
76 _LIT(KDbOnMedia2MissingDrive, "file://TP102EPOSLM_2.LDB"); |
|
77 #else |
|
78 |
|
79 _LIT(KDbOnMedia, "F:TP102EPOSLM.LDB"); |
|
80 _LIT(KDbOnMediaUri, "file://F:TP102EPOSLM.LDB"); |
|
81 |
|
82 _LIT(KDbOnMedia2, "F:TP102EPOSLM_2.LDB"); |
|
83 _LIT(KDbOnMedia2Uri, "file://F:TP102EPOSLM_2.LDB"); |
|
84 _LIT(KDbOnMedia2MissingDrive, "file://TP102EPOSLM_2.LDB"); |
|
85 #endif |
|
86 |
|
87 _LIT(KEmptyURI, ""); |
|
88 |
|
89 iLog->Log(_L("Warning: this test case requires E: drive")); |
|
90 |
|
91 TInt err=KErrNone; |
|
92 |
|
93 RemoveAllLmDatabasesL(); |
|
94 // Create defaultdb |
|
95 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
96 CleanupStack::PushL(dbManager); |
|
97 HPosLmDatabaseInfo* dbInfo4 = HPosLmDatabaseInfo::NewLC(KDatabase4); |
|
98 dbManager->CreateDatabaseL(*dbInfo4); |
|
99 CleanupStack::PopAndDestroy(dbInfo4); |
|
100 dbManager->SetDefaultDatabaseUriL(KDatabase4); |
|
101 |
|
102 // 1) Remove all landmark db |
|
103 RemoveAllLmDatabasesL(); |
|
104 |
|
105 // check the count of databases that could not be delted since they were in use |
|
106 CDesCArray* dbList = dbManager->ListDatabasesLC(); |
|
107 TInt count = dbList->Count(); |
|
108 |
|
109 |
|
110 // 2) Verify no *.ldb files on file system |
|
111 VerifyNrOfDatabasesL(count); |
|
112 |
|
113 // 3) Check default db |
|
114 HBufC* defaultDbUri; |
|
115 defaultDbUri = dbManager->DefaultDatabaseUriLC(); |
|
116 |
|
117 // 4) List all database, should return 0 |
|
118 VerifyNrOfDatabasesL(count); |
|
119 |
|
120 // 5) Check that database does not exist |
|
121 if (dbManager->DatabaseExistsL(KDatabaseUri1)) |
|
122 { |
|
123 |
|
124 iLog->Log(_L("This database should not exist")); |
|
125 User::Leave(-1); |
|
126 } |
|
127 |
|
128 // 6) Create a new database using db api |
|
129 HPosLmDatabaseInfo* dbInfo1 = HPosLmDatabaseInfo::NewLC(KDatabase1); |
|
130 dbManager->CreateDatabaseL(*dbInfo1); |
|
131 CleanupStack::PopAndDestroy(dbInfo1); |
|
132 |
|
133 // 7) List dbs, should contain db created in step6 |
|
134 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
135 if (dbArray->Count() != count+1) |
|
136 { |
|
137 iLog->Log(_L("Database does not contain the last created db")); |
|
138 User::Leave(-1); |
|
139 } |
|
140 |
|
141 iLog->Log((*dbArray)[0]); |
|
142 // 8) Check that dabase does not exist |
|
143 if (!dbManager->DatabaseExistsL(KDatabaseUri1)) |
|
144 { |
|
145 |
|
146 iLog->Log(_L("This database should exist")); |
|
147 User::Leave(-1); |
|
148 } |
|
149 CleanupStack::PopAndDestroy(dbArray); |
|
150 |
|
151 // 9) |
|
152 CPosLandmarkDatabase* db1 = CPosLandmarkDatabase::OpenL(KDatabaseUri1); |
|
153 CleanupStack::PushL(db1); |
|
154 if (db1->IsInitializingNeeded()) |
|
155 { |
|
156 iLog->Log(_L("db1->InitializeL")); |
|
157 ExecuteAndDeleteLD(db1->InitializeL()); |
|
158 } |
|
159 CleanupStack::PopAndDestroy(db1); |
|
160 |
|
161 |
|
162 CleanupStack::PopAndDestroy(defaultDbUri); |
|
163 |
|
164 // 11) Open the default db |
|
165 CPosLandmarkDatabase* defaultDatabase = CPosLandmarkDatabase::OpenL(); |
|
166 CleanupStack::PushL(defaultDatabase); |
|
167 |
|
168 iLog->Log(_L("12) List all databases")); |
|
169 // 12) List all databases |
|
170 TInt verifyDbCount = count +2; |
|
171 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri4); |
|
172 |
|
173 // 13) |
|
174 iLog->Log(_L("13) Does defaultDB exist")); |
|
175 if (!dbManager->DatabaseExistsL(KDatabaseUri4)) |
|
176 { |
|
177 |
|
178 iLog->Log(_L("The default database should have been created")); |
|
179 User::Leave(-1); |
|
180 } |
|
181 |
|
182 // 14) Try to delete the physical file while db is open |
|
183 |
|
184 // Fix this path |
|
185 err = iFileSession.Delete(KDatabase4FullPath); |
|
186 if (err != KErrInUse) |
|
187 { |
|
188 |
|
189 iLog->Log(_L("It was possible to delete default db from file system")); |
|
190 User::Leave(err); |
|
191 } |
|
192 CleanupStack::PopAndDestroy(defaultDatabase); |
|
193 |
|
194 // 15) Create a landmark database using the DBMS API |
|
195 iLog->Log(_L("15) Create a landmark database using the DBMS API")); |
|
196 FTDatabaseUtility::CreateDatabaseL(KDatabase3); |
|
197 // 16) |
|
198 verifyDbCount = count +3; |
|
199 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri3); |
|
200 |
|
201 // 17) Create a database on a removable media |
|
202 iLog->Log(_L("17) Create a database on a removable media")); |
|
203 HPosLmDatabaseInfo* dbInfoMedia = HPosLmDatabaseInfo::NewLC(KDbOnMedia); |
|
204 dbManager->CreateDatabaseL(*dbInfoMedia); |
|
205 CleanupStack::PopAndDestroy(dbInfoMedia); |
|
206 |
|
207 // 18) Verify database |
|
208 verifyDbCount = count + 4; |
|
209 VerifyNrOfDatabasesL(verifyDbCount, KDbOnMediaUri); |
|
210 |
|
211 // 19) Retrieve the display name for the default db, it should be different from actual the filename |
|
212 iLog->Log(_L("19) Retrieve the display name for the default db, it should be different from actual the filename")); |
|
213 HBufC* defUri = dbManager->DefaultDatabaseUriLC(); |
|
214 HPosLmDatabaseInfo* dbInfoReadback = HPosLmDatabaseInfo::NewLC(*defUri); |
|
215 dbManager->GetDatabaseInfoL(*dbInfoReadback); |
|
216 TPosLmDatabaseSettings settings = dbInfoReadback->Settings(); |
|
217 TPtrC name1 = settings.DatabaseName(); |
|
218 CleanupStack::PopAndDestroy(dbInfoReadback); |
|
219 CleanupStack::PopAndDestroy(defUri); |
|
220 |
|
221 |
|
222 // 20) Set a new db as default |
|
223 dbManager->SetDefaultDatabaseUriL(KDbOnMediaUri); |
|
224 |
|
225 // 21) Retrieve the display name for the new default db, should be the same as in step 19 |
|
226 iLog->Log(_L("21) Retrieve the display name for the new default db, should be the same as in step 19")); |
|
227 dbInfoReadback = HPosLmDatabaseInfo::NewLC(KDbOnMediaUri); |
|
228 dbManager->GetDatabaseInfoL(*dbInfoReadback); |
|
229 TPosLmDatabaseSettings settings2 = dbInfoReadback->Settings(); |
|
230 TPtrC name2 = settings2.DatabaseName(); |
|
231 CleanupStack::PopAndDestroy(dbInfoReadback); |
|
232 |
|
233 if (name1.Compare(name2) != 0) |
|
234 { |
|
235 iLog->Log(_L("Names does not match")); |
|
236 User::Leave(-1); |
|
237 } |
|
238 |
|
239 _LIT(KFileColonSlashSlash, "file://"); |
|
240 _LIT(KCColonSomeTestDbDotLdb, "c:SomeTestDb.ldb"); |
|
241 _LIT(KFileColonSlashSlashSomeTestDb2DotLdb, "file://SomeTestDb2.ldb"); |
|
242 _LIT(KCColonSomeTestDb3DotDoc, "c:SomeTestDb3.doc"); |
|
243 _LIT(KEmptyString, ""); |
|
244 _LIT(KFileColonSlahSlashCColonDotLdb, "file://C:.LDB"); |
|
245 _LIT(KVeryLongString, "c:\\SomeVeryLongFilename1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.ldb"); |
|
246 |
|
247 HPosLmDatabaseInfo* dbInfoFileColonSlashSlash = HPosLmDatabaseInfo::NewLC(KFileColonSlashSlash); |
|
248 HPosLmDatabaseInfo* dbInfoCColonSomeTestDbDotLdb = HPosLmDatabaseInfo::NewLC(KCColonSomeTestDbDotLdb); |
|
249 HPosLmDatabaseInfo* dbInfoFileColonSlashSlashSomeTestDb2DotLdb = HPosLmDatabaseInfo::NewLC(KFileColonSlashSlashSomeTestDb2DotLdb); |
|
250 HPosLmDatabaseInfo* dbInfoCColonSomeTestDb3DotDoc = HPosLmDatabaseInfo::NewLC(KCColonSomeTestDb3DotDoc); |
|
251 HPosLmDatabaseInfo* dbInfoEmptyString = HPosLmDatabaseInfo::NewLC(KEmptyString); |
|
252 HPosLmDatabaseInfo* dbInfoFileColonSlahSlashCColonDotLdb = HPosLmDatabaseInfo::NewLC(KFileColonSlahSlashCColonDotLdb); |
|
253 HPosLmDatabaseInfo* dbInfoVeryLongString = HPosLmDatabaseInfo::NewLC(KVeryLongString); |
|
254 |
|
255 |
|
256 // 22) Createa db with same name as an existing |
|
257 dbInfo1 = HPosLmDatabaseInfo::NewLC(KDatabase1); |
|
258 TRAP(err, dbManager->CreateDatabaseL(*dbInfo1)); |
|
259 CleanupStack::PopAndDestroy(dbInfo1); |
|
260 if (err != KErrAlreadyExists) |
|
261 { |
|
262 iLog->Log(_L("22 Should leave with KErrAlreadyExist")); |
|
263 User::Leave(err); |
|
264 } |
|
265 |
|
266 // 23) Create a new database using the db management API with a nonsense URI |
|
267 TRAP(err, dbManager->CreateDatabaseL(*dbInfoFileColonSlashSlash)); |
|
268 if (err != KErrArgument) |
|
269 { |
|
270 iLog->Log(_L("23 Should leave with KErrArgument")); |
|
271 User::Leave(err); |
|
272 } |
|
273 |
|
274 // 24) Create a new database using the db management API with a URI specifying a remote database |
|
275 HPosLmDatabaseInfo* dbInfoRem = HPosLmDatabaseInfo::NewLC(KRemoteDatabaseUri); |
|
276 TRAP(err, dbManager->CreateDatabaseL(*dbInfoRem)); |
|
277 CleanupStack::PopAndDestroy(dbInfoRem); |
|
278 |
|
279 if (err != KErrNotSupported) |
|
280 { |
|
281 iLog->Log(_L("24 Should leave with KErrNotSupported")); |
|
282 User::Leave(err); |
|
283 } |
|
284 |
|
285 // 25) Create a new database using the db management API with a URI with missing protocol |
|
286 TRAP(err, dbManager->CreateDatabaseL(*dbInfoCColonSomeTestDbDotLdb)); |
|
287 if (err != KErrNone) |
|
288 { |
|
289 iLog->Log(_L("25 Should NOT leave")); |
|
290 User::Leave(err); |
|
291 } |
|
292 |
|
293 // 26) Create a new database using the db management API with a URI with missing drive |
|
294 TRAP(err, dbManager->CreateDatabaseL(*dbInfoFileColonSlashSlashSomeTestDb2DotLdb)); |
|
295 if (err != KErrNone) |
|
296 { |
|
297 iLog->Log(_L("26 Should NOT leave")); |
|
298 User::Leave(err); |
|
299 } |
|
300 |
|
301 // 27) Create a new database using the db management API with a URI that does not end with *.ldb |
|
302 TRAP(err, dbManager->CreateDatabaseL(*dbInfoCColonSomeTestDb3DotDoc)); |
|
303 if (err != KErrArgument) |
|
304 { |
|
305 iLog->Log(_L("27 Should leave with KErrArgument")); |
|
306 User::Leave(err); |
|
307 } |
|
308 |
|
309 // 28) Create a new database using the db management API with a URI containing the path to the database file |
|
310 HPosLmDatabaseInfo* dbInfoUri1 = HPosLmDatabaseInfo::NewLC(KDatabaseUri1); |
|
311 TRAP(err, dbManager->CreateDatabaseL(*dbInfoUri1)); |
|
312 CleanupStack::PopAndDestroy(dbInfoUri1); |
|
313 if (err != KErrAlreadyExists) |
|
314 { |
|
315 iLog->Log(_L("28 Should leave with KErrAlreadyExist")); |
|
316 User::Leave(err); |
|
317 } |
|
318 |
|
319 // 29) Create a new database using the db management API with an empty URI |
|
320 TRAP(err, dbManager->CreateDatabaseL(*dbInfoEmptyString)); |
|
321 if (err != KErrArgument) |
|
322 { |
|
323 iLog->Log(_L("29 Should leave with KErrArgument")); |
|
324 User::Leave(err); |
|
325 } |
|
326 |
|
327 // 29b) Create a new database using the db management API with an empty URI (containing file://c:.ldb) |
|
328 TRAP(err, dbManager->CreateDatabaseL(*dbInfoFileColonSlahSlashCColonDotLdb)); |
|
329 if (err != KErrArgument) |
|
330 { |
|
331 iLog->Log(_L("29b Should leave with KErrArgument")); |
|
332 User::Leave(err); |
|
333 } |
|
334 |
|
335 // 30) Create a new database using the db management API with a URI that is longer than allowed |
|
336 TRAP(err, dbManager->CreateDatabaseL(*dbInfoVeryLongString)); |
|
337 if (err != KErrArgument) |
|
338 { |
|
339 iLog->Log(_L(" Should leave with KErrArgument")); |
|
340 User::Leave(err); |
|
341 } |
|
342 |
|
343 CleanupStack::PopAndDestroy(dbInfoVeryLongString); |
|
344 CleanupStack::PopAndDestroy(dbInfoFileColonSlahSlashCColonDotLdb); |
|
345 CleanupStack::PopAndDestroy(dbInfoEmptyString); |
|
346 CleanupStack::PopAndDestroy(dbInfoCColonSomeTestDb3DotDoc); |
|
347 CleanupStack::PopAndDestroy(dbInfoFileColonSlashSlashSomeTestDb2DotLdb); |
|
348 CleanupStack::PopAndDestroy(dbInfoCColonSomeTestDbDotLdb); |
|
349 CleanupStack::PopAndDestroy(dbInfoFileColonSlashSlash); |
|
350 |
|
351 // 31 Try to delete an existing db |
|
352 dbManager->DeleteDatabaseL(KDatabaseUri1); |
|
353 // 32) Check that it is deleted from file system |
|
354 iLog->Log(_L("Trap error below:")); |
|
355 verifyDbCount = count + 5; |
|
356 TRAP(err, VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri1)); |
|
357 if (err != KErrNotFound) |
|
358 { |
|
359 iLog->Log(_L("32 Should not be found")); |
|
360 User::Leave(err); |
|
361 } |
|
362 |
|
363 // 33) Delete same file again, according to header file, nothing should happen |
|
364 // when the file does not exist |
|
365 TRAP(err, dbManager->DeleteDatabaseL(KDatabaseUri1)); |
|
366 if (err != KErrNone) |
|
367 { |
|
368 iLog->Log(_L("33 DeleteDatbaseL, nothing should happen")); |
|
369 User::Leave(err); |
|
370 } |
|
371 iLog->Log(_L("After DeleteDatabaseL")); |
|
372 |
|
373 CFileMan* fileMan = NULL; |
|
374 fileMan = CFileMan::NewL(iFileSession); |
|
375 CleanupStack::PushL(fileMan); |
|
376 |
|
377 dbInfo1 = HPosLmDatabaseInfo::NewLC(KDatabase1); |
|
378 dbManager->CreateDatabaseL(*dbInfo1); |
|
379 CleanupStack::PopAndDestroy(dbInfo1); |
|
380 verifyDbCount = count +6; |
|
381 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri1); |
|
382 // 34 Set an existing non-default db to be read-only (attribute found in F32FILE.H) |
|
383 err = fileMan->Attribs(KDatabase1FullPath, KEntryAttReadOnly, KEntryAttNormal, TTime(0)); |
|
384 if (err != KErrNone) |
|
385 { |
|
386 iLog->Log(_L("Attributes could not be changed for KDatabase1FullPath")); |
|
387 User::Leave(err); |
|
388 } |
|
389 |
|
390 // 35) Try to delete db with read only |
|
391 TRAP(err, dbManager->DeleteDatabaseL(KDatabaseUri1)); |
|
392 if (err != KErrAccessDenied) |
|
393 { |
|
394 iLog->Log(_L("35 Err delete of KDatabaseUri1")); |
|
395 User::Leave(err); |
|
396 } |
|
397 |
|
398 // Change back to writeable (attribute found in F32FILE.H) |
|
399 err = fileMan->Attribs(KDatabase1FullPath, KEntryAttNormal, KEntryAttReadOnly, TTime(0)); |
|
400 if (err != KErrNone) |
|
401 { |
|
402 iLog->Log(_L("Attributes could not be changed KDatabase1FullPath")); |
|
403 User::Leave(err); |
|
404 } |
|
405 |
|
406 // 36) Take a read lock on a db by using a search operation |
|
407 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(KDatabaseUri1); |
|
408 CleanupStack::PushL(lmd); |
|
409 |
|
410 if (lmd->IsInitializingNeeded()) |
|
411 { |
|
412 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
413 } |
|
414 |
|
415 CPosLandmarkSearch* landmarkSearch = CPosLandmarkSearch::NewL(*lmd); |
|
416 CleanupStack::PushL(landmarkSearch); |
|
417 |
|
418 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
419 textCriteria->SetTextL(_L("*")); |
|
420 iOperation = landmarkSearch->StartLandmarkSearchL(*textCriteria, EFalse); |
|
421 |
|
422 // 37) Try to delete db with read lock |
|
423 TRAP(err, dbManager->DeleteDatabaseL(KDatabaseUri1)); |
|
424 if (err != KErrInUse) |
|
425 { |
|
426 iLog->Log(_L("37) Err delete of Read Locked KDatabaseUri1")); |
|
427 User::Leave(err); |
|
428 } |
|
429 |
|
430 ExecuteAndDeleteLD(iOperation); |
|
431 |
|
432 // 38) List databases |
|
433 verifyDbCount = count + 6; |
|
434 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri1); |
|
435 |
|
436 //39) Take a write lock on a db by trying to delete all landmarks operations |
|
437 iOperation = lmd->RemoveAllLandmarksL(); |
|
438 // 40) Try to delete db with write lock |
|
439 TRAP(err, dbManager->DeleteDatabaseL(KDatabaseUri1)); |
|
440 if (err != KErrInUse) |
|
441 { |
|
442 iLog->Log(_L("40) Err delete of Write Locked KDatabaseUri1")); |
|
443 User::Leave(err); |
|
444 } |
|
445 |
|
446 ExecuteAndDeleteLD(iOperation); |
|
447 |
|
448 // 41) List databases |
|
449 verifyDbCount = count + 6; |
|
450 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri1); |
|
451 |
|
452 CleanupStack::PopAndDestroy(textCriteria); |
|
453 CleanupStack::PopAndDestroy(landmarkSearch); |
|
454 CleanupStack::PopAndDestroy(lmd); |
|
455 |
|
456 CleanupStack::PopAndDestroy(fileMan); |
|
457 |
|
458 // 42) Try to delete a non-existing URI |
|
459 TRAP(err, dbManager->DeleteDatabaseL(_L("c:\\NonsenseURI"))); |
|
460 if (err != KErrArgument) |
|
461 { |
|
462 |
|
463 iLog->Log(_L("42: Should leave with KErrArgument11")); |
|
464 User::Leave(err); |
|
465 } |
|
466 |
|
467 // 43) Try to delete a remote URI |
|
468 TRAP(err, dbManager->DeleteDatabaseL(KRemoteDatabaseUri)); |
|
469 if (err!=KErrNotSupported) |
|
470 { |
|
471 iLog->Log(_L("43) Err KRemoteDatabaseUri")); |
|
472 User::Leave(err); |
|
473 } |
|
474 |
|
475 // 44) Try to delete a local db specifying URI with missing protocol |
|
476 dbManager->DeleteDatabaseL(KDatabase1MissingProtocol); |
|
477 |
|
478 // 45) List databases |
|
479 verifyDbCount = count + 5; |
|
480 VerifyNrOfDatabasesL(verifyDbCount); |
|
481 |
|
482 // 46) Try to delete a db on removable media excluding drive in URI |
|
483 // Since the DeleteDatabaseL just returns if the db is not found, verify that no db has been removed |
|
484 |
|
485 HPosLmDatabaseInfo* dbInfoMedia2 = HPosLmDatabaseInfo::NewLC(KDbOnMedia2); |
|
486 dbManager->CreateDatabaseL(*dbInfoMedia2); |
|
487 CleanupStack::PopAndDestroy(dbInfoMedia2); |
|
488 verifyDbCount = count +6; |
|
489 VerifyNrOfDatabasesL(verifyDbCount, KDbOnMedia2Uri); |
|
490 TRAP(err , dbManager->DeleteDatabaseL(KDbOnMedia2MissingDrive)); |
|
491 |
|
492 if (err != KErrNone) |
|
493 { |
|
494 TBuf<100> buffe; |
|
495 buffe.Format(_L("46) Wrong error when deleting KDbOnMedia2MissingDrive, was %d should be %d"), err, KErrNone); |
|
496 |
|
497 iLog->Log(buffe); |
|
498 User::Leave(err); |
|
499 } |
|
500 verifyDbCount = count + 6; |
|
501 VerifyNrOfDatabasesL(verifyDbCount, KDbOnMedia2Uri); |
|
502 |
|
503 // 47) Try to delete a db on c drive excluding drive in URI |
|
504 iLog->Log(_L("47) Try to delete a db on c drive excluding drive in URI")); |
|
505 dbInfo1 = HPosLmDatabaseInfo::NewLC(KDatabase1); |
|
506 TRAP(err, dbManager->CreateDatabaseL(*dbInfo1)); |
|
507 CleanupStack::PopAndDestroy(dbInfo1); |
|
508 if (err != KErrNone && err != KErrAlreadyExists) |
|
509 { |
|
510 iLog->Log(_L("Problem creating file KDatabase1")); |
|
511 User::Leave(err); |
|
512 } |
|
513 TRAP(err, dbManager->DeleteDatabaseL(KDatabase1MissingDrive)); |
|
514 if (err != KErrNone) |
|
515 { |
|
516 iLog->Log(_L("Wrong errro when deleting file")); |
|
517 User::Leave(err); |
|
518 } |
|
519 verifyDbCount = count + 6; |
|
520 VerifyNrOfDatabasesL(verifyDbCount); |
|
521 |
|
522 dbInfo1 = HPosLmDatabaseInfo::NewLC(KDatabase1); |
|
523 dbManager->CreateDatabaseL(*dbInfo1); |
|
524 CleanupStack::PopAndDestroy(dbInfo1); |
|
525 verifyDbCount = count +7; |
|
526 VerifyNrOfDatabasesL(verifyDbCount, KDatabaseUri1); |
|
527 |
|
528 // 48) Try to delete a db with URI that does not end with .ldb |
|
529 iLog->Log(_L("48) Try to delete a db with URI that does not end with .ldb")); |
|
530 TRAP(err, dbManager->DeleteDatabaseL(KDatabase1MissingExtension)); |
|
531 if (err != KErrArgument) |
|
532 { |
|
533 iLog->Log(_L("48) Wrong error when deleting KDatabase1MissingExtension")); |
|
534 User::Leave(err); |
|
535 } |
|
536 |
|
537 // 49) Try to delete a database with a URI that includes the path to the database |
|
538 iLog->Log(_L("49) Try to delete a database with a URI that includes the path to the database")); |
|
539 TRAP(err, dbManager->DeleteDatabaseL(KDatabase1FullPath)); |
|
540 if (err != KErrArgument) |
|
541 { |
|
542 iLog->Log(_L("Wrong error when deleting KDatabase1FullPath")); |
|
543 User::Leave(err); |
|
544 } |
|
545 verifyDbCount = count +7; |
|
546 VerifyNrOfDatabasesL(verifyDbCount); |
|
547 |
|
548 // 50 Delete with empty URI |
|
549 iLog->Log(_L("50) ")); |
|
550 TRAP(err, dbManager->DeleteDatabaseL(KEmptyURI)); |
|
551 if (err != KErrArgument) |
|
552 { |
|
553 iLog->Log(_L("Wrong error when deleting KEmptyURI")); |
|
554 User::Leave(err); |
|
555 } |
|
556 |
|
557 // 51) Try to delete a db with URI that is longer than allowed |
|
558 iLog->Log(_L("51) ")); |
|
559 TRAP(err, dbManager->DeleteDatabaseL(_L("SomeVeryLongFilename1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.ldb"))); |
|
560 if (err != KErrArgument) |
|
561 { |
|
562 iLog->Log(_L("Wrong error when deleting long filename file")); |
|
563 User::Leave(err); |
|
564 } |
|
565 |
|
566 // 52) Try to delete the existing default db |
|
567 iLog->Log(_L("52) ")); |
|
568 dbManager->SetDefaultDatabaseUriL(KDatabase1); |
|
569 dbManager->DeleteDatabaseL(KDatabase1); |
|
570 |
|
571 // 53) List databases |
|
572 iLog->Log(_L("53) ")); |
|
573 verifyDbCount = count +6; |
|
574 VerifyNrOfDatabasesL(verifyDbCount); |
|
575 |
|
576 // 54 Create db on drive that does not exist |
|
577 HPosLmDatabaseInfo* dbInfoUri5 = HPosLmDatabaseInfo::NewLC(KDatabaseUri5); |
|
578 TRAP(err, dbManager->CreateDatabaseL(*dbInfoUri5)); |
|
579 CleanupStack::PopAndDestroy(dbInfoUri5); |
|
580 if (err != KErrNotReady) |
|
581 { |
|
582 iLog->Log(_L("54) Wrong error when creating db on media that does not exist")); |
|
583 User::Leave(err); |
|
584 } |
|
585 verifyDbCount = count +6; |
|
586 VerifyNrOfDatabasesL(verifyDbCount); |
|
587 |
|
588 // 55 Delete db on drive that does not exist |
|
589 TRAP(err, dbManager->DeleteDatabaseL(KDatabaseUri5)); |
|
590 if (err != KErrNotReady) |
|
591 { |
|
592 iLog->Log(_L("55) Wrong error when deleting db on media that does not exist")); |
|
593 User::Leave(err); |
|
594 } |
|
595 |
|
596 _LIT(KLongFileName, "file://C:ABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRST.ldb"); |
|
597 |
|
598 // 56 Create db with long filename |
|
599 HPosLmDatabaseInfo* dbInfoLong = HPosLmDatabaseInfo::NewLC(KLongFileName); |
|
600 TRAP(err, dbManager->CreateDatabaseL(*dbInfoLong)); |
|
601 CleanupStack::PopAndDestroy(dbInfoLong); |
|
602 if (err != KErrArgument) |
|
603 { |
|
604 iLog->Log(_L("57) Wrong error when creating db with long filename")); |
|
605 User::Leave(err); |
|
606 } |
|
607 verifyDbCount = count +6; |
|
608 VerifyNrOfDatabasesL(verifyDbCount); |
|
609 |
|
610 // 57) Check that database with long filename does not exist |
|
611 if (dbManager->DatabaseExistsL(KLongFileName)) |
|
612 { |
|
613 //LogErrorAndLeave(_L("Database with long filename should not exist")); |
|
614 iLog->Log(_L("57) Database with long filename should not exist")); |
|
615 User::Leave(-1); |
|
616 } |
|
617 |
|
618 // 58) Check error ESLI-6ARN66, delete a db with strange filename |
|
619 HPosLmDatabaseInfo* dbInfoWeird = |
|
620 HPosLmDatabaseInfo::NewLC(_L("file://c:!#¤%&()=+`´^¨~'§½-_,;.{}[]$£@0123456789åäöÅÄÖ.ldb")); |
|
621 dbManager->CreateDatabaseL(*dbInfoWeird); |
|
622 CleanupStack::PopAndDestroy(dbInfoWeird); |
|
623 verifyDbCount = count +7; |
|
624 VerifyNrOfDatabasesL(verifyDbCount); |
|
625 |
|
626 CleanupStack::PopAndDestroy(dbList); |
|
627 CleanupStack::PopAndDestroy(dbManager); |
|
628 |
|
629 TRAP(err, RemoveAllLmDatabasesL()); |
|
630 if (err != KErrNone) |
|
631 { |
|
632 |
|
633 iLog->Log(_L("RemoveAllLmDatabasesL should not leave with error")); |
|
634 User::Leave(err); |
|
635 } |
|
636 |
|
637 TestDifferentUrisL(); |
|
638 |
|
639 } |
|
640 |
|
641 // --------------------------------------------------------- |
|
642 // CPosTp102::TestDifferentUrisL |
|
643 // |
|
644 // (other items were commented in a header). |
|
645 // --------------------------------------------------------- |
|
646 // |
|
647 void CPosTp102::TestDifferentUrisL() |
|
648 { |
|
649 iLog->Log(_L("TestDifferentUrisL")); |
|
650 _LIT(KDbUri1, "file://:://c:::en helt \" sjuk .ldb databas\".ldb.ldb.ldb"); |
|
651 _LIT(KDbUri2, "file://c:en helt sjuk databas.ldb"); |
|
652 _LIT(KDbUri3, "file:///c:en helt sjuk databas.ldb"); |
|
653 _LIT(KDbUri4, "file://c::en helt sjuk databas.ldb"); |
|
654 _LIT(KDbUri5, "file://c:en helt sjuk .ldb databas.ldb"); |
|
655 _LIT(KDbUri6, "file://c:en helt sjuk databas.ldb.ldb.ldb"); |
|
656 _LIT(KDbUri7, "file://c:en helt \" sjuk databas.ldb"); |
|
657 _LIT(KDbUri8, "file://c:en helt < sjuk databas.ldb"); |
|
658 _LIT(KDbUri9, "file://c:en helt > sjuk databas.ldb"); |
|
659 _LIT(KDbUri10, "file://c:en helt | sjuk databas.ldb"); |
|
660 _LIT(KDbUri11, "file://c:en helt / sjuk databas.ldb"); |
|
661 _LIT(KDbUri12, "file://c:en helt ? sjuk databas.ldb"); |
|
662 _LIT(KDbUri13, "file://c:en helt \\ sjuk databas.ldb"); |
|
663 _LIT(KDbUri14, "file://c:en helt : sjuk databas.ldb"); |
|
664 // Below tested separately in step 58) |
|
665 //_LIT(KDbUri15, "file://c:!#¤%&()=+`´^¨~'§½-_,;.{}[]$£@0123456789åäöÅÄÖ.ldb"); |
|
666 _LIT(KDbUri16, "file://c:qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM.ldb"); |
|
667 _LIT(KDbUri17, "file://en otroligt helt sjuk databas.ldb"); |
|
668 _LIT(KDbUri18, "c:en helsjuk databas.ldb"); |
|
669 _LIT(KDbUri19, "file://c:\\system\\data\\en helt sjuk databas.ldb"); |
|
670 _LIT(KDbUri20, "file://c:.ldb"); |
|
671 _LIT(KDbUri21, "file://c:filename"); |
|
672 _LIT(KDbUri22, "file://c:filename.dip"); |
|
673 _LIT(KDbUri23, "file://c:filename. ldb"); |
|
674 _LIT(KDbUri24, "file://c:*.ldb"); |
|
675 _LIT(KDbUri25, "file://allan:en helt sjuk databas.ldb"); |
|
676 _LIT(KDbUri26, "file://g:en helt sjuk databas.ldb"); |
|
677 _LIT(KDbUri27, "file://c:filename.ldb"); |
|
678 _LIT(KDbUri28, "file://c:012345678901234567890123456789012345678901234567890123456789.ldb"); |
|
679 |
|
680 const TInt KNrOfUris = 8; |
|
681 const TDesC* listOfUris[] = {&KDbUri2, &KDbUri5, &KDbUri6 |
|
682 , &KDbUri16 , &KDbUri17, &KDbUri18 |
|
683 , &KDbUri27, &KDbUri28 |
|
684 }; |
|
685 /* &KDbUri1*/ |
|
686 |
|
687 const TInt KNrOfNonWorkingUris = 19; |
|
688 const TDesC* listOfUrisNonWorking[] = {&KDbUri1, &KDbUri3 ,&KDbUri4, &KDbUri7, &KDbUri8, &KDbUri9 |
|
689 , &KDbUri10, &KDbUri11, &KDbUri12, &KDbUri13, &KDbUri14, &KDbUri19, &KDbUri20, &KDbUri21 |
|
690 , &KDbUri22, &KDbUri23, &KDbUri24, &KDbUri25, &KDbUri26}; |
|
691 |
|
692 TInt errorList[] = {KErrArgument, KErrBadName, KErrBadName, KErrBadName, KErrBadName ,KErrBadName,KErrBadName, |
|
693 KErrBadName, KErrBadName, KErrArgument, KErrBadName, KErrArgument, KErrArgument, |
|
694 KErrArgument, KErrArgument,KErrArgument, KErrBadName, KErrBadName, KErrNotReady}; |
|
695 |
|
696 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
697 CleanupStack::PushL(dbManager); |
|
698 |
|
699 RemoveAllLmDatabasesL(); |
|
700 TBuf<100> buf; |
|
701 // get the count of dbs that have notbeen deleted isnce they are in use |
|
702 CDesCArray* dbArray1 = dbManager->ListDatabasesLC(); |
|
703 TInt count = dbArray1->Count(); |
|
704 TInt verifyDbcount; |
|
705 |
|
706 for (TInt i=0;i<KNrOfUris;i++) |
|
707 { |
|
708 HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(*listOfUris[i]); |
|
709 iLog->Log(_L("Creating db:")); |
|
710 iLog->Log(*listOfUris[i]); |
|
711 TRAPD(err, dbManager->CreateDatabaseL(*dbInfo)); |
|
712 if (err != KErrNone) |
|
713 { |
|
714 buf.Format(_L("Failed with err %d"), err); |
|
715 iLog->Log(buf); |
|
716 User::Leave(err); |
|
717 } |
|
718 else |
|
719 { |
|
720 iLog->Log(_L("Db created...")); |
|
721 } |
|
722 CleanupStack::PopAndDestroy(dbInfo); |
|
723 verifyDbcount = count + i+1; |
|
724 VerifyNrOfDatabasesL(verifyDbcount); |
|
725 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
726 TInt nr = dbArray->Count(); |
|
727 |
|
728 buf.Format(_L("DB count %d"), nr); |
|
729 iLog->Log(buf); |
|
730 CleanupStack::PopAndDestroy(dbArray); |
|
731 } |
|
732 |
|
733 for (TInt i=0;i<KNrOfNonWorkingUris;i++) |
|
734 { |
|
735 HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(*listOfUrisNonWorking[i]); |
|
736 iLog->Log(_L("Trying to create db:")); |
|
737 iLog->Log(*listOfUrisNonWorking[i]); |
|
738 TRAPD(err, dbManager->CreateDatabaseL(*dbInfo)); |
|
739 if (err != errorList[i]) |
|
740 { |
|
741 buf.Format(_L("Failed with err %d should be %d"), err, errorList[i]); |
|
742 iLog->Log(buf); |
|
743 |
|
744 iLog->Log(buf); |
|
745 User::Leave(err); |
|
746 } |
|
747 CleanupStack::PopAndDestroy(dbInfo); |
|
748 verifyDbcount = count + KNrOfUris; |
|
749 VerifyNrOfDatabasesL(verifyDbcount); |
|
750 } |
|
751 |
|
752 CleanupStack::PopAndDestroy(dbArray1); |
|
753 CleanupStack::PopAndDestroy(dbManager); |
|
754 iLog->Log(_L("TestDifferentUrisL")); |
|
755 } |
|
756 |
|
757 // --------------------------------------------------------- |
|
758 // CPosTp102::VerifyNrOfDatabasesL |
|
759 // |
|
760 // (other items were commented in a header). |
|
761 // --------------------------------------------------------- |
|
762 // |
|
763 void CPosTp102::VerifyNrOfDatabasesL(TInt aExpNrOfDatabases, const TDesC& aDatabaseUri) |
|
764 { |
|
765 iLog->Log(_L("VerifyNrOfDatabasesL")); |
|
766 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
767 CleanupStack::PushL(dbManager); |
|
768 |
|
769 CDesCArray* dbArray = dbManager->ListDatabasesLC(); |
|
770 TInt nr = dbArray->Count(); |
|
771 if (nr != aExpNrOfDatabases) |
|
772 { |
|
773 CleanupStack::PopAndDestroy(dbArray); |
|
774 CleanupStack::PopAndDestroy(dbManager); |
|
775 |
|
776 TBuf<100> buf; |
|
777 buf.Format(_L("Wrong number of databases, was %d, should be %d"), nr, aExpNrOfDatabases); |
|
778 |
|
779 iLog->Log(buf); |
|
780 User::Leave(-1); |
|
781 } |
|
782 |
|
783 TBool found = EFalse; |
|
784 if (aDatabaseUri != KNullDesC) |
|
785 { |
|
786 for (TInt i=0;i<nr;i++) |
|
787 { |
|
788 iLog->Log((*dbArray)[i]); |
|
789 if ((*dbArray)[i].Compare(aDatabaseUri) == KErrNone) |
|
790 { |
|
791 found = ETrue; |
|
792 } |
|
793 } |
|
794 } |
|
795 |
|
796 CleanupStack::PopAndDestroy(dbArray); |
|
797 CleanupStack::PopAndDestroy(dbManager); |
|
798 |
|
799 if (aDatabaseUri != KNullDesC && !found) |
|
800 { |
|
801 iLog->Log(_L("Database was not found")); |
|
802 User::Leave(KErrNotFound); |
|
803 } |
|
804 } |
|
805 |
|
806 // End of File |