|
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 // |
|
15 |
|
16 #include "post23.h" |
|
17 #include <http.h> |
|
18 |
|
19 #include "csrvaddrval.h" |
|
20 |
|
21 CHttpTestCasePost23::CHttpTestCasePost23(CScriptFile* aIniSettingsFile) : |
|
22 iIniSettingsFile(aIniSettingsFile) |
|
23 { |
|
24 iExpectedStatusCode=405; |
|
25 } |
|
26 |
|
27 const TDesC& CHttpTestCasePost23::TestName() |
|
28 { |
|
29 _LIT(KHeaderTestName,"Iteration 2 Post Test 23 "); |
|
30 return KHeaderTestName; |
|
31 } |
|
32 |
|
33 void CHttpTestCasePost23::OpenTestSessionL() |
|
34 { |
|
35 //open a Session |
|
36 |
|
37 iSession.OpenL(); |
|
38 iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Post Test 23)")); |
|
39 iEngine->Utils().LogIt(_L("Session parameters: Default")); |
|
40 |
|
41 InstallAuthenticationL(iSession); |
|
42 |
|
43 //Get the iSession'string pool handle; |
|
44 iMyStrP = iSession.StringPool(); |
|
45 //open string this testcase needs |
|
46 |
|
47 // Literals used in the function |
|
48 _LIT8(KWapTestUrl, "http://WapTestIP/http_tests/rc/401/private/dumpform.pl"); |
|
49 |
|
50 // Replace the host name in the URL |
|
51 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
52 CleanupStack::PushL(newUrl8); |
|
53 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
54 |
|
55 TUriParser8 testURI; |
|
56 testURI.Parse(newUrlPtr8); |
|
57 |
|
58 iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
59 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
60 ++iOpenTransactionCount; |
|
61 |
|
62 //Get a handle of the request in iTransaction |
|
63 RHTTPRequest myRequest = iTransaction.Request(); |
|
64 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
65 //provide some headers |
|
66 THTTPHdrVal contentTypeHdr(iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable())); |
|
67 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()),contentTypeHdr); |
|
68 |
|
69 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
70 iEngine->Utils().LogIt(_L("Method:Post")); |
|
71 iEngine->Utils().LogIt(_L("Content-Type:application/x-www-form-urlencoded ")); |
|
72 myRequest.SetBody(*this); |
|
73 CleanupStack::PopAndDestroy(newUrl8); |
|
74 } |
|
75 |
|
76 void CHttpTestCasePost23::CloseTestSession() |
|
77 { |
|
78 // Close strings used in this session before closing the session |
|
79 //close Transaction and session |
|
80 iTransaction.Close(); |
|
81 iEngine->Utils().LogIt(_L("Transaction terminated\n")); |
|
82 iSession.Close(); |
|
83 iEngine->Utils().LogIt(_L("Session terminated")); |
|
84 } |
|
85 |
|
86 |
|
87 TBool CHttpTestCasePost23::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) |
|
88 { |
|
89 iEngine->Utils().LogIt(_L("Supplying credentials")); |
|
90 iEngine->Utils().DumpData(aURI.UriDes()); |
|
91 iEngine->Utils().DumpData(aRealm.DesC()); |
|
92 iEngine->Utils().DumpData(aAuthenticationType.DesC()); |
|
93 _LIT8(KScooby, "scooby"); |
|
94 _LIT8(KDoo, "doo"); |
|
95 RStringPool p = aRealm.Pool(); |
|
96 aUsername = p.OpenStringL(KScooby); |
|
97 aPassword = p.OpenStringL(KDoo); |
|
98 return ETrue; |
|
99 } |
|
100 |
|
101 void CHttpTestCasePost23::MHFRunL(RHTTPTransaction aTransaction, |
|
102 THTTPEvent aEvent) |
|
103 { |
|
104 switch (aEvent.iStatus) |
|
105 { |
|
106 case THTTPEvent::EGotResponseHeaders: |
|
107 { |
|
108 // HTTP response headers have been received |
|
109 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
110 TInt statusCode = aTransaction.Response().StatusCode(); |
|
111 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
112 DumpRespHeaders(aTransaction); |
|
113 iEngine->SetCurrentStatusCode(statusCode); |
|
114 if (iExpectedStatusCode != statusCode) |
|
115 { |
|
116 iTestFail=1; |
|
117 iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n")); |
|
118 } |
|
119 } break; |
|
120 case THTTPEvent::EGotResponseBodyData: |
|
121 { |
|
122 // Some (more) body data has been received (in the HTTP response) |
|
123 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n")); |
|
124 // for each chunk of data received we have to empty the buffer before |
|
125 // to be able to receive |
|
126 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
127 body->ReleaseData(); |
|
128 } break; |
|
129 case THTTPEvent::EResponseComplete: |
|
130 { |
|
131 // The transaction's response is complete |
|
132 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
133 } break; |
|
134 case THTTPEvent::ESucceeded: |
|
135 { |
|
136 iEngine->Utils().LogIt(_L("<ESucceeded received from the VF>\n")); |
|
137 CActiveScheduler::Stop(); |
|
138 } break; |
|
139 case THTTPEvent::EFailed: |
|
140 { |
|
141 iEngine->Utils().LogIt(_L("<EFailed received from the VF( becouse status code is 4xx) but not a failure for the purpose ofthis test>\n")); |
|
142 CActiveScheduler::Stop(); |
|
143 } break; |
|
144 default: |
|
145 { |
|
146 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
147 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
148 { |
|
149 iTestFail=1; |
|
150 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
151 iEngine->PressAnyKey(); |
|
152 CActiveScheduler::Stop(); |
|
153 } |
|
154 } |
|
155 break; |
|
156 } |
|
157 } |