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 "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: // Contains implementation of CTestNormaliseUriStep class sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file TESTNORMALISEURISTEP.CPP sl@0: @internalTechnology sl@0: */ sl@0: sl@0: // User Include sl@0: #include "TestNormaliseUriStep.h" sl@0: // System Include sl@0: #include sl@0: #include sl@0: sl@0: //constants sl@0: const TInt KAlreadyNormalised = 0; sl@0: const TInt KPercentEncoding = 1; sl@0: const TInt KCaseNormalisation = 2; sl@0: const TInt KRemoveDotegments = 3; sl@0: const TInt KPercentCaseNormalisation = 12; sl@0: const TInt KPercentRemoveDotegments = 13; sl@0: const TInt KCaseRemoveDotegments = 23; sl@0: const TInt KAll = 123; sl@0: sl@0: /** sl@0: Constructor: Sets the test step name. sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestNormaliseUriStep::CTestNormaliseUriStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestNormaliseUriStep); sl@0: } sl@0: sl@0: /** sl@0: Destructor sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestNormaliseUriStep::~CTestNormaliseUriStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Does the main functionality test. sl@0: Here, reads values from INI file and calls NormaliseAndCompareUriL 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 CTestNormaliseUriStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("\n")); sl@0: // Get necessary information from INI file sl@0: sl@0: TPtrC uri; sl@0: TPtrC expUri; sl@0: TInt RetCode; sl@0: sl@0: if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) || sl@0: !GetStringFromConfig(ConfigSection(), KIniExpectedUri, expUri) || sl@0: !GetIntFromConfig(ConfigSection(), KRetCode, RetCode) ) sl@0: { sl@0: ERR_PRINTF3(_L("Problem in reading values from ini. \ sl@0: \nExpected fields are: \n%S\n%S\n"),&KIniUri, &KIniExpectedUri); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: {// No problem in reading values from INI file. Proceed. sl@0: TRAPD(err, NormaliseAndCompareUriL(uri,expUri)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Test step failed: Leave occured in NormaliseAndCompareUriL fun: %D\n"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: __UHEAP_MARKEND; sl@0: switch (RetCode) sl@0: { sl@0: case KAlreadyNormalised : sl@0: { sl@0: INFO_PRINTF1(_L("\nAlready in Normalised Form")); sl@0: break; sl@0: } sl@0: case KPercentEncoding : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through PercentEncoding")); sl@0: break; sl@0: } sl@0: case KCaseNormalisation : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through CaseNormalisation")); sl@0: break; sl@0: } sl@0: case KRemoveDotegments : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through RemoveDotegments")); sl@0: break; sl@0: } sl@0: case KPercentCaseNormalisation : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through PercentEncoding and CaseNormalisation")); sl@0: break; sl@0: } sl@0: case KPercentRemoveDotegments : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through PercentEncoding and RemoveDotegments")); sl@0: break; sl@0: } sl@0: case KCaseRemoveDotegments : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through CaseNormalisation and RemoveDotegments")); sl@0: break; sl@0: } sl@0: case KAll : sl@0: { sl@0: INFO_PRINTF1(_L("\nNormalised through CaseNormalisation,PercentEncoding and RemoveDotegments")); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: //do nothing sl@0: break; sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("\nTest of UriNormalisation is Executed\n")); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Performs syntax normalisation and compares actual & expected result. sl@0: @param aUri A reference to actual Uri to be normalised sl@0: @param aExpUri A reference to expected uri. sl@0: */ sl@0: void CTestNormaliseUriStep::NormaliseAndCompareUriL(const TDesC& aUri,const TDesC& aExpUri) sl@0: { sl@0: CUri8* cUri8=NULL; sl@0: TRAPD(err, cUri8=UriUtils::CreateUriL(aUri)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: const TUriC8& tUri(cUri8->Uri()); sl@0: CUri8* normalisedUri = NULL; sl@0: CleanupStack::PushL(cUri8); sl@0: INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation.")); sl@0: TRAPD(error, normalisedUri=UriUtils::NormaliseUriL(tUri)); sl@0: if(error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("URI normalised.")); sl@0: CleanupStack::PushL(normalisedUri); sl@0: HBufC8* uriBuf = HBufC8::NewLC(aExpUri.Length()); sl@0: TPtr8 expUri8(uriBuf->Des()); sl@0: expUri8.Copy(aExpUri); sl@0: // Comparing actual & expected uris. sl@0: if(normalisedUri->Uri().UriDes().Compare(expUri8)!=0) sl@0: { sl@0: ERR_PRINTF1(_L("Test step failed: actualUri is not matched with expectedUri.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(3, cUri8); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: Constructor: Sets the test step name. sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestNormaliseUriOomStep::CTestNormaliseUriOomStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestOomNormaliseUriStep); sl@0: } sl@0: sl@0: /** sl@0: Destructor sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestNormaliseUriOomStep::~CTestNormaliseUriOomStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Does the main functionality and OOM test of a test step. 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 CTestNormaliseUriOomStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: TPtrC uri; sl@0: if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) ) sl@0: { sl@0: ERR_PRINTF2(_L("Problem in reading values from ini. \ sl@0: \nExpected fields are: \n%S\n"),&KIniUri); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: {// No problem in reading values from INI file. Proceed. sl@0: CUri8* cUri8=NULL; sl@0: TRAPD(err, cUri8=UriUtils::CreateUriL(uri)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: const TUriC8& tUri(cUri8->Uri()); sl@0: CleanupStack::PushL(cUri8); sl@0: INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation.")); sl@0: TInt ret = KErrNoMemory; sl@0: TInt failAt = 0; sl@0: while(ret != KErrNone) sl@0: { sl@0: failAt++; sl@0: INFO_PRINTF2(_L("OOM test step: %d\n"),failAt); sl@0: sl@0: __UHEAP_SETFAIL( RHeap::EDeterministic, failAt ); sl@0: __UHEAP_MARK; sl@0: CUri8* normalisedUri = NULL; sl@0: TRAP( ret, normalisedUri = UriUtils::NormaliseUriL(tUri)); sl@0: delete normalisedUri; sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: if((ret == KErrNoMemory) || (ret == KErrNone)) sl@0: { sl@0: INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(cUri8); sl@0: } sl@0: } sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: