|
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 "post14.h" |
|
17 #include <http.h> |
|
18 |
|
19 #include "csrvaddrval.h" |
|
20 |
|
21 _LIT8(KWapTestUrl, "http://WapTestIP"); |
|
22 |
|
23 CHttpTestCasePost14::CHttpTestCasePost14(CScriptFile* aIniSettingsFile) : |
|
24 CHttpAcceptTestBase(), |
|
25 iIniSettingsFile(aIniSettingsFile) |
|
26 { |
|
27 } |
|
28 |
|
29 const TDesC& CHttpTestCasePost14::TestName() |
|
30 { |
|
31 _LIT(KHeaderTestName,"Iteration 2 Post Test 14 "); |
|
32 return KHeaderTestName; |
|
33 } |
|
34 |
|
35 void CHttpTestCasePost14::OpenTestSessionL() |
|
36 { |
|
37 //open a default Session |
|
38 iSession.OpenL(); |
|
39 |
|
40 //Logs |
|
41 iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Post Test 14)")); |
|
42 iEngine->Utils().LogIt(_L("Session parameters: Default")); |
|
43 |
|
44 InstallAuthenticationL(iSession); |
|
45 |
|
46 //Get the iSession'string pool handle; |
|
47 iMyStrP = iSession.StringPool(); |
|
48 } |
|
49 |
|
50 |
|
51 void CHttpTestCasePost14::OpenTestTrans1L() |
|
52 { |
|
53 // Literals used in the function |
|
54 _LIT8(KUrlPath, "/perl/protected/dumpform.pl"); |
|
55 |
|
56 // Replace the host name in the URL |
|
57 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
58 CleanupStack::PushL(newUrl8); |
|
59 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
60 newUrlPtr8.Append(KUrlPath()); |
|
61 |
|
62 TUriParser8 testURI; |
|
63 testURI.Parse(newUrlPtr8); |
|
64 |
|
65 iTransaction1 = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
66 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
67 ++iOpenTransactionCount; |
|
68 |
|
69 //Get a handle of the request in iTransaction1 |
|
70 RHTTPRequest myRequest = iTransaction1.Request(); |
|
71 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
72 |
|
73 THTTPHdrVal contentTypeHdr(iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable())); |
|
74 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()),contentTypeHdr); |
|
75 |
|
76 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
77 iEngine->Utils().LogIt(_L("Method:Post")); |
|
78 iEngine->Utils().LogIt(_L("Content-Type:application/x-www-form-urlencoded ")); |
|
79 myRequest.SetBody(*this); |
|
80 CleanupStack::PopAndDestroy(newUrl8); |
|
81 } |
|
82 |
|
83 void CHttpTestCasePost14::OpenTestTrans2L() |
|
84 { |
|
85 // Literals used in the function |
|
86 _LIT8(KUrlPath, "/perl/protected/dumpform.pl"); |
|
87 |
|
88 // Replace the host name in the URL |
|
89 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
90 CleanupStack::PushL(newUrl8); |
|
91 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
92 newUrlPtr8.Append(KUrlPath()); |
|
93 |
|
94 TUriParser8 testURI; |
|
95 testURI.Parse(newUrlPtr8); |
|
96 |
|
97 iTransaction2 = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
98 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
99 ++iOpenTransactionCount; |
|
100 |
|
101 //Get a handle of the request in iTransaction2 |
|
102 RHTTPRequest myRequest = iTransaction2.Request(); |
|
103 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
104 |
|
105 THTTPHdrVal contentTypeHdr(iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable())); |
|
106 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()),contentTypeHdr); |
|
107 |
|
108 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
109 iEngine->Utils().LogIt(_L("Method:Post")); |
|
110 myRequest.SetBody(*this); |
|
111 CleanupStack::PopAndDestroy(newUrl8); |
|
112 } |
|
113 |
|
114 void CHttpTestCasePost14::CloseTestSession() |
|
115 { |
|
116 iTransaction1.Close(); |
|
117 iEngine->Utils().LogIt(_L("Transaction1 terminated\n")); |
|
118 iTransaction2.Close(); |
|
119 iEngine->Utils().LogIt(_L("Transaction2 terminated\n")); |
|
120 iSession.Close(); |
|
121 iEngine->Utils().LogIt(_L("Session terminated")); |
|
122 } |
|
123 |
|
124 |
|
125 TBool CHttpTestCasePost14::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) |
|
126 { |
|
127 if(iCallsNum++) |
|
128 { |
|
129 iTestFail=1; |
|
130 iEngine->Utils().LogIt(_L("The test will fail: the credential haven't been kept(the GetCredential function has been called again)")); |
|
131 return EFalse; |
|
132 } |
|
133 iEngine->Utils().LogIt(_L("Supplying credentials")); |
|
134 iEngine->Utils().DumpData(aURI.UriDes()); |
|
135 iEngine->Utils().DumpData(aRealm.DesC()); |
|
136 iEngine->Utils().DumpData(aAuthenticationType.DesC()); |
|
137 _LIT8(KScooby, "scooby"); |
|
138 _LIT8(KDoo, "doo"); |
|
139 RStringPool p = aRealm.Pool(); |
|
140 aUsername = p.OpenStringL(KScooby); |
|
141 aPassword = p.OpenStringL(KDoo); |
|
142 return ETrue; |
|
143 } |
|
144 |
|
145 void CHttpTestCasePost14::DoRunL() |
|
146 { |
|
147 OpenTestSessionL(); |
|
148 |
|
149 //Trans1 |
|
150 OpenTestTrans1L(); |
|
151 iTransaction1.SubmitL(); |
|
152 CActiveScheduler::Start(); |
|
153 |
|
154 //Trans2 |
|
155 OpenTestTrans2L(); |
|
156 iTransaction2.SubmitL(); |
|
157 CActiveScheduler::Start(); |
|
158 |
|
159 CloseTestSession(); |
|
160 if (iTestFail==1) |
|
161 { |
|
162 User::Leave(-1); |
|
163 } |
|
164 } |