|
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 // Contains implementation of CTestHttpServer class |
|
15 // @internalAll |
|
16 // |
|
17 // |
|
18 |
|
19 // User Includes |
|
20 // Test Server |
|
21 #include "testhttpserver.h" |
|
22 |
|
23 // Test steps |
|
24 #include "testhttpbasestep.h" |
|
25 #include "testhttpeboclientstep.h" |
|
26 #include "testhttpeboclientconditionalstep.h" |
|
27 #include "testhttpbuffersizestep.h" |
|
28 #include "testexplicitsessionstep.h" |
|
29 #include "testhttpfiltersuspendstep.h" |
|
30 |
|
31 #if (!defined EKA2) |
|
32 // The system-wide unique name for the test-server |
|
33 _LIT(KServerName, "TestHttpServer"); |
|
34 #endif |
|
35 |
|
36 /** |
|
37 Static factory constructor. Creates and returns instance of the test server |
|
38 @internalTechnology |
|
39 @test |
|
40 @return A pointer to the newly created CTestHttpServer object |
|
41 */ |
|
42 CTestHttpServer* CTestHttpServer::NewL() |
|
43 { |
|
44 // Construct the server |
|
45 CTestHttpServer* server = new(ELeave) CTestHttpServer(); |
|
46 CleanupStack::PushL(server); |
|
47 |
|
48 // CServer base class call |
|
49 // Name the server using the system-wide unique string |
|
50 // Clients use this to create server sessions. |
|
51 server->StartL(server->ServerName()); |
|
52 |
|
53 CleanupStack::Pop(server); |
|
54 return server; |
|
55 } |
|
56 |
|
57 |
|
58 #if (!defined EKA2) |
|
59 /** |
|
60 Creates the Active Scheduler, then creates the test-server, synchronises the |
|
61 thread with the client and then enters the active scheduler. |
|
62 |
|
63 This is EKA1 version of MainL(). Uses sempahore to sync with client |
|
64 as Rendezvous calls are not available |
|
65 */ |
|
66 LOCAL_C void MainL() |
|
67 { |
|
68 // Create and install the active scheduler. |
|
69 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
70 CleanupStack::PushL(sched); |
|
71 CActiveScheduler::Install(sched); |
|
72 |
|
73 // Create the server inside trap harness |
|
74 CTestHttpServer *server = NULL; |
|
75 TRAPD(err, server = CTestHttpServer::NewL()); |
|
76 if (!err) |
|
77 { |
|
78 CleanupStack::PushL(server); |
|
79 RSemaphore sem; |
|
80 |
|
81 // The client API of TestExecute will already have created the |
|
82 // semaphore and will be waiting on it. |
|
83 User::LeaveIfError(sem.OpenGlobal(KServerName)); |
|
84 |
|
85 CleanupStack::Pop(server); |
|
86 |
|
87 // Signal the client |
|
88 sem.Signal(); |
|
89 sem.Close(); |
|
90 |
|
91 // Enter the active scheduler |
|
92 sched->Start(); |
|
93 } |
|
94 CleanupStack::PopAndDestroy(); // sched |
|
95 delete server; |
|
96 |
|
97 } |
|
98 #else |
|
99 /** |
|
100 EKA2 version of MainL() |
|
101 Uses the new Rendezvous call isntead of the older semaphore. |
|
102 */ |
|
103 LOCAL_C void MainL() |
|
104 { |
|
105 // For platform security |
|
106 #if (defined __DATA_CAGING__) |
|
107 RProcess().DataCaging(RProcess::EDataCagingOn); |
|
108 RProcess().SecureApi(RProcess::ESecureApiOn); |
|
109 #endif |
|
110 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
111 CActiveScheduler::Install(sched); |
|
112 CTestHttpServer* server = NULL; |
|
113 |
|
114 // Create the test-server |
|
115 TRAPD(err, server = CTestHttpServer::NewL()); |
|
116 |
|
117 if(!err) |
|
118 { |
|
119 // Sync with the client and enter the active scheduler |
|
120 RProcess::Rendezvous(KErrNone); |
|
121 sched->Start(); |
|
122 } |
|
123 delete server; |
|
124 delete sched; |
|
125 } |
|
126 #endif // #if (!defined EKA2) |
|
127 |
|
128 |
|
129 #if (defined __WINS__ && !defined EKA2) |
|
130 /** |
|
131 DLL entry-point for EKA1 emulator builds. |
|
132 */ |
|
133 GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/) |
|
134 { |
|
135 return KErrNone; |
|
136 } |
|
137 #else |
|
138 /** |
|
139 Exe entry point code, for EKA1 hardware and EKA2 builds. |
|
140 */ |
|
141 GLDEF_C TInt E32Main() |
|
142 { |
|
143 __UHEAP_MARK; |
|
144 CTrapCleanup *cleanup = CTrapCleanup::New(); |
|
145 if (cleanup == NULL) |
|
146 { |
|
147 return KErrNoMemory; |
|
148 } |
|
149 |
|
150 TRAPD(err, MainL()); |
|
151 __ASSERT_ALWAYS(!err,User::Panic(KTxt,err)); |
|
152 delete cleanup; |
|
153 __UHEAP_MARKEND; |
|
154 return KErrNone; |
|
155 } |
|
156 #endif // #if (defined __WINS__ && !defined EKA2) |
|
157 |
|
158 #if (defined __WINS__ && !defined EKA2) |
|
159 /** |
|
160 For EKA1 emulator builds. This function is called when the thread is first |
|
161 resumed. Has the standard thread entry siganture. |
|
162 @internalTechnology |
|
163 @test |
|
164 @return KErrNone if everything is fine or system-wide error if any |
|
165 */ |
|
166 TInt ThreadFunc (TAny* /*aParam*/) |
|
167 { |
|
168 __UHEAP_MARK; |
|
169 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
170 if (cleanup == NULL) |
|
171 { |
|
172 return KErrNoMemory; |
|
173 } |
|
174 TRAPD(err, MainL()); |
|
175 __ASSERT_ALWAYS(!err,User::Panic(KTxt,err)); |
|
176 delete cleanup; |
|
177 __UHEAP_MARKEND; |
|
178 return KErrNone; |
|
179 } |
|
180 |
|
181 /** |
|
182 For EKA1 emulator builds. Creates and starts a thread for the server to run. |
|
183 @internalTechnology |
|
184 @test |
|
185 @param None |
|
186 @return Integer value indicating the error code. |
|
187 */ |
|
188 EXPORT_C TInt NewServer() |
|
189 { |
|
190 _LIT(KThread, "Thread"); |
|
191 RThread thread; |
|
192 |
|
193 // Name the thread as "<Server-Name>Thread" making it hopefully unique |
|
194 TBuf<KMaxTestExecuteNameLength> threadName(KServerName); |
|
195 threadName.Append(KThread); |
|
196 |
|
197 const TInt KMaxHeapSize = 0x1000000; |
|
198 |
|
199 // Create the thread |
|
200 TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize, |
|
201 KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess |
|
202 ); |
|
203 if (err != KErrNone) |
|
204 { |
|
205 return err; |
|
206 } |
|
207 |
|
208 // Start the thread -> effectively calls ThreadFunc |
|
209 thread.Resume(); |
|
210 |
|
211 thread.Close(); |
|
212 return KErrNone; |
|
213 } |
|
214 #endif // #if (defined __WINS__ && !defined EKA2) |
|
215 |
|
216 |
|
217 /** |
|
218 Base class pure virtual |
|
219 @internalTechnology |
|
220 @test |
|
221 @return Instance of the test step |
|
222 @param Descriptor containing the test-step name |
|
223 */ |
|
224 CTestStep* CTestHttpServer::CreateTestStep(const TDesC& aStepName) |
|
225 { |
|
226 CTestStep *testStep = NULL; |
|
227 TRAPD(err,testStep=CreateTestStepL(aStepName)); |
|
228 if(err == KErrNone) |
|
229 return testStep; |
|
230 else |
|
231 return NULL; |
|
232 } |
|
233 |
|
234 |
|
235 CTestStep* CTestHttpServer::CreateTestStepL(const TDesC& aStepName) |
|
236 { |
|
237 CTestStep *testStep = NULL; |
|
238 |
|
239 if (aStepName == KTestHttpEboClientStep) |
|
240 { |
|
241 testStep = new (ELeave) CHttpEboClientStep(); |
|
242 } |
|
243 else if (aStepName == KTestHttpEboClientConditionalStep) |
|
244 { |
|
245 testStep = new (ELeave) CHttpEboClientConditionalStep(); |
|
246 } |
|
247 else if ( aStepName == KTestHttpBufferSizeStep ) |
|
248 { |
|
249 testStep = new (ELeave) CTestHttpBufferSizeStep(); |
|
250 } |
|
251 else if ( aStepName == KTestExplicitSessionStep ) |
|
252 { |
|
253 testStep = new (ELeave) CTestExplicitSessionStep(); |
|
254 } |
|
255 else if ( aStepName == KTestHttpFilterSuspendStep ) |
|
256 { |
|
257 testStep = new (ELeave) CTestHttpFilterSuspendStep(); |
|
258 } |
|
259 |
|
260 return testStep; |
|
261 } |
|
262 |
|
263 /** |
|
264 Returns server name based on the EKA version |
|
265 @internalTechnology |
|
266 @test |
|
267 @return Descriptor containing the servername |
|
268 */ |
|
269 const TPtrC CTestHttpServer::ServerName() |
|
270 { |
|
271 #if (!defined EKA2) |
|
272 return KServerName(); |
|
273 #else |
|
274 // The exe name can be either TestWListBListUriServer or |
|
275 // TestWListBListUriServer_Cap based on whether the normal |
|
276 // or the security tests are being run. So decide the server |
|
277 // name during runtime |
|
278 TParsePtrC serverName(RProcess().FileName()); |
|
279 return serverName.Name(); |
|
280 #endif |
|
281 } |