os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestNormaliseUriStep.cpp
First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Contains implementation of CTestNormaliseUriStep class
19 @file TESTNORMALISEURISTEP.CPP
24 #include "TestNormaliseUriStep.h"
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;
40 Constructor: Sets the test step name.
44 CTestNormaliseUriStep::CTestNormaliseUriStep()
46 //Call base class method to set human readable name for test step
47 SetTestStepName(KTestNormaliseUriStep);
55 CTestNormaliseUriStep::~CTestNormaliseUriStep()
61 Does the main functionality test.
62 Here, reads values from INI file and calls NormaliseAndCompareUriL
65 @return EPass or EFail indicating the success or failure of the test step
67 TVerdict CTestNormaliseUriStep::doTestStepL()
70 INFO_PRINTF1(_L("\n"));
71 // Get necessary information from INI file
77 if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) ||
78 !GetStringFromConfig(ConfigSection(), KIniExpectedUri, expUri) ||
79 !GetIntFromConfig(ConfigSection(), KRetCode, RetCode) )
81 ERR_PRINTF3(_L("Problem in reading values from ini. \
82 \nExpected fields are: \n%S\n%S\n"),&KIniUri, &KIniExpectedUri);
83 SetTestStepResult(EFail);
86 {// No problem in reading values from INI file. Proceed.
87 TRAPD(err, NormaliseAndCompareUriL(uri,expUri));
90 ERR_PRINTF2(_L("Test step failed: Leave occured in NormaliseAndCompareUriL fun: %D\n"), err);
91 SetTestStepResult(EFail);
97 case KAlreadyNormalised :
99 INFO_PRINTF1(_L("\nAlready in Normalised Form"));
102 case KPercentEncoding :
104 INFO_PRINTF1(_L("\nNormalised through PercentEncoding"));
107 case KCaseNormalisation :
109 INFO_PRINTF1(_L("\nNormalised through CaseNormalisation"));
112 case KRemoveDotegments :
114 INFO_PRINTF1(_L("\nNormalised through RemoveDotegments"));
117 case KPercentCaseNormalisation :
119 INFO_PRINTF1(_L("\nNormalised through PercentEncoding and CaseNormalisation"));
122 case KPercentRemoveDotegments :
124 INFO_PRINTF1(_L("\nNormalised through PercentEncoding and RemoveDotegments"));
127 case KCaseRemoveDotegments :
129 INFO_PRINTF1(_L("\nNormalised through CaseNormalisation and RemoveDotegments"));
134 INFO_PRINTF1(_L("\nNormalised through CaseNormalisation,PercentEncoding and RemoveDotegments"));
143 INFO_PRINTF1(_L("\nTest of UriNormalisation is Executed\n"));
144 return TestStepResult();
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.
152 void CTestNormaliseUriStep::NormaliseAndCompareUriL(const TDesC& aUri,const TDesC& aExpUri)
155 TRAPD(err, cUri8=UriUtils::CreateUriL(aUri));
158 ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
159 SetTestStepResult(EFail);
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)
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)
178 ERR_PRINTF1(_L("Test step failed: actualUri is not matched with expectedUri."));
179 SetTestStepResult(EFail);
181 CleanupStack::PopAndDestroy(3, cUri8);
188 Constructor: Sets the test step name.
192 CTestNormaliseUriOomStep::CTestNormaliseUriOomStep()
194 //Call base class method to set human readable name for test step
195 SetTestStepName(KTestOomNormaliseUriStep);
203 CTestNormaliseUriOomStep::~CTestNormaliseUriOomStep()
209 Does the main functionality and OOM test of a test step.
212 @return EPass or EFail indicating the success or failure of the test step
214 TVerdict CTestNormaliseUriOomStep::doTestStepL()
218 if(!GetStringFromConfig(ConfigSection(), KIniUri, uri) )
220 ERR_PRINTF2(_L("Problem in reading values from ini. \
221 \nExpected fields are: \n%S\n"),&KIniUri);
222 SetTestStepResult(EFail);
225 {// No problem in reading values from INI file. Proceed.
227 TRAPD(err, cUri8=UriUtils::CreateUriL(uri));
230 ERR_PRINTF2(_L("Test step failed: Leave occured in Uri object creation: %D\n"), err);
231 SetTestStepResult(EFail);
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;
240 while(ret != KErrNone)
243 INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
245 __UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
247 CUri8* normalisedUri = NULL;
248 TRAP( ret, normalisedUri = UriUtils::NormaliseUriL(tUri));
249 delete normalisedUri;
252 if((ret == KErrNoMemory) || (ret == KErrNone))
254 INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
257 CleanupStack::PopAndDestroy(cUri8);
261 return TestStepResult();