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