Esempio n. 1
0
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0648
@SYMTestCaseDesc        Transactions test
						Simulating  an "out of disk space" situation
@SYMTestPriority        Medium
@SYMTestActions         Transaction test under "out of disk space" circumstances
						while reserving disk space.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
static void TransactionTestL()
	{
    TVolumeIOParamInfo volIoPrm;
    TInt err = TheFs.VolumeIOParam(KTestDrive, volIoPrm);
    TEST2(err, KErrNone);
    RDebug::Print(_L("--Drive %d. BlockSize=%d, ClusterSize=%d, RecReadBufSize=%d, RecWriteBufSize=%d\r\n"), KTestDrive, volIoPrm.iBlockSize, volIoPrm.iClusterSize, volIoPrm.iRecReadBufSize, volIoPrm.iRecWriteBufSize);
    /////////////////////////////////////////////////////////
	CreateTestDbSession();
    //Rserve disk space
	ReserveDiskSpace();
    //Create test database and table. Add some test data to them.
	CreateTestDatabase(TheDbSession, TheDb);
	CreateTestTableL(TheDb);
	AddTestDataL(TheDb);
    RDebug::Print(_L("--Simulate an \"out of disk space\" situation with creating a very large data file, which occupies almost the all the available disk space.\r\n"));
	CreateLargeFileL();
    RDebug::Print(_L("--Attempt to delete test data records. The transaction must fail, because of \"out of disk space\".\r\n"));
    TInt64 diskSpace = FreeDiskSpaceL();
	RDebug::Print(_L("--Attempt to delete test data records. Free disk space = %ld\n"), diskSpace);
	TRAP(err, DeleteRecordsL());
	RDebug::Print(_L("--DeleteRecordsL() returned %d error\r\n"), err);
	TEST(err != KErrNone);
    RDebug::Print(_L("--The attempt failed with err=%d. Get an access to the reserved disk space.\r\n"), err);
    UnlockReservedSpace();
	RDebug::Print(_L("--Try again with getting an access to the reserved disk space.\n"));
    diskSpace = FreeDiskSpaceL();
    RDebug::Print(_L("After GetReserveAccess(), free disk space = %ld\r\n"), diskSpace);
	DeleteRecordsL();
	RDebug::Print(_L("--\"Delete\" transaction was completed successfully.\n"));
    //Free the resources, used in the test
	DeleteLargeDataFiles();
	LockReservedSpace();
    FreeReservedSpace();
	}
