os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestNormaliseUriStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestNormaliseUriStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,263 @@
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 CTestNormaliseUriStep class
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file TESTNORMALISEURISTEP.CPP
1.23 + @internalTechnology
1.24 +*/
1.25 +
1.26 +// User Include
1.27 +#include "TestNormaliseUriStep.h"
1.28 +// System Include
1.29 +#include <uriutils.h>
1.30 +#include <uri8.h>
1.31 +
1.32 +//constants
1.33 +const TInt KAlreadyNormalised = 0;
1.34 +const TInt KPercentEncoding = 1;
1.35 +const TInt KCaseNormalisation = 2;
1.36 +const TInt KRemoveDotegments = 3;
1.37 +const TInt KPercentCaseNormalisation = 12;
1.38 +const TInt KPercentRemoveDotegments = 13;
1.39 +const TInt KCaseRemoveDotegments = 23;
1.40 +const TInt KAll = 123;
1.41 +
1.42 +/**
1.43 + Constructor: Sets the test step name.
1.44 + @internalTechnology
1.45 + @test
1.46 +*/
1.47 +CTestNormaliseUriStep::CTestNormaliseUriStep()
1.48 + {
1.49 + //Call base class method to set human readable name for test step
1.50 + SetTestStepName(KTestNormaliseUriStep);
1.51 + }
1.52 +
1.53 +/**
1.54 + Destructor
1.55 + @internalTechnology
1.56 + @test
1.57 +*/
1.58 +CTestNormaliseUriStep::~CTestNormaliseUriStep()
1.59 + {
1.60 +
1.61 + }
1.62 +
1.63 +/**
1.64 + Does the main functionality test.
1.65 + Here, reads values from INI file and calls NormaliseAndCompareUriL
1.66 + @internalTechnology
1.67 + @param None
1.68 + @return EPass or EFail indicating the success or failure of the test step
1.69 +*/
1.70 +TVerdict CTestNormaliseUriStep::doTestStepL()
1.71 + {
1.72 + __UHEAP_MARK;
1.73 + INFO_PRINTF1(_L("\n"));
1.74 + // Get necessary information from INI file
1.75 +
1.76 + TPtrC uri;
1.77 + TPtrC expUri;
1.78 + TInt RetCode;
1.79 +
1.80 + if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) ||
1.81 + !GetStringFromConfig(ConfigSection(), KIniExpectedUri, expUri) ||
1.82 + !GetIntFromConfig(ConfigSection(), KRetCode, RetCode) )
1.83 + {
1.84 + ERR_PRINTF3(_L("Problem in reading values from ini. \
1.85 + \nExpected fields are: \n%S\n%S\n"),&KIniUri, &KIniExpectedUri);
1.86 + SetTestStepResult(EFail);
1.87 + }
1.88 + else
1.89 + {// No problem in reading values from INI file. Proceed.
1.90 + TRAPD(err, NormaliseAndCompareUriL(uri,expUri));
1.91 + if(err != KErrNone)
1.92 + {
1.93 + ERR_PRINTF2(_L("Test step failed: Leave occured in NormaliseAndCompareUriL fun: %D\n"), err);
1.94 + SetTestStepResult(EFail);
1.95 + }
1.96 + }
1.97 + __UHEAP_MARKEND;
1.98 + switch (RetCode)
1.99 + {
1.100 + case KAlreadyNormalised :
1.101 + {
1.102 + INFO_PRINTF1(_L("\nAlready in Normalised Form"));
1.103 + break;
1.104 + }
1.105 + case KPercentEncoding :
1.106 + {
1.107 + INFO_PRINTF1(_L("\nNormalised through PercentEncoding"));
1.108 + break;
1.109 + }
1.110 + case KCaseNormalisation :
1.111 + {
1.112 + INFO_PRINTF1(_L("\nNormalised through CaseNormalisation"));
1.113 + break;
1.114 + }
1.115 + case KRemoveDotegments :
1.116 + {
1.117 + INFO_PRINTF1(_L("\nNormalised through RemoveDotegments"));
1.118 + break;
1.119 + }
1.120 + case KPercentCaseNormalisation :
1.121 + {
1.122 + INFO_PRINTF1(_L("\nNormalised through PercentEncoding and CaseNormalisation"));
1.123 + break;
1.124 + }
1.125 + case KPercentRemoveDotegments :
1.126 + {
1.127 + INFO_PRINTF1(_L("\nNormalised through PercentEncoding and RemoveDotegments"));
1.128 + break;
1.129 + }
1.130 + case KCaseRemoveDotegments :
1.131 + {
1.132 + INFO_PRINTF1(_L("\nNormalised through CaseNormalisation and RemoveDotegments"));
1.133 + break;
1.134 + }
1.135 + case KAll :
1.136 + {
1.137 + INFO_PRINTF1(_L("\nNormalised through CaseNormalisation,PercentEncoding and RemoveDotegments"));
1.138 + break;
1.139 + }
1.140 + default:
1.141 + {
1.142 + //do nothing
1.143 + break;
1.144 + }
1.145 + }
1.146 + INFO_PRINTF1(_L("\nTest of UriNormalisation is Executed\n"));
1.147 + return TestStepResult();
1.148 + }
1.149 +
1.150 +/**
1.151 + Performs syntax normalisation and compares actual & expected result.
1.152 + @param aUri A reference to actual Uri to be normalised
1.153 + @param aExpUri A reference to expected uri.
1.154 +*/
1.155 +void CTestNormaliseUriStep::NormaliseAndCompareUriL(const TDesC& aUri,const TDesC& aExpUri)
1.156 + {
1.157 + CUri8* cUri8=NULL;
1.158 + TRAPD(err, cUri8=UriUtils::CreateUriL(aUri));
1.159 + if(err != KErrNone)
1.160 + {
1.161 + ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
1.162 + SetTestStepResult(EFail);
1.163 + }
1.164 + else
1.165 + {
1.166 + const TUriC8& tUri(cUri8->Uri());
1.167 + CUri8* normalisedUri = NULL;
1.168 + CleanupStack::PushL(cUri8);
1.169 + INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation."));
1.170 + TRAPD(error, normalisedUri=UriUtils::NormaliseUriL(tUri));
1.171 + if(error == KErrNone)
1.172 + {
1.173 + INFO_PRINTF1(_L("URI normalised."));
1.174 + CleanupStack::PushL(normalisedUri);
1.175 + HBufC8* uriBuf = HBufC8::NewLC(aExpUri.Length());
1.176 + TPtr8 expUri8(uriBuf->Des());
1.177 + expUri8.Copy(aExpUri);
1.178 + // Comparing actual & expected uris.
1.179 + if(normalisedUri->Uri().UriDes().Compare(expUri8)!=0)
1.180 + {
1.181 + ERR_PRINTF1(_L("Test step failed: actualUri is not matched with expectedUri."));
1.182 + SetTestStepResult(EFail);
1.183 + }
1.184 + CleanupStack::PopAndDestroy(3, cUri8);
1.185 + }
1.186 + }
1.187 + }
1.188 +
1.189 +
1.190 +/**
1.191 + Constructor: Sets the test step name.
1.192 + @internalTechnology
1.193 + @test
1.194 +*/
1.195 +CTestNormaliseUriOomStep::CTestNormaliseUriOomStep()
1.196 + {
1.197 + //Call base class method to set human readable name for test step
1.198 + SetTestStepName(KTestOomNormaliseUriStep);
1.199 + }
1.200 +
1.201 +/**
1.202 + Destructor
1.203 + @internalTechnology
1.204 + @test
1.205 +*/
1.206 +CTestNormaliseUriOomStep::~CTestNormaliseUriOomStep()
1.207 + {
1.208 +
1.209 + }
1.210 +
1.211 +/**
1.212 + Does the main functionality and OOM test of a test step.
1.213 + @internalTechnology
1.214 + @param None
1.215 + @return EPass or EFail indicating the success or failure of the test step
1.216 +*/
1.217 +TVerdict CTestNormaliseUriOomStep::doTestStepL()
1.218 + {
1.219 + __UHEAP_MARK;
1.220 + TPtrC uri;
1.221 + if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) )
1.222 + {
1.223 + ERR_PRINTF2(_L("Problem in reading values from ini. \
1.224 + \nExpected fields are: \n%S\n"),&KIniUri);
1.225 + SetTestStepResult(EFail);
1.226 + }
1.227 + else
1.228 + {// No problem in reading values from INI file. Proceed.
1.229 + CUri8* cUri8=NULL;
1.230 + TRAPD(err, cUri8=UriUtils::CreateUriL(uri));
1.231 + if(err != KErrNone)
1.232 + {
1.233 + ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
1.234 + SetTestStepResult(EFail);
1.235 + }
1.236 + else
1.237 + {
1.238 + const TUriC8& tUri(cUri8->Uri());
1.239 + CleanupStack::PushL(cUri8);
1.240 + INFO_PRINTF1(_L("Calling UriUtils::NormaliseUriL which does syntax normalisation."));
1.241 + TInt ret = KErrNoMemory;
1.242 + TInt failAt = 0;
1.243 + while(ret != KErrNone)
1.244 + {
1.245 + failAt++;
1.246 + INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
1.247 +
1.248 + __UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
1.249 + __UHEAP_MARK;
1.250 + CUri8* normalisedUri = NULL;
1.251 + TRAP( ret, normalisedUri = UriUtils::NormaliseUriL(tUri));
1.252 + delete normalisedUri;
1.253 + __UHEAP_MARKEND;
1.254 + __UHEAP_RESET;
1.255 + if((ret == KErrNoMemory) || (ret == KErrNone))
1.256 + {
1.257 + INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
1.258 + }
1.259 + }
1.260 + CleanupStack::PopAndDestroy(cUri8);
1.261 + }
1.262 + }
1.263 + __UHEAP_MARKEND;
1.264 + return TestStepResult();
1.265 + }
1.266 +