|
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 "Tc5.h" |
|
20 #include <http.h> |
|
21 #include "testservers.h" |
|
22 |
|
23 CHttpTestCase5::CHttpTestCase5(CScriptFile* aIniSettingsFile) : |
|
24 CHttpTestTransBase(), |
|
25 iIniSettingsFile(aIniSettingsFile) |
|
26 { |
|
27 } |
|
28 |
|
29 void CHttpTestCase5::DoRunL() |
|
30 { |
|
31 // Literals used in the function |
|
32 _LIT8(KWapTestUrl, "http://WapTestIP/cgi-bin/testcase5.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(TC5)")); |
|
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 mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable()); |
|
52 RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable()); |
|
53 RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable()); |
|
54 |
|
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 v6(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()), v6); |
|
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/vnd.syncml-xml")); |
|
79 iEngine->Utils().LogIt(_L("Content-Length: 6")); |
|
80 myRequest.SetBody(*this); |
|
81 myTransaction.SubmitL(); |
|
82 CActiveScheduler::Start(); |
|
83 |
|
84 //close Transaction and session |
|
85 myTransaction.Close(); |
|
86 iEngine->Utils().LogIt(_L("Transaction terminated\n")); |
|
87 mySession.Close(); |
|
88 iEngine->Utils().LogIt(_L("Session terminated")); |
|
89 if (iTestFail==1) |
|
90 { |
|
91 User::Leave(-1); |
|
92 } |
|
93 CleanupStack::Pop(2); // mySession,myTansaction |
|
94 CleanupStack::PopAndDestroy(newUrl8); |
|
95 } |
|
96 |
|
97 TInt CHttpTestCase5::RunError(TInt aErr) |
|
98 { |
|
99 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 void CHttpTestCase5::DoCancel() |
|
104 { |
|
105 } |
|
106 |
|
107 CHttpTestCase5::~CHttpTestCase5() |
|
108 { |
|
109 } |
|
110 |
|
111 /** set this object active */ |
|
112 void CHttpTestCase5::CompleteOwnRequest() |
|
113 { |
|
114 TRequestStatus* stat = &iStatus; |
|
115 User::RequestComplete(stat,KErrNone); |
|
116 if (!IsActive()) |
|
117 SetActive(); |
|
118 } |
|
119 |
|
120 /** sets base test name. |
|
121 @param void |
|
122 @return string - the test name |
|
123 */ |
|
124 const TDesC& CHttpTestCase5::TestName() |
|
125 { |
|
126 _LIT(KHeaderTestName,"Test Case 5 "); |
|
127 return KHeaderTestName; |
|
128 } |
|
129 |
|
130 TInt CHttpTestCase5::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
131 const THTTPEvent& /*aEvent*/) |
|
132 { |
|
133 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 void CHttpTestCase5::MHFRunL(RHTTPTransaction aTransaction, |
|
138 const THTTPEvent& aEvent) |
|
139 { |
|
140 switch (aEvent.iStatus) |
|
141 { |
|
142 case THTTPEvent::EGotResponseHeaders: |
|
143 { |
|
144 // HTTP response headers have been received |
|
145 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
146 TInt statusCode = aTransaction.Response().StatusCode(); |
|
147 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
148 DumpRespHeaders(aTransaction); |
|
149 iEngine->SetCurrentStatusCode(statusCode); |
|
150 //define 2 RStringF : I want to find a header-field header-vaulue match in the response headers |
|
151 _LIT8(KContentTypeValSyncMl, "application/vnd.syncml-xml"); // ota content type header |
|
152 RStringF contTypeStr = iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()); |
|
153 RStringF syncmlStr = iMyStrP.OpenFStringL(KContentTypeValSyncMl); |
|
154 // get a handle for the headers |
|
155 RHTTPHeaders hdr =aTransaction.Response().GetHeaderCollection(); |
|
156 //parse the headers and look for application/vnd.syncml-xml header |
|
157 THTTPHdrVal hVal; |
|
158 if(hdr.GetField(contTypeStr,0,hVal)== KErrNone) |
|
159 {// Content-Type header is present |
|
160 if (hVal.StrF()==syncmlStr) |
|
161 iEngine->Utils().LogIt(_L("\nOk header application/vnd.syncml-xml found")); |
|
162 else |
|
163 iEngine->Utils().LogIt(_L("\nThe server doesn't support the application/vnd.syncml-xml header")); |
|
164 } |
|
165 syncmlStr.Close(); |
|
166 if (iExpectedStatusCode != statusCode) |
|
167 { |
|
168 iTestFail=1; |
|
169 iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n")); |
|
170 } |
|
171 } break; |
|
172 case THTTPEvent::EGotResponseBodyData: |
|
173 { |
|
174 // Some (more) body data has been received (in the HTTP response) |
|
175 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n")); |
|
176 DumpResponseBody(aTransaction); |
|
177 } break; |
|
178 case THTTPEvent::EResponseComplete: |
|
179 { |
|
180 // The transaction's response is complete |
|
181 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
182 } break; |
|
183 case THTTPEvent::ESucceeded: |
|
184 { |
|
185 iEngine->Utils().LogIt(_L("<ESucceeded received >\n")); |
|
186 CActiveScheduler::Stop(); |
|
187 } break; |
|
188 default: |
|
189 { |
|
190 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
191 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
192 { |
|
193 iTestFail=1; |
|
194 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
195 iEngine->PressAnyKey(); |
|
196 CActiveScheduler::Stop(); |
|
197 } |
|
198 } |
|
199 break; |
|
200 } |
|
201 } |