|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <ss_glob.h> |
|
19 #include <comms-infras/ss_nodemessages_factory.h> |
|
20 #include <comms-infras/ss_nodemessages_dataclient.h> |
|
21 #include <httpstringconstants.h> |
|
22 |
|
23 #include "ptcpclienttests.h" |
|
24 #include "upnp_cf_msgs.h" |
|
25 #include "upnpflowbase.h" |
|
26 #include "httpclientflow.h" |
|
27 #include "upnpflowfactory.h" |
|
28 |
|
29 #include "ctcpclienttestupnp1.h" |
|
30 #include "ctcpclienttestupnp2.h" |
|
31 #include "ctcpclienttestupnp3.h" |
|
32 #include "ctcpclienttestupnp4.h" |
|
33 #include "ctcpclienttestupnp5.h" |
|
34 #include "ctcpclienttestupnp6.h" |
|
35 #include "ctcpclienttestupnp7.h" |
|
36 #include "ctcpclienttestupnp8.h" |
|
37 #include "ctcpclienttestupnp9.h" |
|
38 #include "ctcpclienttestupnp10.h" |
|
39 #include "ctcpclienttestupnp11.h" |
|
40 #include "ctcpclienttestupnp12.h" |
|
41 #include "ctcpclienttestupnp13.h" |
|
42 #include "ctcpclienttestupnp14.h" |
|
43 |
|
44 const TUint16 KActivityNull = 0; |
|
45 const TUint KHttpDefaultPort = 80; |
|
46 |
|
47 //Add Blocks of 64 |
|
48 static const TInt KBlockSize1 = 64; |
|
49 static const TInt KMinGrowth1 = 30; |
|
50 static const TInt KThresholdGrowth1 = 30; |
|
51 static const TInt KInitialAllocation1 = 128; |
|
52 |
|
53 static const TInt KHeapSize = 1024 * 1024; //1MB |
|
54 |
|
55 using namespace Messages; |
|
56 |
|
57 |
|
58 //------------------------------------------------------------------------------------------------- |
|
59 // CTcpClientTestBase |
|
60 //------------------------------------------------------------------------------------------------- |
|
61 |
|
62 #define BEGIN_TESTLIST |
|
63 |
|
64 #define ADD_TEST(name) \ |
|
65 if (aTestName == _L(#name))\ |
|
66 {\ |
|
67 return CTcpClient ## name::NewL(aProvd);\ |
|
68 } |
|
69 |
|
70 #define END_TESTLIST \ |
|
71 User::Leave(KErrNotSupported);\ |
|
72 return NULL; |
|
73 |
|
74 CTcpClientTestBase* CTcpClientTestBase::CreateTestL(const TDesC& aTestName, CProxyProvd* aProvd) |
|
75 { |
|
76 BEGIN_TESTLIST |
|
77 ADD_TEST(TestUPnP) |
|
78 ADD_TEST(TestUPnP1) |
|
79 ADD_TEST(TestUPnP2) |
|
80 ADD_TEST(TestUPnP3) |
|
81 ADD_TEST(TestUPnP4) |
|
82 ADD_TEST(TestUPnP5) |
|
83 ADD_TEST(TestUPnP6) |
|
84 ADD_TEST(TestUPnP7) |
|
85 ADD_TEST(TestUPnP8) |
|
86 ADD_TEST(TestUPnP9) |
|
87 ADD_TEST(TestUPnP10) |
|
88 ADD_TEST(TestUPnP11) |
|
89 ADD_TEST(TestUPnP12) |
|
90 ADD_TEST(TestUPnP13) |
|
91 ADD_TEST(TestUPnP14) |
|
92 ADD_TEST(TestUPnP15) |
|
93 ADD_TEST(TestUPnP16) |
|
94 ADD_TEST(TestUPnP17) |
|
95 END_TESTLIST |
|
96 } |
|
97 |
|
98 |
|
99 void CTcpClientTestBase::StartTestL(const TDesC& aTestName, CProxyProvd* aProvd) |
|
100 { |
|
101 CTcpClientTestBase* test = CreateTestL(aTestName,aProvd); |
|
102 CleanupStack::PushL(test); |
|
103 test->CTcpClientTestBase::ConstructL(); |
|
104 CActiveScheduler::Add(test); |
|
105 CleanupStack::Pop(test); |
|
106 TRequestStatus* stat = &test->iStatus; |
|
107 test->SetActive(); |
|
108 User::RequestComplete(stat,KErrNone); |
|
109 } |
|
110 |
|
111 CTcpClientTestBase::CTcpClientTestBase(CProxyProvd* aProvd) : |
|
112 CActive(EPriorityNormal), iState ( ECreateTestServer ), |
|
113 iProvd(aProvd) |
|
114 {} |
|
115 |
|
116 void CTcpClientTestBase::ConstructL() |
|
117 { |
|
118 //Create the Chunk Manager |
|
119 CChunkManager* chkmgr = CChunkManager::NewL ( KHeapSize ); |
|
120 if ( chkmgr ) |
|
121 { |
|
122 chkmgr->AddPoolL ( KBlockSize1, KInitialAllocation1, KMinGrowth1, KThresholdGrowth1 ); |
|
123 } |
|
124 |
|
125 iChunkManager = chkmgr; |
|
126 iAllocator.SetChunkManager(iChunkManager); |
|
127 |
|
128 SetLoggerL(); |
|
129 } |
|
130 |
|
131 CTcpClientTestBase::~CTcpClientTestBase() |
|
132 { |
|
133 Cancel(); |
|
134 iLogger.Close(); |
|
135 delete iChunkManager; |
|
136 } |
|
137 |
|
138 /** Override this function if you want cleanup to happen before the completion of |
|
139 the test case. This function is called before the test is completed |
|
140 */ |
|
141 void CTcpClientTestBase::Cleanup() |
|
142 {} |
|
143 |
|
144 /** Sets the test case as active again and prevents the object from being destroyed |
|
145 when the RunL completes. |
|
146 |
|
147 Note: The active object is not complete the request again automatically, if this behaviour is |
|
148 desired the user must call User::RequestComplete |
|
149 */ |
|
150 void CTcpClientTestBase::Reschedule() |
|
151 { |
|
152 SetActive(); |
|
153 iReschedule = TRUE; |
|
154 } |
|
155 |
|
156 void CTcpClientTestBase::CompleteSelf ( TInt aError ) |
|
157 { |
|
158 TRequestStatus* pStat = &iStatus; |
|
159 User::RequestComplete ( pStat, aError ); |
|
160 } |
|
161 |
|
162 /** Attaches the iLogger variable to the TestExecute Log Server. This enable this prt to write to |
|
163 the testexecute logs as if it were running directly from TestExecute |
|
164 */ |
|
165 // SetLoggerL() is taken directly from CTestServer::StartLoggerL() in the TEF src TestServerBase.Cpp |
|
166 |
|
167 |
|
168 void CTcpClientTestBase::SetLoggerL() |
|
169 { |
|
170 // Create a cinidata object for parsing the testexecute.ini |
|
171 CTestExecuteIniData* parseTestExecuteIni = NULL; |
|
172 TBuf<KMaxTestExecuteNameLength> resultFilePath; |
|
173 TBuf<KMaxTestExecuteNameLength> xmlFilePath; |
|
174 TInt logMode; |
|
175 TInt logLevel; |
|
176 |
|
177 TRAPD(err,parseTestExecuteIni = CTestExecuteIniData::NewL()); |
|
178 if (err == KErrNone) |
|
179 { |
|
180 CleanupStack::PushL(parseTestExecuteIni); |
|
181 parseTestExecuteIni->ExtractValuesFromIni(); |
|
182 parseTestExecuteIni->GetKeyValueFromIni(KTEFHtmlKey, resultFilePath); |
|
183 parseTestExecuteIni->GetKeyValueFromIni(KTEFXmlKey, xmlFilePath); |
|
184 parseTestExecuteIni->GetKeyValueFromIni(KTEFLogMode, logMode); |
|
185 parseTestExecuteIni->GetKeyValueFromIni(KTEFLogSeverityKey, logLevel); |
|
186 } |
|
187 else |
|
188 { |
|
189 resultFilePath.Copy(KTestExecuteLogPath); |
|
190 xmlFilePath.Copy(KTestExecuteLogPath); |
|
191 logMode = TLoggerOptions(ELogHTMLOnly); |
|
192 logLevel = RFileFlogger::TLogSeverity(ESevrAll); |
|
193 } |
|
194 Logger().SetLoggerOptions(logMode); |
|
195 |
|
196 // Initialise a handle to the file logger |
|
197 User::LeaveIfError(Logger().Connect()); |
|
198 RFs fS; |
|
199 User::LeaveIfError(fS.Connect()); |
|
200 CleanupClosePushL(fS); |
|
201 RFile file; |
|
202 TBuf<KMaxTestExecuteNameLength> xmlLogFile(xmlFilePath); |
|
203 TBuf<KMaxTestExecuteNameLength> logFile; |
|
204 TBuf<KMaxTestExecuteNameLength> logFileNameFile(resultFilePath); |
|
205 logFileNameFile.Append(KTestExecuteScheduleTestLogCompatibilityNameFile); |
|
206 if(file.Open(fS,logFileNameFile,EFileRead | EFileShareAny) != KErrNone) |
|
207 { |
|
208 // For the old flogger we have to create an individual file |
|
209 _LIT(KTxtLog,"TEIntSock.txt"); |
|
210 logFile.Copy(KTxtLog); |
|
211 logMode = TLoggerOptions(0); |
|
212 Logger().SetLoggerOptions(logMode); |
|
213 } |
|
214 else |
|
215 { |
|
216 CleanupClosePushL(file); |
|
217 TBuf8<KMaxTestExecuteNameLength> logFile8; |
|
218 TInt fileSize; |
|
219 User::LeaveIfError(file.Size(fileSize)); |
|
220 User::LeaveIfError(file.Read(logFile8,fileSize)); |
|
221 logFile.Copy(logFile8); |
|
222 xmlLogFile.Append(logFile); |
|
223 _LIT(KXmlExtension,".xml"); |
|
224 xmlLogFile.Append(KXmlExtension); |
|
225 _LIT(KHtmExtension,".htm"); |
|
226 logFile.Append(KHtmExtension); |
|
227 CleanupStack::Pop(&file); |
|
228 file.Close(); |
|
229 } |
|
230 TBuf<KMaxTestExecuteLogFilePath> logFilePath(resultFilePath); |
|
231 logFilePath.Append(logFile); |
|
232 CleanupStack::Pop(&fS); |
|
233 fS.Close(); |
|
234 |
|
235 if (logMode == 0 || logMode == 2) |
|
236 { |
|
237 User::LeaveIfError(Logger().HtmlLogger().CreateLog(logFilePath, RTestExecuteLogServ::ELogModeAppend)); |
|
238 } |
|
239 if (logMode == 1 || logMode == 2) |
|
240 { |
|
241 User::LeaveIfError(Logger().XmlLogger().CreateLog(xmlLogFile,RFileFlogger::ELogModeAppend)); |
|
242 Logger().XmlLogger().SetLogLevel(RFileFlogger::TLogSeverity(logLevel)); |
|
243 } |
|
244 if (parseTestExecuteIni != NULL) |
|
245 { |
|
246 CleanupStack::PopAndDestroy(parseTestExecuteIni); |
|
247 } |
|
248 } |
|
249 |
|
250 |
|
251 |
|
252 /** Called by the active scheduler in order to run the test |
|
253 */ |
|
254 void CTcpClientTestBase::RunL() |
|
255 { |
|
256 iReschedule = EFalse; |
|
257 TVerdict res = RunTestL(); |
|
258 if (!iReschedule) |
|
259 { |
|
260 Cleanup(); |
|
261 FinishTest(res); |
|
262 delete this; |
|
263 return; |
|
264 } |
|
265 } |
|
266 |
|
267 void CTcpClientTestBase::FinishTest(TVerdict aResult) |
|
268 { |
|
269 iProvd->TestComplete(aResult); |
|
270 } |
|
271 |
|
272 void CTcpClientTestBase::DoCancel() |
|
273 { |
|
274 Cleanup(); |
|
275 } |
|
276 |
|
277 //------------------------------------------------------------// |
|
278 /////////////////// CTcpClientTestUPnP ///////////////////////// |
|
279 ////// Testcase: Send the test data from the test client///////// |
|
280 //------------------------------------------------------------// |
|
281 const TUint KTransactionCount = 1; |
|
282 _LIT8 ( KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n" ); |
|
283 _LIT8 ( KTxtRawResponse1, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n" ); |
|
284 |
|
285 |
|
286 CTcpClientTestUPnP* CTcpClientTestUPnP::NewL ( CProxyProvd* aProvd ) |
|
287 { |
|
288 CTcpClientTestUPnP* ret = new ( ELeave ) CTcpClientTestUPnP ( aProvd ); |
|
289 CleanupStack::PushL ( ret ); |
|
290 ret->ConstructL (); |
|
291 CleanupStack::Pop ( ret ); |
|
292 return ret; |
|
293 } |
|
294 |
|
295 CTcpClientTestUPnP::CTcpClientTestUPnP ( CProxyProvd* aProvd ) : |
|
296 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
297 { |
|
298 } |
|
299 |
|
300 CTcpClientTestUPnP::~CTcpClientTestUPnP () |
|
301 { |
|
302 iTimer.Close (); |
|
303 } |
|
304 |
|
305 void CTcpClientTestUPnP::ConstructL() |
|
306 { |
|
307 iTimer.CreateLocal (); |
|
308 } |
|
309 |
|
310 TVerdict CTcpClientTestUPnP::RunTestL() |
|
311 { |
|
312 switch ( iState ) |
|
313 { |
|
314 case ECreateTestServer: |
|
315 { |
|
316 iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>")); |
|
317 |
|
318 iTestServer = CTestTcpServer::NewL ( *this ); |
|
319 |
|
320 iState = ECreateTestClient; |
|
321 iStatus = KRequestPending; |
|
322 Reschedule(); |
|
323 return EPass; |
|
324 } |
|
325 |
|
326 case ECreateTestClient: |
|
327 { |
|
328 iLogger.WriteFormat(_L("<i>TestServer is created..... </i>")); |
|
329 iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>")); |
|
330 |
|
331 THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager ); |
|
332 const TUid requestedUid = { CUPnPFlowFactory::iUid }; |
|
333 |
|
334 TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) ); |
|
335 |
|
336 RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () ); |
|
337 |
|
338 iState = ESendRequestData; |
|
339 iStatus = KRequestPending; |
|
340 Reschedule(); |
|
341 return EPass; |
|
342 } |
|
343 |
|
344 case ESendRequestData: |
|
345 { |
|
346 iLogger.WriteFormat(_L("<i>Client is Created</i>")); |
|
347 iLogger.WriteFormat(_L("<i>Send data..... </i>")); |
|
348 |
|
349 RMemChunk bodyBuf; |
|
350 RMemChunk uriBuf; |
|
351 uriBuf.CreateL ( _L8 ("http://127.0.0.1:9999"), iAllocator ); |
|
352 TUpnpMessage::TUPnPClientRequestInfo msg ( HTTP::EGET, uriBuf, bodyBuf, NULL ); |
|
353 iClientId.Node ().ReceivedL ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iClientId ), msg ); |
|
354 |
|
355 iState = ECleanup; |
|
356 iStatus = KRequestPending; |
|
357 Reschedule (); |
|
358 return EPass; |
|
359 } |
|
360 |
|
361 case ECleanup: |
|
362 { |
|
363 delete iTestServer; |
|
364 // cleanup tcp client flow |
|
365 delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () ); |
|
366 iTimer.After ( iStatus, 60000000 ); //10 secs |
|
367 iState = EComplete; |
|
368 iStatus = KRequestPending; |
|
369 Reschedule (); |
|
370 return EPass; |
|
371 } |
|
372 case EComplete: |
|
373 { |
|
374 return EPass; |
|
375 } |
|
376 default: |
|
377 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
378 ASSERT(0); |
|
379 return EFail; |
|
380 } |
|
381 } |
|
382 |
|
383 void CTcpClientTestUPnP::OnTestServerEventL ( TInt aError ) |
|
384 { |
|
385 CompleteSelf ( aError ); |
|
386 } |
|
387 |
|
388 MTcpClientTestCase* CTcpClientTestUPnP::GetTestCase () |
|
389 { |
|
390 return this; |
|
391 } |
|
392 |
|
393 CTestExecuteLogger& CTcpClientTestUPnP::GetLogger ( ) |
|
394 { |
|
395 return iLogger; |
|
396 } |
|
397 |
|
398 |
|
399 void CTcpClientTestUPnP::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
400 { |
|
401 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
402 { |
|
403 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
404 iClientId = msg.iNodeId; |
|
405 CompleteSelf ( KErrNone ); |
|
406 } |
|
407 else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () ) |
|
408 { |
|
409 CompleteSelf ( EPass ); |
|
410 } |
|
411 } |
|
412 |
|
413 const TDesC& CTcpClientTestUPnP::TestCaseName () const |
|
414 { |
|
415 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
416 return KTxtTitle (); |
|
417 } |
|
418 |
|
419 TInt CTcpClientTestUPnP::TotalTransactionCount () const |
|
420 { |
|
421 return KTransactionCount; |
|
422 } |
|
423 |
|
424 const TDesC8& CTcpClientTestUPnP::GetRawRequest ( TInt aTransIndex ) |
|
425 { |
|
426 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
427 return KTxtRawRequest (); |
|
428 } |
|
429 |
|
430 const TDesC8& CTcpClientTestUPnP::GetRawResponse ( TInt aTransIndex ) |
|
431 { |
|
432 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
433 return KTxtRawResponse1 (); |
|
434 } |
|
435 TInt CTcpClientTestUPnP::TransactionCount () const |
|
436 { |
|
437 return KTransactionCount; |
|
438 } |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |