persistentstorage/sql/TEST/t_sqlbur.cpp
branchRCL_3
changeset 12 6b6fd149daa2
parent 0 08ec8eefde2f
equal deleted inserted replaced
11:211563e4b919 12:6b6fd149daa2
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   128 //Called by the backup client ot get a list of database files to backup
   128 //Called by the backup client ot get a list of database files to backup
   129 //The array is owned by the caller
   129 //The array is owned by the caller
   130 //The SQL server would have the job to get a list of databases owned by
   130 //The SQL server would have the job to get a list of databases owned by
   131 //the given SID and to determine whether the backup flag is set
   131 //the given SID and to determine whether the backup flag is set
   132 //All databases that satisfy this requirement will be added to the array
   132 //All databases that satisfy this requirement will be added to the array
   133 void CSqlBurTestHarness::GetBackUpListL(TSecureId /*aUid*/, RArray<TParse>& aFileList)
   133 void CSqlBurTestHarness::GetBackUpListL(TSecureId aUid, RArray<TParse>& aFileList)
   134 	{
   134 	{
       
   135 	if(aUid.iId == 0)
       
   136 		{//Simulates that there are no databases for backup
       
   137 		aFileList.Reset();
       
   138 		return;
       
   139 		}
   135 	//TheTest.Printf(_L("Getting backup file list for SID=%x\r\n"),aUid);
   140 	//TheTest.Printf(_L("Getting backup file list for SID=%x\r\n"),aUid);
   136 	for(TInt i=0;i<KTestDbFileCnt;++i)
   141 	for(TInt i=0;i<KTestDbFileCnt;++i)
   137 		{
   142 		{
   138 		TParse parse;
   143 		TParse parse;
   139 		parse.Set(KTestFileNames[i], &KPrivateDir, NULL);
   144 		parse.Set(KTestFileNames[i], &KPrivateDir, NULL);
   193 	TheTestHarness = CSqlBurTestHarness::New();
   198 	TheTestHarness = CSqlBurTestHarness::New();
   194 	TEST(TheTestHarness != NULL);
   199 	TEST(TheTestHarness != NULL);
   195 	}
   200 	}
   196 
   201 
   197 //Reads the content of the db files and stores the content to a global memory buffer.
   202 //Reads the content of the db files and stores the content to a global memory buffer.
   198 //That buffer content will be sued later for  a verification of the restore process.
   203 //That buffer content will be used later for verification of the restore process.
   199 void StoreDbContentToBuf(RFs& aFs)
   204 void StoreDbContentToBuf(RFs& aFs)
   200 	{
   205 	{
   201 	for(TInt i=0;i<KTestDbFileCnt;++i)
   206 	for(TInt i=0;i<KTestDbFileCnt;++i)
   202 		{
   207 		{
   203 		RFile dbFile;
   208 		RFile dbFile;
   820 	TEST2(rc, KSqlAtEnd);
   825 	TEST2(rc, KSqlAtEnd);
   821 	db.Close();
   826 	db.Close();
   822 
   827 
   823 	(void)TheTestHarness->Fs().Delete(KBackupFile2);
   828 	(void)TheTestHarness->Fs().Delete(KBackupFile2);
   824 	}
   829 	}
   825 			
   830 		
       
   831 /**
       
   832 @SYMTestCaseID			PDS-SQL-UT-4192
       
   833 @SYMTestCaseDesc		SQL Backup&Restore - empty backup file list test.
       
   834 						The test checks what will happen if the list with the files for backup is empty.
       
   835 						The GetBackupDataSectionL() should immediatelly set the flag parameter to true and do nothing.
       
   836 @SYMTestActions			SQL Backup&Restore - empty backup file list test.
       
   837 @SYMTestExpectedResults Test must not fail
       
   838 @SYMTestPriority		High
       
   839 @SYMDEF					DEF145198
       
   840 */
       
   841 void EmptyBackupFileListTest()
       
   842 	{
       
   843 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4192 Backup&Restore: empty backup file list"));
       
   844 	
       
   845 	CSqlBackupClient* backupClient = NULL;
       
   846 	TRAPD(err, backupClient = CSqlBackupClient::NewL(TheTestHarness));
       
   847 	TEST(backupClient != NULL);
       
   848 	
       
   849 	TRAP(err, backupClient->InitialiseGetProxyBackupDataL(KNullUid, EDriveC));
       
   850 	TEST2(err, KErrNone);
       
   851 
       
   852 	TBuf8<100> buf;
       
   853 	TPtr8 ptr((TUint8*)buf.Ptr(), 0, buf.MaxLength());
       
   854 	TBool finishedFlag = EFalse;
       
   855 	TRAP(err, backupClient->GetBackupDataSectionL(ptr, finishedFlag));
       
   856 	delete backupClient;
       
   857 	TEST2(err, KErrNone);
       
   858 	TEST(finishedFlag);
       
   859 	TEST2(buf.Length(), 0);
       
   860 	}
       
   861 
       
   862 
       
   863 /**
       
   864 @SYMTestCaseID			PDS-SQL-UT-4193
       
   865 @SYMTestCaseDesc		SQL Backup&Restore - file I/O error simulation test.
       
   866 						The test executes a backup, followed by a restore operation 
       
   867 						in a file I/O error simulation loop.
       
   868 @SYMTestActions			SQL Backup&Restore - file I/O error simulation test.
       
   869 @SYMTestExpectedResults Test must not fail
       
   870 @SYMTestPriority		High
       
   871 @SYMDEF					DEF145198
       
   872 */
       
   873 void BackupRestoreFileIoErrTest()
       
   874 	{
       
   875 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4193 Backup: File I/O error simulation test"));
       
   876 
       
   877 	//Make sure that the database content, just before the backup, will be copied to the test biffers.
       
   878 	//The buffers will be used during the restore testing for verification of the database content.
       
   879 	StoreDbContentToBuf(TheTestHarness->Fs());
       
   880 	
       
   881 	for(TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
       
   882 		{
       
   883 		TheTest.Printf(_L("===Backup&Restore, simulated file system error=%d\r\n"), fsError);
       
   884 		
       
   885 		TInt err = KErrGeneral;
       
   886 		TInt bytesStored = -1;
       
   887 		TInt it_cnt1 = 0;
       
   888 		for(;err<KErrNone;++it_cnt1)
       
   889 			{
       
   890 			__UHEAP_MARK;
       
   891 			(void)TheTestHarness->Fs().SetErrorCondition(fsError, it_cnt1);
       
   892 			TRAP(err, bytesStored = DoBackupL());
       
   893 			(void)TheTestHarness->Fs().SetErrorCondition(KErrNone);
       
   894 			__UHEAP_MARKEND;
       
   895 			}
       
   896 		TEST2(err, KErrNone);
       
   897 	
       
   898 		err = KErrGeneral;
       
   899 		TInt bytesRestored = -1;
       
   900 		TInt it_cnt2 = 0;
       
   901 	    for(;err<KErrNone;++it_cnt2)
       
   902 			{
       
   903 			__UHEAP_MARK;
       
   904 			(void)TheTestHarness->Fs().SetErrorCondition(fsError, it_cnt2);
       
   905 			TRAP(err, bytesRestored = DoRestoreL());
       
   906 			(void)TheTestHarness->Fs().SetErrorCondition(KErrNone);
       
   907 			__UHEAP_MARKEND;
       
   908 			}
       
   909 		TEST2(err, KErrNone);
       
   910 		
       
   911 		TEST2(bytesStored, bytesRestored);
       
   912 		CompareDbContentWithBuf(TheTestHarness->Fs());
       
   913 		
       
   914 		TheTest.Printf(_L("Backup&Restore file I/O error simulation test succeeded at backup iteration %d and restore itreration %d\r\n"), it_cnt1 - 1, it_cnt2 - 1);
       
   915 		}
       
   916 	}
       
   917 
       
   918 
   826 void DoMain()
   919 void DoMain()
   827 	{
   920 	{
   828 	TestEnvCreate();
   921 	TestEnvCreate();
   829 
   922 
   830 	TheTest.Start(_L("Store db content to memory buffer"));
   923 	TheTest.Start(_L("Store db content to memory buffer"));
   835 	OomTest();
   928 	OomTest();
   836 
   929 
   837 	FunctionalTest2();
   930 	FunctionalTest2();
   838 
   931 
   839 	LegacyFileFormatTest();
   932 	LegacyFileFormatTest();
       
   933 	
       
   934 	EmptyBackupFileListTest();
       
   935 	
       
   936 	BackupRestoreFileIoErrTest();
   840 
   937 
   841 	TestEnvDestroy();
   938 	TestEnvDestroy();
   842 	}
   939 	}
   843 
   940 
   844 TInt E32Main()
   941 TInt E32Main()