os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriValidationStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Contains implementation of CTestTelUriValidationStep class
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology 
sl@0
    21
*/
sl@0
    22
sl@0
    23
// User Include
sl@0
    24
#include "TestTelUriValidationStep.h"
sl@0
    25
// System Include
sl@0
    26
#include <uri8.h>
sl@0
    27
#include <uriutils.h>
sl@0
    28
sl@0
    29
/**
sl@0
    30
  Constructor: Sets the test step name.
sl@0
    31
  @internalTechnology
sl@0
    32
  @test
sl@0
    33
*/
sl@0
    34
CTestTelUriValidationStep::CTestTelUriValidationStep()
sl@0
    35
	{
sl@0
    36
	//Call base class method to set human readable name for test step
sl@0
    37
	SetTestStepName(KTestTelUriValidationStep);
sl@0
    38
	}
sl@0
    39
sl@0
    40
/**
sl@0
    41
  Destructor
sl@0
    42
  @internalTechnology
sl@0
    43
  @test
sl@0
    44
*/
sl@0
    45
CTestTelUriValidationStep::~CTestTelUriValidationStep()
sl@0
    46
	{
sl@0
    47
sl@0
    48
	}
sl@0
    49
sl@0
    50
/**
sl@0
    51
  Does the main functionality of a test step.
sl@0
    52
  Here, reads values from INI file 
sl@0
    53
  and calls TestTelUriValidate() which does validation of a tel uri.
sl@0
    54
  @internalTechnology 
sl@0
    55
  @param		None
sl@0
    56
  @return		EPass or EFail indicating the success or failure of the test step
sl@0
    57
*/
sl@0
    58
TVerdict CTestTelUriValidationStep::doTestStepL()
sl@0
    59
	{
sl@0
    60
	__UHEAP_MARK;
sl@0
    61
	INFO_PRINTF1(_L("\n"));
sl@0
    62
	// Get necessary information from INI file
sl@0
    63
	TPtrC telUri;
sl@0
    64
	TInt expRetCode;
sl@0
    65
sl@0
    66
	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) ||
sl@0
    67
	   !GetIntFromConfig(ConfigSection(), KIniExpectedRetCode, expRetCode) )
