sl@0: // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "SqlBur.h" sl@0: #include "t_sqlbur.h" sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: RTest TheTest(_L("SQL Backup and Restore Test")); sl@0: sl@0: _LIT(KPrivateDir, "\\private\\10281e17\\"); sl@0: sl@0: //Don't forget to update DeleteBackupFiles() implementation if a new uid is added sl@0: const TSecureId KClientUid = 0x21212122; // the data owner's UID sl@0: const TSecureId KZeroFileSizeUid = 0xFFFF4321; sl@0: const TSecureId KTestClientUid1 = 0xFFFF4322; sl@0: const TSecureId KTestClientUid2 = 0xFFFF4323; sl@0: const TSecureId KTestClientUid3 = 0xFFFF4324; sl@0: sl@0: _LIT(KBackupDir, "C:\\TEST\\"); sl@0: _LIT(KBackupFileTemplate, "C:\\TEST\\Backup.bak"); sl@0: _LIT(KBackupCopy, "C:\\TEST\\Backup2.bak"); sl@0: _LIT(KBackupFile2Z, "Z:\\TEST\\t_sqlbur_backup_ver0.bak"); sl@0: _LIT(KBackupFile2, "C:\\TEST\\t_sqlbur_backup_ver0.bak"); sl@0: sl@0: _LIT(KZeroSizeFile, "C:\\private\\10281e17\\[FFFF4321]t_sqlbur_zero.db"); sl@0: _LIT(KTestFile1, "C:\\private\\10281e17\\[FFFF4322]t_sqlbur_test1.db"); sl@0: _LIT(KTestFile1NameOnly, "[FFFF4322]t_sqlbur_test1.db"); sl@0: _LIT(KTestFile1Bak, "C:\\private\\10281e17\\bak[FFFF4322]t_sqlbur_test1.db.bak"); sl@0: _LIT(KTestDeleteMask1, "C:\\private\\10281e17\\[FFFF4322]*"); sl@0: _LIT(KTestDeleteMask2, "*bur_test1.db"); sl@0: _LIT(KTestFile2, "\\private\\10281e17\\[FFFF4323]t_sqlbur_test2.db"); sl@0: _LIT(KTestFile3, "c:\\private\\10281e17\\[FFFF4324]t_sqlbur_test3.db"); sl@0: _LIT(KTestFile4, "c:\\private\\10281e17\\[FFFF4324]t_sqlbur_test4.db"); sl@0: sl@0: const TDriveNumber KTestDrive = EDriveC; sl@0: sl@0: const TUint KBufferSize = 2048; // used for reading backup files for validation sl@0: sl@0: static CActiveScheduler* TheScheduler = NULL; sl@0: static CSqlSrvTestBurInterface* TheSqlSrvTestBurInterface = NULL; sl@0: sl@0: ///////////////////////////////////// sl@0: sl@0: //Test db files sl@0: _LIT(KTestDbFileName1,"C:[21212122]AADB2.db"); sl@0: _LIT(KTestDbFileName2,"C:[21212122]BBDB2.db"); sl@0: sl@0: //Temp buffers for storing files content, to be compared with what is received after the restore operation. 10 files max. sl@0: TInt TheFileCount = 0; sl@0: const TInt KMaxDbFileSize = 10 * 1024;//The max test db file size - 10 Kb max. sl@0: static TUint8 TheDbFileData[10][KMaxDbFileSize];//An array where the original db file content will be stored sl@0: static TInt TheDbFileSizes[10];//An array where the real db file size will be stored sl@0: static TUint8 TheBuf[KMaxDbFileSize]; sl@0: sl@0: ///////////////////////////////////// sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void DeleteBackupFiles() sl@0: { sl@0: TFileName fname; sl@0: sl@0: fname.Copy(KBackupFileTemplate); sl@0: fname.Append((static_cast (KClientUid)).Name()); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(fname); sl@0: sl@0: fname.Copy(KBackupFileTemplate); sl@0: fname.Append((static_cast (KZeroFileSizeUid)).Name()); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(fname); sl@0: sl@0: fname.Copy(KBackupFileTemplate); sl@0: fname.Append((static_cast (KTestClientUid1)).Name()); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(fname); sl@0: sl@0: fname.Copy(KBackupFileTemplate); sl@0: fname.Append((static_cast (KTestClientUid2)).Name()); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(fname); sl@0: sl@0: fname.Copy(KBackupFileTemplate); sl@0: fname.Append((static_cast (KTestClientUid3)).Name()); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(fname); sl@0: } sl@0: sl@0: void TestEnvDestroy() sl@0: { sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KBackupCopy); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1Bak); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile3); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile4); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KZeroSizeFile); sl@0: sl@0: DeleteBackupFiles(); sl@0: sl@0: delete TheSqlSrvTestBurInterface; sl@0: TheSqlSrvTestBurInterface = NULL; sl@0: sl@0: delete TheScheduler; sl@0: TheScheduler = NULL; sl@0: } sl@0: sl@0: //////////////////////////// sl@0: // Test macros and functions sl@0: //////////////////////////// sl@0: sl@0: void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TestEnvDestroy(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: TestEnvDestroy(); sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static void DestroyFileList(RArray& aFileList) sl@0: { sl@0: for(TInt i=0;iConstruct(); sl@0: return self; sl@0: } sl@0: sl@0: CSqlSrvTestBurInterface::CSqlSrvTestBurInterface() sl@0: { sl@0: } sl@0: sl@0: void CSqlSrvTestBurInterface::Construct() sl@0: { sl@0: TInt err = iFs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: err = iFs.MkDir(KBackupDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: err = iFs.CreatePrivatePath(KTestDrive); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: CSqlSrvTestBurInterface::~CSqlSrvTestBurInterface() sl@0: { sl@0: iFs.Close(); sl@0: } sl@0: sl@0: //Called by the backup client ot get a list of database files to backup sl@0: //The array is owned by the caller sl@0: //The SQL server would have the job to get a list of databases owned by sl@0: //the given SID and to determine whether the backup flag is set sl@0: //All databases that satisfy this requirement will be added to the array. sl@0: void CSqlSrvTestBurInterface::GetBackUpListL(TSecureId aUid, TDriveNumber aDrive, RArray& aFileList) sl@0: { sl@0: if(aUid.iId == 0) sl@0: {//Simulates that there are no databases for backup sl@0: DestroyFileList(aFileList); sl@0: return; sl@0: } sl@0: sl@0: TDriveUnit driveUnit(aDrive); sl@0: TDriveName driveName = driveUnit.Name(); sl@0: TFileName path; sl@0: path.Copy(driveName); sl@0: path.Append(KPrivateDir); sl@0: //Include the aUid and the "*" mask sl@0: TUidName uidName = (static_cast (aUid)).Name(); sl@0: _LIT(KMatchAllDbFiles, "*"); sl@0: TBuf fileNameMask(uidName); sl@0: fileNameMask.Append(KMatchAllDbFiles); sl@0: TParse parse; sl@0: TInt err = parse.Set(path, &fileNameMask, NULL); sl@0: User::LeaveIfError(err); sl@0: //Do the search sl@0: TPtrC fullPath(parse.FullName()); sl@0: CDir* fileNameCol = NULL; sl@0: err = TheSqlSrvTestBurInterface->Fs().GetDir(fullPath, KEntryAttNormal, ESortNone, fileNameCol); sl@0: if(err == KErrNotFound) sl@0: { sl@0: return; sl@0: } sl@0: User::LeaveIfError(err); sl@0: CleanupStack::PushL(fileNameCol); sl@0: TInt fileCount = fileNameCol->Count(); sl@0: err = aFileList.Reserve(fileCount); sl@0: User::LeaveIfError(err); sl@0: //Append the full database file paths to the file names list. sl@0: for(TInt i=0;i (aUid)).Name(); sl@0: _LIT(KMatchAllDbFiles, "*"); sl@0: TBuf fileNameMask(uidName); sl@0: fileNameMask.Append(KMatchAllDbFiles); sl@0: TInt err = aParse.Set(aPath, &fileNameMask, NULL); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: //Reads the content of the db files and stores the content to a global memory buffer. sl@0: //That buffer content will be used later for verification of the restore process. sl@0: void StoreDbContentToBuf(RFs& aFs, TDriveNumber aDrive, TSecureId aUid) sl@0: { sl@0: TFileName path; sl@0: PrepareSearchPath(aDrive, path); sl@0: TParse parse; sl@0: PrepareSearchPattern(path, aUid, parse); sl@0: sl@0: TheFileCount = -1; sl@0: Mem::FillZ(TheDbFileData, sizeof(TheDbFileData)); sl@0: Mem::FillZ(TheDbFileSizes, sizeof(TheDbFileSizes)); sl@0: sl@0: CDir* dir = NULL; sl@0: TInt err = aFs.GetDir(parse.FullName(), KEntryAttNormal, ESortByName, dir); sl@0: TEST2(err, KErrNone); sl@0: TheFileCount = dir->Count(); sl@0: for(TInt i=0;i 0); sl@0: sl@0: TPtr8 bufptr(TheDbFileData[i], 0, KMaxDbFileSize); sl@0: err = dbFile.Read(bufptr, fileSize); sl@0: TEST2(err, KErrNone); sl@0: TEST(fileSize == bufptr.Length()); sl@0: sl@0: TheDbFileSizes[i] = fileSize; sl@0: sl@0: dbFile.Close(); sl@0: } sl@0: delete dir; sl@0: } sl@0: sl@0: //At the moment when this function is called, the db files content is already restored. sl@0: //The function will open the restored db files and compare their content against the content sl@0: //of the original db files (kept in a global memory buffer). sl@0: void CompareDbContentWithBuf(RFs& aFs, TDriveNumber aDrive, TSecureId aUid) sl@0: { sl@0: TFileName path; sl@0: PrepareSearchPath(aDrive, path); sl@0: TParse parse; sl@0: PrepareSearchPattern(path, aUid, parse); sl@0: sl@0: CDir* dir = NULL; sl@0: TInt err = aFs.GetDir(parse.FullName(), KEntryAttNormal, ESortByName, dir); sl@0: TEST2(err, KErrNone); sl@0: TEST2(TheFileCount, dir->Count()); sl@0: for(TInt i=0;i 0); sl@0: sl@0: const ::TEntry& entry = (*dir)[i]; sl@0: err = parse.Set(path, &entry.iName, NULL); sl@0: TEST2(err, KErrNone); sl@0: TPtrC fname(parse.FullName()); sl@0: sl@0: RFile dbFile; sl@0: TInt err = dbFile.Open(aFs, fname, EFileRead); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt fileSize = 0; sl@0: err = dbFile.Size(fileSize); sl@0: TEST2(err, KErrNone); sl@0: TEST(fileSize > 0); sl@0: TEST2(TheDbFileSizes[i], fileSize); sl@0: sl@0: TPtr8 bufptr(TheBuf, 0, KMaxDbFileSize); sl@0: err = dbFile.Read(bufptr, fileSize); sl@0: TEST2(err, KErrNone); sl@0: TEST2(fileSize, bufptr.Length()); sl@0: sl@0: err = Mem::Compare(TheBuf, fileSize, TheDbFileData[i], TheDbFileSizes[i]); sl@0: TEST2(err, 0); sl@0: sl@0: dbFile.Close(); sl@0: } sl@0: delete dir; sl@0: } sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //The backup client will return a series of data chunks representing sl@0: //one of more databases for the uid of the data owner. sl@0: //This data is stored in a file on the C drive for the purposes of the test sl@0: TInt TestBackupL(CSqlBurCallback &aBackupClient, RFs& aFs, TSecureId aUid, TDriveNumber aDrive, TInt aDataChunkSize = KBufferSize) sl@0: { sl@0: TFileName backupFileName; sl@0: backupFileName.Copy(KBackupFileTemplate); sl@0: backupFileName.Append((static_cast (aUid)).Name()); sl@0: sl@0: RFile file; sl@0: CleanupClosePushL(file); sl@0: TInt err = file.Replace(aFs, backupFileName, EFileWrite | EFileStream | EFileShareExclusive); sl@0: User::LeaveIfError(err); sl@0: aBackupClient.InitialiseGetProxyBackupDataL(aUid, aDrive); sl@0: sl@0: TBuf8 buf; sl@0: TPtr8 ptr((TUint8*)buf.Ptr(), aDataChunkSize); sl@0: TBool finishedFlag = EFalse; sl@0: TInt count = 0; sl@0: sl@0: do sl@0: { sl@0: aBackupClient.GetBackupDataSectionL(ptr, finishedFlag); sl@0: count += ptr.Length(); sl@0: err = file.Write(ptr); sl@0: User::LeaveIfError(err); sl@0: ptr.SetLength(0); sl@0: } sl@0: while(!finishedFlag); sl@0: sl@0: CleanupStack::PopAndDestroy(&file); sl@0: sl@0: if(count == 0) sl@0: { sl@0: User::Leave(KErrEof); sl@0: } sl@0: if(!FileExists(aFs, backupFileName)) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: TheTest.Printf(_L("Backup complete. %d bytes processed.\r\n"), count); sl@0: return count; sl@0: } sl@0: sl@0: //This sends the data in chunks form back to the BUR client sl@0: //for nupacking and restoration of the original databases files sl@0: TInt TestRestoreL(CSqlBurCallback &aRestoreClient, RFs& aFs, TSecureId aUid, TDriveNumber aDrive, TInt aDataChunkSize = KBufferSize) sl@0: { sl@0: TFileName backupFileName; sl@0: backupFileName.Copy(KBackupFileTemplate); sl@0: backupFileName.Append((static_cast (aUid)).Name()); sl@0: sl@0: RFile file; sl@0: CleanupClosePushL(file); sl@0: TInt err = file.Open(aFs, backupFileName, EFileRead | EFileShareExclusive); sl@0: User::LeaveIfError(err); sl@0: aRestoreClient.InitialiseRestoreProxyBaseDataL(aUid, aDrive); sl@0: sl@0: TBuf8 buf; sl@0: TPtr8 ptr((TUint8*)buf.Ptr(), aDataChunkSize); sl@0: TBool finishedFlag = EFalse; sl@0: sl@0: TInt fileSize = 0; sl@0: err = file.Size(fileSize); sl@0: User::LeaveIfError(err); sl@0: TInt count = fileSize; sl@0: sl@0: do sl@0: { sl@0: err = file.Read(ptr, aDataChunkSize); sl@0: User::LeaveIfError(err); sl@0: fileSize -= ptr.Length(); sl@0: finishedFlag = fileSize == 0; sl@0: aRestoreClient.RestoreBaseDataSectionL(ptr, finishedFlag); sl@0: ptr.SetLength(0); sl@0: } sl@0: while(fileSize > 0); sl@0: sl@0: CleanupStack::PopAndDestroy(&file); sl@0: sl@0: aRestoreClient.RestoreComplete(aDrive); sl@0: sl@0: if(!finishedFlag) sl@0: { sl@0: User::Leave(KErrEof); sl@0: } sl@0: sl@0: TheTest.Printf(_L("Restore complete. %d bytes processed.\r\n"), count); sl@0: return count; sl@0: } sl@0: sl@0: //Verifies the integrity of the backup file. sl@0: void TestArchiveIntegrityL(CSqlBurCallback &aBackupClient, RFs& aFs, TSecureId aUid) sl@0: { sl@0: RFile bkpFile; sl@0: CleanupClosePushL(bkpFile); sl@0: sl@0: TFileName backupFileName; sl@0: backupFileName.Copy(KBackupFileTemplate); sl@0: backupFileName.Append((static_cast (aUid)).Name()); sl@0: sl@0: TInt err = bkpFile.Open(aFs, backupFileName, EFileRead | EFileShareExclusive); sl@0: User::LeaveIfError(err); sl@0: sl@0: TBuf8 buf; sl@0: TPtr8 ptr((TUint8*)buf.Ptr(), buf.MaxLength()); sl@0: sl@0: TInt bkpFileSize = 0; sl@0: err = bkpFile.Size(bkpFileSize); sl@0: User::LeaveIfError(err); sl@0: sl@0: while(bkpFileSize > 0) sl@0: { sl@0: // get the checksum sl@0: err = bkpFile.Read(ptr, 16); // 8 UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: if(ptr.Length() != 16) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: TPtr ptr16((TUint16*) ptr.Ptr(), 8, 8); sl@0: TLex lex(ptr16); sl@0: TUint32 checksum; sl@0: lex.SkipSpace(); sl@0: err = lex.Val(checksum, EHex); sl@0: User::LeaveIfError(err); sl@0: bkpFileSize -= 16; sl@0: sl@0: // get the old file size sl@0: err = bkpFile.Read(ptr, 16); // 8 UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: if(ptr.Length() != 16) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: ptr16.Set((TUint16*) ptr.Ptr(), 8, 8); sl@0: lex.Assign(ptr16); sl@0: TUint32 oldFileSize; sl@0: lex.SkipSpace(); sl@0: err = lex.Val(oldFileSize, EHex); sl@0: User::LeaveIfError(err); sl@0: bkpFileSize -= 16; sl@0: sl@0: // get the backup file header version sl@0: err = bkpFile.Read(ptr, 8); // 4 UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: ptr16.Set((TUint16*)ptr.Ptr(), 4, 4); sl@0: lex.Assign(ptr16); sl@0: TUint32 hdrVer; sl@0: lex.SkipSpace(); sl@0: err = lex.Val(hdrVer, EHex); sl@0: User::LeaveIfError(err); sl@0: bkpFileSize -= 8; sl@0: sl@0: // get the file size sl@0: err = bkpFile.Read(ptr, 32); // 16 UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: if(ptr.Length() != 32) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: ptr16.Set((TUint16*) ptr.Ptr(), 16, 16); sl@0: lex.Assign(ptr16); sl@0: TInt64 fileSize; sl@0: lex.SkipSpace(); sl@0: err = lex.Val(fileSize, EHex); sl@0: User::LeaveIfError(err); sl@0: bkpFileSize -= 32; sl@0: sl@0: // get the filename size sl@0: err = bkpFile.Read(ptr, 16); // 8 UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: ptr16.Set((TUint16*)ptr.Ptr(), 8, 8); sl@0: lex.Assign(ptr16); sl@0: TUint32 fileNameSize; sl@0: lex.SkipSpace(); sl@0: err = lex.Val(fileNameSize, EHex); sl@0: User::LeaveIfError(err); sl@0: bkpFileSize -= 16; sl@0: sl@0: // get the filename sl@0: err = bkpFile.Read(ptr, fileNameSize * 2); // fileName UTF-16 characters sl@0: User::LeaveIfError(err); sl@0: if(ptr.Length() != (fileNameSize * 2)) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: ptr16.Set((TUint16*) ptr.Ptr(), fileNameSize, fileNameSize); sl@0: lex.Assign(ptr16); sl@0: TParse tp; sl@0: tp.Set(ptr16, NULL, NULL); sl@0: TPtrC dbFileName = tp.Name(); sl@0: bkpFileSize -= fileNameSize * 2; sl@0: sl@0: // open a local file - replaces any previous one sl@0: RFile64 dbFile; sl@0: CleanupClosePushL(dbFile); sl@0: err = dbFile.Replace(aFs, dbFileName, EFileWrite | EFileShareExclusive); sl@0: User::LeaveIfError(err); sl@0: sl@0: // copy all the data (file size bytes) sl@0: TInt bytesLeftToRead = fileSize; sl@0: sl@0: while(bytesLeftToRead > 0) sl@0: { sl@0: TInt readSize = bytesLeftToRead > KBufferSize ? KBufferSize : bytesLeftToRead; sl@0: err = bkpFile.Read(ptr, readSize); sl@0: User::LeaveIfError(err); sl@0: if(ptr.Length() != readSize) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: bytesLeftToRead -= readSize; sl@0: err = dbFile.Write(ptr, readSize); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: bkpFileSize -= fileSize; sl@0: sl@0: // checksum the file sl@0: TUint64 checkSum64 = 0; sl@0: User::LeaveIfError(aBackupClient.CheckSum(dbFile, checkSum64)); sl@0: TUint32 checksum32 = checkSum64 & 0xFFFFFFFF; sl@0: sl@0: if(checksum != checksum32) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: // all done with this file sl@0: CleanupStack::PopAndDestroy(&dbFile); sl@0: err = aFs.Delete(dbFileName); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(&bkpFile); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4002 sl@0: @SYMTestCaseDesc Test for DEF113598 - "SQL, t_sqlbur unit test needs refactoring" sl@0: The test backups 2 test db files, then verifies the backup file integrity, sl@0: then restores the test db files content from the backup file. sl@0: At the end, the test checks that the restored test db files content is the sl@0: same as the content of the original test db file. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF113598 - "SQL, t_sqlbur unit test needs refactoring" sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF113598 sl@0: */ sl@0: void FunctionalTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST(backupClient != NULL); sl@0: sl@0: //////////////////////////////////////// sl@0: sl@0: //Virtual functions - with default implementation sl@0: sl@0: (void)backupClient->GetExpectedDataSize(KTestDrive); sl@0: sl@0: (void)backupClient->GetDataChecksum(KTestDrive); sl@0: sl@0: TBool finished = EFalse; sl@0: TPtr8 ptr(0, 0, 0); sl@0: TRAP(err, backupClient->GetSnapshotDataL(KTestDrive, ptr, finished)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: TRAP(err, backupClient->InitialiseGetBackupDataL(KTestDrive)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: TRAP(err, backupClient->InitialiseRestoreBaseDataL(KTestDrive)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: TRAP(err, backupClient->InitialiseRestoreIncrementDataL(KTestDrive)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: TPtrC8 ptr2(KNullDesC8); sl@0: TRAP(err, backupClient->RestoreIncrementDataSectionL(ptr2, finished)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: TRAP(err, backupClient->AllSnapshotsSuppliedL()); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TRAP(err, backupClient->ReceiveSnapshotDataL(KTestDrive, ptr2, finished)); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: backupClient->TerminateMultiStageOperation(); sl@0: sl@0: //////////////////////////////////////// sl@0: sl@0: TInt bytesStored = 0; sl@0: TRAP(err, bytesStored = TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KClientUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Next(_L("Archive integrity test")); sl@0: sl@0: TRAP(err, TestArchiveIntegrityL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KClientUid)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete backupClient; sl@0: sl@0: TheTest.Next(_L("Restore: functional test")); sl@0: sl@0: CSqlBurCallback* restoreClient = NULL; sl@0: TRAP(err, restoreClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST(restoreClient != NULL); sl@0: sl@0: TInt bytesRestored = 0; sl@0: TRAP(err, bytesRestored = TestRestoreL(*restoreClient, TheSqlSrvTestBurInterface->Fs(), KClientUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TEST(bytesRestored == bytesStored); sl@0: sl@0: delete restoreClient; sl@0: sl@0: CompareDbContentWithBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: } sl@0: sl@0: TInt DoBackupL(TDriveNumber aDrive, TSecureId aUid) sl@0: { sl@0: CSqlBurCallback* backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface); sl@0: CleanupStack::PushL(backupClient); sl@0: TInt bytesStored = TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), aUid, aDrive); sl@0: CleanupStack::PopAndDestroy(backupClient); sl@0: return bytesStored; sl@0: } sl@0: sl@0: TInt DoRestoreL(TDriveNumber aDrive, TSecureId aUid) sl@0: { sl@0: CSqlBurCallback* restoreClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface); sl@0: CleanupStack::PushL(restoreClient); sl@0: TInt bytesRestored = TestRestoreL(*restoreClient, TheSqlSrvTestBurInterface->Fs(), aUid, aDrive); sl@0: CleanupStack::PopAndDestroy(restoreClient); sl@0: return bytesRestored; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4003 sl@0: @SYMTestCaseDesc Test for DEF113598 - "SQL, t_sqlbur unit test needs refactoring" sl@0: Under simulated OOM condition, the test backups 2 test db files, sl@0: then restores the test db files content from the backup file. sl@0: At the end, the test checks that the restored test db files content is the sl@0: same as the content of the original test db file. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF113598 - "SQL, t_sqlbur unit test needs refactoring" sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF113598 sl@0: */ sl@0: void OomTest() sl@0: { sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: TInt err = KErrNoMemory; sl@0: TInt bytesStored = 0; sl@0: TInt count = 0; sl@0: sl@0: for(count=1;err==KErrNoMemory;++count) sl@0: { sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: User::__DbgMarkStart(RHeap::EUser); sl@0: User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext, count); sl@0: TRAP(err, bytesStored = DoBackupL(KTestDrive, KClientUid)); sl@0: User::__DbgMarkEnd(RHeap::EUser, 0); sl@0: sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST(startProcessHandleCount == endProcessHandleCount); sl@0: TEST(startThreadHandleCount == endThreadHandleCount); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("OOM backup test succeeded at heap failure rate of %d\r\n"), count); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: TheTest.Next(_L("Restore: OOM test")); sl@0: err = KErrNoMemory; sl@0: TInt bytesRestored = 0; sl@0: sl@0: for(count=1;err==KErrNoMemory;++count) sl@0: { sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: User::__DbgMarkStart(RHeap::EUser); sl@0: User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext, count); sl@0: TRAP(err, bytesRestored = DoRestoreL(KTestDrive, KClientUid)); sl@0: User::__DbgMarkEnd(RHeap::EUser, 0); sl@0: sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST(startProcessHandleCount == endProcessHandleCount); sl@0: TEST(startThreadHandleCount == endThreadHandleCount); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: User::__DbgSetAllocFail(RHeap::EUser, RAllocator::ENone, 0); sl@0: TheTest.Printf(_L("OOM restore test succeeded at heap failure rate of %d\r\n"), count); sl@0: sl@0: TEST2(bytesStored, bytesRestored); sl@0: sl@0: CompareDbContentWithBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4143 sl@0: @SYMTestCaseDesc SQL Backup&Restore - data chunk size test. sl@0: The test uses an integer array of 10 elements with randomly generated data chunk sizes. sl@0: Then the test runs 10 backup iterations using each time different data chunk size. sl@0: After each backup iteration the test performs a restore operation and checks that the sl@0: data has been backup&restored without errors. sl@0: @SYMTestActions SQL Backup&Restore - data chunk size test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12104 sl@0: */ sl@0: void FunctionalTest2() sl@0: { sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: TInt64 seed = now.Int64(); sl@0: sl@0: const TInt KArraySize = 10; sl@0: TInt dataChunks[10] = {2, 6, 0, 0, 0, 0, 0, 0, 0, 0}; sl@0: const TInt KMaxDataChunkSize = 50; sl@0: sl@0: for(TInt i=2;iFs(), KClientUid, KTestDrive, dataChunks[i])); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TRAP(err, TestArchiveIntegrityL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KClientUid)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete backupClient; sl@0: sl@0: CSqlBurCallback* restoreClient = NULL; sl@0: TRAP(err, restoreClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST(restoreClient != NULL); sl@0: sl@0: TInt bytesRestored = 0; sl@0: TRAP(err, bytesRestored = TestRestoreL(*restoreClient, TheSqlSrvTestBurInterface->Fs(), KClientUid, KTestDrive, dataChunks[i])); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TEST(bytesRestored == bytesStored); sl@0: sl@0: delete restoreClient; sl@0: sl@0: CompareDbContentWithBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4144 sl@0: @SYMTestCaseDesc SQL Backup&Restore - legacy backup file format header test. sl@0: The 64-bit file system related changes made in the SQL server required some sl@0: changes to be made in the format of the backup file header. sl@0: The test checks that a backup file created with the previous format of the file header sl@0: can be restored without errors by the updated Backup&Restore implementation. sl@0: @SYMTestActions SQL Backup&Restore - legacy backup file format header test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority Medium sl@0: @SYMREQ REQ12104 sl@0: */ sl@0: void LegacyFileFormatTest() sl@0: { sl@0: //KBackupFile2 is a database backup file with header version 0. sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KBackupFile2); sl@0: TInt rc = BaflUtils::CopyFile(TheSqlSrvTestBurInterface->Fs(), KBackupFile2Z, KBackupFile2); sl@0: TEST2(rc, KErrNone); sl@0: (void)TheSqlSrvTestBurInterface->Fs().SetAtt(KBackupFile2, 0, KEntryAttReadOnly); sl@0: sl@0: //Restore the databases from KBackupFile2. sl@0: CSqlBurCallback* restoreClient = NULL; sl@0: TRAP(rc, restoreClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST(restoreClient != NULL); sl@0: sl@0: RFile file; sl@0: rc = file.Open(TheSqlSrvTestBurInterface->Fs(), KBackupFile2, EFileRead | EFileShareExclusive); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TRAP(rc, restoreClient->InitialiseRestoreProxyBaseDataL(KClientUid, KTestDrive)); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TBuf8 buf; sl@0: TPtr8 ptr((TUint8*)buf.Ptr(), buf.MaxSize()); sl@0: TBool finishedFlag = EFalse; sl@0: sl@0: TInt fileSize = 0; sl@0: rc = file.Size(fileSize); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: do sl@0: { sl@0: rc = file.Read(ptr); sl@0: TEST2(rc, KErrNone); sl@0: fileSize -= ptr.Size(); sl@0: finishedFlag = fileSize == 0; sl@0: TRAP(rc, restoreClient->RestoreBaseDataSectionL(ptr, finishedFlag)); sl@0: ptr.SetLength(0); sl@0: } sl@0: while(fileSize > 0); sl@0: sl@0: file.Close(); sl@0: sl@0: restoreClient->RestoreComplete(KTestDrive); sl@0: sl@0: TEST(finishedFlag); sl@0: sl@0: delete restoreClient; sl@0: sl@0: //At this point we have two restored databases: KTestDbFileName1 and KTestDbFileName2. sl@0: //The content of the restored file cannot be compared directly, because t_sqlattach uses the same test databases sl@0: //and modifies them. The original database content was stored without executing t_sqlattach. sl@0: //Hence a simple test is made: open the restored database, check if the database content can be accessed. sl@0: sl@0: RSqlDatabase db; sl@0: rc = db.Open(KTestDbFileName1); sl@0: TEST2(rc, KErrNone); sl@0: //The database contains this table: "TABLE C(A1 INTEGER, B2 BLOB)". sl@0: rc = db.Exec(_L("INSERT INTO C VALUES(100, 200)")); sl@0: TEST2(rc, 1); sl@0: RSqlStatement stmt; sl@0: rc = stmt.Prepare(db, _L("SELECT * FROM C")); sl@0: TEST2(rc, KErrNone); sl@0: while((rc = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: } sl@0: stmt.Close(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: db.Close(); sl@0: sl@0: rc = db.Open(KTestDbFileName2); sl@0: TEST2(rc, KErrNone); sl@0: //The database contains this table: "TABLE A1(F1 INTEGER , F2 INTEGER, B1 BLOB)" sl@0: rc = db.Exec(_L("INSERT INTO A1 VALUES(100, 200, NULL)")); sl@0: TEST2(rc, 1); sl@0: rc = stmt.Prepare(db, _L("SELECT * FROM A1")); sl@0: TEST2(rc, KErrNone); sl@0: while((rc = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: } sl@0: stmt.Close(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: db.Close(); sl@0: sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KBackupFile2); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4192 sl@0: @SYMTestCaseDesc SQL Backup&Restore - empty backup file list test. sl@0: The test checks what will happen if the list with the files for backup is empty. sl@0: The GetBackupDataSectionL() should immediatelly set the flag parameter to true and do nothing. sl@0: @SYMTestActions SQL Backup&Restore - empty backup file list test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: @SYMDEF DEF145198 sl@0: */ sl@0: void EmptyBackupFileListTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST(backupClient != NULL); sl@0: sl@0: TRAP(err, backupClient->InitialiseGetProxyBackupDataL(KNullUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TBuf8<100> buf; sl@0: TPtr8 ptr((TUint8*)buf.Ptr(), 0, buf.MaxLength()); sl@0: TBool finishedFlag = EFalse; sl@0: TRAP(err, backupClient->GetBackupDataSectionL(ptr, finishedFlag)); sl@0: delete backupClient; sl@0: TEST2(err, KErrNone); sl@0: TEST(finishedFlag); sl@0: TEST2(buf.Length(), 0); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4193 sl@0: @SYMTestCaseDesc SQL Backup&Restore - file I/O error simulation test. sl@0: The test executes a backup, followed by a restore operation sl@0: in a file I/O error simulation loop. sl@0: @SYMTestActions SQL Backup&Restore - file I/O error simulation test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: @SYMDEF DEF145198 sl@0: */ sl@0: void BackupRestoreFileIoErrTest() sl@0: { sl@0: //Make sure that the database content, just before the backup, will be copied to the test biffers. sl@0: //The buffers will be used during the restore testing for verification of the database content. sl@0: StoreDbContentToBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: sl@0: for(TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError) sl@0: { sl@0: TheTest.Printf(_L("===Backup&Restore, simulated file system error=%d\r\n"), fsError); sl@0: sl@0: TInt err = KErrGeneral; sl@0: TInt bytesStored = -1; sl@0: TInt it_cnt1 = 0; sl@0: for(;errFs().SetErrorCondition(fsError, it_cnt1); sl@0: TRAP(err, bytesStored = DoBackupL(KTestDrive, KClientUid)); sl@0: (void)TheSqlSrvTestBurInterface->Fs().SetErrorCondition(KErrNone); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = KErrGeneral; sl@0: TInt bytesRestored = -1; sl@0: TInt it_cnt2 = 0; sl@0: for(;errFs().SetErrorCondition(fsError, it_cnt2); sl@0: TRAP(err, bytesRestored = DoRestoreL(KTestDrive, KClientUid)); sl@0: (void)TheSqlSrvTestBurInterface->Fs().SetErrorCondition(KErrNone); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: TEST2(err, KErrNone); sl@0: sl@0: TEST2(bytesStored, bytesRestored); sl@0: CompareDbContentWithBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: sl@0: 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); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4225 sl@0: @SYMTestCaseDesc SQL Backup - zero size file backup. sl@0: The test executes a backup on a file with zero size. sl@0: @SYMTestActions SQL Backup - zero size file backup. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void BackupZeroSizeFileTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: // sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KZeroSizeFile); sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: // sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KZeroFileSizeUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Write something to the file sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData, "123456787989"); sl@0: err = file.Write(KData); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Do the restore. After the restore the file size should be 0. sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KZeroFileSizeUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TInt size; sl@0: err = file.Size(size); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST2(size, 0); sl@0: //Write something to the file sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Write(KData); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Call RestoreBaseDataSectionL() with 0 data in the input buffer and finished flag: false. sl@0: TRAP(err, backupClient->InitialiseRestoreProxyBaseDataL(KZeroFileSizeUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: TPtrC8 zeroBuf; sl@0: TRAP(err, backupClient->RestoreBaseDataSectionL(zeroBuf, EFalse)); sl@0: TEST2(err, KErrNone); sl@0: //No restore in this case, sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Size(size); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(size > 0); sl@0: //Call RestoreBaseDataSectionL() with 0 data in the input buffer and finished flag: true. sl@0: TRAP(err, backupClient->InitialiseRestoreProxyBaseDataL(KZeroFileSizeUid, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, backupClient->RestoreBaseDataSectionL(zeroBuf, ETrue)); sl@0: TEST2(err, KErrNone); sl@0: //No restore in this case, sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KZeroSizeFile, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Size(size); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(size > 0); sl@0: // sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KZeroSizeFile); sl@0: delete backupClient; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4226 sl@0: @SYMTestCaseDesc SQL Restore - corrupted archive 1. sl@0: The test does a backup of a file with a non-zero size. sl@0: The the test modifies the archive, simulating a corruption. sl@0: The the test performs a restore from the archive. The corruption sl@0: should be detected and reported by SQL B&R code. sl@0: @SYMTestActions SQL Restore - corrupted archive 1. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void CorruptedArchiveTest1() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: //Create the test file that will be sent for backup sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Backup the file sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Modify the file, which was sent for backup sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEFGH"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.SetSize(KData2().Length()); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Corrupt the archive sl@0: TFileName backupFileName; sl@0: backupFileName.Copy(KBackupFileTemplate); sl@0: backupFileName.Append((static_cast (KTestClientUid1)).Name()); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), backupFileName, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TInt pos = -3; sl@0: err = file.Seek(ESeekEnd, pos); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData3, "ERR"); sl@0: err = file.Write(KData3); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Try to restore the archive sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrCorrupt); sl@0: //Check that the file really has not been restored sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<50> data; sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData2); sl@0: // sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: delete backupClient; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4227 sl@0: @SYMTestCaseDesc SQL Restore - corrupted archive 2. sl@0: The test does a backup of a file with a non-zero size. sl@0: Then the test modifies the archive, byte after byte each step, sl@0: simulating a corruption. sl@0: The the test performs a restore from the archive. The corruption sl@0: should be detected and reported by SQL B&R code. sl@0: @SYMTestActions SQL Restore - corrupted archive 2. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void CorruptedArchiveTest2() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: //Create the test file that will be sent for backup sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Backup the file sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Modify the file, which was sent for backup sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEFGH"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.SetSize(KData2().Length()); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Make a copy of the modified file sl@0: CFileMan* fm = NULL; sl@0: TRAP(err, fm = CFileMan::NewL(TheSqlSrvTestBurInterface->Fs())); sl@0: TEST2(err, KErrNone); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1Bak); sl@0: err = fm->Copy(KTestFile1, KTestFile1Bak); sl@0: TEST2(err, KErrNone); sl@0: //Get the archive size sl@0: TFileName backupFileName; sl@0: backupFileName.Copy(KBackupFileTemplate); sl@0: backupFileName.Append((static_cast (KTestClientUid1)).Name()); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), backupFileName, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TInt size = 0; sl@0: err = file.Size(size); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Save a copy of the archive sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KBackupCopy); sl@0: err = fm->Copy(backupFileName, KBackupCopy); sl@0: TEST2(err, KErrNone); sl@0: //On each iteration step: corrupt the archive and try to do a restore from it. sl@0: for(TInt i=0;iFs(), backupFileName, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TInt pos = i; sl@0: err = file.Seek(ESeekStart, pos); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<1> byte; sl@0: err = file.Read(byte); sl@0: TEST2(err, KErrNone); sl@0: ++byte[0]; sl@0: err = file.Seek(ESeekStart, pos); sl@0: TEST2(err, KErrNone); sl@0: err = file.Write(byte); sl@0: TEST2(err, KErrNone); sl@0: if(i == (size - 1) && (size & 0x01) == 0) sl@0: {//Make the file size an odd number, just to test.... sl@0: err = file.Write(byte); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Restore sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TheTest.Printf(_L("Iteration %d, err=%d\r\n"), i, err); sl@0: if(err == KErrNone) sl@0: { sl@0: //Delete the restored file. The reason that the restore didn't fail is because only the file data is sl@0: //protected with checksum. The restore file header - not. The restore completed, the data was restored sl@0: //to a file with different name. Or even to a file with the same name. Delete created file(s). sl@0: (void)fm->Delete(KTestDeleteMask1); sl@0: (void)fm->Delete(KTestDeleteMask2); sl@0: } sl@0: else sl@0: { sl@0: //The restore completed with an error. The file content is preserved. sl@0: //Check that the file content is the same. sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<50> data; sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData2); sl@0: } sl@0: //Restore the file from the backup copy sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: err = fm->Copy(KTestFile1Bak, KTestFile1); sl@0: TEST2(err, KErrNone); sl@0: //Restore the archive from the good copy. sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(backupFileName); sl@0: err = fm->Copy(KBackupCopy, backupFileName); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: // sl@0: delete fm; sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1Bak); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KBackupCopy); sl@0: delete backupClient; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4228 sl@0: @SYMTestCaseDesc SQL Backup&Restore on a drive different than KTestDrive (C: by default). sl@0: The test creates one database on KTestDrive and another database sl@0: with the same name on a drive different than KTestDrive. sl@0: Then the test backups the "not KTestDrive" drive and restores sl@0: the data after that. The test verifies that the backup&restore sl@0: really impacts only the other drive, not KTestDrive. sl@0: @SYMTestActions SQL Backup&Restore on a drive different than KTestDrive (C: by default). sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void DbDriveTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: // sl@0: TDriveUnit driveUnitDefault(KTestDrive); sl@0: TDriveName driveNameDefault = driveUnitDefault.Name(); sl@0: //Find a r/w drive, different than KTestDrive sl@0: TInt drive = EDriveA; sl@0: for(;drive<=EDriveZ;++drive) sl@0: { sl@0: if(drive == KTestDrive) sl@0: { sl@0: continue; sl@0: } sl@0: TDriveInfo driveInfo; sl@0: err = TheSqlSrvTestBurInterface->Fs().Drive(driveInfo, drive); sl@0: if(err != KErrNone) sl@0: { sl@0: continue; sl@0: } sl@0: if(driveInfo.iDriveAtt & KDriveAttRom) sl@0: { sl@0: continue; sl@0: } sl@0: // sl@0: TDriveUnit driveUnit(drive); sl@0: TDriveName driveName = driveUnit.Name(); sl@0: // sl@0: TVolumeInfo vinfo; sl@0: err = TheSqlSrvTestBurInterface->Fs().Volume(vinfo, drive); sl@0: if(err != KErrNone) sl@0: { sl@0: TheTest.Printf(_L("Drive %S, RFs::Volume() err=%d\r\n"), &driveName, err); sl@0: continue; sl@0: } sl@0: //R/W drive found. sl@0: TheTest.Printf(_L("Test drive: %S\r\n"), &driveName); sl@0: TParse parse; sl@0: err = parse.Set(KTestFile2, &driveName, 0); sl@0: TEST2(err, KErrNone); sl@0: //Create the test file that will be sent for backup sl@0: TPtrC fname1(parse.FullName()); sl@0: TheTest.Printf(_L("Test file 1: %S\r\n"), &fname1); sl@0: err = TheSqlSrvTestBurInterface->Fs().MkDirAll(parse.FullName()); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(parse.FullName()); sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), parse.FullName(), EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Create a test file with the same name on drive KTestDrive sl@0: err = parse.Set(KTestFile2, &driveNameDefault, 0); sl@0: TEST2(err, KErrNone); sl@0: TPtrC fname2(parse.FullName()); sl@0: TheTest.Printf(_L("Test file 2: %S\r\n"), &fname2); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(parse.FullName()); sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), parse.FullName(), EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEFG"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Do the backup on "drive" sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid2, (TDriveNumber)drive)); sl@0: TEST2(err, KErrNone); sl@0: //Modify the file that was sent for backup sl@0: err = parse.Set(KTestFile2, &driveName, 0); sl@0: TEST2(err, KErrNone); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), parse.FullName(), EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData3, "ABCDEFGHYYYYYY"); sl@0: err = file.Write(KData3); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Do the restore on "drive" sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid2, (TDriveNumber)drive)); sl@0: TEST2(err, KErrNone); sl@0: //Verify the content of the restored file sl@0: err = parse.Set(KTestFile2, &driveName, 0); sl@0: TEST2(err, KErrNone); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), parse.FullName(), EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<50> data; sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData1); sl@0: //Verify the content of the file on drive KTestDrive. It should be the same as before the backup&restore. sl@0: err = parse.Set(KTestFile2, &driveNameDefault, 0); sl@0: TEST2(err, KErrNone); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), parse.FullName(), EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData2); sl@0: //Cleanup sl@0: err = parse.Set(KTestFile2, &driveNameDefault, 0); sl@0: TEST2(err, KErrNone); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(parse.FullName()); sl@0: err = parse.Set(KTestFile2, &driveName, 0); sl@0: TEST2(err, KErrNone); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(parse.FullName()); sl@0: break; sl@0: } sl@0: delete backupClient; sl@0: if(drive > EDriveZ) sl@0: { sl@0: TheTest.Printf(_L("No R/W drive has been found, different than %S\r\n"), &driveNameDefault); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4229 sl@0: @SYMTestCaseDesc SQL Backup&Restore with locked file. sl@0: The test creates two test files on the same drive and with the same uid. sl@0: Then the test backups the databases. After the backup the test simulates that sl@0: the first file is "in use". Then the test performs a restore. sl@0: The expected result: the locked file is not restored but the other file is restored. sl@0: @SYMTestActions SQL Backup&Restore with locked file. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void LockFileTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile3); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile4); sl@0: //Create the files. File 1. sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile3, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //...file 2 sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEF"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Backup sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid3, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Modify the files. Keep the first file opened. sl@0: RFile file1; sl@0: err = file1.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile3, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData3, "YYYYYQQQQQQQQQQQ"); sl@0: err = file1.Write(KData3); sl@0: TEST2(err, KErrNone); sl@0: err = file1.Flush(); sl@0: TEST2(err, KErrNone); sl@0: //...file 2 sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData4, "5545495444j32322332234223432"); sl@0: err = file.Write(KData4); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Restore. The reported error should be KErrInUse. sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid3, KTestDrive)); sl@0: TEST2(err, KErrInUse); sl@0: //Close file 1 and check the content. It should be the same as after the backup sl@0: file1.Close(); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile3, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<50> data; sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData3); sl@0: //File2: check the content. It should be the same as before the backup sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData2); sl@0: // sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile4); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile3); sl@0: delete backupClient; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4230 sl@0: @SYMTestCaseDesc SQL Backup&Restore with locked file - test 2. sl@0: The test creates two test files on the same drive and with different uids. sl@0: Then the test backups the databases. After the backup the test simulates that sl@0: the first file is "in use". Then the test performs a restore. sl@0: The expected result: the locked file is not restored but the other file is restored. sl@0: @SYMTestActions SQL Backup&Restore with locked file - test 2. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void LockFileTest2() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1);//KTestClientUid1 used sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile4);//KTestClientUid3 used sl@0: //Create the files. File 1. sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //...file 2 sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEF"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Backup sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid3, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Modify the files. Keep the first file opened. sl@0: RFile file1; sl@0: err = file1.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData3, "YYYYYQQQQQQQQQQQ"); sl@0: err = file1.Write(KData3); sl@0: TEST2(err, KErrNone); sl@0: err = file1.Flush(); sl@0: TEST2(err, KErrNone); sl@0: //...file 2 sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData4, "5545495444j32322332234223432"); sl@0: err = file.Write(KData4); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Restore the first file. The reported error should be KErrInUse. sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrInUse); sl@0: //Restore the second file. The reported error should be KErrNone. sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid3, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Close file 1 and check the content. It should be the same as after the backup sl@0: file1.Close(); sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: TBuf8<50> data; sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData3); sl@0: //File2: check the content. It should be the same as before the backup sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KTestFile4, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: err = file.Read(data); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: TEST(data == KData2); sl@0: // sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile4); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: delete backupClient; sl@0: } sl@0: sl@0: CDir* GetPrivateDirContent(TDriveNumber aDrive) sl@0: { sl@0: TDriveUnit driveUnit(aDrive); sl@0: TDriveName driveName = driveUnit.Name(); sl@0: TFileName path; sl@0: path.Copy(driveName); sl@0: path.Append(KPrivateDir); sl@0: _LIT(KMatchAllDbFiles, "*"); sl@0: path.Append(KMatchAllDbFiles); sl@0: //Do the search sl@0: CDir* fileNameCol = NULL; sl@0: TInt err = TheSqlSrvTestBurInterface->Fs().GetDir(path, KEntryAttNormal, ESortByName, fileNameCol); sl@0: TEST2(err, KErrNone); sl@0: return fileNameCol; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4231 sl@0: @SYMTestCaseDesc SQL Backup&Restore - directory content test. sl@0: The test stores into an array information regarding all files in sl@0: SQL private datacage. Then the test backups one of the files and modifies sl@0: the file after that. Then the test does a restore. Expected result - the only sl@0: modifed file should be the file which was sent for backup. sl@0: @SYMTestActions SQL Backup&Restore - directory content test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void DirectoryContentTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1);//KTestClientUid1 used sl@0: //Create the file sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData1, "123456787989"); sl@0: err = file.Write(KData1); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Store file entries into an array sl@0: CDir* dirBeforeBackup = GetPrivateDirContent(KTestDrive); sl@0: //Backup sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Check dir content sl@0: CDir* dirAfterBackup = GetPrivateDirContent(KTestDrive); sl@0: TEST2(dirBeforeBackup->Count(), dirAfterBackup->Count()); sl@0: for(TInt i=0;iCount();++i) sl@0: { sl@0: const TEntry& entry1 = (*dirBeforeBackup)[i]; sl@0: const TEntry& entry2 = (*dirAfterBackup)[i]; sl@0: TheTest.Printf(_L("Entry1=%S, Entry2=%S\r\n"), &entry1.iName, &entry2.iName); sl@0: TBool rc = entry1.iAtt == entry2.iAtt; sl@0: TEST(rc); sl@0: rc = entry1.iSize == entry2.iSize; sl@0: TEST(rc); sl@0: rc = entry1.iModified == entry2.iModified; sl@0: TEST(rc); sl@0: rc = entry1.iType == entry2.iType; sl@0: TEST(rc); sl@0: rc = entry1.iName == entry2.iName; sl@0: TEST(rc); sl@0: } sl@0: delete dirAfterBackup; sl@0: //Modify the file sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KData2, "ABCDEF"); sl@0: err = file.Write(KData2); sl@0: TEST2(err, KErrNone); sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Restore sl@0: User::After(2000000);//To force a change in the file time stamp (the restored file time stamp). sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Check dir content sl@0: CDir* dirAfterRestore = GetPrivateDirContent(KTestDrive); sl@0: TEST2(dirBeforeBackup->Count(), dirAfterRestore->Count()); sl@0: for(TInt i=0;iCount();++i) sl@0: { sl@0: const TEntry& entry1 = (*dirBeforeBackup)[i]; sl@0: const TEntry& entry2 = (*dirAfterRestore)[i]; sl@0: TheTest.Printf(_L("Entry1=%S, Entry2=%S\r\n"), &entry1.iName, &entry2.iName); sl@0: TBool rc = entry1.iAtt == entry2.iAtt; sl@0: TEST(rc); sl@0: rc = entry1.iSize == entry2.iSize; sl@0: TEST(rc); sl@0: if(entry1.iName.FindF(KTestFile1NameOnly) >= 0) sl@0: { sl@0: rc = entry1.iModified != entry2.iModified; sl@0: } sl@0: else sl@0: { sl@0: rc = entry1.iModified == entry2.iModified; sl@0: } sl@0: TEST(rc); sl@0: rc = entry1.iType == entry2.iType; sl@0: TEST(rc); sl@0: rc = entry1.iName == entry2.iName; sl@0: TEST(rc); sl@0: } sl@0: delete dirAfterRestore; sl@0: // sl@0: delete dirBeforeBackup; sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: delete backupClient; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-UT-4232 sl@0: @SYMTestCaseDesc SQL Backup&Restore - large file test. sl@0: Backup and restore with a file with size bigger than 1 Mb. sl@0: @SYMTestActions SQL Backup&Restore - large file test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMTestPriority High sl@0: */ sl@0: void LargeFileTest() sl@0: { sl@0: CSqlBurCallback* backupClient = NULL; sl@0: TRAPD(err, backupClient = CSqlBurCallback::NewL(*TheSqlSrvTestBurInterface)); sl@0: TEST2(err, KErrNone); sl@0: TEST(backupClient != NULL); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1);//KTestClientUid1 used sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile2);//KTestClientUid2 used sl@0: //Allocate buffer for the data sl@0: const TInt KDataBufSize = 100000; sl@0: HBufC8* dataBuf = HBufC8::New(KDataBufSize); sl@0: TEST(dataBuf != NULL); sl@0: TPtr8 dataPtr = dataBuf->Des(); sl@0: //Create file 1 sl@0: const TInt KFileSize1 = 1201345; sl@0: RFile file; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile1, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: dataPtr.SetLength(dataPtr.MaxLength()); sl@0: const TChar KChar1(0x5A); sl@0: dataPtr.Fill(KChar1); sl@0: TInt len = KFileSize1; sl@0: while(len > 0) sl@0: { sl@0: TInt blockSize = Min(len, dataPtr.MaxLength()); sl@0: err = file.Write(dataPtr, blockSize); sl@0: TEST2(err, KErrNone); sl@0: len -= blockSize; sl@0: } sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Create file 2 sl@0: const TInt KFileSize2 = 1387651; sl@0: err = file.Replace(TheSqlSrvTestBurInterface->Fs(), KTestFile2, EFileRead | EFileWrite); sl@0: TEST2(err, KErrNone); sl@0: dataPtr.SetLength(dataPtr.MaxLength()); sl@0: const TChar KChar2(0xD5); sl@0: dataPtr.Fill(KChar2); sl@0: len = KFileSize2; sl@0: while(len > 0) sl@0: { sl@0: TInt blockSize = Min(len, dataPtr.MaxLength()); sl@0: err = file.Write(dataPtr, blockSize); sl@0: TEST2(err, KErrNone); sl@0: len -= blockSize; sl@0: } sl@0: err = file.Flush(); sl@0: TEST2(err, KErrNone); sl@0: file.Close(); sl@0: //Backup sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, TestBackupL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid2, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Delete the files sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile2); sl@0: //Restore sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid1, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, TestRestoreL(*backupClient, TheSqlSrvTestBurInterface->Fs(), KTestClientUid2, KTestDrive)); sl@0: TEST2(err, KErrNone); sl@0: //Check restored files content sl@0: const TPtrC KFileNames[] = {KTestFile1(), KTestFile2()}; sl@0: const TInt KFileSizes[] = {KFileSize1, KFileSize2}; sl@0: const TChar KSymbols[] = {KChar1, KChar2}; sl@0: for(TInt i=0;i<(sizeof(KFileNames)/sizeof(KFileNames[i]));++i) sl@0: { sl@0: err = file.Open(TheSqlSrvTestBurInterface->Fs(), KFileNames[i], EFileRead); sl@0: TEST2(err, KErrNone); sl@0: len = 0; sl@0: err = file.Size(len); sl@0: TEST2(err, KErrNone); sl@0: TEST2(len, KFileSizes[i]); sl@0: while(len > 0) sl@0: { sl@0: TInt blockSize = Min(len, dataPtr.MaxLength()); sl@0: err = file.Read(dataPtr, blockSize); sl@0: TEST2(err, KErrNone); sl@0: len -= blockSize; sl@0: for(TInt j=0;jFs().Delete(KTestFile2); sl@0: (void)TheSqlSrvTestBurInterface->Fs().Delete(KTestFile1); sl@0: delete backupClient; sl@0: } sl@0: sl@0: void DoMain() sl@0: { sl@0: TestEnvCreate(); sl@0: sl@0: TheTest.Start(_L("Store db content to memory buffer")); sl@0: StoreDbContentToBuf(TheSqlSrvTestBurInterface->Fs(), KTestDrive, KClientUid); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4002 Backup: functional test ")); sl@0: FunctionalTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4003 Backup: OOM test ")); sl@0: OomTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4143 Backup&Restore: functional test 2")); sl@0: FunctionalTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4144 Backup&Restore: legacy file format test")); sl@0: LegacyFileFormatTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4192 Backup&Restore: empty backup file list")); sl@0: EmptyBackupFileListTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4193 Backup: File I/O error simulation test")); sl@0: BackupRestoreFileIoErrTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4225 Zero size file - backup test")); sl@0: BackupZeroSizeFileTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4226 Restore test - corrupted archive 1")); sl@0: CorruptedArchiveTest1(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4227 Restore test - corrupted archive 2")); sl@0: CorruptedArchiveTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4228 Backup&Restore test on a drive different than KTestDrive (C: by default)")); sl@0: DbDriveTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4229 Backup&Restore test with locked file")); sl@0: LockFileTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4230 Backup&Restore test with locked file 2")); sl@0: LockFileTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4231 Backup&Restore - directory content test")); sl@0: DirectoryContentTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-UT-4232 Backup&Restore - large file test")); sl@0: LargeFileTest(); sl@0: sl@0: TestEnvDestroy(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TheTest(tc != NULL); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: DoMain(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }