os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriParsingStep.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriParsingStep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,193 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Contains implementation of CTestTelUriParsingStep class
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology 
    1.24 +*/
    1.25 +
    1.26 +// User Include
    1.27 +#include "TestTelUriParsingStep.h"
    1.28 +// System Include
    1.29 +#include <uri8.h>
    1.30 +#include <uriutilscommon.h>
    1.31 +
    1.32 +/**
    1.33 +  Constructor: Sets the test step name.
    1.34 +  @internalTechnology
    1.35 +  @test
    1.36 +*/
    1.37 +CTestTelUriParsingStep::CTestTelUriParsingStep()
    1.38 +	{
    1.39 +	//Call base class method to set human readable name for test step
    1.40 +	SetTestStepName(KTestTelUriParsingStep);
    1.41 +	}
    1.42 +
    1.43 +/**
    1.44 +  Destructor
    1.45 +  @internalTechnology
    1.46 +  @test
    1.47 +*/
    1.48 +CTestTelUriParsingStep::~CTestTelUriParsingStep()
    1.49 +	{
    1.50 +
    1.51 +	}
    1.52 +
    1.53 +/**
    1.54 +  Does the main functionality of a test step.
    1.55 +  Here, reads values from INI file 
    1.56 +  and calls TestTelUriParsingAndCompareL() which does parsing of a tel uri.
    1.57 +  @internalTechnology 
    1.58 +  @param		None
    1.59 +  @return		EPass or EFail indicating the success or failure of the test step
    1.60 +*/
    1.61 +TVerdict CTestTelUriParsingStep::doTestStepL()
    1.62 +	{
    1.63 +	__UHEAP_MARK;
    1.64 +	INFO_PRINTF1(_L("\n"));
    1.65 +	// Get necessary information from INI file
    1.66 +	TPtrC telUri;
    1.67 +	TPtrC expTelScheme;
    1.68 +	TPtrC expTelPath;
    1.69 +	
    1.70 +	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) ||
    1.71 +	   !GetStringFromConfig(ConfigSection(), KIniExpectedTelScheme, expTelScheme) ||
    1.72 +	   !GetStringFromConfig(ConfigSection(), KIniExpectedTelPath, expTelPath) )
    1.73 +		{
    1.74 +		ERR_PRINTF4(_L("Problem in reading values from ini.			\
    1.75 +						\nExpected fields are: \n%S\n%S\n%S\n"
    1.76 +					  ),&KIniUri, &KIniExpectedTelScheme, &KIniExpectedTelPath
    1.77 +				   );
    1.78 +		SetTestStepResult(EFail);
    1.79 +		}
    1.80 +	else
    1.81 +		{
    1.82 +		// No problem in reading values from INI file. Proceed.
    1.83 +	    // Calling TestTelUriParsingL which does parisng of tel uri and comparing results.
    1.84 +	    TRAPD(err, TestTelUriParsingAndCompareL(telUri,expTelScheme, expTelPath));
    1.85 +	    if(err != KErrNone)
    1.86 +			{
    1.87 +			ERR_PRINTF2(_L("Test step failed: Tel URI parsing failed: %D\n"), err);
    1.88 +			SetTestStepResult(EFail);	
    1.89 +			}
    1.90 +		}
    1.91 +	__UHEAP_MARKEND;
    1.92 +	INFO_PRINTF1(_L("\nTest of TelUriParsing is Executed\n"));
    1.93 +	return TestStepResult();
    1.94 +	}	
    1.95 +
    1.96 +/**
    1.97 +  Performs tel uri parsing and compares actual & expected result.
    1.98 +  @param		aUri A reference to tel-uri to be parsed.
    1.99 +  @param		aScheme A reference to expected scheme component of tel-uri.
   1.100 +  @param		aPath A reference to expected path component of tel-uri.
   1.101 +*/	
   1.102 +void CTestTelUriParsingStep::TestTelUriParsingAndCompareL(const TDesC16& aUri, const TDesC16& aScheme, const TDesC16& aPath)
   1.103 +	{
   1.104 +	// Make 8-bit copies
   1.105 +	HBufC8* uriBuf = HBufC8::NewLC(aUri.Length());
   1.106 +	TPtr8 uri8Bit(uriBuf->Des());
   1.107 +	uri8Bit.Copy(aUri);
   1.108 +
   1.109 +	TUriParser8 uriParser;
   1.110 +	TInt error = KErrNone;
   1.111 +	error = uriParser.Parse(uri8Bit);
   1.112 +	// Is this a valid Uri?
   1.113 +	if( error != KErrNone )
   1.114 +		{
   1.115 +        ERR_PRINTF2(_L("Tel URI parsing failed: %D\n"), error);
   1.116 +	    SetTestStepResult(EFail);
   1.117 +		User::LeaveIfError(error);
   1.118 +		}
   1.119 +
   1.120 +	// Check scheme...
   1.121 +	TInt result = TestComponentL(uriParser, aScheme, EUriScheme);
   1.122 +	if( result != 0 )
   1.123 +		{
   1.124 +		ERR_PRINTF1(_L("Scheme component not matched \n"));
   1.125 +		User::LeaveIfError(KUriUtilsErrDifferentScheme);
   1.126 +		}
   1.127 +
   1.128 +	// Check path...
   1.129 +	result = TestComponentL(uriParser, aPath, EUriPath);
   1.130 +	if( result != 0)
   1.131 +		{
   1.132 +		ERR_PRINTF1(_L("Path component not matched \n"));
   1.133 +		User::LeaveIfError(KUriUtilsErrDifferentPath);
   1.134 +		}
   1.135 +		
   1.136 +	//tel-uri Should not contain Host, UserInfo, Port, Query and Fragment components.
   1.137 +	// Check host...
   1.138 +	const TDesC8& host = uriParser.Extract(EUriHost);
   1.139 +	if( (host.Length() != 0) || (host.Size() != 0) )
   1.140 +		{
   1.141 +	    ERR_PRINTF1(_L("host component is not empty, but it should be empty. \n"));
   1.142 +	    User::LeaveIfError(KUriUtilsErrDifferentHost);
   1.143 +		}
   1.144 +
   1.145 +	//Check UserInfo...
   1.146 +	const TDesC8& userInfo = uriParser.Extract(EUriUserinfo);
   1.147 +	if( (userInfo.Length() != 0) || (userInfo.Size() != 0) )
   1.148 +		{
   1.149 +	    ERR_PRINTF1(_L("UserInfo component is not empty, but it should be empty. \n"));
   1.150 +	    User::LeaveIfError(KUriUtilsErrDifferentUserInfo);
   1.151 +		}
   1.152 +		
   1.153 +	//Check port...
   1.154 +    const TDesC8& uriPort = uriParser.Extract(EUriPort);
   1.155 +	if( (uriPort.Length() != 0) || (uriPort.Size() != 0) )
   1.156 +		{
   1.157 +	    ERR_PRINTF1(_L("Port component is not empty, but it should be empty. \n"));
   1.158 +	    User::LeaveIfError(KUriUtilsErrDifferentPort);
   1.159 +		}
   1.160 +
   1.161 +    //Check query...
   1.162 +    const TDesC8& uriQuery = uriParser.Extract(EUriQuery);
   1.163 +	if( (uriQuery.Length() != 0) || (uriQuery.Size() != 0) )
   1.164 +		{
   1.165 +	    ERR_PRINTF1(_L("Query component is not empty, but it should be empty. \n"));
   1.166 +	    User::LeaveIfError(KUriUtilsErrDifferentQuery);
   1.167 +		}
   1.168 +	
   1.169 +	//Check fragment...
   1.170 +	const TDesC8& uriFrag = uriParser.Extract(EUriFragment);
   1.171 +	if( (uriFrag.Length() != 0) || (uriFrag.Size() != 0) )
   1.172 +		{
   1.173 +	    ERR_PRINTF1(_L("Fragment component is not empty, but it should be empty. \n"));
   1.174 +	    User::LeaveIfError(KUriUtilsErrDifferentFragment);
   1.175 +		}
   1.176 +	CleanupStack::PopAndDestroy(uriBuf); 
   1.177 +	}
   1.178 +
   1.179 +/**
   1.180 +  It extracts and compares with expected component for specified TUriComponent.
   1.181 +  @param		aParser A reference to parsed tel-uri.
   1.182 +  @param		aExpectedComponent A reference to expected component of tel-uri.
   1.183 +  @param		aComponent Enumeration of TUriComponent.
   1.184 +*/
   1.185 +TInt CTestTelUriParsingStep::TestComponentL(const TUriParser8& aParser, const TDesC16& aExpectedComponent,TUriComponent aComponent)
   1.186 +	{
   1.187 +	HBufC8* expectedBuf = HBufC8::NewLC(aExpectedComponent.Length());
   1.188 +	TPtr8 expected8Bit = expectedBuf->Des();
   1.189 +	expected8Bit.Copy(aExpectedComponent);
   1.190 +	TInt result = aParser.Extract(aComponent).Compare(expected8Bit);
   1.191 +	CleanupStack::PopAndDestroy(expectedBuf);
   1.192 +	return result;
   1.193 +	}
   1.194 +
   1.195 +
   1.196 +