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: // 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: sl@0: // User Include sl@0: #include "TestGetFileNameFromUriStep.h" sl@0: sl@0: /** sl@0: Constructor. Sets the test step name sl@0: */ sl@0: CTestGetFileNameFromUriStep::CTestGetFileNameFromUriStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestGetFileNameFromUriStep); sl@0: } sl@0: sl@0: /** sl@0: Does the main functionality of a test step. sl@0: Here, reads values from INI file and calls DoTestL sl@0: @internalTechnology sl@0: @see ExtractFileNameAndCompareL sl@0: @param None sl@0: @return EPass or EFail indicating the success or failure of the test step sl@0: */ sl@0: TVerdict CTestGetFileNameFromUriStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("\n")); sl@0: // Get necessary information from INI file sl@0: TPtrC fileUri; sl@0: TPtrC expectedFileName; sl@0: TPtrC fileType; sl@0: TPtrC drive; sl@0: TInt characterSet; sl@0: sl@0: if(!GetStringFromConfig(ConfigSection(), KIniFileUri, fileUri ) || sl@0: !GetStringFromConfig(ConfigSection(), KIniExpectedFileName, expectedFileName) || sl@0: !GetStringFromConfig(ConfigSection(), KIniFileType, fileType ) || sl@0: !GetIntFromConfig (ConfigSection(), KIniCharacterSet, characterSet ) || sl@0: !GetStringFromConfig(ConfigSection(), KIniDrive, drive ) sl@0: ) sl@0: { sl@0: ERR_PRINTF6(_L("Problem in reading values from ini. \ sl@0: \nExpected fields are: \n%S\n%S\n%S\n%S\n%S\n" sl@0: ),&KIniFileUri, &KIniExpectedFileName, &KIniFileType, &KIniCharacterSet, &KIniDrive sl@0: ); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TRAPD(err, DoTestL(fileUri, expectedFileName, fileType, drive, characterSet)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Leave occured in CTestGetFileNameFromUriStep::DoTestL: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } 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: Constructs fully-qualified filename in case of a private file, checks whether the sl@0: drive is a removable drive. Populates the placeholder and calls sl@0: ExtractFileNameAndCompareL. sl@0: */ sl@0: void CTestGetFileNameFromUriStep::DoTestL(const TPtrC& aFileUri, const TPtrC& aExpectedFileName, const TPtrC& aFileType, TPtrC& aDrive, const TInt& aCharacterSet) sl@0: { sl@0: TInt err = KErrNone; sl@0: TFileName fullyQualifiedName(aExpectedFileName); sl@0: TBool fileNotFound = EFalse; sl@0: sl@0: if(aFileType == KFileTypePrivate) sl@0: {// The file is a private file sl@0: // In the case of a secure vesrion of the OS sl@0: // As the INI file contains relative file-name for private files sl@0: // under the ExpectedFileName field, construct the fully-qualified sl@0: // expected file-name sl@0: if((err = CTestFileUriServer::CreateFullyQualifiedName(aExpectedFileName, aDrive, fullyQualifiedName)) != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: return; sl@0: } sl@0: } sl@0: sl@0: // Check whether drive is removable drive sl@0: TDriveNumber driveNum; sl@0: CTestFileUriServer::GetDriveNumber(aDrive, driveNum); sl@0: TBool aResult; sl@0: 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: sl@0: // Check if any other drive contains a file of the same path and name sl@0: // but comes ahead in the alphabetical order. If yes, that is the correct sl@0: // expected file name sl@0: TBuf<1> correctDrive; sl@0: err = CTestFileUriServer::FirstRemovableDriveWithSameFileName(fullyQualifiedName, 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 if(correctDrive == KNullDesC) sl@0: { sl@0: INFO_PRINTF1(_L("File not found on removable drive")); sl@0: fileNotFound = ETrue; sl@0: } sl@0: else sl@0: { sl@0: correctDrive.LowerCase(); sl@0: TBuf<1> drive = aDrive; sl@0: drive.LowerCase(); sl@0: if(correctDrive != drive) sl@0: { sl@0: fullyQualifiedName.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"), fullyQualifiedName); sl@0: } sl@0: } sl@0: aDrive.Set(KExtMedia()); sl@0: } sl@0: HBufC16* uriWithDrive = NULL; sl@0: sl@0: // Fill the place holder if it exists sl@0: TRAPD(err, uriWithDrive = CTestFileUriServer::CheckAndFillDriveNameL(aFileUri, aDrive)); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured while filling the drive-placeholder: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL(uriWithDrive); sl@0: INFO_PRINTF2(_L("Character Set = %D"), aCharacterSet); sl@0: INFO_PRINTF2(_L("File URI = %S"), uriWithDrive); sl@0: INFO_PRINTF2(_L("Expected Filename = %S"), &fullyQualifiedName); sl@0: fullyQualifiedName.LowerCase(); sl@0: sl@0: // Call template function based on the characterset. sl@0: if(aCharacterSet == KCharSet8) sl@0: { sl@0: TUriParser16 uriParser8; sl@0: HBufC16* hBufC8 = NULL; sl@0: ExtractFileNameAndCompareL(uriParser8, hBufC8, uriWithDrive->Des(), fullyQualifiedName, aFileType, fileNotFound); sl@0: } sl@0: else if(aCharacterSet == KCharSet16) sl@0: { sl@0: TUriParser16 uriParser16; sl@0: HBufC16* hBufC16 = NULL; sl@0: ExtractFileNameAndCompareL(uriParser16, hBufC16, uriWithDrive->Des(), fullyQualifiedName, aFileType, fileNotFound); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Invalid CharacterSet")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(uriWithDrive); sl@0: } sl@0: } sl@0: } // DoTestL sl@0: sl@0: /** sl@0: Template function that calls TUriC::GetFileNameL() after processing sl@0: an 8-bit or 16-bit version of a URI, verifies the expected and sl@0: actual results and sets the test step result accordingly. sl@0: */ sl@0: template sl@0: void CTestGetFileNameFromUriStep::ExtractFileNameAndCompareL(TUriParserType& uriParser8Or16, HBufCType*& fileUri8Or16, const TPtrC& aFileUri, const TFileName& aFullyQualifiedName, const TPtrC& aFileType, const TBool& aFileNotFound) sl@0: { sl@0: fileUri8Or16 = HBufCType::NewLC(aFileUri.Length()); sl@0: fileUri8Or16->Des().Copy(aFileUri); sl@0: uriParser8Or16.Parse(*fileUri8Or16); sl@0: sl@0: // The actual API being tested sl@0: HBufC16* fileName16 = NULL; sl@0: TRAPD(err, fileName16 = uriParser8Or16.GetFileNameL()); sl@0: CleanupStack::PopAndDestroy(fileUri8Or16); sl@0: sl@0: if(aFileType == KFileTypePrivate) sl@0: { sl@0: } sl@0: sl@0: if(aFileNotFound) sl@0: {// aFileNotFound is true when the file is not found on removable drive sl@0: if(err == KErrNotFound || err == KErrPathNotFound) sl@0: { sl@0: INFO_PRINTF2(_L("Leave occured = %D. This is expected if file is not found on removable drive"), err); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Unexpected result = %D when file is not found on removable drive"), err); sl@0: SetTestStepResult(EFail); sl@0: if(fileName16 != NULL) sl@0: { sl@0: INFO_PRINTF2(_L("File name returned = %S"), fileName16); sl@0: delete fileName16; sl@0: } sl@0: } sl@0: } sl@0: else if(err != KErrNone) sl@0: {// If it comes here, it means there's some problem. But some tests sl@0: // expect an error. So just set the error, and leave the decision sl@0: // to TEF sl@0: ERR_PRINTF2(_L("Leave occured: %D"), err); sl@0: SetTestStepError(err); sl@0: } sl@0: else sl@0: {// Things seem to be OK and a file-name has been returned. sl@0: // Do the checking sl@0: sl@0: INFO_PRINTF2(_L("Returned Filename = %S"), fileName16); sl@0: sl@0: fileName16->Des().LowerCase(); sl@0: sl@0: // Compare and set the verdict sl@0: if((fileName16->Des() != aFullyQualifiedName)) sl@0: { sl@0: INFO_PRINTF1(_L("The returned filename did not match the expected filename. Result = INCORRECT")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("The returned filename is the same as the expected filename. Result = CORRECT")); sl@0: } sl@0: sl@0: delete fileName16; sl@0: } sl@0: } // ExtractFileNameAndCompareL() sl@0: sl@0: