|
1 // Copyright (c) 1997-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 // PARAM_MESS_NAME_CStep.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 //Test Step header |
|
21 #include "PARAM_MESS_NAME_CStep.h" |
|
22 |
|
23 |
|
24 //TO BE SAFE |
|
25 IMPORT_C TInt StartDialogThread(); |
|
26 |
|
27 CPARAM_MESS_NAMEStep::CPARAM_MESS_NAMEStep() |
|
28 /** Each test step initialises it's own name |
|
29 */ |
|
30 { |
|
31 // store the name of this test case |
|
32 // this is the name that is used by the script file |
|
33 //DEF iTestStepName = _L("CPARAM_MESS_NAMEStep"); |
|
34 |
|
35 //The server name and IPC number is obtained and all messages are checked Sync |
|
36 SR_ServerName = _L("PARAM_SVR_NAME"); |
|
37 SR_MESSAGE_TYPE = 2; |
|
38 SR_MESSAGE_ID = PARAM_MESS_VALUE; |
|
39 SR_MESSAGE_MASK = PARAM_MESS_CAPMASK; |
|
40 |
|
41 //The iServer_Panic is a unique name from Server,but always truncated to KMaxExitCategoryName |
|
42 |
|
43 iServer_Panic = _L("PARAM_SVR_T16_PANIC"); |
|
44 |
|
45 TCapability cap[] = {ECapabilityPARAM_MESS_NAMECAP, ECapability_Limit}; |
|
46 |
|
47 TSecurityInfo info; |
|
48 info.Set(RProcess()); |
|
49 TBool result = EFalse; |
|
50 |
|
51 for (TInt i = 0; cap[i] != ECapability_Limit; i++) |
|
52 { |
|
53 |
|
54 if (!(info.iCaps.HasCapability(cap[i]))) |
|
55 { |
|
56 result=ETrue; |
|
57 |
|
58 } |
|
59 |
|
60 } |
|
61 |
|
62 iQueryBundle = CConnectionServParameterBundle::NewL(); |
|
63 iQueryBuffer.Create(1024); |
|
64 iResultBuffer.Create(1024); |
|
65 iBadBuffer.Create(4); |
|
66 |
|
67 iExpect_Rejection = result; |
|
68 iStepCap = PARAM_MESS_CAPMASK; |
|
69 |
|
70 //Get a unique thread name |
|
71 ChildThread_SR.Format(_L("ChildThread_%S_%d"),&SR_ServerName,SR_MESSAGE_ID); |
|
72 |
|
73 } |
|
74 |
|
75 /* |
|
76 Exec_SendReceive(): |
|
77 This Fn is called by the Child Thread |
|
78 1. Create a session with the server |
|
79 2. Test an SendReceive call |
|
80 3. Informs the main thread about the status of the call using |
|
81 a. iSessionCreated, if the a connection is established |
|
82 b. iResult_Server, holds the return value for connection |
|
83 c. iResult_SR, the return value of SendReceive call |
|
84 */ |
|
85 TInt CPARAM_MESS_NAMEStep::Exec_SendReceive() |
|
86 { |
|
87 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
88 _LIT(KEsockSessStartMutex,"KESSMTX"); //Keep the descriptor short |
|
89 RMutex mutex; |
|
90 TInt r; |
|
91 // Protect the openning of the session |
|
92 // with a mutex to stop thread collision |
|
93 FOREVER |
|
94 { |
|
95 r = mutex.CreateGlobal(KEsockSessStartMutex()); |
|
96 if (r == KErrNone) |
|
97 break; |
|
98 if (r != KErrAlreadyExists) |
|
99 return r; |
|
100 r=mutex.OpenGlobal(KEsockSessStartMutex()); |
|
101 if (r == KErrNone) |
|
102 break; |
|
103 if (r != KErrNotFound) |
|
104 return r; |
|
105 } |
|
106 mutex.Wait(); // the exclusion ensures the session is started atomically |
|
107 iResult_Server=CreateSession(SR_ServerName,TVersion(),2); |
|
108 // Because ESock is now loaded by the Comms Root Server which is generally started during |
|
109 // the boot this should commonly succeed; however for test code this is still a possibility |
|
110 // Hence here we try starting it; this is an atomic operation (and cheap if it's already started) |
|
111 if (iResult_Server==KErrNotFound) |
|
112 { |
|
113 r=StartC32(); |
|
114 if (r==KErrNone || r==KErrAlreadyExists) |
|
115 { |
|
116 iResult_Server=CreateSession(SR_ServerName,Version(),2); |
|
117 } |
|
118 } |
|
119 |
|
120 mutex.Signal(); |
|
121 mutex.Close(); |
|
122 |
|
123 if(iResult_Server==KErrNone) |
|
124 { |
|
125 iSessionCreated = ETrue; |
|
126 const TInt test_id = dispatch_num<PARAM_MESS_VALUE>::result; |
|
127 if(SR_MESSAGE_ID >= 0) |
|
128 iResult_SR = do_execute(Int2Type<test_id>()); |
|
129 } |
|
130 delete cleanup; |
|
131 return iResult_Server; |
|
132 } |
|
133 |
|
134 |
|
135 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointStatusQuery_Cancel>) |
|
136 // testing the ECMAccessPointStatusQuery_Cancel IPC message |
|
137 { |
|
138 return SendReceive(ECMAccessPointStatusQuery_Cancel,TIpcArgs(0,0,0,0)); |
|
139 } |
|
140 |
|
141 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointNotification_SetupThenAwaitThenGetResultOrSize>) |
|
142 // testing the ECMAccessPointNotification_SetupThenAwaitThenGetResultOrSize IPC message |
|
143 { |
|
144 return SendReceive(ECMAccessPointNotification_SetupThenAwaitThenGetResultOrSize,TIpcArgs(0,0,0,0)); |
|
145 } |
|
146 |
|
147 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointNotification_AwaitThenGetResultOrSize>) |
|
148 // testing the ECMAccessPointNotification_AwaitThenGetResultOrSize IPC message |
|
149 { |
|
150 // connect with server |
|
151 TInt err = ConnectToServer(); |
|
152 if(err != KErrNone) |
|
153 { |
|
154 return err; |
|
155 } |
|
156 TRequestStatus status; |
|
157 // Make Notification Query reques, this is the setup for the ECMAccessPointNotification_AwaitThenGetResultOrSize |
|
158 TRAP(err,NotificationQueryL(status,iResultBuffer, ENotificationStepTwo)); |
|
159 if(err != KErrNone) |
|
160 { |
|
161 return err; |
|
162 } |
|
163 User::WaitForRequest(status); |
|
164 if(status.Int() != KErrNone) |
|
165 { |
|
166 return status.Int(); |
|
167 } |
|
168 // load the result buffer |
|
169 TRAP(err, CConnectionServParameterBundle *bundle = CConnectionServParameterBundle::LoadL(iResultBuffer)); |
|
170 if(err != KErrNone) |
|
171 { |
|
172 return err; |
|
173 } |
|
174 // make ECMAccessPointNotification_AwaitThenGetResultOrSize request then start a connection in order for request to complete |
|
175 SendReceive(ECMAccessPointNotification_AwaitThenGetResultOrSize,TIpcArgs(0,&iResultBuffer,0,iSessionRef), status); |
|
176 OpenConn(); |
|
177 err = iConn.Start(); |
|
178 if(err != KErrNone) |
|
179 { |
|
180 return err; |
|
181 } |
|
182 User::WaitForRequest(status); |
|
183 // make ECMAccessPointNotification_AwaitThenGetResultOrSize request then cancel the notification request |
|
184 SendReceive(ECMAccessPointNotification_AwaitThenGetResultOrSize,TIpcArgs(0,&iBadBuffer,0,iSessionRef), status); |
|
185 SendReceive(ECMAccessPointNotification_Cancel,TIpcArgs(0,0,0,iSessionRef), status); |
|
186 User::WaitForRequest(status); |
|
187 return status.Int(); |
|
188 } |
|
189 |
|
190 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointNotification_GetResult>) |
|
191 { |
|
192 // connect to server |
|
193 TInt err = ConnectToServer(271064565); |
|
194 if(err != KErrNone) |
|
195 { |
|
196 return err; |
|
197 } |
|
198 TRequestStatus status; |
|
199 // Make Notification Query request, this is the setup for the ECMAccessPointNotification_AwaitThenGetResultOrSize |
|
200 // using result buffer that is too small, will cause error after ECMAccessPointNotification_AwaitThenGetResultOrSize |
|
201 TRAP(err,NotificationQueryL(status,iBadBuffer, ENotificationStepTwo)); |
|
202 if(err != KErrNone) |
|
203 { |
|
204 return err; |
|
205 } |
|
206 User::WaitForRequest(status); |
|
207 // make ECMAccessPointNotification_AwaitThenGetResultOrSize request then start a connection in order for request to complete |
|
208 SendReceive(ECMAccessPointNotification_AwaitThenGetResultOrSize,TIpcArgs(0,&iBadBuffer,0,iSessionRef), status); |
|
209 OpenConn(); |
|
210 err = iConn.Start(); |
|
211 if(err != KErrNone) |
|
212 { |
|
213 return err; |
|
214 } |
|
215 User::WaitForRequest(status); |
|
216 iConn.Stop(); |
|
217 // should return an error due to had buffer |
|
218 TRAP(err, CConnectionServParameterBundle *bundle = CConnectionServParameterBundle::LoadL(iResultBuffer)); |
|
219 if(err != KErrNone) |
|
220 { |
|
221 return err; |
|
222 } |
|
223 // Now get result with a buffer of correct size |
|
224 SendReceive(ECMAccessPointNotification_GetResult,TIpcArgs(0,&iResultBuffer,0,iSessionRef), status); |
|
225 User::WaitForRequest(status); |
|
226 if(status.Int() != KErrNone ) |
|
227 { |
|
228 return status.Int(); |
|
229 } |
|
230 // cancel notification request |
|
231 SendReceive(ECMAccessPointNotification_AwaitThenGetResultOrSize,TIpcArgs(0,&iBadBuffer,0,iSessionRef), status); |
|
232 SendReceive(ECMAccessPointNotification_Cancel,TIpcArgs(0,0,0,iSessionRef), status); |
|
233 User::WaitForRequest(status); |
|
234 return status.Int(); |
|
235 } |
|
236 |
|
237 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointNotification_Cancel>) |
|
238 { |
|
239 // connect to server |
|
240 TInt err = ConnectToServer(); |
|
241 if(err != KErrNone) |
|
242 { |
|
243 return err; |
|
244 } |
|
245 TRequestStatus status; |
|
246 // Make Notification Query request, this is the setup for the ECMAccessPointNotification_AwaitThenGetResultOrSize |
|
247 TRAP(err, NotificationQueryL(status, iResultBuffer)); |
|
248 if(err != KErrNone) |
|
249 { |
|
250 return err; |
|
251 } |
|
252 User::WaitForRequest(status); |
|
253 if(status.Int()!= KErrNone) |
|
254 { |
|
255 return err; |
|
256 } |
|
257 // cancel the request |
|
258 SendReceive(ECMAccessPointNotification_Cancel,TIpcArgs(0,0,0,iSessionRef), status); |
|
259 User::WaitForRequest(status); |
|
260 return status.Int(); |
|
261 } |
|
262 |
|
263 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMCreate>) |
|
264 // testing the ECMCreate IPC message |
|
265 { |
|
266 return SendReceive(ECMCreate,TIpcArgs(0,0,0,0)); |
|
267 } |
|
268 |
|
269 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMClose>) |
|
270 // testing the ECMClose IPC message |
|
271 { |
|
272 return SendReceive(ECMClose,TIpcArgs(0,0,0,0)); |
|
273 } |
|
274 |
|
275 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAttachToTierManager>) |
|
276 // testing the ECMAttachToTierManager IPC message |
|
277 { |
|
278 return SendReceive(ECMAttachToTierManager,TIpcArgs(0,0,0,0)); |
|
279 } |
|
280 |
|
281 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointStatusQuery_DoThenGetResultOrSize>) |
|
282 // testing the ECMAccessPointStatusQuery_DoThenGetResultOrSize IPC message |
|
283 { |
|
284 return SendReceive(ECMAccessPointStatusQuery_DoThenGetResultOrSize,TIpcArgs(0,0,0,0)); |
|
285 } |
|
286 |
|
287 TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<ECMAccessPointStatusQuery_GetResult>) |
|
288 { |
|
289 // connect to server with specified tier |
|
290 TInt err = ConnectToServer(271064565); |
|
291 if(err != KErrNone) |
|
292 { |
|
293 return err; |
|
294 } |
|
295 |
|
296 // make an access point query with a buffer that is too small to hold the result |
|
297 TRAP(err, |
|
298 AccessPointQuery(iBadBuffer); |
|
299 CConnectionServParameterBundle *bundle = CConnectionServParameterBundle::LoadL(iResultBuffer); |
|
300 ); |
|
301 if(err != KErrNone) |
|
302 { |
|
303 return err; |
|
304 } |
|
305 TRequestStatus status; |
|
306 // get result with a buffer of sufficient size |
|
307 SendReceive(ECMAccessPointStatusQuery_GetResult,TIpcArgs(&iResultBuffer), status); |
|
308 User::WaitForRequest(status); |
|
309 return status.Int(); |
|
310 } |
|
311 |
|
312 |
|
313 TInt CPARAM_MESS_NAMEStep::ConnectToServer(TUint aTierId) |
|
314 // connect to the RConnServer with specified Tier Uid |
|
315 { |
|
316 TInt result; |
|
317 TPckgBuf<TInt> session(iSessionRef); |
|
318 result = SendReceive(ECMAttachToTierManager,TIpcArgs(aTierId, &session)); |
|
319 iSessionRef = session(); //-- this is the subsession handle |
|
320 return result; |
|
321 } |
|
322 |
|
323 TInt CPARAM_MESS_NAMEStep::AccessPointQuery(RBuf8& aBuf) |
|
324 // Make access point status query |
|
325 { |
|
326 // build a query |
|
327 TAccessPointStatusFilter filter = BuildQuery(); |
|
328 TRAPD(err, AddFilterToQueryL(*iQueryBundle, filter)); |
|
329 if(err != KErrNone) |
|
330 { |
|
331 return err; |
|
332 } |
|
333 err = iQueryBundle->Store(iQueryBuffer); |
|
334 if(err != KErrNone) |
|
335 { |
|
336 return err; |
|
337 } |
|
338 |
|
339 TRequestStatus status; |
|
340 SendReceive(ECMAccessPointStatusQuery_DoThenGetResultOrSize, TIpcArgs(&iQueryBuffer, &aBuf, 0,iSessionRef),status); |
|
341 User::WaitForRequest(status); |
|
342 return status.Int(); |
|
343 } |
|
344 |
|
345 TAccessPointStatusFilter CPARAM_MESS_NAMEStep::BuildQuery(TFilterType aType) |
|
346 // Build a query |
|
347 { |
|
348 TAccessPointStatusFilter filter; |
|
349 switch(aType) |
|
350 { |
|
351 case ENotificationStepTwo : |
|
352 filter.Configured(EAccessPointFlagIgnore); |
|
353 filter.Restricted(EAccessPointFlagIgnore); |
|
354 filter.Available(EAccessPointFlagIgnore); |
|
355 filter.Started(EAccessPointFlagMatchTrue); |
|
356 break; |
|
357 default : |
|
358 filter.Configured(EAccessPointFlagMatchTrue); |
|
359 filter.Restricted(EAccessPointFlagMatchAny); |
|
360 filter.Available(EAccessPointFlagIgnore); |
|
361 filter.Started(EAccessPointFlagIgnore); |
|
362 break; |
|
363 }; |
|
364 return filter; |
|
365 } |
|
366 |
|
367 void CPARAM_MESS_NAMEStep::AddFilterToQueryL(CConnectionServParameterBundle& aBundle,TAccessPointStatusFilter& aFilter ) |
|
368 // Add a filter to the query |
|
369 { |
|
370 aBundle.AddMatchConditionL(aFilter); |
|
371 aBundle.AddParameterSetToReturnL(XAccessPointGenericParameterSet::Type()); |
|
372 } |
|
373 |
|
374 void CPARAM_MESS_NAMEStep::NotificationQueryL(TRequestStatus& aStatus, RBuf8& aBuf, TFilterType aFilterType) |
|
375 // Make access point Notification query |
|
376 { |
|
377 TAccessPointStatusFilter filter = BuildQuery(aFilterType); |
|
378 AddFilterToQueryL(*iQueryBundle, filter); |
|
379 User::LeaveIfError(iQueryBundle->Store(iQueryBuffer)); |
|
380 SendReceive(ECMAccessPointNotification_SetupThenAwaitThenGetResultOrSize, TIpcArgs(&iQueryBuffer, &aBuf, 0,iSessionRef),aStatus); |
|
381 } |
|
382 |
|
383 TInt CPARAM_MESS_NAMEStep::OpenConn() |
|
384 // Open an rconnection |
|
385 { |
|
386 TInt err = iSockServ.Connect(); |
|
387 if(err != KErrNone) |
|
388 { |
|
389 return err; |
|
390 } |
|
391 return iConn.Open(iSockServ); |
|
392 } |
|
393 |