|
1 // Copyright (c) 2006-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 "CINC082448.h" |
|
17 #include "httptestutils.h" |
|
18 #include "es_sock.h" |
|
19 |
|
20 _LIT8 ( KUriTransaction1, "http://10.29.23.12/1.jpg" ); |
|
21 |
|
22 /** |
|
23 This function is called to create a new instance of the class |
|
24 CINC082448 |
|
25 |
|
26 @param aTestNumber The test number that has to be executed |
|
27 @param aIniSettingsFile The script file that holds the sections |
|
28 from which the value has to be retrieved |
|
29 @leave Leaves with a standard error |
|
30 */ |
|
31 CINC082448* CINC082448::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile) |
|
32 { |
|
33 CINC082448* self = new(ELeave)CINC082448(aTestNumber, aIniSettingsFile); |
|
34 CleanupStack::PushL(self); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 /** |
|
40 Destructor |
|
41 */ |
|
42 CINC082448::~CINC082448() |
|
43 { |
|
44 } |
|
45 |
|
46 /** |
|
47 This C++ constructor is called in the NewL function and is used to |
|
48 instantiate iTestNumber and iIniSettingsFile |
|
49 |
|
50 @param aTestNumber - The test number that has to be executed |
|
51 @param aIniSettingsFile - The script file that holds the sections |
|
52 from which the value has to be retrieved |
|
53 */ |
|
54 CINC082448::CINC082448(TInt aTestNumber, CScriptFile* aIniSettingsFile) : |
|
55 iIniSettingsFile(aIniSettingsFile), |
|
56 iTestNumber(aTestNumber) |
|
57 { |
|
58 // does nothing |
|
59 } |
|
60 |
|
61 /** |
|
62 This function is called to initiate the tests. |
|
63 |
|
64 @leave Leaves with a standard error. |
|
65 */ |
|
66 void CINC082448::DoRunL() |
|
67 { |
|
68 TUriParser8 up; |
|
69 up.Parse(KUriTransaction1); |
|
70 |
|
71 // Open the HTTP session |
|
72 iSession.OpenL(); |
|
73 CleanupClosePushL(iSession); |
|
74 |
|
75 RStringPool strP = iSession.StringPool(); |
|
76 |
|
77 // Open a GET transactions, specifying this object as the request body data supplier |
|
78 iTransaction = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
79 iEngine->Utils().LogIt( _L("\nSubmitting first transaction\n") ); |
|
80 iTransaction.SubmitL(); |
|
81 CActiveScheduler::Start(); |
|
82 |
|
83 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
84 RStringPool stringPool = iSession.StringPool (); |
|
85 |
|
86 THTTPHdrVal value; |
|
87 TBool hasValue = connInfo.Property ( stringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), value ); |
|
88 if (hasValue) |
|
89 { |
|
90 RConnection* conn = REINTERPRET_CAST( RConnection*, value.Int() ); |
|
91 TUint count; |
|
92 //get the no of active connections |
|
93 TInt err = conn->EnumerateConnections( count ); |
|
94 if ( err == KErrNone ) |
|
95 { |
|
96 if ( IsConnectionActive( *conn ) ) |
|
97 { |
|
98 iEngine->Utils().LogIt( _L("\nConnection is active. Stop the active connection.\n") ); |
|
99 conn->Stop (); // stop the active connection |
|
100 if ( !IsConnectionActive( *conn ) ) |
|
101 { |
|
102 iEngine->Utils().LogIt( _L("\nConnection stopped.\n") ); |
|
103 } |
|
104 else |
|
105 { |
|
106 iEngine->Utils().LogIt( _L("\nConnection stopped failed.\n") ); |
|
107 } |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 iEngine->Utils().LogIt(_L("Unable to enumerate number of connections, Error: %d"), err); |
|
113 User::Leave ( KErrNotFound ); |
|
114 } |
|
115 } |
|
116 |
|
117 RHTTPTransaction myTransaction2 = iSession.OpenTransactionL ( up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable() )); |
|
118 iEngine->Utils().LogIt( _L("Submitting second transaction\n") ); |
|
119 myTransaction2.SubmitL(); |
|
120 CActiveScheduler::Start(); |
|
121 |
|
122 CleanupStack::PopAndDestroy(&iSession); //close iSession |
|
123 |
|
124 } |
|
125 |
|
126 /** |
|
127 If a test is failed then is function is executed to log the error code |
|
128 with which the test failed |
|
129 |
|
130 @param aErr The error code with which the test failed. |
|
131 */ |
|
132 TInt CINC082448::RunError(TInt aErr) |
|
133 { |
|
134 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
135 return KErrNone; |
|
136 } |
|
137 |
|
138 void CINC082448::DoCancel() |
|
139 { |
|
140 } |
|
141 |
|
142 const TDesC& CINC082448::TestName() |
|
143 { |
|
144 _LIT(KHeaderTestName,"CINC082448"); |
|
145 return KHeaderTestName; |
|
146 } |
|
147 |
|
148 TInt CINC082448::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
|
149 { |
|
150 _LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n"); |
|
151 iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id()); |
|
152 iFailureError = aError; |
|
153 CActiveScheduler::Stop(); |
|
154 return KErrNone; |
|
155 } |
|
156 |
|
157 void CINC082448::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
158 { |
|
159 switch (aEvent.iStatus) |
|
160 { |
|
161 case THTTPEvent::EGotResponseHeaders: |
|
162 { |
|
163 // HTTP response headers have been received |
|
164 iEngine->Utils().LogIt(_L("<Got response headers>")); |
|
165 } break; |
|
166 case THTTPEvent::ESubmit: |
|
167 { |
|
168 } break; |
|
169 case THTTPEvent::EGotResponseBodyData: |
|
170 { |
|
171 // Some (more) body data has been received (in the HTTP response) |
|
172 TPtrC8 bodyData; |
|
173 if(aTransaction.Response().Body()->GetNextDataPart(bodyData) ) |
|
174 { |
|
175 iEngine->Utils().LogIt(_L("1,Got Last Chunk...\n")); |
|
176 } |
|
177 aTransaction.Response().Body()->ReleaseData(); |
|
178 } break; |
|
179 case THTTPEvent::EResponseComplete: |
|
180 { |
|
181 // The transaction's response is complete |
|
182 iEngine->Utils().LogIt(_L("<Transaction Complete>")); |
|
183 } break; |
|
184 case THTTPEvent::ESucceeded: |
|
185 { |
|
186 // The transaction succeeded |
|
187 iEngine->Utils().LogIt(_L("<Transaction succeeded>")); |
|
188 aTransaction.Close(); |
|
189 CActiveScheduler::Stop(); |
|
190 } |
|
191 break; |
|
192 case THTTPEvent::EFailed: |
|
193 { |
|
194 // The transaction failed so fail the test |
|
195 iEngine->Utils().LogIt(_L("<Transaction failed>")); |
|
196 aTransaction.Close(); |
|
197 CActiveScheduler::Stop(); |
|
198 } break; |
|
199 default: |
|
200 { |
|
201 _LIT(KLogDescription, "<unrecognised event> %d"); |
|
202 iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus); |
|
203 if (aEvent.iStatus < 0) |
|
204 { |
|
205 iFailureError = aEvent.iStatus; |
|
206 CActiveScheduler::Stop(); |
|
207 } |
|
208 } |
|
209 break; |
|
210 } |
|
211 return; |
|
212 } |
|
213 |
|
214 TBool CINC082448::IsConnectionActive ( RConnection& aConnection ) |
|
215 { |
|
216 TRequestStatus status; |
|
217 TUint secs = 1; // 1 secs |
|
218 TBool state = EFalse; |
|
219 |
|
220 TPckg < TBool > stateDes( state ); |
|
221 |
|
222 aConnection.IsConnectionActiveRequest( secs, stateDes, status ); |
|
223 User::WaitForRequest ( status ); |
|
224 |
|
225 return state; |
|
226 } |
|
227 |
|
228 void CINC082448::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/) |
|
229 { |
|
230 } |
|
231 |
|
232 TBool CINC082448::GetCredentialsL(const TUriC8& /*aURI*/, RString /*aRealm*/, |
|
233 RStringF /*aAuthenticationType*/, |
|
234 RString& /*aUsername*/, |
|
235 RString& /*aPassword*/) |
|
236 |
|
237 { |
|
238 User::Leave(KErrGeneral); |
|
239 return EFalse; |
|
240 } |