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