author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 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 "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: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
// INCLUDE FILES |
|
22 |
#include <e32svr.h> |
|
23 |
#include <StifParser.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
#include <StifTestInterface.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
25 |
#include "tlmdatabasestest.h" |
19 | 26 |
#include "landmarkservice.h" |
27 |
||
28 |
// CONSTANTS |
|
29 |
||
30 |
_LIT(KLocalProtocol, "file"); |
|
31 |
||
32 |
_LIT(KDb1, "C:eposlm1.ldb"); |
|
33 |
||
34 |
_LIT(KActiveDb1, "file://c:activelm1.ldb"); |
|
35 |
_LIT(KActiveDb2, "file://c:activelm2.ldb"); |
|
36 |
||
37 |
_LIT(KDbInvalidUri1, "file:/c:invalid.ldb"); |
|
38 |
_LIT(KDbInvalidUri2, "z:invalid.ldb"); |
|
39 |
_LIT(KDbInvalidUri3, "c:invalid"); |
|
40 |
_LIT(KDbInvalidUri4, "c:\\invalid.ldb"); |
|
41 |
_LIT(KDbInvalidUri5, "e:invalid.ldb"); |
|
42 |
||
43 |
||
44 |
_LIT(KRemoteUnsupportedDbUri, "http://remote.ldb"); |
|
45 |
||
46 |
||
47 |
// ============================ MEMBER FUNCTIONS =============================== |
|
48 |
||
49 |
||
50 |
// ----------------------------------------------------------------------------- |
|
51 |
// CTLmDbTest::RunMethodL |
|
52 |
// Run specified method. Contains also table of test mothods and their names. |
|
53 |
// ----------------------------------------------------------------------------- |
|
54 |
// |
|
55 |
TInt CTLmDbTest::RunMethodL( |
|
56 |
CStifItemParser& aItem ) |
|
57 |
{ |
|
58 |
||
59 |
static TStifFunctionInfo const KFunctions[] = |
|
60 |
{ |
|
61 |
// Copy this line for every implemented function. |
|
62 |
// First string is the function name used in TestScripter script file. |
|
63 |
// Second is the actual implementation member function. |
|
64 |
ENTRY( "AddDatabase", CTLmDbTest::AddDatabase ), |
|
65 |
ENTRY( "DeleteDatabase", CTLmDbTest::DeleteDatabase), |
|
66 |
ENTRY( "AddExistingDatabase", CTLmDbTest::AddExistingDatabase), |
|
67 |
ENTRY( "AddInvalidDatabase", CTLmDbTest::AddInvalidDatabase), |
|
68 |
ENTRY( "AddRemoteDatabase", CTLmDbTest::AddRemoteDatabase), |
|
69 |
ENTRY( "UpdateDatabase" , CTLmDbTest::UpdateDatabase), |
|
70 |
ENTRY( "SetActiveDb", CTLmDbTest::SetActiveDb ), |
|
71 |
ENTRY( "GetDbList", CTLmDbTest::GetDbList ) |
|
72 |
||
73 |
}; |
|
74 |
||
75 |
const TInt count = sizeof( KFunctions ) / |
|
76 |
sizeof( TStifFunctionInfo ); |
|
77 |
||
78 |
return RunInternalL( KFunctions, count, aItem ); |
|
79 |
||
80 |
} |
|
81 |
||
82 |
// ----------------------------------------------------------------------------- |
|
83 |
// CTLmDbTest::AddDatabase |
|
84 |
// test method function. |
|
85 |
// ----------------------------------------------------------------------------- |
|
86 |
// |
|
87 |
TInt CTLmDbTest::AddDatabase( CStifItemParser& /*aItem*/ ) |
|
88 |
{ |
|
89 |
||
90 |
_LIT( KExample, "AddDatabase" ); |
|
91 |
iLog->Log( KExample ); |
|
92 |
||
93 |
DeleteAllLocalDatabasesL(); |
|
94 |
||
95 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
96 |
CleanupStack::PushL(obj); |
|
97 |
||
98 |
TRAPD (err,obj->AddItemL (KDb1)); |
|
99 |
if (!err) |
|
100 |
{ |
|
101 |
CDesCArray* dbList = iDatabaseManager->ListDatabasesLC(KLocalProtocol); |
|
102 |
err = 1; |
|
103 |
for ( TInt i = 0; i < dbList->Count(); i++ ) |
|
104 |
{ |
|
105 |
TPtrC db = (*dbList)[i]; |
|
106 |
if ( db.Compare(KDb1) ) |
|
107 |
{ |
|
108 |
err = 0; |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
CleanupStack::PopAndDestroy(); //dblist |
|
113 |
} |
|
114 |
||
115 |
CleanupStack::PopAndDestroy(obj); |
|
116 |
||
117 |
DeleteAllLocalDatabasesL(); |
|
118 |
||
119 |
return err; |
|
120 |
} |
|
121 |
// ----------------------------------------------------------------------------- |
|
122 |
// CTLmDbTest::AddExistingDatabase |
|
123 |
// test method function. |
|
124 |
// ----------------------------------------------------------------------------- |
|
125 |
// |
|
126 |
TInt CTLmDbTest::AddExistingDatabase( CStifItemParser& /*aItem*/ ) |
|
127 |
{ |
|
128 |
||
129 |
_LIT( KExample, "AddExistingDatabase" ); |
|
130 |
iLog->Log( KExample ); |
|
131 |
||
132 |
TInt err; |
|
133 |
DeleteAllLocalDatabasesL(); |
|
134 |
||
135 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
136 |
CleanupStack::PushL(obj); |
|
137 |
||
138 |
TRAP (err,obj->AddItemL (KDb1)); |
|
139 |
if (err) |
|
140 |
{ |
|
141 |
CleanupStack::PopAndDestroy(obj); |
|
142 |
return err; |
|
143 |
} |
|
144 |
||
145 |
TRAP (err,obj->AddItemL (KDb1) ); |
|
146 |
||
147 |
CleanupStack::PopAndDestroy(obj); |
|
148 |
||
149 |
DeleteAllLocalDatabasesL(); |
|
150 |
||
151 |
return ( err != KErrAlreadyExists ); |
|
152 |
||
153 |
} |
|
154 |
// ----------------------------------------------------------------------------- |
|
155 |
// CTLmDbTest::AddExistingDatabase |
|
156 |
// test method function. |
|
157 |
// ----------------------------------------------------------------------------- |
|
158 |
// |
|
159 |
TInt CTLmDbTest::AddInvalidDatabase( CStifItemParser& /*aItem*/ ) |
|
160 |
{ |
|
161 |
||
162 |
_LIT( KExample, "AddInvalidDatabase" ); |
|
163 |
iLog->Log( KExample ); |
|
164 |
||
165 |
TInt err; |
|
166 |
DeleteAllLocalDatabasesL(); |
|
167 |
||
168 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
169 |
CleanupStack::PushL(obj); |
|
170 |
||
171 |
||
172 |
TRAP (err,obj->AddItemL (KDbInvalidUri1)); |
|
173 |
if ( !err ) |
|
174 |
{ |
|
175 |
CleanupStack::PopAndDestroy(obj); |
|
176 |
iLog->Log( _L("KDbInvalidUri1 paniced incorrect error : %d"),err ); |
|
177 |
return 1; |
|
178 |
} |
|
179 |
||
180 |
TRAP (err,obj->AddItemL (KDbInvalidUri2)); |
|
181 |
if ( err != KErrAccessDenied ) |
|
182 |
{ |
|
183 |
CleanupStack::PopAndDestroy(obj); |
|
184 |
iLog->Log( _L("KDbInvalidUri2 paniced incorrect error : %d"),err ); |
|
185 |
return err; |
|
186 |
} |
|
187 |
||
188 |
TRAP (err,obj->AddItemL (KDbInvalidUri3)); |
|
189 |
if ( err != KErrArgument ) |
|
190 |
{ |
|
191 |
CleanupStack::PopAndDestroy(obj); |
|
192 |
iLog->Log( _L("KDbInvalidUri3 paniced incorrect error : %d"),err ); |
|
193 |
return err; |
|
194 |
} |
|
195 |
TRAP (err,obj->AddItemL (KDbInvalidUri4)); |
|
196 |
if ( err != KErrArgument ) |
|
197 |
{ |
|
198 |
CleanupStack::PopAndDestroy(obj); |
|
199 |
iLog->Log( _L("KDbInvalidUri4 paniced incorrect error : %d"),err ); |
|
200 |
return err; |
|
201 |
} |
|
202 |
||
203 |
TRAP (err,obj->AddItemL (KDbInvalidUri5)); |
|
204 |
if ( err != KErrNotReady ) |
|
205 |
{ |
|
206 |
CleanupStack::PopAndDestroy(obj); |
|
207 |
iLog->Log( _L("KDbInvalidUri5 paniced incorrect error : %d"),err ); |
|
208 |
return err; |
|
209 |
} |
|
210 |
||
211 |
CleanupStack::PopAndDestroy(obj); |
|
212 |
||
213 |
DeleteAllLocalDatabasesL(); |
|
214 |
||
215 |
return 0; |
|
216 |
||
217 |
} |
|
218 |
// ----------------------------------------------------------------------------- |
|
219 |
// CTLmDbTest::AddRemoteDatabase |
|
220 |
// test method function. |
|
221 |
// ----------------------------------------------------------------------------- |
|
222 |
// |
|
223 |
TInt CTLmDbTest::AddRemoteDatabase( CStifItemParser& /*aItem*/ ) |
|
224 |
{ |
|
225 |
||
226 |
_LIT( KExample, "AddRemoteDatabase" ); |
|
227 |
iLog->Log( KExample ); |
|
228 |
||
229 |
TInt err; |
|
230 |
DeleteAllLocalDatabasesL(); |
|
231 |
||
232 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
233 |
CleanupStack::PushL(obj); |
|
234 |
||
235 |
TRAP (err,obj->AddItemL (KRemoteUnsupportedDbUri)); |
|
236 |
if ( err != KErrNotSupported ) |
|
237 |
{ |
|
238 |
CleanupStack::PopAndDestroy(obj); |
|
239 |
return err; |
|
240 |
} |
|
241 |
||
242 |
CleanupStack::PopAndDestroy(obj); |
|
243 |
||
244 |
DeleteAllLocalDatabasesL(); |
|
245 |
||
246 |
return 0; |
|
247 |
||
248 |
} |
|
249 |
// ----------------------------------------------------------------------------- |
|
250 |
// CTLmDbTest::DeleteDatabase |
|
251 |
// test method function. |
|
252 |
// ----------------------------------------------------------------------------- |
|
253 |
// |
|
254 |
TInt CTLmDbTest ::DeleteDatabase(CStifItemParser& /*aItem*/) |
|
255 |
{ |
|
256 |
_LIT( KExample, "DeleteDatabase" ); |
|
257 |
iLog->Log( KExample ); |
|
258 |
||
259 |
TInt err; |
|
260 |
DeleteAllLocalDatabasesL(); |
|
261 |
||
262 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
263 |
CleanupStack::PushL(obj); |
|
264 |
||
265 |
HPosLmDatabaseInfo* info = HPosLmDatabaseInfo::NewL(KDb1); |
|
266 |
CleanupStack::PushL(info); |
|
267 |
||
268 |
iDatabaseManager->CreateDatabaseL (*info); |
|
269 |
||
270 |
CleanupStack::PopAndDestroy(info); |
|
271 |
||
272 |
||
273 |
TRAP(err,obj->RemoveItemL (KDb1)) |
|
274 |
||
275 |
if (!err) |
|
276 |
{ |
|
277 |
TRAP(err,iDatabaseManager->DatabaseExistsL (KDb1)); |
|
278 |
} |
|
279 |
||
280 |
CleanupStack::PopAndDestroy(obj); |
|
281 |
||
282 |
DeleteAllLocalDatabasesL(); |
|
283 |
||
284 |
return err; |
|
285 |
} |
|
286 |
// ----------------------------------------------------------------------------- |
|
287 |
// CTLmDbTest::UpdateDatabase |
|
288 |
// test method function. |
|
289 |
// ----------------------------------------------------------------------------- |
|
290 |
// |
|
291 |
TInt CTLmDbTest ::UpdateDatabase(CStifItemParser& /*aItem*/) |
|
292 |
{ |
|
293 |
_LIT( KExample, "UpdateDatabase" ); |
|
294 |
iLog->Log( KExample ); |
|
295 |
||
296 |
TInt err; |
|
297 |
DeleteAllLocalDatabasesL(); |
|
298 |
||
299 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
300 |
CleanupStack::PushL(obj); |
|
301 |
||
302 |
HPosLmDatabaseInfo* info = HPosLmDatabaseInfo::NewL(KDb1); |
|
303 |
CleanupStack::PushL(info); |
|
304 |
||
305 |
iDatabaseManager->CreateDatabaseL (*info); |
|
306 |
||
307 |
CleanupStack::PopAndDestroy(info); |
|
308 |
||
309 |
TPosLmDatabaseSettings settings; |
|
310 |
TPosLmDatabaseName dbname = _L("loacal database");; |
|
311 |
settings.SetDatabaseName(dbname); |
|
312 |
||
313 |
TRAP(err,obj->UpdateItemL (settings,KDb1)) |
|
314 |
||
315 |
if (!err) |
|
316 |
{ |
|
317 |
HPosLmDatabaseInfo* info = HPosLmDatabaseInfo::NewL(KDb1); |
|
318 |
CleanupStack::PushL(info); |
|
319 |
TRAP(err,iDatabaseManager->GetDatabaseInfoL (*info)); |
|
320 |
if (!err) |
|
321 |
{ |
|
322 |
const TPosLmDatabaseSettings settings = info->Settings(); |
|
323 |
TPtrC dbname = settings.DatabaseName(); |
|
324 |
if ( !dbname.Compare( _L("loacal database") ) ) |
|
325 |
err = 0; |
|
326 |
else |
|
327 |
err = 1; |
|
328 |
||
329 |
} |
|
330 |
CleanupStack::PopAndDestroy(info); |
|
331 |
} |
|
332 |
||
333 |
CleanupStack::PopAndDestroy(obj); |
|
334 |
||
335 |
DeleteAllLocalDatabasesL(); |
|
336 |
||
337 |
return err; |
|
338 |
} |
|
339 |
// ----------------------------------------------------------------------------- |
|
340 |
// CTLmDbTest::SetActiveDb |
|
341 |
// test method function. |
|
342 |
// ----------------------------------------------------------------------------- |
|
343 |
// |
|
344 |
TInt CTLmDbTest ::SetActiveDb(CStifItemParser& /*aItem*/) |
|
345 |
{ |
|
346 |
_LIT( KExample, "UpdateDatabase" ); |
|
347 |
iLog->Log( KExample ); |
|
348 |
||
349 |
TInt err; |
|
350 |
DeleteAllLocalDatabasesL(); |
|
351 |
||
352 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
353 |
CleanupStack::PushL(obj); |
|
354 |
||
355 |
HPosLmDatabaseInfo* info = HPosLmDatabaseInfo::NewL(KActiveDb1); |
|
356 |
CleanupStack::PushL(info); |
|
357 |
||
358 |
iDatabaseManager->CreateDatabaseL (*info); |
|
359 |
||
360 |
CleanupStack::PopAndDestroy(info); |
|
361 |
||
362 |
info = HPosLmDatabaseInfo::NewL(KActiveDb2); |
|
363 |
CleanupStack::PushL(info); |
|
364 |
||
365 |
iDatabaseManager->CreateDatabaseL (*info); |
|
366 |
||
367 |
CleanupStack::PopAndDestroy(info); |
|
368 |
||
369 |
TRAP (err,obj->SetActiveL(KActiveDb1)); |
|
370 |
if ( !err ) |
|
371 |
{ |
|
372 |
HBufC* Defaultdb = iDatabaseManager->DefaultDatabaseUriLC (); |
|
373 |
if( !Defaultdb->Compare(KActiveDb1) ) |
|
374 |
err = 0; |
|
375 |
else |
|
376 |
err = 1; |
|
377 |
CleanupStack::PopAndDestroy(Defaultdb); //Defaultdb |
|
378 |
} |
|
379 |
||
380 |
if ( !err ) |
|
381 |
{ |
|
382 |
TRAP (err,obj->SetActiveL(KActiveDb2)); |
|
383 |
if ( !err ) |
|
384 |
{ |
|
385 |
HBufC* Defaultdb = iDatabaseManager->DefaultDatabaseUriLC (); |
|
386 |
if( !Defaultdb->Compare(KActiveDb2) ) |
|
387 |
err = 0; |
|
388 |
else |
|
389 |
err = 1; |
|
390 |
CleanupStack::PopAndDestroy(Defaultdb); //Defaultdb |
|
391 |
} |
|
392 |
} |
|
393 |
CleanupStack::PopAndDestroy(obj); |
|
394 |
||
395 |
DeleteAllLocalDatabasesL(); |
|
396 |
||
397 |
return err; |
|
398 |
} |
|
399 |
// ----------------------------------------------------------------------------- |
|
400 |
// CTLmDbTest::GetDbList |
|
401 |
// test method function. |
|
402 |
// ----------------------------------------------------------------------------- |
|
403 |
// |
|
404 |
TInt CTLmDbTest ::GetDbList(CStifItemParser& /*aItem*/) |
|
405 |
{ |
|
406 |
_LIT( KExample, "GetDbList" ); |
|
407 |
iLog->Log( KExample ); |
|
408 |
||
409 |
TInt err; |
|
410 |
DeleteAllLocalDatabasesL(); |
|
411 |
||
412 |
CLandmarkService *obj = CLandmarkService::NewL (); |
|
413 |
CleanupStack::PushL(obj); |
|
414 |
||
415 |
HPosLmDatabaseInfo* info = HPosLmDatabaseInfo::NewL(KActiveDb1); |
|
416 |
CleanupStack::PushL(info); |
|
417 |
||
418 |
iDatabaseManager->CreateDatabaseL (*info); |
|
419 |
iLog->Log(_L("Database created: KActiveDb1")) ; |
|
420 |
||
421 |
CleanupStack::PopAndDestroy(info); |
|
422 |
||
423 |
info = HPosLmDatabaseInfo::NewL(KActiveDb2); |
|
424 |
CleanupStack::PushL(info); |
|
425 |
||
426 |
iDatabaseManager->CreateDatabaseL (*info); |
|
427 |
||
428 |
CleanupStack::PopAndDestroy(info); |
|
429 |
iLog->Log(_L(" Database created: KActiveDb2")); |
|
430 |
||
431 |
CDesCArray* aDatabaseList; |
|
432 |
TRAP(err,obj->GetListL(aDatabaseList)); |
|
433 |
CleanupStack::PushL(aDatabaseList); |
|
434 |
iLog->Log(_L(" Count: %d"),aDatabaseList->Count() ); |
|
435 |
if ( !err ) |
|
436 |
{ |
|
437 |
for (TInt i = 0; i < aDatabaseList->Count(); i++) |
|
438 |
{ |
|
439 |
TPtrC db = (*aDatabaseList)[i] ; |
|
440 |
TBuf<30> buf; |
|
441 |
buf.Copy(db); |
|
442 |
||
443 |
buf.LowerCase(); |
|
444 |
iLog->Log(_L(" Database: %s"),db.Ptr() ); |
|
445 |
if ( buf.Compare(KActiveDb1) && buf.Compare(KActiveDb2) && buf.Compare(_L("file://c:eposlm.ldb"))) |
|
446 |
{ |
|
447 |
iLog->Log(_L(" error")); |
|
448 |
err = 1; |
|
449 |
break; |
|
450 |
} |
|
451 |
||
452 |
iLog->Log(_L(" i: %d"),i ); |
|
453 |
} |
|
454 |
} |
|
455 |
iLog->Log(_L(" Error: %d"),err ); |
|
456 |
CleanupStack::PopAndDestroy(); //aDatabaseList |
|
457 |
||
458 |
CleanupStack::PopAndDestroy(obj); |
|
459 |
||
460 |
DeleteAllLocalDatabasesL(); |
|
461 |
||
462 |
return err; |
|
463 |
} |
|
464 |
||
465 |
// ----------------------------------------------------------------------------- |
|
466 |
// CTLmDbTest::DeleteAllDatabases |
|
467 |
// removes all local databases from the terminal |
|
468 |
// called by all testcases. |
|
469 |
// ----------------------------------------------------------------------------- |
|
470 |
// |
|
471 |
void CTLmDbTest::DeleteAllLocalDatabasesL() |
|
472 |
{ |
|
473 |
TInt count; |
|
474 |
||
475 |
CDesCArray* dbList = iDatabaseManager->ListDatabasesLC(KLocalProtocol); |
|
476 |
count = dbList->Count(); |
|
477 |
||
478 |
for ( TInt i = 0; i < count; i++ ) |
|
479 |
{ |
|
480 |
TPtrC db = (*dbList)[i]; |
|
481 |
iDatabaseManager->DeleteDatabaseL ( db ); |
|
482 |
} |
|
483 |
CleanupStack::PopAndDestroy (1); |
|
484 |
||
485 |
} |