os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestEscapeEncodeUriStep.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 CTestEscapeEncodeUriStep class
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalTechnology 
    21 */
    22 
    23 // User Include
    24 #include "TestEscapeEncodeUriStep.h"
    25 // System Include
    26 #include <escapeutils.h>
    27 /**
    28   Constructor: Sets the test step name.
    29   @internalTechnology
    30   @test
    31 */
    32 CTestEscapeEncodeUriStep::CTestEscapeEncodeUriStep()
    33 	{
    34 	//Call base class method to set human readable name for test step
    35 	SetTestStepName(KTestEscapeEncodeUriStep);
    36 	}
    37 
    38 /**
    39   Destructor
    40   @internalTechnology
    41   @test
    42 */
    43 CTestEscapeEncodeUriStep::~CTestEscapeEncodeUriStep()
    44 	{
    45 
    46 	}
    47 
    48 /**
    49   Does the main functionality of a test step.
    50   Here, reads values from INI file and calls EscEncodeAndCompareUriL
    51   @internalTechnology 
    52   @param		None
    53   @return		EPass or EFail indicating the success or failure of the test step
    54 */
    55 TVerdict CTestEscapeEncodeUriStep::doTestStepL()
    56 	{
    57 	__UHEAP_MARK;
    58 	INFO_PRINTF1(_L("\n"));
    59 	// Get necessary information from INI file
    60 	
    61 	TPtrC decodedComponent; // to be encoded.
    62 	TPtrC expEncodedUri;
    63 	TPtrC expEncodedAuthority;
    64 	TPtrC expEncodedPath;
    65 	TPtrC expEncodedQuery;
    66 	TPtrC expEncodedNormal;
    67 	
    68 	if(!GetStringFromConfig(ConfigSection(), KIniEscapeDecoded, decodedComponent) ||
    69 	   !GetStringFromConfig(ConfigSection(), KIniEscapeEncodedUri, expEncodedUri) ||
    70 	   !GetStringFromConfig(ConfigSection(), KIniEscapeEncodedAuthority, expEncodedAuthority) ||
    71 	   !GetStringFromConfig(ConfigSection(), KIniEscapeEncodedPath, expEncodedPath) ||
    72 	   !GetStringFromConfig(ConfigSection(), KIniEscapeEncodedQuery, expEncodedQuery) ||
    73        !GetStringFromConfig(ConfigSection(), KIniEscapeEncodedNormal, expEncodedNormal)	  )
    74 		{
    75 		ERR_PRINTF7(_L("Problem in reading values from ini.			\
    76 						\nExpected fields are: \n%S\n%S\n%S\n%S\n%S\n%S\n"
    77 					  ),&KIniEscapeDecoded, &KIniEscapeEncodedUri, &KIniEscapeEncodedAuthority, &KIniEscapeEncodedPath, &KIniEscapeEncodedQuery, &KIniEscapeEncodedNormal
    78 				   );
    79 		SetTestStepResult(EFail);
    80 		}
    81 	else
    82 		{// No problem in reading values from INI file. Proceed.
    83 	    TRAPD(err, EscEncodeAndCompareUriL(decodedComponent,expEncodedUri,expEncodedAuthority,expEncodedPath,expEncodedQuery,expEncodedNormal));
    84 	    if(err != KErrNone)
    85 			{
    86 			ERR_PRINTF2(_L("Test step failed: Leave occured in EscEncodeAndCompareUriL fun: %D\n"), err);
    87 			SetTestStepResult(EFail);	
    88 			}
    89 		 }
    90 	__UHEAP_MARKEND;
    91 	INFO_PRINTF1(_L("\nTest of EscapeEncodingUri is Executed\n"));
    92 	return TestStepResult();
    93 	}
    94 
    95 /**
    96   Performs escape encoding in all modes and compares actual & expected result.
    97   @param		aDecodeComp A descriptor with the data to encode.
    98   @param		aExpEncodedUrl An expected descriptor for the escape Mode EEscapeUrlEncoded.
    99   @param		aExpEncodedAut An expected descriptor for the escape Mode EEscapeAuth.
   100   @param		aExpEncodedPath An expected descriptor for the escape Mode EEscapePath.
   101   @param		aExpEncodedQuery An expected descriptor for the escape Mode EEscapeQuery.
   102   @param		aExpEncodedNormal An expected descriptor for the escape Mode EEscapeNormal.
   103 */	
   104 void CTestEscapeEncodeUriStep::EscEncodeAndCompareUriL(const TDesC& aDecodeComp,const TDesC& aExpEncodedUrl,const TDesC& aExpEncodedAut,const TDesC& aExpEncodedPath,const TDesC& aExpEncodedQuery,const TDesC& aExpEncodedNormal)
   105 	{
   106 	HBufC8* decodeBuf = HBufC8::NewLC(aDecodeComp.Length());
   107 	TPtr8 decode8Bit(decodeBuf->Des());
   108 	decode8Bit.Copy(aDecodeComp);
   109 	//Authority mode Encoding 
   110 	TestComponentEncodingL(decode8Bit, aExpEncodedAut, EscapeUtils::EEscapeAuth );
   111      //Path mode Encoding
   112     TestComponentEncodingL(decode8Bit, aExpEncodedPath, EscapeUtils::EEscapePath );
   113     //Query mode Encoding
   114     TestComponentEncodingL(decode8Bit, aExpEncodedQuery, EscapeUtils::EEscapeQuery );
   115     //Normal mode Encoding
   116     TestComponentEncodingL(decode8Bit, aExpEncodedNormal, EscapeUtils::EEscapeNormal );
   117     //Url mode Encoding
   118     TestComponentEncodingL(decode8Bit, aExpEncodedUrl, EscapeUtils::EEscapeUrlEncoded );
   119     
   120     CleanupStack::PopAndDestroy(decodeBuf);
   121     }
   122 	
   123 /**
   124   Performs escape encoding the mode specifed and compares actual & expected result.
   125   @param		aDecode8Bit A descriptor with the data to encode.
   126   @param		aExpEncodedComponent An expected descriptor for the escape mode specified.
   127   @param		aMode An enum specifying the escape mode.
   128 */
   129 void CTestEscapeEncodeUriStep::TestComponentEncodingL(const TDesC8& aDecode8Bit, const TDesC& aExpEncodedComponent, EscapeUtils::TEscapeMode aMode )
   130 	{
   131 	//Component Encoding 
   132 	HBufC8* expEncodedComponentBuf = HBufC8::NewLC(aExpEncodedComponent.Length());
   133 	TPtr8 expEncodedComponent8Bit(expEncodedComponentBuf->Des());
   134 	expEncodedComponent8Bit.Copy(aExpEncodedComponent);
   135 
   136     HBufC8* encodedComponent=EscapeUtils::EscapeEncodeL(aDecode8Bit,aMode);
   137     if(expEncodedComponent8Bit.Compare(*encodedComponent)!=0)
   138 	    {
   139 	    switch (aMode)
   140 		    {
   141 		    case EscapeUtils::EEscapeAuth:
   142 		    	{
   143 		    	ERR_PRINTF1(_L("Test step failed: EEscapeAuth - EscapeEncoding done wrongly.\n"));
   144 		    	break;
   145 		    	}
   146 		    case EscapeUtils::EEscapePath:
   147 		    	{
   148 		    	ERR_PRINTF1(_L("Test step failed: EEscapePath - EscapeEncoding done wrongly.\n"));
   149 		    	break;
   150 		    	}
   151 		    case EscapeUtils::EEscapeQuery:
   152 		    	{
   153 		    	ERR_PRINTF1(_L("Test step failed: EEscapeQuery - EscapeEncoding done wrongly.\n"));
   154 		    	break;
   155 		    	}
   156 		    case EscapeUtils::EEscapeNormal:
   157 		    	{
   158 		    	ERR_PRINTF1(_L("Test step failed: EEscapeNormal - EscapeEncoding done wrongly.\n"));
   159 		    	break;
   160 		    	}
   161 		    case EscapeUtils::EEscapeUrlEncoded:
   162 		    	{
   163 		    	ERR_PRINTF1(_L("Test step failed: EEscapeUrlEncoded - EscapeEncoding done wrongly.\n"));
   164 		    	break;
   165 		    	}
   166 		    default:
   167 		    	{
   168 		    	//do nothing
   169 		    	break;	
   170 		    	}
   171 		    }
   172 	    
   173 		SetTestStepResult(EFail);
   174 	    }
   175     delete encodedComponent;
   176     CleanupStack::PopAndDestroy(expEncodedComponentBuf);	
   177 	}
   178 
   179