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