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); |
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")); |