sl@0: // Copyright (c) 2007-2009 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 the License "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: // Implementation of the t_localtime test. This tests functionality introduced sl@0: // in CR1084 ie. That removable (in practice this means FAT) file systems sl@0: // can be made to use local time for timestamps. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: */ sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: sl@0: #include "t_localtime.h" sl@0: #include "t_server.h" sl@0: sl@0: RTest test(KTestGroupName); sl@0: sl@0: /** sl@0: Constructor for generic test. sl@0: @param aTest The RTest handle to use. sl@0: @param aDriveLetter The drive to be tested. sl@0: @param aBuild Specifies whether tests or being run under UDEB or UREL sl@0: */ sl@0: CLocalTimeTest::CLocalTimeTest(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild) sl@0: :iDriveLetter(aDriveLetter), iTest(aTest), iBuild(aBuild), iOriginalUseLocalTimeFlag(EFalse) sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Factory function for test. sl@0: @param aTest The RTest handle to use. sl@0: @param aDriveLetter The drive to be tested. sl@0: @param aBuild Specifies whether tests or being run under UDEB or UREL sl@0: @return A test object sl@0: */ sl@0: CLocalTimeTest* CLocalTimeTest::NewLC(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild) sl@0: { sl@0: CLocalTimeTest* self = new(ELeave) CLocalTimeTest(aTest, aDriveLetter, aBuild); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Connect the test to the File server sl@0: */ sl@0: void CLocalTimeTest::ConstructL() sl@0: { sl@0: User::LeaveIfError(iRFs.Connect() ); sl@0: iRFs.CharToDrive(iDriveLetter[0], iDrive); sl@0: sl@0: SetTestTypeL(); sl@0: if(iTestType !=ENoTest) sl@0: { sl@0: MakeTestPathL(); sl@0: sl@0: iTestFile = new (ELeave) CTestFile(KFile, &iRFs); sl@0: iTestFile->SetPath(iTestPath); sl@0: iTestFileRFs = new (ELeave) CTestFileRFs(KFile, &iRFs ); sl@0: iTestFileRFs->SetPath(iTestPath); sl@0: iTestDirectory = new (ELeave) CTestDirectory(KDirectory, &iRFs); sl@0: iTestDirectory->SetPath(iTestPath); sl@0: sl@0: if(iBuild==EUdeb) sl@0: iOriginalUseLocalTimeFlag=IsLocalTimeOnRemMediaL(); //store initial setting sl@0: } sl@0: sl@0: if(iTestType==EPositive) sl@0: iExpectedTimeStampOffset=KTimeOffset; sl@0: else sl@0: iExpectedTimeStampOffset=KNullTimeOffset; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: CLocalTimeTest::~CLocalTimeTest() sl@0: { sl@0: if(iTestType!=ENoTest && iBuild==EUdeb) //restore flag to original value sl@0: { sl@0: TRAPD(err, sl@0: { sl@0: if(iOriginalUseLocalTimeFlag) sl@0: LocalTimeForRemMediaOnL(); sl@0: else sl@0: LocalTimeForRemMediaOffL(); sl@0: } sl@0: ); sl@0: __ASSERT_ALWAYS(err==KErrNone, User::PanicUnexpectedLeave()); sl@0: } sl@0: sl@0: if(iTestFile) sl@0: delete iTestFile; sl@0: if(iTestFileRFs) sl@0: delete iTestFileRFs; sl@0: if(iTestDirectory) sl@0: delete iTestDirectory; sl@0: } sl@0: sl@0: /** sl@0: Check that the test can read and modify the flag within sl@0: the FAT or FAT32 plugin. sl@0: */ sl@0: void CLocalTimeTest::TestDebugInterfaceL() sl@0: { sl@0: iTest.Start(_L("Checking debug interface")); sl@0: sl@0: TBool localTimeEnabled(EFalse); sl@0: localTimeEnabled = IsLocalTimeOnRemMediaL(); sl@0: iTest.Printf(_L("Use localtime enable intially? %d\n"), localTimeEnabled); sl@0: sl@0: LocalTimeForRemMediaOffL(); sl@0: localTimeEnabled=IsLocalTimeOnRemMediaL(); sl@0: iTest.Next(_L("Disabling flag...")); sl@0: iTest(!localTimeEnabled); sl@0: sl@0: LocalTimeForRemMediaOnL(); sl@0: localTimeEnabled=IsLocalTimeOnRemMediaL(); sl@0: iTest.Next(_L("Enabling flag...")); sl@0: iTest(localTimeEnabled); sl@0: sl@0: iTest.End(); sl@0: } sl@0: sl@0: /** sl@0: Test that after creating a file or directory its creation time sl@0: has been offset (or not) as expected. sl@0: */ sl@0: void CLocalTimeTest::TestReadCreationTimeL(CFileSystemEntry* aFsEntry) sl@0: { sl@0: iTest.Next(_L("Read creation time")); sl@0: iTest.Printf(_L("Testing on %S"), &aFsEntry->Name()); sl@0: #if defined(_DEBUG) sl@0: LocalTimeForRemMediaOnL(); sl@0: TTime now; sl@0: test_KErrNone(aFsEntry->DeleteCreate()); sl@0: now.UniversalTime(); //hopefuly "now" will be within the 2-second error allowed. sl@0: sl@0: aFsEntry->Close(); sl@0: TTime creationTimeLocal = aFsEntry->CreationTimeL(); sl@0: sl@0: PrintTimeL(_L("Current UTC time"), now); sl@0: PrintExpectedOffset(); sl@0: sl@0: PrintTimeL(_L("creation time"), creationTimeLocal); sl@0: iTest(CLocalTimeTest::FuzzyTimeMatch(creationTimeLocal, now+iExpectedTimeStampOffset)); sl@0: sl@0: #else sl@0: test.Printf(_L("Creation times cannot be accessed in release build\n")); sl@0: sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: Test that when reading a modification time it has been translated (or not) sl@0: as expected. sl@0: @param aFsEntry A file or directory to be tested sl@0: */ sl@0: void CLocalTimeTest::TestReadModificationTimeL(CFileSystemEntry* aFsEntry) sl@0: { sl@0: TInt r= KErrNone; sl@0: iTest.Next(_L("Reading modification time - offset should be subtracted from timestamp ")); sl@0: iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name()); sl@0: LocalTimeForRemMediaOffL(); sl@0: r = aFsEntry->DeleteCreate(); sl@0: test_KErrNone(r); sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: PrintTimeL(_L("Current UTC time"), now); sl@0: //timestamp on disk will be UTC sl@0: r = aFsEntry->SetModificationTime(now); sl@0: test_KErrNone(r); sl@0: aFsEntry->Close(); sl@0: LocalTimeForRemMediaOnL(); sl@0: r = aFsEntry->Open(); sl@0: test_KErrNone(r); sl@0: sl@0: TTime modTime = aFsEntry->ModificationTimeL(); sl@0: test_KErrNone(r); sl@0: sl@0: PrintExpectedOffset(); sl@0: PrintTimeL(_L("modification time"), modTime); sl@0: iTest(CLocalTimeTest::FuzzyTimeMatch(modTime, now - iExpectedTimeStampOffset)); sl@0: aFsEntry->Close(); sl@0: } sl@0: sl@0: /** sl@0: Test that when setting a modification time it is modified as expected. sl@0: @param aFsEntry A file or directory to be tested sl@0: */ sl@0: void CLocalTimeTest::TestSetModificationTimeL(CFileSystemEntry* aFsEntry) sl@0: { sl@0: iTest.Next(_L("Setting modification time - offset should be added to timestamp")); sl@0: iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name()); sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: PrintTimeL(_L("Modification time set"), now); sl@0: LocalTimeForRemMediaOnL(); sl@0: TInt r = KErrNone; sl@0: r = aFsEntry->DeleteCreate(); sl@0: test_KErrNone(r); sl@0: sl@0: //timestamp on disk will be local sl@0: r = aFsEntry->SetModificationTime(now); sl@0: test_KErrNone(r); sl@0: aFsEntry->Close(); sl@0: sl@0: LocalTimeForRemMediaOffL(); sl@0: aFsEntry->Open(); sl@0: sl@0: TTime modTime = aFsEntry->ModificationTimeL(); sl@0: sl@0: PrintExpectedOffset(); sl@0: PrintTimeL(_L("Modification time read"), modTime); sl@0: iTest(CLocalTimeTest::FuzzyTimeMatch(modTime, now+iExpectedTimeStampOffset)); sl@0: sl@0: aFsEntry->Close(); sl@0: } sl@0: /** sl@0: Check that modification times of copied files are preserved sl@0: @param aFsEntry A file or directory to be tested sl@0: */ sl@0: void CLocalTimeTest::TestCopyL(CFileSystemEntry* aFsEntry) sl@0: { sl@0: LocalTimeForRemMediaOnL(); sl@0: sl@0: iTest.Next(_L("Test copying")); sl@0: iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name()); sl@0: aFsEntry->DeleteCreate(); sl@0: TTime mtime = aFsEntry->ModificationTimeL(); sl@0: PrintTimeL(_L("Original mtime"), mtime); sl@0: sl@0: sl@0: CFileSystemEntry* file2 = aFsEntry->CopyL(); sl@0: file2->Close(); sl@0: CleanupStack::PushL(file2); sl@0: sl@0: file2->Open(); sl@0: TTime mtime2 = file2->ModificationTimeL(); sl@0: sl@0: sl@0: iTest.Printf(_L("Modification times should be preserved\n")); sl@0: sl@0: PrintTimeL(_L("Copy's mtime"), mtime2 ); sl@0: iTest(FuzzyTimeMatch(mtime2, mtime) ); //mod time should always be preserved on copy sl@0: sl@0: CleanupStack::PopAndDestroy(file2); sl@0: aFsEntry->Close(); sl@0: } sl@0: sl@0: /** sl@0: Check that modification times of copied directories are preserved sl@0: */ sl@0: void CLocalTimeTest::TestCopyDirL() sl@0: { sl@0: LocalTimeForRemMediaOnL(); sl@0: sl@0: iTest.Next(_L("Test copying directory - modtimes should be preserved")); sl@0: _LIT(KSubDir, "SubDir\\"); sl@0: TPath parentDir(iTestPath); sl@0: parentDir+=KDirectory; sl@0: parentDir.Delete(parentDir.Length()-1, 1); sl@0: sl@0: TPath subDir(parentDir); sl@0: subDir.Append(KPathDelimiter); sl@0: subDir+=KSubDir; sl@0: sl@0: sl@0: TPath destDir(iTestPath); sl@0: destDir+=_L("copyDir"); sl@0: destDir.Append(KPathDelimiter); sl@0: sl@0: iRFs.RmDir(subDir); sl@0: iRFs.MkDirAll(subDir); sl@0: sl@0: TPath destSubDir(destDir); sl@0: destSubDir+=KSubDir; sl@0: iRFs.RmDir(destSubDir); sl@0: sl@0: CFileMan* fMan = CFileMan::NewL(iRFs); sl@0: CleanupStack::PushL(fMan ); sl@0: sl@0: sl@0: sl@0: fMan->Copy(parentDir, destDir , CFileMan::EOverWrite|CFileMan::ERecurse); sl@0: sl@0: TTime originalModtime; sl@0: TTime newDirModtime; sl@0: sl@0: test_KErrNone(iRFs.Modified(subDir, originalModtime) ); sl@0: test_KErrNone(iRFs.Modified(destSubDir, newDirModtime)); sl@0: PrintTimeL(_L("Orginal modtime"), originalModtime); sl@0: PrintTimeL(_L("Copy's modtime"), newDirModtime); sl@0: sl@0: iRFs.RmDir(subDir); sl@0: iRFs.RmDir(destSubDir); sl@0: sl@0: sl@0: iTest(FuzzyTimeMatch(originalModtime,newDirModtime) ); sl@0: sl@0: CleanupStack::PopAndDestroy(fMan); sl@0: } sl@0: sl@0: /** sl@0: Checks whether two times match, to a certain tolerance. By default allow for a 2 second error. sl@0: @param aTestTime One time sl@0: @param aRefTime Second time. sl@0: @return Whether the times matched. sl@0: */ sl@0: TBool CLocalTimeTest::FuzzyTimeMatch(const TTime& aTestTime, const TTime& aRefTime) sl@0: { sl@0: return(aTestTime>=(aRefTime-KModTimeThreshold) && aTestTime<=(aRefTime+KModTimeThreshold)); sl@0: } sl@0: sl@0: /** sl@0: If on UDEB will switch on the flag held in the CFatMountCB object to sl@0: use localtimes on removable media. sl@0: If on UREL will just set the UTC offset on. sl@0: */ sl@0: void CLocalTimeTest::LocalTimeForRemMediaOnL() sl@0: { sl@0: #if defined(_DEBUG) sl@0: User::LeaveIfError(iRFs.ControlIo(iDrive, ELocalTimeForRemovableMediaOn,NULL ,NULL) ); sl@0: #else sl@0: User::SetUTCOffset(KTimeOffset); sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: If on UDEB will switch off the flag held in the CFatMountCB object to sl@0: use localtimes on removable media. sl@0: If on UREL will just set the UTC offset to nothing, sl@0: so that no time conversions are carried out. sl@0: */ sl@0: void CLocalTimeTest::LocalTimeForRemMediaOffL() sl@0: { sl@0: sl@0: #if defined(_DEBUG) sl@0: User::LeaveIfError(iRFs.ControlIo(iDrive, ELocalTimeForRemovableMediaOff,NULL ,NULL) ); sl@0: #else sl@0: User::SetUTCOffset(KNullTimeOffset); sl@0: #endif sl@0: } sl@0: sl@0: TBool CLocalTimeTest::IsLocalTimeOnRemMediaL() sl@0: { sl@0: #if defined(_DEBUG) sl@0: TBool flag(EFalse); sl@0: TPckg flagPckg(flag); sl@0: User::LeaveIfError( iRFs.ControlIo(iDrive, ELocalTimeUsedOnRemovableMedia, flagPckg) ); sl@0: return flagPckg(); sl@0: #else sl@0: return( User::UTCOffset()==KTimeOffset ); sl@0: #endif sl@0: } sl@0: sl@0: void CLocalTimeTest::SetTestTypeL() sl@0: { sl@0: TDriveInfo info; sl@0: sl@0: TFSName fileSystem; sl@0: TInt err; sl@0: err = iRFs.FileSystemName(fileSystem, iDrive); sl@0: sl@0: User::LeaveIfError(err); sl@0: sl@0: //not currently testing on urel due to lack of support for configuration file/estart.txt managment sl@0: if(iBuild==EUrel) sl@0: { sl@0: iTestType=ENoTest; sl@0: return; sl@0: } sl@0: sl@0: if(fileSystem != KFatFileSystem) sl@0: { sl@0: iTestType=ENoTest; sl@0: return; sl@0: } sl@0: err = iRFs.Drive(info, iDrive); sl@0: User::LeaveIfError(err); sl@0: sl@0: if(info.iDriveAtt&KDriveAttRemovable) sl@0: { sl@0: iTestType=EPositive; sl@0: } sl@0: else sl@0: { sl@0: iTestType=ENegative; sl@0: } sl@0: return; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @return Drive letter being tested sl@0: */ sl@0: const TDesC& CLocalTimeTest::DriveLetter() const sl@0: { sl@0: return iDriveLetter; sl@0: } sl@0: /** sl@0: @return Drive number of test. sl@0: */ sl@0: TInt CLocalTimeTest::DriveNumber() const sl@0: { sl@0: return iDrive; sl@0: } sl@0: sl@0: /** sl@0: Print the drive number and letter of the test to the RTest console. sl@0: */ sl@0: void CLocalTimeTest::PrintDrive() const sl@0: { sl@0: TFSName fileSystem; sl@0: TInt err; sl@0: err = iRFs.FileSystemSubType(iDrive, fileSystem); sl@0: test_KErrNone(err); sl@0: test.Printf(_L("Using drive %d %S: Fs Type: %S\n"), DriveNumber(), &DriveLetter(), &fileSystem ); sl@0: } sl@0: sl@0: void CLocalTimeTest::PrintExpectedOffset() const sl@0: { sl@0: iTest.Printf(_L("Expected offset: %d hours\n"), iExpectedTimeStampOffset.Int()/KSecondsPerHour); sl@0: } sl@0: sl@0: /** sl@0: Create directories for the test if necessary. sl@0: */ sl@0: void CLocalTimeTest::MakeTestPathL() sl@0: { sl@0: iTestPath.Append(iDriveLetter); sl@0: iTestPath.Append(KDriveDelimiter); sl@0: iTestPath.Append(KPathDelimiter); sl@0: iTestPath.Append(KTestDir); sl@0: iTestPath.Append(KPathDelimiter); sl@0: sl@0: TInt err=iRFs.MkDirAll(iTestPath); sl@0: if(err!=KErrNone && err!=KErrAlreadyExists) sl@0: User::Leave(err); sl@0: iRFs.SetSessionPath(iTestPath); sl@0: } sl@0: sl@0: void CLocalTimeTest::PrintTimeL(const TDesC& aMessg, const TTime& aTime) const sl@0: { sl@0: TBuf<32> timeBuf; sl@0: _LIT(KTimeFormat, "%F%H:%T:%S"); sl@0: aTime.FormatL(timeBuf, KTimeFormat); sl@0: sl@0: iTest.Printf(_L("%S: %S\n"), &aMessg, &timeBuf); sl@0: } sl@0: sl@0: sl@0: /** sl@0: A callback function passed into a TCleanupItem to restore the system's UTC offset at the end sl@0: of the test. sl@0: */ sl@0: void RestoreOffset(TAny* aOffset) sl@0: { sl@0: User::SetUTCOffset(*static_cast(aOffset) ); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: //////////////////////////////////////////////// sl@0: //////////CFileSystemEntry///////////////////// sl@0: //////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @param aPath Name or full path for entry. sl@0: @param aFs the RFs handle to be used. sl@0: */ sl@0: CFileSystemEntry::CFileSystemEntry(const TDesC& aPath, RFs* aFs ) sl@0: : iRFs(aFs), iFullPath(aPath) sl@0: { sl@0: } sl@0: sl@0: CFileSystemEntry::~CFileSystemEntry() sl@0: {} sl@0: sl@0: /** sl@0: Prepends a path to the existing name or path. sl@0: @param aPath The path to use. sl@0: */ sl@0: void CFileSystemEntry::SetPath(const TDesC& aPath) sl@0: { sl@0: iFullPath.Insert(0, aPath); sl@0: } sl@0: sl@0: void CFileSystemEntry::SetFileServer(RFs* aFs) sl@0: { sl@0: iRFs = aFs; sl@0: } sl@0: sl@0: /** sl@0: Close and delete the entry. sl@0: @return An error code indicating success or failure. sl@0: */ sl@0: TInt CFileSystemEntry::Delete() sl@0: { sl@0: Close(); sl@0: return iRFs->Delete(iFullPath); sl@0: } sl@0: sl@0: /** sl@0: Delete and then make a new file/directory of the same name sl@0: @return An error code indicating success or failure. sl@0: */ sl@0: TInt CFileSystemEntry::DeleteCreate() sl@0: { sl@0: Delete(); sl@0: return Create(); sl@0: } sl@0: sl@0: void CFileSystemEntry::Close() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: @return The creation time of the entry. sl@0: */ sl@0: TTime CFileSystemEntry::CreationTimeL() sl@0: { sl@0: TParsePtrC parse(iFullPath); sl@0: //check there is a drive specified sl@0: if(!parse.DrivePresent() ) sl@0: User::Panic(KTestGroupName, KErrBadName); sl@0: sl@0: TInt driveNumber(0); sl@0: User::LeaveIfError(iRFs->CharToDrive(parse.Drive()[0], driveNumber) ); sl@0: sl@0: TBuf8 narrowPath; sl@0: narrowPath.Copy(parse.Path() ); sl@0: narrowPath.Append(parse.NameAndExt() ); sl@0: sl@0: //remove trailing slash if present sl@0: if(narrowPath[narrowPath.Length()-1]==KPathDelimiter) sl@0: narrowPath.Delete(narrowPath.Length()-1, 1); sl@0: sl@0: TTime creationTime=0; sl@0: TPckg timePckg(creationTime); sl@0: sl@0: User::LeaveIfError(iRFs->ControlIo(driveNumber, ECreationTime, narrowPath, timePckg) ); sl@0: sl@0: return timePckg(); sl@0: } sl@0: sl@0: const TDesC& CFileSystemEntry::Name() const sl@0: { sl@0: return iName; sl@0: } sl@0: sl@0: sl@0: //////////////////////////////////////////////// sl@0: //////////CTestDirectory//////////////////////// sl@0: //////////////////////////////////////////////// sl@0: sl@0: CTestDirectory::CTestDirectory(const TDesC& aPath, RFs* aFs) sl@0: :CFileSystemEntry(aPath, aFs) sl@0: { sl@0: iName.Set(KTestDirectoryName); sl@0: } sl@0: sl@0: TInt CTestDirectory::Open() sl@0: { sl@0: return KErrNone; //directories can't be opened. sl@0: } sl@0: sl@0: TInt CTestDirectory::Create() sl@0: { sl@0: return iRFs->MkDir(iFullPath); sl@0: } sl@0: sl@0: TInt CTestDirectory::Delete() sl@0: { sl@0: return iRFs->RmDir(iFullPath ); sl@0: } sl@0: sl@0: TTime CTestDirectory::ModificationTimeL() sl@0: { sl@0: TTime time; sl@0: User::LeaveIfError( iRFs->Modified(iFullPath, time) ); sl@0: return time; sl@0: } sl@0: TInt CTestDirectory::SetModificationTime(const TTime& aTime) sl@0: { sl@0: return iRFs->SetModified(iFullPath, aTime); sl@0: } sl@0: CFileSystemEntry* CTestDirectory::CopyL() sl@0: { sl@0: return NULL; sl@0: } sl@0: sl@0: sl@0: //////////////////////////////////////////////// sl@0: //////////CTestFile///////////////////////////// sl@0: //////////////////////////////////////////////// sl@0: sl@0: CTestFile::CTestFile(const TDesC& aPath, RFs* aFs) sl@0: :CFileSystemEntry(aPath, aFs) sl@0: { sl@0: iName.Set(KTestFileRFile); sl@0: } sl@0: sl@0: CTestFile::~CTestFile() sl@0: { sl@0: Close(); sl@0: } sl@0: sl@0: TInt CTestFile::Open() sl@0: { sl@0: return iRFile.Open(*iRFs, iFullPath, EFileShareExclusive|EFileWrite); sl@0: } sl@0: sl@0: TInt CTestFile::Create() sl@0: { sl@0: return iRFile.Replace(*iRFs, iFullPath, EFileShareExclusive|EFileWrite); sl@0: } sl@0: void CTestFile::Close() sl@0: { sl@0: iRFile.Close(); sl@0: } sl@0: sl@0: TTime CTestFile::ModificationTimeL() sl@0: { sl@0: TTime time; sl@0: User::LeaveIfError(iRFile.Modified(time) ); sl@0: return time; sl@0: } sl@0: sl@0: TInt CTestFile::SetModificationTime(const TTime& aTime) sl@0: { sl@0: return iRFile.SetModified(aTime); sl@0: } sl@0: sl@0: CFileSystemEntry* CTestFile::CopyL() sl@0: { sl@0: CFileMan* fMan = CFileMan::NewL(*iRFs); sl@0: CleanupStack::PushL(fMan); sl@0: sl@0: TFileName newName(iFullPath); sl@0: newName.Append(_L("~")); sl@0: CFileSystemEntry* copy= new(ELeave) CTestFile(newName, iRFs); sl@0: CleanupStack::PushL(copy); sl@0: copy->Delete(); //delete anything at the path already sl@0: Close(); sl@0: User::LeaveIfError(fMan->Copy(iFullPath,newName) ); sl@0: sl@0: CleanupStack::Pop(copy); sl@0: CleanupStack::PopAndDestroy(fMan); sl@0: return copy; sl@0: } sl@0: sl@0: //////////////////////////////////////////////// sl@0: ////////////CTestFileRFs//////////////////////// sl@0: //////////////////////////////////////////////// sl@0: CTestFileRFs::CTestFileRFs(const TDesC& aPath, RFs* aFs) : CTestFile(aPath, aFs) sl@0: { sl@0: iName.Set(KTestFileRFs); sl@0: } sl@0: TTime CTestFileRFs::ModificationTimeL() sl@0: { sl@0: TBool isOpen=KErrNone; sl@0: test_KErrNone(iRFs->IsFileOpen(iFullPath, isOpen)); sl@0: if(isOpen) sl@0: Close(); sl@0: TTime time; sl@0: User::LeaveIfError(iRFs->Modified(iFullPath,time) ); sl@0: if(isOpen) sl@0: Open(); sl@0: return time; sl@0: sl@0: } sl@0: sl@0: TInt CTestFileRFs::SetModificationTime(const TTime& aTime) sl@0: { sl@0: TBool isOpen=KErrNone; sl@0: test_KErrNone(iRFs->IsFileOpen(iFullPath, isOpen)); sl@0: if(isOpen) sl@0: Close(); sl@0: TInt err = iRFs->SetModified(iFullPath, aTime); sl@0: if(isOpen) sl@0: Open(); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: CTestFileRFs::~CTestFileRFs() sl@0: { sl@0: Close(); sl@0: } sl@0: sl@0: sl@0: //////////////////////////////////////////////////// sl@0: //////////Entry point and main////////////////////// sl@0: //////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: Construct and run the various tests. sl@0: */ sl@0: void CallTestsL() sl@0: { sl@0: test.Start(KTestGroupName); sl@0: #if defined(_DEBUG) sl@0: CLocalTimeTest::TBuild build = CLocalTimeTest::EUdeb; sl@0: #else sl@0: CLocalTimeTest::TBuild build = CLocalTimeTest::EUrel; sl@0: #endif sl@0: TPtrC drive((TUint16*)&gDriveToTest, 1); sl@0: sl@0: CLocalTimeTest* timeTest= CLocalTimeTest::NewLC(test, drive , build); sl@0: timeTest->RunTestsL(); sl@0: CleanupStack::PopAndDestroy(timeTest); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void CLocalTimeTest::RunTestsL() sl@0: { sl@0: PrintDrive(); sl@0: if(iTestType==ENoTest) sl@0: { sl@0: iTest.Printf(_L("Not runnning tests on this drive\n")); sl@0: return; sl@0: } sl@0: sl@0: iTest.Start(_L("Running tests")); sl@0: sl@0: //Be able to restore to original timezone after test sl@0: TTimeIntervalSeconds savedUTCOffset = User::UTCOffset(); sl@0: TCleanupItem restoreOffset(RestoreOffset, &savedUTCOffset); sl@0: CleanupStack::PushL(restoreOffset); sl@0: sl@0: //This functionallity must be tested with a non-zero GMT offset. sl@0: test.Printf(_L("Setting UTC offset to %d hours\n"), KHoursOffset); sl@0: User::SetUTCOffset(KTimeOffset); sl@0: sl@0: if(iBuild==EUdeb) sl@0: iTest.Printf(_L("Testing on UDEB build\n")); sl@0: else if(iBuild==EUrel) sl@0: iTest.Printf(_L("Testing on UREL build\n")); sl@0: sl@0: if(iTestType==EPositive) sl@0: iTest.Printf(_L("Drive is removable, running positive tests\n")); sl@0: else if(iTestType==ENegative) sl@0: iTest.Printf(_L("Drive is non-removable, running negative tests\n")); sl@0: sl@0: sl@0: if(iBuild==EUdeb) //these tests cannot be used without ControlIO sl@0: { sl@0: TestDebugInterfaceL(); sl@0: TestReadCreationTimeL(iTestFile); sl@0: TestReadCreationTimeL(iTestFileRFs); sl@0: TestReadCreationTimeL(iTestDirectory); sl@0: } sl@0: sl@0: TestReadModificationTimeL(iTestFile); sl@0: TestReadModificationTimeL(iTestFileRFs); sl@0: TestReadModificationTimeL(iTestDirectory); sl@0: sl@0: TestSetModificationTimeL(iTestFile); sl@0: TestSetModificationTimeL(iTestFileRFs); sl@0: TestSetModificationTimeL(iTestDirectory); sl@0: sl@0: TestCopyL(iTestFile); sl@0: TestCopyL(iTestFileRFs); sl@0: TestCopyDirL(); sl@0: sl@0: CleanupStack::PopAndDestroy(&savedUTCOffset); sl@0: iTest.End(); sl@0: }