Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // DBMS security policy - testing new APIs
15 // All tests assume that drive C is presented in the system and is not a ROM drive.
16 // Please, ensure that t_dbenvcreate test is executed before t_dbplatsec<N>/t_dbplatsecperf tests!
17 // Please, ensure that t_dbenvdestroy test is executed after t_dbplatsec<N>/t_dbplatsecperf tests!
23 #include "t_dbplatsecdef.h"
24 #include "t_dbplatsecutl.h"
25 #include "t_dbplatsecdb.h"
26 #include "t_dbplatsectbl.h"
29 RTest TheTest(_L("t_dbplatsec : DBMS platform security testing"));
31 RDbNamedDatabase TheDb1;
32 RDbNamedDatabase TheDb2;
36 void DeleteDatabases();
37 TDBSCUtils TheDbscUtils(TheTest, &DeleteDatabases);
39 void DeleteDatabases()
45 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
46 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
47 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
50 static void GetDatabaseRPolicyTest()
52 TSecurityPolicy policy;
53 TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EReadPolicy, policy);
55 TCompiledSecurityPolicy testSecurityPolicy(policy);
56 TSecurityPolicy::TType type = testSecurityPolicy.Type();
57 TEST(type == TSecurityPolicy::ETypeC3);
58 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityCommDD));
59 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityPowerMgmt));
60 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityTrustedUI));
63 static void GetDatabaseWPolicyTest()
65 TSecurityPolicy policy;
66 TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EWritePolicy, policy);
68 TCompiledSecurityPolicy testSecurityPolicy(policy);
69 TSecurityPolicy::TType type = testSecurityPolicy.Type();
70 TEST(type == TSecurityPolicy::ETypeC3);
71 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityMultimediaDD));
72 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityReadDeviceData));
73 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, static_cast <TCapability> (TUint8(ECapability_None))));
76 static void GetDatabaseSPolicyTest()
78 TSecurityPolicy policy;
79 TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::ESchemaPolicy, policy);
81 TCompiledSecurityPolicy testSecurityPolicy(policy);
82 TSecurityPolicy::TType type = testSecurityPolicy.Type();
83 TEST(type == TSecurityPolicy::ETypeC7);
84 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityWriteDeviceData));
85 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityDRM));
86 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityProtServ));
87 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityDiskAdmin));
88 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityNetworkControl));
89 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityWriteUserData));
90 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilitySwEvent));
93 static void GetTablePolicyTest(const TDesC& aTableName,
94 RDbs::TPolicyType aPolicyType,
95 TSecurityPolicy::TType aType,
98 const TCapability* aCapabilities, TInt aCapCount)
100 TSecurityPolicy policy;
101 TInt err = TheDbs.GetTablePolicy(KSecureDbUid, aTableName, aPolicyType, policy);
102 TEST2(err, KErrNone);
103 TCompiledSecurityPolicy testSecurityPolicy(policy);
104 TEST(testSecurityPolicy.Type() == aType);
105 for(TInt i=0;i<aCapCount;++i)
107 TEST(TDBSCUtils::HasCapability(testSecurityPolicy, aCapabilities[i]));
109 if(testSecurityPolicy.Type() == TSecurityPolicy::ETypeS3)
111 TEST(testSecurityPolicy.SecureId() == aSecureId);
113 else if(testSecurityPolicy.Type() == TSecurityPolicy::ETypeV3)
115 TEST(testSecurityPolicy.VendorId() == aVendorId);
119 //Tests RDbs::GetDatabasePolicy()/RDbs::GetTablePolicy() with invalid arguments
120 static void InvalidPolicyArgTestsL()
122 TheTest.Printf(_L("--Invalid UID\n"));
123 const TUid KInvalidUid = {0x490122};
124 TSecurityPolicy policy;
125 TInt err = TheDbs.GetDatabasePolicy(KInvalidUid, RDbs::EWritePolicy, policy);
126 TEST2(err, KErrArgument);
127 err = TheDbs.GetDatabasePolicy(KNullUid, RDbs::EWritePolicy, policy);
128 TEST2(err, KErrArgument);
129 err = TheDbs.GetTablePolicy(KInvalidUid, KTableName1, RDbs::EWritePolicy, policy);
130 TEST2(err, KErrArgument);
131 err = TheDbs.GetTablePolicy(KNullUid, KTableName1, RDbs::EWritePolicy, policy);
132 TEST2(err, KErrArgument);
134 TheTest.Printf(_L("--Invalid policy type\n"));
135 err = TheDbs.GetDatabasePolicy(KSecureDbUid, static_cast <RDbs::TPolicyType> (100), policy);
136 TEST2(err, KErrArgument);
137 err = TheDbs.GetTablePolicy(KSecureDbUid, KTableName2, static_cast <RDbs::TPolicyType> (101), policy);
138 TEST2(err, KErrArgument);
140 TheTest.Printf(_L("--Table name, which is not in the policy file\n"));
141 _LIT(KMissingTableName, "AAAAAA");
142 err = TheDbs.GetTablePolicy(KSecureDbUid, KMissingTableName, RDbs::EWritePolicy, policy);
143 TEST2(err, KErrNone);//This must be the related database policy
144 TSecurityPolicy dbPolicy;
145 err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EWritePolicy, dbPolicy);
146 TEST2(err, KErrNone);
147 TCompiledSecurityPolicy sp1(policy);
148 TCompiledSecurityPolicy sp2(dbPolicy);
151 TheTest.Printf(_L("--Table name - zero length\n"));
152 _LIT(KInvTableName, "");
153 err = TheDbs.GetTablePolicy(KSecureDbUid, KInvTableName, RDbs::EWritePolicy, policy);
154 TEST2(err, KErrArgument);
156 TheTest.Printf(_L("--Table name - Schema policy request\n"));
157 err = TheDbs.GetTablePolicy(KSecureDbUid, KTableName3, RDbs::ESchemaPolicy, policy);
158 TEST2(err, KErrNotSupported);
161 //Returns a valid drive number, but not presented in the system
162 static TDriveNumber FirstNotPresentedDriveNumber()
165 TEST2(fs.Connect(), KErrNone);
166 TDriveNumber drvNumber = static_cast <TDriveNumber> (1000);
167 for(TInt i=EDriveA;i<=EDriveZ;++i)
169 TDriveInfo driveInfo;
170 if(fs.Drive(driveInfo, static_cast <TDriveNumber> (i)) == KErrNone)
172 if(driveInfo.iType == EMediaNotPresent)
174 drvNumber = static_cast <TDriveNumber> (i);
180 TEST(drvNumber <= EDriveZ);
184 //Returns the first valid ROM drive number.
185 static TDriveNumber FirstROMDriveNumber()
188 TEST2(fs.Connect(), KErrNone);
189 TDriveNumber drvNumber = static_cast <TDriveNumber> (1000);
190 for(TInt i=EDriveA;i<=EDriveZ;++i)
192 TDriveInfo driveInfo;
193 if(fs.Drive(driveInfo, static_cast <TDriveNumber> (i)) == KErrNone)
195 if(driveInfo.iDriveAtt & KDriveAttRom)
197 drvNumber = static_cast <TDriveNumber> (i);
203 TEST(drvNumber <= EDriveZ);
207 //Tests RDbs::DatabaseNamesL() with invalid arguments
208 static void InvalidPolicyArgTests2L()
210 CDbDatabaseNames* dbNames = NULL;
212 TheTest.Printf(_L("--Invalid UID\n"));
213 const TUid KInvalidUid = {0x490122};
214 TRAPD(err, dbNames = TheDbs.DatabaseNamesL(EDriveC, KInvalidUid));
215 TEST2(err, KErrArgument);
216 TEST(dbNames == NULL);
218 TheTest.Printf(_L("--Null UID\n"));
219 TRAP(err, dbNames = TheDbs.DatabaseNamesL(EDriveC, KNullUid));
220 TEST2(err, KErrArgument);
221 TEST(dbNames == NULL);
223 TheTest.Printf(_L("--Invalid drive\n"));
224 TRAP(err, dbNames = TheDbs.DatabaseNamesL(static_cast <TDriveNumber> (-1), KSecureDbUid));
225 TEST2(err, KErrBadName);
226 TEST(dbNames == NULL);
227 TRAP(err, TheDbs.DatabaseNamesL(static_cast <TDriveNumber> (1765), KSecureDbUid));
228 TEST2(err, KErrBadName);
229 TEST(dbNames == NULL);
231 TheTest.Printf(_L("--Valid drive number, but not presented in the system\n"));
232 TDriveNumber driveNumber = ::FirstNotPresentedDriveNumber();
233 TRAP(err, dbNames = TheDbs.DatabaseNamesL(driveNumber, KSecureDbUid));
234 TEST2(err, KErrNotReady);
235 TEST(dbNames == NULL);
239 @SYMTestCaseID SYSLIB-DBMS-CT-0003
240 @SYMTestCaseDesc Test RDbs::GetDatabasePolicy(), RDbs::GetTablePolicy()
241 getting database or table security policies.
242 @SYMTestPriority High
243 @SYMTestActions A call with valid arguments and result check.
244 A call with an invalid UID.
245 A call with an invalid security policy type.
246 A call with a table name, not presented in the policy file.
247 A call requesting schema security policy of a table.
248 @SYMTestExpectedResults The test must not fail.
250 DBMS shall provide an API to apply security policies to database tables.
252 static void GetPolicyTestL()
254 TheTest.Printf(_L("--Simple GetDatabasePolicy() tests\n"));
255 ::GetDatabaseRPolicyTest();
256 ::GetDatabaseWPolicyTest();
257 ::GetDatabaseSPolicyTest();
259 ::InvalidPolicyArgTestsL();
261 TheTest.Printf(_L("--Simple GetTablePolicy() tests\n"));
262 TCapability caps1[] = {ECapabilityCommDD, ECapabilityPowerMgmt, ECapabilityTrustedUI};
263 TCapability caps2[] = {ECapabilityMultimediaDD, ECapabilityReadDeviceData};
264 ::GetTablePolicyTest(KTableName1, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps1, 3);
265 ::GetTablePolicyTest(KTableName1, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
267 TCapability caps3[] = {static_cast <TCapability> (TUint8(ECapability_None))};
268 ::GetTablePolicyTest(KTableName2, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps3, 1);
269 ::GetTablePolicyTest(KTableName2, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
271 TCapability caps4[] = {ECapabilityReadUserData};
272 ::GetTablePolicyTest(KTableName3, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps1, 3);
273 ::GetTablePolicyTest(KTableName3, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps4, 1);
275 TCapability caps5[] = {ECapabilityWriteUserData};
276 ::GetTablePolicyTest(KTableName4, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps5, 1);
277 ::GetTablePolicyTest(KTableName4, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
281 @SYMTestCaseID SYSLIB-DBMS-CT-0004
282 @SYMTestCaseDesc Test RDbs::DatabaseNamesL(TDriveNumber, const TDesC&, TUid) -
283 getting a list of secure shared databases.
284 @SYMTestPriority High
285 @SYMTestActions A call with valid arguments and result check
286 A call with an invalid drive number.
287 A call with a valid, but not presented in the system, drive number.
288 A call with an invalid UID.
289 @SYMTestExpectedResults The test must not fail.
291 DBMS shall provide an API to apply security policies to database tables.
293 static void GetDatabaseListTestL()
295 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
296 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
298 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
301 TheDb2 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb2Name);
305 dbName.Copy(KDb1Name().Mid(KDatabaseNamePos));
306 TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
307 dbName.Copy(KDb2Name().Mid(KDatabaseNamePos));
308 TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
310 TheTest.Printf(_L("--An attempt to retrieve the list of database names for an UID, which security policy cannot be satisfied by the current test application\n"));
311 CDbDatabaseNames* dbNames = NULL;
312 TRAPD(err, dbNames = TheDbs.DatabaseNamesL(EDriveZ, KSecureDbUid2));
314 TEST2(err, KErrNone);
316 ::InvalidPolicyArgTests2L();
320 @SYMTestCaseID SYSLIB-DBMS-CT-0005
321 @SYMTestCaseDesc Test RDbs::CopyDatabase(const TDesC&, const TDesC&, TUid) -
322 copying secure shared database .
323 @SYMTestPriority High
324 @SYMTestActions A call with valid arguments and result check
325 A call with an invalid source database name.
326 A call with an invalid target database name.
327 A call with an invalid UID.
328 An attempt to copy an opened database.
329 An attempt to copy a database, which security policy cannot be satisfied.
330 An attempt to copy a database with path specified in the database name.
331 An attempt to copy non-existing database.
332 @SYMTestExpectedResults The test must not fail.
334 DBMS shall provide an API to apply security policies to database tables.
336 static void CopyDatabaseTestL()
338 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
339 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
342 TheTest.Printf(_L("--Simple copy test\n"));
343 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
344 TInt err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KSecureDbUid);
345 TEST2(err, KErrNone);
347 dbName.Copy(KDb3Name().Mid(KDatabaseNamePos));
348 TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
349 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
351 TheTest.Printf(_L("--An attempt to copy a source database, which security policy cannot be satisfied by the current test application\n"));
352 err = TheDbs.CopyDatabase(KProtDb1ZName, KDb3Name, KSecureDbUid2);
353 TEST2(err, KErrPermissionDenied);
355 TheTest.Printf(_L("--Null source database name\n"));
356 err = TheDbs.CopyDatabase(KNullDesC, KDb3Name, KSecureDbUid);
357 TEST2(err, KErrArgument);
358 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
360 TheTest.Printf(_L("--Source database name with not presented drive number\n"));
361 TDriveNumber driveNumber = ::FirstNotPresentedDriveNumber();
363 TEST2(RFs::DriveToChar(driveNumber, driveChar), KErrNone);
364 TBuf<KDatabaseNamePos> drvBuf;
365 drvBuf.Append(driveChar);
368 dbName.Append(KDb1Name().Mid(KDatabaseNamePos));
369 err = TheDbs.CopyDatabase(dbName, KDb3Name, KSecureDbUid);
370 TEST2(err, KErrNotReady);
372 TheTest.Printf(_L("--Source database name - only with a drive letter and \":\"\n"));
373 err = TheDbs.CopyDatabase(drvBuf, KDb3Name, KSecureDbUid);
374 TEST2(err, KErrNotReady);
376 TheTest.Printf(_L("--Source database name - only with a drive letter\n"));
378 err = TheDbs.CopyDatabase(drvBuf, KDb3Name, KSecureDbUid);
379 TEST2(err, KErrArgument);
381 TheTest.Printf(_L("--Null destination database name\n"));
382 err = TheDbs.CopyDatabase(KDb1Name, KNullDesC, KSecureDbUid);
383 TEST2(err, KErrArgument);
385 TheTest.Printf(_L("--Destination database name with not presented drive number\n"));
388 dbName.Append(KDb3Name().Mid(KDatabaseNamePos));
389 err = TheDbs.CopyDatabase(KDb1Name, dbName, KSecureDbUid);
390 TEST2(err, KErrNotReady);
392 TheTest.Printf(_L("--Destination database - ROM drive\n"));
393 TDriveNumber romDriveNumber = ::FirstROMDriveNumber();
394 TEST2(RFs::DriveToChar(romDriveNumber, driveChar), KErrNone);
395 drvBuf[0] = static_cast <TText> (driveChar);
397 dbName.Append(KDb3Name().Mid(KDatabaseNamePos));
398 err = TheDbs.CopyDatabase(KDb1Name, dbName, KSecureDbUid);
399 TEST2(err, KErrAccessDenied);
401 TheTest.Printf(_L("--A source database with a valid name, but not presented in the system\n"));
402 _LIT(KMissingDb, "C:asdhasfsudfygusdfuierfb.db");
403 err = TheDbs.CopyDatabase(KMissingDb, KDb3Name, KSecureDbUid);
404 TEST2(err, KErrNotFound);
406 TheTest.Printf(_L("--A test with an open source database\n"));
407 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
408 TheDb2 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
409 err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KSecureDbUid);
411 TEST2(err, KErrInUse);
413 TheTest.Printf(_L("--An atempt to copy over an existing database\n"));
414 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
415 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb2Name);
417 err = TheDbs.CopyDatabase(KDb1Name, KDb2Name, KSecureDbUid);
418 TEST2(err, KErrAlreadyExists);
420 TheTest.Printf(_L("--Too long destination database name > KDbMaxName symbols\n"));
421 _LIT(KTooLongDbName, "A_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789.db");
422 err = TheDbs.CopyDatabase(KDb1Name, KTooLongDbName, KSecureDbUid);
423 TEST2(err, KErrArgument);
425 TheTest.Printf(_L("--Null UID\n"));
426 err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KNullUid);
427 TEST2(err, KErrArgument);
429 TheTest.Printf(_L("--Invalid UID\n"));
430 const TUid KInvalidUid = {0x490122};
431 err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KInvalidUid);
432 TEST2(err, KErrArgument);
434 TheTest.Printf(_L("--An attempt to copy a database with the path specified in the name\n"));
435 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
436 _LIT(KSrcDbName2, "C:\\a.Db");
437 _LIT(KDestDbName2, "C:\\b.dB");
438 err = TheDbs.CopyDatabase(KSrcDbName2, KDestDbName2, KSecureDbUid);
439 TEST2(err, KErrArgument);
443 @SYMTestCaseID SYSLIB-DBMS-CT-0006
444 @SYMTestCaseDesc Test RDbs::Delete(const TDesC&, TUid) - deleting secure shared database .
445 @SYMTestPriority High
446 @SYMTestActions A call with valid arguments and result check
447 A call with an invalid UID.
448 A call with an invalid database name.
449 An attempt to delete an opened database.
450 An attempt to delete a database, which security policy cannot be satisfied.
451 An attempt to delete a database with path specified in the database name.
452 An attempt to delete non-existing database.
453 @SYMTestExpectedResults The test must not fail.
455 DBMS shall provide an API to apply security policies to database tables.
457 static void DeleteDatabaseTestL()
459 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
460 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
463 TheTest.Printf(_L("--Simple delete database test\n"));
464 TInt err = TheDbs.DeleteDatabase(KDb1Name, KSecureDbUid);
465 TEST2(err, KErrNone);
467 TheTest.Printf(_L("--Null UID\n"));
468 err = TheDbs.DeleteDatabase(KDb1Name, KNullUid);
469 TEST2(err, KErrArgument);
471 TheTest.Printf(_L("--Invalid UID\n"));
472 const TUid KInvalidUid = {0x490122};
473 err = TheDbs.DeleteDatabase(KDb1Name, KInvalidUid);
474 TEST2(err, KErrArgument);
476 TheTest.Printf(_L("--Null database name\n"));
477 err = TheDbs.DeleteDatabase(KNullDesC, KSecureDbUid);
478 TEST2(err, KErrArgument);
480 TheTest.Printf(_L("--Non-existing database - no drive letter (the name is invalid)\n"));
481 _LIT(KTooLongDbName, "A_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789.db");
482 err = TheDbs.DeleteDatabase(KTooLongDbName, KSecureDbUid);
483 TEST2(err, KErrArgument);
484 _LIT(KInvDbName1, "UI789.db");
485 err = TheDbs.DeleteDatabase(KInvDbName1, KSecureDbUid);
486 TEST2(err, KErrArgument);
488 TheTest.Printf(_L("--Non-existing database - valid db name\n"));
489 _LIT(KMissingDbName1, "C:A0192345.db");
490 err = TheDbs.DeleteDatabase(KMissingDbName1, KSecureDbUid);
491 TEST2(err, KErrNotFound);
493 TheTest.Printf(_L("--An attempt to delete a database with the path specified in the name\n"));
494 _LIT(KMissingDbName2, "C:\\TEMP\\A0192345.db");
495 err = TheDbs.DeleteDatabase(KMissingDbName2, KSecureDbUid);
496 TEST2(err, KErrArgument);
498 TheTest.Printf(_L("--An attempt to delete a database, which security policy cannot be satisfied by the current test application\n"));
499 err = TheDbs.DeleteDatabase(KProtDb1CName, KSecureDbUid2);
500 TEST2(err, KErrPermissionDenied);
502 TheTest.Printf(_L("--An attempt to delete an open database\n"));
503 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
504 TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
505 err = TheDbs.DeleteDatabase(KDb1Name, KSecureDbUid);
506 TEST2(err, KErrInUse);
511 @SYMTestCaseID SYSLIB-DBMS-CT-0007
512 @SYMTestCaseDesc Test RDbNamedDatabase::Create(RDbs&, const TDesC&, const TDesC&) -
513 secure shared database creation.
514 @SYMTestPriority High
515 @SYMTestActions A call with valid arguments and result check
516 An attempt to create already existing database.
517 An attempt to create already existing and opened database.
518 RDbNamedDatabase::Create() called with an invalid format string.
519 RDbNamedDatabase::Create() called with a database name containing '\' symbols.
520 An attempt to create a database, which security policy cannot be satisfied.
521 @SYMTestExpectedResults The test must not fail.
523 DBMS shall provide an API to apply security policies to database tables.
525 static void CreateDatabaseL()
527 TheTest.Printf(_L("--Simple create database test\n"));
528 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
530 format.Copy(KSecure);
531 format.Append(KSecureDbUid.Name());
532 TInt err = TheDb1.Create(TheDbs, KDb1Name, format);
533 TEST2(err, KErrNone);
535 TheTest.Printf(_L("--An atempt to recreate an open database\n"));
536 err = TheDb1.Create(TheDbs, KDb1Name, format);
537 TEST2(err, KErrAlreadyExists);
540 TheTest.Printf(_L("--An atempt to recreate an existing database\n"));
541 err = TheDb1.Create(TheDbs, KDb1Name, format);
542 TEST2(err, KErrAlreadyExists);
544 TheTest.Printf(_L("--Format string with \"SECURE\" keyword and some other words too\n"));
545 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
546 format.Copy(_L("A "));
547 format.Append(KSecure);
548 format.Append(_L(" B"));
549 format.Append(KSecureDbUid.Name());
550 err = TheDb1.Create(TheDbs, KDb1Name, format);
552 TEST2(err, KErrNotSupported);
554 TheTest.Printf(_L("--Format string with \"SeCuRe\" keyword\n"));
555 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
556 format.Copy(_L("SeCuRe"));
557 format.Append(KSecureDbUid.Name());
558 err = TheDb1.Create(TheDbs, KDb1Name, format);
560 TEST2(err, KErrNone);
562 TheTest.Printf(_L("--Format string with \"SECURED\" keyword\n"));
563 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
564 format.Copy(_L("SECURED"));
565 format.Append(KSecureDbUid.Name());
566 err = TheDb1.Create(TheDbs, KDb1Name, format);
568 TEST2(err, KErrNotSupported);
570 TheTest.Printf(_L("--Format string with a null uid\n"));
571 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
572 format.Copy(_L("SECURE"));
573 format.Append(KNullUid.Name());
574 err = TheDb1.Create(TheDbs, KDb1Name, format);
576 TEST2(err, KErrArgument);
578 TheTest.Printf(_L("--Format string with an invalid uid\n"));
579 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
580 format.Copy(_L("SECURE"));
581 const TUid KInvalidUid = {0x490122};
582 format.Append(KInvalidUid.Name());
583 err = TheDb1.Create(TheDbs, KDb1Name, format);
585 TEST2(err, KErrArgument);
587 TheTest.Printf(_L("--Format string with a uid only\n"));
588 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
589 format.Copy(KSecureDbUid.Name());
590 err = TheDb1.Create(TheDbs, KDb1Name, format);
592 TEST2(err, KErrNotSupported);
594 TheTest.Printf(_L("--Blank format string\n"));
595 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
597 err = TheDb1.Create(TheDbs, KDb1Name, format);
599 TEST2(err, KErrNotSupported);
601 TheTest.Printf(_L("--Valid format string + database name with a path\n"));
602 TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
603 format.Copy(KSecure);
604 format.Append(KSecureDbUid.Name());
605 _LIT(KSrcDbName2, "C:\\a.Db");
606 err = TheDb1.Create(TheDbs, KSrcDbName2, format);
608 TEST2(err, KErrArgument);
610 TheTest.Printf(_L("--An attempt to create a database, which security policy cannot be satisfied by the current test application\n"));
611 format.Copy(KSecure);
612 format.Append(KSecureDbUid2.Name());
613 err = TheDb1.Create(TheDbs, KProtDb2CName, format);
615 TEST2(err, KErrPermissionDenied);
618 static void INC057327L()
620 TRAPD(err,delete TheDbs.DatabaseNamesL(EDriveZ, TUid::Uid(0x12344321)));
621 TheTest(err == KErrNone);
626 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0003 Get database/table policies "));
629 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0004 Get databases list "));
630 ::GetDatabaseListTestL();
632 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0005 Copy database "));
633 ::CopyDatabaseTestL();
635 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0006 Delete database "));
636 ::DeleteDatabaseTestL();
638 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0007 Create database "));
641 TheTest.Next(_L("Database security"));
644 TheTest.Next(_L("Table security"));
647 TheTest.Next(_L("Test for INC057327"));
654 CTrapCleanup* tc = CTrapCleanup::New();
657 TInt err = TheDbs.Connect();
658 TEST2(err, KErrNone);
660 TRAP(err, ::DoRunL());
661 TEST2(err, KErrNone);
672 User::Heap().Check();