|
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 "Tc9.h" |
|
20 #include <http.h> |
|
21 #include "testservers.h" |
|
22 |
|
23 CHttpTestCase9::CHttpTestCase9(CScriptFile* aIniSettingsFile) : |
|
24 CHttpTestTransBase(), |
|
25 iIniSettingsFile(aIniSettingsFile) |
|
26 { |
|
27 } |
|
28 |
|
29 void CHttpTestCase9::DoRunL() |
|
30 { |
|
31 //Prepare anything needed for a correct POST Request based on TestCase5 |
|
32 //and submit it |
|
33 OpenTestSessionL(); |
|
34 iTransaction.SubmitL(); |
|
35 CActiveScheduler::Start(); |
|
36 //close anything opend and pop anything pushed on the CleanupStack |
|
37 CloseTestSession(); |
|
38 if (iTestFail==1) |
|
39 { |
|
40 User::Leave(-1); |
|
41 } |
|
42 } |
|
43 |
|
44 TInt CHttpTestCase9::RunError(TInt aErr) |
|
45 { |
|
46 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
47 return KErrNone; |
|
48 } |
|
49 |
|
50 void CHttpTestCase9::DoCancel() |
|
51 { |
|
52 } |
|
53 |
|
54 CHttpTestCase9::~CHttpTestCase9() |
|
55 { |
|
56 } |
|
57 |
|
58 /** increment the value of iState and set active to create call to RunL |
|
59 with new state value |
|
60 */ |
|
61 |
|
62 /** set this object active */ |
|
63 void CHttpTestCase9::CompleteOwnRequest() |
|
64 { |
|
65 TRequestStatus* stat = &iStatus; |
|
66 User::RequestComplete(stat,KErrNone); |
|
67 if (!IsActive()) |
|
68 SetActive(); |
|
69 } |
|
70 |
|
71 /** sets base test name. |
|
72 @param void |
|
73 @return string - the test name |
|
74 */ |
|
75 const TDesC& CHttpTestCase9::TestName() |
|
76 { |
|
77 _LIT(KHeaderTestName,"Test Case 9 "); |
|
78 return KHeaderTestName; |
|
79 } |
|
80 |
|
81 |
|
82 TInt CHttpTestCase9::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
83 const THTTPEvent& /*aEvent*/) |
|
84 { |
|
85 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
86 return KErrNone; |
|
87 } |
|
88 |
|
89 void CHttpTestCase9::MHFRunL(RHTTPTransaction aTransaction, |
|
90 const THTTPEvent& aEvent) |
|
91 { |
|
92 switch (aEvent.iStatus) |
|
93 { |
|
94 case THTTPEvent::EGotResponseHeaders: |
|
95 { |
|
96 // HTTP response headers have been received |
|
97 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
98 TInt statusCode = aTransaction.Response().StatusCode(); |
|
99 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
100 DumpRespHeaders(aTransaction); |
|
101 iEngine->SetCurrentStatusCode(statusCode); |
|
102 } break; |
|
103 case THTTPEvent::EGotResponseBodyData: |
|
104 { |
|
105 // Some (more) body data has been received (in the HTTP response) |
|
106 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n")); |
|
107 // for each chunk of data received we have to empty the buffer before |
|
108 // to be able to receive |
|
109 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
110 body->ReleaseData(); |
|
111 } break; |
|
112 case THTTPEvent::EResponseComplete: |
|
113 { |
|
114 // The transaction's response is complete |
|
115 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
116 } break; |
|
117 case THTTPEvent::ESucceeded: |
|
118 { |
|
119 iEngine->Utils().LogIt(_L("<ESucceeded received>\n")); |
|
120 iTestFail=1; |
|
121 iEngine->Utils().LogIt(_L("<The Test will fail :ESucceeded received instead ofEFailed>\n")); |
|
122 CActiveScheduler::Stop(); |
|
123 } break; |
|
124 case THTTPEvent::EFailed: |
|
125 { |
|
126 iEngine->Utils().LogIt(_L("<EFailed received>\n")); |
|
127 iEngine->Utils().LogIt(_L("<Test passed>\n")); |
|
128 CActiveScheduler::Stop(); |
|
129 } break; |
|
130 default: |
|
131 { |
|
132 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
133 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
134 { |
|
135 iTestFail=1; |
|
136 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
137 iEngine->PressAnyKey(); |
|
138 CActiveScheduler::Stop(); |
|
139 } |
|
140 } |
|
141 break; |
|
142 } |
|
143 } |
|
144 |
|
145 void CHttpTestCase9::OpenTestSessionL() |
|
146 { |
|
147 // Literals used in the function |
|
148 _LIT8(KWapTestUrl, "http://WapTestIP/perl/wrong_resource.txt"); |
|
149 |
|
150 // Replace the host name in the URL |
|
151 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
152 CleanupStack::PushL(newUrl8); |
|
153 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
154 |
|
155 TUriParser8 testURI; |
|
156 testURI.Parse(newUrlPtr8); |
|
157 |
|
158 //open a Session |
|
159 iSession.OpenL(); |
|
160 iEngine->Utils().LogIt(_L("Session Created(9) (Default parameters")); |
|
161 //Get the iSession'string pool handle; |
|
162 iMyStrP = iSession.StringPool(); |
|
163 //open string this testcase needs |
|
164 RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable()); |
|
165 RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable()); |
|
166 RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable()); |
|
167 |
|
168 //Create , open in the CS a Transaction in iSession |
|
169 iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
170 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
171 //Get a handle of the request in iTransaction |
|
172 RHTTPRequest myRequest = iTransaction.Request(); |
|
173 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
174 //provide some headers |
|
175 THTTPHdrVal v2(textPlain); |
|
176 THTTPHdrVal v3(textHtml); |
|
177 THTTPHdrVal v4(6); |
|
178 THTTPHdrVal v5(mimeType); |
|
179 |
|
180 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2); |
|
181 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3); |
|
182 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4); |
|
183 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5); |
|
184 |
|
185 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
186 iEngine->Utils().LogIt(_L("Method:Post")); |
|
187 iEngine->Utils().LogIt(_L("Accept:test/plain,text/html")); |
|
188 iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded")); |
|
189 iEngine->Utils().LogIt(_L("Content-Length: 6")); |
|
190 myRequest.SetBody(*this); |
|
191 CleanupStack::PopAndDestroy(newUrl8); |
|
192 } |
|
193 |
|
194 void CHttpTestCase9::CloseTestSession() |
|
195 { |
|
196 // Close strings used in this session before closing the session |
|
197 //close Transaction and session |
|
198 iTransaction.Close(); |
|
199 iEngine->Utils().LogIt(_L("Transaction terminated\n")); |
|
200 iSession.Close(); |
|
201 iEngine->Utils().LogIt(_L("Session terminated")); |
|
202 } |
|
203 |