|
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 "Tc2.h" |
|
20 #include <http.h> |
|
21 #include "testservers.h" |
|
22 |
|
23 #include "csrvaddrval.h" |
|
24 |
|
25 |
|
26 CHttpTestCase2::CHttpTestCase2(CScriptFile* aIniSettingsFile) : |
|
27 iIniSettingsFile(aIniSettingsFile) |
|
28 { |
|
29 iExpectedStatusCode=0; |
|
30 } |
|
31 |
|
32 // methods derived from MHTTPDataSuplier |
|
33 void CHttpTestCase2::MHFRunL(RHTTPTransaction aTransaction, |
|
34 const THTTPEvent& aEvent) |
|
35 { |
|
36 switch (aEvent.iStatus) |
|
37 { |
|
38 case THTTPEvent::EGotResponseHeaders: |
|
39 { |
|
40 iEngine->Utils().LogIt(_L("<EGotResponseHeaders received>\n")); |
|
41 DumpRespHeaders(aTransaction); |
|
42 iEngine->SetCurrentStatusCode(aTransaction.Response().StatusCode()); |
|
43 } break; |
|
44 case THTTPEvent::EGotResponseBodyData: |
|
45 { |
|
46 // Some (more) body data has been received (in the HTTP response) |
|
47 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n")); |
|
48 DumpResponseBody(aTransaction); |
|
49 } break; |
|
50 case THTTPEvent::EResponseComplete: |
|
51 { |
|
52 // The transaction's response is complete |
|
53 iEngine->Utils().LogIt(_L("<EResponseComplete received>\n")); |
|
54 } break; |
|
55 default: |
|
56 { |
|
57 iTestFail=1; |
|
58 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
59 iEngine->PressAnyKey(); |
|
60 CActiveScheduler::Stop(); |
|
61 } |
|
62 break; |
|
63 } |
|
64 } |
|
65 |
|
66 TInt CHttpTestCase2::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
67 const THTTPEvent& /*aEvent*/) |
|
68 { |
|
69 return aError; |
|
70 } |
|
71 |
|
72 void CHttpTestCase2::DoRunL() |
|
73 { |
|
74 // Literals used in the function |
|
75 _LIT8(KWapTestUrl, "http://WapTestIP/perl/dumpform.pl"); |
|
76 |
|
77 // Replace the host name in the URL |
|
78 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
79 CleanupStack::PushL(newUrl8); |
|
80 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
81 |
|
82 TUriParser8 testURI; |
|
83 testURI.Parse(newUrlPtr8); |
|
84 |
|
85 //open a Session |
|
86 RHTTPSession mySession; |
|
87 mySession.OpenL(); |
|
88 CleanupClosePushL(mySession); |
|
89 iEngine->Utils().LogIt(_L("Session Created (TC2)")); |
|
90 iEngine->Utils().LogIt(_L("Session (Default) parameters: RHTTPProxy aProxy = RHTTPProxy(), MHTTPSessionCallback* aCallback = NULL")); |
|
91 |
|
92 // Get the mySession'string pool handle; |
|
93 iMyStrP = mySession.StringPool(); |
|
94 |
|
95 //get strings used in this test |
|
96 RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable()); |
|
97 RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable()); |
|
98 RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable()); |
|
99 |
|
100 // Create , open and push in the CS a Transaction in mySession |
|
101 RHTTPTransaction myTransaction; |
|
102 myTransaction = mySession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
103 CleanupClosePushL(myTransaction); |
|
104 iEngine->Utils().LogIt(_L("Transaction Created in mySession")); |
|
105 |
|
106 // Get a handle of the request in myTransaction |
|
107 RHTTPRequest myRequest = myTransaction.Request(); |
|
108 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
109 // provide some headers |
|
110 THTTPHdrVal v2(textPlain); |
|
111 THTTPHdrVal v3(textHtml); |
|
112 THTTPHdrVal v4(6); |
|
113 THTTPHdrVal v5(mimeType); |
|
114 |
|
115 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2 ); |
|
116 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3); |
|
117 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), v4); |
|
118 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5); |
|
119 |
|
120 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
121 iEngine->Utils().LogIt(_L("Method:Post")); |
|
122 iEngine->Utils().LogIt(_L("Accept:test/plain,text/html")); |
|
123 iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded")); |
|
124 iEngine->Utils().LogIt(_L("Content-Length: 4")); |
|
125 myRequest.SetBody(*this); |
|
126 iEngine->Utils().LogIt(_L("Transaction terminated")); |
|
127 |
|
128 // Close strings used in this session before closing the session |
|
129 //close transaction and session |
|
130 myTransaction.Close(); |
|
131 iEngine->Utils().LogIt(_L("Transaction terminated")); |
|
132 mySession.Close(); |
|
133 iEngine->Utils().LogIt(_L("Session terminated")); |
|
134 if (iTestFail==1) |
|
135 { |
|
136 User::Leave(-1); |
|
137 } |
|
138 CleanupStack::Pop(2); // mySession,myTansaction |
|
139 CleanupStack::PopAndDestroy(newUrl8); |
|
140 } |
|
141 |
|
142 TInt CHttpTestCase2::RunError(TInt aErr) |
|
143 { |
|
144 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
145 return KErrNone; |
|
146 } |
|
147 void CHttpTestCase2::DoCancel() |
|
148 { |
|
149 } |
|
150 |
|
151 CHttpTestCase2::~CHttpTestCase2() |
|
152 { |
|
153 } |
|
154 |
|
155 /** set this object active */ |
|
156 void CHttpTestCase2::CompleteOwnRequest() |
|
157 { |
|
158 TRequestStatus* stat = &iStatus; |
|
159 User::RequestComplete(stat,KErrNone); |
|
160 if (!IsActive()) |
|
161 SetActive(); |
|
162 } |
|
163 |
|
164 /** sets base test name. |
|
165 @param void |
|
166 @return string - the test name |
|
167 */ |
|
168 |
|
169 const TDesC& CHttpTestCase2::TestName() |
|
170 { |
|
171 _LIT(KHeaderTestName,"Test Case 2 "); |
|
172 return KHeaderTestName; |
|
173 } |