os/persistentdata/persistentstorage/dbms/tdbms/t_dbbackupsid.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    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!
    18 // 
    19 //
    20 
    21 #include <d32dbms.h>
    22 #include <e32test.h>
    23 
    24 //Global definitions
    25 RTest 				TheTest(_L("t_dbbackupsid"));
    26 RDbs 				TheDbs;
    27 
    28 ///////////////////////////////////////////////////////////////////////////////////////
    29 ///////////////////////////////////////////////////////////////////////////////////////
    30 //Test macros and functions
    31 static void Check(TInt aValue, TInt aLine)
    32 	{
    33 	if(!aValue)
    34 		{
    35 		TheTest(EFalse, aLine);
    36 		}
    37 	}
    38 static void Check(TInt aValue, TInt aExpected, TInt aLine)
    39 	{
    40 	if(aValue != aExpected)
    41 		{
    42 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    43 		TheTest(EFalse, aLine);
    44 		}
    45 	}
    46 #define TEST(arg) 					Check((arg), __LINE__)
    47 #define TEST2(aValue, aExpected) 	Check(aValue, aExpected, __LINE__)
    48 
    49 ///////////////////////////////////////////////////////////////////////////////////////
    50 ///////////////////////////////////////////////////////////////////////////////////////
    51 
    52 /**
    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.
    57 @SYMTestPriority High
    58 @SYMTestActions  RDbs::GetBackupPath() test.
    59 @SYMTestExpectedResults The test must not fail.
    60 @SYMPREQ PREQ277
    61 */
    62 static void TestBackupSID()
    63 	{
    64 	TBuf<KMaxPath> backupPath;
    65 	//Invalid SID
    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);
    76 	//Invalid UID
    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);
    82 	dbUid.iUid = 0;
    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);
    95 	//Valid arguments
    96 	TheTest.Printf(_L("--Valid GetBackupPath() arguments\n"));
    97 	err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
    98 	TEST2(err, KErrNone);
    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);
   109 	}
   110 
   111 //DEF063053  Additional method required on RDbs API for Secure Backup
   112 static void DEF063053L()
   113 	{
   114 	//Invalid SID
   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);
   121 	TEST(!paths);
   122 
   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);
   127 	TEST(!paths);
   128 
   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);
   133 	TEST(!paths);
   134 
   135 	//Invalid UID
   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);
   141 	TEST(!paths);
   142 
   143 	TheTest.Printf(_L("--Invalid UID: 0\n"));
   144 	dbUid.iUid = 0;
   145 	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
   146 	TEST2(err, KErrArgument);
   147 	TEST(!paths);
   148 
   149 	//Valid arguments
   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);
   155 	TEST(paths != NULL);
   156 	for(TInt i=0;i<paths->Count();++i)
   157 		{
   158 		const TDesC& dd = (*paths)[i];
   159 		RDebug::Print(_L("  Database %d: %S\r\n"), i + 1, &dd);
   160 		}
   161 	delete paths;
   162 	paths = NULL;
   163 
   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);
   170 	TEST(paths != NULL);
   171 	TEST(paths->Count() == 0);
   172 	delete paths;
   173 	}
   174 
   175 static void DoRunL()
   176 	{
   177 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0036 Backup&restore SID "));
   178 	::TestBackupSID();
   179 
   180 	TheTest.Next(_L("DEF063053 Additional method required on RDbs API for Secure Backup"));
   181 	::DEF063053L();
   182 	}
   183 
   184 TInt E32Main()
   185     {
   186 	__UHEAP_MARK;
   187 	CTrapCleanup* tc = CTrapCleanup::New();
   188 	TEST(tc != NULL);
   189 
   190 	TheTest.Title();
   191 
   192 	TInt err = TheDbs.Connect();
   193 	TEST2(err, KErrNone);
   194 
   195 	TRAP(err, ::DoRunL());
   196 	TEST2(err, KErrNone);
   197 
   198 	TheDbs.Close();
   199 
   200 	TheTest.End();
   201 	TheTest.Close();
   202 
   203 	delete tc;
   204 
   205 	__UHEAP_MARKEND;
   206 	User::Heap().Check();
   207 	return KErrNone;
   208     }