//static
TUint32 WidgetUnzipUtilityS60::uncompressedSizeL(const QString& aZipFileName, const TChar& aDriveLetter)
{
    RFs fs;
    User::LeaveIfError(fs.Connect()); // not possible to continue without RFs
    CleanupClosePushL(fs);

    TUint64 uncompressedSize(0);
    TInt allocUnitSize(8192); // use 8kb cluster size when no information is available

    TInt drive(0);
    TInt err = fs.CharToDrive(aDriveLetter, drive);
    // get cluster size to calculate uncompressed widget size more accurately
    if (!err) {
        TVolumeIOParamInfo ioInfo;
        err = fs.VolumeIOParam(drive, ioInfo);

        // VolumeIOParam.iClusterSize contains also possible error code
        if (!err && ioInfo.iClusterSize > 0) {
            allocUnitSize = ioInfo.iClusterSize;
        }
    }

    QString zipFileName = QDir::toNativeSeparators(aZipFileName);

    TPtrC16 zName(reinterpret_cast<const TUint16*>(zipFileName.utf16()));
    CZipFile *zipfile = CZipFile::NewL(fs, zName);
    CleanupStack::PushL(zipfile);

    CZipFileMemberIterator *members = zipfile->GetMembersL();
    CleanupStack::PushL(members);

    CZipFileMember* member = members->NextL();
    while (member != NULL) {
        TUint32 fileSize(member->UncompressedSize());
        if(fileSize != UINT_MAX)
            fileSize = (fileSize + (allocUnitSize - (fileSize % allocUnitSize)));
        uncompressedSize += fileSize;
        delete member;
        member = members->NextL();
    }
    CleanupStack::PopAndDestroy(3);  // members, zipfile, fs.connect

    if(uncompressedSize > UINT_MAX)
        return UINT_MAX;
    return (TUint32)uncompressedSize;
}
/**
@SYMTestCaseID			PDS-SQL-UT-4141
@SYMTestCaseDesc		RFileBuf64::SetReadAheadSize() test.
						The test iterates over all existing drives.
						For each R/W drive a test file is created using RFileBuf64 class.
						Then the test collects information regarding the block size, cluster size and 
						read buffer size and calls RFileBuf64::SetReadAheadSize() with these parameters
						to check how the read-ahead buffer size will be recalculated.
@SYMTestActions			RFileBuf64::SetReadAheadSize() test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void SetReadAheadSizeTest()
	{
	TheTest.Printf(_L("==================\r\n"));
	_LIT(KType1, "Not present");
	_LIT(KType2, "Unknown");
	_LIT(KType3, "Floppy");
	_LIT(KType4, "Hard disk");
	_LIT(KType5, "CD ROM");
	_LIT(KType6, "RAM disk");
	_LIT(KType7, "Flash");
	_LIT(KType8, "ROM drive");
	_LIT(KType9, "Remote drive");
	_LIT(KType10,"NAND flash");
	_LIT(KType11,"Rotating media");
	
	for(TInt drive=EDriveA;drive<=EDriveZ;++drive)
		{
		TDriveInfo driveInfo;
		TInt err = TheFs.Drive(driveInfo, drive);
		if(err == KErrNone)
			{
			TVolumeInfo vinfo;
			err = TheFs.Volume(vinfo, drive);
			if(err == KErrNone)
				{
				TVolumeIOParamInfo vparam;
				err = TheFs.VolumeIOParam(drive, vparam);
				TEST2(err, KErrNone);
				TBuf8<128> vinfoex8;
				err = TheFs.QueryVolumeInfoExt(drive, EFileSystemSubType, vinfoex8);
				TEST2(err, KErrNone);
				TPtrC vinfoex((const TUint16*)(vinfoex8.Ptr() + 8), vinfoex8[0]);
				TPtrC KMediaTypeNames[] = {KType1(), KType2(), KType3(), KType4(), KType5(), KType6(), KType7(), KType8(), KType9(), KType10(), KType11()};
				TheTest.Printf(_L("Drive: %C:, Type: %16.16S, File System: %8.8S, Size: %d Mb.\r\n"), 'A' + drive, &KMediaTypeNames[driveInfo.iType], &vinfoex, (TInt)(vinfo.iSize / (1024 * 1024)));
				TheTest.Printf(_L("            Size: %ld bytes.\r\n"), vinfo.iSize);
				TheTest.Printf(_L("       Block size=%d, Cluster size=%d, Read buffer size=%d.\r\n"), vparam.iBlockSize, vparam.iClusterSize, vparam.iRecReadBufSize);
				if(driveInfo.iType == EMediaRam || driveInfo.iType == EMediaHardDisk || driveInfo.iType == EMediaFlash || driveInfo.iType == EMediaNANDFlash)
				  	{
					TDriveUnit drvUnit(drive);
					TDriveName drvName = drvUnit.Name();
					TParse parse;
					parse.Set(KTestFile2, &drvName, NULL);
					TheDbName.Copy(parse.FullName());
					TRAP(err, BaflUtils::EnsurePathExistsL(TheFs, TheDbName));
					if(err == KErrNone || err == KErrAlreadyExists)
						{
						(void)TheFs.Delete(TheDbName);
						RFileBuf64 fbuf64(8 * 1024);
						err = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite);
						TEST2(err, KErrNone);
						TInt readAhead = fbuf64.SetReadAheadSize(vparam.iBlockSize, vparam.iRecReadBufSize);
						TheTest.Printf(_L("       Read-ahead size=%d.\r\n"), readAhead);
						fbuf64.Close();
						(void)TheFs.Delete(TheDbName);
						}
					else
						{
						TheTest.Printf(_L("Drive %C. BaflUtils::EnsurePathExistsL() has failed with err=%d.\r\n"), 'A' + drive, err);	
						}
					}
				}
			else
				{
				TheTest.Printf(_L("Drive %C. RFs::Volume() has failed with err=%d.\r\n"), 'A' + drive, err);	
				}
			}
		else
			{
			TheTest.Printf(_L("Drive %C. RFs::Drive() has failed with err=%d.\r\n"), 'A' + drive, err);	
			}
		}
	TheTest.Printf(_L("==================\r\n"));
	//
	RFileBuf64 fbuf64(8 * 1024);//buffer capacity = 8Kb
	
	//"ReadRecBufSize" defined and is power of two, the "BlockSize" is also defined and is power of two
	TInt err2 = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	TInt blockSize = 4096; TInt readRecBufSize = 2048;
	TInt readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, readRecBufSize);
	fbuf64.Close();
	
	//"ReadRecBufSize" defined and is power of two but is less than the default read-ahead value
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = 0; readRecBufSize = 128;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
	fbuf64.Close();
	
	//"ReadRecBufSize" defined and is power of two but is bigger than the buffer capacity
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = -10; readRecBufSize = fbuf64.iCapacity * 2;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, fbuf64.iCapacity);
	fbuf64.Close();
	
	//"ReadRecBufSize" defined but is not power of two, "BlockSize" defined but is less than the default read-ahead value
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = 512; readRecBufSize = 4000;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
	fbuf64.Close();
	
	//"ReadRecBufSize" defined but is not power of two, "BlockSize" defined and is bigger than the default read-ahead value
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = 4096; readRecBufSize = 4000;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, blockSize);
	fbuf64.Close();

	//"ReadRecBufSize" defined but is not power of two, "BlockSize" defined and is bigger than the buffer capacity
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = fbuf64.iCapacity * 2; readRecBufSize = 1;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, fbuf64.iCapacity);
	fbuf64.Close();
	
	//"ReadRecBufSize" negative, "BlockSize" defined but is not power of two
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = 1000; readRecBufSize = -2;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
	fbuf64.Close();
	
	//"ReadRecBufSize" negative, "BlockSize" negative
	err2 = fbuf64.Open(TheFs, TheDbName, EFileRead | EFileWrite);
	TEST2(err2, KErrNone);
	blockSize = -1; readRecBufSize = -2;
	readAhead2 = fbuf64.SetReadAheadSize(blockSize, readRecBufSize);
	TEST2(readAhead2, RFileBuf64::KDefaultReadAheadSize);
	fbuf64.Close();
	//
	(void)TheFs.Delete(TheDbName);
	}