|
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 // Implementation of CHttpHdrCodecTest |
|
15 // |
|
16 // |
|
17 |
|
18 #include <inetprottextutils.h> |
|
19 #include "t_hdrcodec.h" |
|
20 |
|
21 _LIT8(KFieldSeparator, "\n"); |
|
22 |
|
23 |
|
24 void CHttpHdrCodecTest::DoRunL() |
|
25 { |
|
26 iExpectedStatusCode = 0; |
|
27 // insert test code here, allow it to leave if the test fails |
|
28 RunTestsL(); |
|
29 } |
|
30 |
|
31 TInt CHttpHdrCodecTest::RunError(TInt aErr) |
|
32 { |
|
33 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
34 return KErrNone; |
|
35 } |
|
36 |
|
37 void CHttpHdrCodecTest::DoCancel() |
|
38 { |
|
39 } |
|
40 |
|
41 const TDesC& CHttpHdrCodecTest::TestName() |
|
42 { |
|
43 _LIT(KHeaderTestName,"CHttpHdrCodecTest"); |
|
44 return KHeaderTestName; |
|
45 } |
|
46 |
|
47 CHttpHdrCodecTest::CHttpHdrCodecTest() |
|
48 // Constructor |
|
49 { |
|
50 // Initial timestamp is time now |
|
51 ResetTimeElapsed(); |
|
52 } |
|
53 |
|
54 CHttpHdrCodecTest::~CHttpHdrCodecTest() |
|
55 // Destructor (virtual) |
|
56 { |
|
57 } |
|
58 |
|
59 CHttpHdrCodecTest* CHttpHdrCodecTest::NewLC() |
|
60 // Create a new CHttpHdrCodecTest and place it on the clean-up stack then return it |
|
61 { |
|
62 CHttpHdrCodecTest* me = new(ELeave) CHttpHdrCodecTest; |
|
63 CleanupStack::PushL(me); |
|
64 return me; |
|
65 } |
|
66 |
|
67 CHttpHdrCodecTest* CHttpHdrCodecTest::NewL() |
|
68 // Create a new CHttpHdrCodecTest and return it |
|
69 { |
|
70 CHttpHdrCodecTest* me = new(ELeave) CHttpHdrCodecTest; |
|
71 return me; |
|
72 } |
|
73 |
|
74 void CHttpHdrCodecTest::RunTestsL() |
|
75 { |
|
76 // start the session |
|
77 iSession.OpenL(); |
|
78 CleanupClosePushL(iSession); |
|
79 // Locate the string pool |
|
80 iStrP = iSession.StringPool(); |
|
81 |
|
82 _LIT8(KTxtHTTPProt, "HTTP/TCP"); |
|
83 iProtHnd = CProtocolHandler::NewL(KTxtHTTPProt(), iSession); |
|
84 CleanupStack::PushL(iProtHnd); |
|
85 |
|
86 iEngine->Console().Printf(_L("\nStart of header codec tests")); |
|
87 ResetTimeElapsed(); |
|
88 |
|
89 // Run tests on parsed -> OTA data conversions, for each header implemented |
|
90 TestEncodeAcceptL(); |
|
91 TestEncodeAcceptCharsetL(); |
|
92 TestEncodeAuthorizationL(); |
|
93 TestEncodeConnectionL(); |
|
94 TestEncodeContentLengthL(); |
|
95 TestEncodeContentTypeL(); |
|
96 TestEncodeHostL(); |
|
97 TestEncodeTransferEncodingL(); |
|
98 TestEncodeUserAgentL(); |
|
99 TestEncodeDateL(); |
|
100 TestEncodeLocaleIndependentDateL(); |
|
101 TestEncodeUpgradeL(); |
|
102 |
|
103 TestEncodeCookieL(); |
|
104 TestEncodeCacheControlL(); |
|
105 |
|
106 // Run tests on OTA data -> parsed conversions, for each header implemented |
|
107 TestDecodeConnectionL(); |
|
108 TestDecodeContentLengthL(); |
|
109 TestDecodeContentTypeL(); |
|
110 TestDecodeContentTypeWithMultipleParametersL(); |
|
111 TestDecodeContentTypeMissingParameterL(); |
|
112 TestDecodeServerL(); |
|
113 TestDecodeDateL(); |
|
114 TestDecodeTransferEncodingL(); |
|
115 TestDecodeWWWAuthenticateL(); |
|
116 TestDecodeUpgradeL(); |
|
117 |
|
118 TestDecodeSetCookieL(); |
|
119 TestDecodeSetCookie2L(); |
|
120 TestDecodeSetCookie3L(); |
|
121 TestDecodeSetCookie4L(); |
|
122 //test for DEF080697: Cookies: When sending a request to an origin server, Browser is not sending the |
|
123 TestEncodeCookiePortL(); |
|
124 |
|
125 |
|
126 TestDecodeCacheControlL(); |
|
127 |
|
128 // Do some round trip encode->decode and check the original input is the same as the final output |
|
129 TestRoundTripConnectionL(); |
|
130 TestRoundTripContentLengthL(); |
|
131 TestRoundTripContentLength2L(); |
|
132 TestRoundTripContentTypeL(); |
|
133 TestRoundTripTransferEncodingL(); |
|
134 |
|
135 TestDuplicateHeaderResponsesL(); |
|
136 |
|
137 //test for DEF078684: Authorization header nonce count is sent incorrectly |
|
138 TestEncodeAuthorization1L(); |
|
139 |
|
140 //test for INC118854:Invalid parsing of HTTP headers when value contains a ";" character |
|
141 TestDecodeContentDispositionL(); |
|
142 |
|
143 TestGetCustomFieldValueL(); |
|
144 |
|
145 TestGetCustomFieldNullValueL(); |
|
146 |
|
147 TestGetCustomFieldNoValueL(); |
|
148 |
|
149 // test for PDEF138861: Trying to access header field part at Index < 0 |
|
150 TestInvalidHeaderFieldPartL (); |
|
151 |
|
152 // End of tests |
|
153 DisplayTimeElapsed(); |
|
154 iEngine->Console().Printf(_L("\nEnd of header codec tests")); |
|
155 CleanupStack::PopAndDestroy(2,&iSession); |
|
156 } |
|
157 |
|
158 void CHttpHdrCodecTest::TestDuplicateHeaderResponsesL() |
|
159 { |
|
160 // Test Headers that are handled by textmode codec |
|
161 |
|
162 // Response with 2 connection type headers |
|
163 TInt numParts=2; |
|
164 RStringF header = iStrP.StringF(HTTP::EConnection, RHTTPSession::GetTable()); |
|
165 _LIT8(KConnectionRawHeader1, "close\nkeep-alive"); |
|
166 TestDuplicateHeaderDecodingL(header,KConnectionRawHeader1, numParts); |
|
167 |
|
168 _LIT8(KConnectionRawHeader2, "close, keep-alive"); |
|
169 TestDuplicateHeaderDecodingL(header,KConnectionRawHeader2, numParts); |
|
170 |
|
171 // Response with 2 content type headers |
|
172 numParts=1; |
|
173 header = iStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()); |
|
174 _LIT8(KContentTypeRawHeader1, "text/html\ntext/html"); |
|
175 TestDuplicateHeaderDecodingL(header, KContentTypeRawHeader1,numParts); |
|
176 |
|
177 // Response with 2 different date headers |
|
178 // This also checks Expires and Last-Modified as they use the same generic date parsing in |
|
179 // the codec |
|
180 header = iStrP.StringF(HTTP::EDate, RHTTPSession::GetTable()); |
|
181 _LIT8(KDateRawHeader1, "Tue, 15 Nov 1994 08:12:31 GMT\n Wed, 16 Nov 1994 09:00:30 GMT"); |
|
182 TestDuplicateHeaderDecodingL(header, KDateRawHeader1, numParts); |
|
183 |
|
184 // Response with 3 different content length headers |
|
185 // This also checks Age as that uses the same generic number parsing |
|
186 header = iStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()); |
|
187 _LIT8(KContentLengthRawHeader1, "10\n200\n3000"); |
|
188 TestDuplicateHeaderDecodingL(header, KContentLengthRawHeader1, numParts); |
|
189 |
|
190 |
|
191 // Response with 2 different transfer-encodings |
|
192 numParts=2; |
|
193 header = iStrP.StringF(HTTP::ETransferEncoding, RHTTPSession::GetTable()); |
|
194 _LIT8(KTransferEncodingRawHeader1, "chunked\nchunked2"); |
|
195 TestDuplicateHeaderDecodingL(header, KTransferEncodingRawHeader1, numParts); |
|
196 |
|
197 // Response with 2 different WWWAuthenticate headers |
|
198 header = iStrP.StringF(HTTP::EWWWAuthenticate, RHTTPSession::GetTable()); |
|
199 _LIT8(KWWWAuthenticateRawHeader1, "basic realm=castle\nbasic realm=magic"); |
|
200 TestDuplicateHeaderDecodingL(header, KWWWAuthenticateRawHeader1, numParts); |
|
201 |
|
202 // Response with 2 different SetCookie headers |
|
203 // Also tests SetCookie2 as that goes through same codec |
|
204 header = iStrP.StringF(HTTP::ESetCookie, RHTTPSession::GetTable()); |
|
205 _LIT8(KSetCookieRawHeader1, "cookie=chocolate\ncookie=ginger"); |
|
206 TestDuplicateHeaderDecodingL(header, KSetCookieRawHeader1, numParts); |
|
207 |
|
208 // Response with 2 cache control headers |
|
209 header = iStrP.StringF(HTTP::ECacheControl, RHTTPSession::GetTable()); |
|
210 _LIT8(KCacheControlRawHeader1, "max-age=100\nno-transform"); |
|
211 TestDuplicateHeaderDecodingL(header, KCacheControlRawHeader1, numParts); |
|
212 |
|
213 |
|
214 header = iStrP.StringF(HTTP::ECacheControl, RHTTPSession::GetTable()); |
|
215 _LIT8(KCacheControlRawHeader2, "max-age=100, no-transform"); |
|
216 TestDuplicateHeaderDecodingL(header, KCacheControlRawHeader2, numParts); |
|
217 |
|
218 |
|
219 // Response with 2 pragma headers |
|
220 // This also tests vary and content-langugage which both use same generic parser |
|
221 header = iStrP.StringF(HTTP::EPragma, RHTTPSession::GetTable()); |
|
222 _LIT8(KPragmaRawHeader1, "pragma1\npragma2"); |
|
223 TestDuplicateHeaderDecodingL(header, KPragmaRawHeader1, numParts); |
|
224 |
|
225 |
|
226 // Test some headers that will use the default codec |
|
227 numParts=2; |
|
228 // Response with 2 ETag headers |
|
229 header = iStrP.StringF(HTTP::EETag, RHTTPSession::GetTable()); |
|
230 _LIT8(KETagRawHeader1, "\"xxxyz\"\n\"xyyz\""); |
|
231 TestDuplicateHeaderDecodingL(header, KETagRawHeader1, numParts); |
|
232 |
|
233 header = iStrP.StringF(HTTP::EETag, RHTTPSession::GetTable()); |
|
234 _LIT8(KETagRawHeader2, "\"xxxyz\"\n\"xyyz\" "); |
|
235 TestDuplicateHeaderDecodingL(header, KETagRawHeader2, numParts); |
|
236 |
|
237 |
|
238 |
|
239 // Default codec with one header |
|
240 numParts=1; |
|
241 header = iStrP.StringF(HTTP::EETag, RHTTPSession::GetTable()); |
|
242 _LIT8(KETagRawHeader3, "\"xxxyz\""); |
|
243 TestDuplicateHeaderDecodingL(header, KETagRawHeader3, numParts); |
|
244 |
|
245 iEngine->Utils().LogIt ( _L ("\nTestDuplicateHeaderResponsesL test success.")); |
|
246 } |
|
247 |
|
248 |
|
249 void CHttpHdrCodecTest::TestDuplicateHeaderDecodingL(RStringF aHeader, |
|
250 const TDesC8& aRawResponseHeader, |
|
251 TInt aExpectedNumberParts) |
|
252 /* This is to test decoding of multiple response headers |
|
253 HTTP Framework deals with these by joining them together using \n as a seperator |
|
254 */ |
|
255 { |
|
256 RHTTPHeaders headers = GetHeadersLC(); |
|
257 headers.SetRawFieldL(aHeader, aRawResponseHeader, KFieldSeparator); |
|
258 |
|
259 // Check parsing of raw header. Framework should only return first header if there are duplicates |
|
260 // Don't bother checking multiple values on one line. |
|
261 TPtrC8 rawHeader(KNullDesC8); |
|
262 User::LeaveIfError(headers.GetRawField(aHeader,rawHeader)); |
|
263 TInt firstNewLinePosition = aRawResponseHeader.Locate('\n'); |
|
264 if (firstNewLinePosition != KErrNotFound) |
|
265 { |
|
266 TPtrC8 expectedRawResponse(rawHeader.Left(firstNewLinePosition)); |
|
267 if (rawHeader.CompareF(expectedRawResponse) != 0) |
|
268 { |
|
269 TBuf < 1024 > rawHeader16; |
|
270 TBuf < 1024 > expectedRawResponse16; |
|
271 rawHeader16.Copy ( rawHeader ); |
|
272 expectedRawResponse16.Copy ( expectedRawResponse ); |
|
273 |
|
274 iEngine->Utils().LogIt ( _L("Raw header comparison failed -> %S != %S"), &rawHeader16, &expectedRawResponse16 ); |
|
275 User::Leave(KErrArgument); |
|
276 } |
|
277 } |
|
278 |
|
279 |
|
280 // Check parsing when converting through codec |
|
281 TInt numberParts = headers.FieldPartsL(aHeader); |
|
282 if (numberParts != aExpectedNumberParts) |
|
283 { |
|
284 iEngine->Utils().LogIt ( _L("\nNumber parts differ from expected. -> %d != %d"), numberParts, aExpectedNumberParts ); |
|
285 User::Leave(KErrArgument); |
|
286 } |
|
287 |
|
288 |
|
289 ReleaseHeaders(); |
|
290 |
|
291 iEngine->Utils().LogIt ( _L ("\nTestDuplicateHeaderDecodingL test success.")); |
|
292 } |
|
293 |
|
294 |
|
295 void CHttpHdrCodecTest::TestEncodeAcceptL() |
|
296 { |
|
297 // the result we expect and that we will validate |
|
298 _LIT8(KAcceptOTAVal, "text/html; q=0.8, text/vnd.wap.wml; q=0.2; extended=value, text/*"); |
|
299 |
|
300 // Open strings used in this test |
|
301 RStringF textHtml = iStrP.StringF(HTTP::ETextHtml,RHTTPSession::GetTable()); |
|
302 RStringF textWml = iStrP.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable()); |
|
303 RStringF textAny = iStrP.StringF(HTTP::ETextAny,RHTTPSession::GetTable()); |
|
304 |
|
305 RStringF extended = iStrP.OpenFStringL(_L8("extended")); |
|
306 CleanupClosePushL(extended); |
|
307 RStringF extendVal = iStrP.OpenFStringL(_L8("value")); |
|
308 CleanupClosePushL(extendVal); |
|
309 // |
|
310 iEngine->Console().Printf(_L("\nTest encoding 'Accept' header")); |
|
311 |
|
312 RHTTPHeaders hdr = GetHeadersLC(); |
|
313 |
|
314 // Set up the parsed header |
|
315 RStringF accept = iStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()); |
|
316 THTTPHdrVal accVal(textHtml); |
|
317 THTTPHdrVal q(THTTPHdrVal::TQConv(0.8)); |
|
318 hdr.SetFieldL(accept, accVal, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), q); |
|
319 accVal.SetStrF(textWml); |
|
320 q.SetInt(THTTPHdrVal::TQConv(0.2)); |
|
321 hdr.SetFieldL(accept, accVal, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), q); |
|
322 q.SetStrF(extendVal); |
|
323 hdr.SetFieldL(accept, accVal, extended, q); |
|
324 accVal.SetStrF(textAny); |
|
325 hdr.SetFieldL(accept, accVal); |
|
326 |
|
327 // now get the OTA data |
|
328 TPtrC8 ota; |
|
329 hdr.GetRawField(accept, ota); |
|
330 if (ota.Compare(KAcceptOTAVal()) != 0) |
|
331 { |
|
332 TBuf<512> ota16; |
|
333 ota16.Copy (ota); |
|
334 iEngine->Utils().LogIt ( _L("\nAccept OTA comparison failed -> %S"), &ota16 ); |
|
335 User::Leave(KErrArgument); |
|
336 } |
|
337 |
|
338 |
|
339 // Close strings used in this test |
|
340 ReleaseHeaders(); |
|
341 CleanupStack::PopAndDestroy(2, &extended); |
|
342 |
|
343 iEngine->Utils().LogIt ( _L ("\nTestEncodeAcceptL test success.")); |
|
344 } |
|
345 |
|
346 void CHttpHdrCodecTest::TestEncodeAcceptCharsetL() |
|
347 { |
|
348 // the result we expect and that we will validate |
|
349 _LIT8(KAccChSetOTAVal, "iso-8859-5, unicode-1-1; q=0.8"); |
|
350 |
|
351 // Open strings used in this test |
|
352 RStringF iso8859_5 = iStrP.OpenFStringL(_L8("iso-8859-5")); |
|
353 CleanupClosePushL(iso8859_5); |
|
354 RStringF unicode1_1 = iStrP.OpenFStringL(_L8("unicode-1-1")); |
|
355 CleanupClosePushL(unicode1_1); |
|
356 |
|
357 iEngine->Console().Printf(_L("\nTest encoding 'Accept-Charset' header")); |
|
358 RHTTPHeaders hdr = GetHeadersLC(); |
|
359 |
|
360 // Set up the parsed header |
|
361 RStringF accChSet= iStrP.StringF(HTTP::EAcceptCharset,RHTTPSession::GetTable()); |
|
362 THTTPHdrVal accChSetVal(iso8859_5); |
|
363 hdr.SetFieldL(accChSet, accChSetVal); |
|
364 // |
|
365 accChSetVal.SetStrF(unicode1_1); |
|
366 THTTPHdrVal q(THTTPHdrVal::TQConv(0.8)); |
|
367 hdr.SetFieldL(accChSet, accChSetVal, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), q); |
|
368 |
|
369 // now get the OTA data |
|
370 TPtrC8 ota; |
|
371 hdr.GetRawField(accChSet, ota); |
|
372 if (ota.Compare(KAccChSetOTAVal()) != 0) |
|
373 { |
|
374 TBuf<512> ota16; |
|
375 ota16.Copy (ota); |
|
376 iEngine->Utils().LogIt ( _L("\nComparison of charset field failed -> %S"), &ota16 ); |
|
377 User::Leave(KErrArgument); |
|
378 } |
|
379 |
|
380 |
|
381 ReleaseHeaders(); |
|
382 |
|
383 CleanupStack::PopAndDestroy(2, &iso8859_5); |
|
384 iEngine->Utils().LogIt ( _L ("\nTestEncodeAcceptCharsetL test success.")); |
|
385 } |
|
386 |
|
387 //test for DEF078684: Authorization header nonce count is sent incorrectly |
|
388 void CHttpHdrCodecTest::TestEncodeAuthorization1L() |
|
389 { |
|
390 // the result we expect and that we will validate |
|
391 _LIT8(KAuthorizationOTAVal, "Digest nc=00000001, algorithm=MD5, nonce=\"999999\""); |
|
392 |
|
393 // Open strings used in this test |
|
394 RString ncVal = iStrP.OpenStringL(_L8("00000001")); |
|
395 CleanupClosePushL(ncVal); |
|
396 |
|
397 RString algVal = iStrP.OpenStringL(_L8("MD5")); |
|
398 CleanupClosePushL(algVal); |
|
399 |
|
400 RString nonceVal = iStrP.OpenStringL(_L8("999999")); |
|
401 CleanupClosePushL(nonceVal); |
|
402 |
|
403 // |
|
404 iEngine->Console().Printf(_L("\nTest encoding 'Authorization' header")); |
|
405 RHTTPHeaders hdr = GetHeadersLC(); |
|
406 |
|
407 RStringF authStr = iStrP.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()); |
|
408 THTTPHdrVal authVal(iStrP.StringF(HTTP::EDigest,RHTTPSession::GetTable())); |
|
409 THTTPHdrVal hdrNcVal(ncVal); |
|
410 |
|
411 RStringF ncStr = iStrP.StringF(HTTP::ENc,RHTTPSession::GetTable()); |
|
412 hdr.SetFieldL(authStr, authVal,ncStr,hdrNcVal); |
|
413 |
|
414 THTTPHdrVal hdralgVal(algVal); |
|
415 RStringF algStr = iStrP.StringF(HTTP::EAlgorithm,RHTTPSession::GetTable()); |
|
416 hdr.SetFieldL(authStr, authVal,algStr,hdralgVal); |
|
417 |
|
418 THTTPHdrVal hdrnonceVal(nonceVal); |
|
419 RStringF nonceStr = iStrP.StringF(HTTP::ENonce,RHTTPSession::GetTable()); |
|
420 hdr.SetFieldL(authStr, authVal,nonceStr,hdrnonceVal); |
|
421 |
|
422 // now get the OTA data |
|
423 TPtrC8 ota; |
|
424 hdr.GetRawField(authStr, ota); |
|
425 if (ota.Compare(KAuthorizationOTAVal()) != 0) |
|
426 { |
|
427 TBuf<512> ota16; |
|
428 ota16.Copy (ota); |
|
429 iEngine->Utils().LogIt ( _L("\nComparison of Authorization field failed -> %S"), &ota16 ); |
|
430 User::Leave(KErrArgument); |
|
431 } |
|
432 |
|
433 ReleaseHeaders(); |
|
434 |
|
435 CleanupStack::PopAndDestroy(&nonceVal); |
|
436 CleanupStack::PopAndDestroy(&algVal); |
|
437 CleanupStack::PopAndDestroy(&ncVal); |
|
438 iEngine->Utils().LogIt ( _L ("\nTestEncodeAuthorizationL test success.")); |
|
439 } |
|
440 void CHttpHdrCodecTest::TestEncodeAuthorizationL() |
|
441 { |
|
442 // the result we expect and that we will validate |
|
443 _LIT8(KAuthorizationOTAVal, "Basic c3ltYmlhbjpmMXN5bmNtbA=="); |
|
444 |
|
445 // Open strings used in this test |
|
446 RString basicCred = iStrP.OpenStringL(_L8("c3ltYmlhbjpmMXN5bmNtbA==")); |
|
447 CleanupClosePushL(basicCred); |
|
448 // |
|
449 iEngine->Console().Printf(_L("\nTest encoding 'Authorization' header")); |
|
450 RHTTPHeaders hdr = GetHeadersLC(); |
|
451 |
|
452 RStringF authStr = iStrP.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()); |
|
453 THTTPHdrVal authVal(iStrP.StringF(HTTP::EBasic,RHTTPSession::GetTable())); |
|
454 hdr.SetFieldL(authStr, authVal); // sets part 1 |
|
455 THTTPHdrVal credVal(basicCred); |
|
456 hdr.SetFieldL(authStr, credVal); // sets part 2 |
|
457 |
|
458 // now get the OTA data |
|
459 TPtrC8 ota; |
|
460 hdr.GetRawField(authStr, ota); |
|
461 if (ota.Compare(KAuthorizationOTAVal()) != 0) |
|
462 { |
|
463 TBuf<512> ota16; |
|
464 ota16.Copy (ota); |
|
465 iEngine->Utils().LogIt ( _L("\nComparison of Authorization field failed -> %S"), &ota16 ); |
|
466 User::Leave(KErrArgument); |
|
467 } |
|
468 |
|
469 |
|
470 ReleaseHeaders(); |
|
471 |
|
472 CleanupStack::PopAndDestroy(&basicCred); |
|
473 iEngine->Utils().LogIt ( _L ("\nTestEncodeAuthorizationL test success.")); |
|
474 } |
|
475 |
|
476 void CHttpHdrCodecTest::TestEncodeConnectionL() |
|
477 { |
|
478 // the result we expect and that we will validate |
|
479 _LIT8(KConnectionOTAVal, "close, keep-alive"); |
|
480 |
|
481 // Open strings used in this test |
|
482 RStringF otherToken = iStrP.StringF(HTTP::EKeepAlive,RHTTPSession::GetTable()); |
|
483 // |
|
484 iEngine->Console().Printf(_L("\nTest encoding 'Connection' header")); |
|
485 RHTTPHeaders hdr = GetHeadersLC(); |
|
486 RStringF connStr = iStrP.StringF(HTTP::EConnection,RHTTPSession::GetTable()); |
|
487 THTTPHdrVal connVal(iStrP.StringF(HTTP::EClose,RHTTPSession::GetTable())); |
|
488 hdr.SetFieldL(connStr, connVal); // sets part 1 |
|
489 THTTPHdrVal keepAlive(otherToken); |
|
490 hdr.SetFieldL(connStr, keepAlive); // sets part 2 |
|
491 |
|
492 // now get the OTA data |
|
493 TPtrC8 ota; |
|
494 hdr.GetRawField(connStr, ota); |
|
495 if (ota.CompareF(KConnectionOTAVal()) != 0) |
|
496 { |
|
497 TBuf<512> ota16; |
|
498 ota16.Copy (ota); |
|
499 iEngine->Utils().LogIt ( _L("\nComparison of connection field failed -> %S"), &ota16 ); |
|
500 User::Leave(KErrArgument); |
|
501 } |
|
502 |
|
503 ReleaseHeaders(); |
|
504 |
|
505 iEngine->Utils().LogIt ( _L ("\nTestEncodeConnectionL test success.\n")); |
|
506 } |
|
507 |
|
508 void CHttpHdrCodecTest::TestEncodeContentLengthL() |
|
509 { |
|
510 // the result we expect and that we will validate |
|
511 _LIT8(KContentLengthOTAVal, "12345"); |
|
512 // |
|
513 iEngine->Console().Printf(_L("\nTest encoding 'Content-Length' header")); |
|
514 RHTTPHeaders hdr = GetHeadersLC(); |
|
515 RStringF lengthStr = iStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()); |
|
516 THTTPHdrVal lengthVal(12345); |
|
517 hdr.SetFieldL(lengthStr, lengthVal); // sets part 1 |
|
518 |
|
519 // now get the OTA data |
|
520 TPtrC8 ota; |
|
521 hdr.GetRawField(lengthStr, ota); |
|
522 if (ota.Compare(KContentLengthOTAVal()) != 0) |
|
523 { |
|
524 TBuf<512> ota16; |
|
525 ota16.Copy (ota); |
|
526 iEngine->Utils().LogIt ( _L("\nComparison of content length field value failed. -> %S"), &ota16 ); |
|
527 User::Leave(KErrArgument); |
|
528 } |
|
529 |
|
530 ReleaseHeaders(); |
|
531 iEngine->Utils().LogIt ( _L ("\nTestEncodeContentLengthL test success.")); |
|
532 } |
|
533 |
|
534 void CHttpHdrCodecTest::TestEncodeContentTypeL() |
|
535 { |
|
536 // the result we expect and that we will validate |
|
537 _LIT8(KContentTypeOTAVal1, "text/plain"); |
|
538 _LIT8(KContentTypeOTAVal2, "text/html; charset=us-ascii"); |
|
539 _LIT8(KContentTypeOTAVal3, "text/vnd.wap.wml; charset=utf-8; transcode=yes"); |
|
540 |
|
541 // Open strings used in this test |
|
542 RStringF textHtml = iStrP.StringF(HTTP::ETextHtml,RHTTPSession::GetTable()); |
|
543 RStringF textWml = iStrP.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable()); |
|
544 RStringF textPlain = iStrP.StringF(HTTP::ETextPlain,RHTTPSession::GetTable()); |
|
545 |
|
546 RStringF usAscii = iStrP.OpenFStringL(_L8("us-ascii")); |
|
547 CleanupClosePushL(usAscii); |
|
548 RStringF utf8 = iStrP.OpenFStringL(_L8("utf-8")); |
|
549 CleanupClosePushL(utf8); |
|
550 RStringF extended = iStrP.OpenFStringL(_L8("transcode")); |
|
551 CleanupClosePushL(extended); |
|
552 RStringF extendVal = iStrP.OpenFStringL(_L8("yes")); |
|
553 CleanupClosePushL(extendVal); |
|
554 // |
|
555 iEngine->Console().Printf(_L("\nTest encoding 'Content-Type' header (no params)")); |
|
556 RHTTPHeaders hdr = GetHeadersLC(); |
|
557 |
|
558 // Set up the parsed header |
|
559 RStringF contType = iStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
560 THTTPHdrVal ctVal(textPlain); |
|
561 hdr.SetFieldL(contType, ctVal); |
|
562 |
|
563 // now get the OTA data |
|
564 TPtrC8 ota; |
|
565 hdr.GetRawField(contType, ota); |
|
566 if (ota.Compare(KContentTypeOTAVal1()) != 0) |
|
567 { |
|
568 TBuf<512> ota16; |
|
569 ota16.Copy (ota); |
|
570 iEngine->Utils().LogIt ( _L("\nComparison of content type (no params) field failed. -> %S"), &ota16); |
|
571 User::Leave(KErrArgument); |
|
572 } |
|
573 |
|
574 // |
|
575 iEngine->Console().Printf(_L("\nTest encoding 'Content-Type' header (with charset parameter)")); |
|
576 hdr.RemoveField(contType); |
|
577 ctVal.SetStrF(textHtml); |
|
578 THTTPHdrVal chSet(usAscii); |
|
579 hdr.SetFieldL(contType, ctVal, iStrP.StringF(HTTP::ECharset,RHTTPSession::GetTable()), chSet); |
|
580 hdr.GetRawField(contType, ota); |
|
581 if (ota.Compare(KContentTypeOTAVal2()) != 0) |
|
582 { |
|
583 TBuf<512> ota16; |
|
584 ota16.Copy (ota); |
|
585 iEngine->Utils().LogIt ( _L("Comparison of content type (with charset parameter) failed -> %S"), &ota16 ); |
|
586 User::Leave(KErrArgument); |
|
587 } |
|
588 |
|
589 // |
|
590 iEngine->Console().Printf(_L("\nTest encoding 'Content-Type' header (with two parameters)")); |
|
591 hdr.RemoveField(contType); |
|
592 ctVal.SetStrF(textWml); |
|
593 chSet.SetStrF(utf8); |
|
594 hdr.SetFieldL(contType, ctVal, iStrP.StringF(HTTP::ECharset,RHTTPSession::GetTable()), chSet); |
|
595 chSet.SetStrF(extendVal); |
|
596 hdr.SetFieldL(contType, ctVal, extended, chSet); |
|
597 hdr.GetRawField(contType, ota); |
|
598 if (ota.Compare(KContentTypeOTAVal3()) != 0) |
|
599 { |
|
600 TBuf<512> ota16; |
|
601 ota16.Copy (ota); |
|
602 iEngine->Utils().LogIt ( _L("Comparison of content type (with two parameters) field failed -> %S"), &ota16 ); |
|
603 User::Leave(KErrArgument); |
|
604 } |
|
605 |
|
606 |
|
607 ReleaseHeaders(); |
|
608 CleanupStack::PopAndDestroy(4,&usAscii); |
|
609 iEngine->Utils().LogIt ( _L ("\nTestEncodeContentTypeL test success.")); |
|
610 } |
|
611 |
|
612 void CHttpHdrCodecTest::TestEncodeHostL() |
|
613 { |
|
614 _LIT8(KHostOTAVal1, "www.symbian.com"); // ota host header |
|
615 _LIT8(KHostOTAVal2, "www.psion.com:8080"); // ota host header |
|
616 |
|
617 // Open strings used in this test |
|
618 RStringF host1Str = iStrP.OpenFStringL(_L8("www.symbian.com")); |
|
619 CleanupClosePushL(host1Str); |
|
620 RStringF host2Str = iStrP.OpenFStringL(_L8("www.psion.com")); |
|
621 CleanupClosePushL(host2Str); |
|
622 // |
|
623 iEngine->Console().Printf(_L("\nTest encoding 'Host' header (no port)")); |
|
624 RHTTPHeaders hdr = GetHeadersLC(); |
|
625 RStringF host = iStrP.StringF(HTTP::EHost,RHTTPSession::GetTable()); |
|
626 THTTPHdrVal hostVal(host1Str); |
|
627 hdr.SetFieldL(host, hostVal); |
|
628 |
|
629 // now get the OTA data |
|
630 TPtrC8 ota; |
|
631 hdr.GetRawField(host, ota); |
|
632 if (ota.Compare(KHostOTAVal1()) != 0) |
|
633 { |
|
634 TBuf < 512 > ota16; |
|
635 ota16.Copy ( ota ); |
|
636 |
|
637 iEngine->Utils().LogIt ( _L("\nComparison of host field failed. -> %S"), &ota16 ); |
|
638 User::Leave(KErrArgument); |
|
639 } |
|
640 |
|
641 // |
|
642 iEngine->Console().Printf(_L("\nTest encoding 'Host' header (with port parameter)")); |
|
643 hdr.RemoveField(host); |
|
644 RStringF port = iStrP.StringF(HTTP::EPort,RHTTPSession::GetTable()); |
|
645 hostVal.SetStrF(host2Str); |
|
646 THTTPHdrVal portNum(8080); |
|
647 hdr.SetFieldL(host, hostVal, port, portNum); |
|
648 |
|
649 // now get the OTA data |
|
650 hdr.GetRawField(host, ota); |
|
651 if (ota.Compare(KHostOTAVal2()) != 0) |
|
652 { |
|
653 TBuf < 512 > ota16; |
|
654 ota16.Copy ( ota ); |
|
655 iEngine->Utils().LogIt ( _L("\nComparison of host (with port parameter) field failed -> %S"), &ota16 ); |
|
656 User::Leave(KErrArgument); |
|
657 } |
|
658 |
|
659 |
|
660 ReleaseHeaders(); |
|
661 |
|
662 CleanupStack::PopAndDestroy(2,&host1Str); |
|
663 iEngine->Utils().LogIt(_L("\nTestEncodeHostL test success.")); |
|
664 } |
|
665 |
|
666 void CHttpHdrCodecTest::TestEncodeTransferEncodingL() |
|
667 { |
|
668 // the result we expect and that we will validate |
|
669 _LIT8(KTransferEncodingOTAVal, "chunked, another"); |
|
670 |
|
671 // Open strings used in this test |
|
672 RStringF anotherToken = iStrP.OpenFStringL(_L8("another")); |
|
673 CleanupClosePushL(anotherToken); |
|
674 // |
|
675 iEngine->Console().Printf(_L("\nTest encoding 'Transfer-Encoding' header")); |
|
676 RHTTPHeaders hdr = GetHeadersLC(); |
|
677 RStringF trEncStr = iStrP.StringF(HTTP::ETransferEncoding,RHTTPSession::GetTable()); |
|
678 THTTPHdrVal trEncVal(iStrP.StringF(HTTP::EChunked,RHTTPSession::GetTable())); |
|
679 hdr.SetFieldL(trEncStr, trEncVal); // sets part 1 |
|
680 trEncVal.SetStrF(anotherToken); |
|
681 hdr.SetFieldL(trEncStr, trEncVal); // sets part 2 |
|
682 |
|
683 // now get the OTA data |
|
684 TPtrC8 ota; |
|
685 hdr.GetRawField(trEncStr, ota); |
|
686 if(ota.Compare(KTransferEncodingOTAVal()) != 0) |
|
687 { |
|
688 TBuf < 512 > ota16; |
|
689 ota16.Copy ( ota ); |
|
690 iEngine->Utils().LogIt ( _L("\nComparison of Transfer-Encoding field failed. -> %S"), &ota16 ); |
|
691 User::Leave(KErrArgument); |
|
692 } |
|
693 |
|
694 |
|
695 ReleaseHeaders(); |
|
696 |
|
697 CleanupStack::PopAndDestroy(&anotherToken); |
|
698 iEngine->Utils().LogIt ( _L ("\nTestEncodeTransferEncodingL test success.")); |
|
699 } |
|
700 |
|
701 void CHttpHdrCodecTest::TestEncodeUserAgentL() |
|
702 { |
|
703 // the result we expect and that we will validate |
|
704 _LIT8(KUserAgentOTAVal, "CERN-LineMode/2.15 libwww/2.17b3"); |
|
705 |
|
706 // Open strings used in this test |
|
707 RStringF ua1Str = iStrP.OpenFStringL(_L8("CERN-LineMode/2.15")); |
|
708 CleanupClosePushL(ua1Str); |
|
709 RStringF ua2Str = iStrP.OpenFStringL(_L8("libwww/2.17b3")); |
|
710 CleanupClosePushL(ua2Str); |
|
711 // |
|
712 iEngine->Console().Printf(_L("\nTest encoding 'User-Agent' header")); |
|
713 RHTTPHeaders hdr = GetHeadersLC(); |
|
714 RStringF uaStr = iStrP.StringF(HTTP::EUserAgent,RHTTPSession::GetTable()); |
|
715 THTTPHdrVal uaVal(ua1Str); |
|
716 hdr.SetFieldL(uaStr, uaVal); // sets part 1 |
|
717 uaVal.SetStrF(ua2Str); |
|
718 hdr.SetFieldL(uaStr, uaVal); // sets part 2 |
|
719 |
|
720 // now get the OTA data |
|
721 TPtrC8 ota; |
|
722 hdr.GetRawField(uaStr, ota); |
|
723 if(ota.Compare(KUserAgentOTAVal()) != 0) |
|
724 { |
|
725 TBuf < 512 > ota16; |
|
726 ota16.Copy ( ota ); |
|
727 iEngine->Utils().LogIt ( _L("\nComparison of User-Agent field failed. -> %S"), &ota16 ); |
|
728 User::Leave(KErrArgument); |
|
729 } |
|
730 |
|
731 |
|
732 ReleaseHeaders(); |
|
733 |
|
734 CleanupStack::PopAndDestroy(2,&ua1Str); |
|
735 iEngine->Utils().LogIt ( _L ("\nTestEncodeUserAgentL test success.")); |
|
736 } |
|
737 |
|
738 void CHttpHdrCodecTest::TestEncodeCookieL() |
|
739 { |
|
740 _LIT8(KEncodedCookieHeader1, "CUSTOMER=WILE_E_COYOTE"); |
|
741 _LIT8(KEncodedCookieHeader2, "CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKETLAUNCHER_0001"); |
|
742 _LIT8(KEncodedCookieHeader3, "CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKETLAUNCHER_0001; SHIPPING=FEDEX"); |
|
743 _LIT8(KEncodedCookieHeader4, "$VERSION=1; CUSTOMER=WILE_E_COYOTE; $PATH=/"); |
|
744 |
|
745 _LIT8(KName1, "CUSTOMER"); |
|
746 _LIT8(KValue1, "WILE_E_COYOTE"); |
|
747 _LIT8(KName2, "PART_NUMBER"); |
|
748 _LIT8(KValue2, "ROCKETLAUNCHER_0001"); |
|
749 _LIT8(KName3, "SHIPPING"); |
|
750 _LIT8(KValue3, "FEDEX"); |
|
751 _LIT8(KVersion, "1"); |
|
752 _LIT8(KPath, "/"); |
|
753 |
|
754 RString name1 = iStrP.OpenStringL(KName1); |
|
755 CleanupClosePushL(name1); |
|
756 RString value1 = iStrP.OpenStringL(KValue1); |
|
757 CleanupClosePushL(value1); |
|
758 RString name2 = iStrP.OpenStringL(KName2); |
|
759 CleanupClosePushL(name2); |
|
760 RString value2 = iStrP.OpenStringL(KValue2); |
|
761 CleanupClosePushL(value2); |
|
762 RString name3 = iStrP.OpenStringL(KName3); |
|
763 CleanupClosePushL(name3); |
|
764 RString value3 = iStrP.OpenStringL(KValue3); |
|
765 CleanupClosePushL(value3); |
|
766 RStringF version = iStrP.OpenFStringL(KVersion); |
|
767 CleanupClosePushL(version); |
|
768 RStringF path = iStrP.OpenFStringL(KPath); |
|
769 CleanupClosePushL(path); |
|
770 |
|
771 RStringF cookie = iStrP.StringF(HTTP::ECookie, RHTTPSession::GetTable()); |
|
772 RStringF cookieName = iStrP.StringF(HTTP::ECookieName, RHTTPSession::GetTable()); |
|
773 RStringF cookieValue = iStrP.StringF(HTTP::ECookieValue, RHTTPSession::GetTable()); |
|
774 RStringF cookieVersion = iStrP.StringF(HTTP::EVersion, RHTTPSession::GetTable()); |
|
775 RStringF cookiePath = iStrP.StringF(HTTP::EPath, RHTTPSession::GetTable()); |
|
776 |
|
777 TPtrC8 rawHeader; |
|
778 RHTTPHeaders hdr = GetHeadersLC(); |
|
779 |
|
780 THTTPHdrVal hVal; |
|
781 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
782 hVal.SetStr(name1); |
|
783 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
784 hVal.SetStr(value1); |
|
785 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
786 |
|
787 hdr.GetRawField(cookie, rawHeader); |
|
788 if (rawHeader.CompareF(KEncodedCookieHeader1) !=0) |
|
789 { |
|
790 TBuf < 1024> rawHeader16; |
|
791 rawHeader16.Copy ( rawHeader ); |
|
792 |
|
793 iEngine->Utils().LogIt ( _L("\nComparison of cookie header1 failed. -> %S"), &rawHeader16); |
|
794 User::Leave(KErrArgument); |
|
795 } |
|
796 |
|
797 |
|
798 ReleaseHeaders(); |
|
799 |
|
800 hdr = GetHeadersLC(); |
|
801 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
802 hVal.SetStr(name1); |
|
803 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
804 hVal.SetStr(value1); |
|
805 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
806 hVal.SetStr(name2); |
|
807 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
808 hVal.SetStr(value2); |
|
809 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
810 |
|
811 hdr.GetRawField(cookie, rawHeader); |
|
812 if (rawHeader.CompareF(KEncodedCookieHeader2) !=0) |
|
813 { |
|
814 TBuf < 1024> rawHeader16; |
|
815 rawHeader16.Copy ( rawHeader ); |
|
816 |
|
817 iEngine->Utils().LogIt ( _L("\nComparison of cookie header2 failed. -> %S"), &rawHeader16); |
|
818 User::Leave(KErrArgument); |
|
819 } |
|
820 |
|
821 |
|
822 ReleaseHeaders(); |
|
823 |
|
824 hdr = GetHeadersLC(); |
|
825 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
826 hVal.SetStr(name1); |
|
827 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
828 hVal.SetStr(value1); |
|
829 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
830 hVal.SetStr(name2); |
|
831 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
832 hVal.SetStr(value2); |
|
833 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
834 hVal.SetStr(name3); |
|
835 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
836 hVal.SetStr(value3); |
|
837 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
838 |
|
839 hdr.GetRawField(cookie, rawHeader); |
|
840 if (rawHeader.CompareF(KEncodedCookieHeader3) !=0) |
|
841 { |
|
842 TBuf < 1024> rawHeader16; |
|
843 rawHeader16.Copy ( rawHeader ); |
|
844 |
|
845 iEngine->Utils().LogIt ( _L("\nComparison of cookie header3 failed %S"), &rawHeader16 ); |
|
846 User::Leave(KErrArgument); |
|
847 } |
|
848 |
|
849 ReleaseHeaders(); |
|
850 |
|
851 hdr = GetHeadersLC(); |
|
852 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
853 hVal.SetStr(name1); |
|
854 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
855 hVal.SetStr(value1); |
|
856 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
857 hVal.SetStr(name2); |
|
858 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
859 hVal.SetStr(value2); |
|
860 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
861 hVal.SetStr(name3); |
|
862 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
863 hVal.SetStr(value3); |
|
864 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
865 |
|
866 hdr.GetRawField(cookie, rawHeader); |
|
867 if (rawHeader.CompareF(KEncodedCookieHeader3) !=0) |
|
868 { |
|
869 TBuf < 1024> rawHeader16; |
|
870 rawHeader16.Copy ( rawHeader ); |
|
871 |
|
872 iEngine->Utils().LogIt ( _L("\nComparison of cookie header4 failed %S"), &rawHeader16 ); |
|
873 User::Leave(KErrArgument); |
|
874 } |
|
875 ReleaseHeaders(); |
|
876 |
|
877 hdr = GetHeadersLC(); |
|
878 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
879 hVal.SetStrF(version); |
|
880 hdr.SetParamL(cookie, cookieVersion, hVal, 0); |
|
881 hVal.SetStr(name1); |
|
882 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
883 hVal.SetStr(value1); |
|
884 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
885 hVal.SetStrF(path); |
|
886 hdr.SetParamL(cookie, cookiePath, hVal, 0); |
|
887 |
|
888 hdr.GetRawField(cookie, rawHeader); |
|
889 if (rawHeader.CompareF(KEncodedCookieHeader4) !=0) |
|
890 { |
|
891 TBuf < 1024> rawHeader16; |
|
892 rawHeader16.Copy ( rawHeader ); |
|
893 |
|
894 iEngine->Utils().LogIt ( _L("\nComparison of cookie header5 failed -> %S"), &rawHeader16); |
|
895 User::Leave(KErrArgument); |
|
896 } |
|
897 |
|
898 |
|
899 ReleaseHeaders(); |
|
900 |
|
901 CleanupStack::PopAndDestroy(8,&name1); |
|
902 iEngine->Utils().LogIt ( _L ("\nTestEncodeCookieL test success.")); |
|
903 } |
|
904 |
|
905 void CHttpHdrCodecTest::TestDecodeSetCookieL() |
|
906 { |
|
907 RStringF setCookie = iStrP.StringF(HTTP::ESetCookie,RHTTPSession::GetTable()); |
|
908 |
|
909 RStringF cookieName = iStrP.StringF(HTTP::ECookieName,RHTTPSession::GetTable()); |
|
910 RStringF cookieValue= iStrP.StringF(HTTP::ECookieValue,RHTTPSession::GetTable()); |
|
911 RStringF cookiePath= iStrP.StringF(HTTP::EPath,RHTTPSession::GetTable()); |
|
912 RStringF cookieExpires= iStrP.StringF(HTTP::EExpires,RHTTPSession::GetTable()); |
|
913 |
|
914 THTTPHdrVal hdrVal; |
|
915 RHTTPHeaders hdr = GetHeadersLC(); |
|
916 _LIT8(KEncodedCookie1, "CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23"); |
|
917 _LIT8(KCookie1Name, "CUSTOMER"); |
|
918 _LIT8(KCookie1Value, "WILE_E_COYOTE"); |
|
919 _LIT8(KCookie1Path, "/"); |
|
920 _LIT8(KCookie1Expires, "Wednesday, 09-Nov-99 23"); |
|
921 |
|
922 RString cookie1Name = iStrP.OpenStringL(KCookie1Name); |
|
923 CleanupClosePushL(cookie1Name); |
|
924 RString cookie1Value = iStrP.OpenStringL(KCookie1Value); |
|
925 CleanupClosePushL(cookie1Value); |
|
926 RStringF cookie1Path = iStrP.OpenFStringL(KCookie1Path); |
|
927 CleanupClosePushL(cookie1Path); |
|
928 RStringF cookie1Expires = iStrP.OpenFStringL(KCookie1Expires); |
|
929 CleanupClosePushL(cookie1Expires); |
|
930 |
|
931 hdr.SetRawFieldL(setCookie, KEncodedCookie1, KFieldSeparator); |
|
932 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
933 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Name)) |
|
934 { |
|
935 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Name failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie1Name ); |
|
936 User::Leave(KErrArgument); |
|
937 } |
|
938 |
|
939 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
940 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Value)) |
|
941 { |
|
942 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Value failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie1Value ); |
|
943 User::Leave(KErrArgument); |
|
944 } |
|
945 |
|
946 User::LeaveIfError(hdr.GetParam(setCookie, cookieExpires, hdrVal)); |
|
947 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1Expires)) |
|
948 { |
|
949 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Expires failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1Expires ); |
|
950 User::Leave(KErrArgument); |
|
951 } |
|
952 |
|
953 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
954 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1Path)) |
|
955 { |
|
956 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Path failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1Path ); |
|
957 User::Leave(KErrArgument); |
|
958 } |
|
959 |
|
960 |
|
961 CleanupStack::PopAndDestroy(4,&cookie1Name); // cookie1Expires, cookie1Path, cookie1Value, cookie1Name |
|
962 ReleaseHeaders(); |
|
963 |
|
964 hdr = GetHeadersLC(); |
|
965 _LIT8(KEncodedCookie2, "PART_NUMBER=ROCKETLAUNCHER_0001; path=/"); |
|
966 _LIT8(KCookie2Name, "PART_NUMBER"); |
|
967 _LIT8(KCookie2Value, "ROCKETLAUNCHER_0001"); |
|
968 _LIT8(KCookie2Path, "/"); |
|
969 |
|
970 RString cookie2Name = iStrP.OpenStringL(KCookie2Name); |
|
971 CleanupClosePushL(cookie2Name); |
|
972 RString cookie2Value = iStrP.OpenStringL(KCookie2Value); |
|
973 CleanupClosePushL(cookie2Value); |
|
974 RStringF cookie2Path = iStrP.OpenFStringL(KCookie2Path); |
|
975 CleanupClosePushL(cookie2Path); |
|
976 |
|
977 hdr.SetRawFieldL(setCookie, KEncodedCookie2, KFieldSeparator); |
|
978 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
979 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie2Name)) |
|
980 { |
|
981 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Name failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie2Name ); |
|
982 User::Leave(KErrArgument); |
|
983 } |
|
984 |
|
985 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
986 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie2Value)) |
|
987 { |
|
988 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Value failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie2Value ); |
|
989 User::Leave(KErrArgument); |
|
990 } |
|
991 |
|
992 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
993 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie2Path)) |
|
994 { |
|
995 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Path failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie2Path ); |
|
996 User::Leave(KErrArgument); |
|
997 } |
|
998 |
|
999 |
|
1000 CleanupStack::PopAndDestroy(3, &cookie2Name); // cookie2Path, cookie2Value, cookie2Name; |
|
1001 ReleaseHeaders(); |
|
1002 |
|
1003 hdr = GetHeadersLC(); |
|
1004 _LIT8(KEncodedCookie3, " SHIPPING=FEDEX; path=/foo"); |
|
1005 _LIT8(KCookie3Name, "SHIPPING"); |
|
1006 _LIT8(KCookie3Value, "FEDEX"); |
|
1007 _LIT8(KCookie3Path, "/foo"); |
|
1008 |
|
1009 RString cookie3Name = iStrP.OpenStringL(KCookie3Name); |
|
1010 CleanupClosePushL(cookie3Name); |
|
1011 RString cookie3Value = iStrP.OpenStringL(KCookie3Value); |
|
1012 CleanupClosePushL(cookie3Value); |
|
1013 RStringF cookie3Path = iStrP.OpenFStringL(KCookie3Path); |
|
1014 CleanupClosePushL(cookie3Path); |
|
1015 hdr.SetRawFieldL(setCookie, KEncodedCookie3, KFieldSeparator); |
|
1016 |
|
1017 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
1018 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie3Name)) |
|
1019 { |
|
1020 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Name failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie3Name ); |
|
1021 User::Leave(KErrArgument); |
|
1022 } |
|
1023 |
|
1024 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
1025 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie3Value)) |
|
1026 { |
|
1027 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Value failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie3Value ); |
|
1028 User::Leave(KErrArgument); |
|
1029 } |
|
1030 |
|
1031 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
1032 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie3Path)) |
|
1033 { |
|
1034 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Path failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie3Path ); |
|
1035 User::Leave(KErrArgument); |
|
1036 } |
|
1037 |
|
1038 |
|
1039 CleanupStack::PopAndDestroy(3,&cookie3Name); //cookie3Path, cookie3Value, cookie3Name |
|
1040 ReleaseHeaders(); |
|
1041 iEngine->Utils().LogIt ( _L ("\nTestDecodeSetCookieL test success.")); |
|
1042 } |
|
1043 |
|
1044 void CHttpHdrCodecTest::TestDecodeSetCookie2L() |
|
1045 { |
|
1046 RStringF setCookie = iStrP.StringF(HTTP::ESetCookie2, RHTTPSession::GetTable()); |
|
1047 |
|
1048 RStringF cookieName = iStrP.StringF(HTTP::ECookieName, RHTTPSession::GetTable()); |
|
1049 RStringF cookieValue= iStrP.StringF(HTTP::ECookieValue, RHTTPSession::GetTable()); |
|
1050 RStringF cookiePath= iStrP.StringF(HTTP::EPath, RHTTPSession::GetTable()); |
|
1051 RStringF cookieMaxAge= iStrP.StringF(HTTP::EMaxAge, RHTTPSession::GetTable()); |
|
1052 RStringF cookiePort= iStrP.StringF(HTTP::ECookiePort, RHTTPSession::GetTable()); |
|
1053 RStringF cookieComment= iStrP.StringF(HTTP::EComment, RHTTPSession::GetTable()); |
|
1054 RStringF cookieCommentURL= iStrP.StringF(HTTP::ECommentURL, RHTTPSession::GetTable()); |
|
1055 RStringF cookieSecure= iStrP.StringF(HTTP::ESecure, RHTTPSession::GetTable()); |
|
1056 RStringF cookieDiscard= iStrP.StringF(HTTP::EDiscard, RHTTPSession::GetTable()); |
|
1057 |
|
1058 THTTPHdrVal hdrVal; |
|
1059 RHTTPHeaders hdr = GetHeadersLC(); |
|
1060 _LIT8(KEncodedCookie1, |
|
1061 "CUSTOMER=WILE_E_COYOTE; path=/; max-age=0; port=\"80,8000\"; comment=This is a cookie; commentURL=http://www.cookie.com; secure; discard"); |
|
1062 _LIT8(KCookie1Name, "CUSTOMER"); |
|
1063 _LIT8(KCookie1Value, "WILE_E_COYOTE"); |
|
1064 _LIT8(KCookie1Path, "/"); |
|
1065 _LIT8(KCookie1MaxAge, "0"); |
|
1066 _LIT8(KCookie1Port, "\"80,8000\""); |
|
1067 _LIT8(KCookie1Comment, "This is a cookie"); |
|
1068 _LIT8(KCookie1CommentURL, "http://www.cookie.com"); |
|
1069 |
|
1070 RString cookie1Name = iStrP.OpenStringL(KCookie1Name); |
|
1071 CleanupClosePushL(cookie1Name); |
|
1072 RString cookie1Value = iStrP.OpenStringL(KCookie1Value); |
|
1073 CleanupClosePushL(cookie1Value); |
|
1074 RStringF cookie1Path = iStrP.OpenFStringL(KCookie1Path); |
|
1075 CleanupClosePushL(cookie1Path); |
|
1076 RStringF cookie1MaxAge = iStrP.OpenFStringL(KCookie1MaxAge); |
|
1077 CleanupClosePushL(cookie1MaxAge); |
|
1078 RStringF cookie1Port = iStrP.OpenFStringL(KCookie1Port); |
|
1079 CleanupClosePushL(cookie1Port); |
|
1080 RStringF cookie1Comment = iStrP.OpenFStringL(KCookie1Comment); |
|
1081 CleanupClosePushL(cookie1Comment); |
|
1082 RStringF cookie1CommentURL = iStrP.OpenFStringL(KCookie1CommentURL); |
|
1083 CleanupClosePushL(cookie1CommentURL); |
|
1084 |
|
1085 hdr.SetRawFieldL(setCookie, KEncodedCookie1, KFieldSeparator); |
|
1086 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
1087 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Name)) |
|
1088 { |
|
1089 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Name & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie1Name ); |
|
1090 User::Leave(KErrArgument); |
|
1091 } |
|
1092 |
|
1093 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
1094 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Value)) |
|
1095 { |
|
1096 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Value & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie1Value ); |
|
1097 User::Leave(KErrArgument); |
|
1098 } |
|
1099 |
|
1100 User::LeaveIfError(hdr.GetParam(setCookie, cookieMaxAge, hdrVal)); |
|
1101 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1MaxAge)) |
|
1102 { |
|
1103 iEngine->Utils().LogIt ( _L("\nComparison of cookie1MaxAge & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1MaxAge ); |
|
1104 User::Leave(KErrArgument); |
|
1105 } |
|
1106 |
|
1107 User::LeaveIfError(hdr.GetParam(setCookie, cookiePort, hdrVal)); |
|
1108 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1Port)) |
|
1109 { |
|
1110 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Port & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1Port ); |
|
1111 User::Leave(KErrArgument); |
|
1112 } |
|
1113 |
|
1114 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
1115 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1Path)) |
|
1116 { |
|
1117 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Path & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1Path ); |
|
1118 User::Leave(KErrArgument); |
|
1119 } |
|
1120 |
|
1121 User::LeaveIfError(hdr.GetParam(setCookie, cookieComment, hdrVal)); |
|
1122 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1Comment)) |
|
1123 { |
|
1124 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Comment & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1Comment ); |
|
1125 User::Leave(KErrArgument); |
|
1126 } |
|
1127 |
|
1128 User::LeaveIfError(hdr.GetParam(setCookie, cookieCommentURL, hdrVal)); |
|
1129 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie1CommentURL)) |
|
1130 { |
|
1131 iEngine->Utils().LogIt ( _L("\nComparison of cookie1CommentURL & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie1CommentURL ); |
|
1132 User::Leave(KErrArgument); |
|
1133 } |
|
1134 |
|
1135 User::LeaveIfError(hdr.GetParam(setCookie, cookieSecure, hdrVal)); |
|
1136 User::LeaveIfError(hdr.GetParam(setCookie, cookieDiscard, hdrVal)); |
|
1137 |
|
1138 CleanupStack::PopAndDestroy(7,&cookie1Name); // cookie1CommentURL, cookie1Comment, cookie1Port, cookie1MaxAge, cookie1Path, cookie1Value, cookie1Name |
|
1139 ReleaseHeaders(); |
|
1140 |
|
1141 hdr = GetHeadersLC(); |
|
1142 _LIT8(KEncodedCookie2, "PART_NUMBER=ROCKETLAUNCHER_0001; path=/"); |
|
1143 _LIT8(KCookie2Name, "PART_NUMBER"); |
|
1144 _LIT8(KCookie2Value, "ROCKETLAUNCHER_0001"); |
|
1145 _LIT8(KCookie2Path, "/"); |
|
1146 |
|
1147 RString cookie2Name = iStrP.OpenStringL(KCookie2Name); |
|
1148 CleanupClosePushL(cookie2Name); |
|
1149 RString cookie2Value = iStrP.OpenStringL(KCookie2Value); |
|
1150 CleanupClosePushL(cookie2Value); |
|
1151 RStringF cookie2Path = iStrP.OpenFStringL(KCookie2Path); |
|
1152 CleanupClosePushL(cookie2Path); |
|
1153 |
|
1154 hdr.SetRawFieldL(setCookie, KEncodedCookie2, KFieldSeparator); |
|
1155 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
1156 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie2Name)) |
|
1157 { |
|
1158 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Name & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie2Name ); |
|
1159 User::Leave(KErrArgument); |
|
1160 } |
|
1161 |
|
1162 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
1163 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie2Value)) |
|
1164 { |
|
1165 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Value & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie2Value ); |
|
1166 User::Leave(KErrArgument); |
|
1167 } |
|
1168 |
|
1169 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
1170 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie2Path)) |
|
1171 { |
|
1172 iEngine->Utils().LogIt ( _L("\nComparison of cookie2Path & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie2Path ); |
|
1173 User::Leave(KErrArgument); |
|
1174 } |
|
1175 |
|
1176 |
|
1177 CleanupStack::PopAndDestroy(3, &cookie2Name); // cookie2Path, cookie2Value, cookie2Name; |
|
1178 ReleaseHeaders(); |
|
1179 |
|
1180 hdr = GetHeadersLC(); |
|
1181 _LIT8(KEncodedCookie3, " SHIPPING=FEDEX; path=/foo"); |
|
1182 _LIT8(KCookie3Name, "SHIPPING"); |
|
1183 _LIT8(KCookie3Value, "FEDEX"); |
|
1184 _LIT8(KCookie3Path, "/foo"); |
|
1185 |
|
1186 RString cookie3Name = iStrP.OpenStringL(KCookie3Name); |
|
1187 CleanupClosePushL(cookie3Name); |
|
1188 RString cookie3Value = iStrP.OpenStringL(KCookie3Value); |
|
1189 CleanupClosePushL(cookie3Value); |
|
1190 RStringF cookie3Path = iStrP.OpenFStringL(KCookie3Path); |
|
1191 CleanupClosePushL(cookie3Path); |
|
1192 hdr.SetRawFieldL(setCookie, KEncodedCookie3, KFieldSeparator); |
|
1193 |
|
1194 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
1195 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie3Name)) |
|
1196 { |
|
1197 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Name & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie3Name ); |
|
1198 User::Leave(KErrArgument); |
|
1199 } |
|
1200 |
|
1201 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
1202 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie3Value)) |
|
1203 { |
|
1204 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Value & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrVal, hdrVal.Str() == cookie3Value ); |
|
1205 User::Leave(KErrArgument); |
|
1206 } |
|
1207 |
|
1208 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
1209 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookie3Path)) |
|
1210 { |
|
1211 iEngine->Utils().LogIt ( _L("\nComparison of cookie3Path & hdr type failed -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookie3Path ); |
|
1212 User::Leave(KErrArgument); |
|
1213 } |
|
1214 |
|
1215 |
|
1216 CleanupStack::PopAndDestroy(3,&cookie3Name); //cookie3Path, cookie3Value, cookie3Name |
|
1217 ReleaseHeaders(); |
|
1218 |
|
1219 iEngine->Utils().LogIt ( _L ("\nTestDecodeSetCookie2L test success.")); |
|
1220 } |
|
1221 |
|
1222 void CHttpHdrCodecTest::TestDecodeSetCookie3L() |
|
1223 { |
|
1224 // Directly testing a defect fix INC036055. Parsing a string with three quotes. |
|
1225 // Testing ExtractNextTokenFromList which can be used for extracting cookies. |
|
1226 |
|
1227 _LIT8(KSeperator, "\\n"); |
|
1228 _LIT8(KCookieBuf, "quote1\"quote2\"quote3\""); |
|
1229 |
|
1230 TBuf8<0x100> buf(KCookieBuf()); |
|
1231 TPtrC8 ptr = buf.Ptr(); |
|
1232 TPtrC8 token; |
|
1233 |
|
1234 User::LeaveIfError(InetProtTextUtils::ExtractNextTokenFromList(ptr, token, KSeperator)); |
|
1235 iEngine->Utils().LogIt ( _L ("\nTestDecodeSetCookie3L test success.")); |
|
1236 } |
|
1237 |
|
1238 // INC070131 |
|
1239 void CHttpHdrCodecTest::TestDecodeSetCookie4L() |
|
1240 { |
|
1241 RStringF setCookie = iStrP.StringF(HTTP::ESetCookie,RHTTPSession::GetTable()); |
|
1242 |
|
1243 RStringF cookieName = iStrP.StringF(HTTP::ECookieName,RHTTPSession::GetTable()); |
|
1244 RStringF cookieValue= iStrP.StringF(HTTP::ECookieValue,RHTTPSession::GetTable()); |
|
1245 RStringF cookiePath= iStrP.StringF(HTTP::EPath,RHTTPSession::GetTable()); |
|
1246 RStringF cookieExpires= iStrP.StringF(HTTP::EExpires,RHTTPSession::GetTable()); |
|
1247 RStringF cookieDomain= iStrP.StringF(HTTP::EDomain,RHTTPSession::GetTable()); |
|
1248 |
|
1249 THTTPHdrVal hdrVal; |
|
1250 RHTTPHeaders hdr = GetHeadersLC(); |
|
1251 _LIT8(KEncodedCookie1, "id=33263187046453257 bb=141A11twQw_\"4totrK4ow| adv=; Domain=.bluestreak.com; expires=Friday 02-Oct-2015 05:50:28 GMT; path=/;"); |
|
1252 _LIT8(KCookie1Name, "id"); |
|
1253 _LIT8(KCookie1Value, "33263187046453257 bb=141A11twQw_\"4totrK4ow| adv="); |
|
1254 _LIT8(KCookieDomain, ".bluestreak.com"); |
|
1255 _LIT8(KCookieExpires, "Friday 02-Oct-2015 05:50:28 GMT"); |
|
1256 _LIT8(KCookiePath, "/"); |
|
1257 |
|
1258 RString cookie1Name = iStrP.OpenStringL(KCookie1Name); |
|
1259 CleanupClosePushL(cookie1Name); |
|
1260 RString cookie1Value = iStrP.OpenStringL(KCookie1Value); |
|
1261 CleanupClosePushL(cookie1Value); |
|
1262 RStringF cookieExpiresVal = iStrP.OpenFStringL(KCookieExpires); |
|
1263 CleanupClosePushL(cookieExpiresVal); |
|
1264 RStringF cookieDomainVal = iStrP.OpenFStringL(KCookieDomain); |
|
1265 CleanupClosePushL(cookieDomainVal); |
|
1266 RStringF cookiePathVal = iStrP.OpenFStringL(KCookiePath); |
|
1267 CleanupClosePushL(cookiePathVal); |
|
1268 |
|
1269 |
|
1270 hdr.SetRawFieldL(setCookie, KEncodedCookie1, KFieldSeparator); |
|
1271 User::LeaveIfError(hdr.GetParam(setCookie, cookieName, hdrVal)); |
|
1272 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Name)) |
|
1273 { |
|
1274 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Name failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie1Name ); |
|
1275 User::Leave(KErrArgument); |
|
1276 } |
|
1277 |
|
1278 User::LeaveIfError(hdr.GetParam(setCookie, cookieValue, hdrVal)); |
|
1279 if (!(hdrVal.Type() == THTTPHdrVal::KStrVal && hdrVal.Str() == cookie1Value)) |
|
1280 { |
|
1281 iEngine->Utils().LogIt ( _L("\nComparison of cookie1Value failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.Str() == cookie1Value ); |
|
1282 User::Leave(KErrArgument); |
|
1283 } |
|
1284 |
|
1285 User::LeaveIfError(hdr.GetParam(setCookie, cookieExpires, hdrVal)); |
|
1286 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookieExpiresVal)) |
|
1287 { |
|
1288 iEngine->Utils().LogIt ( _L("\nComparison of cookieExpires failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookieExpiresVal ); |
|
1289 User::Leave(KErrArgument); |
|
1290 } |
|
1291 |
|
1292 User::LeaveIfError(hdr.GetParam(setCookie, cookieDomain, hdrVal)); |
|
1293 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookieDomainVal)) |
|
1294 { |
|
1295 iEngine->Utils().LogIt ( _L("\nComparison of cookieExpires failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookieDomainVal ); |
|
1296 User::Leave(KErrArgument); |
|
1297 } |
|
1298 |
|
1299 User::LeaveIfError(hdr.GetParam(setCookie, cookiePath, hdrVal)); |
|
1300 if (!(hdrVal.Type() == THTTPHdrVal::KStrFVal && hdrVal.StrF() == cookiePathVal)) |
|
1301 { |
|
1302 iEngine->Utils().LogIt ( _L("\nComparison of cookieExpires failed. -> %d,%d"), hdrVal.Type() == THTTPHdrVal::KStrFVal, hdrVal.StrF() == cookiePathVal ); |
|
1303 User::Leave(KErrArgument); |
|
1304 } |
|
1305 |
|
1306 CleanupStack::PopAndDestroy( 5, &cookie1Name ); |
|
1307 ReleaseHeaders(); |
|
1308 iEngine->Utils().LogIt ( _L ("\nTestDecodeSetCookie4L test success.")); |
|
1309 } |
|
1310 |
|
1311 //test for DEF080697: Cookies: When sending a request to an origin server, Browser is not sending the |
|
1312 void CHttpHdrCodecTest::TestEncodeCookiePortL() |
|
1313 { |
|
1314 RHTTPHeaders hdr = GetHeadersLC(); |
|
1315 _LIT8(KEncodedCookie5, "$Version=112; CUSTOMER=WILE_E_COYOTE; $Path=/; $Port=\"80,8000\""); |
|
1316 _LIT8(KName1, "CUSTOMER"); |
|
1317 _LIT8(KValue1, "WILE_E_COYOTE"); |
|
1318 _LIT8(KCookiePort, "80,8000"); |
|
1319 _LIT8(KVersion, "112"); |
|
1320 _LIT8(KPath, "/"); |
|
1321 |
|
1322 RString name1 = iStrP.OpenStringL(KName1); |
|
1323 CleanupClosePushL(name1); |
|
1324 RString value1 = iStrP.OpenStringL(KValue1); |
|
1325 CleanupClosePushL(value1); |
|
1326 RStringF version = iStrP.OpenFStringL(KVersion); |
|
1327 CleanupClosePushL(version); |
|
1328 RStringF cookiePort1 = iStrP.OpenFStringL(KCookiePort); |
|
1329 CleanupClosePushL(cookiePort1); |
|
1330 RStringF path = iStrP.OpenFStringL(KPath); |
|
1331 CleanupClosePushL(path); |
|
1332 |
|
1333 |
|
1334 RStringF cookie = iStrP.StringF(HTTP::ECookie, RHTTPSession::GetTable()); |
|
1335 RStringF cookieName = iStrP.StringF(HTTP::ECookieName, RHTTPSession::GetTable()); |
|
1336 RStringF cookieValue = iStrP.StringF(HTTP::ECookieValue, RHTTPSession::GetTable()); |
|
1337 RStringF cookieVersion = iStrP.StringF(HTTP::EVersion, RHTTPSession::GetTable()); |
|
1338 RStringF cookiePort = iStrP.StringF(HTTP::ECookiePort, RHTTPSession::GetTable()); |
|
1339 RStringF cookiePath = iStrP.StringF(HTTP::EPath, RHTTPSession::GetTable()); |
|
1340 |
|
1341 |
|
1342 THTTPHdrVal hVal; |
|
1343 hdr.SetFieldL(cookie, THTTPHdrVal()); |
|
1344 |
|
1345 hVal.SetStrF(version); |
|
1346 hdr.SetParamL(cookie, cookieVersion, hVal, 0); |
|
1347 |
|
1348 hVal.SetStr(name1); |
|
1349 hdr.SetParamL(cookie, cookieName, hVal, 0); |
|
1350 |
|
1351 hVal.SetStr(value1); |
|
1352 hdr.SetParamL(cookie, cookieValue, hVal, 0); |
|
1353 |
|
1354 hVal.SetStrF(path); |
|
1355 hdr.SetParamL(cookie, cookiePath, hVal, 0); |
|
1356 |
|
1357 hVal.SetStrF(cookiePort1); |
|
1358 hdr.SetParamL(cookie, cookiePort, hVal, 0); |
|
1359 |
|
1360 TPtrC8 ota; |
|
1361 hdr.GetRawField(cookie, ota); |
|
1362 |
|
1363 if(ota.Compare(KEncodedCookie5) != 0) |
|
1364 { |
|
1365 TBuf < 1024> rawHeader16; |
|
1366 rawHeader16.Copy ( ota ); |
|
1367 |
|
1368 iEngine->Utils().LogIt ( _L("\nComparison of Encode Cookie Port failed. -> %S"), &rawHeader16 ); |
|
1369 User::Leave(KErrArgument); |
|
1370 } |
|
1371 |
|
1372 CleanupStack::PopAndDestroy(5, &name1); |
|
1373 ReleaseHeaders(); |
|
1374 } |
|
1375 |
|
1376 void CHttpHdrCodecTest::TestEncodeCacheControlL() |
|
1377 { |
|
1378 _LIT8(KEncodedCacheControlHeader, "public, no-cache=\"wibble,wobble\""); |
|
1379 _LIT8(KPublic, "public"); |
|
1380 _LIT8(KNoCache, "no-cache=\"wibble,wobble\""); |
|
1381 RStringF publicStr = iStrP.OpenFStringL(KPublic); |
|
1382 CleanupClosePushL(publicStr); |
|
1383 RStringF noCacheStr = iStrP.OpenFStringL(KNoCache); |
|
1384 CleanupClosePushL(noCacheStr); |
|
1385 |
|
1386 TPtrC8 rawHeader; |
|
1387 RHTTPHeaders hdr = GetHeadersLC(); |
|
1388 RStringF cc = iStrP.StringF(HTTP::ECacheControl,RHTTPSession::GetTable()); |
|
1389 hdr.SetFieldL(cc, THTTPHdrVal(publicStr)); |
|
1390 hdr.SetFieldL(cc, THTTPHdrVal(noCacheStr)); |
|
1391 hdr.GetRawField(cc, rawHeader); |
|
1392 if(rawHeader.Compare(KEncodedCacheControlHeader) != 0) |
|
1393 { |
|
1394 TBuf < 1024> rawHeader16; |
|
1395 rawHeader16.Copy ( rawHeader ); |
|
1396 |
|
1397 iEngine->Utils().LogIt ( _L("\nComparison of Cache Control header failed. -> %S"), &rawHeader16 ); |
|
1398 User::Leave(KErrArgument); |
|
1399 } |
|
1400 |
|
1401 ReleaseHeaders(); |
|
1402 |
|
1403 CleanupStack::PopAndDestroy(2,&publicStr); |
|
1404 |
|
1405 iEngine->Utils().LogIt ( _L ("\nTestEncodeCacheControlL test success.")); |
|
1406 } |
|
1407 |
|
1408 |
|
1409 void CHttpHdrCodecTest::TestEncodeDateL() |
|
1410 { |
|
1411 // the result we expect and that we will validate |
|
1412 // _LIT8(KDateVal1, "Sun, 06 Nov 2001 08:49:37 -0700"); // ota date header, rfc1123 format |
|
1413 |
|
1414 |
|
1415 // ReleaseHeaders(); |
|
1416 } |
|
1417 |
|
1418 |
|
1419 void CHttpHdrCodecTest::TestEncodeLocaleIndependentDateL() |
|
1420 { |
|
1421 |
|
1422 iEngine->Console().Printf(_L("\nTest encoding 'Custom Date' header for Locale independence")); |
|
1423 RHTTPHeaders hdr = GetHeadersLC(); |
|
1424 |
|
1425 _LIT8(KRefDate, "Wed, 08 Jun 1977 12:00:00 GMT"); |
|
1426 |
|
1427 TLocale locale; |
|
1428 |
|
1429 TDateTime refDate(1977, EJune, 7, 12, 00, 00, 0); // note offset of the date value by 1 |
|
1430 THTTPHdrVal refDateHdrVal(refDate); |
|
1431 THTTPHdrVal returnedDateHdrVal; |
|
1432 TPtrC8 rawDateJP; |
|
1433 TPtrC8 rawDateUSA; |
|
1434 TPtrC8 rawDateEU; |
|
1435 |
|
1436 //Sets the capability to change the date format |
|
1437 RProcess process; |
|
1438 TSecurityInfo info(process); |
|
1439 info.iCaps.AddCapability(ECapabilityWriteDeviceData); |
|
1440 |
|
1441 //Japanese Locale Settings |
|
1442 locale.SetDateFormat(EDateJapanese); |
|
1443 locale.Set(); |
|
1444 |
|
1445 RStringF japDateRStr = iStrP.OpenFStringL(_L8("JapanLocaleDate")); |
|
1446 CleanupClosePushL(japDateRStr); |
|
1447 hdr.SetFieldL(japDateRStr,refDateHdrVal); |
|
1448 |
|
1449 //Check if it encodes in the correct format |
|
1450 hdr.GetRawField(japDateRStr, rawDateJP); |
|
1451 if (rawDateJP.Compare(KRefDate())) |
|
1452 User::Leave(KErrCorrupt); |
|
1453 else |
|
1454 iEngine->Console().Printf(_L("Japanese, ")); |
|
1455 CleanupStack::PopAndDestroy(&japDateRStr); |
|
1456 |
|
1457 |
|
1458 //American Locale Settings |
|
1459 locale.SetDateFormat(EDateAmerican); |
|
1460 locale.Set(); |
|
1461 |
|
1462 RStringF usaDateRStr= iStrP.OpenFStringL(_L8("USALocaleDate")); |
|
1463 CleanupClosePushL(usaDateRStr); |
|
1464 hdr.SetFieldL(usaDateRStr,refDateHdrVal); |
|
1465 |
|
1466 |
|
1467 hdr.GetRawField(usaDateRStr, rawDateUSA); |
|
1468 if (rawDateUSA.Compare(KRefDate())) |
|
1469 User::Leave(KErrCorrupt); |
|
1470 else |
|
1471 iEngine->Console().Printf(_L("\nUSA, ")); |
|
1472 CleanupStack::PopAndDestroy(&usaDateRStr); |
|
1473 |
|
1474 |
|
1475 //European Locale Settings |
|
1476 locale.SetDateFormat(EDateEuropean); |
|
1477 locale.Set(); |
|
1478 |
|
1479 |
|
1480 RStringF euDateRStr= iStrP.OpenFStringL(_L8("EULocaleDate")); |
|
1481 CleanupClosePushL(euDateRStr); |
|
1482 hdr.SetFieldL(euDateRStr,refDateHdrVal); |
|
1483 |
|
1484 hdr.GetRawField(euDateRStr, rawDateEU); |
|
1485 if (rawDateEU.Compare(KRefDate())) |
|
1486 User::Leave(KErrCorrupt); |
|
1487 else |
|
1488 iEngine->Console().Printf(_L("\nEU formats independent\t")); |
|
1489 CleanupStack::PopAndDestroy(&euDateRStr); |
|
1490 |
|
1491 |
|
1492 ReleaseHeaders(); |
|
1493 iEngine->Utils().LogIt ( _L ("\nTestEncodeLocaleIndependentDateL test success")); |
|
1494 } |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 void CHttpHdrCodecTest::TestDecodeConnectionL() |
|
1500 { |
|
1501 _LIT8(KConnectionVal1, "close, value1, value2,, value3 , ,lastvalue"); // ota connection header |
|
1502 |
|
1503 // Open strings used in this test |
|
1504 RStringF connectionStr = iStrP.StringF(HTTP::EConnection,RHTTPSession::GetTable()); |
|
1505 RStringF pt1Str = iStrP.StringF(HTTP::EClose,RHTTPSession::GetTable()); |
|
1506 |
|
1507 RStringF pt2Str = iStrP.OpenFStringL(_L8("value1")); |
|
1508 CleanupClosePushL(pt2Str); |
|
1509 RStringF pt3Str = iStrP.OpenFStringL(_L8("value2")); |
|
1510 CleanupClosePushL(pt3Str); |
|
1511 RStringF pt4Str = iStrP.OpenFStringL(_L8("")); |
|
1512 CleanupClosePushL(pt4Str); |
|
1513 RStringF pt5Str = iStrP.OpenFStringL(_L8("value3")); |
|
1514 CleanupClosePushL(pt5Str); |
|
1515 RStringF pt6Str = iStrP.OpenFStringL(_L8("")); |
|
1516 CleanupClosePushL(pt6Str); |
|
1517 RStringF pt7Str = iStrP.OpenFStringL(_L8("lastvalue")); |
|
1518 CleanupClosePushL(pt7Str); |
|
1519 |
|
1520 iEngine->Console().Printf(_L("\nTest decoding 'Connection' header")); |
|
1521 RHTTPHeaders hdr = GetHeadersLC(); |
|
1522 |
|
1523 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
1524 hdr.SetRawFieldL(connectionStr, KConnectionVal1(), KFieldSeparator); |
|
1525 |
|
1526 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1527 THTTPHdrVal hVal; |
|
1528 User::LeaveIfError(hdr.GetField(connectionStr,0,hVal)); |
|
1529 |
|
1530 iEngine->Console().Printf(_L("\ncheck for correct number of parts")); |
|
1531 if(hdr.FieldPartsL(connectionStr) != 7) |
|
1532 { |
|
1533 iEngine->Utils().LogIt ( _L("\nComparison of Connection header failed.") ); |
|
1534 User::Leave(KErrArgument); |
|
1535 } |
|
1536 |
|
1537 |
|
1538 iEngine->Console().Printf(_L("\ndecode and check each header part")); |
|
1539 THTTPHdrVal vPt1; |
|
1540 User::LeaveIfError(hdr.GetField(connectionStr, 0, vPt1)); |
|
1541 THTTPHdrVal vPt2; |
|
1542 User::LeaveIfError(hdr.GetField(connectionStr, 1, vPt2)); |
|
1543 |
|
1544 THTTPHdrVal vPt3; |
|
1545 User::LeaveIfError(hdr.GetField(connectionStr, 2, vPt3)); |
|
1546 |
|
1547 THTTPHdrVal vPt4; |
|
1548 User::LeaveIfError(hdr.GetField(connectionStr, 3, vPt4)); |
|
1549 |
|
1550 THTTPHdrVal vPt5; |
|
1551 User::LeaveIfError(hdr.GetField(connectionStr, 4, vPt5)); |
|
1552 |
|
1553 THTTPHdrVal vPt6; |
|
1554 User::LeaveIfError(hdr.GetField(connectionStr, 5, vPt6)); |
|
1555 |
|
1556 THTTPHdrVal vPt7; User::LeaveIfError(hdr.GetField(connectionStr, 6, vPt7)); |
|
1557 |
|
1558 if( (vPt1.StrF() != pt1Str) || (vPt2.StrF() != pt2Str) || (vPt3.StrF() != pt3Str) |
|
1559 || (vPt4.StrF() != pt4Str) || (vPt5.StrF() != pt5Str) || (vPt6.StrF() != pt6Str) |
|
1560 || (vPt7.StrF() != pt7Str)) |
|
1561 { |
|
1562 iEngine->Utils().LogIt ( _L("\nHeader part checking failed. ") ); |
|
1563 User::Leave(KErrArgument); |
|
1564 } |
|
1565 |
|
1566 |
|
1567 ReleaseHeaders(); |
|
1568 CleanupStack::PopAndDestroy(6,&pt2Str); |
|
1569 iEngine->Utils().LogIt ( _L ("\nTestDecodeConnectionL test success.")); |
|
1570 } |
|
1571 |
|
1572 void CHttpHdrCodecTest::TestDecodeContentLengthL() |
|
1573 { |
|
1574 _LIT8(KContentLengthVal1, "123456"); // ota content length header |
|
1575 _LIT8(KContentLengthVal2, "123456.5"); |
|
1576 _LIT8(KContentLengthVal3, "0.5"); |
|
1577 |
|
1578 RHTTPHeaders hdr = GetHeadersLC(); |
|
1579 // |
|
1580 iEngine->Console().Printf(_L("\nTest decoding 'Content-Length' header")); |
|
1581 |
|
1582 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
1583 RStringF contLenStr = iStrP.OpenFStringL(_L8("Content-Length")); |
|
1584 hdr.SetRawFieldL(contLenStr, KContentLengthVal1(), KFieldSeparator); |
|
1585 |
|
1586 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1587 THTTPHdrVal hVal; |
|
1588 User::LeaveIfError(hdr.GetField(contLenStr,0,hVal)); |
|
1589 |
|
1590 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1591 THTTPHdrVal hdrVal; |
|
1592 User::LeaveIfError(hdr.GetField(contLenStr,0,hdrVal)); |
|
1593 if (hdr.FieldPartsL(contLenStr) != 1) |
|
1594 { |
|
1595 iEngine->Utils().LogIt ( _L("\nHeader contains no Content-Length header.") ); |
|
1596 User::Leave(KErrArgument); |
|
1597 } |
|
1598 |
|
1599 |
|
1600 THTTPHdrVal vPt1; |
|
1601 User::LeaveIfError(hdr.GetField(contLenStr, 0,vPt1)); |
|
1602 if (vPt1.Int() != 123456) |
|
1603 { |
|
1604 iEngine->Utils().LogIt ( _L("\nContent length value is not 123456 -> %d"), vPt1.Int() ); |
|
1605 User::Leave(KErrArgument); |
|
1606 } |
|
1607 |
|
1608 hdr.RemoveAllFields(); |
|
1609 hdr.SetRawFieldL(contLenStr, KContentLengthVal2(), KFieldSeparator); |
|
1610 |
|
1611 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1612 User::LeaveIfError(hdr.GetField(contLenStr,0,hVal)); |
|
1613 |
|
1614 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1615 User::LeaveIfError(hdr.GetField(contLenStr,0,hdrVal)); |
|
1616 if (hdr.FieldPartsL(contLenStr) != 1) |
|
1617 { |
|
1618 iEngine->Utils().LogIt ( _L("\nHeader contains no Content-Length header.") ); |
|
1619 User::Leave(KErrArgument); |
|
1620 } |
|
1621 |
|
1622 User::LeaveIfError(hdr.GetField(contLenStr, 0,vPt1)); |
|
1623 if (vPt1.Int() != 123456) |
|
1624 { |
|
1625 iEngine->Utils().LogIt ( _L("\nContent length value is not 123456 -> %d"), vPt1.Int() ); |
|
1626 User::Leave(KErrArgument); |
|
1627 } |
|
1628 |
|
1629 |
|
1630 hdr.RemoveAllFields(); |
|
1631 hdr.SetRawFieldL(contLenStr, KContentLengthVal3(), KFieldSeparator); |
|
1632 |
|
1633 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1634 User::LeaveIfError(hdr.GetField(contLenStr,0,hVal)); |
|
1635 |
|
1636 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1637 User::LeaveIfError(hdr.GetField(contLenStr,0,hdrVal)); |
|
1638 if (hdr.FieldPartsL(contLenStr) != 1) |
|
1639 { |
|
1640 iEngine->Utils().LogIt ( _L("\nHeader contains no Content-Length header.") ); |
|
1641 User::Leave(KErrArgument); |
|
1642 } |
|
1643 |
|
1644 User::LeaveIfError(hdr.GetField(contLenStr, 0,vPt1)); |
|
1645 if (vPt1.Int() != 0) |
|
1646 { |
|
1647 iEngine->Utils().LogIt ( _L("\nContent length value is not 0 -> %d"), vPt1.Int() ); |
|
1648 User::Leave(KErrArgument); |
|
1649 } |
|
1650 |
|
1651 ReleaseHeaders(); |
|
1652 iEngine->Utils().LogIt ( _L ("\nTestDecodeContentLengthL test success.")); |
|
1653 } |
|
1654 |
|
1655 void CHttpHdrCodecTest::TestDecodeContentTypeL() |
|
1656 { |
|
1657 _LIT8(KContentTypeVal1, "text/html; charset=\"iso-8859-1\""); // ota content type header |
|
1658 |
|
1659 RHTTPHeaders hdr = GetHeadersLC(); |
|
1660 // |
|
1661 iEngine->Console().Printf(_L("\nTest decoding 'Content-Type' header")); |
|
1662 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
1663 RStringF contTypeStr = iStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
1664 hdr.SetRawFieldL(contTypeStr, KContentTypeVal1(), KFieldSeparator); |
|
1665 |
|
1666 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1667 THTTPHdrVal hVal; |
|
1668 User::LeaveIfError(hdr.GetField(contTypeStr,0,hVal)); |
|
1669 |
|
1670 _LIT8(KMediaType, "text/html"); |
|
1671 _LIT8(KCharsetQuoted, "iso-8859-1"); |
|
1672 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1673 THTTPHdrVal hdrVal; |
|
1674 User::LeaveIfError(hdr.GetField(contTypeStr,0,hdrVal)); |
|
1675 |
|
1676 if(hdr.FieldPartsL(contTypeStr) != 1) |
|
1677 { |
|
1678 iEngine->Utils().LogIt ( _L("\nHeader contains no Content-Type header.") ); |
|
1679 User::Leave(KErrArgument); |
|
1680 } |
|
1681 |
|
1682 |
|
1683 if (!CompareStringL(hdrVal.StrF(), KMediaType())) |
|
1684 { |
|
1685 iEngine->Utils().LogIt ( _L("\nHeader not contains media type ( text/html) value.") ); |
|
1686 User::Leave(KErrArgument); |
|
1687 } |
|
1688 |
|
1689 |
|
1690 RStringF charsetStr = iStrP.StringF(HTTP::ECharset,RHTTPSession::GetTable()); |
|
1691 THTTPHdrVal paramVal; |
|
1692 |
|
1693 User::LeaveIfError(hdr.GetParam(contTypeStr, charsetStr, paramVal)); |
|
1694 if (!CompareStringL(paramVal.StrF(), KCharsetQuoted())) |
|
1695 { |
|
1696 iEngine->Utils().LogIt ( _L("Header not contains the charset value") ); |
|
1697 User::Leave(KErrArgument); |
|
1698 } |
|
1699 |
|
1700 |
|
1701 ReleaseHeaders(); |
|
1702 |
|
1703 iEngine->Utils().LogIt ( _L ("\nTestDecodeContentTypeL test success.")); |
|
1704 } |
|
1705 |
|
1706 void CHttpHdrCodecTest::TestDecodeContentTypeWithMultipleParametersL() |
|
1707 { |
|
1708 // ota content type header |
|
1709 _LIT8(KContentTypeVal1, "image/jpeg; fwd=\"no\"; ringtone=\"yes\""); |
|
1710 |
|
1711 RHTTPHeaders hdr = GetHeadersLC(); |
|
1712 // |
|
1713 iEngine->Console().Printf(_L("\nTest decoding 'Content-Type with multiple params' header")); |
|
1714 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
1715 RStringF contTypeStr = iStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
1716 hdr.SetRawFieldL(contTypeStr, KContentTypeVal1(), KFieldSeparator); |
|
1717 |
|
1718 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1719 THTTPHdrVal hVal; |
|
1720 User::LeaveIfError(hdr.GetField(contTypeStr,0,hVal)); |
|
1721 |
|
1722 _LIT8(KMediaType, "image/jpeg"); |
|
1723 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1724 THTTPHdrVal hdrVal; |
|
1725 User::LeaveIfError(hdr.GetField(contTypeStr,0,hdrVal)); |
|
1726 |
|
1727 if(hdr.FieldPartsL(contTypeStr) != 1) |
|
1728 User::Leave(KErrArgument); |
|
1729 |
|
1730 if (!CompareStringL(hdrVal.StrF(), KMediaType())) |
|
1731 User::Leave(KErrArgument); |
|
1732 |
|
1733 // Check 1st parameter |
|
1734 _LIT8(KFwdValue, "no"); |
|
1735 _LIT8( KFwdString, "fwd"); |
|
1736 RStringF fwdString = iStrP.OpenFStringL(KFwdString); |
|
1737 |
|
1738 THTTPHdrVal paramVal; |
|
1739 User::LeaveIfError(hdr.GetParam(contTypeStr, fwdString, paramVal)); |
|
1740 if (!CompareStringL(paramVal.StrF(), KFwdValue())) |
|
1741 User::Leave(KErrArgument); |
|
1742 fwdString.Close(); |
|
1743 |
|
1744 // Check 2nd parameter |
|
1745 _LIT8(KRingtoneValue, "yes"); |
|
1746 _LIT8( KRingtoneString, "ringtone"); |
|
1747 RStringF ringtoneString = iStrP.OpenFStringL(KRingtoneString); |
|
1748 |
|
1749 THTTPHdrVal paramVal2; |
|
1750 User::LeaveIfError(hdr.GetParam(contTypeStr, ringtoneString, paramVal2)); |
|
1751 if (!CompareStringL(paramVal2.StrF(), KRingtoneValue())) |
|
1752 User::Leave(KErrArgument); |
|
1753 ringtoneString.Close(); |
|
1754 |
|
1755 ReleaseHeaders(); |
|
1756 } |
|
1757 |
|
1758 // Test behaviour of ContentType decoding is when a parameter value is missing. |
|
1759 void CHttpHdrCodecTest::TestDecodeContentTypeMissingParameterL() |
|
1760 { |
|
1761 _LIT8(KContentTypeVal1, "text/html; charset="); // ota content type header with a parameter value missing |
|
1762 |
|
1763 RHTTPHeaders hdr = GetHeadersLC(); |
|
1764 // |
|
1765 iEngine->Console().Printf(_L("\nTest decoding 'Content-Type' header with a parameter missing")); |
|
1766 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
1767 RStringF contTypeStr = iStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
1768 hdr.SetRawFieldL(contTypeStr, KContentTypeVal1(), KFieldSeparator); |
|
1769 |
|
1770 iEngine->Console().Printf(_L("\ncheck for header presence")); |
|
1771 THTTPHdrVal hVal; |
|
1772 User::LeaveIfError(hdr.GetField(contTypeStr,0,hVal)); |
|
1773 |
|
1774 _LIT8(KMediaType, "text/html"); |
|
1775 _LIT8(KCharsetQuoted, ""); |
|
1776 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
1777 THTTPHdrVal hdrVal; |
|
1778 User::LeaveIfError(hdr.GetField(contTypeStr,0,hdrVal)); |
|
1779 |
|
1780 if(hdr.FieldPartsL(contTypeStr) != 1) |
|
1781 { |
|
1782 iEngine->Utils().LogIt ( _L("\nHeader contains no Content-Type header ( when a parameter value is missing ).")); |
|
1783 User::Leave(KErrArgument); |
|
1784 } |
|
1785 |
|
1786 |
|
1787 if (!CompareStringL(hdrVal.StrF(), KMediaType())) |
|
1788 { |
|
1789 iEngine->Utils().LogIt ( _L("\nHeader contains no media type ( when a parameter value is missing ) ") ); |
|
1790 User::Leave(KErrArgument); |
|
1791 } |
|
1792 |
|
1793 |
|
1794 RStringF charsetStr = iStrP.StringF(HTTP::ECharset,RHTTPSession::GetTable()); |
|
1795 THTTPHdrVal paramVal; |
|
1796 |
|
1797 User::LeaveIfError(hdr.GetParam(contTypeStr, charsetStr, paramVal)); |
|
1798 if (!CompareStringL(paramVal.StrF(), KCharsetQuoted())) |
|
1799 { |
|
1800 iEngine->Utils().LogIt ( _L("\nHeader contains no charset value ( when a parameter value is missing ) ") ); |
|
1801 User::Leave(KErrArgument); |
|
1802 } |
|
1803 |
|
1804 |
|
1805 ReleaseHeaders(); |
|
1806 iEngine->Utils().LogIt ( _L ("\nTestDecodeContentTypeMissingParameterL test success.")); |
|
1807 } |
|
1808 |
|
1809 void CHttpHdrCodecTest::TestDecodeDateL() |
|
1810 { |
|
1811 _LIT8(KDateVal1, "Sun, 06 Nov 2001 08:49:37 GMT"); // ota date header, rfc1123 format |
|
1812 _LIT8(KDateVal2, "Sunday, 06-Nov-01 08:49:37 GMT"); // ota date header, rfc850 format |
|
1813 _LIT8(KDateVal3, "Sun Nov 6 08:49:37 2001"); // ota date header, ansi asctime format |
|
1814 |
|
1815 |
|
1816 _LIT8(KDateVal4, "Mon, 07 Nov 2001 08:49:37 +1100"); // rfc1123 format with offset |
|
1817 _LIT8(KDateVal5, "Tue, 08 Nov 2001 08:49:37 PST"); // rfc1123 format timezone |
|
1818 _LIT8(KDateVal6, "Wed, 09 Nov 2001 08:49:37 ABC"); // rfc1123 format bogus timezone |
|
1819 _LIT8(KDateVal7, "Thu, 10 Nov 2001 08:49:37"); // rfc1123 format - no timezone |
|
1820 _LIT8(KDateVal8, "Fri, 10 Nov 2001 08:49:37 GMT"); // ota date header, rfc1123 format |
|
1821 _LIT8(KDateVal9, "Sunday, 06-Nov-01 08:49:37 -0200"); // rfc850 format with offset |
|
1822 |
|
1823 RHTTPHeaders hdr = GetHeadersLC(); |
|
1824 THTTPHdrVal dummy; |
|
1825 // |
|
1826 iEngine->Console().Printf(_L("\nTest decoding 'Date' header")); |
|
1827 RStringF dateStr = iStrP.StringF(HTTP::EDate,RHTTPSession::GetTable()); |
|
1828 TDateTime refDate(2001, ENovember, 5, 8, 49, 37, 0); // note offset of the date value by 1 |
|
1829 //Changed the Values due to Fix in InetProtUtils for Defect PDEF126657. |
|
1830 TDateTime refDate4(2001, ENovember, 5, 21, 49, 37, 0); // note offset of the date value by 1 |
|
1831 TDateTime refDate5(2001, ENovember, 7, 16, 49, 37, 0); // note offset of the date value by 1 |
|
1832 TDateTime refDate9(2001, ENovember, 5, 10, 49, 37, 0); // note offset of the date value by 1 |
|
1833 // |
|
1834 iEngine->Console().Printf(_L("\nDate format 1: add OTA data to header collection")); |
|
1835 hdr.SetRawFieldL(dateStr, KDateVal1(), KFieldSeparator); |
|
1836 |
|
1837 iEngine->Console().Printf(_L("\nDate format 1: check for header presence")); |
|
1838 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
1839 |
|
1840 |
|
1841 iEngine->Console().Printf(_L("\nDate format 1: decode header and check")); |
|
1842 if (hdr.FieldPartsL(dateStr) != 1) |
|
1843 { |
|
1844 iEngine->Utils().LogIt ( _L("\nDate format 1: checking failed.") ); |
|
1845 User::Leave(KErrArgument); |
|
1846 } |
|
1847 |
|
1848 |
|
1849 THTTPHdrVal datePt1; |
|
1850 User::LeaveIfError(hdr.GetField(dateStr, 0,datePt1)); |
|
1851 if (!CompareDate(datePt1.DateTime(), refDate)) |
|
1852 { |
|
1853 iEngine->Utils().LogIt ( _L("\nDate format 1 comparison failed.") ); |
|
1854 User::Leave(KErrArgument); |
|
1855 } |
|
1856 |
|
1857 // |
|
1858 iEngine->Console().Printf(_L("\nDate format 2: add OTA data to header collection")); |
|
1859 hdr.RemoveField(dateStr); |
|
1860 hdr.SetRawFieldL(dateStr, KDateVal2(), KFieldSeparator); |
|
1861 iEngine->Console().Printf(_L("\nDate format 2: check for header presence")); |
|
1862 |
|
1863 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
1864 |
|
1865 iEngine->Console().Printf(_L("\nDate format 2: decode header and check")); |
|
1866 if (hdr.FieldPartsL(dateStr) != 1) |
|
1867 { |
|
1868 iEngine->Utils().LogIt ( _L("\nDate format 2: checking failed" )); |
|
1869 User::Leave(KErrArgument); |
|
1870 } |
|
1871 |
|
1872 |
|
1873 THTTPHdrVal datePt2; |
|
1874 User::LeaveIfError(hdr.GetField(dateStr, 0, datePt2)); |
|
1875 if (!CompareDate(datePt2.DateTime(), refDate)) |
|
1876 { |
|
1877 iEngine->Utils().LogIt ( _L("\nDate format 2 comparison failed.") ); |
|
1878 User::Leave(KErrArgument); |
|
1879 } |
|
1880 |
|
1881 // |
|
1882 iEngine->Console().Printf(_L("\nDate format 3: add OTA data to header collection")); |
|
1883 hdr.RemoveField(dateStr); |
|
1884 hdr.SetRawFieldL(dateStr, KDateVal3(), KFieldSeparator); |
|
1885 |
|
1886 iEngine->Console().Printf(_L("\nDate format 3: check for header presence")); |
|
1887 iEngine->Console().Printf(_L("\nDate format 3: decode header and check")); |
|
1888 THTTPHdrVal hdrVal; |
|
1889 User::LeaveIfError(hdr.GetField(dateStr,0,hdrVal)); |
|
1890 if (hdr.FieldPartsL(dateStr) != 1) |
|
1891 { |
|
1892 iEngine->Utils().LogIt ( _L("\nDate format 3: checking failed" ) ); |
|
1893 User::Leave(KErrArgument); |
|
1894 } |
|
1895 |
|
1896 |
|
1897 THTTPHdrVal datePt3; |
|
1898 User::LeaveIfError(hdr.GetField(dateStr, 0,datePt3)); |
|
1899 if (!CompareDate(datePt3.DateTime(), refDate)) |
|
1900 { |
|
1901 iEngine->Utils().LogIt ( _L("\nDate format 3 comparison failed") ); |
|
1902 User::Leave(KErrArgument); |
|
1903 } |
|
1904 |
|
1905 |
|
1906 // |
|
1907 iEngine->Console().Printf(_L("\nDate format 4: add OTA data to header collection")); |
|
1908 hdr.RemoveField(dateStr); |
|
1909 hdr.SetRawFieldL(dateStr, KDateVal4(), KFieldSeparator); |
|
1910 |
|
1911 iEngine->Console().Printf(_L("\nDate format 4: check for header presence")); |
|
1912 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
1913 |
|
1914 iEngine->Console().Printf(_L("\nDate format 4: decode header and check")); |
|
1915 if (hdr.FieldPartsL(dateStr) != 1) |
|
1916 { |
|
1917 iEngine->Utils().LogIt ( _L("\nDate format 4: checking failed")); |
|
1918 User::Leave(KErrArgument); |
|
1919 } |
|
1920 |
|
1921 |
|
1922 THTTPHdrVal datePt4; |
|
1923 User::LeaveIfError(hdr.GetField(dateStr, 0,datePt4)); |
|
1924 if (!CompareDate(datePt4.DateTime(), refDate4)) |
|
1925 { |
|
1926 iEngine->Utils().LogIt ( _L("\nDate format 4 comparison failed") ); |
|
1927 User::Leave(KErrArgument); |
|
1928 } |
|
1929 |
|
1930 |
|
1931 // |
|
1932 iEngine->Console().Printf(_L("\nDate format 5: add OTA data to header collection")); |
|
1933 hdr.RemoveField(dateStr); |
|
1934 hdr.SetRawFieldL(dateStr, KDateVal5(), KFieldSeparator); |
|
1935 |
|
1936 iEngine->Console().Printf(_L("\nDate format 5: check for header presence")); |
|
1937 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
1938 |
|
1939 iEngine->Console().Printf(_L("\nDate format 5: decode header and check")); |
|
1940 if (hdr.FieldPartsL(dateStr) != 1) |
|
1941 { |
|
1942 iEngine->Utils().LogIt ( _L("\nDate format 5: checking failed ")); |
|
1943 User::Leave(KErrArgument); |
|
1944 } |
|
1945 |
|
1946 |
|
1947 THTTPHdrVal datePt5; |
|
1948 User::LeaveIfError(hdr.GetField(dateStr, 0,datePt5)); |
|
1949 if (!CompareDate(datePt5.DateTime(), refDate5)) |
|
1950 { |
|
1951 iEngine->Utils().LogIt ( _L("\nDate format 5 comparison failed") ); |
|
1952 User::Leave(KErrArgument); |
|
1953 } |
|
1954 |
|
1955 |
|
1956 // |
|
1957 iEngine->Console().Printf(_L("\nDate format 6: add OTA data to header collection")); |
|
1958 hdr.RemoveField(dateStr); |
|
1959 hdr.SetRawFieldL(dateStr, KDateVal6(), KFieldSeparator); |
|
1960 |
|
1961 iEngine->Console().Printf(_L("\nDate format 6: check for header presence")); |
|
1962 TInt err = hdr.GetField(dateStr,0,dummy); |
|
1963 if(err !=KErrCorrupt) |
|
1964 { |
|
1965 iEngine->Utils().LogIt ( _L("\nDate format 6: not a corrupt header.") ); |
|
1966 User::Leave(KErrArgument); |
|
1967 } |
|
1968 |
|
1969 |
|
1970 // |
|
1971 iEngine->Console().Printf(_L("\nDate format 7: add OTA data to header collection")); |
|
1972 hdr.RemoveField(dateStr); |
|
1973 hdr.SetRawFieldL(dateStr, KDateVal7(), KFieldSeparator); |
|
1974 |
|
1975 iEngine->Console().Printf(_L("\nDate format 7: check for header presence")); |
|
1976 err = hdr.GetField(dateStr,0,dummy); |
|
1977 if(err !=KErrCorrupt) |
|
1978 { |
|
1979 iEngine->Utils().LogIt ( _L("\nDate format 7: not a corrupt header") ); |
|
1980 User::Leave(KErrArgument); |
|
1981 } |
|
1982 |
|
1983 |
|
1984 // |
|
1985 iEngine->Console().Printf(_L("\nDate format 8: add OTA data to header collection")); |
|
1986 hdr.RemoveField(dateStr); |
|
1987 hdr.SetRawFieldL(dateStr, KDateVal8(), KFieldSeparator); |
|
1988 |
|
1989 iEngine->Console().Printf(_L("\nDate format 8: check for header presence")); |
|
1990 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
1991 |
|
1992 iEngine->Console().Printf(_L("\nDate format 8: decode header and check")); |
|
1993 if (hdr.FieldPartsL(dateStr) != 1) |
|
1994 { |
|
1995 iEngine->Utils().LogIt ( _L("\nDate format 8: checking failed")); |
|
1996 User::Leave(KErrArgument); |
|
1997 } |
|
1998 |
|
1999 // |
|
2000 iEngine->Console().Printf(_L("\nDate format 9: add OTA data to header collection")); |
|
2001 hdr.RemoveField(dateStr); |
|
2002 hdr.SetRawFieldL(dateStr, KDateVal9(), KFieldSeparator); |
|
2003 |
|
2004 iEngine->Console().Printf(_L("\nDate format 9: check for header presence")); |
|
2005 User::LeaveIfError(hdr.GetField(dateStr,0,dummy)); |
|
2006 |
|
2007 iEngine->Console().Printf(_L("\nDate format 9: decode header and check")); |
|
2008 if (hdr.FieldPartsL(dateStr) != 1) |
|
2009 { |
|
2010 iEngine->Utils().LogIt ( _L("\nDate format 9: checking failed ")); |
|
2011 User::Leave(KErrArgument); |
|
2012 } |
|
2013 |
|
2014 |
|
2015 THTTPHdrVal datePt9; |
|
2016 User::LeaveIfError(hdr.GetField(dateStr, 0,datePt9)); |
|
2017 if (!CompareDate(datePt9.DateTime(), refDate9)) |
|
2018 { |
|
2019 iEngine->Utils().LogIt ( _L("\nDate format 8 comparison failed.") ); |
|
2020 User::Leave(KErrArgument); |
|
2021 } |
|
2022 |
|
2023 |
|
2024 ReleaseHeaders(); |
|
2025 iEngine->Utils().LogIt ( _L ("\nTestDecodeDateL test success.")); |
|
2026 } |
|
2027 |
|
2028 void CHttpHdrCodecTest::TestDecodeServerL() |
|
2029 { |
|
2030 _LIT8(KServerVal1, "CERN/3.0 libwww/2.17"); // ota server header |
|
2031 |
|
2032 RHTTPHeaders hdr = GetHeadersLC(); |
|
2033 // |
|
2034 iEngine->Console().Printf(_L("\nTest decoding 'Server' header")); |
|
2035 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
2036 RStringF serverStr = iStrP.StringF(HTTP::EServer,RHTTPSession::GetTable()); |
|
2037 hdr.SetRawFieldL(serverStr, KServerVal1(), KFieldSeparator); |
|
2038 |
|
2039 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
2040 THTTPHdrVal hdrVal; |
|
2041 User::LeaveIfError(hdr.GetField(serverStr,0,hdrVal)); |
|
2042 if (hdr.FieldPartsL(serverStr) != 1) |
|
2043 { |
|
2044 iEngine->Utils().LogIt ( _L("Server header not present.") ); |
|
2045 User::Leave(KErrArgument); |
|
2046 } |
|
2047 |
|
2048 |
|
2049 THTTPHdrVal servPt; |
|
2050 User::LeaveIfError(hdr.GetField(serverStr, 0,servPt)); |
|
2051 if(!CompareStringL(servPt.StrF(), KServerVal1())) |
|
2052 { |
|
2053 iEngine->Utils().LogIt ( _L("Comparison of server header value failed.") ); |
|
2054 User::Leave(KErrArgument); |
|
2055 } |
|
2056 |
|
2057 ReleaseHeaders(); |
|
2058 iEngine->Utils().LogIt ( _L ("\nTestDecodeServerL test success.")); |
|
2059 } |
|
2060 |
|
2061 void CHttpHdrCodecTest::TestDecodeTransferEncodingL() |
|
2062 { |
|
2063 _LIT8(KTransferEncodingVal1, "chunked, extension1;param1=value1, extension2"); // ota transfer-encoding header |
|
2064 _LIT8(KTransferEncodingVal2, "identity, extension3;param3=value3, extension4"); // ota transfer-encoding header |
|
2065 |
|
2066 RHTTPHeaders hdr = GetHeadersLC(); |
|
2067 // |
|
2068 iEngine->Console().Printf(_L("\nTest decoding 'Transfer-Encoding' header")); |
|
2069 |
|
2070 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
2071 RStringF xferEncStr = iStrP.StringF(HTTP::ETransferEncoding,RHTTPSession::GetTable()); |
|
2072 hdr.SetRawFieldL(xferEncStr, KTransferEncodingVal1(), KFieldSeparator); |
|
2073 hdr.SetRawFieldL(xferEncStr, KTransferEncodingVal2(), KFieldSeparator); |
|
2074 |
|
2075 _LIT8(KPart1Val, "chunked"); |
|
2076 _LIT8(KPart2Val, "extension1"); |
|
2077 _LIT8(KPart3Val, "extension2"); |
|
2078 _LIT8(KPart4Val, "identity"); |
|
2079 _LIT8(KPart5Val, "extension3"); |
|
2080 _LIT8(KPart6Val, "extension4"); |
|
2081 _LIT8(KParam1Val, "value1"); |
|
2082 _LIT8(KParam3Val, "value3"); |
|
2083 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
2084 if (hdr.FieldPartsL(xferEncStr) != 6) |
|
2085 { |
|
2086 iEngine->Utils().LogIt ( _L("Transfer-Encoding check failed.") ); |
|
2087 User::Leave(KErrArgument); |
|
2088 } |
|
2089 |
|
2090 |
|
2091 THTTPHdrVal pt1Val; |
|
2092 User::LeaveIfError(hdr.GetField(xferEncStr, 0,pt1Val)); |
|
2093 if (!CompareStringL(pt1Val.StrF(), KPart1Val())) |
|
2094 { |
|
2095 iEngine->Utils().LogIt ( _L("Compairson of part1 value failed.") ); |
|
2096 User::Leave(KErrArgument); |
|
2097 } |
|
2098 |
|
2099 |
|
2100 THTTPHdrVal pt2Val; |
|
2101 User::LeaveIfError(hdr.GetField(xferEncStr, 1,pt2Val)); |
|
2102 if (!CompareStringL(pt2Val.StrF(), KPart2Val())) |
|
2103 { |
|
2104 iEngine->Utils().LogIt ( _L("Comparison of part2 value failed.")); |
|
2105 User::Leave(KErrArgument); |
|
2106 } |
|
2107 |
|
2108 |
|
2109 THTTPHdrVal pt3Val; |
|
2110 User::LeaveIfError(hdr.GetField(xferEncStr, 2,pt3Val)); |
|
2111 if (!CompareStringL(pt3Val.StrF(), KPart3Val())) |
|
2112 { |
|
2113 iEngine->Utils().LogIt ( _L("Comparison of part3 value failed.") ); |
|
2114 User::Leave(KErrArgument); |
|
2115 } |
|
2116 |
|
2117 |
|
2118 RStringF param1Str = iStrP.OpenFStringL(_L8("param1")); |
|
2119 THTTPHdrVal param1Val; |
|
2120 if (hdr.GetParam(xferEncStr, param1Str, param1Val, 1)) // part 1 is the extension1 part |
|
2121 { |
|
2122 iEngine->Utils().LogIt ( _L("param1 value is not present.") ); |
|
2123 User::Leave(KErrArgument); |
|
2124 } |
|
2125 |
|
2126 |
|
2127 if (!CompareStringL(param1Val.StrF(), KParam1Val())) |
|
2128 { |
|
2129 iEngine->Utils().LogIt ( _L("Param1 value is not matching.") ); |
|
2130 User::Leave(KErrArgument); |
|
2131 } |
|
2132 |
|
2133 |
|
2134 param1Str.Close(); |
|
2135 |
|
2136 |
|
2137 THTTPHdrVal pt4Val; |
|
2138 User::LeaveIfError(hdr.GetField(xferEncStr, 3,pt4Val)); |
|
2139 if (!CompareStringL(pt4Val.StrF(), KPart4Val())) |
|
2140 { |
|
2141 iEngine->Utils().LogIt ( _L("Comparison of part4 value (identity) is failed.")); |
|
2142 User::Leave(KErrArgument); |
|
2143 } |
|
2144 |
|
2145 |
|
2146 THTTPHdrVal pt5Val; |
|
2147 User::LeaveIfError(hdr.GetField(xferEncStr, 4,pt5Val)); |
|
2148 if (!CompareStringL(pt5Val.StrF(), KPart5Val())) |
|
2149 { |
|
2150 iEngine->Utils().LogIt ( _L("Comparison of part5 value (extension3) is failed") ); |
|
2151 User::Leave(KErrArgument); |
|
2152 } |
|
2153 |
|
2154 |
|
2155 THTTPHdrVal pt6Val; |
|
2156 User::LeaveIfError(hdr.GetField(xferEncStr, 5,pt6Val)); |
|
2157 if (!CompareStringL(pt6Val.StrF(), KPart6Val())) |
|
2158 { |
|
2159 iEngine->Utils().LogIt ( _L("Comparison of part6 value (extension4) is failed") ); |
|
2160 User::Leave(KErrArgument); |
|
2161 } |
|
2162 |
|
2163 |
|
2164 RStringF param3Str = iStrP.OpenFStringL(_L8("param3")); |
|
2165 THTTPHdrVal param3Val; |
|
2166 if (hdr.GetParam(xferEncStr, param3Str, param3Val, 4)) // part 4 is the extension3 part |
|
2167 { |
|
2168 iEngine->Utils().LogIt ( _L("param3 value is missing.") ); |
|
2169 User::Leave(KErrArgument); |
|
2170 } |
|
2171 |
|
2172 |
|
2173 if (!CompareStringL(param3Val.StrF(), KParam3Val())) |
|
2174 { |
|
2175 iEngine->Utils().LogIt ( _L("Comparison of part3 value is failed.") ); |
|
2176 User::Leave(KErrArgument); |
|
2177 } |
|
2178 |
|
2179 |
|
2180 param3Str.Close(); |
|
2181 |
|
2182 ReleaseHeaders(); |
|
2183 iEngine->Utils().LogIt ( _L ("\nTestDecodeTransferEncodingL test success.")); |
|
2184 } |
|
2185 |
|
2186 void CHttpHdrCodecTest::TestDecodeWWWAuthenticateL() |
|
2187 { |
|
2188 _LIT8(KWWWAuthenticateVal1, "Basic realm=\"basicrealm\", Digest realm=\"digestrealm\""); // ota WWW-Authenticate header |
|
2189 _LIT8(KWWWAuthenticateVal2, "Digest realm=\"digestrealm2\""); |
|
2190 _LIT8(KWWWAuthenticateVal3, "NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S=="); |
|
2191 _LIT8(KWWWAuthenticateVal4, "NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S="); |
|
2192 _LIT8(KWWWAuthenticateVal5, "NTLM"); |
|
2193 _LIT8(KWWWAuthenticateVal6, "NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S"); |
|
2194 |
|
2195 RHTTPHeaders hdr= GetHeadersLC(); |
|
2196 // |
|
2197 iEngine->Console().Printf(_L("\nTest decoding 'WWW-Authenticate' header")); |
|
2198 |
|
2199 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
2200 RStringF wwwAuthStr = iStrP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); |
|
2201 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal1(), KFieldSeparator); |
|
2202 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal2(), KFieldSeparator); |
|
2203 |
|
2204 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal3(), KFieldSeparator); |
|
2205 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal4(), KFieldSeparator); |
|
2206 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal5(), KFieldSeparator); |
|
2207 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal6(), KFieldSeparator); |
|
2208 hdr.SetRawFieldL(wwwAuthStr, KWWWAuthenticateVal2(), KFieldSeparator); |
|
2209 |
|
2210 _LIT8(KPart1Val, "Basic"); |
|
2211 _LIT8(KParam1, "realm"); |
|
2212 _LIT8(KParam1Val, "basicrealm"); |
|
2213 _LIT8(KPart2Val, "Digest"); |
|
2214 _LIT8(KParam2, "realm"); |
|
2215 _LIT8(KParam2Val, "digestrealm"); |
|
2216 _LIT8(KPart3Val, "Digest"); |
|
2217 _LIT8(KParam3, "realm"); |
|
2218 _LIT8(KParam3Val, "digestrealm2"); |
|
2219 _LIT8(KPart4689Val, "NTLM"); |
|
2220 _LIT8(KPart5Val, "TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S=="); |
|
2221 _LIT8(KPart7Val, "TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S="); |
|
2222 _LIT8(KPart10Val, "TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S"); |
|
2223 |
|
2224 |
|
2225 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
2226 TInt parts = hdr.FieldPartsL(wwwAuthStr); |
|
2227 if (hdr.FieldPartsL(wwwAuthStr) != 11) |
|
2228 { |
|
2229 iEngine->Utils().LogIt ( _L("WWW-Authenticate header is not present.") ); |
|
2230 User::Leave(KErrArgument); |
|
2231 } |
|
2232 |
|
2233 |
|
2234 // check first part |
|
2235 THTTPHdrVal pt1Val; |
|
2236 User::LeaveIfError(hdr.GetField(wwwAuthStr, 0,pt1Val)); |
|
2237 if(!CompareStringL(pt1Val.StrF(), KPart1Val())) |
|
2238 { |
|
2239 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part1 checking failed") ); |
|
2240 User::Leave(KErrArgument); |
|
2241 } |
|
2242 |
|
2243 |
|
2244 RStringF param1Str = iStrP.OpenFStringL(KParam1()); |
|
2245 THTTPHdrVal param1Val; |
|
2246 if (hdr.GetParam(wwwAuthStr, param1Str, param1Val, 0)) |
|
2247 { |
|
2248 iEngine->Utils().LogIt ( _L("Cannot get param1 value.") ); |
|
2249 User::Leave(KErrArgument); |
|
2250 } |
|
2251 |
|
2252 |
|
2253 if (!CompareStringL(param1Val.Str(), KParam1Val())) |
|
2254 { |
|
2255 iEngine->Utils().LogIt ( _L("Comparison of param1 value is failed.") ); |
|
2256 User::Leave(KErrArgument); |
|
2257 } |
|
2258 |
|
2259 param1Str.Close(); |
|
2260 |
|
2261 // check second part |
|
2262 THTTPHdrVal pt2Val; |
|
2263 User::LeaveIfError(hdr.GetField(wwwAuthStr, 1,pt2Val)); |
|
2264 if(!CompareStringL(pt2Val.StrF(), KPart2Val())) |
|
2265 { |
|
2266 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part2 checking failed.") ); |
|
2267 User::Leave(KErrArgument); |
|
2268 } |
|
2269 |
|
2270 THTTPHdrVal param2Val; |
|
2271 RStringF param2Str = iStrP.OpenFStringL(KParam2()); |
|
2272 if (hdr.GetParam(wwwAuthStr, param2Str, param2Val, 1)) |
|
2273 { |
|
2274 iEngine->Utils().LogIt ( _L("Cannot get param2 value.") ); |
|
2275 User::Leave(KErrArgument); |
|
2276 } |
|
2277 |
|
2278 if (!CompareStringL(param2Val.Str(), KParam2Val())) |
|
2279 { |
|
2280 iEngine->Utils().LogIt ( _L("Comparison of param2 value is failed.") ); |
|
2281 User::Leave(KErrArgument); |
|
2282 } |
|
2283 |
|
2284 param2Str.Close(); |
|
2285 |
|
2286 // check third part |
|
2287 THTTPHdrVal pt3Val; |
|
2288 User::LeaveIfError(hdr.GetField(wwwAuthStr, 2,pt3Val)); |
|
2289 if(!CompareStringL(pt3Val.StrF(), KPart3Val())) |
|
2290 { |
|
2291 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part3 checking failed.")); |
|
2292 User::Leave(KErrArgument); |
|
2293 } |
|
2294 |
|
2295 THTTPHdrVal param3Val; |
|
2296 RStringF param3Str = iStrP.OpenFStringL(KParam3()); |
|
2297 if (hdr.GetParam(wwwAuthStr, param3Str, param3Val, 2)) |
|
2298 { |
|
2299 iEngine->Utils().LogIt ( _L("Cannot get param3 value.") ); |
|
2300 User::Leave(KErrArgument); |
|
2301 } |
|
2302 |
|
2303 if (!CompareStringL(param3Val.Str(), KParam3Val())) |
|
2304 { |
|
2305 iEngine->Utils().LogIt ( _L("Comparison of param3 value is failed.") ); |
|
2306 User::Leave(KErrArgument); |
|
2307 } |
|
2308 |
|
2309 param3Str.Close(); |
|
2310 |
|
2311 THTTPHdrVal pt4Val; |
|
2312 User::LeaveIfError(hdr.GetField(wwwAuthStr, 3, pt4Val)); |
|
2313 if(!CompareStringL(pt4Val.StrF(), KPart4689Val())) |
|
2314 { |
|
2315 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part4 checking failed.")); |
|
2316 User::Leave(KErrArgument); |
|
2317 } |
|
2318 |
|
2319 THTTPHdrVal pt5Val; |
|
2320 User::LeaveIfError(hdr.GetField(wwwAuthStr, 4, pt5Val)); |
|
2321 if(!CompareStringL(pt5Val.StrF(), KPart5Val())) |
|
2322 { |
|
2323 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part5 checking failed.")); |
|
2324 User::Leave(KErrArgument); |
|
2325 } |
|
2326 |
|
2327 THTTPHdrVal pt6Val; |
|
2328 User::LeaveIfError(hdr.GetField(wwwAuthStr, 5, pt6Val)); |
|
2329 if(!CompareStringL(pt6Val.StrF(), KPart4689Val())) |
|
2330 { |
|
2331 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part6 checking failed.")); |
|
2332 User::Leave(KErrArgument); |
|
2333 } |
|
2334 |
|
2335 THTTPHdrVal pt7Val; |
|
2336 User::LeaveIfError(hdr.GetField(wwwAuthStr, 6, pt7Val)); |
|
2337 if(!CompareStringL(pt7Val.StrF(), KPart7Val())) |
|
2338 { |
|
2339 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part7 checking failed.")); |
|
2340 User::Leave(KErrArgument); |
|
2341 } |
|
2342 |
|
2343 THTTPHdrVal pt8Val; |
|
2344 User::LeaveIfError(hdr.GetField(wwwAuthStr, 7, pt8Val)); |
|
2345 if(!CompareStringL(pt8Val.StrF(), KPart4689Val())) |
|
2346 { |
|
2347 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part8 checking failed.")); |
|
2348 User::Leave(KErrArgument); |
|
2349 } |
|
2350 |
|
2351 THTTPHdrVal pt9Val; |
|
2352 User::LeaveIfError(hdr.GetField(wwwAuthStr, 8, pt9Val)); |
|
2353 if(!CompareStringL(pt9Val.StrF(), KPart4689Val())) |
|
2354 { |
|
2355 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part9 checking failed.")); |
|
2356 User::Leave(KErrArgument); |
|
2357 } |
|
2358 |
|
2359 THTTPHdrVal pt10Val; |
|
2360 User::LeaveIfError(hdr.GetField(wwwAuthStr, 9, pt10Val)); |
|
2361 if(!CompareStringL(pt10Val.StrF(), KPart10Val())) |
|
2362 { |
|
2363 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part10 checking failed.")); |
|
2364 User::Leave(KErrArgument); |
|
2365 } |
|
2366 |
|
2367 |
|
2368 THTTPHdrVal pt11Val; |
|
2369 User::LeaveIfError(hdr.GetField(wwwAuthStr, 10,pt11Val)); |
|
2370 if(!CompareStringL(pt11Val.StrF(), KPart2Val())) |
|
2371 { |
|
2372 iEngine->Utils().LogIt ( _L("WWW-Authenticate - part11 checking failed.") ); |
|
2373 User::Leave(KErrArgument); |
|
2374 } |
|
2375 |
|
2376 THTTPHdrVal param11Val; |
|
2377 RStringF param11Str = iStrP.OpenFStringL(KParam2()); |
|
2378 if (hdr.GetParam(wwwAuthStr, param11Str, param11Val, 1)) |
|
2379 { |
|
2380 iEngine->Utils().LogIt ( _L("Cannot get param11 value.") ); |
|
2381 User::Leave(KErrArgument); |
|
2382 } |
|
2383 |
|
2384 if (!CompareStringL(param11Val.Str(), KParam2Val())) |
|
2385 { |
|
2386 iEngine->Utils().LogIt ( _L("Comparison of param11 value is failed.") ); |
|
2387 User::Leave(KErrArgument); |
|
2388 } |
|
2389 |
|
2390 param11Str.Close(); |
|
2391 |
|
2392 ReleaseHeaders(); |
|
2393 iEngine->Utils().LogIt ( _L ("\nTestDecodeWWWAuthenticateL test success.")); |
|
2394 } |
|
2395 |
|
2396 void CHttpHdrCodecTest::TestDecodeCacheControlL() |
|
2397 { |
|
2398 |
|
2399 _LIT8(KCacheControlVal1, "private,no-cache,must-revalidate,max-age=100"); |
|
2400 _LIT8(KCacheControlVal2, "no-cache,max-stale=50"); |
|
2401 |
|
2402 _LIT8(KCacheControl1, "private"); |
|
2403 _LIT8(KCacheControl2, "no-cache"); |
|
2404 _LIT8(KCacheControl3, "must-revalidate"); |
|
2405 _LIT8(KCacheControlParam1, "max-age"); |
|
2406 _LIT8(KCacheControlParam2, "max-stale"); |
|
2407 |
|
2408 TInt maxAgeVal = 100; |
|
2409 TInt maxStaleVal = 50; |
|
2410 THTTPHdrVal maxAgeHdrVal(maxAgeVal); |
|
2411 THTTPHdrVal maxStaleHdrVal(maxStaleVal); |
|
2412 |
|
2413 RHTTPHeaders hdr = GetHeadersLC(); |
|
2414 |
|
2415 RStringF cacheControlStr = iStrP.StringF(HTTP::ECacheControl,RHTTPSession::GetTable()); |
|
2416 hdr.SetRawFieldL(cacheControlStr, KCacheControlVal1, KFieldSeparator); |
|
2417 hdr.SetRawFieldL(cacheControlStr, KCacheControlVal2, KFieldSeparator); |
|
2418 |
|
2419 if (hdr.FieldPartsL(cacheControlStr) != 6) |
|
2420 { |
|
2421 iEngine->Utils().LogIt ( _L("Cache control header doesn't have 6 parts.") ); |
|
2422 User::Leave(KErrArgument); |
|
2423 } |
|
2424 |
|
2425 THTTPHdrVal val; |
|
2426 User::LeaveIfError(hdr.GetField(cacheControlStr, 0,val)); |
|
2427 if(!CompareStringL(val.StrF(), KCacheControl1())) |
|
2428 { |
|
2429 iEngine->Utils().LogIt ( _L("Comparison of cache control1 value is failed.") ); |
|
2430 User::Leave(KErrArgument); |
|
2431 } |
|
2432 |
|
2433 User::LeaveIfError(hdr.GetField(cacheControlStr, 1,val)); |
|
2434 if(!CompareStringL(val.StrF(), KCacheControl2())) |
|
2435 { |
|
2436 iEngine->Utils().LogIt ( _L("Comparison of cache control2 value is failed.") ); |
|
2437 User::Leave(KErrArgument); |
|
2438 } |
|
2439 |
|
2440 User::LeaveIfError(hdr.GetField(cacheControlStr, 2,val)); |
|
2441 if(!CompareStringL(val.StrF(), KCacheControl3())) |
|
2442 { |
|
2443 iEngine->Utils().LogIt ( _L("Comparison of cache control3 value is failed.") ); |
|
2444 User::Leave(KErrArgument); |
|
2445 } |
|
2446 |
|
2447 RStringF param1Str = iStrP.OpenFStringL(KCacheControlParam1()); |
|
2448 CleanupClosePushL(param1Str); |
|
2449 THTTPHdrVal param1Val; |
|
2450 if(hdr.GetParam(cacheControlStr, param1Str, param1Val, 3)) |
|
2451 { |
|
2452 iEngine->Utils().LogIt ( _L("\ncacheControlStr - Cannot get param value.") ); |
|
2453 User::Leave(KErrArgument); |
|
2454 } |
|
2455 if(!CompareValue(param1Val.Int(),maxAgeVal)) |
|
2456 { |
|
2457 iEngine->Utils().LogIt ( _L("Comparison of cache control paramvalue is failed.") ); |
|
2458 User::Leave(KErrArgument); |
|
2459 } |
|
2460 CleanupStack::PopAndDestroy(¶m1Str); |
|
2461 |
|
2462 |
|
2463 User::LeaveIfError(hdr.GetField(cacheControlStr, 4,val)); |
|
2464 if(!CompareStringL(val.StrF(), KCacheControl2())) |
|
2465 { |
|
2466 iEngine->Utils().LogIt ( _L("Comparison of cache control5 value is failed.")); |
|
2467 User::Leave(KErrArgument); |
|
2468 } |
|
2469 |
|
2470 RStringF param2Str = iStrP.OpenFStringL(KCacheControlParam2()); |
|
2471 CleanupClosePushL(param2Str); |
|
2472 THTTPHdrVal param2Val; |
|
2473 if(hdr.GetParam(cacheControlStr, param2Str, param2Val,5)) |
|
2474 { |
|
2475 iEngine->Utils().LogIt ( _L("\ncacheControlStr - Cannot get param value.") ); |
|
2476 User::Leave(KErrArgument); |
|
2477 } |
|
2478 if(!CompareValue(param2Val.Int(),maxStaleVal)) |
|
2479 { |
|
2480 iEngine->Utils().LogIt ( _L("Comparison of cache control paramvalue is failed.") ); |
|
2481 User::Leave(KErrArgument); |
|
2482 } |
|
2483 CleanupStack::PopAndDestroy(¶m2Str); |
|
2484 |
|
2485 ReleaseHeaders(); |
|
2486 iEngine->Utils().LogIt ( _L ("\nTestDecodeCacheControlL test success.")); |
|
2487 } |
|
2488 |
|
2489 void CHttpHdrCodecTest::TestEncodeUpgradeL() |
|
2490 { |
|
2491 _LIT8(KUpgradeOTAVal1, "HTTP/2.0, SHTTP/1.3"); |
|
2492 |
|
2493 iEngine->Console().Printf(_L("\nTest encoding 'Upgrade' header")); |
|
2494 RHTTPHeaders hdr = GetHeadersLC(); |
|
2495 |
|
2496 RStringF http = iStrP.OpenFStringL(_L8("HTTP/2.0")); |
|
2497 CleanupClosePushL(http); |
|
2498 RStringF shttp = iStrP.OpenFStringL(_L8("SHTTP/1.3")); |
|
2499 CleanupClosePushL(shttp); |
|
2500 |
|
2501 RStringF upgradeStr = iStrP.StringF(HTTP::EUpgrade, RHTTPSession::GetTable()); |
|
2502 |
|
2503 THTTPHdrVal val(http); |
|
2504 THTTPHdrVal val2(shttp); |
|
2505 |
|
2506 hdr.SetFieldL(upgradeStr, val); |
|
2507 hdr.SetFieldL(upgradeStr, val2); |
|
2508 |
|
2509 TPtrC8 ota; |
|
2510 hdr.GetRawField(upgradeStr, ota); |
|
2511 if(ota.Compare(KUpgradeOTAVal1) != 0) |
|
2512 { |
|
2513 TBuf<512> temp; |
|
2514 temp.Copy(ota); |
|
2515 iEngine->Utils().LogIt(_L("\nComparison of Upgrade field value failed: %S"), &temp); |
|
2516 User::Leave(KErrArgument); |
|
2517 } |
|
2518 |
|
2519 CleanupStack::PopAndDestroy(2);//Pop and destroy http and shttp objects |
|
2520 ReleaseHeaders(); |
|
2521 iEngine->Utils().LogIt ( _L ("\nTestEncodeUpgradeL test success.")); |
|
2522 } |
|
2523 |
|
2524 void CHttpHdrCodecTest::TestDecodeUpgradeL() |
|
2525 { |
|
2526 _LIT8(KUpgradeHdrVal, "HTTP/2.0, SHTTP/1.3" ); |
|
2527 _LIT8(KHttpVal, "HTTP/2.0"); |
|
2528 _LIT8(KSHttpVal, "SHTTP/1.3"); |
|
2529 |
|
2530 RHTTPHeaders hdr = GetHeadersLC(); |
|
2531 // |
|
2532 iEngine->Console().Printf(_L("\nTest decoding 'Upgrade' header")); |
|
2533 iEngine->Console().Printf(_L("\nadd OTA data to header collection")); |
|
2534 |
|
2535 RStringF upgradeStr = iStrP.StringF(HTTP::EUpgrade,RHTTPSession::GetTable()); |
|
2536 |
|
2537 hdr.SetRawFieldL(upgradeStr, KUpgradeHdrVal(), KFieldSeparator); |
|
2538 |
|
2539 iEngine->Console().Printf(_L("\ndecode header and check")); |
|
2540 |
|
2541 if (hdr.FieldPartsL(upgradeStr) != 2)//Check if the Upgrade header has 2 values |
|
2542 { |
|
2543 iEngine->Utils().LogIt ( _L("Upgrade header not present.") ); |
|
2544 User::Leave(KErrArgument); |
|
2545 } |
|
2546 |
|
2547 //Get the HTTP/2.0 |
|
2548 THTTPHdrVal upgradePt; |
|
2549 User::LeaveIfError(hdr.GetField(upgradeStr, 0,upgradePt)); |
|
2550 |
|
2551 if(!CompareStringL(upgradePt.StrF(), KHttpVal())) |
|
2552 { |
|
2553 iEngine->Utils().LogIt ( _L("Comparison of Upgrade header value failed.") ); |
|
2554 User::Leave(KErrArgument); |
|
2555 } |
|
2556 |
|
2557 //Get the SHTTP/1.3 |
|
2558 THTTPHdrVal upgradePt2; |
|
2559 User::LeaveIfError(hdr.GetField(upgradeStr, 1, upgradePt2)); |
|
2560 |
|
2561 if(!CompareStringL(upgradePt2.StrF(), KSHttpVal())) |
|
2562 { |
|
2563 iEngine->Utils().LogIt ( _L("Comparison of Upgrade header value failed.") ); |
|
2564 User::Leave(KErrArgument); |
|
2565 } |
|
2566 |
|
2567 ReleaseHeaders(); |
|
2568 iEngine->Utils().LogIt ( _L ("\nTestDecodeUpgradeL test success.")); |
|
2569 } |
|
2570 |
|
2571 void CHttpHdrCodecTest::TestRoundTripConnectionL() |
|
2572 { |
|
2573 } |
|
2574 |
|
2575 void CHttpHdrCodecTest::TestRoundTripContentLengthL() |
|
2576 { |
|
2577 _LIT8(KContentLengthOTAVal, "25234"); |
|
2578 RHTTPHeaders hdr = GetHeadersLC(); |
|
2579 // |
|
2580 iEngine->Console().Printf(_L("\nTest round-tripping 'Content-Length' header")); |
|
2581 RStringF contLenStr = iStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()); |
|
2582 hdr.SetRawFieldL(contLenStr, KContentLengthOTAVal(), KFieldSeparator); |
|
2583 |
|
2584 // Force a decode by getting the 1st part of the value |
|
2585 THTTPHdrVal dummy; |
|
2586 User::LeaveIfError(hdr.GetField(contLenStr,0,dummy)); |
|
2587 |
|
2588 // Force a re-encode by getting the OTA data |
|
2589 TPtrC8 ota; |
|
2590 User::LeaveIfError(hdr.GetRawField(contLenStr, ota)); |
|
2591 |
|
2592 // This should look identical |
|
2593 if (ota.Compare(KContentLengthOTAVal()) != 0) |
|
2594 { |
|
2595 iEngine->Utils().LogIt ( _L("Content-Length field value is not matching.") ); |
|
2596 User::Leave(KErrArgument); |
|
2597 } |
|
2598 |
|
2599 // |
|
2600 ReleaseHeaders(); |
|
2601 iEngine->Utils().LogIt ( _L ("\nTestRoundTripContentLengthL test success.")); |
|
2602 } |
|
2603 |
|
2604 |
|
2605 void CHttpHdrCodecTest::TestRoundTripContentLength2L() |
|
2606 { |
|
2607 HBufC8* onesBuf = HBufC8::NewLC(4096); |
|
2608 TPtr8 ones = onesBuf->Des(); |
|
2609 |
|
2610 ones.AppendFill('1',4096); |
|
2611 _LIT8(KKnownToBeBad, "2147483649"); |
|
2612 |
|
2613 const TInt KNumberOfOnes[] = {9, 32, 255, 256, 4096}; |
|
2614 |
|
2615 for(TInt i=0;i<6;i++) |
|
2616 { |
|
2617 TPtrC8 use; |
|
2618 if(i<5) |
|
2619 { |
|
2620 ones.SetLength(KNumberOfOnes[i]); |
|
2621 use.Set(ones); |
|
2622 } |
|
2623 else |
|
2624 { |
|
2625 use.Set(KKnownToBeBad); |
|
2626 } |
|
2627 RHTTPHeaders hdr = GetHeadersLC(); |
|
2628 // |
|
2629 iEngine->Console().Printf(_L("\nTest round-tripping 'Content-Length' header")); |
|
2630 RStringF contLenStr = iStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()); |
|
2631 hdr.SetRawFieldL(contLenStr, use , KFieldSeparator); |
|
2632 |
|
2633 // Force a decode by getting the 1st part of the value, if possible. |
|
2634 THTTPHdrVal dummy; |
|
2635 hdr.GetField(contLenStr,0,dummy); // ignore errors |
|
2636 |
|
2637 // Force a re-encode by getting the OTA data |
|
2638 TPtrC8 ota; |
|
2639 User::LeaveIfError(hdr.GetRawField(contLenStr, ota)); |
|
2640 |
|
2641 |
|
2642 // This should look identical |
|
2643 if (ota.Compare(use) != 0) |
|
2644 { |
|
2645 iEngine->Utils().LogIt ( _L("Round-tripping Content-Length field is not matching.") ); |
|
2646 User::Leave(KErrArgument); |
|
2647 } |
|
2648 |
|
2649 // |
|
2650 ReleaseHeaders(); |
|
2651 } |
|
2652 |
|
2653 CleanupStack::PopAndDestroy(onesBuf); |
|
2654 iEngine->Utils().LogIt ( _L ("\nTestRoundTripContentLength2L test success.")); |
|
2655 } |
|
2656 |
|
2657 void CHttpHdrCodecTest::TestRoundTripContentTypeL() |
|
2658 { |
|
2659 _LIT8(KContentTypeOTAVal1, "text/plain"); |
|
2660 _LIT8(KContentTypeOTAVal2, "text/html; charset=us-ascii"); |
|
2661 _LIT8(KContentTypeOTAVal3, "text/vnd.wap/wml; charset=utf-8; wmlversion=12"); |
|
2662 RHTTPHeaders hdr = GetHeadersLC(); |
|
2663 // |
|
2664 iEngine->Console().Printf(_L("\nTest round-tripping 'Content-Type' header")); |
|
2665 RStringF contTypeStr = iStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
2666 hdr.SetRawFieldL(contTypeStr, KContentTypeOTAVal1(), KFieldSeparator); |
|
2667 |
|
2668 // Force a decode by getting the 1st part of the value |
|
2669 THTTPHdrVal dummy; |
|
2670 User::LeaveIfError(hdr.GetField(contTypeStr,0,dummy)); |
|
2671 |
|
2672 // Force a re-encode by getting the OTA data |
|
2673 TPtrC8 ota; |
|
2674 User::LeaveIfError(hdr.GetRawField(contTypeStr, ota)); |
|
2675 |
|
2676 // This should look identical |
|
2677 if (ota.Compare(KContentTypeOTAVal1()) != 0) |
|
2678 { |
|
2679 iEngine->Utils().LogIt ( _L("Content-Type value1 is not matching.") ); |
|
2680 User::Leave(KErrArgument); |
|
2681 } |
|
2682 |
|
2683 |
|
2684 // Now do the charset parameter test |
|
2685 hdr.RemoveField(contTypeStr); |
|
2686 hdr.SetRawFieldL(contTypeStr, KContentTypeOTAVal2(), KFieldSeparator); |
|
2687 User::LeaveIfError(hdr.GetField(contTypeStr,0,dummy)); |
|
2688 User::LeaveIfError(hdr.GetRawField(contTypeStr, ota)); |
|
2689 if (ota.Compare(KContentTypeOTAVal2()) != 0) |
|
2690 { |
|
2691 iEngine->Utils().LogIt ( _L("Content-Type value2 is not matching.") ); |
|
2692 User::Leave(KErrArgument); |
|
2693 } |
|
2694 |
|
2695 |
|
2696 // Now do the two parameter test |
|
2697 hdr.RemoveField(contTypeStr); |
|
2698 hdr.SetRawFieldL(contTypeStr, KContentTypeOTAVal3(), KFieldSeparator); |
|
2699 User::LeaveIfError(hdr.GetField(contTypeStr,0,dummy)); |
|
2700 User::LeaveIfError(hdr.GetRawField(contTypeStr, ota)); |
|
2701 if (ota.Compare(KContentTypeOTAVal3()) != 0) |
|
2702 { |
|
2703 iEngine->Utils().LogIt ( _L("Content-Type value3 is not matching.") ); |
|
2704 User::Leave(KErrArgument); |
|
2705 } |
|
2706 |
|
2707 // |
|
2708 ReleaseHeaders(); |
|
2709 iEngine->Utils().LogIt ( _L ("\nTestRoundTripContentTypeL test success.")); |
|
2710 } |
|
2711 |
|
2712 void CHttpHdrCodecTest::TestDecodeContentDispositionL() |
|
2713 { |
|
2714 iEngine->Utils().LogIt ( _L ("\nTesting decode functionality of Content-Disposition.")); |
|
2715 |
|
2716 _LIT8(KContentDisposition, "attachment;filename=Starshine"); |
|
2717 _LIT8(KContentDisposition1, "attachment;filename=Starshine;"); |
|
2718 _LIT8(KContentDisposition2, "attachment;filename=\"Starshine\""); |
|
2719 _LIT8(KContentDisposition3, "attachment;filename=\"Starshine\";"); |
|
2720 _LIT8(KContentDisposition4, "attachment;filename=\"Star;shine\""); |
|
2721 _LIT8(KContentDisposition5, "attachment;filename=\"Star;shine\";"); |
|
2722 _LIT8(KContentDisposition6, "attachment;filename=\"Star;shine\";date=\"25/06/1983\""); |
|
2723 _LIT8(KContentDisposition7, "attachment;filename=\"Star;shine\";date=\"25-06-1983\";"); |
|
2724 _LIT8(KContentDisposition8, "attachment;filename=Starshine;date=\"25-06-1983\""); |
|
2725 _LIT8(KContentDisposition9, "attachment;filename=Starshine;date=25-06-1983"); |
|
2726 |
|
2727 |
|
2728 RHTTPHeaders hdr= GetHeadersLC(); |
|
2729 |
|
2730 RStringF contentDisposition = iStrP.StringF(HTTP::EContentDisposition,RHTTPSession::GetTable()); |
|
2731 |
|
2732 _LIT8(KPart1Val, "attachment"); |
|
2733 _LIT8(KParam1, "filename"); |
|
2734 _LIT8(KParam2, "date"); |
|
2735 _LIT8(KParam1Val, "Starshine"); |
|
2736 _LIT8(KParam2Val, "Star;shine"); |
|
2737 _LIT8(KParam3Val, "25/06/1983"); |
|
2738 _LIT8(KParam4Val, "25-06-1983"); |
|
2739 |
|
2740 |
|
2741 // First Case. |
|
2742 hdr.SetRawFieldL(contentDisposition, KContentDisposition(), KFieldSeparator); |
|
2743 iEngine->Utils().LogIt ( _L ("\nCase 1:- Content-Disposition: attachment;filename=Starshine")); |
|
2744 THTTPHdrVal pt1Val; |
|
2745 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt1Val)); |
|
2746 if(!CompareStringL(pt1Val.StrF(), KPart1Val())) |
|
2747 { |
|
2748 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2749 User::Leave(KErrArgument); |
|
2750 } |
|
2751 |
|
2752 RStringF param1Str = iStrP.OpenFStringL(KParam1()); |
|
2753 CleanupClosePushL(param1Str); |
|
2754 THTTPHdrVal param1Val; |
|
2755 if (hdr.GetParam(contentDisposition, param1Str, param1Val, 0)) |
|
2756 { |
|
2757 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2758 User::Leave(KErrArgument); |
|
2759 } |
|
2760 |
|
2761 if (!CompareStringL(param1Val.StrF(), KParam1Val())) |
|
2762 { |
|
2763 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2764 User::Leave(KErrArgument); |
|
2765 } |
|
2766 |
|
2767 CleanupStack::PopAndDestroy(¶m1Str); |
|
2768 hdr.RemoveField( contentDisposition ); |
|
2769 |
|
2770 // Second Case. |
|
2771 iEngine->Utils().LogIt ( _L ("\nCase 2:- Content-Disposition: attachment;filename=Starshine;")); |
|
2772 hdr.SetRawFieldL(contentDisposition, KContentDisposition1(), KFieldSeparator); |
|
2773 THTTPHdrVal pt2Val; |
|
2774 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt2Val)); |
|
2775 if(!CompareStringL(pt2Val.StrF(), KPart1Val())) |
|
2776 { |
|
2777 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2778 User::Leave(KErrArgument); |
|
2779 } |
|
2780 |
|
2781 RStringF param2Str = iStrP.OpenFStringL(KParam1()); |
|
2782 CleanupClosePushL(param2Str); |
|
2783 THTTPHdrVal param2Val; |
|
2784 if (hdr.GetParam(contentDisposition, param2Str, param2Val, 0)) |
|
2785 { |
|
2786 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2787 User::Leave(KErrArgument); |
|
2788 } |
|
2789 |
|
2790 if (!CompareStringL(param2Val.StrF(), KParam1Val())) |
|
2791 { |
|
2792 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2793 User::Leave(KErrArgument); |
|
2794 } |
|
2795 |
|
2796 CleanupStack::PopAndDestroy(¶m2Str); |
|
2797 hdr.RemoveField( contentDisposition ); |
|
2798 |
|
2799 // Third Case. |
|
2800 iEngine->Utils().LogIt ( _L ("\nCase 3:- Content-Disposition: attachment;filename=\"Starshine\"")); |
|
2801 hdr.SetRawFieldL(contentDisposition, KContentDisposition2(), KFieldSeparator); |
|
2802 THTTPHdrVal pt3Val; |
|
2803 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt3Val)); |
|
2804 if(!CompareStringL(pt3Val.StrF(), KPart1Val())) |
|
2805 { |
|
2806 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2807 User::Leave(KErrArgument); |
|
2808 } |
|
2809 |
|
2810 RStringF param3Str = iStrP.OpenFStringL(KParam1()); |
|
2811 CleanupClosePushL(param3Str); |
|
2812 THTTPHdrVal param3Val; |
|
2813 if (hdr.GetParam(contentDisposition, param3Str, param3Val, 0)) |
|
2814 { |
|
2815 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2816 User::Leave(KErrArgument); |
|
2817 } |
|
2818 |
|
2819 if (!CompareStringL(param3Val.StrF(), KParam1Val())) |
|
2820 { |
|
2821 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2822 User::Leave(KErrArgument); |
|
2823 } |
|
2824 |
|
2825 CleanupStack::PopAndDestroy(¶m3Str); |
|
2826 hdr.RemoveField( contentDisposition ); |
|
2827 |
|
2828 // Fourth Case. |
|
2829 iEngine->Utils().LogIt ( _L ("\nCase 4:- Content-Disposition: attachment;filename=\"Starshine\";")); |
|
2830 hdr.SetRawFieldL(contentDisposition, KContentDisposition3(), KFieldSeparator); |
|
2831 THTTPHdrVal pt4Val; |
|
2832 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt4Val)); |
|
2833 if(!CompareStringL(pt4Val.StrF(), KPart1Val())) |
|
2834 { |
|
2835 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2836 User::Leave(KErrArgument); |
|
2837 } |
|
2838 |
|
2839 RStringF param4Str = iStrP.OpenFStringL(KParam1()); |
|
2840 CleanupClosePushL(param4Str); |
|
2841 THTTPHdrVal param4Val; |
|
2842 if (hdr.GetParam(contentDisposition, param4Str, param4Val, 0)) |
|
2843 { |
|
2844 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2845 User::Leave(KErrArgument); |
|
2846 } |
|
2847 |
|
2848 if (!CompareStringL(param4Val.StrF(), KParam1Val())) |
|
2849 { |
|
2850 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2851 User::Leave(KErrArgument); |
|
2852 } |
|
2853 |
|
2854 CleanupStack::PopAndDestroy(¶m4Str); |
|
2855 hdr.RemoveField( contentDisposition ); |
|
2856 |
|
2857 // Fifth Case. |
|
2858 iEngine->Utils().LogIt ( _L ("\nCase 5:- Content-Disposition: attachment;filename=\"Star;shine\"")); |
|
2859 hdr.SetRawFieldL(contentDisposition, KContentDisposition4(), KFieldSeparator); |
|
2860 THTTPHdrVal pt5Val; |
|
2861 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt5Val)); |
|
2862 if(!CompareStringL(pt5Val.StrF(), KPart1Val())) |
|
2863 { |
|
2864 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2865 User::Leave(KErrArgument); |
|
2866 } |
|
2867 |
|
2868 RStringF param5Str = iStrP.OpenFStringL(KParam1()); |
|
2869 CleanupClosePushL(param5Str); |
|
2870 THTTPHdrVal param5Val; |
|
2871 if (hdr.GetParam(contentDisposition, param5Str, param5Val, 0)) |
|
2872 { |
|
2873 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2874 User::Leave(KErrArgument); |
|
2875 } |
|
2876 |
|
2877 if (!CompareStringL(param5Val.StrF(), KParam2Val())) |
|
2878 { |
|
2879 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2880 User::Leave(KErrArgument); |
|
2881 } |
|
2882 |
|
2883 CleanupStack::PopAndDestroy(¶m5Str); |
|
2884 hdr.RemoveField( contentDisposition ); |
|
2885 |
|
2886 // Sixth Case. |
|
2887 iEngine->Utils().LogIt ( _L ("\nCase 6:- Content-Disposition: attachment;filename=\"Star;shine\";")); |
|
2888 hdr.SetRawFieldL(contentDisposition, KContentDisposition5(), KFieldSeparator); |
|
2889 THTTPHdrVal pt6Val; |
|
2890 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt6Val)); |
|
2891 if(!CompareStringL(pt6Val.StrF(), KPart1Val())) |
|
2892 { |
|
2893 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2894 User::Leave(KErrArgument); |
|
2895 } |
|
2896 |
|
2897 RStringF param6Str = iStrP.OpenFStringL(KParam1()); |
|
2898 CleanupClosePushL(param6Str); |
|
2899 THTTPHdrVal param6Val; |
|
2900 if (hdr.GetParam(contentDisposition, param6Str, param6Val, 0)) |
|
2901 { |
|
2902 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2903 User::Leave(KErrArgument); |
|
2904 } |
|
2905 |
|
2906 if (!CompareStringL(param6Val.StrF(), KParam2Val())) |
|
2907 { |
|
2908 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2909 User::Leave(KErrArgument); |
|
2910 } |
|
2911 |
|
2912 CleanupStack::PopAndDestroy(¶m6Str); |
|
2913 hdr.RemoveField( contentDisposition ); |
|
2914 |
|
2915 // Seventh Case. |
|
2916 iEngine->Utils().LogIt ( _L ("\nCase 7:- Content-Disposition: attachment;filename=\"Star;shine\";date=\"25/06/1983\"")); |
|
2917 hdr.SetRawFieldL(contentDisposition, KContentDisposition6(), KFieldSeparator); |
|
2918 THTTPHdrVal pt7Val; |
|
2919 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt7Val)); |
|
2920 if(!CompareStringL(pt7Val.StrF(), KPart1Val())) |
|
2921 { |
|
2922 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2923 User::Leave(KErrArgument); |
|
2924 } |
|
2925 |
|
2926 RStringF param7Str = iStrP.OpenFStringL(KParam1()); |
|
2927 CleanupClosePushL(param7Str); |
|
2928 THTTPHdrVal param7Val; |
|
2929 if (hdr.GetParam(contentDisposition, param7Str, param7Val, 0)) |
|
2930 { |
|
2931 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2932 User::Leave(KErrArgument); |
|
2933 } |
|
2934 |
|
2935 if (!CompareStringL(param7Val.StrF(), KParam2Val())) |
|
2936 { |
|
2937 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2938 User::Leave(KErrArgument); |
|
2939 } |
|
2940 |
|
2941 CleanupStack::PopAndDestroy(¶m7Str); |
|
2942 |
|
2943 RStringF param8Str = iStrP.OpenFStringL(KParam2()); |
|
2944 CleanupClosePushL(param8Str); |
|
2945 THTTPHdrVal param8Val; |
|
2946 if (hdr.GetParam(contentDisposition, param8Str, param8Val, 0)) |
|
2947 { |
|
2948 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param2 value.") ); |
|
2949 User::Leave(KErrArgument); |
|
2950 } |
|
2951 |
|
2952 if (!CompareStringL(param8Val.StrF(), KParam3Val())) |
|
2953 { |
|
2954 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param2 checking failed.") ); |
|
2955 User::Leave(KErrArgument); |
|
2956 } |
|
2957 |
|
2958 CleanupStack::PopAndDestroy(¶m8Str); |
|
2959 |
|
2960 hdr.RemoveField( contentDisposition ); |
|
2961 |
|
2962 |
|
2963 // Eight Case. |
|
2964 iEngine->Utils().LogIt ( _L ("\nCase 8:- Content-Disposition: attachment;filename=\"Star;shine\";date=\"25-06-1983\";")); |
|
2965 hdr.SetRawFieldL(contentDisposition, KContentDisposition7(), KFieldSeparator); |
|
2966 THTTPHdrVal pt8Val; |
|
2967 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt8Val)); |
|
2968 if(!CompareStringL(pt8Val.StrF(), KPart1Val())) |
|
2969 { |
|
2970 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
2971 User::Leave(KErrArgument); |
|
2972 } |
|
2973 |
|
2974 RStringF param9Str = iStrP.OpenFStringL(KParam1()); |
|
2975 CleanupClosePushL(param9Str); |
|
2976 THTTPHdrVal param9Val; |
|
2977 if (hdr.GetParam(contentDisposition, param9Str, param9Val, 0)) |
|
2978 { |
|
2979 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
2980 User::Leave(KErrArgument); |
|
2981 } |
|
2982 |
|
2983 if (!CompareStringL(param9Val.StrF(), KParam2Val())) |
|
2984 { |
|
2985 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
2986 User::Leave(KErrArgument); |
|
2987 } |
|
2988 |
|
2989 CleanupStack::PopAndDestroy(¶m9Str); |
|
2990 |
|
2991 RStringF param10Str = iStrP.OpenFStringL(KParam2()); |
|
2992 CleanupClosePushL(param10Str); |
|
2993 THTTPHdrVal param10Val; |
|
2994 if (hdr.GetParam(contentDisposition, param10Str, param10Val, 0)) |
|
2995 { |
|
2996 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param2 value.") ); |
|
2997 User::Leave(KErrArgument); |
|
2998 } |
|
2999 |
|
3000 if (!CompareStringL(param10Val.StrF(), KParam4Val())) |
|
3001 { |
|
3002 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param2 checking failed.") ); |
|
3003 User::Leave(KErrArgument); |
|
3004 } |
|
3005 |
|
3006 CleanupStack::PopAndDestroy(¶m10Str); |
|
3007 hdr.RemoveField( contentDisposition ); |
|
3008 |
|
3009 // Ninth case |
|
3010 iEngine->Utils().LogIt ( _L ("\nCase 9:- Content-Disposition: attachment;filename=Starshine;date=\"25-06-1983\"")); |
|
3011 hdr.SetRawFieldL(contentDisposition, KContentDisposition8(), KFieldSeparator); |
|
3012 THTTPHdrVal pt9Val; |
|
3013 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt9Val)); |
|
3014 if(!CompareStringL(pt9Val.StrF(), KPart1Val())) |
|
3015 { |
|
3016 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
3017 User::Leave(KErrArgument); |
|
3018 } |
|
3019 |
|
3020 RStringF param11Str = iStrP.OpenFStringL(KParam1()); |
|
3021 CleanupClosePushL(param11Str); |
|
3022 THTTPHdrVal param11Val; |
|
3023 if (hdr.GetParam(contentDisposition, param11Str, param11Val, 0)) |
|
3024 { |
|
3025 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
3026 User::Leave(KErrArgument); |
|
3027 } |
|
3028 |
|
3029 if (!CompareStringL(param11Val.StrF(), KParam1Val())) |
|
3030 { |
|
3031 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
3032 User::Leave(KErrArgument); |
|
3033 } |
|
3034 |
|
3035 CleanupStack::PopAndDestroy(¶m11Str); |
|
3036 |
|
3037 RStringF param12Str = iStrP.OpenFStringL(KParam2()); |
|
3038 CleanupClosePushL(param12Str); |
|
3039 THTTPHdrVal param12Val; |
|
3040 if (hdr.GetParam(contentDisposition, param12Str, param12Val, 0)) |
|
3041 { |
|
3042 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param2 value.") ); |
|
3043 User::Leave(KErrArgument); |
|
3044 } |
|
3045 |
|
3046 if (!CompareStringL(param12Val.StrF(), KParam4Val())) |
|
3047 { |
|
3048 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param2 checking failed.") ); |
|
3049 User::Leave(KErrArgument); |
|
3050 } |
|
3051 |
|
3052 CleanupStack::PopAndDestroy(¶m12Str); |
|
3053 hdr.RemoveField( contentDisposition ); |
|
3054 //Tenth case |
|
3055 iEngine->Utils().LogIt ( _L ("\nCase 10:- Content-Disposition: attachment;filename=Starshine;date=\"25-06-1983\"")); |
|
3056 hdr.SetRawFieldL(contentDisposition, KContentDisposition9(), KFieldSeparator); |
|
3057 THTTPHdrVal pt10Val; |
|
3058 User::LeaveIfError(hdr.GetField(contentDisposition, 0,pt10Val)); |
|
3059 if(!CompareStringL(pt10Val.StrF(), KPart1Val())) |
|
3060 { |
|
3061 iEngine->Utils().LogIt ( _L("\nContent-Disposition - part1 checking failed") ); |
|
3062 User::Leave(KErrArgument); |
|
3063 } |
|
3064 |
|
3065 RStringF param13Str = iStrP.OpenFStringL(KParam1()); |
|
3066 CleanupClosePushL(param13Str); |
|
3067 THTTPHdrVal param13Val; |
|
3068 if (hdr.GetParam(contentDisposition, param13Str, param13Val, 0)) |
|
3069 { |
|
3070 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param1 value.") ); |
|
3071 User::Leave(KErrArgument); |
|
3072 } |
|
3073 |
|
3074 if (!CompareStringL(param13Val.StrF(), KParam1Val())) |
|
3075 { |
|
3076 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param1 checking failed.") ); |
|
3077 User::Leave(KErrArgument); |
|
3078 } |
|
3079 |
|
3080 CleanupStack::PopAndDestroy(¶m13Str); |
|
3081 |
|
3082 RStringF param14Str = iStrP.OpenFStringL(KParam2()); |
|
3083 CleanupClosePushL(param14Str); |
|
3084 THTTPHdrVal param14Val; |
|
3085 if (hdr.GetParam(contentDisposition, param14Str, param14Val, 0)) |
|
3086 { |
|
3087 iEngine->Utils().LogIt ( _L("\nContent-Disposition - Cannot get param2 value.") ); |
|
3088 User::Leave(KErrArgument); |
|
3089 } |
|
3090 |
|
3091 if (!CompareStringL(param14Val.StrF(), KParam4Val())) |
|
3092 { |
|
3093 iEngine->Utils().LogIt ( _L("\nContent-Disposition - param2 checking failed.") ); |
|
3094 User::Leave(KErrArgument); |
|
3095 } |
|
3096 |
|
3097 CleanupStack::PopAndDestroy(¶m14Str); |
|
3098 hdr.RemoveField( contentDisposition ); |
|
3099 |
|
3100 ReleaseHeaders(); |
|
3101 iEngine->Utils().LogIt ( _L ("\nTestDecodeContentDispositionL test success.")); |
|
3102 } |
|
3103 |
|
3104 void CHttpHdrCodecTest::TestGetCustomFieldValueL() |
|
3105 { |
|
3106 iEngine->Utils().LogIt ( _L ("\nTesting custom header value. The value is folded into multiple lines.")); |
|
3107 |
|
3108 _LIT8(KCustomField, "foldedField"); |
|
3109 _LIT8(KCustomVal, "first line\r\nsecond line\r\r\nthird line\r\n"); |
|
3110 |
|
3111 RHTTPHeaders hdr= GetHeadersLC(); |
|
3112 RStringF customField = iStrP.OpenFStringL(KCustomField()); |
|
3113 CleanupClosePushL(customField); |
|
3114 RStringF customVal = iStrP.OpenFStringL(KCustomVal()); |
|
3115 CleanupClosePushL(customVal); |
|
3116 |
|
3117 THTTPHdrVal val(customVal); |
|
3118 |
|
3119 hdr.SetFieldL(customField, val); |
|
3120 TPtrC8 rawValue; |
|
3121 hdr.GetRawField(customField, rawValue); |
|
3122 |
|
3123 CleanupStack::PopAndDestroy(&customVal); |
|
3124 CleanupStack::PopAndDestroy(&customField); |
|
3125 |
|
3126 TPtrC8 hdrVal(KCustomVal()); |
|
3127 hdrVal.Set(hdrVal.Left(hdrVal.Length() - 1)); |
|
3128 if(rawValue.Compare(hdrVal) != 0) |
|
3129 { |
|
3130 iEngine->Utils().LogIt ( _L("\nTesting custom header value failed.") ); |
|
3131 User::Leave(KErrArgument); |
|
3132 } |
|
3133 |
|
3134 ReleaseHeaders(); |
|
3135 iEngine->Utils().LogIt ( _L ("\nTesting custom header value was successful.")); |
|
3136 } |
|
3137 |
|
3138 void CHttpHdrCodecTest::TestGetCustomFieldNullValueL() |
|
3139 { |
|
3140 iEngine->Utils().LogIt ( _L ("\nTesting custom header value as NULL")); |
|
3141 |
|
3142 _LIT8(KCustomField, "X-Oma-Drm-Separate-Delivery"); |
|
3143 |
|
3144 RHTTPHeaders hdr= GetHeadersLC(); |
|
3145 RStringF customField = iStrP.OpenFStringL(KCustomField()); |
|
3146 CleanupClosePushL(customField); |
|
3147 RStringF customVal = iStrP.OpenFStringL(KNullDesC8); |
|
3148 CleanupClosePushL(customVal); |
|
3149 |
|
3150 THTTPHdrVal val(customVal); |
|
3151 |
|
3152 hdr.SetFieldL(customField, val); |
|
3153 TPtrC8 rawValue; |
|
3154 hdr.GetRawField(customField, rawValue); |
|
3155 |
|
3156 CleanupStack::PopAndDestroy(&customVal); |
|
3157 CleanupStack::PopAndDestroy(&customField); |
|
3158 |
|
3159 TPtrC8 hdrVal(KNullDesC8); |
|
3160 if(rawValue.Compare(hdrVal) != 0) |
|
3161 { |
|
3162 iEngine->Utils().LogIt ( _L("\nTesting custom header value failed.") ); |
|
3163 User::Leave(KErrArgument); |
|
3164 } |
|
3165 |
|
3166 ReleaseHeaders(); |
|
3167 iEngine->Utils().LogIt ( _L ("\nTesting custom header value was successful.")); |
|
3168 } |
|
3169 |
|
3170 void CHttpHdrCodecTest::TestGetCustomFieldNoValueL() |
|
3171 { |
|
3172 iEngine->Utils().LogIt ( _L ("\nTesting custom header value as [\r\n]")); |
|
3173 |
|
3174 _LIT8(KCustomField, "X-Oma-Drm-Separate-Delivery"); |
|
3175 |
|
3176 RHTTPHeaders hdr= GetHeadersLC(); |
|
3177 RStringF customField = iStrP.OpenFStringL(KCustomField()); |
|
3178 CleanupClosePushL(customField); |
|
3179 RStringF customVal = iStrP.OpenFStringL(KNullDesC8); |
|
3180 CleanupClosePushL(customVal); |
|
3181 |
|
3182 hdr.SetRawFieldL(customField, KNullDesC8, KFieldSeparator); |
|
3183 TPtrC8 rawValue; |
|
3184 hdr.GetRawField(customField, rawValue); |
|
3185 |
|
3186 CleanupStack::PopAndDestroy(&customVal); |
|
3187 CleanupStack::PopAndDestroy(&customField); |
|
3188 |
|
3189 TPtrC8 hdrVal(KNullDesC8); |
|
3190 if(rawValue.Compare(hdrVal) != 0) |
|
3191 { |
|
3192 iEngine->Utils().LogIt ( _L("\nTesting custom header value failed.") ); |
|
3193 User::Leave(KErrArgument); |
|
3194 } |
|
3195 |
|
3196 ReleaseHeaders(); |
|
3197 iEngine->Utils().LogIt ( _L ("\nTesting custom header value was successful.")); |
|
3198 } |
|
3199 |
|
3200 void CHttpHdrCodecTest::TestInvalidHeaderFieldPartL () |
|
3201 { |
|
3202 iEngine->Utils().LogIt ( _L ("\nTestInvalidHeaderFieldPartL test started.")); |
|
3203 iEngine->Console().Printf(_L("\nTest 'Accept'(for example) header by adding one/more field parts and query for non-existing field part")); |
|
3204 iEngine->Utils().LogIt ( _L ("\nCreating Accept Header as Accept: text/html; q=0.8, text/vnd.wap.wml; q=0.2; extended=value, text/*")); |
|
3205 |
|
3206 // Open strings used in this test |
|
3207 RStringF textHtml = iStrP.StringF(HTTP::ETextHtml,RHTTPSession::GetTable()); |
|
3208 RStringF textWml = iStrP.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable()); |
|
3209 RStringF textAny = iStrP.StringF(HTTP::ETextAny,RHTTPSession::GetTable()); |
|
3210 |
|
3211 RStringF extended = iStrP.OpenFStringL(_L8("extended")); |
|
3212 CleanupClosePushL(extended); |
|
3213 RStringF extendVal = iStrP.OpenFStringL(_L8("value")); |
|
3214 CleanupClosePushL(extendVal); |
|
3215 // |
|
3216 |
|
3217 RHTTPHeaders hdr = GetHeadersLC(); |
|
3218 |
|
3219 // Set up the parsed header |
|
3220 RStringF accept = iStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()); |
|
3221 THTTPHdrVal accVal(textHtml); |
|
3222 THTTPHdrVal q(THTTPHdrVal::TQConv(0.8)); |
|
3223 hdr.SetFieldL(accept, accVal, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), q); |
|
3224 accVal.SetStrF(textWml); |
|
3225 q.SetInt(THTTPHdrVal::TQConv(0.2)); |
|
3226 hdr.SetFieldL(accept, accVal, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), q); |
|
3227 q.SetStrF(extendVal); |
|
3228 hdr.SetFieldL(accept, accVal, extended, q); |
|
3229 accVal.SetStrF(textAny); |
|
3230 hdr.SetFieldL(accept, accVal); |
|
3231 // now get the OTA data |
|
3232 THTTPHdrVal paramVal; |
|
3233 TInt err = hdr.GetParam(accept, iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable()), paramVal, -1); |
|
3234 |
|
3235 if ( err != KErrNotFound ) |
|
3236 { |
|
3237 iEngine->Utils().LogIt ( _L("\nTestInvalidHeaderFieldPartL failed, expected error: KErrNotFound, result error [%d]"), err ); |
|
3238 User::Leave(KErrArgument); |
|
3239 } |
|
3240 |
|
3241 // Close strings used in this test |
|
3242 ReleaseHeaders(); |
|
3243 CleanupStack::PopAndDestroy(2, &extended); |
|
3244 |
|
3245 iEngine->Utils().LogIt ( _L ("\nTestInvalidHeaderFieldPartL test success.")); |
|
3246 |
|
3247 } |
|
3248 |
|
3249 void CHttpHdrCodecTest::TestRoundTripTransferEncodingL() |
|
3250 { |
|
3251 } |
|
3252 |
|
3253 TBool CHttpHdrCodecTest::CompareStringL(RStringF aStrTk, const TDesC8& aDes) |
|
3254 { |
|
3255 RStringF desStr = iStrP.OpenFStringL(aDes); |
|
3256 TBool retVal = (desStr == aStrTk); |
|
3257 desStr.Close(); |
|
3258 return retVal; |
|
3259 } |
|
3260 TBool CHttpHdrCodecTest::CompareStringL(RString aStrTk, const TDesC8& aDes) |
|
3261 { |
|
3262 RString desStr = iStrP.OpenStringL(aDes); |
|
3263 TBool retVal = (desStr == aStrTk); |
|
3264 desStr.Close(); |
|
3265 return retVal; |
|
3266 } |
|
3267 |
|
3268 TBool CHttpHdrCodecTest::CompareValue(TInt aVal1, TInt aVal2) |
|
3269 { |
|
3270 return (aVal1 == aVal2); |
|
3271 } |
|
3272 |
|
3273 TBool CHttpHdrCodecTest::CompareDate(TDateTime aDate1, TDateTime aDate2) |
|
3274 { |
|
3275 return ((aDate1.Year() == aDate2.Year()) && |
|
3276 (aDate1.Month() == aDate2.Month()) && |
|
3277 (aDate1.Day() == aDate2.Day()) && |
|
3278 (aDate1.Hour() == aDate2.Hour()) && |
|
3279 (aDate1.Minute() == aDate2.Minute()) && |
|
3280 (aDate1.Second() == aDate2.Second()) && |
|
3281 (aDate1.MicroSecond() == aDate2.MicroSecond())); |
|
3282 } |
|
3283 |
|
3284 |
|
3285 void CHttpHdrCodecTest::ResetTimeElapsed() |
|
3286 // Resets timestamp to time now |
|
3287 { |
|
3288 iLastTimeStamp.UniversalTime(); |
|
3289 } |
|
3290 |
|
3291 |
|
3292 void CHttpHdrCodecTest::DisplayTimeElapsed() |
|
3293 // Calculate elapsed time since last measurement, and display |
|
3294 { |
|
3295 TTime timeNow; |
|
3296 timeNow.UniversalTime(); |
|
3297 TTimeIntervalMicroSeconds elapsedMicroSec = |
|
3298 timeNow.MicroSecondsFrom(iLastTimeStamp); |
|
3299 iLastTimeStamp = timeNow; |
|
3300 iEngine->Console().Printf( |
|
3301 _L("Time elapsed since last measurement is: %d ms\n"), |
|
3302 elapsedMicroSec.Int64()/1000 |
|
3303 ); |
|
3304 } |
|
3305 |
|
3306 RHTTPHeaders CHttpHdrCodecTest::GetHeadersLC() |
|
3307 { |
|
3308 _LIT8(KUri, "http://www.symbian.com"); |
|
3309 TUriParser8 up; |
|
3310 up.Parse(KUri); |
|
3311 iTransaction = iSession.OpenTransactionL(up, *this, iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
3312 CleanupClosePushL(iTransaction); |
|
3313 return iTransaction.Request().GetHeaderCollection(); |
|
3314 } |
|
3315 |
|
3316 void CHttpHdrCodecTest::ReleaseHeaders() |
|
3317 { |
|
3318 CleanupStack::PopAndDestroy(&iTransaction); |
|
3319 } |
|
3320 |
|
3321 void CHttpHdrCodecTest::MHFRunL(RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/) |
|
3322 { |
|
3323 } |
|
3324 |
|
3325 TInt CHttpHdrCodecTest::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/) |
|
3326 { |
|
3327 return aError; |
|
3328 } |
|
3329 |