sl@0
    68
		{
sl@0
    69
		ERR_PRINTF3(_L("Problem in reading values from ini.			\
sl@0
    70
						\nExpected fields are: \n%S\n%S\n" ),&KIniUri, &KIniExpectedRetCode );
sl@0
    71
		SetTestStepResult(EFail);
sl@0
    72
		}
sl@0
    73
	else
sl@0
    74
		{
sl@0
    75
		// No problem in reading values from INI file. Proceed.
sl@0
    76
		// Calling TestTelUriValidate which does validation of tel uri and comparing results.
sl@0
    77
	    TRAPD(err, TestTelUriValidateAndCompareL(telUri,expRetCode));
sl@0
    78
	    if(err != KErrNone)
sl@0
    79
		    {
sl@0
    80
	        ERR_PRINTF1(_L("Test step failed: Leave occured in TestTelUriValidateAndCompareL \n"));
sl@0
    81
	        SetTestStepResult(EFail);	
sl@0
    82
		    }
sl@0
    83
		}
sl@0
    84
	__UHEAP_MARKEND;
sl@0
    85
	INFO_PRINTF1(_L("\nTest of TelUri Validation is Executed"));
sl@0
    86
	return TestStepResult();
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
  Performs tel uri validation and compares actual & expected result.
sl@0
    91
  @param		aTelUri A reference to tel-uri to be validated.
sl@0
    92
  @param		aExpRetCode An expected retrn code to be compared.
sl@0
    93
*/	
sl@0
    94
void CTestTelUriValidationStep::TestTelUriValidateAndCompareL(const TDesC16& aTelUri, const TInt aExpRetCode)
sl@0
    95
	{
sl@0
    96
    CUri8* cUri8 = UriUtils::CreateUriL(aTelUri);
sl@0
    97
    const TUriC8& telUri(cUri8->Uri());
sl@0
    98
	// Validating tel uri
sl@0
    99
	TInt errCode = telUri.Validate();
sl@0
   100
    if(errCode != aExpRetCode)
sl@0
   101
		{
sl@0
   102
	  	ERR_PRINTF2(_L("Tel URI validation failed %D\n"), errCode);
sl@0
   103
	    SetTestStepResult(EFail);	
sl@0
   104
		}
sl@0
   105
	delete cUri8;
sl@0
   106
	}
sl@0
   107
sl@0
   108
/**
sl@0
   109
  Constructor: Sets the test step name.
sl@0
   110
  @internalTechnology
sl@0
   111
  @test
sl@0
   112
*/
sl@0
   113
CTestTelUriValidationOomStep::CTestTelUriValidationOomStep()
sl@0
   114
	{
sl@0
   115
	//Call base class method to set human readable name for test step
sl@0
   116
	SetTestStepName(KTestOomTelUriValidationStep);
sl@0
   117
	}
sl@0
   118
sl@0
   119
/**
sl@0
   120
  Destructor
sl@0
   121
  @internalTechnology
sl@0
   122
  @test
sl@0
   123
*/
sl@0
   124
CTestTelUriValidationOomStep::~CTestTelUriValidationOomStep()
sl@0
   125
	{
sl@0
   126
sl@0
   127
	}
sl@0
   128
sl@0
   129
/**
sl@0
   130
  Does the main functionality of a test step and performs OOM test.
sl@0
   131
  Here, reads values from INI file 
sl@0
   132
  and calls TestTelUriValidate() which does validation of a tel uri.
sl@0
   133
  @internalTechnology 
sl@0
   134
  @param		None
sl@0
   135
  @return		EPass or EFail indicating the success or failure of the test step
sl@0
   136
*/
sl@0
   137
TVerdict CTestTelUriValidationOomStep::doTestStepL()
sl@0
   138
	{
sl@0
   139
	__UHEAP_MARK;
sl@0
   140
	TPtrC telUri;
sl@0
   141
	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) )
sl@0
   142
		{
sl@0
   143
		ERR_PRINTF2(_L("Problem in reading values from ini.    \
sl@0
   144
						\nExpected fields are: \n%S\n" ), &KIniUri);
sl@0
   145
		SetTestStepResult(EFail);
sl@0
   146
		}
sl@0
   147
	else
sl@0
   148
		{
sl@0
   149
		CUri8* cUri8 = UriUtils::CreateUriL(telUri);
sl@0
   150
    	const TUriC8& telUri(cUri8->Uri());
sl@0
   151
		INFO_PRINTF1(_L("Calling telUri.Validate() which does tel-Uri Validation.")); 	
sl@0
   152
		TInt ret = KErrNoMemory;
sl@0
   153
		TInt failAt = 0;
sl@0
   154
		while(ret != KErrNone)
sl@0
   155
			{
sl@0
   156
			failAt++;
sl@0
   157
			INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
sl@0
   158
sl@0
   159
			__UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
sl@0
   160
			__UHEAP_MARK;
sl@0
   161
			TRAP( ret, telUri.Validate());
sl@0
   162
			__UHEAP_MARKEND;
sl@0
   163
			__UHEAP_RESET;
sl@0
   164
			if((ret == KErrNoMemory) || (ret == KErrNone))
sl@0
   165
				{
sl@0
   166
				INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
sl@0
   167
				}
sl@0
   168
			}
sl@0
   169
		delete cUri8;
sl@0
   170
		}
sl@0
   171
	__UHEAP_MARKEND;
sl@0
   172
	INFO_PRINTF1(_L("\n OOM Test of TelUri Validation is Executed"));
sl@0
   173
	return TestStepResult();
sl@0
   174
	}
sl@0
   175
sl@0
   176