|
1 // Copyright (c) 2001-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 // |
|
15 |
|
16 #include "CUriAndAuthorityTest.h" |
|
17 |
|
18 #include <e32base.h> |
|
19 |
|
20 #include "UriAndAuthorityTestCommon.h" |
|
21 #include <uriutilscommon.h> |
|
22 #include <uriutils.h> |
|
23 #include "UriAndAuthorityTests.h" |
|
24 #include "SipUriAndAuthorityTests.h" |
|
25 |
|
26 CUriAndAuthorityTest* CUriAndAuthorityTest::NewLC(CIpuTestHarness* aTestHarness) |
|
27 { |
|
28 CUriAndAuthorityTest* self = new (ELeave) CUriAndAuthorityTest(aTestHarness); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CUriAndAuthorityTest* CUriAndAuthorityTest::NewL(CIpuTestHarness* aTestHarness) |
|
35 { |
|
36 CUriAndAuthorityTest* self = CUriAndAuthorityTest::NewLC(aTestHarness); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CUriAndAuthorityTest::CUriAndAuthorityTest(CIpuTestHarness* aTestHarness) |
|
42 : iTestHarness(aTestHarness) |
|
43 { |
|
44 } |
|
45 |
|
46 void CUriAndAuthorityTest::ConstructL() |
|
47 { |
|
48 } |
|
49 |
|
50 CUriAndAuthorityTest::~CUriAndAuthorityTest() |
|
51 { |
|
52 } |
|
53 |
|
54 void CUriAndAuthorityTest::DoTestsL() |
|
55 { |
|
56 // Test TUriParser Component Extraction |
|
57 TestUriComponentExtractionL(KComps0, KScheme0, KUserInfo0, KHost0, KPort0, KPath0, KQuery0, KFragment0); |
|
58 TestUriComponentExtractionL(KComps1, KScheme1, KUserInfo1, KHost1, KPort1, KPath1, KQuery1, KFragment1); |
|
59 TestUriComponentExtractionL(KComps2, KScheme2, KUserInfo2, KHost2, KPort2, KPath2, KQuery2, KFragment2); |
|
60 TestUriComponentExtractionL(KComps3, KScheme3, KUserInfo3, KHost3, KPort3, KPath3, KQuery3, KFragment3); |
|
61 TestUriComponentExtractionL(KComps4, KScheme4, KUserInfo4, KHost4, KPort4, KPath4, KQuery4, KFragment4); |
|
62 TestUriComponentExtractionL(KComps5, KScheme5, KUserInfo5, KHost5, KPort5, KPath5, KQuery5, KFragment5); |
|
63 TestUriComponentExtractionL(KComps6, KScheme6, KUserInfo6, KHost6, KPort6, KPath6, KQuery6, KFragment6); |
|
64 TestUriComponentExtractionL(KComps10, KScheme10, KUserInfo10, KHost10, KPort10, KPath10, KQuery10, KFragment10); |
|
65 TestUriComponentExtractionL(KComps11, KScheme11, KUserInfo11, KHost11, KPort11, KPath11, KQuery11, KFragment11); |
|
66 TestUriComponentExtractionL(KComps12, KScheme12, KUserInfo12, KHost12, KPort12, KPath12, KQuery12, KFragment12); |
|
67 TestUriComponentExtractionL(KComps13, KScheme13, KUserInfo13, KHost13, KPort13, KPath13, KQuery13, KFragment13); |
|
68 TestUriComponentExtractionL(KComps14, KScheme14, KUserInfo14, KHost14, KPort14, KPath14, KQuery14, KFragment14); |
|
69 TestUriComponentExtractionL(KComps15, KScheme15, KUserInfo15, KHost15, KPort15, KPath15, KQuery15, KFragment15); |
|
70 TestUriComponentExtractionL(KComps16, KScheme16, KUserInfo16, KHost16, KPort16, KPath16, KQuery16, KFragment16); |
|
71 TestUriComponentExtractionL(KComps17, KScheme17, KUserInfo17, KHost17, KPort17, KPath17, KQuery17, KFragment17); |
|
72 TestUriComponentExtractionL(KComps18, KScheme18, KUserInfo18, KHost18, KPort18, KPath18, KQuery18, KFragment18); |
|
73 TestUriComponentExtractionL(KComps19, KScheme19, KUserInfo19, KHost19, KPort19, KPath19, KQuery19, KFragment19); |
|
74 TestUriComponentExtractionL(KComps20, KScheme20, KUserInfo20, KHost20, KPort20, KPath20, KQuery20, KFragment20); |
|
75 TestUriComponentExtractionL(KComps21, KScheme21, KUserInfo21, KHost21, KPort21, KPath21, KQuery21, KFragment21); |
|
76 TestUriComponentExtractionL(KComps22, KScheme22, KUserInfo22, KHost22, KPort22, KPath22, KQuery22, KFragment22); |
|
77 TestUriComponentExtractionL(KComps23, KScheme23, KUserInfo23, KHost23, KPort23, KPath23, KQuery23, KFragment23); |
|
78 TestUriComponentExtractionL(KComps24, KScheme24, KUserInfo24, KHost24, KPort24, KPath24, KQuery24, KFragment24); |
|
79 TestUriComponentExtractionL(KComps25, KScheme25, KUserInfo25, KHost25, KPort25, KPath25, KQuery25, KFragment25); |
|
80 TestUriComponentExtractionL(KComps26, KScheme26, KUserInfo26, KHost26, KPort26, KPath26, KQuery26, KFragment26); |
|
81 TestUriComponentExtractionL(KComps27, KScheme27, KUserInfo27, KHost27, KPort27, KPath27, KQuery27, KFragment27); |
|
82 TestUriComponentExtractionL(KComps28, KScheme28, KUserInfo28, KHost28, KPort28, KPath28, KQuery28, KFragment28); |
|
83 TestUriComponentExtractionL(KComps29, KScheme29, KUserInfo29, KHost29, KPort29, KPath29, KQuery29, KFragment29); |
|
84 |
|
85 // |
|
86 // IPv6 Test cases Section 2.9.1 |
|
87 TestUriComponentExtractionL(KComps30, KScheme30, KUserInfo30, KHost30, KPort30, KPath30, KQuery30, KFragment30); |
|
88 TestUriComponentExtractionL(KComps31, KScheme31, KUserInfo31, KHost31, KPort31, KPath31, KQuery31, KFragment31); |
|
89 TestUriComponentExtractionL(KComps32, KScheme32, KUserInfo32, KHost32, KPort32, KPath32, KQuery32, KFragment32); |
|
90 TestUriComponentExtractionL(KComps33, KScheme33, KUserInfo33, KHost33, KPort33, KPath33, KQuery33, KFragment33); |
|
91 TestUriComponentExtractionL(KComps34, KScheme34, KUserInfo34, KHost34, KPort34, KPath34, KQuery34, KFragment34); |
|
92 TestUriComponentExtractionL(KComps35, KScheme35, KUserInfo35, KHost35, KPort35, KPath35, KQuery35, KFragment35); |
|
93 TestUriComponentExtractionL(KComps36, KScheme36, KUserInfo36, KHost36, KPort36, KPath36, KQuery36, KFragment36); |
|
94 |
|
95 TestAuthorityComponentExtractionL(KAuthority0, KUserInfo0, KHost0, KPort0); |
|
96 TestAuthorityComponentExtractionL(KAuthority1, KUserInfo1, KHost1, KPort1); |
|
97 TestAuthorityComponentExtractionL(KAuthority2, KUserInfo2, KHost2, KPort2); |
|
98 TestAuthorityComponentExtractionL(KAuthority3, KUserInfo3, KHost3, KPort3); |
|
99 TestAuthorityComponentExtractionL(KAuthority4, KUserInfo4, KHost4, KPort4); |
|
100 TestAuthorityComponentExtractionL(KAuthority5, KUserInfo5, KHost5, KPort5); |
|
101 TestAuthorityComponentExtractionL(KAuthority6, KUserInfo6, KHost6, KPort6); |
|
102 TestAuthorityComponentExtractionL(KAuthority10, KUserInfo10, KHost10, KPort10); |
|
103 TestAuthorityComponentExtractionL(KAuthority11, KUserInfo11, KHost11, KPort11); |
|
104 TestAuthorityComponentExtractionL(KAuthority12, KUserInfo12, KHost12, KPort12); |
|
105 TestAuthorityComponentExtractionL(KAuthority13, KUserInfo13, KHost13, KPort13); |
|
106 TestAuthorityComponentExtractionL(KAuthority14, KUserInfo14, KHost14, KPort14); |
|
107 TestAuthorityComponentExtractionL(KAuthority15, KUserInfo15, KHost15, KPort15); |
|
108 TestAuthorityComponentExtractionL(KAuthority16, KUserInfo16, KHost16, KPort16); |
|
109 TestAuthorityComponentExtractionL(KAuthority17, KUserInfo17, KHost17, KPort17); |
|
110 TestAuthorityComponentExtractionL(KAuthority18, KUserInfo18, KHost18, KPort18); |
|
111 TestAuthorityComponentExtractionL(KAuthority19, KUserInfo19, KHost19, KPort19); |
|
112 TestAuthorityComponentExtractionL(KAuthority20, KUserInfo20, KHost20, KPort20); |
|
113 TestAuthorityComponentExtractionL(KAuthority21, KUserInfo21, KHost21, KPort21); |
|
114 TestAuthorityComponentExtractionL(KAuthority22, KUserInfo22, KHost22, KPort22); |
|
115 TestAuthorityComponentExtractionL(KAuthority23, KUserInfo23, KHost23, KPort23); |
|
116 TestAuthorityComponentExtractionL(KAuthority24, KUserInfo24, KHost24, KPort24); |
|
117 TestAuthorityComponentExtractionL(KAuthority25, KUserInfo25, KHost25, KPort25); |
|
118 TestAuthorityComponentExtractionL(KAuthority26, KUserInfo26, KHost26, KPort26); |
|
119 TestAuthorityComponentExtractionL(KAuthority27, KUserInfo27, KHost27, KPort27); |
|
120 TestAuthorityComponentExtractionL(KAuthority28, KUserInfo28, KHost28, KPort28); |
|
121 TestAuthorityComponentExtractionL(KAuthority29, KUserInfo29, KHost29, KPort29); |
|
122 |
|
123 // IPv6 Test cases |
|
124 TestAuthorityComponentExtractionL(KAuthority30, KUserInfo30, KHost30, KPort30); |
|
125 TestAuthorityComponentExtractionL(KAuthority31, KUserInfo31, KHost31, KPort31); |
|
126 TestAuthorityComponentExtractionL(KAuthority32, KUserInfo32, KHost32, KPort32); |
|
127 TestAuthorityComponentExtractionL(KAuthority33, KUserInfo33, KHost33, KPort33); |
|
128 TestAuthorityComponentExtractionL(KAuthority34, KUserInfo34, KHost34, KPort34); |
|
129 TestAuthorityComponentExtractionL(KAuthority35, KUserInfo35, KHost35, KPort35); |
|
130 TestAuthorityComponentExtractionL(KAuthority36, KUserInfo36, KHost36, KPort36); |
|
131 |
|
132 TestResolveL(KBase,KRelative1,KResolved1); |
|
133 TestResolveL(KBase,KRelative2,KResolved2); |
|
134 TestResolveL(KBase,KRelative3,KResolved3); |
|
135 TestResolveL(KBase,KRelative4,KResolved4); |
|
136 TestResolveL(KBase,KRelative5,KResolved5); |
|
137 TestResolveL(KBase,KRelative6,KResolved6); |
|
138 TestResolveL(KBase,KRelative7,KResolved7); |
|
139 TestResolveL(KBase,KRelative8,KResolved8); |
|
140 TestResolveL(KBase,KRelative9,KResolved9); |
|
141 TestResolveL(KBase,KRelative10,KResolved10); |
|
142 TestResolveL(KBase,KRelative11,KResolved11); |
|
143 TestResolveL(KBase,KRelative12,KResolved12); |
|
144 TestResolveL(KBase,KRelative13,KResolved13); |
|
145 TestResolveL(KBase,KRelative14,KResolved14); |
|
146 TestResolveL(KBase,KRelative15,KResolved15); |
|
147 TestResolveL(KBase,KRelative16,KResolved16); |
|
148 TestResolveL(KBase,KRelative17,KResolved17); |
|
149 TestResolveL(KBase,KRelative18,KResolved18); |
|
150 TestResolveL(KBase,KRelative19,KResolved19); |
|
151 TestResolveL(KBase,KRelative20,KResolved20); |
|
152 TestResolveL(KBase,KRelative21,KResolved21); |
|
153 TestResolveL(KBase,KRelative22,KResolved22); |
|
154 |
|
155 TestResolveL(KBase,KRelative23,KResolved23); |
|
156 TestResolveL(KBase,KRelative24,KResolved24); |
|
157 TestResolveL(KBase,KRelative25,KResolved25); |
|
158 TestResolveL(KBase,KRelative26,KResolved26); |
|
159 TestResolveL(KBase,KRelative27,KResolved27); |
|
160 TestResolveL(KBase,KRelative28,KResolved28); |
|
161 TestResolveL(KBase,KRelative29,KResolved29); |
|
162 TestResolveL(KBase,KRelative30,KResolved30); |
|
163 |
|
164 TestResolveL(KBase,KRelative31,KResolved31); |
|
165 TestResolveL(KBase,KRelative32,KResolved32); |
|
166 TestResolveL(KBase,KRelative33,KResolved33); |
|
167 TestResolveL(KBase,KRelative34,KResolved34); |
|
168 TestResolveL(KBase,KRelative35,KResolved35); |
|
169 TestResolveL(KBase,KRelative36,KResolved36); |
|
170 |
|
171 TestResolveL(KBase,KRelative37,KResolved37); |
|
172 TestResolveL(KBase,KRelative38,KResolved38); |
|
173 TestResolveL(KBase,KRelative39,KResolved39); |
|
174 TestResolveL(KBase,KRelative40,KResolved40); |
|
175 |
|
176 TestResolveL(KBase,KRelative41,KResolved41); |
|
177 |
|
178 TestResolveL(KBase,KRelative42,KResolved42); |
|
179 |
|
180 iTestHarness->LogIt(_L("Next Test - Defect EDNMTAN-4H9K6A, CUrlWrap::ResolveL does not parse file Urls properly")); |
|
181 TestResolveL(KBaseFile, KRelativeFile1, KResolvedFile1); |
|
182 |
|
183 iTestHarness->LogIt(_L("Next Test - Defect EDNSTAR-4HTNB4, CUrlWrap::ResolveL panics with zero length aUrlBase")); |
|
184 TestResolveL(KNullDesC, KRelativeFile1, KRelativeFile1); |
|
185 |
|
186 iTestHarness->LogIt(_L("Next Test - Defect EDNPHAD-4J6EUY, CUrlWrap::ResolveL fails when the base and relative URLs both have fragments")); |
|
187 TestResolveL(KBaseBug1, KRelativeBug1, KResolvedBug1); |
|
188 TestResolveL(KBaseBug2, KRelativeBug2, KResolvedBug2); |
|
189 TestResolveL(KBaseBug2, KRelativeBug3, KResolvedBug3); |
|
190 |
|
191 iTestHarness->LogIt(_L("Next Test - Defect EDNFUDN-4JYFH7, CUrl overflow causes WINS crash during sub-doc fetch")); |
|
192 TestResolveL(KBaseBug3, KRelativeBug4, KResolvedBug4); |
|
193 |
|
194 TestUriCompareL(KUri_Compare0_a, KUri_Compare0_b, KUriMatchFlags0); |
|
195 TestUriCompareL(KUri_Compare1_a, KUri_Compare1_b, KUriMatchFlags1); |
|
196 |
|
197 // IPv6 Test cases for section 2.9.1.1.1 |
|
198 TestUriCompareL(KUri_Compare2_a, KUri_Compare2_b, KUriMatchFlags2); |
|
199 // and section 2.9.1.1.2 |
|
200 TestUriCompareL(KUri_Compare3_a, KUri_Compare3_b, KUriMatchFlags3); |
|
201 |
|
202 TestAuthorityCompareL(KAuth_Compare0_a, KAuth_Compare0_b, KAuthMatchFlags0); |
|
203 TestAuthorityCompareL(KAuth_Compare1_a, KAuth_Compare1_b, KAuthMatchFlags1); |
|
204 |
|
205 TestUriComponentPresenceL(KUri_Presence0, KUriPresenceFlags0); |
|
206 TestUriComponentPresenceL(KUri_Presence1, KUriPresenceFlags1); |
|
207 |
|
208 TestAuthorityComponentPresenceL(KAuthority_Presence0, KAuthorityPresenceFlags0); |
|
209 TestAuthorityComponentPresenceL(KAuthority_Presence1, KAuthorityPresenceFlags1); |
|
210 |
|
211 TestUriDesL(KUri_Des0); |
|
212 |
|
213 TestAuthorityDesL(KAuthority_Des0); |
|
214 |
|
215 TestUriSchemeValidiyL(KUri_SchemeValidation0, KUri_SchemeValidity0); |
|
216 TestUriSchemeValidiyL(KUri_SchemeValidation1, KUri_SchemeValidity1); |
|
217 |
|
218 TestUriWithoutFragmentL(KUri_WithoutFragment0, KUri_WithoutFragment_Result0); |
|
219 TestUriWithoutFragmentL(KUri_WithoutFragment1, KUri_WithoutFragment_Result1); |
|
220 |
|
221 TestUriSetComponentL(KUri_Scheme0, KUri_Host0, KUri_Userinfo0, KUri_Port0, KUri_Path0, KUri_Query0, KUri_Fragment0, |
|
222 KUri_SchemeComp0, KUri_HostComp0, KUri_UserinfoComp0, KUri_PortComp0, KUri_PathComp0, KUri_QueryComp0, KUri_FragmentComp0); |
|
223 |
|
224 TestUriRemoveComponentL(KUri_NoScheme0, KUri_NoHost0, KUri_NoUserinfo0, KUri_NoPort0, KUri_NoPath0, |
|
225 KUri_NoQuery0, KUri_NoFragment0, KUri_Whole0); |
|
226 |
|
227 // Same test as above, but with an IPv6 format host, section 2.9.1.4 |
|
228 // Apart from the IPv6 address, the component data from the previous test can be reused |
|
229 TestUriSetComponentL(KUri_Scheme0, KUri_IPv6Host0, KUri_IPv6UserInfo0, KUri_IPv6Port0, KUri_IPv6Path0, KUri_IPv6Query0, KUri_IPv6Fragment0, |
|
230 KUri_SchemeComp0, KUri_IPv6HostComp0, KUri_UserinfoComp0, KUri_PortComp0, KUri_PathComp0, KUri_QueryComp0, KUri_FragmentComp0); |
|
231 |
|
232 TestUriRemoveComponentL(KUri_IPv6NoScheme0, KUri_IPv6NoHost0, KUri_IPv6NoUserinfo0, KUri_IPv6NoPort0, KUri_IPv6NoPath0, |
|
233 KUri_IPv6NoQuery0, KUri_IPv6NoFragment0, KUri_IPv6Whole0); |
|
234 |
|
235 TestAuthoritySetComponentL(KAuthority_Host0, KAuthority_Userinfo0, KAuthority_Port0, |
|
236 KAuthority_HostComp0, KAuthority_UserinfoComp0, KAuthority_PortComp0); |
|
237 |
|
238 TestAuthoritySetAndEscapeComponentL(KAuthorityEscaped_Host0, KAuthorityEscaped_Userinfo0, KAuthorityEscaped_Port0, |
|
239 KAuthorityEscaped_HostComp0, KAuthorityEscaped_UserinfoComp0, KAuthorityEscaped_PortComp0); |
|
240 |
|
241 TestAuthorityRemoveComponentL(KAuthority_NoHost0, KAuthority_NoUserinfo0, KAuthority_NoPort0, KAuthority_Whole0); |
|
242 |
|
243 // Same tests as above but for IPv6, as per section 2.9.1.4 |
|
244 TestAuthoritySetComponentL(KAuthority_IPv6Host0, KAuthority_IPv6Userinfo0, KAuthority_IPv6Port0, |
|
245 KAuthority_IPv6HostComp0, KAuthority_IPv6UserinfoComp0, KAuthority_IPv6PortComp0); |
|
246 |
|
247 TestAuthorityRemoveComponentL(KAuthority_IPv6NoHost0, KAuthority_IPv6NoUserinfo0, KAuthority_IPv6NoPort0, KAuthority_IPv6Whole0); |
|
248 } |
|
249 |
|
250 // |
|
251 // |
|
252 // Uri Tests |
|
253 // |
|
254 // |
|
255 |
|
256 void CUriAndAuthorityTest::TestUriComponentExtractionL(const TDesC16& aUri, const TDesC16& aScheme, |
|
257 const TDesC16& aUserinfo, const TDesC16& aHost, |
|
258 const TDesC16& aPort, const TDesC16& aPath, |
|
259 const TDesC16& aQuery, const TDesC16& aFragment) const |
|
260 { |
|
261 iTestHarness->StartTestL(_L("Test TUriParser Component Extraction (deprecated 16-bit )")); |
|
262 iTestHarness->LogIt(_L("Uri - %S"), &aUri); |
|
263 |
|
264 TInt error = DoUriComponentExtraction<TUriParser16>(aUri, aScheme, aUserinfo, aHost, aPort, aPath, aQuery, aFragment); |
|
265 |
|
266 //check for failed Sip test |
|
267 if (KErrNotFound!=aPath.Find(_L(",")) && KErrNotFound!=aScheme.Find(_L("sIp"))) |
|
268 { |
|
269 iTestHarness->LogIt(KCompsSipUriInvalidMess6); |
|
270 error=KErrNone; |
|
271 } |
|
272 iTestHarness->EndTest(error); |
|
273 |
|
274 iTestHarness->StartTestL(_L("Test TUriParser Component Extraction")); |
|
275 iTestHarness->LogIt(_L("Uri - %S"), &aUri); |
|
276 |
|
277 |
|
278 TRAP( error , DoUriComponentExtractionL(aUri, aScheme, aUserinfo, aHost, aPort, aPath, aQuery, aFragment) ) |
|
279 |
|
280 //check for failed Sip test |
|
281 if (aPath.Find(_L(","))!=KErrNotFound && aScheme.Find(_L("sIp")) != KErrNotFound) |
|
282 { |
|
283 iTestHarness->LogIt(KCompsSipUriInvalidMess6); |
|
284 error=KErrNone; |
|
285 } |
|
286 iTestHarness->EndTest(error); |
|
287 |
|
288 // Make 8-bit copies |
|
289 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); |
|
290 TPtr8 uri8Bit = uriBuf->Des(); |
|
291 uri8Bit.Copy(aUri); |
|
292 |
|
293 HBufC8* schemeBuf = HBufC8::NewLC(aScheme.Length()); |
|
294 TPtr8 scheme8Bit = schemeBuf->Des(); |
|
295 scheme8Bit.Copy(aScheme); |
|
296 |
|
297 HBufC8* userinfoBuf = HBufC8::NewLC(aUserinfo.Length()); |
|
298 TPtr8 userinfo8Bit = userinfoBuf->Des(); |
|
299 userinfo8Bit.Copy(aUserinfo); |
|
300 |
|
301 HBufC8* hostBuf = HBufC8::NewLC(aHost.Length()); |
|
302 TPtr8 host8Bit = hostBuf->Des(); |
|
303 host8Bit.Copy(aHost); |
|
304 |
|
305 HBufC8* portBuf = HBufC8::NewLC(aPort.Length()); |
|
306 TPtr8 port8Bit = portBuf->Des(); |
|
307 port8Bit.Copy(aPort); |
|
308 |
|
309 HBufC8* pathBuf = HBufC8::NewLC(aPath.Length()); |
|
310 TPtr8 path8Bit = pathBuf->Des(); |
|
311 path8Bit.Copy(aPath); |
|
312 |
|
313 HBufC8* queryBuf = HBufC8::NewLC(aQuery.Length()); |
|
314 TPtr8 query8Bit = queryBuf->Des(); |
|
315 query8Bit.Copy(aQuery); |
|
316 |
|
317 HBufC8* fragmentBuf = HBufC8::NewLC(aFragment.Length()); |
|
318 TPtr8 fragment8Bit = fragmentBuf->Des(); |
|
319 fragment8Bit.Copy(aFragment); |
|
320 |
|
321 iTestHarness->StartTestL(_L("Test TUriParser Component Extraction (8-bit)")); |
|
322 iTestHarness->LogIt(_L("Uri - %S"), &aUri); |
|
323 |
|
324 error = DoUriComponentExtraction<TUriParser8>(uri8Bit, scheme8Bit, userinfo8Bit, host8Bit, port8Bit, path8Bit, query8Bit, fragment8Bit); |
|
325 |
|
326 //check for failed Sip test |
|
327 if (aPath.Find(_L(","))!=KErrNotFound && aScheme.Find(_L("sIp"))!=KErrNotFound) |
|
328 { |
|
329 iTestHarness->LogIt(KCompsSipUriInvalidMess6); |
|
330 error=KErrNone; |
|
331 } |
|
332 iTestHarness->EndTest(error); |
|
333 |
|
334 CleanupStack::PopAndDestroy(8, uriBuf); // uriBuf, schemeBuf, userinfoBuf, hostBuf, portBuf, pathBuf, queryBuf, fragmentBuf |
|
335 } |
|
336 |
|
337 void CUriAndAuthorityTest::TestResolveL(const TDesC& aBase, const TDesC& aReference, const TDesC& aExpected) const |
|
338 { |
|
339 iTestHarness->StartTestL(_L("Testing Resolving Functionality (16-bit)")); |
|
340 iTestHarness->LogIt(_L("Test Resolving %S , %S -> %S"), &aBase, &aReference, &aExpected); |
|
341 |
|
342 TInt error = DoTestResolve<TUriParser16, CUri16>(aBase, aReference, aExpected); |
|
343 |
|
344 iTestHarness->EndTest(error); |
|
345 |
|
346 // Make 8-bit copies |
|
347 HBufC8* baseBuf = HBufC8::NewLC(aBase.Length()); |
|
348 TPtr8 base8Bit = baseBuf->Des(); |
|
349 base8Bit.Copy(aBase); |
|
350 |
|
351 HBufC8* refBuf = HBufC8::NewLC(aReference.Length()); |
|
352 TPtr8 ref8Bit = refBuf->Des(); |
|
353 ref8Bit.Copy(aReference); |
|
354 |
|
355 HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length()); |
|
356 TPtr8 expected8Bit = expectedBuf->Des(); |
|
357 expected8Bit.Copy(aExpected); |
|
358 |
|
359 iTestHarness->StartTestL(_L("Testing Resolving Functionality (8-bit)")); |
|
360 |
|
361 //Abnormal examples below differs from RFC 2396 to the current implementation of |
|
362 //RFC3986. So, the expected output for ResolveL for Uri8 is modified to support |
|
363 //section 5.4.2 of RFC 3986. |
|
364 |
|
365 if( aReference.Compare(KRelative23) == 0 || |
|
366 aReference.Compare(KRelative24) == 0 || |
|
367 aReference.Compare(KRelative25) == 0 || |
|
368 aReference.Compare(KRelative26) == 0 ) |
|
369 { |
|
370 _LIT8(KRfc3986,"http://a/g"); |
|
371 expected8Bit.Copy(KRfc3986); |
|
372 _LIT(KRfc3986Bit16,"http://a/g"); |
|
373 iTestHarness->LogIt(_L("Test Resolving as per RFC3986 %S , %S -> %S"), &aBase, &aReference, &KRfc3986Bit16); |
|
374 } |
|
375 else |
|
376 { |
|
377 iTestHarness->LogIt(_L("Test Resolving %S , %S -> %S"), &aBase, &aReference, &aExpected); |
|
378 } |
|
379 error = DoTestResolve<TUriParser8, CUri8>(base8Bit, ref8Bit, expected8Bit); |
|
380 |
|
381 iTestHarness->EndTest(error); |
|
382 |
|
383 CleanupStack::PopAndDestroy(3, baseBuf); // baseBuf, refBuf, expectedBuf |
|
384 } |
|
385 |
|
386 void CUriAndAuthorityTest::TestUriCompareL(const TDesC& aUri1, const TDesC& aUri2, TInt aMatchFlags) const |
|
387 { |
|
388 iTestHarness->StartTestL(_L("Test TUriC Component Compare (16-bit)")); |
|
389 |
|
390 TInt error = DoUriCompare<TUriParser16>(aUri1, aUri2, aMatchFlags); |
|
391 |
|
392 iTestHarness->EndTest(error); |
|
393 |
|
394 // Make 8-bit copies |
|
395 HBufC8* uriBuf1 = HBufC8::NewLC(aUri1.Length()); |
|
396 TPtr8 uri8Bit1 = uriBuf1->Des(); |
|
397 uri8Bit1.Copy(aUri1); |
|
398 |
|
399 HBufC8* uriBuf2 = HBufC8::NewLC(aUri2.Length()); |
|
400 TPtr8 uri8Bit2 = uriBuf2->Des(); |
|
401 uri8Bit2.Copy(aUri2); |
|
402 |
|
403 iTestHarness->StartTestL(_L("Test TUriC Component Compare (8-bit)")); |
|
404 |
|
405 error = DoUriCompare<TUriParser8>(uri8Bit1, uri8Bit2, aMatchFlags); |
|
406 |
|
407 iTestHarness->EndTest(error); |
|
408 |
|
409 CleanupStack::PopAndDestroy(2, uriBuf1); // uriBuf1, uriBuf2 |
|
410 } |
|
411 |
|
412 void CUriAndAuthorityTest::TestUriComponentPresenceL(const TDesC& aUri, TInt aPresenceFlags) const |
|
413 { |
|
414 iTestHarness->StartTestL(_L("Test TUriC Component Presence (16-bit)")); |
|
415 |
|
416 TInt error = DoUriComponentPresence<TUriParser16>(aUri, aPresenceFlags); |
|
417 |
|
418 iTestHarness->EndTest(error); |
|
419 |
|
420 // Make 8-bit copy |
|
421 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); |
|
422 TPtr8 uri8Bit = uriBuf->Des(); |
|
423 uri8Bit.Copy(aUri); |
|
424 |
|
425 iTestHarness->StartTestL(_L("Test TUriC Component Presence (8-bit)")); |
|
426 |
|
427 error = DoUriComponentPresence<TUriParser8>(uri8Bit, aPresenceFlags); |
|
428 |
|
429 iTestHarness->EndTest(error); |
|
430 |
|
431 CleanupStack::PopAndDestroy(uriBuf); // uriBuf |
|
432 } |
|
433 |
|
434 void CUriAndAuthorityTest::TestUriDesL(const TDesC& aUri) const |
|
435 { |
|
436 iTestHarness->StartTestL(_L("Test TUriC UriDes() (16-bit deprecated)")); |
|
437 |
|
438 TInt error = DoUriDes<TUriParser16>(aUri); |
|
439 |
|
440 iTestHarness->EndTest(error); |
|
441 |
|
442 iTestHarness->StartTestL(_L("Test TUriC UriDes() (16-bit)")); |
|
443 |
|
444 TRAP( error , DoUriDesL(aUri) ); |
|
445 |
|
446 iTestHarness->EndTest(error); |
|
447 |
|
448 // Make 8-bit copy |
|
449 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); |
|
450 TPtr8 uri8Bit = uriBuf->Des(); |
|
451 uri8Bit.Copy(aUri); |
|
452 |
|
453 iTestHarness->StartTestL(_L("Test TUriC UriDes() (8-bit)")); |
|
454 |
|
455 error = DoUriDes<TUriParser8>(uri8Bit); |
|
456 |
|
457 iTestHarness->EndTest(error); |
|
458 |
|
459 CleanupStack::PopAndDestroy(uriBuf); // uriBuf |
|
460 } |
|
461 |
|
462 void CUriAndAuthorityTest::TestUriSchemeValidiyL(const TDesC& aUri, TBool aValidScheme) const |
|
463 { |
|
464 iTestHarness->StartTestL(_L("Test TUriC Scheme Validation (16-bit)")); |
|
465 |
|
466 TInt error = DoUriSchemeValidation<TUriParser16>(aUri, aValidScheme); |
|
467 |
|
468 iTestHarness->EndTest(error); |
|
469 |
|
470 // Make 8-bit copy |
|
471 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); |
|
472 TPtr8 uri8Bit = uriBuf->Des(); |
|
473 uri8Bit.Copy(aUri); |
|
474 |
|
475 iTestHarness->StartTestL(_L("Test TUriC Scheme Validation (8-bit)")); |
|
476 |
|
477 error = DoUriSchemeValidation<TUriParser8>(uri8Bit, aValidScheme); |
|
478 |
|
479 iTestHarness->EndTest(error); |
|
480 |
|
481 CleanupStack::PopAndDestroy(uriBuf); // uriBuf |
|
482 } |
|
483 |
|
484 void CUriAndAuthorityTest::TestUriWithoutFragmentL(const TDesC& aUri, const TDesC& aExpected) |
|
485 { |
|
486 iTestHarness->StartTestL(_L("Test TUriC Uri Without Fragment (16-bit)")); |
|
487 |
|
488 TInt error = DoUriWithoutFragment<TUriParser16, TPtrC16>(aUri, aExpected); |
|
489 |
|
490 iTestHarness->EndTest(error); |
|
491 |
|
492 // Make 8-bit copy |
|
493 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length()); |
|
494 TPtr8 uri8Bit = uriBuf->Des(); |
|
495 uri8Bit.Copy(aUri); |
|
496 |
|
497 HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length()); |
|
498 TPtr8 expected8Bit = expectedBuf->Des(); |
|
499 expected8Bit.Copy(aExpected); |
|
500 |
|
501 iTestHarness->StartTestL(_L("Test TUriC Uri Without Fragment (8-bit)")); |
|
502 |
|
503 error = DoUriWithoutFragment<TUriParser8, TPtrC8>(uri8Bit, expected8Bit); |
|
504 |
|
505 iTestHarness->EndTest(error); |
|
506 |
|
507 CleanupStack::PopAndDestroy(2, uriBuf); // uriBuf, expectedBuf |
|
508 } |
|
509 |
|
510 void CUriAndAuthorityTest::TestUriSetComponentL(const TDesC& aUri_Scheme, const TDesC& aUri_Host, const TDesC& aUri_Userinfo, |
|
511 const TDesC& aUri_Port, const TDesC& aUri_Path, const TDesC& aUri_Query, |
|
512 const TDesC& aUri_Fragment, const TDesC& aScheme, const TDesC& aHost, |
|
513 const TDesC& aUserinfo, const TDesC& aPort, const TDesC& aPath, |
|
514 const TDesC& aQuery, const TDesC& aFragment) const |
|
515 |
|
516 { |
|
517 iTestHarness->StartTestL(_L("Test CUri SetComponentL (16-bit)")); |
|
518 |
|
519 TInt error = DoUriConstruction<CUri16>(aUri_Scheme, aUri_Host, aUri_Userinfo, aUri_Port, aUri_Path, |
|
520 aUri_Query, aUri_Fragment, aScheme, aHost, aUserinfo, aPort, aPath, aQuery, aFragment); |
|
521 |
|
522 iTestHarness->EndTest(error); |
|
523 |
|
524 // Make 8-bit copies |
|
525 HBufC8* uri_SchemeBuf = HBufC8::NewLC(aUri_Scheme.Length()); |
|
526 TPtr8 uri_Scheme8Bit = uri_SchemeBuf->Des(); |
|
527 uri_Scheme8Bit.Copy(aUri_Scheme); |
|
528 |
|
529 HBufC8* uri_HostBuf = HBufC8::NewLC(aUri_Host.Length()); |
|
530 TPtr8 uri_Host8Bit = uri_HostBuf->Des(); |
|
531 uri_Host8Bit.Copy(aUri_Host); |
|
532 |
|
533 HBufC8* uri_UserinfoBuf = HBufC8::NewLC(aUri_Userinfo.Length()); |
|
534 TPtr8 uri_Userinfo8Bit = uri_UserinfoBuf->Des(); |
|
535 uri_Userinfo8Bit.Copy(aUri_Userinfo); |
|
536 |
|
537 HBufC8* uri_PortBuf = HBufC8::NewLC(aUri_Port.Length()); |
|
538 TPtr8 uri_Port8Bit = uri_PortBuf->Des(); |
|
539 uri_Port8Bit.Copy(aUri_Port); |
|
540 |
|
541 HBufC8* uri_PathBuf = HBufC8::NewLC(aUri_Path.Length()); |
|
542 TPtr8 uri_Path8Bit = uri_PathBuf->Des(); |
|
543 uri_Path8Bit.Copy(aUri_Path); |
|
544 |
|
545 HBufC8* uri_QueryBuf = HBufC8::NewLC(aUri_Query.Length()); |
|
546 TPtr8 uri_Query8Bit = uri_QueryBuf->Des(); |
|
547 uri_Query8Bit.Copy(aUri_Query); |
|
548 |
|
549 HBufC8* uri_FragmentBuf = HBufC8::NewLC(aUri_Fragment.Length()); |
|
550 TPtr8 uri_Fragment8Bit = uri_FragmentBuf->Des(); |
|
551 uri_Fragment8Bit.Copy(aUri_Fragment); |
|
552 |
|
553 // And the individual components |
|
554 HBufC8* schemeBuf = HBufC8::NewLC(aScheme.Length()); |
|
555 TPtr8 scheme8Bit = schemeBuf->Des(); |
|
556 scheme8Bit.Copy(aScheme); |
|
557 |
|
558 HBufC8* userinfoBuf = HBufC8::NewLC(aUserinfo.Length()); |
|
559 TPtr8 userinfo8Bit = userinfoBuf->Des(); |
|
560 userinfo8Bit.Copy(aUserinfo); |
|
561 |
|
562 HBufC8* hostBuf = HBufC8::NewLC(aHost.Length()); |
|
563 TPtr8 host8Bit = hostBuf->Des(); |
|
564 host8Bit.Copy(aHost); |
|
565 |
|
566 HBufC8* portBuf = HBufC8::NewLC(aPort.Length()); |
|
567 TPtr8 port8Bit = portBuf->Des(); |
|
568 port8Bit.Copy(aPort); |
|
569 |
|
570 HBufC8* pathBuf = HBufC8::NewLC(aPath.Length()); |
|
571 TPtr8 path8Bit = pathBuf->Des(); |
|
572 path8Bit.Copy(aPath); |
|
573 |
|
574 HBufC8* queryBuf = HBufC8::NewLC(aQuery.Length()); |
|
575 TPtr8 query8Bit = queryBuf->Des(); |
|
576 query8Bit.Copy(aQuery); |
|
577 |
|
578 HBufC8* fragmentBuf = HBufC8::NewLC(aFragment.Length()); |
|
579 TPtr8 fragment8Bit = fragmentBuf->Des(); |
|
580 fragment8Bit.Copy(aFragment); |
|
581 |
|
582 iTestHarness->StartTestL(_L("Test CUri SetComponentL (8-bit)")); |
|
583 |
|
584 error = DoUriConstruction<CUri8>(uri_Scheme8Bit, uri_Host8Bit, uri_Userinfo8Bit, uri_Port8Bit, uri_Path8Bit, |
|
585 uri_Query8Bit, uri_Fragment8Bit, scheme8Bit, host8Bit, userinfo8Bit, port8Bit, path8Bit, query8Bit, fragment8Bit); |
|
586 |
|
587 iTestHarness->EndTest(error); |
|
588 CleanupStack::PopAndDestroy(14, uri_SchemeBuf); // too many to list! |
|
589 } |
|
590 |
|
591 void CUriAndAuthorityTest::TestUriRemoveComponentL(const TDesC& aUri_NoScheme, const TDesC& aUri_NoHost, const TDesC& aUri_NoUserinfo, |
|
592 const TDesC& aUri_NoPort, const TDesC& aUri_NoPath, const TDesC& aUri_NoQuery, |
|
593 const TDesC& aUri_NoFragment, const TDesC& aUri_Whole) const |
|
594 { |
|
595 iTestHarness->StartTestL(_L("Test CUri RemoveComponentL (16-bit)")); |
|
596 |
|
597 TInt error = DoUriDestruction<CUri16, TUriParser16>(aUri_NoScheme, aUri_NoHost, aUri_NoUserinfo, aUri_NoPort, aUri_NoPath, |
|
598 aUri_NoQuery, aUri_NoFragment, aUri_Whole); |
|
599 |
|
600 iTestHarness->EndTest(error); |
|
601 |
|
602 // Make 8-bit copies |
|
603 HBufC8* uri_NoSchemeBuf = HBufC8::NewLC(aUri_NoScheme.Length()); |
|
604 TPtr8 uri_NoScheme8Bit = uri_NoSchemeBuf->Des(); |
|
605 uri_NoScheme8Bit.Copy(aUri_NoScheme); |
|
606 |
|
607 HBufC8* uri_NoHostBuf = HBufC8::NewLC(aUri_NoHost.Length()); |
|
608 TPtr8 uri_NoHost8Bit = uri_NoHostBuf->Des(); |
|
609 uri_NoHost8Bit.Copy(aUri_NoHost); |
|
610 |
|
611 HBufC8* uri_NoUserinfoBuf = HBufC8::NewLC(aUri_NoUserinfo.Length()); |
|
612 TPtr8 uri_NoUserinfo8Bit = uri_NoUserinfoBuf->Des(); |
|
613 uri_NoUserinfo8Bit.Copy(aUri_NoUserinfo); |
|
614 |
|
615 HBufC8* uri_NoPortBuf = HBufC8::NewLC(aUri_NoPort.Length()); |
|
616 TPtr8 uri_NoPort8Bit = uri_NoPortBuf->Des(); |
|
617 uri_NoPort8Bit.Copy(aUri_NoPort); |
|
618 |
|
619 HBufC8* uri_NoPathBuf = HBufC8::NewLC(aUri_NoPath.Length()); |
|
620 TPtr8 uri_NoPath8Bit = uri_NoPathBuf->Des(); |
|
621 uri_NoPath8Bit.Copy(aUri_NoPath); |
|
622 |
|
623 HBufC8* uri_NoQueryBuf = HBufC8::NewLC(aUri_NoQuery.Length()); |
|
624 TPtr8 uri_NoQuery8Bit = uri_NoQueryBuf->Des(); |
|
625 uri_NoQuery8Bit.Copy(aUri_NoQuery); |
|
626 |
|
627 HBufC8* uri_NoFragmentBuf = HBufC8::NewLC(aUri_NoFragment.Length()); |
|
628 TPtr8 uri_NoFragment8Bit = uri_NoFragmentBuf->Des(); |
|
629 uri_NoFragment8Bit.Copy(aUri_NoFragment); |
|
630 |
|
631 HBufC8* uri_WholeBuf = HBufC8::NewLC(aUri_Whole.Length()); |
|
632 TPtr8 uri_Whole8Bit = uri_WholeBuf->Des(); |
|
633 uri_Whole8Bit.Copy(aUri_Whole); |
|
634 |
|
635 iTestHarness->StartTestL(_L("Test CUri RemoveComponentL (8-bit)")); |
|
636 |
|
637 error = DoUriDestruction<CUri8, TUriParser8>(uri_NoScheme8Bit, uri_NoHost8Bit, uri_NoUserinfo8Bit, uri_NoPort8Bit, |
|
638 uri_NoPath8Bit, uri_NoQuery8Bit, uri_NoFragment8Bit, uri_Whole8Bit); |
|
639 |
|
640 iTestHarness->EndTest(error); |
|
641 CleanupStack::PopAndDestroy(8, uri_NoSchemeBuf); // too many to list! |
|
642 } |
|
643 |
|
644 // |
|
645 // |
|
646 // Authority Tests |
|
647 // |
|
648 // |
|
649 |
|
650 void CUriAndAuthorityTest::TestAuthorityComponentExtractionL(const TDesC16& aAuthority, const TDesC16& aUserinfo, |
|
651 const TDesC16& aHost, const TDesC16& aPort) const |
|
652 { |
|
653 iTestHarness->StartTestL(_L("Test TAuthority Component Extraction (deprecated 16-bit)")); |
|
654 iTestHarness->LogIt(_L("Uri - %S"), &aAuthority); |
|
655 |
|
656 TInt error = DoAuthorityComponentExtraction<TAuthorityParser16>(aAuthority, aUserinfo, aHost, aPort); |
|
657 |
|
658 iTestHarness->EndTest(error); |
|
659 |
|
660 iTestHarness->StartTestL(_L("Test TAuthority Component Extraction (16-bit)")); |
|
661 iTestHarness->LogIt(_L("Uri - %S"), &aAuthority); |
|
662 |
|
663 TRAP(error, DoAuthorityComponentExtractionL(aAuthority, aUserinfo, aHost, aPort) ); |
|
664 |
|
665 iTestHarness->EndTest(error); |
|
666 |
|
667 // Make 8-bit copies |
|
668 HBufC8* authorityBuf = HBufC8::NewLC(aAuthority.Length()); |
|
669 TPtr8 authority8Bit = authorityBuf->Des(); |
|
670 authority8Bit.Copy(aAuthority); |
|
671 |
|
672 HBufC8* userinfoBuf = HBufC8::NewLC(aUserinfo.Length()); |
|
673 TPtr8 userinfo8Bit = userinfoBuf->Des(); |
|
674 userinfo8Bit.Copy(aUserinfo); |
|
675 |
|
676 HBufC8* hostBuf = HBufC8::NewLC(aHost.Length()); |
|
677 TPtr8 host8Bit = hostBuf->Des(); |
|
678 host8Bit.Copy(aHost); |
|
679 |
|
680 HBufC8* portBuf = HBufC8::NewLC(aPort.Length()); |
|
681 TPtr8 port8Bit = portBuf->Des(); |
|
682 port8Bit.Copy(aPort); |
|
683 |
|
684 iTestHarness->StartTestL(_L("Test TAuthority Component Extraction (8-bit)")); |
|
685 iTestHarness->LogIt(_L("Uri - %S"), &aAuthority); |
|
686 |
|
687 error = DoAuthorityComponentExtraction<TAuthorityParser8>(authority8Bit, userinfo8Bit, host8Bit, port8Bit); |
|
688 |
|
689 iTestHarness->EndTest(error); |
|
690 |
|
691 CleanupStack::PopAndDestroy(4, authorityBuf); // authorityBuf, userInfoBuf, hostBuf, portBuf |
|
692 } |
|
693 |
|
694 void CUriAndAuthorityTest::TestAuthorityCompareL(const TDesC& aAuthority1, const TDesC& aAuthority2, TInt aMatchFlags) const |
|
695 { |
|
696 iTestHarness->StartTestL(_L("Test TAuthorityC Component Compare (16-bit)")); |
|
697 |
|
698 TInt error = DoAuthorityCompare<TAuthorityParser16>(aAuthority1, aAuthority2, aMatchFlags); |
|
699 |
|
700 iTestHarness->EndTest(error); |
|
701 |
|
702 // Make 8-bit copies |
|
703 HBufC8* authorityBuf1 = HBufC8::NewLC(aAuthority1.Length()); |
|
704 TPtr8 authority8Bit1 = authorityBuf1->Des(); |
|
705 authority8Bit1.Copy(aAuthority1); |
|
706 |
|
707 HBufC8* authorityBuf2 = HBufC8::NewLC(aAuthority2.Length()); |
|
708 TPtr8 authority8Bit2 = authorityBuf2->Des(); |
|
709 authority8Bit2.Copy(aAuthority2); |
|
710 |
|
711 iTestHarness->StartTestL(_L("Test TAuthorityC Component Compare (8-bit)")); |
|
712 |
|
713 error = DoAuthorityCompare<TAuthorityParser8>(authority8Bit1, authority8Bit2, aMatchFlags); |
|
714 |
|
715 iTestHarness->EndTest(error); |
|
716 |
|
717 CleanupStack::PopAndDestroy(2, authorityBuf1); // authorityBuf1, authorityBuf2 |
|
718 } |
|
719 |
|
720 void CUriAndAuthorityTest::TestAuthorityComponentPresenceL(const TDesC& aAuthority, TInt aPresenceFlags) const |
|
721 { |
|
722 iTestHarness->StartTestL(_L("Test TAuthorityC Component Presence (16-bit)")); |
|
723 |
|
724 TInt error = DoAuthorityComponentPresence<TAuthorityParser16>(aAuthority, aPresenceFlags); |
|
725 |
|
726 iTestHarness->EndTest(error); |
|
727 |
|
728 // Make 8-bit copy |
|
729 HBufC8* authorityBuf = HBufC8::NewLC(aAuthority.Length()); |
|
730 TPtr8 authority8Bit = authorityBuf->Des(); |
|
731 authority8Bit.Copy(aAuthority); |
|
732 |
|
733 iTestHarness->StartTestL(_L("Test TAuthorityC Component Presence (8-bit)")); |
|
734 |
|
735 error = DoAuthorityComponentPresence<TAuthorityParser8>(authority8Bit, aPresenceFlags); |
|
736 |
|
737 iTestHarness->EndTest(error); |
|
738 |
|
739 CleanupStack::PopAndDestroy(authorityBuf); // authorityBuf |
|
740 } |
|
741 |
|
742 void CUriAndAuthorityTest::TestAuthorityDesL(const TDesC& aAuthority) |
|
743 { |
|
744 iTestHarness->StartTestL(_L("Test TAuthorityC AuthorityDes() (16-bit deprecated)")); |
|
745 |
|
746 TInt error = DoAuthorityDes<TAuthorityParser16>(aAuthority); |
|
747 |
|
748 iTestHarness->EndTest(error); |
|
749 |
|
750 iTestHarness->StartTestL(_L("Test TAuthorityC AuthorityDes() (16-bit)")); |
|
751 |
|
752 TRAP( error , DoAuthorityDesL(aAuthority) ); |
|
753 |
|
754 iTestHarness->EndTest(error); |
|
755 |
|
756 // Make 8-bit copy |
|
757 HBufC8* authorityBuf = HBufC8::NewLC(aAuthority.Length()); |
|
758 TPtr8 authority8Bit = authorityBuf->Des(); |
|
759 authority8Bit.Copy(aAuthority); |
|
760 |
|
761 iTestHarness->StartTestL(_L("Test TAuthorityC AuthorityDes() (8-bit)")); |
|
762 |
|
763 error = DoAuthorityDes<TAuthorityParser8>(authority8Bit); |
|
764 |
|
765 iTestHarness->EndTest(error); |
|
766 |
|
767 CleanupStack::PopAndDestroy(authorityBuf); // authorityBuf |
|
768 } |
|
769 |
|
770 void CUriAndAuthorityTest::TestAuthoritySetComponentL(const TDesC& aAuthority_Host, const TDesC& aAuthority_Userinfo, |
|
771 const TDesC& aAuthority_Port, const TDesC& aHost, |
|
772 const TDesC& aUserinfo, const TDesC& aPort) |
|
773 |
|
774 { |
|
775 iTestHarness->StartTestL(_L("Test CAuthority SetComponentL (16-bit)")); |
|
776 |
|
777 TInt error = DoAuthorityConstruction<CAuthority16>(aAuthority_Host, aAuthority_Userinfo, aAuthority_Port, |
|
778 aHost, aUserinfo, aPort); |
|
779 |
|
780 iTestHarness->EndTest(error); |
|
781 |
|
782 // Make 8-bit copies |
|
783 HBufC8* authority_HostBuf = HBufC8::NewLC(aAuthority_Host.Length()); |
|
784 TPtr8 authority_Host8Bit = authority_HostBuf->Des(); |
|
785 authority_Host8Bit.Copy(aAuthority_Host); |
|
786 |
|
787 HBufC8* authority_UserinfoBuf = HBufC8::NewLC(aAuthority_Userinfo.Length()); |
|
788 TPtr8 authority_Userinfo8Bit = authority_UserinfoBuf->Des(); |
|
789 authority_Userinfo8Bit.Copy(aAuthority_Userinfo); |
|
790 |
|
791 HBufC8* authority_PortBuf = HBufC8::NewLC(aAuthority_Port.Length()); |
|
792 TPtr8 authority_Port8Bit = authority_PortBuf->Des(); |
|
793 authority_Port8Bit.Copy(aAuthority_Port); |
|
794 |
|
795 // And the individual components |
|
796 HBufC8* userinfoBuf = HBufC8::NewLC(aUserinfo.Length()); |
|
797 TPtr8 userinfo8Bit = userinfoBuf->Des(); |
|
798 userinfo8Bit.Copy(aUserinfo); |
|
799 |
|
800 HBufC8* hostBuf = HBufC8::NewLC(aHost.Length()); |
|
801 TPtr8 host8Bit = hostBuf->Des(); |
|
802 host8Bit.Copy(aHost); |
|
803 |
|
804 HBufC8* portBuf = HBufC8::NewLC(aPort.Length()); |
|
805 TPtr8 port8Bit = portBuf->Des(); |
|
806 port8Bit.Copy(aPort); |
|
807 |
|
808 iTestHarness->StartTestL(_L("Test CAuthority SetComponentL (8-bit)")); |
|
809 |
|
810 error = DoAuthorityConstruction<CAuthority8>(authority_Host8Bit, authority_Userinfo8Bit, authority_Port8Bit, |
|
811 host8Bit, userinfo8Bit, port8Bit); |
|
812 |
|
813 iTestHarness->EndTest(error); |
|
814 CleanupStack::PopAndDestroy(6, authority_HostBuf); // too many to list! |
|
815 } |
|
816 |
|
817 void CUriAndAuthorityTest::TestAuthoritySetAndEscapeComponentL(const TDesC& aAuthority_Host, const TDesC& aAuthority_Userinfo, |
|
818 const TDesC& aAuthority_Port, const TDesC& aHost, |
|
819 const TDesC& aUserinfo, const TDesC& aPort) const |
|
820 |
|
821 { |
|
822 iTestHarness->StartTestL(_L("Test CAuthority SetAndEscapeComponentL (16-bit)")); |
|
823 |
|
824 TInt error = DoAuthorityEscapedConstruction<CAuthority16>(aAuthority_Host, aAuthority_Userinfo, aAuthority_Port, |
|
825 aHost, aUserinfo, aPort); |
|
826 |
|
827 iTestHarness->EndTest(error); |
|
828 |
|
829 // Make 8-bit copies |
|
830 HBufC8* authority_HostBuf = HBufC8::NewLC(aAuthority_Host.Length()); |
|
831 TPtr8 authority_Host8Bit = authority_HostBuf->Des(); |
|
832 authority_Host8Bit.Copy(aAuthority_Host); |
|
833 |
|
834 HBufC8* authority_UserinfoBuf = HBufC8::NewLC(aAuthority_Userinfo.Length()); |
|
835 TPtr8 authority_Userinfo8Bit = authority_UserinfoBuf->Des(); |
|
836 authority_Userinfo8Bit.Copy(aAuthority_Userinfo); |
|
837 |
|
838 HBufC8* authority_PortBuf = HBufC8::NewLC(aAuthority_Port.Length()); |
|
839 TPtr8 authority_Port8Bit = authority_PortBuf->Des(); |
|
840 authority_Port8Bit.Copy(aAuthority_Port); |
|
841 |
|
842 // And the individual components |
|
843 HBufC8* userinfoBuf = HBufC8::NewLC(aUserinfo.Length()); |
|
844 TPtr8 userinfo8Bit = userinfoBuf->Des(); |
|
845 userinfo8Bit.Copy(aUserinfo); |
|
846 |
|
847 HBufC8* hostBuf = HBufC8::NewLC(aHost.Length()); |
|
848 TPtr8 host8Bit = hostBuf->Des(); |
|
849 host8Bit.Copy(aHost); |
|
850 |
|
851 HBufC8* portBuf = HBufC8::NewLC(aPort.Length()); |
|
852 TPtr8 port8Bit = portBuf->Des(); |
|
853 port8Bit.Copy(aPort); |
|
854 |
|
855 iTestHarness->StartTestL(_L("Test CAuthority SetAnsEscapeComponentL (8-bit)")); |
|
856 |
|
857 error = DoAuthorityEscapedConstruction<CAuthority8>(authority_Host8Bit, authority_Userinfo8Bit, authority_Port8Bit, |
|
858 host8Bit, userinfo8Bit, port8Bit); |
|
859 |
|
860 iTestHarness->EndTest(error); |
|
861 CleanupStack::PopAndDestroy(6, authority_HostBuf); // too many to list! |
|
862 } |
|
863 |
|
864 void CUriAndAuthorityTest::TestAuthorityRemoveComponentL(const TDesC& aAuthority_NoHost, const TDesC& aAuthority_NoUserinfo, |
|
865 const TDesC& aAuthority_NoPort, const TDesC& aAuthority_Whole) const |
|
866 { |
|
867 iTestHarness->StartTestL(_L("Test CAuthority RemoveComponentL (16-bit)")); |
|
868 |
|
869 TInt error = DoAuthorityDestruction<CAuthority16, TAuthorityParser16>(aAuthority_NoHost, aAuthority_NoUserinfo, |
|
870 aAuthority_NoPort, aAuthority_Whole); |
|
871 |
|
872 iTestHarness->EndTest(error); |
|
873 |
|
874 // Make 8-bit copies |
|
875 HBufC8* authority_NoHostBuf = HBufC8::NewLC(aAuthority_NoHost.Length()); |
|
876 TPtr8 authority_NoHost8Bit = authority_NoHostBuf->Des(); |
|
877 authority_NoHost8Bit.Copy(aAuthority_NoHost); |
|
878 |
|
879 HBufC8* authority_NoUserinfoBuf = HBufC8::NewLC(aAuthority_NoUserinfo.Length()); |
|
880 TPtr8 authority_NoUserinfo8Bit = authority_NoUserinfoBuf->Des(); |
|
881 authority_NoUserinfo8Bit.Copy(aAuthority_NoUserinfo); |
|
882 |
|
883 HBufC8* authority_NoPortBuf = HBufC8::NewLC(aAuthority_NoPort.Length()); |
|
884 TPtr8 authority_NoPort8Bit = authority_NoPortBuf->Des(); |
|
885 authority_NoPort8Bit.Copy(aAuthority_NoPort); |
|
886 |
|
887 HBufC8* authority_WholeBuf = HBufC8::NewLC(aAuthority_Whole.Length()); |
|
888 TPtr8 authority_Whole8Bit = authority_WholeBuf->Des(); |
|
889 authority_Whole8Bit.Copy(aAuthority_Whole); |
|
890 |
|
891 iTestHarness->StartTestL(_L("Test CAuthority RemoveComponentL (8-bit)")); |
|
892 |
|
893 error = DoAuthorityDestruction<CAuthority8, TAuthorityParser8>(authority_NoHost8Bit, authority_NoUserinfo8Bit, |
|
894 authority_NoPort8Bit, authority_Whole8Bit); |
|
895 |
|
896 iTestHarness->EndTest(error); |
|
897 CleanupStack::PopAndDestroy(4, authority_NoHostBuf); // too many to list! |
|
898 } |
|
899 |
|
900 // |
|
901 // |
|
902 // Implementation of LOCAL functions |
|
903 // |
|
904 // |
|
905 |
|
906 template<class TUriParserType, class TDesCType> |
|
907 TInt DoUriComponentExtraction(const TDesCType& aUri, const TDesCType& aScheme, |
|
908 const TDesCType& aUserinfo, const TDesCType& aHost, |
|
909 const TDesCType& aPort, const TDesCType& aPath, |
|
910 const TDesCType& aQuery, const TDesCType& aFragment) |
|
911 { |
|
912 TUriParserType uriParser; |
|
913 TInt error = uriParser.Parse(aUri); |
|
914 // Is this a valid Uri? |
|
915 if( error == KUriUtilsErrInvalidUri ) |
|
916 { |
|
917 return error; |
|
918 } |
|
919 |
|
920 // Check scheme... |
|
921 if( TestComponent(uriParser, aScheme, EUriScheme) != 0 ) |
|
922 { |
|
923 return KUriUtilsErrDifferentScheme; |
|
924 } |
|
925 // Check userinfo... |
|
926 if( TestComponent(uriParser, aUserinfo, EUriUserinfo) != 0 ) |
|
927 { |
|
928 return KUriUtilsErrDifferentUserInfo; |
|
929 } |
|
930 // Check host... |
|
931 if( TestComponent(uriParser, aHost, EUriHost) != 0 ) |
|
932 { |
|
933 return KUriUtilsErrDifferentHost; |
|
934 } |
|
935 // Check port... |
|
936 if( TestComponent(uriParser, aPort, EUriPort) != 0 ) |
|
937 { |
|
938 return KUriUtilsErrDifferentPort; |
|
939 } |
|
940 // Check path... |
|
941 if( TestComponent(uriParser, aPath, EUriPath) != 0) |
|
942 { |
|
943 return KUriUtilsErrDifferentPath; |
|
944 } |
|
945 // Check query... |
|
946 if( TestComponent(uriParser, aQuery, EUriQuery) != 0 ) |
|
947 { |
|
948 return KUriUtilsErrDifferentQuery; |
|
949 } |
|
950 // Check fragment... |
|
951 if( TestComponent(uriParser, aFragment, EUriFragment) != 0 ) |
|
952 { |
|
953 return KUriUtilsErrDifferentFragment; |
|
954 } |
|
955 return KErrNone; |
|
956 } |
|
957 |
|
958 |
|
959 /** create 8-bit URI from descriptor, compare components*/ |
|
960 void DoUriComponentExtractionL(const TDesC& aUri, const TDesC& aScheme, |
|
961 const TDesC& aUserinfo, const TDesC& aHost, |
|
962 const TDesC& aPort, const TDesC& aPath, |
|
963 const TDesC& aQuery, const TDesC& aFragment) |
|
964 { |
|
965 CUri8* uri = UriUtils::CreateUriL(aUri); |
|
966 CleanupStack::PushL(uri); |
|
967 |
|
968 // Check scheme... |
|
969 HBufC* text = uri->Uri().DisplayFormL(EUriScheme); |
|
970 TInt error = ( text->Compare(aScheme) == 0 ) ? KErrNone : KUriUtilsErrDifferentScheme; |
|
971 delete text; |
|
972 User::LeaveIfError(error); |
|
973 |
|
974 // Check userinfo... |
|
975 text = uri->Uri().DisplayFormL(EUriUserinfo); |
|
976 error = ( text->Compare(aUserinfo) == 0 ) ? KErrNone : KUriUtilsErrDifferentUserInfo; |
|
977 delete text; |
|
978 User::LeaveIfError(error); |
|
979 |
|
980 // Check host... |
|
981 text = uri->Uri().DisplayFormL(EUriHost); |
|
982 error = ( text->Compare(aHost) == 0 ) ? KErrNone : KUriUtilsErrDifferentHost; |
|
983 delete text; |
|
984 User::LeaveIfError(error); |
|
985 |
|
986 // Check port... |
|
987 text = uri->Uri().DisplayFormL(EUriPort); |
|
988 error = ( text->Compare(aPort) == 0 ) ? KErrNone : KUriUtilsErrDifferentPort; |
|
989 delete text; |
|
990 User::LeaveIfError(error); |
|
991 |
|
992 // Check path... |
|
993 text = uri->Uri().DisplayFormL(EUriPath); |
|
994 error = ( text->Compare(aPath) == 0 ) ? KErrNone : KUriUtilsErrDifferentPath; |
|
995 delete text; |
|
996 User::LeaveIfError(error); |
|
997 |
|
998 // Check query... |
|
999 text = uri->Uri().DisplayFormL(EUriQuery); |
|
1000 error = ( text->Compare(aQuery) == 0 ) ? KErrNone : KUriUtilsErrDifferentQuery; |
|
1001 delete text; |
|
1002 User::LeaveIfError(error); |
|
1003 |
|
1004 // Check fragment... |
|
1005 text = uri->Uri().DisplayFormL(EUriFragment); |
|
1006 error = ( text->Compare(aFragment) == 0 ) ? KErrNone : KUriUtilsErrDifferentFragment; |
|
1007 delete text; |
|
1008 User::LeaveIfError(error); |
|
1009 CleanupStack::PopAndDestroy(uri); |
|
1010 } |
|
1011 |
|
1012 |
|
1013 template<class TAuthorityParserType, class TDesCType> |
|
1014 TInt DoAuthorityComponentExtraction(const TDesCType& aAuthority, const TDesCType& aUserInfo, |
|
1015 const TDesCType& aHost, const TDesCType& aPort) |
|
1016 { |
|
1017 TAuthorityParserType authorityParser; |
|
1018 TInt error = authorityParser.Parse(aAuthority); |
|
1019 |
|
1020 // Check userinfo... |
|
1021 if( TestComponent(authorityParser, aUserInfo, EAuthorityUserinfo) != 0 ) |
|
1022 { |
|
1023 return KUriUtilsErrDifferentUserInfo; |
|
1024 } |
|
1025 // Check host... |
|
1026 if( TestComponent(authorityParser, aHost, EAuthorityHost) != 0 ) |
|
1027 { |
|
1028 return KUriUtilsErrDifferentHost; |
|
1029 } |
|
1030 // Check port... |
|
1031 if( TestComponent(authorityParser, aPort, EAuthorityPort) != 0 ) |
|
1032 { |
|
1033 return KUriUtilsErrDifferentPort; |
|
1034 } |
|
1035 return error; |
|
1036 } |
|
1037 |
|
1038 /** create 8-bit Authority from descriptor, compare components*/ |
|
1039 void DoAuthorityComponentExtractionL(const TDesC& aAuthority, const TDesC& aUserInfo, |
|
1040 const TDesC& aHost, const TDesC& aPort) |
|
1041 { |
|
1042 CAuthority8* authority = UriUtils::CreateAuthorityL(aAuthority); |
|
1043 CleanupStack::PushL(authority); |
|
1044 |
|
1045 // Check userinfo... |
|
1046 HBufC* text = authority->Authority().DisplayFormL(EAuthorityUserinfo); |
|
1047 TInt error = ( text->Compare(aUserInfo) == 0 ) ? KErrNone : KUriUtilsErrDifferentUserInfo; |
|
1048 delete text; |
|
1049 User::LeaveIfError(error); |
|
1050 |
|
1051 // Check host... |
|
1052 text = authority->Authority().DisplayFormL(EAuthorityHost); |
|
1053 error = ( text->Compare(aHost) == 0 ) ? KErrNone : KUriUtilsErrDifferentHost; |
|
1054 delete text; |
|
1055 |
|
1056 // Check port... |
|
1057 text = authority->Authority().DisplayFormL(EAuthorityPort); |
|
1058 error = ( text->Compare(aPort) == 0 ) ? KErrNone : KUriUtilsErrDifferentPort; |
|
1059 delete text; |
|
1060 |
|
1061 CleanupStack::PopAndDestroy(authority); |
|
1062 } |
|
1063 |
|
1064 template<class TParserType, class TDesCType, class TComponentType> |
|
1065 TInt TestComponent(const TParserType& aParser, const TDesCType& aExpected, TComponentType aComponent) |
|
1066 { |
|
1067 return aParser.Extract(aComponent).Compare(aExpected); |
|
1068 } |
|
1069 |
|
1070 template<class TUriParserType, class CUriType, class TDesCType> |
|
1071 TInt DoTestResolve(const TDesCType& aBase, const TDesCType& aReference, const TDesCType& aExpected) |
|
1072 { |
|
1073 TUriParserType baseUri; |
|
1074 TInt error = baseUri.Parse(aBase); |
|
1075 if ( error != KErrNone ) |
|
1076 { |
|
1077 return error; |
|
1078 } |
|
1079 TUriParserType refUri; |
|
1080 error = refUri.Parse(aReference); |
|
1081 if ( error != KErrNone ) |
|
1082 { |
|
1083 return error; |
|
1084 } |
|
1085 CUriType* resolvedUri = NULL; |
|
1086 TRAP(error, resolvedUri = CUriType::ResolveL(baseUri, refUri)); |
|
1087 if( error != KErrNone ) |
|
1088 { |
|
1089 return error; |
|
1090 } |
|
1091 error = resolvedUri->Uri().UriDes().Compare(aExpected); |
|
1092 |
|
1093 delete resolvedUri; |
|
1094 return error; |
|
1095 } |
|
1096 |
|
1097 template<class TUriParserType, class TDesCType> |
|
1098 TInt DoUriCompare(const TDesCType& aUri1, const TDesCType& aUri2, TInt aMatchFlags) |
|
1099 { |
|
1100 TUriParserType uri1; |
|
1101 TInt error = uri1.Parse(aUri1); |
|
1102 if( error == KUriUtilsErrInvalidUri ) |
|
1103 { |
|
1104 return error; |
|
1105 } |
|
1106 TUriParserType uri2; |
|
1107 error = uri2.Parse(aUri2); |
|
1108 if( error == KUriUtilsErrInvalidUri ) |
|
1109 { |
|
1110 return error; |
|
1111 } |
|
1112 // Test compare for fragment |
|
1113 if( (error = TestCompare(uri1, uri2, EUriFragment, (aMatchFlags & EFragmentFlag))) != 0 ) |
|
1114 { |
|
1115 return KErrNotFound; |
|
1116 } |
|
1117 // Test compare for query |
|
1118 if( (error = TestCompare(uri1, uri2, EUriQuery, (aMatchFlags & EQueryFlag))) != 0 ) |
|
1119 { |
|
1120 return KErrNotFound; |
|
1121 } |
|
1122 // Test compare for path |
|
1123 if( (error = TestCompare(uri1, uri2, EUriPath, (aMatchFlags & EPathFlag))) != 0 ) |
|
1124 { |
|
1125 return KErrNotFound; |
|
1126 } |
|
1127 // Test compare for port |
|
1128 if( (error = TestCompare(uri1, uri2, EUriPort, (aMatchFlags & EPortFlag))) != 0 ) |
|
1129 { |
|
1130 return KErrNotFound; |
|
1131 } |
|
1132 // Test compare for userinfo |
|
1133 if( (error = TestCompare(uri1, uri2, EUriUserinfo, (aMatchFlags & EUserinfoFlag))) != 0 ) |
|
1134 { |
|
1135 return KErrNotFound; |
|
1136 } |
|
1137 // Test compare for host |
|
1138 if( (error = TestCompare(uri1, uri2, EUriHost, (aMatchFlags & EHostFlag))) != 0 ) |
|
1139 { |
|
1140 return KErrNotFound; |
|
1141 } |
|
1142 // Test compare for scheme |
|
1143 if( (error = TestCompare(uri1, uri2, EUriScheme, (aMatchFlags & ESchemeFlag))) != 0 ) |
|
1144 { |
|
1145 return KErrNotFound; |
|
1146 } |
|
1147 return error; |
|
1148 } |
|
1149 |
|
1150 template<class TAuthorityParserType, class TDesCType> |
|
1151 TInt DoAuthorityCompare(const TDesCType& aAuthority1, const TDesCType& aAuthority2, TInt aMatchFlags) |
|
1152 { |
|
1153 TAuthorityParserType auth1; |
|
1154 TInt error = auth1.Parse(aAuthority1); |
|
1155 TAuthorityParserType auth2; |
|
1156 error = auth2.Parse(aAuthority2); |
|
1157 // Test compare for userinfo |
|
1158 if( (error = TestCompare(auth1, auth2, EAuthorityUserinfo, (aMatchFlags & EUserinfoFlag))) != 0 ) |
|
1159 { |
|
1160 return KErrNotFound; |
|
1161 } |
|
1162 // Test compare for port |
|
1163 if( (error = TestCompare(auth1, auth2, EAuthorityPort, (aMatchFlags & EPortFlag))) != 0 ) |
|
1164 { |
|
1165 return KErrNotFound; |
|
1166 } |
|
1167 // Test compare for host |
|
1168 if( (error = TestCompare(auth1, auth2, EAuthorityHost, (aMatchFlags & EHostFlag))) != 0 ) |
|
1169 { |
|
1170 return KErrNotFound; |
|
1171 } |
|
1172 return error; |
|
1173 } |
|
1174 |
|
1175 template<class TParserType, class TComponentType> |
|
1176 TInt TestCompare(const TParserType& aData1, const TParserType& aData2, TComponentType aComponent, TBool aExpectedMatch) |
|
1177 { |
|
1178 TInt error = aData1.Compare(aData2, aComponent); |
|
1179 TBool match = error == 0; |
|
1180 if( (!match && aExpectedMatch) | (match && !aExpectedMatch) ) |
|
1181 { |
|
1182 return KErrNotFound; |
|
1183 } |
|
1184 return KErrNone; |
|
1185 } |
|
1186 |
|
1187 template<class TUriParserType, class TDesCType> |
|
1188 TInt DoUriComponentPresence(const TDesCType& aUri, TInt aPresenceFlags) |
|
1189 { |
|
1190 TUriParserType uri; |
|
1191 TInt error = uri.Parse(aUri); |
|
1192 if( error == KUriUtilsErrInvalidUri ) |
|
1193 { |
|
1194 return error; |
|
1195 } |
|
1196 // Test compare for scheme |
|
1197 if( (error = TestPresence(uri, EUriScheme, (aPresenceFlags & ESchemeFlag))) != 0) |
|
1198 { |
|
1199 return KErrNotFound; |
|
1200 } |
|
1201 // Test compare for host |
|
1202 if( (error = TestPresence(uri, EUriHost, (aPresenceFlags & EHostFlag))) != 0) |
|
1203 { |
|
1204 return KErrNotFound; |
|
1205 } |
|
1206 // Test compare for userinfo |
|
1207 if( (error = TestPresence(uri, EUriUserinfo, (aPresenceFlags & EUserinfoFlag))) != 0) |
|
1208 { |
|
1209 return KErrNotFound; |
|
1210 } |
|
1211 // Test compare for port |
|
1212 if( (error = TestPresence(uri, EUriPort, (aPresenceFlags & EPortFlag))) != 0) |
|
1213 { |
|
1214 return KErrNotFound; |
|
1215 } |
|
1216 // Test compare for path |
|
1217 if( (error = TestPresence(uri, EUriPath, (aPresenceFlags & EPathFlag))) != 0) |
|
1218 { |
|
1219 return KErrNotFound; |
|
1220 } |
|
1221 // Test compare for query |
|
1222 if( (error = TestPresence(uri, EUriQuery, (aPresenceFlags & EQueryFlag))) != 0) |
|
1223 { |
|
1224 return KErrNotFound; |
|
1225 } |
|
1226 // Test compare for fragment |
|
1227 if( (error = TestPresence(uri, EUriFragment, (aPresenceFlags & EFragmentFlag))) != 0) |
|
1228 { |
|
1229 return KErrNotFound; |
|
1230 } |
|
1231 return error; |
|
1232 } |
|
1233 |
|
1234 template<class TAuthorityParserType, class TDesCType> |
|
1235 TInt DoAuthorityComponentPresence(const TDesCType& aAuthority, TInt aPresenceFlags) |
|
1236 { |
|
1237 TAuthorityParserType authority; |
|
1238 TInt error = authority.Parse(aAuthority); |
|
1239 // Test compare for host |
|
1240 if( (error = TestPresence(authority, EAuthorityHost, (aPresenceFlags & EHostFlag))) != 0) |
|
1241 { |
|
1242 return KErrNotFound; |
|
1243 } |
|
1244 // Test compare for userinfo |
|
1245 if( (error = TestPresence(authority, EAuthorityUserinfo, (aPresenceFlags & EUserinfoFlag))) != 0) |
|
1246 { |
|
1247 return KErrNotFound; |
|
1248 } |
|
1249 // Test compare for port |
|
1250 if( (error = TestPresence(authority, EAuthorityPort, (aPresenceFlags & EPortFlag))) != 0) |
|
1251 { |
|
1252 return KErrNotFound; |
|
1253 } |
|
1254 return error; |
|
1255 } |
|
1256 |
|
1257 template<class TParserType, class TComponentType> |
|
1258 TInt TestPresence(const TParserType& aData, TComponentType aComponent, TBool aExpectedPresence) |
|
1259 { |
|
1260 TBool present = aData.IsPresent(aComponent); |
|
1261 if( (!present && aExpectedPresence) | (present && !aExpectedPresence) ) |
|
1262 { |
|
1263 return KErrNotFound; |
|
1264 } |
|
1265 return KErrNone; |
|
1266 } |
|
1267 |
|
1268 template<class TUriParserType, class TDesCType> |
|
1269 TInt DoUriDes(const TDesCType& aUri) |
|
1270 { |
|
1271 TUriParserType uri; |
|
1272 TInt error = uri.Parse(aUri); |
|
1273 if( error == KUriUtilsErrInvalidUri ) |
|
1274 { |
|
1275 return error; |
|
1276 } |
|
1277 if( uri.UriDes().Compare(aUri) != 0) |
|
1278 { |
|
1279 return KErrNotFound; |
|
1280 } |
|
1281 return KErrNone; |
|
1282 } |
|
1283 |
|
1284 void DoUriDesL(const TDesC& aUri) |
|
1285 { |
|
1286 CUri8* uri = UriUtils::CreateUriL(aUri); |
|
1287 CleanupStack::PushL(uri); |
|
1288 |
|
1289 HBufC* text = uri->Uri().DisplayFormL(); |
|
1290 TInt error = ( text->Compare(aUri) == 0 ) ? KErrNone : KErrNotFound; |
|
1291 delete text; |
|
1292 User::LeaveIfError(error); |
|
1293 CleanupStack::PopAndDestroy(uri); |
|
1294 } |
|
1295 |
|
1296 template<class TAuthorityParserType, class TDesCType> |
|
1297 TInt DoAuthorityDes(const TDesCType& aAuthority) |
|
1298 { |
|
1299 TAuthorityParserType authority; |
|
1300 TInt error = authority.Parse(aAuthority); |
|
1301 if( (error = authority.AuthorityDes().Compare(aAuthority)) != 0) |
|
1302 { |
|
1303 return KErrNotFound; |
|
1304 } |
|
1305 return error; |
|
1306 } |
|
1307 |
|
1308 void DoAuthorityDesL(const TDesC& aAuthority) |
|
1309 { |
|
1310 CAuthority8* authority = UriUtils::CreateAuthorityL(aAuthority); |
|
1311 CleanupStack::PushL(authority); |
|
1312 |
|
1313 HBufC* text = authority->Authority().DisplayFormL(); |
|
1314 TInt error = ( text->Compare(aAuthority) == 0 ) ? KErrNone : KErrNotFound; |
|
1315 delete text; |
|
1316 User::LeaveIfError(error); |
|
1317 |
|
1318 CleanupStack::PopAndDestroy(authority); |
|
1319 } |
|
1320 |
|
1321 template<class TUriParserType, class TDesCType> |
|
1322 TInt DoUriSchemeValidation(const TDesCType& aUri, TBool aValidScheme) |
|
1323 { |
|
1324 TUriParserType uri; |
|
1325 TInt error = uri.Parse(aUri); |
|
1326 if( error == KUriUtilsErrInvalidUri ) |
|
1327 { |
|
1328 return error; |
|
1329 } |
|
1330 TBool valid = uri.IsSchemeValid(); |
|
1331 if( (!valid && aValidScheme) | (valid && !aValidScheme) ) |
|
1332 { |
|
1333 return KErrNotFound; |
|
1334 } |
|
1335 return KErrNone; |
|
1336 } |
|
1337 |
|
1338 template<class TUriParserType, class TPtrCType, class TDesCType> |
|
1339 TInt DoUriWithoutFragment(const TDesCType& aUri, const TDesCType& aExpected) |
|
1340 { |
|
1341 TUriParserType uri; |
|
1342 TInt error = uri.Parse(aUri); |
|
1343 if( error == KUriUtilsErrInvalidUri ) |
|
1344 { |
|
1345 return error; |
|
1346 } |
|
1347 TPtrCType uriWithoutFragment; |
|
1348 uri.UriWithoutFragment(uriWithoutFragment); |
|
1349 if( (error = uriWithoutFragment.Compare(aExpected)) != 0) |
|
1350 { |
|
1351 return KErrNotFound; |
|
1352 } |
|
1353 return error; |
|
1354 } |
|
1355 |
|
1356 template<class CUriType, class TDesCType> |
|
1357 TInt DoUriConstruction(const TDesCType& aUri_Scheme, const TDesCType& aUri_Host, const TDesCType& aUri_Userinfo, |
|
1358 const TDesCType& aUri_Port, const TDesCType& aUri_Path, const TDesCType& aUri_Query, |
|
1359 const TDesCType& aUri_Fragment, const TDesCType& aScheme, const TDesCType& aHost, |
|
1360 const TDesCType& aUserinfo, const TDesCType& aPort, const TDesCType& aPath, |
|
1361 const TDesCType& aQuery, const TDesCType& aFragment) |
|
1362 { |
|
1363 // Create the CUriType object |
|
1364 CUriType* uri = NULL; |
|
1365 TRAPD(error, uri = CUriType::NewL()); |
|
1366 if( error != KErrNone ) |
|
1367 { |
|
1368 return error; |
|
1369 } |
|
1370 CleanupStack::PushL(uri); |
|
1371 // Add scheme... |
|
1372 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriScheme, aScheme, aUri_Scheme) != KErrNone ) |
|
1373 { |
|
1374 CleanupStack::PopAndDestroy(uri); // uri |
|
1375 return KErrNotFound; |
|
1376 } |
|
1377 |
|
1378 // Add host... |
|
1379 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriHost, aHost, aUri_Host) != KErrNone ) |
|
1380 { |
|
1381 CleanupStack::PopAndDestroy(uri); // uri |
|
1382 return KErrNotFound; |
|
1383 } |
|
1384 // Add userinfo... |
|
1385 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriUserinfo, aUserinfo, aUri_Userinfo) != KErrNone ) |
|
1386 { |
|
1387 CleanupStack::PopAndDestroy(uri); // uri |
|
1388 return KErrNotFound; |
|
1389 } |
|
1390 // Add port... |
|
1391 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriPort, aPort, aUri_Port) != KErrNone ) |
|
1392 { |
|
1393 CleanupStack::PopAndDestroy(uri); // uri |
|
1394 return KErrNotFound; |
|
1395 } |
|
1396 // Add path... |
|
1397 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriPath, aPath, aUri_Path) != KErrNone ) |
|
1398 { |
|
1399 CleanupStack::PopAndDestroy(uri); // uri |
|
1400 return KErrNotFound; |
|
1401 } |
|
1402 // Add query... |
|
1403 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriQuery, aQuery, aUri_Query) != KErrNone ) |
|
1404 { |
|
1405 CleanupStack::PopAndDestroy(uri); // uri |
|
1406 return KErrNotFound; |
|
1407 } |
|
1408 // Add fragment... |
|
1409 if( DoUriSetAndCompareComponent<CUriType>(uri, EUriFragment, aFragment, aUri_Fragment) != KErrNone ) |
|
1410 { |
|
1411 CleanupStack::PopAndDestroy(uri); // uri |
|
1412 return KErrNotFound; |
|
1413 } |
|
1414 // Cleanup and return |
|
1415 CleanupStack::PopAndDestroy(uri); // uri |
|
1416 return KErrNone; |
|
1417 } |
|
1418 |
|
1419 template<class CUriType, class TDesCType> |
|
1420 TInt DoUriSetAndCompareComponent(CUriType* aUri, TUriComponent aComponent, const TDesCType& aData, const TDesCType& aExpected) |
|
1421 { |
|
1422 TRAPD(error, aUri->SetComponentL(aData, aComponent)); |
|
1423 if( error != KErrNone ) |
|
1424 { |
|
1425 return error; |
|
1426 } |
|
1427 // Compare with expected |
|
1428 if( aUri->Uri().UriDes().Compare(aExpected) != 0) |
|
1429 { |
|
1430 return KErrNotFound; |
|
1431 } |
|
1432 return KErrNone; |
|
1433 } |
|
1434 |
|
1435 template<class CUriType, class TUriParserType, class TDesCType> |
|
1436 TInt DoUriDestruction(const TDesCType& aUri_NoScheme, const TDesCType& aUri_NoHost, const TDesCType& aUri_NoUserinfo, |
|
1437 const TDesCType& aUri_NoPort, const TDesCType& aUri_NoPath, const TDesCType& aUri_NoQuery, |
|
1438 const TDesCType& aUri_NoFragment, const TDesCType& aUri_Whole) |
|
1439 { |
|
1440 // Create a TUriC-derived objet from whole uri |
|
1441 TUriParserType parser; |
|
1442 TInt error = parser.Parse(aUri_Whole); |
|
1443 if( error == KUriUtilsErrInvalidUri ) |
|
1444 { |
|
1445 return error; |
|
1446 } |
|
1447 // Create the CUriType object |
|
1448 CUriType* uri = NULL; |
|
1449 TRAP(error, uri = CUriType::NewL(parser)); |
|
1450 if( error != KErrNone ) |
|
1451 { |
|
1452 return error; |
|
1453 } |
|
1454 CleanupStack::PushL(uri); |
|
1455 // Remove fragment... |
|
1456 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriFragment, aUri_NoFragment) != KErrNone ) |
|
1457 { |
|
1458 CleanupStack::PopAndDestroy(uri); // uri |
|
1459 return KErrNotFound; |
|
1460 } |
|
1461 // Remove query... |
|
1462 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriQuery, aUri_NoQuery) != KErrNone ) |
|
1463 { |
|
1464 CleanupStack::PopAndDestroy(uri); // uri |
|
1465 return KErrNotFound; |
|
1466 } |
|
1467 // Remove path... |
|
1468 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriPath, aUri_NoPath) != KErrNone ) |
|
1469 { |
|
1470 CleanupStack::PopAndDestroy(uri); // uri |
|
1471 return KErrNotFound; |
|
1472 } |
|
1473 // Remove port... |
|
1474 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriPort, aUri_NoPort) != KErrNone ) |
|
1475 { |
|
1476 CleanupStack::PopAndDestroy(uri); // uri |
|
1477 return KErrNotFound; |
|
1478 } |
|
1479 // Remove userinfo... |
|
1480 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriUserinfo, aUri_NoUserinfo) != KErrNone ) |
|
1481 { |
|
1482 CleanupStack::PopAndDestroy(uri); // uri |
|
1483 return KErrNotFound; |
|
1484 } |
|
1485 // Remove host... |
|
1486 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriHost, aUri_NoHost) != KErrNone ) |
|
1487 { |
|
1488 CleanupStack::PopAndDestroy(uri); // uri |
|
1489 return KErrNotFound; |
|
1490 } |
|
1491 // Remove scheme... |
|
1492 if( DoUriRemoveAndCompareComponent<CUriType>(uri, EUriScheme, aUri_NoScheme) != KErrNone ) |
|
1493 { |
|
1494 CleanupStack::PopAndDestroy(uri); // uri |
|
1495 return KErrNotFound; |
|
1496 } |
|
1497 // Cleanup and return |
|
1498 CleanupStack::PopAndDestroy(uri); // uri |
|
1499 return KErrNone; |
|
1500 } |
|
1501 |
|
1502 template<class CUriType, class TDesCType> |
|
1503 TInt DoUriRemoveAndCompareComponent(CUriType* aUri, TUriComponent aComponent, const TDesCType& aExpected) |
|
1504 { |
|
1505 TRAPD(error, aUri->RemoveComponentL(aComponent)); |
|
1506 if( error != KErrNone ) |
|
1507 { |
|
1508 return error; |
|
1509 } |
|
1510 // Compare with expected |
|
1511 if( aUri->Uri().UriDes().Compare(aExpected) != 0) |
|
1512 { |
|
1513 return KErrNotFound; |
|
1514 } |
|
1515 return KErrNone; |
|
1516 } |
|
1517 |
|
1518 template<class CAuthorityType, class TDesCType> |
|
1519 TInt DoAuthorityConstruction(const TDesCType& aAuthority_Host, const TDesCType& aAuthority_Userinfo, const TDesCType& aAuthority_Port, |
|
1520 const TDesCType& aHost, const TDesCType& aUserinfo, const TDesCType& aPort) |
|
1521 { |
|
1522 // Create the CAuthorityType object |
|
1523 CAuthorityType* authority = NULL; |
|
1524 TRAPD(error, authority = CAuthorityType::NewL()); |
|
1525 if( error != KErrNone ) |
|
1526 { |
|
1527 return error; |
|
1528 } |
|
1529 CleanupStack::PushL(authority); |
|
1530 // Add host... |
|
1531 if( DoAuthoritySetAndCompareComponent<CAuthorityType>(authority, EAuthorityHost, aHost, aAuthority_Host) != KErrNone ) |
|
1532 { |
|
1533 CleanupStack::PopAndDestroy(authority); // authority |
|
1534 return KErrNotFound; |
|
1535 } |
|
1536 // Add userinfo... |
|
1537 if( DoAuthoritySetAndCompareComponent<CAuthorityType>(authority, EAuthorityUserinfo, aUserinfo, aAuthority_Userinfo) != KErrNone ) |
|
1538 { |
|
1539 CleanupStack::PopAndDestroy(authority); // authority |
|
1540 return KErrNotFound; |
|
1541 } |
|
1542 // Add port... |
|
1543 if( DoAuthoritySetAndCompareComponent<CAuthorityType>(authority, EAuthorityPort, aPort, aAuthority_Port) != KErrNone ) |
|
1544 { |
|
1545 CleanupStack::PopAndDestroy(authority); // authority |
|
1546 return KErrNotFound; |
|
1547 } |
|
1548 // Cleanup and return |
|
1549 CleanupStack::PopAndDestroy(authority); // authority |
|
1550 return KErrNone; |
|
1551 } |
|
1552 |
|
1553 template<class CAuthorityType, class TDesCType> |
|
1554 TInt DoAuthoritySetAndCompareComponent(CAuthorityType* aAuthority, TAuthorityComponent aComponent, const TDesCType& aData, const TDesCType& aExpected) |
|
1555 { |
|
1556 TRAPD(error, aAuthority->SetComponentL(aData, aComponent)); |
|
1557 if( error != KErrNone ) |
|
1558 { |
|
1559 return error; |
|
1560 } |
|
1561 // Compare with expected |
|
1562 if( aAuthority->Authority().AuthorityDes().Compare(aExpected) != 0) |
|
1563 { |
|
1564 return KErrNotFound; |
|
1565 } |
|
1566 return KErrNone; |
|
1567 } |
|
1568 |
|
1569 template<class CAuthorityType, class TDesCType> |
|
1570 TInt DoAuthorityEscapedConstruction(const TDesCType& aAuthority_Host, const TDesCType& aAuthority_Userinfo, const TDesCType& aAuthority_Port, |
|
1571 const TDesCType& aHost, const TDesCType& aUserinfo, const TDesCType& aPort) |
|
1572 { |
|
1573 // Create the CAuthorityType object |
|
1574 CAuthorityType* authority = NULL; |
|
1575 TRAPD(error, authority = CAuthorityType::NewL()); |
|
1576 if( error != KErrNone ) |
|
1577 { |
|
1578 return error; |
|
1579 } |
|
1580 CleanupStack::PushL(authority); |
|
1581 // Add host... |
|
1582 if( DoAuthoritySetAndEscapeAndCompareComponent<CAuthorityType>(authority, EAuthorityHost, aHost, aAuthority_Host) != KErrNone ) |
|
1583 { |
|
1584 CleanupStack::PopAndDestroy(authority); // authority |
|
1585 return KErrNotFound; |
|
1586 } |
|
1587 // Add userinfo... |
|
1588 if( DoAuthoritySetAndEscapeAndCompareComponent<CAuthorityType>(authority, EAuthorityUserinfo, aUserinfo, aAuthority_Userinfo) != KErrNone ) |
|
1589 { |
|
1590 CleanupStack::PopAndDestroy(authority); // authority |
|
1591 return KErrNotFound; |
|
1592 } |
|
1593 // Add port... |
|
1594 if( DoAuthoritySetAndEscapeAndCompareComponent<CAuthorityType>(authority, EAuthorityPort, aPort, aAuthority_Port) != KErrNone ) |
|
1595 { |
|
1596 CleanupStack::PopAndDestroy(authority); // authority |
|
1597 return KErrNotFound; |
|
1598 } |
|
1599 // Cleanup and return |
|
1600 CleanupStack::PopAndDestroy(authority); // authority |
|
1601 return KErrNone; |
|
1602 } |
|
1603 |
|
1604 template<class CAuthorityType, class TDesCType> |
|
1605 TInt DoAuthoritySetAndEscapeAndCompareComponent(CAuthorityType* aAuthority, TAuthorityComponent aComponent, const TDesCType& aData, const TDesCType& aExpected) |
|
1606 { |
|
1607 TRAPD(error, aAuthority->SetAndEscapeComponentL(aData, aComponent)); |
|
1608 if( error != KErrNone ) |
|
1609 { |
|
1610 return error; |
|
1611 } |
|
1612 // Compare with expected |
|
1613 if( aAuthority->Authority().AuthorityDes().Compare(aExpected) != 0) |
|
1614 { |
|
1615 return KErrNotFound; |
|
1616 } |
|
1617 return KErrNone; |
|
1618 } |
|
1619 |
|
1620 template<class CAuthorityType, class TAuthorityParserType, class TDesCType> |
|
1621 TInt DoAuthorityDestruction(const TDesCType& aAuthority_NoHost, const TDesCType& aAuthority_NoUserinfo, |
|
1622 const TDesCType& aAuthority_NoPort, const TDesCType& aAuthority_Whole) |
|
1623 { |
|
1624 // Create a TAuthorityC-derived objet from whole authority |
|
1625 TAuthorityParserType parser; |
|
1626 TInt error = parser.Parse(aAuthority_Whole); |
|
1627 // Create the CAuthorityType object |
|
1628 CAuthorityType* authority = NULL; |
|
1629 TRAP(error, authority = CAuthorityType::NewL(parser)); |
|
1630 if( error != KErrNone ) |
|
1631 { |
|
1632 return error; |
|
1633 } |
|
1634 CleanupStack::PushL(authority); |
|
1635 // Remove port... |
|
1636 if( DoAuthorityRemoveAndCompareComponent<CAuthorityType>(authority, EAuthorityPort, aAuthority_NoPort) != KErrNone ) |
|
1637 { |
|
1638 CleanupStack::PopAndDestroy(authority); // authority |
|
1639 return KErrNotFound; |
|
1640 } |
|
1641 // Remove userinfo... |
|
1642 if( DoAuthorityRemoveAndCompareComponent<CAuthorityType>(authority, EAuthorityUserinfo, aAuthority_NoUserinfo) != KErrNone ) |
|
1643 { |
|
1644 CleanupStack::PopAndDestroy(authority); // authority |
|
1645 return KErrNotFound; |
|
1646 } |
|
1647 // Remove host... |
|
1648 if( DoAuthorityRemoveAndCompareComponent<CAuthorityType>(authority, EAuthorityHost, aAuthority_NoHost) != KErrNone ) |
|
1649 { |
|
1650 CleanupStack::PopAndDestroy(authority); // authority |
|
1651 return KErrNotFound; |
|
1652 } |
|
1653 // Cleanup and return |
|
1654 CleanupStack::PopAndDestroy(authority); // authority |
|
1655 return KErrNone; |
|
1656 } |
|
1657 |
|
1658 template<class CAuthorityType, class TDesCType> |
|
1659 TInt DoAuthorityRemoveAndCompareComponent(CAuthorityType* aAuthority, TAuthorityComponent aComponent, const TDesCType& aExpected) |
|
1660 { |
|
1661 TRAPD(error, aAuthority->RemoveComponentL(aComponent)); |
|
1662 if( error != KErrNone ) |
|
1663 { |
|
1664 return error; |
|
1665 } |
|
1666 // Compare with expected |
|
1667 if( aAuthority->Authority().AuthorityDes().Compare(aExpected) != 0) |
|
1668 { |
|
1669 return KErrNotFound; |
|
1670 } |
|
1671 return KErrNone; |
|
1672 } |