|
1 // Copyright (c) 2004-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 // Author: Franco.Bellu@symbian.com |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include "Tc6.h" |
|
20 #include <http.h> |
|
21 #include "testservers.h" |
|
22 |
|
23 CHttpTestCase6::CHttpTestCase6(CScriptFile* aIniSettingsFile) : |
|
24 CHttpTestTransBase(), |
|
25 iIniSettingsFile(aIniSettingsFile) |
|
26 { |
|
27 } |
|
28 |
|
29 void CHttpTestCase6::DoRunL() |
|
30 { |
|
31 // Literals used in the function |
|
32 _LIT8(KWapTestUrl, "http://WapTestIP/cgi-bin/testcase6.cgi"); |
|
33 |
|
34 // Replace the host name in the URL |
|
35 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
36 CleanupStack::PushL(newUrl8); |
|
37 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
38 |
|
39 TUriParser8 testURI; |
|
40 testURI.Parse(newUrlPtr8); |
|
41 |
|
42 //open a Session |
|
43 RHTTPSession mySession; |
|
44 mySession.OpenL(); |
|
45 CleanupClosePushL(mySession); |
|
46 iEngine->Utils().LogIt(_L("Session Created(TC6)")); |
|
47 iEngine->Utils().LogIt(_L("Session parameters: Default")); |
|
48 //Get the mySession'string pool handle; |
|
49 iMyStrP = mySession.StringPool(); |
|
50 //open string this testcase needs |
|
51 RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable()); |
|
52 RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable()); |
|
53 _LIT8(KHttpApplicationOcspResponse,"application/ocsp-response"); |
|
54 RStringF mimeType = iMyStrP.OpenFStringL(KHttpApplicationOcspResponse); |
|
55 //Create , open and push in the CS a Transaction in mySession |
|
56 RHTTPTransaction myTransaction; |
|
57 myTransaction = mySession.OpenTransactionL(testURI, *this, mySession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
58 CleanupClosePushL(myTransaction); |
|
59 iEngine->Utils().LogIt(_L("Transaction Created in mySession")); |
|
60 //Get a handle of the request in myTransaction |
|
61 RHTTPRequest myRequest = myTransaction.Request(); |
|
62 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
63 // provide some headers |
|
64 |
|
65 THTTPHdrVal v2(textPlain); |
|
66 THTTPHdrVal v3(textHtml); |
|
67 THTTPHdrVal v4(6); |
|
68 THTTPHdrVal v5(mimeType); |
|
69 |
|
70 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2 ); |
|
71 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3); |
|
72 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), v4); |
|
73 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5); |
|
74 |
|
75 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
76 iEngine->Utils().LogIt(_L("Method:Post")); |
|
77 iEngine->Utils().LogIt(_L("Accept:test/plain,text/html")); |
|
78 iEngine->Utils().LogIt(_L("Content-Type: application/ocsp-response")); |
|
79 iEngine->Utils().LogIt(_L("Content-Length: 6")); |
|
80 myRequest.SetBody(*this); |
|
81 myTransaction.SubmitL(); |
|
82 CActiveScheduler::Start(); |
|
83 |
|
84 // Close strings used in this session before closing the session |
|
85 mimeType.Close(); |
|
86 //close transaction and session |
|
87 myTransaction.Close(); |
|
88 iEngine->Utils().LogIt(_L("Transaction terminated\n")); |
|
89 mySession.Close(); |
|
90 iEngine->Utils().LogIt(_L("Session terminated")); |
|
91 if (iTestFail==1) |
|
92 { |
|
93 User::Leave(-1); |
|
94 } |
|
95 CleanupStack::Pop(2); // mySession,myTansaction |
|
96 CleanupStack::PopAndDestroy(newUrl8); |
|
97 } |
|
98 |
|
99 TInt CHttpTestCase6::RunError(TInt aErr) |
|
100 { |
|
101 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
102 return KErrNone; |
|
103 } |
|
104 |
|
105 void CHttpTestCase6::DoCancel() |
|
106 { |
|
107 } |
|
108 |
|
109 CHttpTestCase6::~CHttpTestCase6() |
|
110 { |
|
111 } |
|
112 |
|
113 /** set this object active */ |
|
114 void CHttpTestCase6::CompleteOwnRequest() |
|
115 { |
|
116 TRequestStatus* stat = &iStatus; |
|
117 User::RequestComplete(stat,KErrNone); |
|
118 if (!IsActive()) |
|
119 SetActive(); |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 /** sets base test name. |
|
125 @param void |
|
126 @return string - the test name |
|
127 */ |
|
128 const TDesC& CHttpTestCase6::TestName() |
|
129 { |
|
130 _LIT(KHeaderTestName,"Test Case 6 "); |
|
131 return KHeaderTestName; |
|
132 } |
|
133 |
|
134 TInt CHttpTestCase6::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
135 const THTTPEvent& /*aEvent*/) |
|
136 { |
|
137 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 void CHttpTestCase6::MHFRunL(RHTTPTransaction aTransaction, |
|
142 const THTTPEvent& aEvent) |
|
143 { |
|
144 switch (aEvent.iStatus) |
|
145 { |
|
146 case THTTPEvent::EGotResponseHeaders: |
|
147 { |
|
148 // HTTP response headers have been received |
|
149 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
150 TInt statusCode = aTransaction.Response().StatusCode(); |
|
151 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
152 DumpRespHeaders(aTransaction); |
|
153 iEngine->SetCurrentStatusCode(statusCode); |
|
154 //define 2 RStringF : I want to find a header-field header-vaulue |
|
155 //match in the response headers |
|
156 RStringF contTypeStr = iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()); |
|
157 _LIT8(KHttpApplicationOcspResponse,"application/ocsp-response"); |
|
158 RStringF ocspStr = iMyStrP.OpenFStringL(KHttpApplicationOcspResponse); |
|
159 // get a handle for the headers |
|
160 RHTTPHeaders hdr =aTransaction.Response().GetHeaderCollection(); |
|
161 //parse them and look for application/ocsp-response header |
|
162 THTTPHdrVal hVal; |
|
163 if(hdr.GetField(contTypeStr,0,hVal) == KErrNone) |
|
164 { |
|
165 if (hVal.StrF()==ocspStr) |
|
166 iEngine->Utils().LogIt(_L("\nOk header application/ocsp-response found")); |
|
167 else |
|
168 iEngine->Utils().LogIt(_L("\nThe server doesn't support the application/ocsp-response header")); |
|
169 } |
|
170 ocspStr.Close(); |
|
171 if (iExpectedStatusCode != statusCode) |
|
172 { |
|
173 iTestFail=1; |
|
174 iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n")); |
|
175 } |
|
176 } break; |
|
177 case THTTPEvent::EGotResponseBodyData: |
|
178 { |
|
179 // Some (more) body data has been received (in the HTTP response) |
|
180 iEngine->Utils().LogIt(_L("<Got a chunk of data>\n")); |
|
181 DumpResponseBody(aTransaction); |
|
182 } break; |
|
183 case THTTPEvent::EResponseComplete: |
|
184 { |
|
185 // The transaction's response is complete |
|
186 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
187 } break; |
|
188 case THTTPEvent::ESucceeded: |
|
189 { |
|
190 iEngine->Utils().LogIt(_L("<ESucceeded received >\n")); |
|
191 CActiveScheduler::Stop(); |
|
192 } break; |
|
193 default: |
|
194 { |
|
195 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
196 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
197 { |
|
198 iTestFail=1; |
|
199 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
200 iEngine->PressAnyKey(); |
|
201 CActiveScheduler::Stop(); |
|
202 } |
|
203 } |
|
204 break; |
|
205 } |
|
206 } |
|
207 |