os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriValidationStep.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/TestTelUriValidationStep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,176 @@
     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 CTestTelUriValidationStep 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 "TestTelUriValidationStep.h"
    1.28 +// System Include
    1.29 +#include <uri8.h>
    1.30 +#include <uriutils.h>
    1.31 +
    1.32 +/**
    1.33 +  Constructor: Sets the test step name.
    1.34 +  @internalTechnology
    1.35 +  @test
    1.36 +*/
    1.37 +CTestTelUriValidationStep::CTestTelUriValidationStep()
    1.38 +	{
    1.39 +	//Call base class method to set human readable name for test step
    1.40 +	SetTestStepName(KTestTelUriValidationStep);
    1.41 +	}
    1.42 +
    1.43 +/**
    1.44 +  Destructor
    1.45 +  @internalTechnology
    1.46 +  @test
    1.47 +*/
    1.48 +CTestTelUriValidationStep::~CTestTelUriValidationStep()
    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 TestTelUriValidate() which does validation 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 CTestTelUriValidationStep::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 +	TInt expRetCode;
    1.68 +
    1.69 +	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) ||
    1.70 +	   !GetIntFromConfig(ConfigSection(), KIniExpectedRetCode, expRetCode) )
    1.71 +		{
    1.72 +		ERR_PRINTF3(_L("Problem in reading values from ini.			\
    1.73 +						\nExpected fields are: \n%S\n%S\n" ),&KIniUri, &KIniExpectedRetCode );
    1.74 +		SetTestStepResult(EFail);
    1.75 +		}
    1.76 +	else
    1.77 +		{
    1.78 +		// No problem in reading values from INI file. Proceed.
    1.79 +		// Calling TestTelUriValidate which does validation of tel uri and comparing results.
    1.80 +	    TRAPD(err, TestTelUriValidateAndCompareL(telUri,expRetCode));
    1.81 +	    if(err != KErrNone)
    1.82 +		    {
    1.83 +	        ERR_PRINTF1(_L("Test step failed: Leave occured in TestTelUriValidateAndCompareL \n"));
    1.84 +	        SetTestStepResult(EFail);	
    1.85 +		    }
    1.86 +		}
    1.87 +	__UHEAP_MARKEND;
    1.88 +	INFO_PRINTF1(_L("\nTest of TelUri Validation is Executed"));
    1.89 +	return TestStepResult();
    1.90 +	}
    1.91 +
    1.92 +/**
    1.93 +  Performs tel uri validation and compares actual & expected result.
    1.94 +  @param		aTelUri A reference to tel-uri to be validated.
    1.95 +  @param		aExpRetCode An expected retrn code to be compared.
    1.96 +*/	
    1.97 +void CTestTelUriValidationStep::TestTelUriValidateAndCompareL(const TDesC16& aTelUri, const TInt aExpRetCode)
    1.98 +	{
    1.99 +    CUri8* cUri8 = UriUtils::CreateUriL(aTelUri);
   1.100 +    const TUriC8& telUri(cUri8->Uri());
   1.101 +	// Validating tel uri
   1.102 +	TInt errCode = telUri.Validate();
   1.103 +    if(errCode != aExpRetCode)
   1.104 +		{
   1.105 +	  	ERR_PRINTF2(_L("Tel URI validation failed %D\n"), errCode);
   1.106 +	    SetTestStepResult(EFail);	
   1.107 +		}
   1.108 +	delete cUri8;
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +  Constructor: Sets the test step name.
   1.113 +  @internalTechnology
   1.114 +  @test
   1.115 +*/
   1.116 +CTestTelUriValidationOomStep::CTestTelUriValidationOomStep()
   1.117 +	{
   1.118 +	//Call base class method to set human readable name for test step
   1.119 +	SetTestStepName(KTestOomTelUriValidationStep);
   1.120 +	}
   1.121 +
   1.122 +/**
   1.123 +  Destructor
   1.124 +  @internalTechnology
   1.125 +  @test
   1.126 +*/
   1.127 +CTestTelUriValidationOomStep::~CTestTelUriValidationOomStep()
   1.128 +	{
   1.129 +
   1.130 +	}
   1.131 +
   1.132 +/**
   1.133 +  Does the main functionality of a test step and performs OOM test.
   1.134 +  Here, reads values from INI file 
   1.135 +  and calls TestTelUriValidate() which does validation of a tel uri.
   1.136 +  @internalTechnology 
   1.137 +  @param		None
   1.138 +  @return		EPass or EFail indicating the success or failure of the test step
   1.139 +*/
   1.140 +TVerdict CTestTelUriValidationOomStep::doTestStepL()
   1.141 +	{
   1.142 +	__UHEAP_MARK;
   1.143 +	TPtrC telUri;
   1.144 +	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) )
   1.145 +		{
   1.146 +		ERR_PRINTF2(_L("Problem in reading values from ini.    \
   1.147 +						\nExpected fields are: \n%S\n" ), &KIniUri);
   1.148 +		SetTestStepResult(EFail);
   1.149 +		}
   1.150 +	else
   1.151 +		{
   1.152 +		CUri8* cUri8 = UriUtils::CreateUriL(telUri);
   1.153 +    	const TUriC8& telUri(cUri8->Uri());
   1.154 +		INFO_PRINTF1(_L("Calling telUri.Validate() which does tel-Uri Validation.")); 	
   1.155 +		TInt ret = KErrNoMemory;
   1.156 +		TInt failAt = 0;
   1.157 +		while(ret != KErrNone)
   1.158 +			{
   1.159 +			failAt++;
   1.160 +			INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
   1.161 +
   1.162 +			__UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
   1.163 +			__UHEAP_MARK;
   1.164 +			TRAP( ret, telUri.Validate());
   1.165 +			__UHEAP_MARKEND;
   1.166 +			__UHEAP_RESET;
   1.167 +			if((ret == KErrNoMemory) || (ret == KErrNone))
   1.168 +				{
   1.169 +				INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
   1.170 +				}
   1.171 +			}
   1.172 +		delete cUri8;
   1.173 +		}
   1.174 +	__UHEAP_MARKEND;
   1.175 +	INFO_PRINTF1(_L("\n OOM Test of TelUri Validation is Executed"));
   1.176 +	return TestStepResult();
   1.177 +	}
   1.178 +
   1.179 +