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