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 - Backup&Restore SID test.
15 // The test assume that drive C is presented in the system and is not a ROM drive.
16 // Please, ensure that t_predbsc test is executed before T_DBMSBackupSID test!
17 // Please, ensure that t_postdbsc test is executed after T_DBMSBackupSID test!
25 RTest TheTest(_L("t_dbbackupsid"));
28 ///////////////////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////////////////////
30 //Test macros and functions
31 static void Check(TInt aValue, TInt aLine)
35 TheTest(EFalse, aLine);
38 static void Check(TInt aValue, TInt aExpected, TInt aLine)
40 if(aValue != aExpected)
42 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
43 TheTest(EFalse, aLine);
46 #define TEST(arg) Check((arg), __LINE__)
47 #define TEST2(aValue, aExpected) Check(aValue, aExpected, __LINE__)
49 ///////////////////////////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////////////////////////
53 @SYMTestCaseID SYSLIB-DBMS-CT-0036
54 @SYMTestCaseDesc Backup&restore Secure ID test.
55 This function tests RDbs::GetBackupPath() with different sets of input
56 parameters: invalid and valid.
58 @SYMTestActions RDbs::GetBackupPath() test.
59 @SYMTestExpectedResults The test must not fail.
62 static void TestBackupSID()
64 TBuf<KMaxPath> backupPath;
66 TSecureId backupSID = 0;
67 TUid dbUid = {0x1133557A};
68 _LIT(KDbName, "C:abcd.db");
69 TheTest.Printf(_L("--Invalid backup SID: 0\n"));
70 TInt err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
71 TEST2(err, KErrArgument);
72 backupSID = (TUint32)ECapability_None;
73 TheTest.Printf(_L("--Invalid backup SID: ECapability_None\n"));
74 err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
75 TEST2(err, KErrArgument);
77 backupSID = 0x30003000;
78 dbUid.iUid = 0xFB34010F;
79 TheTest.Printf(_L("--Invalid UID: no security policy for it\n"));
80 err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
81 TEST2(err, KErrNotFound);
83 TheTest.Printf(_L("--Invalid UID: 0\n"));
84 err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
85 TEST2(err, KErrArgument);
86 //Invalid database name
87 dbUid.iUid = 0x1133557A;
88 TheTest.Printf(_L("--Null database name\n"));
89 err = TheDbs.GetBackupPath(backupSID, KNullDesC, dbUid, backupPath);
90 TEST2(err, KErrArgument);
91 TheTest.Printf(_L("--Database name: no drive\n"));
92 _LIT(KDbName2, "abcd.db");
93 err = TheDbs.GetBackupPath(backupSID, KDbName2, dbUid, backupPath);
94 TEST2(err, KErrArgument);
96 TheTest.Printf(_L("--Valid GetBackupPath() arguments\n"));
97 err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
99 TheTest.Printf(_L("--Path: %S\n"), &backupPath);
100 _LIT(KExpectedPath, "C:\\PRIVATE\\100012A5\\DBS_1133557A_ABCD.DB");
101 TEST(backupPath.CompareF(KExpectedPath) == 0);
102 //Valid arguments, but old format security policy file (without "backup" section)
103 TSecureId backupSID3 = 1;
104 TUid dbUid3 = {0x11335578};
105 _LIT(KDbName3, "C:Z.db");
106 TheTest.Printf(_L("--Valid GetBackupPath() arguments, old format file\n"));
107 err = TheDbs.GetBackupPath(backupSID3, KDbName3, dbUid3, backupPath);
108 TEST2(err, KErrPermissionDenied);
111 //DEF063053 Additional method required on RDbs API for Secure Backup
112 static void DEF063053L()
115 TheTest.Printf(_L("--Invalid backup SID: 0\n"));
116 TSecureId backupSID = 0;
117 TUid dbUid = {0x1133557A};
118 CDbStrings* paths = NULL;
119 TRAPD(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
120 TEST2(err, KErrArgument);
123 TheTest.Printf(_L("--Invalid backup SID: ECapability_None\n"));
124 backupSID = (TUint32)ECapability_None;
125 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
126 TEST2(err, KErrArgument);
129 TheTest.Printf(_L("--Invalid backup SID: not matching the SID in security policy\n"));
130 backupSID = (TUint32)0x109345FF;
131 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
132 TEST2(err, KErrPermissionDenied);
136 TheTest.Printf(_L("--Invalid UID: no security policy for it\n"));
137 backupSID = 0x30003000;
138 dbUid.iUid = 0xFB34010F;
139 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
140 TEST2(err, KErrArgument);
143 TheTest.Printf(_L("--Invalid UID: 0\n"));
145 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
146 TEST2(err, KErrArgument);
150 TheTest.Printf(_L("--Valid BackupPathL() arguments\n"));
151 backupSID = 0x30003000;
152 dbUid.iUid = 0x1133557A;
153 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
154 TEST2(err, KErrNone);
156 for(TInt i=0;i<paths->Count();++i)
158 const TDesC& dd = (*paths)[i];
159 RDebug::Print(_L(" Database %d: %S\r\n"), i + 1, &dd);
164 //Valid arguments, but no databases having the supplied security policy UID.
165 TheTest.Printf(_L("--Valid BackupPathL() arguments, no databases\n"));
166 backupSID = 0x30003001;
167 dbUid.iUid = 0x11335577;
168 TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
169 TEST2(err, KErrNone);
171 TEST(paths->Count() == 0);
177 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0036 Backup&restore SID "));
180 TheTest.Next(_L("DEF063053 Additional method required on RDbs API for Secure Backup"));
187 CTrapCleanup* tc = CTrapCleanup::New();
192 TInt err = TheDbs.Connect();
193 TEST2(err, KErrNone);
195 TRAP(err, ::DoRunL());
196 TEST2(err, KErrNone);
206 User::Heap().Check();