|
1 // Copyright (c) 2003-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 classes: CTestEngine |
|
15 // |
|
16 // |
|
17 |
|
18 #include "ctestengine.h" |
|
19 #if !defined __CTESTMESSAGECOMPOSER_H__ |
|
20 #include "ctestmessagecomposer.h" |
|
21 #endif |
|
22 #if !defined CTESTMESSAGEPARSER_H_ |
|
23 #include "ctestmessageparser.h" |
|
24 #endif |
|
25 |
|
26 #define KTestRequestHeader _L8("HTTP MESSAGE PERFORMANCE LOGGER\n\n\n") |
|
27 |
|
28 _LIT(KFilePath, "c:\\logs\\http\\"); |
|
29 _LIT(KFileName, "c:\\logs\\http\\msg_peformance_logger.txt"); |
|
30 _LIT(KTestHttpMessageComposer,"Composing HTTP Request Message \n \n \n"); |
|
31 _LIT(KTestHttpMessageParser,"Parsing HTTP Response Message \n \n \n"); |
|
32 _LIT(KTestHttpMessagePeformanceTitle, "HTTP Message Performance Test Harness"); |
|
33 CTestEngine* CTestEngine::NewL() |
|
34 { |
|
35 CTestEngine* self = new (ELeave) CTestEngine(); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTestEngine::~CTestEngine() |
|
43 { |
|
44 delete iTestUtils; |
|
45 } |
|
46 |
|
47 const TDesC& CTestEngine::TestName() |
|
48 { |
|
49 _LIT(KTestName, "HTTP message Test"); |
|
50 return KTestName; |
|
51 } |
|
52 CTestEngine::CTestEngine() |
|
53 { |
|
54 iStartTime = 0; |
|
55 iEndTime = 0; |
|
56 } |
|
57 |
|
58 void CTestEngine::ConstructL() |
|
59 { |
|
60 iTestUtils = CHTTPTestUtils::NewL(KTestHttpMessagePeformanceTitle()); |
|
61 iTestUtils->InitCommsL(); |
|
62 } |
|
63 |
|
64 void CTestEngine::DoRunL() |
|
65 { |
|
66 |
|
67 } |
|
68 void CTestEngine::DoCancel() |
|
69 { |
|
70 } |
|
71 void CTestEngine::RunTestsL() |
|
72 { |
|
73 //Tests for composer |
|
74 iTestUtils->StartTestL(_L("Test 1 for composition of http message having multiple Headers with no body")); |
|
75 TestComposeMessageL(1); |
|
76 iTestUtils->EndTest(iTestFailed); |
|
77 iTestUtils->StartTestL(_L("Test 2 for composition of http message having 8 Headers with no body")); |
|
78 TestComposeMessageL(2); |
|
79 iTestUtils->EndTest(iTestFailed); |
|
80 //Tests for parser |
|
81 iTestUtils->StartTestL(_L("Test 1 for http message parser")); |
|
82 //Message to be parsed : "HTTP/1.1 200 OK\r\nDate: Tue, 04 Aug 2009 10:49:50 GMT\r\nServer: Apache/2.2.11 (Unix)\r\nLast-Modified: Thu, 16 Jul 2009 12:06:00 GMT\r\nETag: 4c0f49-329-46ed17eb73a00 \r\nAccept-Ranges: bytes\r\n\r\n " |
|
83 TestParseMessageL(1); |
|
84 iTestUtils->EndTest(iTestFailed); |
|
85 iTestUtils->StartTestL(_L("Test 2 for http message parser")); |
|
86 //Message to be parsed : "HTTP/1.1 200 OK\r\nDate: Tue, 04 Aug 2009 10:49:59 GMT\r\nServer: Apache/2.2.11 (Unix)\r\nLast-Modified: Thu, 16 Jul 2009 12:06:00 GMT\r\nETag: 4c134b-cbc-46ed17eb73a00 \r\nAccept-Ranges: bytes\r\nContent-Length: 3260\r\nKeep-Alive: timeout=5, max=88\r\nConnection: Keep-Alive\r\nContent-Type: image/png\r\n\r\n " |
|
87 TestParseMessageL(2); |
|
88 iTestUtils->EndTest(iTestFailed); |
|
89 iTestUtils->StartTestL(_L("Test 3 for http message parser")); |
|
90 //Message to be parsed : "HTTP/1.1 200 OK\r\nDate: Tue, 04 Aug 2009 10:49:59 GMT\r\nServer: Apache\r\nConnection: Close\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html\r\n\r\n " |
|
91 TestParseMessageL(3); |
|
92 iTestUtils->EndTest(iTestFailed); |
|
93 iTestUtils->StartTestL(_L("Test 4 for http message parser")); |
|
94 //Message to be parsed : "HTTP/1.1 200 OK\r\nDate: Tue, Date: Tue, 22 Sep 2009 04:27:56 GMT\r\nServer: Apache\r\nContent-Encoding: gzip\r\nContent-Length: 6355\r\nContent-Type: text/html\r\nExpires: Tue, 22 Sep 2009 04:27:56 GMT\r\nCache-Control: max-age=0, no-cache\r\nPragma: no-cache\r\nConnection: close\r\nVary: Accept-Encoding\r\n\r\n " |
|
95 TestParseMessageL(4); |
|
96 iTestUtils->EndTest(iTestFailed); |
|
97 } |
|
98 |
|
99 void CTestEngine::TestComposeMessageL(TInt aNumberofHeaders) |
|
100 { |
|
101 iTestFailed = EFalse; |
|
102 CTestMessageComposer* messagecomposer = CTestMessageComposer::NewL(*this); |
|
103 CleanupStack::PushL(messagecomposer); |
|
104 messagecomposer->SetHeaderL(aNumberofHeaders); |
|
105 StartTimer(); |
|
106 messagecomposer->StartRequest(); |
|
107 CActiveScheduler::Start(); |
|
108 EndTimer(KTestHttpMessageComposer); |
|
109 CleanupStack::PopAndDestroy(messagecomposer); |
|
110 } |
|
111 |
|
112 void CTestEngine::TestParseMessageL(TInt aMessageType) |
|
113 { |
|
114 CTestMessageParser* messageparser = CTestMessageParser::NewL(*this); |
|
115 CleanupStack::PushL(messageparser); |
|
116 StartTimer(); |
|
117 messageparser->StartRequest(aMessageType); |
|
118 CActiveScheduler::Start(); |
|
119 EndTimer(KTestHttpMessageParser); |
|
120 CleanupStack::PopAndDestroy(messageparser); |
|
121 } |
|
122 |
|
123 void CTestEngine::NotifyError(TInt /*aError*/) |
|
124 { |
|
125 } |
|
126 |
|
127 void CTestEngine::NotifyStart() |
|
128 { |
|
129 } |
|
130 |
|
131 void CTestEngine::NotifyComplete() |
|
132 { |
|
133 CActiveScheduler::Stop(); |
|
134 } |
|
135 |
|
136 void CTestEngine::LogIt(const TDesC& aComment) |
|
137 { |
|
138 TInt err = iFs.Connect(); |
|
139 if(err == KErrNone) |
|
140 { |
|
141 iFs.MkDirAll(KFilePath); |
|
142 err = iFile.Open(iFs, KFileName, EFileWrite); |
|
143 if(err == KErrNotFound) |
|
144 { |
|
145 iFile.Create(iFs, KFileName, EFileWrite); |
|
146 iFile.Write(KTestRequestHeader); |
|
147 } |
|
148 TFileText file; |
|
149 file.Set(iFile); |
|
150 file.Write(aComment); |
|
151 iFile.Close(); |
|
152 iFs.Close(); |
|
153 } |
|
154 else |
|
155 { |
|
156 User::InfoPrint(_L("Cannot write to file")); |
|
157 } |
|
158 } |
|
159 |
|
160 void CTestEngine::StartTimer() |
|
161 { |
|
162 iStartTime = User::FastCounter(); |
|
163 } |
|
164 |
|
165 void CTestEngine::EndTimer(const TDesC& aComment) |
|
166 { |
|
167 iEndTime = User::FastCounter(); |
|
168 iTimeDifference = iEndTime-iStartTime; |
|
169 _LIT(KTimeDiff, ",%ld microseconds\n"); |
|
170 RBuf myBuf; |
|
171 myBuf.Create (aComment.Length()+64); |
|
172 myBuf.Append (aComment ); |
|
173 myBuf.AppendFormat(KTimeDiff, iTimeDifference.Int64()); |
|
174 LogIt(myBuf); |
|
175 myBuf.Close(); |
|
176 iStartTime = 0; |
|
177 iEndTime = 0; |
|
178 } |
|
179 |
|
180 |