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 CTestTelUriParsingStep class sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: // User Include sl@0: #include "TestTelUriParsingStep.h" sl@0: // System Include sl@0: #include sl@0: #include sl@0: sl@0: /** sl@0: Constructor: Sets the test step name. sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestTelUriParsingStep::CTestTelUriParsingStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestTelUriParsingStep); sl@0: } sl@0: sl@0: /** sl@0: Destructor sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: CTestTelUriParsingStep::~CTestTelUriParsingStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Does the main functionality of a test step. sl@0: Here, reads values from INI file sl@0: and calls TestTelUriParsingAndCompareL() which does parsing of a tel uri. 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 CTestTelUriParsingStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("\n")); sl@0: // Get necessary information from INI file sl@0: TPtrC telUri; sl@0: TPtrC expTelScheme; sl@0: TPtrC expTelPath; sl@0: sl@0: if(!GetStringFromConfig(ConfigSection(), KIniUri, telUri) || sl@0: !GetStringFromConfig(ConfigSection(), KIniExpectedTelScheme, expTelScheme) || sl@0: !GetStringFromConfig(ConfigSection(), KIniExpectedTelPath, expTelPath) ) sl@0: { sl@0: ERR_PRINTF4(_L("Problem in reading values from ini. \ sl@0: \nExpected fields are: \n%S\n%S\n%S\n" sl@0: ),&KIniUri, &KIniExpectedTelScheme, &KIniExpectedTelPath sl@0: ); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: // No problem in reading values from INI file. Proceed. sl@0: // Calling TestTelUriParsingL which does parisng of tel uri and comparing results. sl@0: TRAPD(err, TestTelUriParsingAndCompareL(telUri,expTelScheme, expTelPath)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Test step failed: Tel URI parsing failed: %D\n"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: __UHEAP_MARKEND; sl@0: INFO_PRINTF1(_L("\nTest of TelUriParsing is Executed\n")); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Performs tel uri parsing and compares actual & expected result. sl@0: @param aUri A reference to tel-uri to be parsed. sl@0: @param aScheme A reference to expected scheme component of tel-uri. sl@0: @param aPath A reference to expected path component of tel-uri. sl@0: */ sl@0: void CTestTelUriParsingStep::TestTelUriParsingAndCompareL(const TDesC16& aUri, const TDesC16& aScheme, const TDesC16& aPath) sl@0: { sl@0: // Make 8-bit copies sl@0: HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); sl@0: TPtr8 uri8Bit(uriBuf->Des()); sl@0: uri8Bit.Copy(aUri); sl@0: sl@0: TUriParser8 uriParser; sl@0: TInt error = KErrNone; sl@0: error = uriParser.Parse(uri8Bit); sl@0: // Is this a valid Uri? sl@0: if( error != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Tel URI parsing failed: %D\n"), error); sl@0: SetTestStepResult(EFail); sl@0: User::LeaveIfError(error); sl@0: } sl@0: sl@0: // Check scheme... sl@0: TInt result = TestComponentL(uriParser, aScheme, EUriScheme); sl@0: if( result != 0 ) sl@0: { sl@0: ERR_PRINTF1(_L("Scheme component not matched \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentScheme); sl@0: } sl@0: sl@0: // Check path... sl@0: result = TestComponentL(uriParser, aPath, EUriPath); sl@0: if( result != 0) sl@0: { sl@0: ERR_PRINTF1(_L("Path component not matched \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentPath); sl@0: } sl@0: sl@0: //tel-uri Should not contain Host, UserInfo, Port, Query and Fragment components. sl@0: // Check host... sl@0: const TDesC8& host = uriParser.Extract(EUriHost); sl@0: if( (host.Length() != 0) || (host.Size() != 0) ) sl@0: { sl@0: ERR_PRINTF1(_L("host component is not empty, but it should be empty. \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentHost); sl@0: } sl@0: sl@0: //Check UserInfo... sl@0: const TDesC8& userInfo = uriParser.Extract(EUriUserinfo); sl@0: if( (userInfo.Length() != 0) || (userInfo.Size() != 0) ) sl@0: { sl@0: ERR_PRINTF1(_L("UserInfo component is not empty, but it should be empty. \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentUserInfo); sl@0: } sl@0: sl@0: //Check port... sl@0: const TDesC8& uriPort = uriParser.Extract(EUriPort); sl@0: if( (uriPort.Length() != 0) || (uriPort.Size() != 0) ) sl@0: { sl@0: ERR_PRINTF1(_L("Port component is not empty, but it should be empty. \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentPort); sl@0: } sl@0: sl@0: //Check query... sl@0: const TDesC8& uriQuery = uriParser.Extract(EUriQuery); sl@0: if( (uriQuery.Length() != 0) || (uriQuery.Size() != 0) ) sl@0: { sl@0: ERR_PRINTF1(_L("Query component is not empty, but it should be empty. \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentQuery); sl@0: } sl@0: sl@0: //Check fragment... sl@0: const TDesC8& uriFrag = uriParser.Extract(EUriFragment); sl@0: if( (uriFrag.Length() != 0) || (uriFrag.Size() != 0) ) sl@0: { sl@0: ERR_PRINTF1(_L("Fragment component is not empty, but it should be empty. \n")); sl@0: User::LeaveIfError(KUriUtilsErrDifferentFragment); sl@0: } sl@0: CleanupStack::PopAndDestroy(uriBuf); sl@0: } sl@0: sl@0: /** sl@0: It extracts and compares with expected component for specified TUriComponent. sl@0: @param aParser A reference to parsed tel-uri. sl@0: @param aExpectedComponent A reference to expected component of tel-uri. sl@0: @param aComponent Enumeration of TUriComponent. sl@0: */ sl@0: TInt CTestTelUriParsingStep::TestComponentL(const TUriParser8& aParser, const TDesC16& aExpectedComponent,TUriComponent aComponent) sl@0: { sl@0: HBufC8* expectedBuf = HBufC8::NewLC(aExpectedComponent.Length()); sl@0: TPtr8 expected8Bit = expectedBuf->Des(); sl@0: expected8Bit.Copy(aExpectedComponent); sl@0: TInt result = aParser.Extract(aComponent).Compare(expected8Bit); sl@0: CleanupStack::PopAndDestroy(expectedBuf); sl@0: return result; sl@0: } sl@0: sl@0: sl@0: