sl@0: // Copyright (c) 2004-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 "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: // TESTGENERATEFILEURIFORALLFILESSTEP.CPP sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: // Epoc Includes sl@0: // For File URI handler API sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // User Include sl@0: #include "TestForAllFilesStep.h" sl@0: sl@0: /** sl@0: Constructor. Sets the test step name sl@0: */ sl@0: CTestForAllFilesStep::CTestForAllFilesStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestForAllFilesStep); sl@0: } sl@0: sl@0: /** sl@0: Does the main functionality of a test step. Here just calls DoTestL. sl@0: @internalTechnology sl@0: @param None sl@0: @return EPass or EFail indicating the success or failure of the test step sl@0: */ sl@0: TVerdict CTestForAllFilesStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("\n")); sl@0: TRAPD(err, DoTestL()); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Leave occured in CTestForAllFilesStep::DoTestL: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: INFO_PRINTF1(_L("\n")); sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } // doTestStepL() sl@0: sl@0: /** sl@0: Scans all the directories and calls TestBothWaysL that tests the sl@0: creation of URI from a filename and vice versa for all the files. sl@0: */ sl@0: void CTestForAllFilesStep::DoTestL() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TBuf<4> rootDir; sl@0: CDirScan *dirScan = CDirScan::NewLC(fs); sl@0: TInt drive; sl@0: for(drive = EDriveA; drive <= EDriveZ; ++drive) sl@0: { sl@0: rootDir.Format(_L("%c:\\"), static_cast(KLetterA + drive)); sl@0: dirScan->SetScanDataL(rootDir, KEntryAttNormal, ESortNone); sl@0: CDir* entryList = NULL; sl@0: FOREVER sl@0: { sl@0: TRAPD(err, dirScan->NextL(entryList)); sl@0: if(err == KErrNotReady) sl@0: { sl@0: INFO_PRINTF2(_L("Drive %S not ready"), &rootDir); sl@0: break; sl@0: } sl@0: if (entryList==NULL) sl@0: { sl@0: break; sl@0: } sl@0: CleanupStack::PushL(entryList); sl@0: TFileName filename; sl@0: TInt index; sl@0: for(index = 0; index < entryList->Count(); ++index) sl@0: { sl@0: const TEntry& entry = (*entryList)[index]; sl@0: filename = dirScan->FullPath(); sl@0: filename.Append(entry.iName); sl@0: INFO_PRINTF1(_L("\n")); sl@0: INFO_PRINTF2(_L("The next file name in the dir-scan = %S"), &filename); sl@0: INFO_PRINTF1(_L("Calling 8-bit versions")); sl@0: sl@0: // To keep VC compiler happy as it does not support sl@0: // explicit template calls.Hence passing empty variables sl@0: // cUri8 and tUriParser8 sl@0: CUri8* cUri8 = NULL; sl@0: TUriParser8 tUriParser8; sl@0: TestBothWaysL(cUri8, tUriParser8, filename); sl@0: INFO_PRINTF1(_L("\n")); sl@0: INFO_PRINTF1(_L("Calling 16-bit versions")); sl@0: CUri16* cUri16 = NULL; sl@0: TUriParser16 tUriParser16; sl@0: TestBothWaysL(cUri16, tUriParser16, filename); sl@0: } sl@0: CleanupStack::PopAndDestroy(entryList); sl@0: } // FOREVER sl@0: } sl@0: fs.Close(); sl@0: CleanupStack::PopAndDestroy(dirScan); sl@0: } sl@0: } // DoTestL sl@0: sl@0: /** sl@0: Template function that calls CUri::CreateFileUriL to generate a URI and sl@0: calls TUriC::GetFileNameL() with this URI, to verify that the filename so got sl@0: is the same as the original one. sl@0: */ sl@0: template sl@0: void CTestForAllFilesStep::TestBothWaysL(CUriType*& cUri8Or16, TUriParserType& tUriParser8Or16, TFileName& aFileName) sl@0: { sl@0: TUint flags = KErrNone; sl@0: TDriveNumber driveNum; sl@0: TParse parser; sl@0: parser.Set(aFileName, 0, 0); sl@0: TBuf<1> drive = parser.Drive().Left(1); sl@0: drive.LowerCase(); sl@0: sl@0: CTestFileUriServer::GetDriveNumber(drive, driveNum); sl@0: TBool aResult; sl@0: TInt err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: if(aResult) sl@0: {// The drive is a removable drive sl@0: INFO_PRINTF1(_L("The drive is a removable drive")); sl@0: flags = EExtMedia; sl@0: } sl@0: sl@0: // Generate the URI sl@0: TRAPD(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, flags)); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured in CreateFileUriL: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL(cUri8Or16); sl@0: // Just in case, create a 16-bit heap desc and print. sl@0: HBufC16* tempBuf = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length()); sl@0: tempBuf->Des().Copy(cUri8Or16->Uri().UriDes()); sl@0: INFO_PRINTF2(_L("File URI returned by CreateFileUriL = %S"), tempBuf); sl@0: delete tempBuf; sl@0: sl@0: if(aResult) sl@0: { sl@0: TBuf<1> correctDrive; sl@0: err = CTestFileUriServer::FirstRemovableDriveWithSameFileName(aFileName, correctDrive); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured in FirstRemovableDriveWithSameFileName: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: correctDrive.LowerCase(); sl@0: if(correctDrive != drive) sl@0: { sl@0: aFileName.Replace(0, 1, correctDrive); sl@0: INFO_PRINTF1(_L("One more removable drive found with the same file name, but is ahead in alphabetical order")); sl@0: INFO_PRINTF2(_L("Hence the correct expected file name is %S"), aFileName); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Convert the URI to filename back again sl@0: HBufC16* returnedFileName = NULL; sl@0: sl@0: tUriParser8Or16.Parse(cUri8Or16->Uri().UriDes()); sl@0: TRAPD(err, returnedFileName = tUriParser8Or16.GetFileNameL()); sl@0: CleanupStack::PopAndDestroy(cUri8Or16); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured in GetFileNameL: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("The filename returned by GetFileNameL = %S"), returnedFileName); sl@0: sl@0: // Verify the result sl@0: aFileName.LowerCase(); sl@0: returnedFileName->Des().LowerCase(); sl@0: sl@0: if(returnedFileName->Compare(aFileName) != KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("The returned filename did not match the original filename. Result = INCORRECT")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("The returned filename is same as the original filename. Result = CORRECT")); sl@0: } sl@0: delete returnedFileName; sl@0: } sl@0: } sl@0: } sl@0: } // TestBothWaysL sl@0: sl@0: