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: #include sl@0: sl@0: // User Include sl@0: #include "TestGenerateFileUriStep.h" sl@0: sl@0: /** sl@0: Constructor. Sets the test step name sl@0: */ sl@0: CTestGenerateFileUriStep::CTestGenerateFileUriStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestGenerateFileUriStep); 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 GenerateFileUriAndCompareL sl@0: @param None sl@0: @return EPass or EFail indicating the success or failure of the test step sl@0: */ sl@0: TVerdict CTestGenerateFileUriStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("\n")); sl@0: // Get necessary information from INI file sl@0: TPtrC fileName; sl@0: TPtrC expectedFileUri; sl@0: TPtrC fileType; sl@0: TInt characterSet; sl@0: TPtrC drive; sl@0: sl@0: if(!GetStringFromConfig(ConfigSection(), KIniFileName, fileName ) || sl@0: !GetStringFromConfig(ConfigSection(), KIniExpectedFileUri, expectedFileUri ) || 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: ),&KIniFileName, &KIniExpectedFileUri, &KIniFileType, &KIniCharacterSet, &KIniDrive sl@0: ); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: {// No problem in reading values from INI file. Proceed. sl@0: TRAPD(err, DoTestL(fileName, expectedFileUri, fileType, drive, characterSet)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Leave occured in CTestGenerateFileUriStep::DoTestL: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: __UHEAP_MARKEND; sl@0: INFO_PRINTF1(_L("\n")); sl@0: return TestStepResult(); sl@0: } // doTestStepL() sl@0: sl@0: /** sl@0: Checks whether the drive is a removable drive. Populates the placeholder. sl@0: And calls ExtractFileNameAndCompareL. sl@0: */ sl@0: void CTestGenerateFileUriStep::DoTestL(const TPtrC& aFileName, const TPtrC& aExpectedFileUri, const TPtrC& aFileType, const TPtrC& aDrive, const TInt& aCharacterSet) sl@0: { sl@0: INFO_PRINTF2(_L("Character Set = %D"), aCharacterSet); sl@0: INFO_PRINTF2(_L("File name = %S"), &aFileName); sl@0: sl@0: // Eliminate any characters like colon, slash etc. sl@0: TPtrC drive(aDrive.Left(1)); sl@0: sl@0: TUint flags = KErrNone; sl@0: TDriveNumber driveNum; 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: drive.Set(KExtMedia()); sl@0: } sl@0: HBufC16* expectedUriWithDrive = NULL; sl@0: sl@0: // Fill the place holder if it exists sl@0: TRAPD(err, expectedUriWithDrive = CTestFileUriServer::CheckAndFillDriveNameL(aExpectedFileUri, drive)); 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: {// All preliminary operations OK so far, go ahead and perform the test. sl@0: CleanupStack::PushL(expectedUriWithDrive); sl@0: INFO_PRINTF2(_L("Expected File URI = %S"), expectedUriWithDrive); sl@0: if(aCharacterSet == KCharSet8) sl@0: { sl@0: CUri16* cUri8 = NULL; sl@0: GenerateFileUriAndCompareL(cUri8, aFileName, expectedUriWithDrive, flags, driveNum, aFileType); sl@0: } sl@0: else if(aCharacterSet == KCharSet16) sl@0: { sl@0: CUri16* cUri16 = NULL; sl@0: GenerateFileUriAndCompareL(cUri16, aFileName, expectedUriWithDrive, flags, driveNum, aFileType); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Invalid CharacterSet")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(expectedUriWithDrive); sl@0: } sl@0: } sl@0: } // DoTestL sl@0: sl@0: /** sl@0: Template function that calls the 8 or 16-bit version of sl@0: CreatePrivateFileUriL() or CreateFileUriL(), verifies the expected and sl@0: actual results and sets the test step result accordingly. sl@0: */ sl@0: template sl@0: void CTestGenerateFileUriStep::GenerateFileUriAndCompareL(CUriType*& cUri8Or16, const TPtrC& aFileName, HBufC16*& aExpectedFileUri8Or16, const TUint& aFlags, const TInt& aDriveNum, const TPtrC& aFileType) sl@0: { sl@0: TInt err = KErrNone; sl@0: sl@0: // Get the URI object sl@0: if(aFileType == KFileTypePrivate) sl@0: {// Call private version sl@0: TRAP(err, cUri8Or16 = CUriType::CreatePrivateFileUriL(aFileName, static_cast(aDriveNum), aFlags)); sl@0: sl@0: // Test it in case of NON-secure version too, but in that case sl@0: // the expected result is a Leave with KErrNotSupported. sl@0: } sl@0: else sl@0: {// Call non-private version sl@0: TRAP(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, aFlags)); sl@0: } sl@0: sl@0: 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 URI has been returned. Do the checking sl@0: sl@0: CleanupStack::PushL(cUri8Or16); sl@0: sl@0: // Construct a fully lowercase 16-bit version of the returned URI, so that we sl@0: // can do print, compare etc. sl@0: HBufC16* lowerCaseUri16 = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length()); sl@0: lowerCaseUri16->Des().Copy(cUri8Or16->Uri().UriDes()); sl@0: CleanupStack::PopAndDestroy(cUri8Or16); sl@0: sl@0: INFO_PRINTF2(_L("The returned URI = %S"), lowerCaseUri16); sl@0: sl@0: lowerCaseUri16->Des().LowerCase(); sl@0: sl@0: // Make expected URI too, fully lowercase sl@0: aExpectedFileUri8Or16->Des().LowerCase(); sl@0: sl@0: // Compare and set the verdict sl@0: if (lowerCaseUri16->Des() != aExpectedFileUri8Or16->Des()) sl@0: { sl@0: INFO_PRINTF1(_L("The returned and expected URIs did not match. Result = INCORRECT")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("The returned and expected URIs matched. Result = CORRECT")); sl@0: } sl@0: delete lowerCaseUri16; sl@0: } sl@0: } // GenerateFileUriAndCompareL() sl@0: