|
1 // Copyright (c) 2007-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 // defines test class: CINC097492_4 |
|
15 // |
|
16 // |
|
17 |
|
18 #include "CINC097492_4.h" |
|
19 #include "examplecookiemanager.h" |
|
20 #include <http/ccookiefilterinterface.h> |
|
21 |
|
22 // User include |
|
23 #include "csrvaddrval.h" |
|
24 |
|
25 // Literals used in the file |
|
26 _LIT8(KHttpUrl1, "http://www.seoconsultants.com/w3c/status-codes/302.asp"); |
|
27 _LIT8(KHttpUrl2, "http://www.seoconsultants.com/w3c/status-codes/302.asp"); |
|
28 _LIT8(KHttpUrl3, "http://www.seoconsultants.com/w3c/status-codes/302.asp"); |
|
29 |
|
30 /** |
|
31 This function is called to create a new instance of the class |
|
32 CINC097492_4 |
|
33 |
|
34 @param aTestNumber The test number that has to be executed |
|
35 @param aIniSettingsFile The script file that holds the sections |
|
36 from which the value has to be retrieved |
|
37 @leave Leaves with a standard error |
|
38 */ |
|
39 CINC097492_4* CINC097492_4::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile) |
|
40 { |
|
41 CINC097492_4* self = new(ELeave)CINC097492_4(aTestNumber, aIniSettingsFile); |
|
42 CleanupStack::PushL(self); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 /** |
|
48 Destructor |
|
49 */ |
|
50 CINC097492_4::~CINC097492_4() |
|
51 { |
|
52 iTransArray.Close(); |
|
53 } |
|
54 |
|
55 /** |
|
56 This C++ constructor is called in the NewL function and is used to |
|
57 instantiate iTestNumber and iIniSettingsFile |
|
58 |
|
59 @param aTestNumber - The test number that has to be executed |
|
60 @param aIniSettingsFile - The script file that holds the sections |
|
61 from which the value has to be retrieved |
|
62 */ |
|
63 CINC097492_4::CINC097492_4(TInt aTestNumber, CScriptFile* aIniSettingsFile) : |
|
64 iIniSettingsFile(aIniSettingsFile), |
|
65 iTestNumber(aTestNumber) |
|
66 { |
|
67 } |
|
68 |
|
69 /** |
|
70 This function is called to initiate the tests. |
|
71 |
|
72 @leave Leaves with a standard error. |
|
73 */ |
|
74 void CINC097492_4::DoRunL() |
|
75 { |
|
76 // Open the HTTP session |
|
77 iSession.OpenL(); |
|
78 CleanupClosePushL(iSession); |
|
79 |
|
80 CreateTransArrayL(); |
|
81 |
|
82 CActiveScheduler::Start(); |
|
83 |
|
84 CleanupStack::PopAndDestroy(&iSession); //close iSession |
|
85 } |
|
86 |
|
87 /** |
|
88 If a test is failed then is function is executed to log the error code |
|
89 with which the test failed |
|
90 |
|
91 @param aErr The error code with which the test failed. |
|
92 */ |
|
93 TInt CINC097492_4::RunError(TInt aErr) |
|
94 { |
|
95 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
96 return KErrNone; |
|
97 } |
|
98 |
|
99 void CINC097492_4::DoCancel() |
|
100 { |
|
101 } |
|
102 |
|
103 const TDesC& CINC097492_4::TestName() |
|
104 { |
|
105 _LIT(KHeaderTestName,"CINC097492_4"); |
|
106 return KHeaderTestName; |
|
107 } |
|
108 |
|
109 TInt CINC097492_4::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
|
110 { |
|
111 _LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n"); |
|
112 iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id()); |
|
113 iFailureError = aError; |
|
114 CActiveScheduler::Stop(); |
|
115 return KErrNone; |
|
116 } |
|
117 |
|
118 void CINC097492_4::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
119 { |
|
120 switch (aEvent.iStatus) |
|
121 { |
|
122 case THTTPEvent::EGotResponseHeaders: |
|
123 { |
|
124 // HTTP response headers have been received |
|
125 iEngine->Utils().LogIt(_L("<Got response headers>")); |
|
126 MHTTPDataSupplier* body = aTransaction.Response().Body (); |
|
127 if ( body ) |
|
128 { |
|
129 body->ReleaseData (); |
|
130 } |
|
131 } break; |
|
132 case THTTPEvent::ESubmit: |
|
133 { |
|
134 } break; |
|
135 case THTTPEvent::EGotResponseBodyData: |
|
136 { |
|
137 // Some (more) body data has been received (in the HTTP response) |
|
138 iEngine->Utils().LogIt(_L("<Got a chunk of data>")); |
|
139 // Get the body data supplier |
|
140 MHTTPDataSupplier* iRespBody = aTransaction.Response().Body(); |
|
141 // Append to the output file. |
|
142 TPtrC8 bodyData; |
|
143 TBool lastChunk = iRespBody->GetNextDataPart( bodyData ); |
|
144 iRespBody->ReleaseData(); |
|
145 } break; |
|
146 case THTTPEvent::EResponseComplete: |
|
147 { |
|
148 // The transaction's response is complete |
|
149 iEngine->Utils().LogIt(_L("<Transaction Complete>")); |
|
150 } break; |
|
151 case THTTPEvent::ESucceeded: |
|
152 { |
|
153 // The transaction succeeded |
|
154 iEngine->Utils().LogIt(_L("<Transaction succeeded>")); |
|
155 aTransaction.Close(); |
|
156 if(--iOpenTransCount == 0) |
|
157 { |
|
158 CActiveScheduler::Stop(); |
|
159 } |
|
160 } |
|
161 break; |
|
162 case THTTPEvent::EFailed: |
|
163 { |
|
164 // The transaction failed so fail the test |
|
165 iEngine->Utils().LogIt(_L("<Transaction failed>")); |
|
166 aTransaction.Close(); |
|
167 if(--iOpenTransCount == 0) |
|
168 { |
|
169 CActiveScheduler::Stop(); |
|
170 } |
|
171 } break; |
|
172 default: |
|
173 { |
|
174 _LIT(KLogDescription, "<unrecognised event> %d"); |
|
175 iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus); |
|
176 if (aEvent.iStatus < 0) |
|
177 { |
|
178 iFailureError = aEvent.iStatus; |
|
179 CActiveScheduler::Stop(); |
|
180 } |
|
181 } |
|
182 break; |
|
183 } |
|
184 |
|
185 return; |
|
186 } |
|
187 |
|
188 |
|
189 void CINC097492_4::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/) |
|
190 { |
|
191 if (iTestNumber == 11) |
|
192 { |
|
193 User::Leave(KErrNone); |
|
194 } |
|
195 |
|
196 iCookieManager = CExampleCookieManager::NewL(iSession.StringPool()); |
|
197 |
|
198 CCookieFilterInterface::InstallFilterL(iSession, iCookieManager); |
|
199 } |
|
200 |
|
201 void CINC097492_4::CreateTransArrayL() |
|
202 { |
|
203 RStringPool strP = iSession.StringPool(); |
|
204 TUriParser8 up; |
|
205 |
|
206 up.Parse(KHttpUrl1); |
|
207 RHTTPTransaction trans1 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
208 CleanupClosePushL(trans1); |
|
209 iTransArray.Append(trans1); |
|
210 CleanupStack::Pop(&trans1); |
|
211 |
|
212 up.Parse(KHttpUrl2); |
|
213 RHTTPTransaction trans2 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
214 CleanupClosePushL(trans2); |
|
215 iTransArray.Append(trans2); |
|
216 CleanupStack::Pop(&trans2); |
|
217 |
|
218 up.Parse(KHttpUrl3); |
|
219 RHTTPTransaction trans3 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
220 CleanupClosePushL(trans3); |
|
221 iTransArray.Append(trans3); |
|
222 CleanupStack::Pop(&trans3); |
|
223 |
|
224 for(TInt i=0; i<iTransArray.Count(); i++) |
|
225 { |
|
226 iTransArray[i].SubmitL(); |
|
227 iOpenTransCount++; |
|
228 } |
|
229 } |
|
230 |
|
231 |