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 CTestTelUriParsingStep class
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalTechnology
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
// User Include
|
sl@0
|
24 |
#include "TestTelUriParsingStep.h"
|
sl@0
|
25 |
// System Include
|
sl@0
|
26 |
#include <uri8.h>
|
sl@0
|
27 |
#include <uriutilscommon.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
Constructor: Sets the test step name.
|
sl@0
|
31 |
@internalTechnology
|
sl@0
|
32 |
@test
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
CTestTelUriParsingStep::CTestTelUriParsingStep()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
//Call base class method to set human readable name for test step
|
sl@0
|
37 |
SetTestStepName(KTestTelUriParsingStep);
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
/**
|
sl@0
|
41 |
Destructor
|
sl@0
|
42 |
@internalTechnology
|
sl@0
|
43 |
@test
|
sl@0
|
44 |
*/
|
sl@0
|
45 |
CTestTelUriParsingStep::~CTestTelUriParsingStep()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
Does the main functionality of a test step.
|
sl@0
|
52 |
Here, reads values from INI file
|
sl@0
|
53 |
and calls TestTelUriParsingAndCompareL() which does parsing of a tel uri.
|
sl@0
|
54 |
@internalTechnology
|
sl@0
|
55 |
@param None
|
sl@0
|
56 |
@return EPass or EFail indicating the success or failure of the test step
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
TVerdict CTestTelUriParsingStep::doTestStepL()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
__UHEAP_MARK;
|
sl@0
|
61 |
INFO_PRINTF1(_L("\n"));
|
sl@0
|
62 |
// Get necessary information from INI file
|
sl@0
|
63 |
TPtrC telUri;
|
sl@0
|
64 |
TPtrC expTelScheme;
|
sl@0
|
65 |
TPtrC expTelPath;
|
sl@0
|
66 |
|
sl@0
|
67 |
if(!GetStringFromConfig(ConfigSection(), KIniUri, telUri) ||
|
sl@0
|
68 |
!GetStringFromConfig(ConfigSection(), KIniExpectedTelScheme, expTelScheme) ||
|
sl@0
|
69 |
!GetStringFromConfig(ConfigSection(), KIniExpectedTelPath, expTelPath) )
|
sl@0
|
70 |
{
|
sl@0
|
71 |
ERR_PRINTF4(_L("Problem in reading values from ini. \
|
sl@0
|
72 |
\nExpected fields are: \n%S\n%S\n%S\n"
|
sl@0
|
73 |
),&KIniUri, &KIniExpectedTelScheme, &KIniExpectedTelPath
|
sl@0
|
74 |
);
|
sl@0
|
75 |
SetTestStepResult(EFail);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
else
|
sl@0
|
78 |
{
|
sl@0
|
79 |
// No problem in reading values from INI file. Proceed.
|
sl@0
|
80 |
// Calling TestTelUriParsingL which does parisng of tel uri and comparing results.
|
sl@0
|
81 |
TRAPD(err, TestTelUriParsingAndCompareL(telUri,expTelScheme, expTelPath));
|
sl@0
|
82 |
if(err != KErrNone)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
ERR_PRINTF2(_L("Test step failed: Tel URI parsing failed: %D\n"), err);
|
sl@0
|
85 |
SetTestStepResult(EFail);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
}
|
sl@0
|
88 |
__UHEAP_MARKEND;
|
sl@0
|
89 |
INFO_PRINTF1(_L("\nTest of TelUriParsing is Executed\n"));
|
sl@0
|
90 |
return TestStepResult();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
/**
|
sl@0
|
94 |
Performs tel uri parsing and compares actual & expected result.
|
sl@0
|
95 |
@param aUri A reference to tel-uri to be parsed.
|
sl@0
|
96 |
@param aScheme A reference to expected scheme component of tel-uri.
|
sl@0
|
97 |
@param aPath A reference to expected path component of tel-uri.
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
void CTestTelUriParsingStep::TestTelUriParsingAndCompareL(const TDesC16& aUri, const TDesC16& aScheme, const TDesC16& aPath)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
// Make 8-bit copies
|
sl@0
|
102 |
HBufC8* uriBuf = HBufC8::NewLC(aUri.Length());
|
sl@0
|
103 |
TPtr8 uri8Bit(uriBuf->Des());
|
sl@0
|
104 |
uri8Bit.Copy(aUri);
|
sl@0
|
105 |
|
sl@0
|
106 |
TUriParser8 uriParser;
|
sl@0
|
107 |
TInt error = KErrNone;
|
sl@0
|
108 |
error = uriParser.Parse(uri8Bit);
|
sl@0
|
109 |
// Is this a valid Uri?
|
sl@0
|
110 |
if( error != KErrNone )
|
sl@0
|
111 |
{
|
sl@0
|
112 |
ERR_PRINTF2(_L("Tel URI parsing failed: %D\n"), error);
|
sl@0
|
113 |
SetTestStepResult(EFail);
|
sl@0
|
114 |
User::LeaveIfError(error);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
// Check scheme...
|
sl@0
|
118 |
TInt result = TestComponentL(uriParser, aScheme, EUriScheme);
|
sl@0
|
119 |
if( result != 0 )
|
sl@0
|
120 |
{
|
sl@0
|
121 |
ERR_PRINTF1(_L("Scheme component not matched \n"));
|
sl@0
|
122 |
User::LeaveIfError(KUriUtilsErrDifferentScheme);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
// Check path...
|
sl@0
|
126 |
result = TestComponentL(uriParser, aPath, EUriPath);
|
sl@0
|
127 |
if( result != 0)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
ERR_PRINTF1(_L("Path component not matched \n"));
|
sl@0
|
130 |
User::LeaveIfError(KUriUtilsErrDifferentPath);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
//tel-uri Should not contain Host, UserInfo, Port, Query and Fragment components.
|
sl@0
|
134 |
// Check host...
|
sl@0
|
135 |
const TDesC8& host = uriParser.Extract(EUriHost);
|
sl@0
|
136 |
if( (host.Length() != 0) || (host.Size() != 0) )
|
sl@0
|
137 |
{
|
sl@0
|
138 |
ERR_PRINTF1(_L("host component is not empty, but it should be empty. \n"));
|
sl@0
|
139 |
User::LeaveIfError(KUriUtilsErrDifferentHost);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
//Check UserInfo...
|
sl@0
|
143 |
const TDesC8& userInfo = uriParser.Extract(EUriUserinfo);
|
sl@0
|
144 |
if( (userInfo.Length() != 0) || (userInfo.Size() != 0) )
|
sl@0
|
145 |
{
|
sl@0
|
146 |
ERR_PRINTF1(_L("UserInfo component is not empty, but it should be empty. \n"));
|
sl@0
|
147 |
User::LeaveIfError(KUriUtilsErrDifferentUserInfo);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
//Check port...
|
sl@0
|
151 |
const TDesC8& uriPort = uriParser.Extract(EUriPort);
|
sl@0
|
152 |
if( (uriPort.Length() != 0) || (uriPort.Size() != 0) )
|
sl@0
|
153 |
{
|
sl@0
|
154 |
ERR_PRINTF1(_L("Port component is not empty, but it should be empty. \n"));
|
sl@0
|
155 |
User::LeaveIfError(KUriUtilsErrDifferentPort);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
//Check query...
|
sl@0
|
159 |
const TDesC8& uriQuery = uriParser.Extract(EUriQuery);
|
sl@0
|
160 |
if( (uriQuery.Length() != 0) || (uriQuery.Size() != 0) )
|
sl@0
|
161 |
{
|
sl@0
|
162 |
ERR_PRINTF1(_L("Query component is not empty, but it should be empty. \n"));
|
sl@0
|
163 |
User::LeaveIfError(KUriUtilsErrDifferentQuery);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
//Check fragment...
|
sl@0
|
167 |
const TDesC8& uriFrag = uriParser.Extract(EUriFragment);
|
sl@0
|
168 |
if( (uriFrag.Length() != 0) || (uriFrag.Size() != 0) )
|
sl@0
|
169 |
{
|
sl@0
|
170 |
ERR_PRINTF1(_L("Fragment component is not empty, but it should be empty. \n"));
|
sl@0
|
171 |
User::LeaveIfError(KUriUtilsErrDifferentFragment);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
CleanupStack::PopAndDestroy(uriBuf);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
/**
|
sl@0
|
177 |
It extracts and compares with expected component for specified TUriComponent.
|
sl@0
|
178 |
@param aParser A reference to parsed tel-uri.
|
sl@0
|
179 |
@param aExpectedComponent A reference to expected component of tel-uri.
|
sl@0
|
180 |
@param aComponent Enumeration of TUriComponent.
|
sl@0
|
181 |
*/
|
sl@0
|
182 |
TInt CTestTelUriParsingStep::TestComponentL(const TUriParser8& aParser, const TDesC16& aExpectedComponent,TUriComponent aComponent)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
HBufC8* expectedBuf = HBufC8::NewLC(aExpectedComponent.Length());
|
sl@0
|
185 |
TPtr8 expected8Bit = expectedBuf->Des();
|
sl@0
|
186 |
expected8Bit.Copy(aExpectedComponent);
|
sl@0
|
187 |
TInt result = aParser.Extract(aComponent).Compare(expected8Bit);
|
sl@0
|
188 |
CleanupStack::PopAndDestroy(expectedBuf);
|
sl@0
|
189 |
return result;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
|
sl@0
|
193 |
|