os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestNormaliseUriStep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Contains implementation of CTestNormaliseUriStep class
    15 // 
    16 //
    17 
    18 /**
    19  @file TESTNORMALISEURISTEP.CPP
    20  @internalTechnology
    21 */
    22 
    23 // User Include
    24 #include "TestNormaliseUriStep.h"
    25 // System Include
    26 #include <uriutils.h>
    27 #include <uri8.h>
    28 
    29 //constants
    30 const TInt KAlreadyNormalised 			= 0;
    31 const TInt KPercentEncoding				= 1;
    32 const TInt KCaseNormalisation			= 2;
    33 const TInt KRemoveDotegments			= 3;
    34 const TInt KPercentCaseNormalisation 	= 12;
    35 const TInt KPercentRemoveDotegments 	= 13;
    36 const TInt KCaseRemoveDotegments 		= 23;
    37 const TInt KAll 						= 123;
    38 
    39 /**
    40   Constructor: Sets the test step name.
    41   @internalTechnology
    42   @test
    43 */
    44 CTestNormaliseUriStep::CTestNormaliseUriStep()
    45 	{
    46 	//Call base class method to set human readable name for test step
    47 	SetTestStepName(KTestNormaliseUriStep);
    48 	}
    49 
    50 /**
    51   Destructor
    52   @internalTechnology
    53   @test
    54 */
    55 CTestNormaliseUriStep::~CTestNormaliseUriStep()
    56 	{
    57 	
    58 	}
    59 
    60 /**
    61   Does the main functionality test.
    62   Here, reads values from INI file and calls NormaliseAndCompareUriL
    63   @internalTechnology 
    64   @param		None
    65   @return		EPass or EFail indicating the success or failure of the test step
    66 */
    67 TVerdict CTestNormaliseUriStep::doTestStepL()
    68 	{
    69 	__UHEAP_MARK;
    70 	INFO_PRINTF1(_L("\n"));
    71 	// Get necessary information from INI file
    72 
    73 	TPtrC uri;
    74 	TPtrC expUri;
    75 	TInt RetCode;
    76 	
    77 	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, uri) ||
    78 	   !GetStringFromConfig(ConfigSection(), KIniExpectedUri, expUri) ||
    79 	   !GetIntFromConfig(ConfigSection(), KRetCode, RetCode) )
    80 		{
    81 		ERR_PRINTF3(_L("Problem in reading values from ini.			\
    82 						\nExpected fields are: \n%S\n%S\n"),&KIniUri, &KIniExpectedUri);
    83 		SetTestStepResult(EFail);
    84 		}
    85 	else
    86 		{// No problem in reading values from INI file. Proceed.
    87 	    TRAPD(err, NormaliseAndCompareUriL(uri,expUri));
    88 	    if(err != KErrNone)
    89 		    {
    90 	        ERR_PRINTF2(_L("Test step failed: Leave occured in NormaliseAndCompareUriL fun: %D\n"), err);
    91 	 	    SetTestStepResult(EFail);	
    92 		    }
    93 		 }
    94 	__UHEAP_MARKEND;
    95 	switch (RetCode)
    96 		{
    97 		case KAlreadyNormalised :
    98 			{
    99 			INFO_PRINTF1(_L("\nAlready in Normalised Form"));
   100 			break;	
   101 			}
   102 		case KPercentEncoding :
   103 			{
   104 			INFO_PRINTF1(_L("\nNormalised through PercentEncoding"));
   105 			break;	
   106 			}
   107 		case KCaseNormalisation :
   108 			{
   109 			INFO_PRINTF1(_L("\nNormalised through CaseNormalisation"));
   110 			break;	
   111 			}
   112 		case KRemoveDotegments :
   113 			{
   114 			INFO_PRINTF1(_L("\nNormalised through RemoveDotegments"));
   115 			break;	
   116 			}
   117 		case KPercentCaseNormalisation :
   118 			{
   119 			INFO_PRINTF1(_L("\nNormalised through PercentEncoding and CaseNormalisation"));
   120 			break;	
   121 			}
   122 		case KPercentRemoveDotegments :
   123 			{
   124 			INFO_PRINTF1(_L("\nNormalised through PercentEncoding and RemoveDotegments"));
   125 			break;	
   126 			}
   127 		case KCaseRemoveDotegments :
   128 			{
   129 			INFO_PRINTF1(_L("\nNormalised through CaseNormalisation and RemoveDotegments"));
   130 			break;	
   131 			}
   132 		case KAll :
   133 			{
   134 			INFO_PRINTF1(_L("\nNormalised through CaseNormalisation,PercentEncoding and RemoveDotegments"));
   135 			break;	
   136 			}
   137 		default:
   138 			{
   139 			//do nothing
   140 			break;	
   141 			}
   142 		}
   143 	INFO_PRINTF1(_L("\nTest of UriNormalisation is Executed\n"));
   144 	return TestStepResult();
   145 	}
   146 	
   147 /**
   148   Performs syntax normalisation and compares actual & expected result.
   149   @param		aUri A reference to actual Uri to be normalised
   150   @param		aExpUri A reference to expected uri.
   151 */	
   152 void CTestNormaliseUriStep::NormaliseAndCompareUriL(const TDesC& aUri,const TDesC& aExpUri)
   153 	{
   154     CUri8* cUri8=NULL;
   155 	TRAPD(err, cUri8=UriUtils::CreateUriL(aUri));
   156 	if(err != KErrNone)
   157 		{
   158 		ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
   159 		SetTestStepResult(EFail);
   160 		}
   161 	else
   162 		{
   163 		const TUriC8& tUri(cUri8->Uri());
   164 		CUri8* normalisedUri = NULL; 
   165 		CleanupStack::PushL(cUri8);
   166 		INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation.")); 	
   167 		TRAPD(error, normalisedUri=UriUtils::NormaliseUriL(tUri));
   168 		if(error == KErrNone)
   169 			{
   170 			INFO_PRINTF1(_L("URI normalised.")); 	
   171 			CleanupStack::PushL(normalisedUri);
   172 			HBufC8* uriBuf = HBufC8::NewLC(aExpUri.Length());
   173 			TPtr8 expUri8(uriBuf->Des());
   174 			expUri8.Copy(aExpUri);
   175 			// Comparing actual & expected uris.
   176 			if(normalisedUri->Uri().UriDes().Compare(expUri8)!=0)
   177 				{
   178 				ERR_PRINTF1(_L("Test step failed: actualUri is not matched with expectedUri."));
   179 				SetTestStepResult(EFail);
   180 				}
   181 			CleanupStack::PopAndDestroy(3, cUri8);
   182 			}
   183 		}
   184 	}
   185 
   186 
   187 /**
   188   Constructor: Sets the test step name.
   189   @internalTechnology
   190   @test
   191 */
   192 CTestNormaliseUriOomStep::CTestNormaliseUriOomStep()
   193 	{
   194 	//Call base class method to set human readable name for test step
   195 	SetTestStepName(KTestOomNormaliseUriStep);
   196 	}
   197 
   198 /**
   199   Destructor
   200   @internalTechnology
   201   @test
   202 */
   203 CTestNormaliseUriOomStep::~CTestNormaliseUriOomStep()
   204 	{
   205 	
   206 	}
   207 
   208 /**
   209   Does the main functionality and OOM test of a test step.
   210   @internalTechnology 
   211   @param		None
   212   @return		EPass or EFail indicating the success or failure of the test step
   213 */
   214 TVerdict CTestNormaliseUriOomStep::doTestStepL()
   215 	{
   216 	__UHEAP_MARK;
   217 	TPtrC uri;
   218 	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, uri) )
   219 		{
   220 		ERR_PRINTF2(_L("Problem in reading values from ini.			\
   221 						\nExpected fields are: \n%S\n"),&KIniUri);
   222 		SetTestStepResult(EFail);
   223 		}
   224 	else
   225 		{// No problem in reading values from INI file. Proceed.
   226 	    CUri8* cUri8=NULL;
   227 		TRAPD(err, cUri8=UriUtils::CreateUriL(uri));
   228 		if(err != KErrNone)
   229 			{
   230 			ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
   231 			SetTestStepResult(EFail);
   232 			}
   233 		else
   234 			{
   235 			const TUriC8& tUri(cUri8->Uri());
   236 			CleanupStack::PushL(cUri8);
   237 			INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation.")); 	
   238 			TInt ret = KErrNoMemory;
   239 			TInt failAt = 0;
   240 			while(ret != KErrNone)
   241 				{
   242 				failAt++;
   243 				INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
   244 
   245 				__UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
   246 				__UHEAP_MARK;
   247 				CUri8* normalisedUri = NULL;
   248 				TRAP( ret, normalisedUri = UriUtils::NormaliseUriL(tUri));
   249 				delete normalisedUri;
   250 				__UHEAP_MARKEND;
   251 				__UHEAP_RESET;
   252 				if((ret == KErrNoMemory) || (ret == KErrNone))
   253 					{
   254 					INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
   255 					}
   256 				}
   257 			CleanupStack::PopAndDestroy(cUri8);
   258 			}
   259 		}
   260 	__UHEAP_MARKEND;
   261 	return TestStepResult();
   262 	}
   263