|
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 the License "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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <e32def.h> |
|
18 #include <e32def_private.h> |
|
19 |
|
20 #include <d32resmanus.h> |
|
21 |
|
22 #ifdef PRM_ENABLE_EXTENDED_VERSION |
|
23 #define LDD_NAME _L("resourcecontrollerextended.ldd") |
|
24 #else |
|
25 #define LDD_NAME _L("resourcecontrol.ldd") |
|
26 #endif |
|
27 |
|
28 #ifdef PRM_ENABLE_EXTENDED_VERSION |
|
29 #define PDD_NAME _L("resourcecontrollerextended.pdd") |
|
30 #else |
|
31 #define PDD_NAME _L("resourcecontroller.pdd") |
|
32 #endif |
|
33 |
|
34 //#define PIRATE_THREAD_TESTS |
|
35 |
|
36 _LIT(testableResourceName,"SymbianSimulResource"); |
|
37 |
|
38 #ifdef RESMANUS_KERN |
|
39 _LIT(testName,"t_resmanuskern"); |
|
40 #else |
|
41 _LIT(testName,"t_resmanus"); |
|
42 #endif |
|
43 |
|
44 TBuf<16> gTestName(testName); |
|
45 |
|
46 GLDEF_D RTest gTest(testName); |
|
47 GLDEF_D RBusDevResManUs gChannel; |
|
48 |
|
49 TUint8 KNoOfGetStateRequests = 5; |
|
50 TUint8 KNoOfSetStateRequests = 4; |
|
51 TUint8 KNoOfNotifyRequests = 7; |
|
52 #define MAX_NUM_REQUESTS 8 // Must be (at least) one greater than the largest of |
|
53 // KNoOfGetStateRequests, KNoOfSetStateRequests, KNoOfNotifyRequests |
|
54 #ifdef _DEBUG |
|
55 TUint gLongLatencyResource; |
|
56 TBool gHaveAsyncRes = EFalse; |
|
57 TInt gAsyncResStateDelta = 0; |
|
58 |
|
59 TUint gSharedResource; |
|
60 TBool gHaveSharedRes = EFalse; |
|
61 TInt gSharedResStateDelta = 0; |
|
62 #else |
|
63 // The UREL version of the driver will not implement the arrays and functionality required |
|
64 // to determine the async and shared resources to use at runtime. The values provided here |
|
65 // have been pre-determined to operate successfully with the simulated PSL. |
|
66 // |
|
67 TUint gLongLatencyResource = 6; |
|
68 TBool gHaveAsyncRes = ETrue; |
|
69 TInt gAsyncResStateDelta = -1; |
|
70 |
|
71 TUint gSharedResource = 12; |
|
72 TBool gHaveSharedRes = ETrue; |
|
73 TInt gSharedResStateDelta = -1; |
|
74 #endif |
|
75 |
|
76 TBool gUseCached = EFalse; |
|
77 |
|
78 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel) |
|
79 { |
|
80 TInt r = KErrNone; |
|
81 // API accepts 8-bit descriptors, only - so convert name accordingly |
|
82 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName; |
|
83 EightBitName.Copy(aName); |
|
84 r=(aChannel.Open(EightBitName)); |
|
85 if (r!=KErrNone) |
|
86 gTest.Printf(_L("OpenChannel: Handle for channel %S error code =0x%x\n"),&aName,r); |
|
87 else |
|
88 gTest.Printf(_L("OpenChannel: Handle for channel %S =0x%x\n"),&aName,aChannel.Handle()); |
|
89 return r; |
|
90 } |
|
91 |
|
92 LOCAL_C TInt HelperResources() |
|
93 // |
|
94 // Helper method to support OpenAndRegisterChannel |
|
95 // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName |
|
96 // |
|
97 { |
|
98 TInt r = KErrNone; |
|
99 |
|
100 __KHEAP_MARK; |
|
101 |
|
102 // Check what resources are available |
|
103 gTest.Printf(_L("**Test GetNoOfResources\n")); |
|
104 TUint numResources=0; |
|
105 if((r=gChannel.GetNoOfResources(numResources))!=KErrNone) |
|
106 { |
|
107 gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r); |
|
108 return r; |
|
109 } |
|
110 gTest.Printf(_L("Number of resources = %d (=0x%x)\n"),numResources,numResources); |
|
111 |
|
112 // Read the resource information |
|
113 gTest.Printf(_L("**Test GetAllResourcesInfo\n")); |
|
114 |
|
115 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
116 // and reference via an RSimplePointerArray |
|
117 TUint bufSize = numResources; |
|
118 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize); |
|
119 for(TUint i=0;i<bufSize;i++) |
|
120 { |
|
121 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
122 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
123 { |
|
124 gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r); |
|
125 } |
|
126 } |
|
127 TUint updateNumResources=numResources; |
|
128 if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone) |
|
129 { |
|
130 gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r); |
|
131 return r; |
|
132 } |
|
133 gTest.Printf(_L("Updated number of resources = %d\n"),updateNumResources); |
|
134 |
|
135 #ifdef _DEBUG |
|
136 // Print resource names |
|
137 { |
|
138 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; |
|
139 for(TUint i=0; i<updateNumResources; i++) |
|
140 { |
|
141 TResourceInfoBuf* currRes = infoPtrs[i]; |
|
142 name.Copy((*currRes)().iName); |
|
143 name.PtrZ(); |
|
144 gTest.Printf(_L("Resource %d name = %S \n"),i,&name); |
|
145 }; |
|
146 } |
|
147 #endif |
|
148 |
|
149 // Select a resource to use, then pass its name to GetResourceIdByName |
|
150 // to check that the corresponding resource ID is acquired. |
|
151 TResourceInfo currRes = (*infoPtrs[0])(); |
|
152 if(updateNumResources>1) |
|
153 currRes=(*infoPtrs[1])();// First resource may be a dummy |
|
154 TUint resourceId; |
|
155 gTest.Printf(_L("Invoking GetResourceIdByName for last resource name extracted \n")); |
|
156 if((r=gChannel.GetResourceIdByName(currRes.iName, resourceId))!=KErrNone) |
|
157 { |
|
158 gTest.Printf(_L("GetResourceIdByName for channel returned %d \n"),r); |
|
159 return r; |
|
160 } |
|
161 gTest.Printf(_L("GetResourceIdByName gave ID = %d\n"),resourceId); |
|
162 |
|
163 infoPtrs.Close(); |
|
164 |
|
165 __KHEAP_MARKEND; |
|
166 |
|
167 return r; |
|
168 } |
|
169 |
|
170 LOCAL_C TInt CheckForSimulatedResources() |
|
171 // |
|
172 // Get the name of the first resource - if it does not match the expected name |
|
173 // then the testing must not proceed, so return the relevant error code |
|
174 // |
|
175 { |
|
176 TInt r = KErrNone; |
|
177 TResourceInfoBuf buffer; |
|
178 if((r=gChannel.GetResourceInfo(1, &buffer))!=KErrNone) // first resource ID = 1 |
|
179 { |
|
180 gTest.Printf(_L("CheckForSimulatedResources, candidate get resource info returned %d\n"),r); |
|
181 return r; |
|
182 } |
|
183 // Check the name of the resource |
|
184 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; |
|
185 name.Copy(buffer().iName); |
|
186 name.PtrZ(); |
|
187 if((r=name.Compare(testableResourceName))!=KErrNone) |
|
188 { |
|
189 gTest.Printf(_L("Resource name = %S, require %S \n"),&name,&testableResourceName); |
|
190 r=KErrNotSupported; |
|
191 } |
|
192 return r; |
|
193 } |
|
194 |
|
195 //---------------------------------------------------------------------------------------------- |
|
196 //! @SYMTestCaseID KBASE-T_RESMANUS-0607 |
|
197 //! @SYMTestType UT |
|
198 //! @SYMPREQ PREQ1398 |
|
199 //! @SYMTestCaseDesc This test case tests channel opening and initialisation APIs. |
|
200 //! @SYMTestActions 0) Call Open API with a valid name. |
|
201 //! |
|
202 //! 1) Call Open API for two more channels |
|
203 //! (to demonstrate multiple clients (channels) can be supported concurrently). |
|
204 //! |
|
205 //! 2) Call Open with an oversized name. |
|
206 //! |
|
207 //! 3) Call GetNoOfResources API |
|
208 //! |
|
209 //! 4) Call GetAllResourcesInfo API |
|
210 //! |
|
211 //! 5) Call GetResourceIdByName API for last of resource names gathered |
|
212 //! in previous step |
|
213 //! |
|
214 //! 6) Call Initialise API on the channel originally created, with non-zero arguments. |
|
215 //! |
|
216 //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise. |
|
217 //! 1) API should return with KErrNone, exits otherwise. |
|
218 //! 2) API should return with KErrBadName, exits otherwise. |
|
219 //! 3) API should return with KErrNone, exits otherwise. |
|
220 //! 4) API should return with KErrNone, exits otherwise. |
|
221 //! 5) API should return with KErrNone, exits otherwise. |
|
222 //! 6) API should return with KErrNone, exits otherwise. |
|
223 //! |
|
224 //! @SYMTestPriority High |
|
225 //! @SYMTestStatus Implemented |
|
226 //---------------------------------------------------------------------------------------------- |
|
227 LOCAL_C TInt OpenAndRegisterChannel() |
|
228 // |
|
229 // Test Open and Initialise functionality |
|
230 // Also invokes Resource inspection methods via HelperResource |
|
231 // |
|
232 { |
|
233 TInt r; |
|
234 |
|
235 if((r=OpenChannel(gTestName, gChannel))!=KErrNone) |
|
236 return r; |
|
237 |
|
238 // Check that the simulated resources required to support this testing are present |
|
239 // If not, close the channel and return the propagated error code. |
|
240 if((r=CheckForSimulatedResources())!=KErrNone) |
|
241 { |
|
242 gChannel.Close(); |
|
243 return r; |
|
244 } |
|
245 |
|
246 __KHEAP_MARK; // gTestName will remain open (allocated) when heap is checked |
|
247 |
|
248 // Open a couple of additional channels to prove that more than one |
|
249 // can exist |
|
250 _LIT(tempStr1,"temp1"); |
|
251 TBufC<16> tempName1(tempStr1); |
|
252 _LIT(tempStr2,"temp2"); |
|
253 TBufC<16> tempName2(tempStr2); |
|
254 |
|
255 RBusDevResManUs channelTwo; |
|
256 RBusDevResManUs channelThree; |
|
257 |
|
258 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) |
|
259 return r; |
|
260 if((r=OpenChannel(tempName2, channelThree))!=KErrNone) |
|
261 return r; |
|
262 |
|
263 // The following test requires manual enabling in resource controller of macro |
|
264 // DEBUG_VERSION - this is not done by default, so test is deactivated here. |
|
265 // |
|
266 #if 0 |
|
267 // Test rejection if try a name already in use |
|
268 // |
|
269 // (For UREL builds, duplicate names are allowed; but |
|
270 // for UDEB builds, they are monitored and rejected) |
|
271 // |
|
272 RBusDevResManUs channelSameName; |
|
273 r=OpenChannel(tempName1, channelSameName); |
|
274 channelSameName.Close(); // Channel not used after here |
|
275 if (r==KErrNone) |
|
276 { |
|
277 gTest.Printf(_L("Error: Handle for re-used name channel =0x%x\n"),channelSameName.Handle()); |
|
278 return KErrGeneral; |
|
279 } |
|
280 else if(r!=KErrCouldNotConnect) |
|
281 { |
|
282 gTest.Printf(_L("Error: re-used name gave unexpected error code =0x%x\n"),r); |
|
283 return r; |
|
284 } |
|
285 else // if(r==KErrCouldNotConnect) |
|
286 { |
|
287 gTest.Printf(_L("Re-used channel name rejected with correct error code\n")); |
|
288 } |
|
289 #endif // if 0 |
|
290 |
|
291 // Test oversized name rejection |
|
292 _LIT(longStr,"1abcdefghijklmnopqrstuvwxyz2abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz4abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz6abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz8abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz10abcdefghijklmnopqrstuvwxyz"); |
|
293 TBufC<271> longName(longStr); |
|
294 |
|
295 // API accepts 8-bit descriptors for names, only |
|
296 TBuf8<271>longName_8Bit; |
|
297 longName_8Bit.Copy(longName); |
|
298 |
|
299 RBusDevResManUs channelLong; |
|
300 r=(channelLong.Open(longName_8Bit)); |
|
301 channelLong.Close(); // Channel not used after here |
|
302 if (r==KErrNone) |
|
303 { |
|
304 gTest.Printf(_L("Error: Handle for oversize name channel =0x%x\n"),channelLong.Handle()); |
|
305 return KErrGeneral; |
|
306 } |
|
307 else if(r!=KErrBadName) |
|
308 { |
|
309 gTest.Printf(_L("Error: oversized name gave unexpected error code =0x%x\n"),r); |
|
310 return r; |
|
311 } |
|
312 else // if(r==KErrBadName) |
|
313 { |
|
314 gTest.Printf(_L("Oversized name for channel rejected with correct error code\n")); |
|
315 } |
|
316 |
|
317 // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName |
|
318 if((r=HelperResources())!=KErrNone) |
|
319 return r; |
|
320 |
|
321 // Close the temporary channels |
|
322 // Do this before channel registration to enable valid check of kernel heap |
|
323 channelTwo.Close(); |
|
324 channelThree.Close(); |
|
325 |
|
326 __KHEAP_MARKEND; |
|
327 |
|
328 // Channel registration |
|
329 gTest.Printf(_L("Invoking Initialise with values 0x%x, 0x%x, 0x%x\n"),KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests); |
|
330 if ((r=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests))!=KErrNone) |
|
331 { |
|
332 gTest.Printf(_L("Initialise for channel returned %d\n"),r); |
|
333 return r; |
|
334 } |
|
335 |
|
336 return KErrNone; |
|
337 } |
|
338 |
|
339 |
|
340 LOCAL_C TInt HelperClients() |
|
341 // |
|
342 // Helper method to support TestGetClientGetResourceInfo |
|
343 // Invokes GetNoOfClients and GetNamesAllClients |
|
344 // |
|
345 { |
|
346 __KHEAP_MARK; |
|
347 |
|
348 TInt r = KErrNone; |
|
349 TUint numClients = 0; |
|
350 TUint numAllClients = 0; |
|
351 // |
|
352 // GetNoOfClients - with aIncludeKern=EFalse |
|
353 // |
|
354 if((r=gChannel.GetNoOfClients(numClients, EFalse)) != KErrNone) |
|
355 { |
|
356 gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) returned %d\n"),r); |
|
357 return r; |
|
358 } |
|
359 gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) gave 0x%x clients\n"),numClients); |
|
360 |
|
361 // |
|
362 // GetNoOfClients - with aIncludeKern=ETrue |
|
363 // |
|
364 r=gChannel.GetNoOfClients(numAllClients, ETrue); |
|
365 #ifdef RESMANUS_KERN |
|
366 if(r==KErrNone) |
|
367 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrNone\n")); |
|
368 #else |
|
369 if(r==KErrPermissionDenied) |
|
370 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); |
|
371 #endif |
|
372 else |
|
373 { |
|
374 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned %d"),r); |
|
375 return KErrGeneral; |
|
376 } |
|
377 |
|
378 // To support the GetNamesAllClients testing, instantiate TClientName objects |
|
379 // and reference via an RSimplePointerArray |
|
380 TUint bufSize = (numAllClients>numClients)?numAllClients:numClients; |
|
381 RSimplePointerArray<TClientName> infoPtrs(bufSize); |
|
382 for(TUint i=0;i<bufSize;i++) |
|
383 { |
|
384 TClientName *info = new TClientName(); |
|
385 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
386 { |
|
387 gTest.Printf(_L("GetNamesAllClients infoPtrs.Insert at index %d returned %d\n"),i,r); |
|
388 } |
|
389 } |
|
390 |
|
391 // |
|
392 // GetNamesAllClients - with aIncludeKern=EFalse |
|
393 // |
|
394 if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone) |
|
395 { |
|
396 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned %d\n"),r); |
|
397 return r; |
|
398 } |
|
399 #ifdef _DEBUG |
|
400 else |
|
401 { |
|
402 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned KErrNone, names follow\n")); |
|
403 for(TUint i=0;i<numClients;i++) |
|
404 { |
|
405 TClientName *currName = infoPtrs[i]; |
|
406 TBuf16<sizeof(TClientName)> name; |
|
407 name.Copy(*currName); |
|
408 gTest.Printf(_L("Client name %d = %S\n"),i,&name); |
|
409 } |
|
410 } |
|
411 #endif |
|
412 |
|
413 // |
|
414 // GetNamesAllClients - with aIncludeKern=ETrue |
|
415 // |
|
416 #ifdef RESMANUS_KERN |
|
417 if((r=gChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone) |
|
418 { |
|
419 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d\n"),r); |
|
420 return r; |
|
421 } |
|
422 #ifdef _DEBUG |
|
423 else |
|
424 { |
|
425 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrNone, names follow\n")); |
|
426 for(TUint i=0;i<numAllClients;i++) |
|
427 { |
|
428 TClientName *currName = infoPtrs[i]; |
|
429 TBuf16<sizeof(TClientName)> name; |
|
430 name.Copy(*currName); |
|
431 gTest.Printf(_L("Client name %d = %S\n"),i,&name); |
|
432 } |
|
433 } |
|
434 #endif |
|
435 #else |
|
436 if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) == KErrPermissionDenied) |
|
437 { |
|
438 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); |
|
439 r=KErrNone; // Ensure misleading status is not returned |
|
440 } |
|
441 else |
|
442 { |
|
443 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d"),r); |
|
444 return r; |
|
445 } |
|
446 #endif |
|
447 |
|
448 infoPtrs.Close(); |
|
449 __KHEAP_MARKEND; |
|
450 |
|
451 return r; |
|
452 } |
|
453 |
|
454 LOCAL_C TInt HelperClientsUsingResource(TUint aResourceId) |
|
455 // |
|
456 // Helper method to support TestGetClientGetResourceInfo |
|
457 // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource |
|
458 // |
|
459 { |
|
460 __KHEAP_MARK; |
|
461 |
|
462 TInt r = KErrNone; |
|
463 // |
|
464 // GetNumClientsUsingResource - with aIncludeKern=ETrue |
|
465 // |
|
466 TUint resourceAllClients = 0; |
|
467 if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceAllClients, ETrue)) == KErrPermissionDenied) |
|
468 { |
|
469 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); |
|
470 #ifdef RESMANUS_KERN |
|
471 return r; |
|
472 } |
|
473 else |
|
474 { |
|
475 if(r!=KErrNone) |
|
476 { |
|
477 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); |
|
478 return r; |
|
479 } |
|
480 else |
|
481 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) reported 0x%x clients\n"),resourceAllClients); |
|
482 } |
|
483 #else |
|
484 } |
|
485 else |
|
486 { |
|
487 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); |
|
488 return r; |
|
489 } |
|
490 #endif |
|
491 // |
|
492 // GetNumClientsUsingResource - with aIncludeKern=EFalse |
|
493 // |
|
494 TUint resourceClients = 0; |
|
495 if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceClients, EFalse)) != KErrNone) |
|
496 { |
|
497 // If there are no clients that have requested a level then the Resource Controller will |
|
498 // the client ID as a bad argument |
|
499 if(!((resourceClients==0)&&(r==KErrArgument))) |
|
500 { |
|
501 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r); |
|
502 return r; |
|
503 } |
|
504 else |
|
505 r=KErrNone; // Ensure expected error is not misinterpeted |
|
506 } |
|
507 else |
|
508 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) reported 0x%x clients\n"),resourceClients); |
|
509 |
|
510 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects |
|
511 // and reference via an RSimplePointerArray |
|
512 TUint bufSize = (resourceAllClients>resourceClients)?resourceAllClients:resourceClients; |
|
513 if(bufSize>0) |
|
514 { |
|
515 RSimplePointerArray<TClientInfoBuf> infoPtrs(bufSize); |
|
516 for(TUint i=0;i<bufSize;i++) |
|
517 { |
|
518 TClientInfoBuf *info = new TClientInfoBuf(); |
|
519 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
520 { |
|
521 gTest.Printf(_L("GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),i,r); |
|
522 } |
|
523 } |
|
524 |
|
525 // |
|
526 // GetInfoOnClientsUsingResource - with aIncludeKern=EFalse |
|
527 // |
|
528 if((r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceClients, &infoPtrs, EFalse)) != KErrNone) |
|
529 { |
|
530 // If there are no clients that have requested a level then the resource will not |
|
531 // have been found |
|
532 if(!((resourceClients==0)&&(r==KErrNotFound))) |
|
533 { |
|
534 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r); |
|
535 return r; |
|
536 } |
|
537 } |
|
538 #ifdef _DEBUG |
|
539 else |
|
540 { |
|
541 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned KErrNone, info follows\n")); |
|
542 for(TUint i=0;i<resourceClients;i++) |
|
543 { |
|
544 TClientInfoBuf* currInfoBuf = infoPtrs[i]; |
|
545 TClientInfo currInfo=(*currInfoBuf)(); |
|
546 TBuf16<sizeof(TClientName)> name; |
|
547 name.Copy(currInfo.iName); |
|
548 gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId); |
|
549 } |
|
550 } |
|
551 #endif |
|
552 // |
|
553 // GetInfoOnClientsUsingResource - with aIncludeKern=ETrue |
|
554 // |
|
555 r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceAllClients, &infoPtrs, ETrue); |
|
556 { |
|
557 #ifdef RESMANUS_KERN |
|
558 if(r != KErrNone) |
|
559 { |
|
560 // If there are no clients that have requested a level then the Resource Controller |
|
561 // will report a request for information on 0 clients as a bad argument |
|
562 if(!((resourceClients==0)&&(r==KErrArgument))) |
|
563 { |
|
564 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); |
|
565 return r; |
|
566 } |
|
567 else |
|
568 r=KErrNone; // Ensure misleading result is not returned |
|
569 } |
|
570 #ifdef _DEBUG |
|
571 else |
|
572 { |
|
573 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone, info follows\n")); |
|
574 for(TUint i=0;i<resourceClients;i++) |
|
575 { |
|
576 TClientInfoBuf* currInfoBuf = infoPtrs[i]; |
|
577 TClientInfo currInfo=(*currInfoBuf)(); |
|
578 TBuf16<sizeof(TClientName)> name; |
|
579 name.Copy(currInfo.iName); |
|
580 gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId); |
|
581 } |
|
582 } |
|
583 #endif |
|
584 #else |
|
585 if(r == KErrNone) |
|
586 { |
|
587 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone")); |
|
588 return KErrGeneral; |
|
589 } |
|
590 else if(r==KErrPermissionDenied) |
|
591 { |
|
592 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); |
|
593 r=KErrNone; // Ensure that misleading result is not propagated |
|
594 } |
|
595 else |
|
596 { |
|
597 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); |
|
598 // If there are no clients that have requested a level then the Resource Controller |
|
599 // will report a request for information on 0 clients as a bad argument |
|
600 if(!((resourceClients==0)&&(r==KErrArgument))) |
|
601 return r; |
|
602 } |
|
603 #endif |
|
604 } |
|
605 } |
|
606 |
|
607 __KHEAP_MARKEND; |
|
608 |
|
609 return r; |
|
610 } |
|
611 |
|
612 |
|
613 |
|
614 LOCAL_C TInt HelperResourcesInUseByClient() |
|
615 // |
|
616 // Helper method to supportTestGetClientGetResourceInfo |
|
617 // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient |
|
618 // |
|
619 { |
|
620 __KHEAP_MARK; |
|
621 |
|
622 TInt r = KErrNone; |
|
623 // |
|
624 // GetNumResourcesInUseByClient |
|
625 // |
|
626 // API accepts 8-bit descriptors, only - so convert name accordingly |
|
627 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit; |
|
628 name8Bit.Copy(gTestName); |
|
629 TClientName* clientName = (TClientName*)&name8Bit; |
|
630 #if _DEBUG |
|
631 TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit; |
|
632 clientName16Bit.Copy(*clientName); |
|
633 clientName16Bit.SetLength(clientName->Length()); |
|
634 gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S (expect KErrPermissionDenied if no levels requested yet)\n"),&clientName16Bit); |
|
635 #endif |
|
636 TUint numResourcesForClient; |
|
637 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResourcesForClient)) != KErrNone) |
|
638 { |
|
639 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
640 return r; |
|
641 } |
|
642 gTest.Printf(_L("GetNumResourcesInUseByClient gave number of resources = %d\n"),numResourcesForClient); |
|
643 // |
|
644 // In addition, check response when the name of an unknown client is passed |
|
645 // |
|
646 // Negative test - ensure that an unknown client name fails |
|
647 _LIT(dumName,"DoesNotExist"); |
|
648 TBuf<16> dumNameBuf(dumName); |
|
649 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>dumName8Bit; |
|
650 dumName8Bit.Copy(dumNameBuf); |
|
651 TClientName* dumClientName = (TClientName*)&dumName8Bit; |
|
652 #if _DEBUG |
|
653 gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S\n"),&dumNameBuf); |
|
654 #endif |
|
655 TUint numResForDumClient; |
|
656 if((r=gChannel.GetNumResourcesInUseByClient(*dumClientName, numResForDumClient)) != KErrNotFound) |
|
657 { |
|
658 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
659 if(r==KErrNone) |
|
660 r=KErrGeneral; |
|
661 return r; |
|
662 } |
|
663 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
664 r=KErrNone; // Ensure misleading error code is not propagated |
|
665 |
|
666 // |
|
667 // GetInfoOnResourcesInUseByClient |
|
668 // |
|
669 // If the (TUint) number of resources in use by the client is zero skip the attempt to read the resource information |
|
670 TUint updatedNumResourcesForClient = numResourcesForClient; |
|
671 if(numResourcesForClient!=0) |
|
672 { |
|
673 TUint bufSize = numResourcesForClient; |
|
674 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize); |
|
675 for(TUint i=0;i<bufSize;i++) |
|
676 { |
|
677 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
678 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
679 { |
|
680 gTest.Printf(_L("GetInfoOnResourcesInUseByClient infoPtrs.Insert at index %d returned %d\n"),i,r); |
|
681 } |
|
682 } |
|
683 |
|
684 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, updatedNumResourcesForClient, &infoPtrs)) != KErrNone) |
|
685 { |
|
686 gTest.Printf(_L("GetInfoOnResourcesInUseByClient returned %d\n"),r); |
|
687 // If there are no clients that have requested a level then the Resource Controller |
|
688 // will report a request for information on 0 clients as a bad argument |
|
689 if(!((updatedNumResourcesForClient==0)&&(r==KErrArgument))) |
|
690 return r; |
|
691 else |
|
692 r=KErrNone; // Ensure misleading value is not returned by this function |
|
693 } |
|
694 else |
|
695 { |
|
696 gTest.Printf(_L("GetInfoOnResourcesInUseByClient gave updated number of resources %d\n"),updatedNumResourcesForClient); |
|
697 #ifdef _DEBUG |
|
698 // Print resource names |
|
699 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; |
|
700 for(TUint i=0; i<updatedNumResourcesForClient; i++) |
|
701 { |
|
702 TResourceInfoBuf* currRes = infoPtrs[i]; |
|
703 name.Copy((*currRes)().iName); |
|
704 name.PtrZ(); |
|
705 gTest.Printf(_L("Resource %d name = %S \n"),i,&name); |
|
706 }; |
|
707 #endif |
|
708 } |
|
709 // |
|
710 // In addition, check response when the name of an unknown client is passed |
|
711 // |
|
712 // Negative test - ensure that an unknown client name fails |
|
713 r=gChannel.GetInfoOnResourcesInUseByClient(*dumClientName, updatedNumResourcesForClient, &infoPtrs); |
|
714 gTest.Printf(_L("GetInfoOnResourcesInUseByClient for dummy client returned %d\n"),r); |
|
715 if(r==KErrNone) |
|
716 return KErrGeneral; |
|
717 else if(r!=KErrNotFound) |
|
718 return r; |
|
719 // Ensure that misleading information is not returned to the calling function |
|
720 r=KErrNone; |
|
721 |
|
722 infoPtrs.Close(); |
|
723 } |
|
724 |
|
725 __KHEAP_MARKEND; |
|
726 |
|
727 return r; |
|
728 } |
|
729 |
|
730 |
|
731 LOCAL_C TInt HelperGetClientResourceInfo() |
|
732 // |
|
733 // Test methods to access information about clients and resources |
|
734 // |
|
735 { |
|
736 __KHEAP_MARK; |
|
737 |
|
738 TInt r = KErrNone; |
|
739 // Invokes GetNoOfClients and GetNamesAllClients |
|
740 if((r=HelperClients())!=KErrNone) |
|
741 return r; |
|
742 |
|
743 // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource |
|
744 // |
|
745 // First invoke on the Async resource |
|
746 TUint resourceId = 1; // Arbitrary |
|
747 if(gHaveAsyncRes) |
|
748 { |
|
749 resourceId = gLongLatencyResource; |
|
750 gTest.Printf(_L("Invoking HelperClientsUsinResource for Async resource ID %d\n"),resourceId); |
|
751 } |
|
752 else |
|
753 { |
|
754 gTest.Printf(_L("Invoking HelperClientsUsinResource for default resource ID %d (Async resource not yet accessed)\n"),resourceId); |
|
755 } |
|
756 if((r=HelperClientsUsingResource(resourceId))!=KErrNone) |
|
757 return r; |
|
758 // |
|
759 // Second invoke on the Shared resource - skip if not available |
|
760 if(gHaveSharedRes) |
|
761 { |
|
762 resourceId = gSharedResource; |
|
763 gTest.Printf(_L("Invoking HelperClientsUsinResource for Shared resource ID %d\n"),resourceId); |
|
764 if((r=HelperClientsUsingResource(resourceId))!=KErrNone) |
|
765 return r; |
|
766 } |
|
767 |
|
768 // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient |
|
769 if((r=HelperResourcesInUseByClient())!=KErrNone) |
|
770 return r; |
|
771 |
|
772 __KHEAP_MARKEND; |
|
773 |
|
774 return r; |
|
775 } |
|
776 |
|
777 #ifdef _DEBUG |
|
778 LOCAL_C TInt SetAsyncResource() |
|
779 // |
|
780 // Support function for tests of asynchronous API methods |
|
781 // |
|
782 { |
|
783 if(!gHaveAsyncRes) |
|
784 { |
|
785 gTest.Printf(_L("SetAsyncResource, Find Async resource to use\n")); |
|
786 TRequestStatus status; |
|
787 TBool cached = gUseCached; |
|
788 TInt readValue = 0; |
|
789 TInt levelOwnerId = 0; |
|
790 TUint numPotentialResources; |
|
791 TUint index=0; |
|
792 TInt r=gChannel.GetNumCandidateAsyncResources(numPotentialResources); |
|
793 if(r!=KErrNone) |
|
794 { |
|
795 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources returned %d\n"),r); |
|
796 return r; |
|
797 } |
|
798 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources found %d resources\n"),numPotentialResources); |
|
799 while((numPotentialResources>0) && !gHaveAsyncRes) |
|
800 { |
|
801 TUint tryResourceId=0; |
|
802 r=gChannel.GetCandidateAsyncResourceId(index,tryResourceId); |
|
803 if(r!=KErrNone) |
|
804 { |
|
805 gTest.Printf(_L("SetAsyncResource, GetCandidateAsyncResourceId returned %d\n"),r); |
|
806 break; |
|
807 } |
|
808 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources index %d, resource ID %d\n"),index,tryResourceId); |
|
809 // For the candidate resource to be usable, we need its current state |
|
810 // to be sufficiently less the maximum for positive sense (or sufficiently |
|
811 // more than the greater than the minimum for negative sense - but the current |
|
812 // version of the code only considers positive sense). |
|
813 gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId); |
|
814 User::WaitForRequest(status); |
|
815 if(status.Int() != KErrNone) |
|
816 { |
|
817 gTest.Printf(_L("SetAsyncResource, candidate get state returned %d\n"),r); |
|
818 return r; |
|
819 } |
|
820 gTest.Printf(_L("SetAsyncResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId); |
|
821 TResourceInfoBuf buffer; |
|
822 if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone) |
|
823 { |
|
824 gTest.Printf(_L("SetAsyncResource, candidate get resource info returned %d\n"),r); |
|
825 return r; |
|
826 } |
|
827 // Print resource info |
|
828 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; |
|
829 TResourceInfo* infoPtr = &(buffer()); |
|
830 name.Copy(infoPtr->iName); |
|
831 gTest.Printf(_L("SetAsyncResource: Resource name = %S \n"),&name); |
|
832 gTest.Printf(_L("SetAsyncResource: Resource Class =%d\n"),infoPtr->iClass); |
|
833 gTest.Printf(_L("SetAsyncResource: Resource Type =%d\n"), infoPtr->iType); |
|
834 gTest.Printf(_L("SetAsyncResource: Resource Usage =%d\n"), infoPtr->iUsage); |
|
835 gTest.Printf(_L("SetAsyncResource: Resource Sense =%d\n"), infoPtr->iSense); |
|
836 gTest.Printf(_L("SetAsyncResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel); |
|
837 gTest.Printf(_L("SetAsyncResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel); |
|
838 |
|
839 if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) |
|
840 { |
|
841 gLongLatencyResource = tryResourceId; |
|
842 gAsyncResStateDelta = 1; // Will change resource level in positive direction |
|
843 gHaveAsyncRes = ETrue; |
|
844 } |
|
845 else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) |
|
846 { |
|
847 gLongLatencyResource = tryResourceId; |
|
848 gAsyncResStateDelta = -1; // Will change resource level in negative direction |
|
849 gHaveAsyncRes = ETrue; |
|
850 } |
|
851 else |
|
852 { |
|
853 ++index; |
|
854 --numPotentialResources; |
|
855 } |
|
856 }; |
|
857 } |
|
858 if(!gHaveAsyncRes) |
|
859 { |
|
860 gTest.Printf(_L("**Test SetAsyncResource - don't have suitable resource ... exiting\n")); |
|
861 return KErrNotReady; |
|
862 } |
|
863 |
|
864 return KErrNone; |
|
865 } |
|
866 |
|
867 LOCAL_C TInt SetSharedResource() |
|
868 // |
|
869 // Support function for tests of shareable resources |
|
870 // |
|
871 { |
|
872 __KHEAP_MARK; |
|
873 |
|
874 if(!gHaveSharedRes) |
|
875 { |
|
876 TRequestStatus status; |
|
877 TBool cached = gUseCached; |
|
878 TInt readValue = 0; |
|
879 TUint numPotentialResources; |
|
880 TUint index=0; |
|
881 TInt r=gChannel.GetNumCandidateSharedResources(numPotentialResources); |
|
882 if(r!=KErrNone) |
|
883 { |
|
884 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources returned %d\n"),r); |
|
885 return r; |
|
886 } |
|
887 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources found %d resources\n"),numPotentialResources); |
|
888 while((numPotentialResources>0) && !gHaveSharedRes) |
|
889 { |
|
890 TUint tryResourceId=0; |
|
891 r=gChannel.GetCandidateSharedResourceId(index,tryResourceId); |
|
892 if(r!=KErrNone) |
|
893 { |
|
894 gTest.Printf(_L("SetSharedResource, GetCandidateSharedResourceId returned %d\n"),r); |
|
895 break; |
|
896 } |
|
897 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources index %d, resource ID %d\n"),index,tryResourceId); |
|
898 // To support the tests, the selected shareable resource must not be the same |
|
899 // resource as that selected for asynchronous testing |
|
900 if(gHaveAsyncRes) |
|
901 if(tryResourceId==gLongLatencyResource) |
|
902 { |
|
903 gTest.Printf(_L("SetSharedResource - skipping candidate resource %d - already used for async testing\n"),tryResourceId); |
|
904 continue; |
|
905 } |
|
906 // For the candidate resource to be usable, we need its current state |
|
907 // to be sufficiently less the maximum for positive sense (or sufficiently |
|
908 // more than the greater than the minimum for negative sense - but the current |
|
909 // version of the code only considers positive sense). |
|
910 TInt levelOwnerId = 0; |
|
911 gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId); |
|
912 User::WaitForRequest(status); |
|
913 if(status.Int() != KErrNone) |
|
914 { |
|
915 gTest.Printf(_L("SetSharedResource, candidate get state returned %d\n"),r); |
|
916 return r; |
|
917 } |
|
918 gTest.Printf(_L("SetSharedResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId); |
|
919 TResourceInfoBuf buffer; |
|
920 if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone) |
|
921 { |
|
922 gTest.Printf(_L("SetSharedResource, candidate get resource info returned %d\n"),r); |
|
923 return r; |
|
924 } |
|
925 // Print resource info |
|
926 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; |
|
927 TResourceInfo* infoPtr = &buffer(); |
|
928 name.Copy(infoPtr->iName); |
|
929 gTest.Printf(_L("SetSharedResource: Resource name = %S \n"),&name); |
|
930 gTest.Printf(_L("SetSharedResource: Resource Class =%d\n"),infoPtr->iClass); |
|
931 gTest.Printf(_L("SetSharedResource: Resource Type =%d\n"), infoPtr->iType); |
|
932 gTest.Printf(_L("SetSharedResource: Resource Usage =%d\n"), infoPtr->iUsage); |
|
933 gTest.Printf(_L("SetSharedResource: Resource Sense =%d\n"), infoPtr->iSense); |
|
934 gTest.Printf(_L("SetSharedResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel); |
|
935 gTest.Printf(_L("SetSharedResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel); |
|
936 |
|
937 if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) |
|
938 { |
|
939 gSharedResource = tryResourceId; |
|
940 gSharedResStateDelta = 1; // Will change resource level in positive direction |
|
941 gHaveSharedRes = ETrue; |
|
942 } |
|
943 else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) |
|
944 { |
|
945 gSharedResource = tryResourceId; |
|
946 gSharedResStateDelta = -1; // Will change resource level in negative direction |
|
947 gHaveSharedRes = ETrue; |
|
948 } |
|
949 else |
|
950 { |
|
951 ++index; |
|
952 --numPotentialResources; |
|
953 } |
|
954 }; |
|
955 } |
|
956 if(!gHaveSharedRes) |
|
957 { |
|
958 gTest.Printf(_L("**Test SetSharedResource - don't have suitable resource ... exiting\n")); |
|
959 return KErrNotReady; |
|
960 } |
|
961 |
|
962 __KHEAP_MARKEND; |
|
963 return KErrNone; |
|
964 } |
|
965 |
|
966 #endif |
|
967 |
|
968 |
|
969 //---------------------------------------------------------------------------------------------- |
|
970 //! @SYMTestCaseID KBASE-T_RESMANUS-0609 |
|
971 //! @SYMTestType UT |
|
972 //! @SYMPREQ PREQ1398 |
|
973 //! @SYMTestCaseDesc This test case tests APIs for retrieving information about |
|
974 //! (1) clients of the channel and |
|
975 //! (2) power resources. |
|
976 //! Since the client lacks the ReadDeviceData PlatSec capability it will not |
|
977 //! be permitted to access information about kernel-side clients |
|
978 //! |
|
979 //! The tests are invoked a number of times: |
|
980 //! - first, to examine the starting state |
|
981 //! - then, to examine the effect of adding a new client (channel) |
|
982 //! - then, the examine the effect of adding a new client that requests a |
|
983 //| level on a resource |
|
984 //! - then, to test the effect of the original client requesting a level |
|
985 //! on a resource |
|
986 //! |
|
987 //! @SYMTestActions 0) Call GetNoOfClients API with default aIncludeKern=EFalse. |
|
988 //! |
|
989 //! 1) Call GetNoOfClients API with aIncludeKern=ETrue. |
|
990 //! |
|
991 //! 2) Call GetNamesAllClients API with default aIncludeKern=EFalse. |
|
992 //! |
|
993 //! 3) Call GetNamesAllClients API with aIncludeKern=ETrue. |
|
994 //! |
|
995 //! 4) Call GetNumClientsUsingResource API with aIncludeKern=ETrue. |
|
996 //! |
|
997 //! 5) Call GetNumClientsUsingResource API with default aIncludeKern=EFalse. |
|
998 //! |
|
999 //! 6) Call GetInfoOnClientsUsingResource API with default aIncludeKern=EFalse. |
|
1000 //! |
|
1001 //! 7) Call GetInfoOnClientsUsingResource API with aIncludeKern=ETrue. |
|
1002 //! |
|
1003 //! 8) GetNumResourcesInUseByClient for the original client |
|
1004 //! |
|
1005 //! 9) GetNumResourcesInUseByClient for a non-existent client |
|
1006 //! |
|
1007 //! 10) GetInfoOnResourcesInUseByClient for the original client |
|
1008 //! |
|
1009 //! 11) GetInfoOnResourcesInUseByClient for a non-existent client |
|
1010 //! |
|
1011 //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise. |
|
1012 //! |
|
1013 //! 1) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise. |
|
1014 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise. |
|
1015 //! |
|
1016 //! 2) API should return with KErrNone, exits otherwise. |
|
1017 //! |
|
1018 //! 3) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise |
|
1019 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise |
|
1020 //! |
|
1021 //! 4) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise. |
|
1022 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise. |
|
1023 //! |
|
1024 //! 5) API should return with KErrNone, exits otherwise |
|
1025 //! |
|
1026 //! 6) API should return with KErrNone, exits otherwise. |
|
1027 //! |
|
1028 //! 7) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise |
|
1029 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise |
|
1030 //! |
|
1031 //! 8) API should return with KErrNone, exits otherwise. |
|
1032 //! |
|
1033 //! 9) API should return with KErrNotFound, exits otherwise. |
|
1034 //! |
|
1035 //! 10) API should return with KErrNone, exits otherwise. |
|
1036 //! |
|
1037 //! 11) API should return with KErrNotFound, exits otherwise. |
|
1038 //! |
|
1039 //! @SYMTestPriority High |
|
1040 //! @SYMTestStatus Implemented |
|
1041 //---------------------------------------------------------------------------------------------- |
|
1042 LOCAL_C TInt TestGetClientGetResourceInfo() |
|
1043 // |
|
1044 // Test methods to access information about clients and resources |
|
1045 // |
|
1046 { |
|
1047 TInt r = KErrNone; |
|
1048 |
|
1049 // Open a couple of additional channels |
|
1050 _LIT(tempStr1,"ExtraChan1"); |
|
1051 TBufC<16> tempName1(tempStr1); |
|
1052 _LIT(tempStr2,"ExtraChan2"); |
|
1053 TBufC<16> tempName2(tempStr2); |
|
1054 |
|
1055 RBusDevResManUs channelTwo; |
|
1056 RBusDevResManUs channelThree; |
|
1057 |
|
1058 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) |
|
1059 return r; |
|
1060 if((r=OpenChannel(tempName2, channelThree))!=KErrNone) |
|
1061 return r; |
|
1062 |
|
1063 // Test the tracking of the client and resource info |
|
1064 // |
|
1065 |
|
1066 // First invocation to establish starting state |
|
1067 #ifdef _DEBUG |
|
1068 gTest.Printf(_L("TestGetClientGetResourceInfo: First HelperGetClientResourceInfo call (starting state):\n")); |
|
1069 #endif |
|
1070 if((r=HelperGetClientResourceInfo())!=KErrNone) |
|
1071 return r; |
|
1072 |
|
1073 // Second invocation - examine effect of adding a client |
|
1074 _LIT(tempStr3,"ExtraChan3"); |
|
1075 TBufC<16> tempName3(tempStr3); |
|
1076 RBusDevResManUs channelFour; |
|
1077 if((r=OpenChannel(tempName3, channelFour))!=KErrNone) |
|
1078 return r; |
|
1079 #ifdef _DEBUG |
|
1080 gTest.Printf(_L("TestGetClientGetResourceInfo: Second HelperGetClientResourceInfo call (added client ExtraChan3):\n")); |
|
1081 #endif |
|
1082 |
|
1083 if((r=HelperGetClientResourceInfo())!=KErrNone) |
|
1084 return r; |
|
1085 |
|
1086 // Third invocation - examine effect of new client requesting a level for a resource |
|
1087 // (This relies on getting and setting the state of gSharedResource - so skip the |
|
1088 // test if this has not yet been identified |
|
1089 // |
|
1090 TUint startingLevel = 0; |
|
1091 #ifdef _DEBUG |
|
1092 if((r=SetSharedResource())!=KErrNone) |
|
1093 return r; |
|
1094 #endif |
|
1095 if(!gHaveSharedRes) |
|
1096 { |
|
1097 gTest.Printf(_L("TestGetClientGetResourceInfo: no suitable shareable resource, so skipping third call:\n")); |
|
1098 } |
|
1099 else |
|
1100 { |
|
1101 // Channel registration |
|
1102 gTest.Printf(_L("Initialise for temporary channel with arguments 1,1,0\n")); |
|
1103 if ((r=channelFour.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state |
|
1104 { |
|
1105 gTest.Printf(_L("Initialise for channel returned %d\n"),r); |
|
1106 return r; |
|
1107 } |
|
1108 // Get initial state |
|
1109 TRequestStatus status; |
|
1110 TBool cached = gUseCached; |
|
1111 TInt readValue; |
|
1112 TInt levelOwnerId = 0; |
|
1113 channelFour.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); |
|
1114 User::WaitForRequest(status); |
|
1115 r=status.Int(); |
|
1116 if(r != KErrNone) |
|
1117 { |
|
1118 gTest.Printf(_L("TestGetClientGetResourceInfo, first get state for shareable returned %d\n"),r); |
|
1119 return r; |
|
1120 } |
|
1121 startingLevel = (TUint)readValue; |
|
1122 // Write updated state |
|
1123 TUint newLevel = (TUint)(readValue + gSharedResStateDelta); |
|
1124 gTest.Printf(_L("TestGetClientGetResourceInfo: levelOwnerId = %d\n"), levelOwnerId); |
|
1125 gTest.Printf(_L("TestGetClientGetResourceInfo: shareable resource startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel); |
|
1126 channelFour.ChangeResourceState(status,gSharedResource,newLevel); |
|
1127 User::WaitForRequest(status); |
|
1128 r=status.Int(); |
|
1129 if(r != KErrNone) |
|
1130 { |
|
1131 gTest.Printf(_L("TestGetClientGetResourceInfo, first change state for shareable resource returned %d\n"),r); |
|
1132 return r; |
|
1133 } |
|
1134 #ifdef _DEBUG |
|
1135 gTest.Printf(_L("TestGetClientGetResourceInfo: third HelperGetClientResourceInfo call (new client set level on shared resource):\n")); |
|
1136 #endif |
|
1137 if((r=HelperGetClientResourceInfo())!=KErrNone) |
|
1138 return r; |
|
1139 } |
|
1140 |
|
1141 |
|
1142 // Fourth invocation - examine effect of orignal client requesting a level for |
|
1143 // the Shared resource |
|
1144 if(gHaveSharedRes) |
|
1145 { |
|
1146 TRequestStatus status; |
|
1147 TBool cached = gUseCached; |
|
1148 TInt readValue; |
|
1149 TInt levelOwnerId; |
|
1150 gChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); |
|
1151 User::WaitForRequest(status); |
|
1152 r=status.Int(); |
|
1153 if(r != KErrNone) |
|
1154 { |
|
1155 gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel get state on Shareable resource returned %d\n"),r); |
|
1156 return r; |
|
1157 } |
|
1158 gTest.Printf(_L("TestGetClientGetResourceInfo, GetResourceState levelOwnerId = %d\n"),levelOwnerId); // Request a level on the resource |
|
1159 gChannel.ChangeResourceState(status,gSharedResource,(readValue+gSharedResStateDelta)); |
|
1160 User::WaitForRequest(status); |
|
1161 if(status.Int() != KErrNone) |
|
1162 { |
|
1163 gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel change state on Shareable returned %d\n"),r); |
|
1164 return r; |
|
1165 } |
|
1166 #ifdef _DEBUG |
|
1167 gTest.Printf(_L("TestGetClientGetResourceInfo: fourth HelperGetClientResourceInfo call (gChannel set level on Shareable resource):\n")); |
|
1168 #endif |
|
1169 if((r=HelperGetClientResourceInfo())!=KErrNone) |
|
1170 return r; |
|
1171 } |
|
1172 |
|
1173 // Return the resource to the state it was on function entry |
|
1174 if(gHaveSharedRes) |
|
1175 { |
|
1176 TRequestStatus status; |
|
1177 gTest.Printf(_L("TestGetClientGetResourceInfo: returning sharable resource to startingLevel=0x%x\n"), startingLevel); |
|
1178 gChannel.ChangeResourceState(status,gSharedResource,startingLevel); |
|
1179 User::WaitForRequest(status); |
|
1180 r=status.Int(); |
|
1181 if(r != KErrNone) |
|
1182 { |
|
1183 gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r); |
|
1184 return r; |
|
1185 } |
|
1186 } |
|
1187 |
|
1188 |
|
1189 // Close the temporary channels |
|
1190 channelTwo.Close(); |
|
1191 channelThree.Close(); |
|
1192 channelFour.Close(); |
|
1193 |
|
1194 return r; |
|
1195 } |
|
1196 |
|
1197 |
|
1198 |
|
1199 //---------------------------------------------------------------------------------------------- |
|
1200 //! @SYMTestCaseID KBASE-T_RESMANUS-0610 |
|
1201 //! @SYMTestType UT |
|
1202 //! @SYMPREQ PREQ1398 |
|
1203 //! @SYMTestCaseDesc This test case tests APIs for getting and setting the state of resources; |
|
1204 //! it also tests APIs to cancel such requests. |
|
1205 //! |
|
1206 //! @SYMTestActions 0) Call API to get the initial state of a selected resource. |
|
1207 //! |
|
1208 //! 1) Call API to modify the state of the resource. |
|
1209 //! |
|
1210 //! 2) Call API to get the new state of the resource and check it exhibits |
|
1211 //! the expected value. |
|
1212 //! |
|
1213 //! 3) Call API to return the resource state to its original value. |
|
1214 //! |
|
1215 //! 4) Call API to get the state of a long latency resource then call API |
|
1216 //! with operation-type qualifier cancel the request. |
|
1217 //! |
|
1218 //! 5) Call API to modify the state of the long latency resource then call API |
|
1219 //! with operation-type qualifier to cancel the request. |
|
1220 //! |
|
1221 //! 6) Call API to get the state of a long latency resource and wait for it |
|
1222 //! to complete. Then call API with operation-type qualifier to cancel the request. |
|
1223 //! |
|
1224 //! 7) Call API to modify the state of the long latency resource and wait for |
|
1225 //! it to complete. Then call API with operation-type qualifier to cancel the request. |
|
1226 //! |
|
1227 //! 8) Call API to get the state of a long latency resource then call API |
|
1228 //! without operation-type qualifier to cancel the request. |
|
1229 //! |
|
1230 //! 9) Call API to modify the state of the long latency resource then call API |
|
1231 //! without operation-type qualifier to cancel the request. |
|
1232 //! |
|
1233 //! 10) Call API to get the state of a long latency resource and wait for it |
|
1234 //! to complete. Then call API without operation-type qualifier to cancel the request. |
|
1235 //! |
|
1236 //! 11) Call API to modify the state of the long latency resource and wait for |
|
1237 //! it to complete. Then call API without operation-type qualifier to cancel the request. |
|
1238 //! |
|
1239 //! 12) Call API to get the state of a long latency resource 'n' times. Then call API with |
|
1240 //! resource qualifier to cancel the requests. |
|
1241 //! |
|
1242 //! 13) Call API to modify the state of a long latency resource 'm' times. Then call API with |
|
1243 //! resource qualifier to cancel the requests. |
|
1244 //! |
|
1245 //! 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete. |
|
1246 //! Then call API with resource qualifier to cancel the requests. |
|
1247 //! |
|
1248 //! 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete. |
|
1249 //! Then call API with resource qualifier to cancel the requests. |
|
1250 //! |
|
1251 //! 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1252 //! a long latency resource 'm' times. Call the API to cancel the get operations with resource qualifier. |
|
1253 //! Wait for the operations to complete. Check the state of the associated TRequestStatus objects. |
|
1254 //! |
|
1255 //! 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1256 //! a long latency resource 'm' times. Call the API to cancel the modify operations with resource qualifier. |
|
1257 //! Wait for the get operations to complete. Check the state of the associated TRequestStatus objects. |
|
1258 //! |
|
1259 //! 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1260 //! a long latency resource 'm' times. Wait for the get operations to complete. Call the API to cancel the get |
|
1261 //! operations with resource qualifier. Check the state of the associated TRequestStatus objects. |
|
1262 //! |
|
1263 //! 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1264 //! a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify |
|
1265 //! operations with resource qualifier. Check the state of the associated TRequestStatus objects. |
|
1266 //! |
|
1267 //! 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1268 //! a long latency resource 'm' times. |
|
1269 //! Then call API with operation-type qualifier to cancel the even-numbered get request(s). |
|
1270 //! Then call API without operation-type qualifier to cancel the even-numbered modify request(s). |
|
1271 //! Check the state of the associated TRequestStatus objects. |
|
1272 //! |
|
1273 //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone, exits otherwise. |
|
1274 //! |
|
1275 //! 1) The associated TRequestStatus object should indicate KErrNone, exits otherwise. |
|
1276 //! |
|
1277 //! 2) The associated TRequestStatus object should indicate KErrNone, exits otherwise. |
|
1278 //! Exit if the value read back is not as expected. |
|
1279 //! |
|
1280 //! 3) The associated TRequestStatus object should indicate KErrNone, exits otherwise. |
|
1281 //! |
|
1282 //! 4) The associated TRequestStatus object should indicate KErrCancel if the cancel |
|
1283 //! request was accepted, exits otherwise. |
|
1284 //! The associated TRequestStatus object should indicate KErrNone if the cancel request |
|
1285 //! was not accepted, exits otherwise. |
|
1286 //! |
|
1287 //! 5) The associated TRequestStatus object should indicate KErrCancel if the cancel |
|
1288 //! request was accepted, exits otherwise. |
|
1289 //! The associated TRequestStatus object should indicate KErrNone if the cancel request |
|
1290 //! was not accepted, exits otherwise. |
|
1291 //! |
|
1292 //! 6) The TRequestStatus object associated with the get operation should indicate |
|
1293 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel |
|
1294 //! operation should indicate KErrNone - exits otherwise. |
|
1295 //! |
|
1296 //! 7) The TRequestStatus object associated with the get operation should indicate |
|
1297 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel |
|
1298 //! operation should indicate KErrNone - exits otherwise. |
|
1299 //! |
|
1300 //! 8) The associated TRequestStatus object should indicate KErrCancel, exits otherwise. |
|
1301 //! |
|
1302 //! 9) The associated TRequestStatus object should indicate KErrCancel, exits otherwise. |
|
1303 //! |
|
1304 //! 10) The TRequestStatus object associated with the get operation should indicate |
|
1305 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel |
|
1306 //! operation should indicate KErrNone - exits otherwise. |
|
1307 //! |
|
1308 //! 11) The TRequestStatus object associated with the get operation should indicate |
|
1309 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel |
|
1310 //! operation should indicate KErrNone - exits otherwise. |
|
1311 //! |
|
1312 //! 12) The TRequestStatus objects should all exibit KErrCancel - exits otherwise. |
|
1313 //! |
|
1314 //! 13) The TRequestStatus objects should all exibit KErrCancel - exits otherwise. |
|
1315 //! |
|
1316 //! 14) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise. |
|
1317 //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise |
|
1318 //! |
|
1319 //! 15) The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise. |
|
1320 //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise |
|
1321 //! |
|
1322 //! 16) The TRequestStatus objects associated with the get operations should all exibit KErrCancel - exits otherwise. |
|
1323 //! The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise |
|
1324 //! |
|
1325 //! 17) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise. |
|
1326 //! The TRequestStatus objects associated with the modify operations should all exibit KErrCancel - exits otherwise |
|
1327 //! |
|
1328 //! 18) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise. |
|
1329 //! |
|
1330 //! 19) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise. |
|
1331 //! |
|
1332 //! 20) The TRequestStatus objects associated with the even-numbered request should exhibit KErrCancel. |
|
1333 //! The TRequestStatus objects associated with the odd-numbered request should exhibit KErrNone. |
|
1334 //! |
|
1335 //! @SYMTestPriority High |
|
1336 //! @SYMTestStatus Implemented |
|
1337 //---------------------------------------------------------------------------------------------- |
|
1338 LOCAL_C TInt TestGetSetResourceStateOps() |
|
1339 // |
|
1340 // Test resource state access methods |
|
1341 // |
|
1342 { |
|
1343 TInt r = KErrNone; |
|
1344 |
|
1345 TRequestStatus status; |
|
1346 TBool cached = gUseCached; |
|
1347 TInt readValue = 0; |
|
1348 TInt levelOwnerId = 0; |
|
1349 TInt testNo = 0; |
|
1350 |
|
1351 #ifdef _DEBUG |
|
1352 // Ensure we have a resource we can use |
|
1353 if((r=SetAsyncResource())!=KErrNone) |
|
1354 return r; |
|
1355 #endif |
|
1356 |
|
1357 // 0) Call API to get the initial state of a selected resource. |
|
1358 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1359 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1360 User::WaitForRequest(status); |
|
1361 if(status.Int() != KErrNone) |
|
1362 { |
|
1363 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); |
|
1364 return r; |
|
1365 } |
|
1366 TUint startingLevel = (TUint)readValue; |
|
1367 gTest.Printf(_L("TestGetSetResourceStateOps: initial level read =0x%x, levelOwnerId = %d\n"),readValue,levelOwnerId); |
|
1368 |
|
1369 // 1) Call API to modify the state of the resource. |
|
1370 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1371 TUint newLevel = (TUint)(readValue + gAsyncResStateDelta); |
|
1372 gTest.Printf(_L("TestGetSetResourceStateOps: writing 0x%x\n"), newLevel); |
|
1373 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); |
|
1374 User::WaitForRequest(status); |
|
1375 if(status.Int() != KErrNone) |
|
1376 { |
|
1377 gTest.Printf(_L("TestGetSetResourceStateOps, first change state returned %d\n"),r); |
|
1378 return r; |
|
1379 } |
|
1380 |
|
1381 // 2) Call API to get the new state of the resource and check it exhibits the expected value. |
|
1382 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1383 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1384 User::WaitForRequest(status); |
|
1385 if(status.Int() != KErrNone) |
|
1386 { |
|
1387 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); |
|
1388 return r; |
|
1389 } |
|
1390 gTest.Printf(_L("TestGetSetResourceStateOps: level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId); |
|
1391 gTest(newLevel==(TUint)readValue); |
|
1392 |
|
1393 // 3) Call API to return the resource state to its original value. |
|
1394 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1395 gTest.Printf(_L("TestGetSetResourceStateOps: write original level 0x%x\n"), startingLevel); |
|
1396 gChannel.ChangeResourceState(status,gLongLatencyResource,startingLevel); |
|
1397 User::WaitForRequest(status); |
|
1398 if(status.Int() != KErrNone) |
|
1399 { |
|
1400 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); |
|
1401 return r; |
|
1402 } |
|
1403 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1404 User::WaitForRequest(status); |
|
1405 if(status.Int() != KErrNone) |
|
1406 { |
|
1407 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); |
|
1408 return r; |
|
1409 } |
|
1410 gTest.Printf(_L("TestGetSetResourceStateOps: check original level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId); |
|
1411 |
|
1412 // 4) Call API to get the state of a long latency resource then call API with operation-type qualifier cancel the request. |
|
1413 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1414 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1415 r=gChannel.CancelGetResourceState(status); |
|
1416 if(r!=KErrInUse) |
|
1417 { |
|
1418 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r); |
|
1419 } |
|
1420 if(r!=KErrCompletion) // If request had not completed before cancellation request |
|
1421 { |
|
1422 User::WaitForRequest(status); |
|
1423 if(r==KErrNone) // Cancel expected to proceed as requested |
|
1424 { |
|
1425 if(status.Int() != KErrCancel) |
|
1426 { |
|
1427 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r); |
|
1428 return r; |
|
1429 } |
|
1430 } |
|
1431 else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion |
|
1432 { |
|
1433 if(status.Int() != KErrNone) |
|
1434 { |
|
1435 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r); |
|
1436 return r; |
|
1437 } |
|
1438 } |
|
1439 else if(status.Int() != KErrCancel) // Just report the error code and return |
|
1440 { |
|
1441 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); |
|
1442 return r; |
|
1443 } |
|
1444 |
|
1445 } |
|
1446 |
|
1447 // 5) Call API to modify the state of the long latency resource then call API with operation-type qualifier to cancel the request. |
|
1448 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1449 newLevel = (TUint)(readValue + gAsyncResStateDelta); |
|
1450 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); |
|
1451 r=gChannel.CancelChangeResourceState(status); |
|
1452 if(r!=KErrInUse) |
|
1453 { |
|
1454 gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r); |
|
1455 } |
|
1456 if(r!=KErrCompletion) // If request had not completed before cancellation request |
|
1457 { |
|
1458 User::WaitForRequest(status); |
|
1459 if(r==KErrNone) // Cancel expected to proceed as requested |
|
1460 { |
|
1461 if(status.Int() != KErrCancel) |
|
1462 { |
|
1463 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r); |
|
1464 return r; |
|
1465 } |
|
1466 } |
|
1467 else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion |
|
1468 { |
|
1469 if(status.Int() != KErrNone) |
|
1470 { |
|
1471 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r); |
|
1472 return r; |
|
1473 } |
|
1474 } |
|
1475 else if(status.Int() != KErrCancel) // Just report the error code and return |
|
1476 { |
|
1477 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); |
|
1478 return r; |
|
1479 } |
|
1480 } |
|
1481 |
|
1482 |
|
1483 // 6) Call API to get the state of a long latency resource and wait for it to complete. |
|
1484 // Then call API with operation-type qualifier to cancel the request. |
|
1485 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1486 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1487 User::WaitForRequest(status); |
|
1488 if(status.Int() != KErrNone) |
|
1489 { |
|
1490 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); |
|
1491 return r; |
|
1492 } |
|
1493 r=gChannel.CancelGetResourceState(status); |
|
1494 if(r!=KErrNone) |
|
1495 { |
|
1496 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r); |
|
1497 } |
|
1498 if(status.Int() != KErrNone) // TRequestStatus should be unchanged |
|
1499 { |
|
1500 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r); |
|
1501 return r; |
|
1502 } |
|
1503 |
|
1504 // 7) Call API to modify the state of the long latency resource and wait for it to complete. |
|
1505 // Then call API with operation-type qualifier to cancel the request. |
|
1506 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1507 gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1508 User::WaitForRequest(status); |
|
1509 if(status.Int() != KErrNone) |
|
1510 { |
|
1511 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); |
|
1512 return r; |
|
1513 } |
|
1514 r=gChannel.CancelChangeResourceState(status); |
|
1515 if(r!=KErrNone) |
|
1516 { |
|
1517 gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r); |
|
1518 } |
|
1519 if(status.Int() != KErrNone) // TRequestStatus should be unchanged |
|
1520 { |
|
1521 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r); |
|
1522 return r; |
|
1523 } |
|
1524 |
|
1525 // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request. |
|
1526 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1527 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1528 gChannel.CancelAsyncOperation(&status); |
|
1529 User::WaitForRequest(status); |
|
1530 if(status.Int() != KErrCancel) |
|
1531 { |
|
1532 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); |
|
1533 return r; |
|
1534 } |
|
1535 |
|
1536 // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request. |
|
1537 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1538 newLevel = (TUint)(readValue + gAsyncResStateDelta); |
|
1539 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); |
|
1540 gChannel.CancelAsyncOperation(&status); |
|
1541 User::WaitForRequest(status); |
|
1542 if(status.Int() != KErrCancel) |
|
1543 { |
|
1544 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r); |
|
1545 return r; |
|
1546 } |
|
1547 |
|
1548 // 10) Call API to get the state of a long latency resource and wait for it to complete. |
|
1549 // Then call API without operation-type qualifier to cancel the request. |
|
1550 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1551 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1552 User::WaitForRequest(status); |
|
1553 if(status.Int() != KErrNone) |
|
1554 { |
|
1555 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); |
|
1556 return r; |
|
1557 } |
|
1558 gChannel.CancelAsyncOperation(&status); |
|
1559 if(status.Int() != KErrNone) // TRequestStatus should be unchanged |
|
1560 { |
|
1561 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r); |
|
1562 return r; |
|
1563 } |
|
1564 |
|
1565 // 11) Call API to modify the state of the long latency resource and wait for it to complete. |
|
1566 // Then call API without operation-type qualifier to cancel the request. |
|
1567 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1568 gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1569 User::WaitForRequest(status); |
|
1570 if(status.Int() != KErrNone) |
|
1571 { |
|
1572 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); |
|
1573 return r; |
|
1574 } |
|
1575 gChannel.CancelAsyncOperation(&status); |
|
1576 if(status.Int() != KErrNone) // TRequestStatus should be unchanged |
|
1577 { |
|
1578 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r); |
|
1579 return r; |
|
1580 } |
|
1581 |
|
1582 // 'n' and 'm' values and support for cancellation of multiple requests |
|
1583 const TInt KLoopVarN = 2; |
|
1584 const TInt KLoopVarM = 3; |
|
1585 TRequestStatus getReqStatus[KLoopVarN]; |
|
1586 TRequestStatus setReqStatus[KLoopVarM]; |
|
1587 TInt i=0; |
|
1588 |
|
1589 // 12) Call API to get the state of a long latency resource 'n' times. |
|
1590 // Then call API with resource qualifier to cancel the requests. |
|
1591 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1592 for(i=0;i<KLoopVarN;i++) |
|
1593 { |
|
1594 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1595 } |
|
1596 gChannel.CancelGetResourceStateRequests(gLongLatencyResource); |
|
1597 for(i=0;i<KLoopVarN;i++) |
|
1598 { |
|
1599 User::WaitForRequest(getReqStatus[i]); |
|
1600 if((r=getReqStatus[i].Int()) != KErrCancel) |
|
1601 { |
|
1602 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r); |
|
1603 return r; |
|
1604 } |
|
1605 } |
|
1606 |
|
1607 // 13) Call API to modify the state of a long latency resource 'm' times. |
|
1608 // Then call API with resource qualifier to cancel the requests. |
|
1609 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1610 for(i=0;i<KLoopVarM;i++) |
|
1611 { |
|
1612 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1613 } |
|
1614 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource); |
|
1615 for(i=0;i<KLoopVarM;i++) |
|
1616 { |
|
1617 User::WaitForRequest(setReqStatus[i]); |
|
1618 if((r=setReqStatus[i].Int()) != KErrCancel) |
|
1619 { |
|
1620 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r); |
|
1621 return r; |
|
1622 } |
|
1623 } |
|
1624 |
|
1625 // 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete. |
|
1626 // Then call API with resource qualifier to cancel the requests. |
|
1627 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1628 for(i=0;i<KLoopVarN;i++) |
|
1629 { |
|
1630 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1631 } |
|
1632 for(i=0;i<KLoopVarN;i++) |
|
1633 { |
|
1634 User::WaitForRequest(getReqStatus[i]); |
|
1635 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1636 { |
|
1637 gTest.Printf(_L("TestGetSetResourceStateOps, before cancel get state status[%d] = %d\n"),i,r); |
|
1638 return r; |
|
1639 } |
|
1640 } |
|
1641 gChannel.CancelGetResourceStateRequests(gLongLatencyResource); |
|
1642 for(i=0;i<KLoopVarN;i++) |
|
1643 { |
|
1644 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1645 { |
|
1646 gTest.Printf(_L("TestGetSetResourceStateOps, after cancel get state status[%d] = %d\n"),i,r); |
|
1647 return r; |
|
1648 } |
|
1649 } |
|
1650 |
|
1651 // 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete. |
|
1652 // Then call API with resource qualifier to cancel the requests. |
|
1653 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1654 for(i=0;i<KLoopVarM;i++) |
|
1655 { |
|
1656 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1657 } |
|
1658 for(i=0;i<KLoopVarM;i++) |
|
1659 { |
|
1660 User::WaitForRequest(setReqStatus[i]); |
|
1661 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1662 { |
|
1663 gTest.Printf(_L("TestGetSetResourceStateOps, before cancel change state status[%d] = %d\n"),i,r); |
|
1664 return r; |
|
1665 } |
|
1666 } |
|
1667 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource); |
|
1668 for(i=0;i<KLoopVarM;i++) |
|
1669 { |
|
1670 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1671 { |
|
1672 gTest.Printf(_L("TestGetSetResourceStateOps, after cancel change state status[%d] = %d\n"),i,r); |
|
1673 return r; |
|
1674 } |
|
1675 } |
|
1676 |
|
1677 // 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1678 // a long latency resource 'm' times. |
|
1679 // Call the API to cancel the get operations with resource qualifier. |
|
1680 // Wait for the operations to complete. Check the state of the associated TRequestStatus objects. |
|
1681 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1682 for(i=0;i<KLoopVarN;i++) |
|
1683 { |
|
1684 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1685 } |
|
1686 for(i=0;i<KLoopVarM;i++) |
|
1687 { |
|
1688 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1689 } |
|
1690 gChannel.CancelGetResourceStateRequests(gLongLatencyResource); |
|
1691 for(i=0;i<KLoopVarN;i++) |
|
1692 { |
|
1693 User::WaitForRequest(getReqStatus[i]); |
|
1694 if((r=getReqStatus[i].Int()) != KErrCancel) |
|
1695 { |
|
1696 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r); |
|
1697 return r; |
|
1698 } |
|
1699 } |
|
1700 for(i=0;i<KLoopVarM;i++) |
|
1701 { |
|
1702 User::WaitForRequest(setReqStatus[i]); |
|
1703 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1704 { |
|
1705 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r); |
|
1706 return r; |
|
1707 } |
|
1708 } |
|
1709 |
|
1710 // 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1711 // a long latency resource 'm' times. |
|
1712 // Call the API to cancel the modify operations with resource qualifier. |
|
1713 // Wait for the get operations to complete. Check the state of the associated TRequestStatus objects. |
|
1714 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1715 for(i=0;i<KLoopVarN;i++) |
|
1716 { |
|
1717 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1718 } |
|
1719 for(i=0;i<KLoopVarM;i++) |
|
1720 { |
|
1721 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1722 } |
|
1723 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource); |
|
1724 for(i=0;i<KLoopVarN;i++) |
|
1725 { |
|
1726 User::WaitForRequest(getReqStatus[i]); |
|
1727 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1728 { |
|
1729 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r); |
|
1730 return r; |
|
1731 } |
|
1732 } |
|
1733 for(i=0;i<KLoopVarM;i++) |
|
1734 { |
|
1735 User::WaitForRequest(setReqStatus[i]); |
|
1736 if((r=setReqStatus[i].Int()) != KErrCancel) |
|
1737 { |
|
1738 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r); |
|
1739 return r; |
|
1740 } |
|
1741 } |
|
1742 |
|
1743 // 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1744 // a long latency resource 'm' times. Wait for the get operations to complete. |
|
1745 // Call the API to cancel the get operations with resource qualifier. Check the state of the associated TRequestStatus objects. |
|
1746 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1747 for(i=0;i<KLoopVarN;i++) |
|
1748 { |
|
1749 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1750 } |
|
1751 TInt flipper = -1; |
|
1752 for(i=0;i<KLoopVarM;i++) |
|
1753 { |
|
1754 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + (flipper*gAsyncResStateDelta))); |
|
1755 flipper*=-1; |
|
1756 } |
|
1757 for(i=0;i<KLoopVarN;i++) |
|
1758 { |
|
1759 User::WaitForRequest(getReqStatus[i]); |
|
1760 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1761 { |
|
1762 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r); |
|
1763 return r; |
|
1764 } |
|
1765 } |
|
1766 gChannel.CancelGetResourceStateRequests(gLongLatencyResource); |
|
1767 for(i=0;i<KLoopVarM;i++) |
|
1768 { |
|
1769 User::WaitForRequest(setReqStatus[i]); |
|
1770 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1771 { |
|
1772 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d]= %d\n"),i,r); |
|
1773 return r; |
|
1774 } |
|
1775 } |
|
1776 for(i=0;i<KLoopVarN;i++) |
|
1777 { |
|
1778 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1779 { |
|
1780 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status[%d]= %d\n"),i,r); |
|
1781 return r; |
|
1782 } |
|
1783 } |
|
1784 |
|
1785 // 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of |
|
1786 // a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify |
|
1787 // operations with resource qualifier. Check the state of the associated TRequestStatus objects. |
|
1788 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1789 for(i=0;i<KLoopVarN;i++) |
|
1790 { |
|
1791 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1792 } |
|
1793 for(i=0;i<KLoopVarM;i++) |
|
1794 { |
|
1795 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1796 } |
|
1797 for(i=0;i<KLoopVarM;i++) |
|
1798 { |
|
1799 User::WaitForRequest(setReqStatus[i]); |
|
1800 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1801 { |
|
1802 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r); |
|
1803 return r; |
|
1804 } |
|
1805 } |
|
1806 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource); |
|
1807 for(i=0;i<KLoopVarN;i++) |
|
1808 { |
|
1809 User::WaitForRequest(getReqStatus[i]); |
|
1810 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1811 { |
|
1812 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r); |
|
1813 return r; |
|
1814 } |
|
1815 } |
|
1816 for(i=0;i<KLoopVarM;i++) |
|
1817 { |
|
1818 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1819 { |
|
1820 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r); |
|
1821 return r; |
|
1822 } |
|
1823 } |
|
1824 |
|
1825 // 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of a long latency resource 'm' times. |
|
1826 // Then call API without operation-type qualifier to cancel the even-numbered modify request(s). |
|
1827 // Then call API with operation-type qualifier to cancel the even-numbered get request(s). |
|
1828 // Check the state of the associated TRequestStatus objects. |
|
1829 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1830 for(i=0;i<KLoopVarN;i++) |
|
1831 { |
|
1832 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1833 } |
|
1834 for(i=0;i<KLoopVarM;i++) |
|
1835 { |
|
1836 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta)); |
|
1837 } |
|
1838 for(i=0;i<KLoopVarM;i+=2) |
|
1839 { |
|
1840 gChannel.CancelAsyncOperation(&(setReqStatus[i])); |
|
1841 } |
|
1842 for(i=0;i<KLoopVarN;i+=2) |
|
1843 { |
|
1844 r=gChannel.CancelGetResourceState(getReqStatus[i]); |
|
1845 if(r!=KErrNone) |
|
1846 { |
|
1847 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r); |
|
1848 return r; |
|
1849 } |
|
1850 } |
|
1851 for(i=0;i<KLoopVarM;i++) |
|
1852 { |
|
1853 User::WaitForRequest(setReqStatus[i]); |
|
1854 if((r=setReqStatus[i].Int()) != KErrCancel) |
|
1855 { |
|
1856 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r); |
|
1857 return r; |
|
1858 } |
|
1859 if(++i >= KLoopVarM) |
|
1860 break; |
|
1861 User::WaitForRequest(setReqStatus[i]); |
|
1862 if((r=setReqStatus[i].Int()) != KErrNone) |
|
1863 { |
|
1864 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r); |
|
1865 return r; |
|
1866 } |
|
1867 } |
|
1868 for(i=0;i<KLoopVarN;i++) |
|
1869 { |
|
1870 User::WaitForRequest(getReqStatus[i]); |
|
1871 if((r=getReqStatus[i].Int()) != KErrCancel) |
|
1872 { |
|
1873 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r); |
|
1874 return r; |
|
1875 } |
|
1876 if(++i >= KLoopVarN) |
|
1877 break; |
|
1878 User::WaitForRequest(getReqStatus[i]); |
|
1879 if((r=getReqStatus[i].Int()) != KErrNone) |
|
1880 { |
|
1881 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r); |
|
1882 return r; |
|
1883 } |
|
1884 } |
|
1885 return KErrNone; |
|
1886 } |
|
1887 |
|
1888 |
|
1889 //---------------------------------------------------------------------------------------------- |
|
1890 //! @SYMTestCaseID KBASE-T_RESMANUS-0611 |
|
1891 //! @SYMTestType UT |
|
1892 //! @SYMPREQ PREQ1398 |
|
1893 //! @SYMTestCaseDesc This test case tests APIs for regulating getting and setting the state of resources |
|
1894 //! |
|
1895 //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API) |
|
1896 //! of requests to get the current state of a resource. Then issue one further request. |
|
1897 //! |
|
1898 //! 1) Issue the maximum number (requested in the call to the Initialise API) of |
|
1899 //! requests to set the current state of a resource. Then issue one further request. |
|
1900 //! |
|
1901 //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last request |
|
1902 //! exhibits status code KErrUnderflow - exit otherwise. Test that the |
|
1903 //! TRequestStatus objects associated with the preceding requests exhibit |
|
1904 //! status code KErrNone - exit otherwise. |
|
1905 //! |
|
1906 //! 1) Test that the TRequestStatus object associated with the last request |
|
1907 //! exhibits status code KErrUnderflow - exit otherwise. Test that the |
|
1908 //! TRequestStatus objects associated with the preceding requests exhibit |
|
1909 //! status code KErrNone - exit otherwise. |
|
1910 //! |
|
1911 //! @SYMTestPriority High |
|
1912 //! @SYMTestStatus Implemented |
|
1913 //---------------------------------------------------------------------------------------------- |
|
1914 LOCAL_C TInt TestGetSetResourceStateQuota() |
|
1915 // |
|
1916 // Test resource state access quota management |
|
1917 // |
|
1918 { |
|
1919 TUint resourceId; |
|
1920 |
|
1921 // To perform the quota test we need a long latency resource |
|
1922 // If one has not been defined alert the user and return |
|
1923 if(!gHaveAsyncRes) |
|
1924 { |
|
1925 gTest.Printf(_L("TestGetSetResourceStateQuota: don't have suitable asynchronous resource ... exiting\n")); |
|
1926 return KErrNone; |
|
1927 } |
|
1928 else |
|
1929 resourceId = gLongLatencyResource; |
|
1930 |
|
1931 TInt r = KErrNone; |
|
1932 TBool lastErr = KErrNone; |
|
1933 |
|
1934 TInt i = 0; |
|
1935 TRequestStatus status[MAX_NUM_REQUESTS]; |
|
1936 TInt state[MAX_NUM_REQUESTS]; |
|
1937 TBool cached = gUseCached; |
|
1938 TInt levelOwnerId = 0; |
|
1939 |
|
1940 // |
|
1941 // Test GetResourceState - check client can not exceed quota of requests |
|
1942 // |
|
1943 gTest.Printf(_L("**Test GetResourceState (quota management)\n")); |
|
1944 |
|
1945 // KNoOfGetStateRequests Get state requests (of the same resource, ID=1) to consume the client quota |
|
1946 for(i=0; i<KNoOfGetStateRequests; i++) |
|
1947 gChannel.GetResourceState(status[i],resourceId,cached,&(state[i]),&levelOwnerId); |
|
1948 |
|
1949 // Addition Get state request to exceed the quota - the provided TRequestStatus |
|
1950 // object should indicate KErrUnderflow |
|
1951 gChannel.GetResourceState(status[KNoOfGetStateRequests],resourceId,cached,&(state[KNoOfGetStateRequests]),&levelOwnerId); |
|
1952 User::WaitForRequest(status[KNoOfGetStateRequests]); |
|
1953 if(status[KNoOfGetStateRequests].Int() != KErrUnderflow) |
|
1954 { |
|
1955 gTest.Printf(_L("TestGetSetResourceStateQuota, extra get state returned %d\n"),r); |
|
1956 return r; |
|
1957 } |
|
1958 |
|
1959 // Need to check the TRequestStatus objects |
|
1960 for(i=0; i<KNoOfGetStateRequests; i++) |
|
1961 { |
|
1962 User::WaitForRequest(status[i]); |
|
1963 if((r=status[i].Int()) != KErrNone) |
|
1964 { |
|
1965 gTest.Printf(_L("TestGetSetResourceStateQuota, get state %d returned %d\n"),i, r); |
|
1966 lastErr = r; |
|
1967 } |
|
1968 } |
|
1969 if(lastErr != KErrNone) |
|
1970 return lastErr; |
|
1971 |
|
1972 // |
|
1973 // Test ChangeResourceState - check client can not exceed quota of requests |
|
1974 // |
|
1975 gTest.Printf(_L("**Test ChangeResourceState (quota management)\n")); |
|
1976 |
|
1977 // KNoOfSetStateRequests Set state requests (of the same resource, ID=1) to consume the client quota |
|
1978 TInt newState = (state[1])+1; |
|
1979 for(i=0; i<KNoOfSetStateRequests; i++) |
|
1980 { |
|
1981 gChannel.ChangeResourceState(status[i],resourceId,newState); |
|
1982 } |
|
1983 |
|
1984 // Addition Set state request to exceed the quota - the provided TRequestStatus |
|
1985 // object should indicate KErrUnderflow |
|
1986 gChannel.ChangeResourceState(status[KNoOfSetStateRequests],resourceId,newState); |
|
1987 User::WaitForRequest(status[KNoOfSetStateRequests]); |
|
1988 if(status[KNoOfSetStateRequests].Int() != KErrUnderflow) |
|
1989 { |
|
1990 gTest.Printf(_L("TestGetSetResourceStateQuota, extra set state returned %d\n"),r); |
|
1991 return r; |
|
1992 } |
|
1993 |
|
1994 // Need to check the TRequestStatus objects |
|
1995 for(i=0; i<KNoOfSetStateRequests; i++) |
|
1996 { |
|
1997 User::WaitForRequest(status[i]); |
|
1998 if((r=status[i].Int()) != KErrNone) |
|
1999 { |
|
2000 gTest.Printf(_L("TestGetSetResourceStateQuota, set state %d returned %d\n"),i, r); |
|
2001 lastErr = r; |
|
2002 } |
|
2003 } |
|
2004 if(lastErr != KErrNone) |
|
2005 return lastErr; |
|
2006 |
|
2007 return r; |
|
2008 } |
|
2009 |
|
2010 |
|
2011 LOCAL_C TInt TriggerNotification(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt aDelta) |
|
2012 // |
|
2013 // Support the notification tests - cause a notification for the specified resource |
|
2014 // |
|
2015 { |
|
2016 TInt r = KErrNone; |
|
2017 TInt readValue = 0; |
|
2018 TInt levelOwnerId = 0; |
|
2019 // Get initial state |
|
2020 gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId); |
|
2021 User::WaitForRequest(aStatus); |
|
2022 if(aStatus.Int() != KErrNone) |
|
2023 { |
|
2024 r=aStatus.Int(); |
|
2025 gTest.Printf(_L("TriggerNotification, get state returned %d\n"),r); |
|
2026 return r; |
|
2027 } |
|
2028 TUint startingLevel = (TUint)readValue; |
|
2029 |
|
2030 // Write updated state |
|
2031 TUint newLevel = (TUint)(readValue + aDelta); |
|
2032 gTest.Printf(_L("TriggerNotification: startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel); |
|
2033 gChannel.ChangeResourceState(aStatus,aResourceId,newLevel); |
|
2034 User::WaitForRequest(aStatus); |
|
2035 if(aStatus.Int() != KErrNone) |
|
2036 { |
|
2037 r=aStatus.Int(); |
|
2038 gTest.Printf(_L("TriggerNotification, change state returned %d\n"),r); |
|
2039 return r; |
|
2040 } |
|
2041 |
|
2042 return r; |
|
2043 } |
|
2044 |
|
2045 |
|
2046 LOCAL_C TInt CalcNotifyDirAndThr(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt& aThreshold, TBool& aDirection) |
|
2047 // |
|
2048 // Support the notification tests - determine an appropriate threshold and direction to request |
|
2049 // |
|
2050 { |
|
2051 __KHEAP_MARK; |
|
2052 |
|
2053 // Need to know current state |
|
2054 TInt r = KErrNone; |
|
2055 TInt readValue = 0; |
|
2056 TInt levelOwnerId = 0; |
|
2057 { |
|
2058 gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId); |
|
2059 User::WaitForRequest(aStatus); |
|
2060 if(aStatus.Int() != KErrNone) |
|
2061 { |
|
2062 r=aStatus.Int(); |
|
2063 gTest.Printf(_L("TestNotificationOps, pre-qualified notify get state returned %d\n"),r); |
|
2064 return r; |
|
2065 } |
|
2066 } |
|
2067 aThreshold = readValue + gAsyncResStateDelta; |
|
2068 aDirection=(gAsyncResStateDelta>0)?ETrue:EFalse; |
|
2069 |
|
2070 __KHEAP_MARKEND; |
|
2071 |
|
2072 return r; |
|
2073 } |
|
2074 |
|
2075 |
|
2076 //---------------------------------------------------------------------------------------------- |
|
2077 //! @SYMTestCaseID KBASE-T_RESMANUS-0612 |
|
2078 //! @SYMTestType UT |
|
2079 //! @SYMPREQ PREQ1398 |
|
2080 //! @SYMTestCaseDesc This test case tests APIs for requesting both qualified and unqualified |
|
2081 //! notifications; it also tests APIs to cancel such requests. |
|
2082 //! |
|
2083 //! @SYMTestActions 0) Call API to request notification of an unqualified change in resource |
|
2084 //! state for a selected resource. Trigger a state change. |
|
2085 //! |
|
2086 //! 1) Call API to request notification of a qualified change in resource |
|
2087 //! state for a selected resource. Trigger a state change. |
|
2088 //! |
|
2089 //! 2) Call API to request notification of an unqualified change in resource |
|
2090 //! state for a selected resource. Then call API to cancel all notifications for the resource. |
|
2091 //! |
|
2092 //! 3) Call API to request notification of a qualified change in resource |
|
2093 //! state for a selected resource. Then call API to cancel all notifications for the resource. |
|
2094 //! |
|
2095 //! 4) Call API to request notification of an unqualified change in resource |
|
2096 //! state for a selected resource. Trigger a state change. Then call API to cancel all |
|
2097 //! notifications for the resource. |
|
2098 //! |
|
2099 //! 5) Call API to request notification of a qualified change in resource |
|
2100 //! state for a selected resource. Trigger a state change. Then call API to cancel all |
|
2101 //! notifications for the resource. |
|
2102 //! |
|
2103 //! 6) Call API to request notification of an unqualified change in resource |
|
2104 //! state for a selected resource. Then call API to cancel the notification request |
|
2105 //! |
|
2106 //! 7) Call API to request notification of a qualified change in resource |
|
2107 //! state for a selected resource. Then call API to cancel the notification request |
|
2108 //! |
|
2109 //! 8) Call API to request notification of an unqualified change in resource |
|
2110 //! state for a selected resource. Trigger a state change. Then call API to cancel the |
|
2111 //! notification request |
|
2112 //! |
|
2113 //! 9) Call API to request notification of a qualified change in resource |
|
2114 //! state for a selected resource. Trigger a state change. Then call API to cancel the |
|
2115 //! notification request |
|
2116 //! |
|
2117 //! 10) Call API to request notification of an unqualified change in resource |
|
2118 //! state for a selected resource. Then call API to cancel generic async request |
|
2119 //! |
|
2120 //! 11) Call API to request notification of a qualified change in resource |
|
2121 //! state for a selected resource. Then call API to cancel generic async request |
|
2122 //! |
|
2123 //! 12) Call API to request notification of an unqualified change in resource |
|
2124 //! state for a selected resource. Trigger a state change. Then call API to cancel |
|
2125 //! generic async request |
|
2126 //! |
|
2127 //! 13) Call API to request notification of a qualified change in resource |
|
2128 //! state for a selected resource. Trigger a state change. Then call API to cancel |
|
2129 //! generic async request |
|
2130 //! |
|
2131 //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone |
|
2132 //! - exits otherwise. |
|
2133 //! |
|
2134 //! 1) The associated TRequestStatus object should indicate KErrNone |
|
2135 //! - exits otherwise. |
|
2136 //! |
|
2137 //! 2) The associated TRequestStatus object should indicate KErrCancel |
|
2138 //! - exits otherwise. |
|
2139 //! |
|
2140 //! 3) The associated TRequestStatus object should indicate KErrCancel |
|
2141 //! - exits otherwise. |
|
2142 //! |
|
2143 //! 4) The TRequestStatus object should indicate state KRequestPending until |
|
2144 //! the state change is triggered, upon which it should exhibit state |
|
2145 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2146 //! Exit for any deviation from this behaviour. |
|
2147 //! |
|
2148 //! 5) The TRequestStatus object should indicate state KRequestPending until |
|
2149 //! the state change is triggered, upon which it should exhibit state |
|
2150 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2151 //! Exit for any deviation from this behaviour. |
|
2152 //! |
|
2153 //! 6) The associated TRequestStatus object should indicate KErrCancel |
|
2154 //! - exits otherwise. |
|
2155 //! |
|
2156 //! 7) The associated TRequestStatus object should indicate KErrCancel |
|
2157 //! - exits otherwise. |
|
2158 //! |
|
2159 //! 8) The TRequestStatus object should indicate state KRequestPending until |
|
2160 //! the state change is triggered, upon which it should exhibit state |
|
2161 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2162 //! Exit for any deviation from this behaviour. |
|
2163 //! |
|
2164 //! 9) The TRequestStatus object should indicate state KRequestPending until |
|
2165 //! the state change is triggered, upon which it should exhibit state |
|
2166 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2167 //! Exit for any deviation from this behaviour. |
|
2168 //! |
|
2169 //! 10) The associated TRequestStatus object should indicate KErrCancel |
|
2170 //! - exits otherwise. |
|
2171 //! |
|
2172 //! 11) The associated TRequestStatus object should indicate KErrCancel |
|
2173 //! - exits otherwise. |
|
2174 //! |
|
2175 //! 12) The TRequestStatus object should indicate state KRequestPending until |
|
2176 //! the state change is triggered, upon which it should exhibit state |
|
2177 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2178 //! Exit for any deviation from this behaviour. |
|
2179 //! |
|
2180 //! 13) The TRequestStatus object should indicate state KRequestPending until |
|
2181 //! the state change is triggered, upon which it should exhibit state |
|
2182 //! KErrNone. After the cancellation it should still exhibit state KErrNone. |
|
2183 //! Exit for any deviation from this behaviour. |
|
2184 //! |
|
2185 //! @SYMTestPriority High |
|
2186 //! @SYMTestStatus Implemented |
|
2187 //---------------------------------------------------------------------------------------------- |
|
2188 LOCAL_C TInt TestNotificationOps() |
|
2189 // |
|
2190 // Test notification methods |
|
2191 // |
|
2192 { |
|
2193 __KHEAP_MARK; |
|
2194 |
|
2195 TInt r = KErrNone; |
|
2196 TRequestStatus status; |
|
2197 TUint resourceId; |
|
2198 TInt stateDelta; |
|
2199 if(!gHaveAsyncRes) |
|
2200 { |
|
2201 resourceId = 2; // Arbitrary |
|
2202 stateDelta = 1; // Arbitrary |
|
2203 } |
|
2204 else |
|
2205 { |
|
2206 resourceId = gLongLatencyResource; |
|
2207 stateDelta = gAsyncResStateDelta; |
|
2208 } |
|
2209 TInt testIndex = 0; |
|
2210 |
|
2211 // 0) Call API to request notification of an unqualified change in resource |
|
2212 // state for a selected resource. Trigger a state change. |
|
2213 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2214 gChannel.RequestNotification(status, resourceId); |
|
2215 if(status.Int() != KRequestPending) |
|
2216 { |
|
2217 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2218 return KErrGeneral; |
|
2219 } |
|
2220 TBool cached = gUseCached; |
|
2221 TRequestStatus triggerStatus; |
|
2222 if((r=TriggerNotification(triggerStatus, resourceId, cached, stateDelta))!=KErrNone) |
|
2223 return r; |
|
2224 User::WaitForRequest(status); |
|
2225 if(status.Int()!=KErrNone) |
|
2226 { |
|
2227 gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int()); |
|
2228 return r; |
|
2229 } |
|
2230 |
|
2231 // 1) Call API to request notification of a qualified change in resource |
|
2232 // state for a selected resource. Trigger a state change. |
|
2233 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2234 TInt dumThreshold=0; |
|
2235 TBool dumDirection=EFalse; |
|
2236 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2237 return r; |
|
2238 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2239 if(status.Int() != KRequestPending) |
|
2240 { |
|
2241 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2242 return KErrGeneral; |
|
2243 } |
|
2244 // Pass gAsyncResStateDelta as this represents the delta value |
|
2245 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2246 return r; |
|
2247 User::WaitForRequest(status); |
|
2248 if(status.Int()!=KErrNone) |
|
2249 { |
|
2250 gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int()); |
|
2251 return r; |
|
2252 } |
|
2253 |
|
2254 // 2) Call API to request notification of an unqualified change in resource |
|
2255 // state for a selected resource. Then call API to cancel all notifications for the resource. |
|
2256 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2257 gChannel.RequestNotification(status, resourceId); |
|
2258 if(status.Int() != KRequestPending) |
|
2259 { |
|
2260 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2261 return KErrGeneral; |
|
2262 } |
|
2263 r=gChannel.CancelNotificationRequests(resourceId); |
|
2264 if(r!=KErrNone) |
|
2265 { |
|
2266 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); |
|
2267 return r; |
|
2268 } |
|
2269 User::WaitForRequest(status); |
|
2270 if(status.Int()!=KErrCancel) |
|
2271 { |
|
2272 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); |
|
2273 return r; |
|
2274 } |
|
2275 |
|
2276 // 3) Call API to request notification of a qualified change in resource |
|
2277 // state for a selected resource. Then call API to cancel all notifications for the resource. |
|
2278 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2279 dumThreshold = 0; // Arbitrary |
|
2280 dumDirection = ETrue; // Arbitrary |
|
2281 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2282 return r; |
|
2283 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2284 if(status.Int() != KRequestPending) |
|
2285 { |
|
2286 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2287 return KErrGeneral; |
|
2288 } |
|
2289 r=gChannel.CancelNotificationRequests(resourceId); |
|
2290 if(r!=KErrNone) |
|
2291 { |
|
2292 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); |
|
2293 return r; |
|
2294 } |
|
2295 User::WaitForRequest(status); |
|
2296 if(status.Int()!=KErrCancel) |
|
2297 { |
|
2298 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); |
|
2299 return r; |
|
2300 } |
|
2301 |
|
2302 // 4) Call API to request notification of an unqualified change in resource |
|
2303 // state for a selected resource. Trigger a state change. Then call API to cancel all |
|
2304 // notifications for the resource. |
|
2305 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2306 gChannel.RequestNotification(status, resourceId); |
|
2307 if(status.Int() != KRequestPending) |
|
2308 { |
|
2309 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2310 return KErrGeneral; |
|
2311 } |
|
2312 // Pass gAsyncResStateDelta as this represents the delta value |
|
2313 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2314 return r; |
|
2315 User::WaitForRequest(status); |
|
2316 if(status.Int()!=KErrNone) |
|
2317 { |
|
2318 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); |
|
2319 return r; |
|
2320 } |
|
2321 r=gChannel.CancelNotificationRequests(resourceId); |
|
2322 if(r!=KErrNone) |
|
2323 { |
|
2324 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); |
|
2325 return r; |
|
2326 } |
|
2327 if(status.Int()!=KErrNone) |
|
2328 { |
|
2329 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); |
|
2330 return r; |
|
2331 } |
|
2332 |
|
2333 // 5) Call API to request notification of a qualified change in resource |
|
2334 // state for a selected resource. Trigger a state change. Then call API to cancel all |
|
2335 // notifications for the resource. |
|
2336 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2337 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2338 return r; |
|
2339 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2340 if(status.Int() != KRequestPending) |
|
2341 { |
|
2342 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2343 return KErrGeneral; |
|
2344 } |
|
2345 // Pass gAsyncResStateDelta as this represents the delta value |
|
2346 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2347 return r; |
|
2348 User::WaitForRequest(status); |
|
2349 if(status.Int()!=KErrNone) |
|
2350 { |
|
2351 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); |
|
2352 return r; |
|
2353 } |
|
2354 r=gChannel.CancelNotificationRequests(resourceId); |
|
2355 if(r!=KErrNone) |
|
2356 { |
|
2357 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); |
|
2358 return r; |
|
2359 } |
|
2360 if(status.Int()!=KErrNone) |
|
2361 { |
|
2362 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); |
|
2363 return r; |
|
2364 } |
|
2365 |
|
2366 // 6) Call API to request notification of an unqualified change in resource |
|
2367 // state for a selected resource. Then call API to cancel the notification request |
|
2368 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2369 gChannel.RequestNotification(status, resourceId); |
|
2370 if(status.Int() != KRequestPending) |
|
2371 { |
|
2372 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2373 return KErrGeneral; |
|
2374 } |
|
2375 r=gChannel.CancelRequestNotification(status); |
|
2376 if(r!=KErrNone) |
|
2377 { |
|
2378 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); |
|
2379 return r; |
|
2380 } |
|
2381 User::WaitForRequest(status); |
|
2382 if(status.Int()!=KErrCancel) |
|
2383 { |
|
2384 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); |
|
2385 return r; |
|
2386 } |
|
2387 |
|
2388 // 7) Call API to request notification of a qualified change in resource |
|
2389 // state for a selected resource. Then call API to cancel the notification request |
|
2390 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2391 dumThreshold = 0; // Arbitrary |
|
2392 dumDirection = ETrue; // Arbitrary |
|
2393 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2394 return r; |
|
2395 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2396 if(status.Int() != KRequestPending) |
|
2397 { |
|
2398 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2399 return KErrGeneral; |
|
2400 } |
|
2401 r=gChannel.CancelRequestNotification(status); |
|
2402 if(r!=KErrNone) |
|
2403 { |
|
2404 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); |
|
2405 return r; |
|
2406 } |
|
2407 User::WaitForRequest(status); |
|
2408 if(status.Int()!=KErrCancel) |
|
2409 { |
|
2410 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); |
|
2411 return r; |
|
2412 } |
|
2413 |
|
2414 // 8) Call API to request notification of an unqualified change in resource |
|
2415 // state for a selected resource. Trigger a state change. Then call API to cancel the |
|
2416 // notification request |
|
2417 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2418 gChannel.RequestNotification(status, resourceId); |
|
2419 if(status.Int() != KRequestPending) |
|
2420 { |
|
2421 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2422 return KErrGeneral; |
|
2423 } |
|
2424 // Pass gAsyncResStateDelta as this represents the delta value |
|
2425 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2426 return r; |
|
2427 User::WaitForRequest(status); |
|
2428 if(status.Int()!=KErrNone) |
|
2429 { |
|
2430 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); |
|
2431 return r; |
|
2432 } |
|
2433 r=gChannel.CancelRequestNotification(status); |
|
2434 if(r!=KErrNone) |
|
2435 { |
|
2436 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); |
|
2437 return r; |
|
2438 } |
|
2439 if(status.Int()!=KErrNone) |
|
2440 { |
|
2441 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); |
|
2442 return r; |
|
2443 } |
|
2444 |
|
2445 // 9) Call API to request notification of a qualified change in resource |
|
2446 // state for a selected resource. Trigger a state change. Then call API to cancel the |
|
2447 // notification request |
|
2448 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2449 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2450 return r; |
|
2451 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2452 if(status.Int() != KRequestPending) |
|
2453 { |
|
2454 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2455 return KErrGeneral; |
|
2456 } |
|
2457 // Pass gAsyncResStateDelta as this represents the delta value |
|
2458 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2459 return r; |
|
2460 User::WaitForRequest(status); |
|
2461 if(status.Int()!=KErrNone) |
|
2462 { |
|
2463 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); |
|
2464 return r; |
|
2465 } |
|
2466 r=gChannel.CancelRequestNotification(status); |
|
2467 if(r!=KErrNone) |
|
2468 { |
|
2469 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); |
|
2470 return r; |
|
2471 } |
|
2472 if(status.Int()!=KErrNone) |
|
2473 { |
|
2474 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); |
|
2475 return r; |
|
2476 } |
|
2477 |
|
2478 |
|
2479 // 10) Call API to request notification of an unqualified change in resource |
|
2480 // state for a selected resource. Then call API to cancel generic async request |
|
2481 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2482 gChannel.RequestNotification(status, resourceId); |
|
2483 if(status.Int() != KRequestPending) |
|
2484 { |
|
2485 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2486 return KErrGeneral; |
|
2487 } |
|
2488 gChannel.CancelAsyncOperation(&status); |
|
2489 User::WaitForRequest(status); |
|
2490 if(status.Int()!=KErrCancel) |
|
2491 { |
|
2492 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); |
|
2493 return r; |
|
2494 } |
|
2495 |
|
2496 // 11) Call API to request notification of a qualified change in resource |
|
2497 // state for a selected resource. Then call API to cancel generic async request |
|
2498 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2499 dumThreshold = 0; // Arbitrary |
|
2500 dumDirection = ETrue; // Arbitrary |
|
2501 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2502 return r; |
|
2503 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2504 if(status.Int() != KRequestPending) |
|
2505 { |
|
2506 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2507 return KErrGeneral; |
|
2508 } |
|
2509 gChannel.CancelAsyncOperation(&status); |
|
2510 User::WaitForRequest(status); |
|
2511 if(status.Int()!=KErrCancel) |
|
2512 { |
|
2513 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); |
|
2514 return r; |
|
2515 } |
|
2516 |
|
2517 // 12) Call API to request notification of an unqualified change in resource |
|
2518 // state for a selected resource. Trigger a state change. Then call API to cancel |
|
2519 // generic async request |
|
2520 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2521 gChannel.RequestNotification(status, resourceId); |
|
2522 if(status.Int() != KRequestPending) |
|
2523 { |
|
2524 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2525 return KErrGeneral; |
|
2526 } |
|
2527 // Pass gAsyncResStateDelta as this represents the delta value |
|
2528 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2529 return r; |
|
2530 User::WaitForRequest(status); |
|
2531 if(status.Int()!=KErrNone) |
|
2532 { |
|
2533 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); |
|
2534 return r; |
|
2535 } |
|
2536 gChannel.CancelAsyncOperation(&status); |
|
2537 if(status.Int()!=KErrNone) |
|
2538 { |
|
2539 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); |
|
2540 return r; |
|
2541 } |
|
2542 |
|
2543 // 13) Call API to request notification of a qualified change in resource |
|
2544 // state for a selected resource. Trigger a state change. Then call API to cancel |
|
2545 // generic async request |
|
2546 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); |
|
2547 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2548 return r; |
|
2549 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); |
|
2550 if(status.Int() != KRequestPending) |
|
2551 { |
|
2552 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); |
|
2553 return KErrGeneral; |
|
2554 } |
|
2555 // Pass gAsyncResStateDelta as this represents the delta value |
|
2556 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2557 return r; |
|
2558 User::WaitForRequest(status); |
|
2559 if(status.Int()!=KErrNone) |
|
2560 { |
|
2561 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); |
|
2562 return r; |
|
2563 } |
|
2564 gChannel.CancelAsyncOperation(&status); |
|
2565 if(status.Int()!=KErrNone) |
|
2566 { |
|
2567 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); |
|
2568 return r; |
|
2569 } |
|
2570 |
|
2571 __KHEAP_MARKEND; |
|
2572 |
|
2573 return r; |
|
2574 } |
|
2575 |
|
2576 //---------------------------------------------------------------------------------------------- |
|
2577 //! @SYMTestCaseID KBASE-T_RESMANUS-0613 |
|
2578 //! @SYMTestType UT |
|
2579 //! @SYMPREQ PREQ1398 |
|
2580 //! @SYMTestCaseDesc This test case tests quota management for notification operations. |
|
2581 //! |
|
2582 //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API) |
|
2583 //! of requests for notification of unqualified changes to the state of a |
|
2584 //! resource. Then issue one further request. |
|
2585 //! |
|
2586 //! 1) Issue the maximum number (requested in the call to the Initialise API) |
|
2587 //! of requests for notification of qualified changes to the state of a |
|
2588 //! resource. Then issue one further request. |
|
2589 //! |
|
2590 //! 2) Issue the maximum number (requested in the call to the Initialise API) |
|
2591 //! of requests for notification changes to the state of a resource, where |
|
2592 //! every odd request is for an unqualified change and every even request is |
|
2593 //! for a qualified change. Then issue one further request. |
|
2594 //! |
|
2595 //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last |
|
2596 //! request exhibits status code KErrUnderflow - exit otherwise. Test |
|
2597 //! that the TRequestStatus objects associated with the preceding requests |
|
2598 //! exhibit status code KErrNone - exit otherwise. |
|
2599 //! |
|
2600 //! 1) Test that the TRequestStatus object associated with the last request |
|
2601 //! exhibits status code KErrUnderflow - exit otherwise. Test that the |
|
2602 //! TRequestStatus objects associated with the preceding requests exhibit |
|
2603 //! status code KErrNone - exit otherwise. |
|
2604 //! |
|
2605 //! 2) Test that the TRequestStatus object associated with the last request |
|
2606 //! exhibits status code KErrUnderflow - exit otherwise. Test that the |
|
2607 //! TRequestStatus objects associated with the preceding requests exhibit |
|
2608 //! status code KErrNone - exit otherwise. |
|
2609 //! |
|
2610 //! @SYMTestPriority High |
|
2611 //! @SYMTestStatus Implemented |
|
2612 //---------------------------------------------------------------------------------------------- |
|
2613 LOCAL_C TInt TestNotificationQuota() |
|
2614 // |
|
2615 // Test notification request quota management |
|
2616 // |
|
2617 { |
|
2618 __KHEAP_MARK; |
|
2619 |
|
2620 TInt r = KErrNone; |
|
2621 TRequestStatus status[MAX_NUM_REQUESTS]; |
|
2622 TInt loopVar=0; |
|
2623 TBool cached = gUseCached; |
|
2624 TRequestStatus triggerStatus; |
|
2625 TUint resourceId = gLongLatencyResource; |
|
2626 |
|
2627 // Test quota for basic operation |
|
2628 // |
|
2629 // Loop to perform maximum number of requests, check TRequestStatus objects are pending |
|
2630 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2631 { |
|
2632 gChannel.RequestNotification(status[loopVar], resourceId); |
|
2633 if(status[loopVar].Int() != KRequestPending) |
|
2634 { |
|
2635 gTest.Printf(_L("TestNotificationQuota: status not KRequestPending, =%d\n"), |
|
2636 status[loopVar].Int()); |
|
2637 return KErrGeneral; |
|
2638 } |
|
2639 } |
|
2640 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow |
|
2641 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId); |
|
2642 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow) |
|
2643 { |
|
2644 gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"), |
|
2645 KNoOfNotifyRequests,status[loopVar].Int()); |
|
2646 return KErrGeneral; |
|
2647 } |
|
2648 // Loop to trigger previously-issued notifications, check TRequestStatus objects |
|
2649 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2650 { |
|
2651 // Pass gAsyncResStateDelta as this represents the delta value |
|
2652 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2653 return r; |
|
2654 User::WaitForRequest(status[loopVar]); |
|
2655 if(status[loopVar].Int()!=KErrNone) |
|
2656 { |
|
2657 gTest.Printf(_L("TestNotificationQuota: trigger basic request status[%d] = %d\n"), |
|
2658 loopVar,status[loopVar].Int()); |
|
2659 return r; |
|
2660 } |
|
2661 } |
|
2662 |
|
2663 |
|
2664 // Test quota for qualified operation |
|
2665 // |
|
2666 TInt dumThreshold = -25; // Arbitrary |
|
2667 TBool dumDirection = ETrue; // Arbitrary |
|
2668 // |
|
2669 // Loop to perform maximum number of requests, check TRequestStatus objects are pending |
|
2670 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2671 { |
|
2672 if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2673 return r; |
|
2674 gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection); |
|
2675 if(status[loopVar].Int() != KRequestPending) |
|
2676 { |
|
2677 gTest.Printf(_L("TestNotificationQuota: status[%d] not KRequestPending, =%d\n"), |
|
2678 loopVar,status[loopVar].Int()); |
|
2679 return KErrGeneral; |
|
2680 } |
|
2681 } |
|
2682 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow |
|
2683 if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2684 return r; |
|
2685 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection); |
|
2686 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow) |
|
2687 { |
|
2688 gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"), |
|
2689 KNoOfNotifyRequests,status[loopVar].Int()); |
|
2690 return KErrGeneral; |
|
2691 } |
|
2692 // Loop to trigger previously-issued notifications, check TRequestStatus objects |
|
2693 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2694 { |
|
2695 // Pass gAsyncResStateDelta as this represents the delta value |
|
2696 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2697 return r; |
|
2698 User::WaitForRequest(status[loopVar]); |
|
2699 if(status[loopVar].Int()!=KErrNone) |
|
2700 { |
|
2701 gTest.Printf(_L("TestNotificationQuota: trigger qualified request status[%d] = %d\n"), |
|
2702 loopVar,status[loopVar].Int()); |
|
2703 return r; |
|
2704 } |
|
2705 } |
|
2706 |
|
2707 // Text quota with mixture of basic and qualified requests |
|
2708 // |
|
2709 TBool qualified = ETrue; |
|
2710 // Issue requests and check TRequestStatus objects are pending |
|
2711 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2712 { |
|
2713 if(qualified) |
|
2714 { |
|
2715 if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2716 return r; |
|
2717 gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection); |
|
2718 } |
|
2719 else |
|
2720 { |
|
2721 gChannel.RequestNotification(status[loopVar], resourceId); |
|
2722 } |
|
2723 qualified=!qualified; |
|
2724 if(status[loopVar].Int() != KRequestPending) |
|
2725 { |
|
2726 gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KRequestPending, =%d\n"), |
|
2727 loopVar,status[loopVar].Int()); |
|
2728 return KErrGeneral; |
|
2729 } |
|
2730 } |
|
2731 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow |
|
2732 if(qualified) |
|
2733 { |
|
2734 if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone) |
|
2735 return r; |
|
2736 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection); |
|
2737 } |
|
2738 else |
|
2739 { |
|
2740 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId); |
|
2741 } |
|
2742 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow) |
|
2743 { |
|
2744 gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KErrUnderflow, =%d\n"), |
|
2745 KNoOfNotifyRequests,status[loopVar].Int()); |
|
2746 return KErrGeneral; |
|
2747 } |
|
2748 // Loop to trigger previously-issued notifications, check TRequestStatus objects |
|
2749 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++) |
|
2750 { |
|
2751 // Pass gAsyncResStateDelta as this represents the delta value |
|
2752 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) |
|
2753 return r; |
|
2754 User::WaitForRequest(status[loopVar]); |
|
2755 if(status[loopVar].Int()!=KErrNone) |
|
2756 { |
|
2757 gTest.Printf(_L("TestNotificationQuota: trigger mixed request status[%d] = %d\n"), |
|
2758 loopVar,status[loopVar].Int()); |
|
2759 return r; |
|
2760 } |
|
2761 } |
|
2762 |
|
2763 __KHEAP_MARKEND; |
|
2764 |
|
2765 return r; |
|
2766 } |
|
2767 |
|
2768 #ifdef PIRATE_THREAD_TESTS |
|
2769 |
|
2770 RThread PirateThread; |
|
2771 TRequestStatus PirateStatus; |
|
2772 const TInt KHeapSize=0x4000; |
|
2773 const TInt KStackSize=0x4000; |
|
2774 |
|
2775 _LIT(KPirateThreadName,"Pirate"); |
|
2776 |
|
2777 TInt PirateThreadFn(TAny* /*aSrcThread*/) |
|
2778 { |
|
2779 #if 0 |
|
2780 TInt r=KErrNone; |
|
2781 RBusDevResManUs pirateChannel = gChannel; |
|
2782 RThread& thread = *((RThread*)aSrcThread); |
|
2783 |
|
2784 /* 1 - pirate with current thread - Panics kernel with KErrBadHandle */ |
|
2785 if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied) |
|
2786 { |
|
2787 gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(RThread(),EOwnerProcess) returned %d\n"),r); |
|
2788 return KErrGeneral; |
|
2789 } |
|
2790 |
|
2791 /* 2 - pirate with parent thread - Panics kernel with KErrBadHandle */ |
|
2792 pirateChannel = gChannel; |
|
2793 if((r=pirateChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied) |
|
2794 { |
|
2795 gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(thread,EOwnerThread) returned %d\n"),r); |
|
2796 return KErrGeneral; |
|
2797 } |
|
2798 |
|
2799 /* 3 - gChannel with current thread - Panics kernel with KErrBadHandle */ |
|
2800 if((r=gChannel.Duplicate(RThread(),EOwnerThread))!=KErrAccessDenied) |
|
2801 { |
|
2802 gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(RThread(),EOwnerThread) returned %d\n"),r); |
|
2803 return KErrGeneral; |
|
2804 } |
|
2805 |
|
2806 /* 4 - gChannel with parent thread - Panics kernel with KErrBadHandle */ |
|
2807 if((r=gChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied) |
|
2808 { |
|
2809 gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(thread,EOwnerThread)returned %d\n"),r); |
|
2810 return KErrGeneral; |
|
2811 } |
|
2812 #endif |
|
2813 |
|
2814 // pirateChannel.Close(); |
|
2815 return KErrNone; |
|
2816 } |
|
2817 |
|
2818 TInt StartPirate(RThread& aSrcThread) |
|
2819 { |
|
2820 TAny* srcThread =(TAny*)(&aSrcThread); |
|
2821 TInt r=PirateThread.Create(KPirateThreadName,PirateThreadFn,KStackSize,KHeapSize,KHeapSize,srcThread,EOwnerThread); |
|
2822 if (r!=KErrNone) |
|
2823 return r; |
|
2824 PirateThread.Logon(PirateStatus); |
|
2825 PirateThread.Resume(); |
|
2826 return KErrNone; |
|
2827 } |
|
2828 |
|
2829 TInt WaitForPirateThread() |
|
2830 { |
|
2831 User::WaitForRequest(PirateStatus); |
|
2832 TInt exitType=PirateThread.ExitType(); |
|
2833 TInt exitReason=PirateThread.ExitReason(); |
|
2834 TBuf<16> exitCat=PirateThread.ExitCategory(); |
|
2835 if((exitType!= EExitKill)||(exitReason!=KErrNone)) |
|
2836 { |
|
2837 gTest.Printf(_L("Pirate thread error: %d\n"),PirateStatus.Int()); |
|
2838 gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat); |
|
2839 gTest(0); |
|
2840 } |
|
2841 PirateThread.Close(); |
|
2842 return KErrNone; |
|
2843 } |
|
2844 |
|
2845 #endif |
|
2846 |
|
2847 //---------------------------------------------------------------------------------------------- |
|
2848 //! @SYMTestCaseID KBASE-T_RESMANUS-0608 |
|
2849 //! @SYMTestType UT |
|
2850 //! @SYMPREQ PREQ1398 |
|
2851 //! @SYMTestCaseDesc This test case tests that channels can not be shared between threads. |
|
2852 //! @SYMTestActions 0) Attempt to Duplicate the channel handle with EOwnerProcess as the owner type. |
|
2853 //! |
|
2854 //! 1) Attempt to Duplicate the channel handle with EOwnerThread |
|
2855 //! |
|
2856 //! @SYMTestExpectedResults 0) API should return with KErrAccessDenied, exits otherwise. |
|
2857 //! 1) API should return with KErrNone, exits otherwise. |
|
2858 //! |
|
2859 //! @SYMTestPriority High |
|
2860 //! @SYMTestStatus Implemented |
|
2861 //---------------------------------------------------------------------------------------------- |
|
2862 LOCAL_C TInt TestThreadExclusiveAccess() |
|
2863 // |
|
2864 // Test mechanism to prevent other threads accessing a channel |
|
2865 // |
|
2866 { |
|
2867 __KHEAP_MARK; |
|
2868 |
|
2869 TInt r; |
|
2870 RBusDevResManUs pirateChannel = gChannel; |
|
2871 if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied) |
|
2872 { |
|
2873 gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r); |
|
2874 if(r==KErrNone) |
|
2875 r=KErrGeneral; |
|
2876 return r; |
|
2877 } |
|
2878 pirateChannel = gChannel; |
|
2879 if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone) |
|
2880 { |
|
2881 gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r); |
|
2882 return r; |
|
2883 } |
|
2884 #ifdef PIRATE_THREAD_TESTS |
|
2885 RThread& threadRef = RThread(); |
|
2886 if((r=StartPirate(threadRef))!=KErrNone) |
|
2887 { |
|
2888 gTest.Printf(_L("TestThreadExclusiveAccess: StartPirate returned %d\n"),r); |
|
2889 return KErrGeneral; |
|
2890 } |
|
2891 if((r=WaitForPirateThread())!=KErrNone) |
|
2892 { |
|
2893 gTest.Printf(_L("TestThreadExclusiveAccess: WaitForPirateThread returned %d\n"),r); |
|
2894 return KErrGeneral; |
|
2895 } |
|
2896 #endif |
|
2897 pirateChannel.Close(); |
|
2898 |
|
2899 __KHEAP_MARKEND; |
|
2900 |
|
2901 return KErrNone; |
|
2902 } |
|
2903 |
|
2904 RThread Thrd2; |
|
2905 TRequestStatus Thrd2Status; |
|
2906 const TInt KHeapSize=0x4000; |
|
2907 const TInt KStackSize=0x4000; |
|
2908 |
|
2909 _LIT(KThrd2Name,"Thread2"); |
|
2910 |
|
2911 |
|
2912 TInt Thread2Fn(TAny* /* */) |
|
2913 // |
|
2914 // Test that more than one thread can be supported |
|
2915 // |
|
2916 { |
|
2917 TInt r; |
|
2918 |
|
2919 // Open a channel |
|
2920 // |
|
2921 _LIT(secThrdStr,"Thrd2Channel"); |
|
2922 TBufC<16> secThrdName(secThrdStr); |
|
2923 // API accepts 8-bit descriptors, only - so convert name accordingly |
|
2924 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName; |
|
2925 EightBitName.Copy(secThrdName); |
|
2926 RBusDevResManUs secThrdChannel; |
|
2927 if((r=secThrdChannel.Open(EightBitName))!=KErrNone) |
|
2928 return r; |
|
2929 |
|
2930 // Read the resource information |
|
2931 // |
|
2932 TUint numResources=0; |
|
2933 if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone) |
|
2934 return r; |
|
2935 |
|
2936 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
2937 // and reference via an RSimplePointerArray |
|
2938 TUint bufSize = numResources; |
|
2939 RSimplePointerArray<TResourceInfoBuf> resPtrs(bufSize); |
|
2940 for(TUint i=0;i<bufSize;i++) |
|
2941 { |
|
2942 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
2943 if((r=resPtrs.Insert(info, i))!=KErrNone) |
|
2944 return r; |
|
2945 } |
|
2946 |
|
2947 TUint updateNumResources=numResources; |
|
2948 if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,updateNumResources))!=KErrNone) |
|
2949 return r; |
|
2950 resPtrs.Close(); |
|
2951 |
|
2952 |
|
2953 // Read current client information |
|
2954 // |
|
2955 TUint numClients=0; |
|
2956 TUint numAllClients=0; |
|
2957 // |
|
2958 // GetNoOfClients - with default aIncludeKern=EFalse |
|
2959 // |
|
2960 if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone) |
|
2961 return r; |
|
2962 // |
|
2963 // GetNoOfClients - with aIncludeKern=ETrue |
|
2964 // |
|
2965 r=secThrdChannel.GetNoOfClients(numAllClients, ETrue); |
|
2966 #ifdef RESMANUS_KERN |
|
2967 if(r!=KErrNone) |
|
2968 #else |
|
2969 if(r!=KErrPermissionDenied) |
|
2970 #endif |
|
2971 return KErrGeneral; |
|
2972 // |
|
2973 // Need a buffer big enough to contain numClients instances of TClientName |
|
2974 // To support the GetNamesAllClients testing, instantiate TClientName objects |
|
2975 // and reference via an RSimplePointerArray |
|
2976 TUint resBufSize = (numAllClients>numClients)?numAllClients:numClients; |
|
2977 RSimplePointerArray<TClientName> infoPtrs(resBufSize); |
|
2978 for(TUint j=0;j<resBufSize;j++) |
|
2979 { |
|
2980 TClientName *info = new TClientName(); |
|
2981 if((r=infoPtrs.Insert(info, j))!=KErrNone) |
|
2982 return r; |
|
2983 } |
|
2984 // |
|
2985 // GetNamesAllClients - with aIncludeKern=EFalse |
|
2986 // |
|
2987 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone) |
|
2988 return r; |
|
2989 // |
|
2990 // GetNamesAllClients - with aIncludeKern=ETrue |
|
2991 // |
|
2992 #ifdef RESMANUS_KERN |
|
2993 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone) |
|
2994 return r; |
|
2995 #else |
|
2996 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied) |
|
2997 { |
|
2998 if(r==KErrNone) |
|
2999 r=KErrGeneral; |
|
3000 return r; |
|
3001 } |
|
3002 else |
|
3003 r=KErrNone; // Ensure misleading result is not propagated |
|
3004 #endif |
|
3005 infoPtrs.Close(); |
|
3006 |
|
3007 // If we don't have a shared resource identified, skip the remaining tests |
|
3008 if(gHaveSharedRes) |
|
3009 { |
|
3010 // Register with the Resource Controller |
|
3011 // |
|
3012 if ((r=secThrdChannel.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state |
|
3013 return r; |
|
3014 // Set a level on the shared resource |
|
3015 // |
|
3016 // Get initial state |
|
3017 TRequestStatus status; |
|
3018 TBool cached = gUseCached; |
|
3019 TInt readValue; |
|
3020 TInt levelOwnerId; |
|
3021 secThrdChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); |
|
3022 User::WaitForRequest(status); |
|
3023 r=status.Int(); |
|
3024 if(r != KErrNone) |
|
3025 return r; |
|
3026 // Write updated state |
|
3027 TUint newLevel = (TUint)(readValue + gSharedResStateDelta); |
|
3028 secThrdChannel.ChangeResourceState(status,gSharedResource,newLevel); |
|
3029 User::WaitForRequest(status); |
|
3030 r=status.Int(); |
|
3031 if(r != KErrNone) |
|
3032 return r; |
|
3033 |
|
3034 // Read current client information |
|
3035 // |
|
3036 numClients=0; |
|
3037 numAllClients=0; |
|
3038 // |
|
3039 // GetNoOfClients - with default aIncludeKern=EFalse |
|
3040 // |
|
3041 if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone) |
|
3042 return r; |
|
3043 // |
|
3044 // GetNoOfClients - with aIncludeKern=ETrue |
|
3045 // |
|
3046 #ifdef RESMANUS_KERN |
|
3047 if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrNone) |
|
3048 #else |
|
3049 if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrPermissionDenied) |
|
3050 #endif |
|
3051 return KErrGeneral; |
|
3052 // |
|
3053 // Need a buffer big enough to contain numClients instances of TClientName |
|
3054 // To support the GetNamesAllClients testing, instantiate TClientName objects |
|
3055 // and reference via an RSimplePointerArray |
|
3056 TUint bufSize = (numAllClients>numClients)?numAllClients:numClients; |
|
3057 RSimplePointerArray<TClientName> infoPtrs(bufSize); |
|
3058 for(TUint i=0;i<bufSize;i++) |
|
3059 { |
|
3060 TClientName *info = new TClientName(); |
|
3061 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3062 return r; |
|
3063 } |
|
3064 // |
|
3065 // GetNamesAllClients - with aIncludeKern=EFalse |
|
3066 // |
|
3067 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone) |
|
3068 return r; |
|
3069 // |
|
3070 // GetNamesAllClients - with aIncludeKern=ETrue |
|
3071 // |
|
3072 #ifdef RESMANUS_KERN |
|
3073 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone) |
|
3074 return r; |
|
3075 #else |
|
3076 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied) |
|
3077 { |
|
3078 if(r==KErrNone) |
|
3079 r=KErrGeneral; |
|
3080 return r; |
|
3081 } |
|
3082 else |
|
3083 r=KErrNone; // Ensure misleading result is not propagated |
|
3084 #endif |
|
3085 infoPtrs.Close(); |
|
3086 |
|
3087 // Read the resource information |
|
3088 // |
|
3089 numResources=0; |
|
3090 if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone) |
|
3091 return r; |
|
3092 |
|
3093 // |
|
3094 // Need a buffer big enough to contain numResources instances of TResourceInfoBuf |
|
3095 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
3096 // and reference via an RSimplePointerArray |
|
3097 RSimplePointerArray<TResourceInfoBuf> resPtrs(numResources); |
|
3098 for(TUint j=0;j<numResources;j++) |
|
3099 { |
|
3100 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3101 if((r=resPtrs.Insert(info, j))!=KErrNone) |
|
3102 return r; |
|
3103 } |
|
3104 |
|
3105 if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,numResources))!=KErrNone) |
|
3106 return r; |
|
3107 resPtrs.Close(); |
|
3108 } |
|
3109 |
|
3110 // Close the channel |
|
3111 secThrdChannel.Close(); |
|
3112 return r; |
|
3113 } |
|
3114 |
|
3115 TInt StartThread2() |
|
3116 { |
|
3117 TInt r=Thrd2.Create(KThrd2Name,Thread2Fn,KStackSize,KHeapSize,KHeapSize,NULL,EOwnerThread); |
|
3118 if (r!=KErrNone) |
|
3119 return r; |
|
3120 Thrd2.Logon(Thrd2Status); |
|
3121 Thrd2.Resume(); |
|
3122 return KErrNone; |
|
3123 } |
|
3124 |
|
3125 TInt WaitForThread2() |
|
3126 { |
|
3127 User::WaitForRequest(Thrd2Status); |
|
3128 TInt exitType=Thrd2.ExitType(); |
|
3129 TInt exitReason=Thrd2.ExitReason(); |
|
3130 TBuf<16> exitCat=Thrd2.ExitCategory(); |
|
3131 if((exitType!= EExitKill)||(exitReason!=KErrNone)) |
|
3132 { |
|
3133 gTest.Printf(_L("Thread2 error: %d\n"),Thrd2Status.Int()); |
|
3134 gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat); |
|
3135 gTest(0); |
|
3136 } |
|
3137 Thrd2.Close(); |
|
3138 return KErrNone; |
|
3139 } |
|
3140 |
|
3141 |
|
3142 //---------------------------------------------------------------------------------------------- |
|
3143 //! @SYMTestCaseID KBASE-T_RESMANUS-0614 |
|
3144 //! @SYMTestType UT |
|
3145 //! @SYMPREQ PREQ1398 |
|
3146 //! @SYMTestCaseDesc This test case tests that an additional thread can open a channel and |
|
3147 //! exercise selected APIs. |
|
3148 //! |
|
3149 //! @SYMTestActions 0) Call API to open a channel. |
|
3150 //! |
|
3151 //! 1) Call GetNoOfResources API. |
|
3152 //! |
|
3153 //! 2) Call GetAllResourcesInfo API. |
|
3154 //! |
|
3155 //! 3) Call GetNoOfClients API with default aIncludeKern=EFalse. |
|
3156 //! |
|
3157 //! 4) Call GetNoOfClients API with aIncludeKern=ETrue |
|
3158 //! |
|
3159 //! 5) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse. |
|
3160 //! |
|
3161 //! 6) Call GetNamesAllClientsAPI with aIncludeKern=ETrue |
|
3162 //! |
|
3163 //! 7) Call Initialise API. |
|
3164 //! |
|
3165 //! 8) Call GetResourceState API for selected resource. |
|
3166 //! |
|
3167 //! 9) Call GetResourceState API for selected resource. |
|
3168 //! |
|
3169 //! 10) Call GetNoOfClients API with default aIncludeKern=EFalse. |
|
3170 //! |
|
3171 //! 11) Call GetNoOfClients API with aIncludeKern=ETrue |
|
3172 //! |
|
3173 //! 12) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse. |
|
3174 //! |
|
3175 //! 13) Call GetNamesAllClientsAPI with aIncludeKern=ETrue |
|
3176 //! |
|
3177 //! 14) Call GetNoOfResources API. |
|
3178 //! |
|
3179 //! 15) Call GetAllResourcesInfo API. |
|
3180 //! |
|
3181 //! @SYMTestExpectedResults 0) Test that the channel was opened - exit otherwise. |
|
3182 //! |
|
3183 //! 1) Test that the API call returned KErrNone - exit otherwise. |
|
3184 //! |
|
3185 //! 2) Test that the API call returned KErrNone - exit otherwise. |
|
3186 //! |
|
3187 //! 3) Test that the API call returned KErrNone - exit otherwise. |
|
3188 //! |
|
3189 //! 4) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise |
|
3190 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise |
|
3191 //! |
|
3192 //! 5) Test that the API call returned KErrNone - exit otherwise. |
|
3193 //! |
|
3194 //! 6) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise |
|
3195 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise |
|
3196 //! |
|
3197 //! 7) Test that the API call returned KErrNone - exit otherwise |
|
3198 //! |
|
3199 //! 8) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise |
|
3200 //! |
|
3201 //! 9) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise |
|
3202 //! |
|
3203 //! 10) Test that the API call returned KErrNone - exit otherwise. |
|
3204 //! |
|
3205 //! 11) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise |
|
3206 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise |
|
3207 //! |
|
3208 //! 12) Test that the API call returned KErrNone - exit otherwise. |
|
3209 //! |
|
3210 //! 13) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise |
|
3211 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise |
|
3212 //! |
|
3213 //! 14) Test that the API call returned KErrNone - exit otherwise. |
|
3214 //! |
|
3215 //! 15) Test that the API call returned KErrNone - exit otherwise. |
|
3216 //! |
|
3217 //! @SYMTestPriority High |
|
3218 //! @SYMTestStatus Implemented |
|
3219 //---------------------------------------------------------------------------------------------- |
|
3220 LOCAL_C TInt TestAdditionalThread() |
|
3221 // |
|
3222 // Test that more than one thread can be supported |
|
3223 // |
|
3224 { |
|
3225 TInt r; |
|
3226 if((r=StartThread2())!=KErrNone) |
|
3227 { |
|
3228 gTest.Printf(_L("TestAdditionalThread: StartThread2 returned %d\n"),r); |
|
3229 return KErrGeneral; |
|
3230 } |
|
3231 if((r=WaitForThread2())!=KErrNone) |
|
3232 { |
|
3233 gTest.Printf(_L("TestAdditionalThread: WaitForThread2 returned %d\n"),r); |
|
3234 return KErrGeneral; |
|
3235 } |
|
3236 |
|
3237 return r; |
|
3238 } |
|
3239 |
|
3240 |
|
3241 LOCAL_C TInt LocateResourceWithDependencies(TUint &aNumResources, TUint &aResId, TUint &aNumDependents) |
|
3242 // |
|
3243 // Support function for tests of dependencies |
|
3244 // |
|
3245 { |
|
3246 __KHEAP_MARK; |
|
3247 |
|
3248 TInt r = KErrNone; |
|
3249 if((r=gChannel.GetNoOfResources(aNumResources))!=KErrNone) |
|
3250 { |
|
3251 gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r); |
|
3252 return r; |
|
3253 } |
|
3254 TUint bufSize = aNumResources; |
|
3255 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize); |
|
3256 for(TUint i=0;i<bufSize;i++) |
|
3257 { |
|
3258 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3259 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3260 { |
|
3261 gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r); |
|
3262 } |
|
3263 } |
|
3264 TUint updateNumResources=aNumResources; |
|
3265 if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone) |
|
3266 { |
|
3267 gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r); |
|
3268 return r; |
|
3269 } |
|
3270 for(TUint resNo=0;resNo<aNumResources;resNo++) |
|
3271 { |
|
3272 TResourceInfoBuf *info = infoPtrs[resNo]; |
|
3273 TUint resId = ((*info)()).iId; |
|
3274 TUint numDependents = 0; |
|
3275 r=gChannel.GetNumDependentsForResource(resId,&numDependents, EFalse); // EFalse - don't load the dependency info |
|
3276 if((r!=KErrNone)&&(r!=KErrNotFound)&&(r!=KErrNotSupported)) |
|
3277 { |
|
3278 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); |
|
3279 return r; |
|
3280 } |
|
3281 if(numDependents>0) |
|
3282 { |
|
3283 aResId = resId; |
|
3284 aNumDependents = numDependents; |
|
3285 break; |
|
3286 } |
|
3287 } |
|
3288 |
|
3289 infoPtrs.Close(); |
|
3290 |
|
3291 __KHEAP_MARKEND; |
|
3292 |
|
3293 return r; |
|
3294 } |
|
3295 |
|
3296 |
|
3297 |
|
3298 //---------------------------------------------------------------------------------------------- |
|
3299 //! @SYMTestCaseID KBASE-T_RESMANUS-0615 |
|
3300 //! @SYMTestType UT |
|
3301 //! @SYMPREQ PREQ1398 |
|
3302 //! @SYMTestCaseDesc This test case tests the different options available for handling transient data. |
|
3303 //! @SYMTestActions 0) Locate a resource that has at least one dependency. |
|
3304 //! |
|
3305 //! 1) Read the number of dependencies without reading the dependency information. |
|
3306 //! Call to read the dependency information (without re-loading). |
|
3307 //! |
|
3308 //! 2) Read the number of dependencies (with default option of reading the dependency information). |
|
3309 //! Then read the dependency information (without re-loading). |
|
3310 //! |
|
3311 //! 3) Repeat the read the number of dependencies without reading the dependency information |
|
3312 //! Then read the dependency information (without re-loading). |
|
3313 //! Then read the dependency information (with re-loading). |
|
3314 //! |
|
3315 //! 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size |
|
3316 //! |
|
3317 //! 5) Read the number of (all) resources without reading the resource information. |
|
3318 //! Call to read (all) the resource information (without re-loading). |
|
3319 //! |
|
3320 //! 6) Read the number of (all) resources (with default option of reading the resource information). |
|
3321 //! Then read (all) the resource information (without re-loading). |
|
3322 //! |
|
3323 //! 7) Repeat the read the number of (all) resources without reading the resources information |
|
3324 //! Then read (all) the resources information (without re-loading). |
|
3325 //! Then read (all) the resources information (with re-loading). |
|
3326 //! |
|
3327 //! 8) Attempt to read (all) the resource information (without re-loading) with a buffer of insufficient size |
|
3328 //! |
|
3329 //! 9) Read the number of user-side clients using a resource without reading the resource information. |
|
3330 //! Call to read the information for user-side clients using a resource (without re-loading). |
|
3331 //! |
|
3332 //! 10) Read the number of user-side clients (with loading of the client information) |
|
3333 //! Call to read the client information (without re-loading) should return be successful |
|
3334 //! Call to read the information for a resourceID with zero clients (without re-loading) |
|
3335 //! Call to read the information for the first resourceID |
|
3336 //! |
|
3337 //! 11) Repeat the read of the number of user-side clients (without re-loading) |
|
3338 //! Call to read the client information (without re-loading) |
|
3339 //! Call to read the client information (with re-loading) |
|
3340 //! |
|
3341 //! 12) Open a second channel on the User-Side API, and call initialise support for resource state access |
|
3342 //! Get the current state of a specific resource, then change the state |
|
3343 //! Call to read the number of user-side clients for the resource (with loading of the client information) |
|
3344 //! but with a buffer of insufficient size. |
|
3345 //! |
|
3346 //! 13) Read the number of resources in use by a specified client (without loading) |
|
3347 //! Call to read the information on the resources in use by the client (without loading) |
|
3348 //! |
|
3349 //! 14) Open a third channel on the User-Side API, do not call initialise. |
|
3350 //! Read the number of resources in use by a specified client (with loading) |
|
3351 //! Call to read the information for resources in use by the third channel (without re-loading) |
|
3352 //! Call to read the information for resources in use by the second channel (without re-loading) |
|
3353 //! |
|
3354 //! 15) Read the number of resources in use by a specified client (without loading) |
|
3355 //! Call to read the information on the resources in use by the client (without loading) |
|
3356 //! Call to read the information on the resources in use by the client (with loading) |
|
3357 //! |
|
3358 //! 16) Read the number of resources in use by a specified client (with loading) |
|
3359 //! Call to read the information on the resources in use by the client (without loading) |
|
3360 //! with a buffer of insufficient size. |
|
3361 //! |
|
3362 //! @SYMTestExpectedResults 0) If a suitable resource is found, the number of dependencies is reported - exit otherwise. |
|
3363 //! |
|
3364 //! 1) Test that the read of the number of dependencies returns KErrNone - exit otherwise. |
|
3365 //! Test that the read of the dependency information returned KErrNotReady - exit otherwise. |
|
3366 //! |
|
3367 //! 2) Test that the read of the number of dependencies returns KErrNone - exit otherwise. |
|
3368 //! Test that the read of the dependency information returned KErrNone - exit otherwise. |
|
3369 //! |
|
3370 //! 3) Test that the read of the number of dependencies returns KErrNone - exit otherwise. |
|
3371 //! Test that the read of the dependency information (without re-loading) returned KErrNotReady - exit otherwise. |
|
3372 //! Test that the read of the dependency information (with re-loading) returned KErrNone - exit otherwise. |
|
3373 //! |
|
3374 //! 4) Test that the read of the dependency information returns KErrArgument - exit otherwise |
|
3375 //! |
|
3376 //! 5) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3377 //! Test that the read of the resource information returned KErrNotReady - exit otherwise. |
|
3378 //! |
|
3379 //! 6) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3380 //! Test that the read of the resource information returned KErrNone - exit otherwise. |
|
3381 //! |
|
3382 //! 7) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3383 //! Test that the read of the resource information (without re-loading) returned KErrNotReady - exit otherwise. |
|
3384 //! Test that the read of the resources information (with re-loading) returned KErrNone - exit otherwise. |
|
3385 //! |
|
3386 //! 8) Test that the read of the resource information returns KErrArgument - exit otherwise |
|
3387 //! |
|
3388 //! 9) Test that the read of the number of clients returns KErrNone - exit otherwise. |
|
3389 //! Test that the read of the client information returned KErrNotReady - exit otherwise. |
|
3390 //! |
|
3391 //! 10) Test that the read of the number of clients returns KErrNone - exit otherwise. |
|
3392 //! Test that the read of the client information returned KErrNone - exit otherwise. |
|
3393 //! Test that the read of the client information returned KErrNone and numClients==0 - exit otherwise. |
|
3394 //! Test that the read of the client information returned KErrNotReady - exit otherwise. |
|
3395 //! |
|
3396 //! 11) Test that the read of the number of clients returns KErrNone - exit otherwise. |
|
3397 //! Test that the read of the client information returned KErrNotReady - exit otherwise. |
|
3398 //! Test that the read of the client information returned KErrNone - exit otherwise. |
|
3399 //! |
|
3400 //! 12) Test that the opening and initialisation of the channel was successful - exit otherwise. |
|
3401 //! Test that the get and change of the resource state completed successfully - exit otherwise |
|
3402 //! Test that the read of the client information returned KErrArgument - exit otherwise. |
|
3403 //! |
|
3404 //! 13) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3405 //! Test that the read of the resource information returned KErrNotReady - exit otherwise. |
|
3406 //! |
|
3407 //! 14) Test that the opening of the channel was successful - exit otherwise. |
|
3408 //! Test that the read of the resource information returned KErrNone - exit otherwise. |
|
3409 //! Test that the read of the client information returned KErrNone, and numResources = 0 - exit otherwise. |
|
3410 //! Test that the read of the client information returned KErrNotReady - exit otherwise. |
|
3411 //! |
|
3412 //! 15) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3413 //! Test that the read of the resource information returned KErrNotReady - exit otherwise. |
|
3414 //! Test that the read of the resource information returned KErrNone - exit otherwise. |
|
3415 //! |
|
3416 //! 16) Test that the read of the number of resources returns KErrNone - exit otherwise. |
|
3417 //! Test that the read of the resource information returned KErrArgument - exit otherwise.. |
|
3418 //! |
|
3419 //! @SYMTestPriority High |
|
3420 //! @SYMTestStatus Implemented |
|
3421 //---------------------------------------------------------------------------------------------- |
|
3422 LOCAL_C TInt TestTransientHandling() |
|
3423 // |
|
3424 // Test APIs with options for handling transient data (dependencies, resources and clients) |
|
3425 // |
|
3426 { |
|
3427 TInt r = KErrNone; |
|
3428 TUint testNo = 1; |
|
3429 |
|
3430 TUint numDependents = 0; |
|
3431 TUint resNo = 0; |
|
3432 |
|
3433 // |
|
3434 // Dependency data tests |
|
3435 // |
|
3436 |
|
3437 gTest.Printf(_L("TestTransientHandling: dependency data tests ...\n")); |
|
3438 |
|
3439 // 0) Find a resource that has dependents - if none is located skip the remaining dependancy tests |
|
3440 // (this reads the number of dependencies, without loading the dependency data) |
|
3441 // |
|
3442 TUint numResources=0; |
|
3443 if((r=LocateResourceWithDependencies(numResources, resNo, numDependents))!=KErrNone) |
|
3444 { |
|
3445 gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n")); |
|
3446 return KErrNone; |
|
3447 } |
|
3448 if(numDependents==0) |
|
3449 { |
|
3450 gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n")); |
|
3451 } |
|
3452 else |
|
3453 { |
|
3454 // 1) Read the number of dependencies without reading the dependency information |
|
3455 // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady |
|
3456 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3457 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone) |
|
3458 { |
|
3459 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); |
|
3460 return r; |
|
3461 } |
|
3462 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); |
|
3463 if(numDependents > 0) |
|
3464 { |
|
3465 RBuf8 buffer; |
|
3466 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) |
|
3467 return KErrGeneral; |
|
3468 buffer.SetLength(0); |
|
3469 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady) |
|
3470 { |
|
3471 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); |
|
3472 return KErrGeneral; |
|
3473 } |
|
3474 buffer.Close(); |
|
3475 } |
|
3476 |
|
3477 // 2) Read the number of dependencies (and, by default, read the dependency information) |
|
3478 // Subsequent call to read the dependency information (without re-loading) should return be successful |
|
3479 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3480 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents))!=KErrNone) |
|
3481 { |
|
3482 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); |
|
3483 return r; |
|
3484 } |
|
3485 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); |
|
3486 if(numDependents > 0) |
|
3487 { |
|
3488 RBuf8 buffer; |
|
3489 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) |
|
3490 return KErrGeneral; |
|
3491 buffer.SetLength(0); |
|
3492 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNone) |
|
3493 { |
|
3494 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); |
|
3495 return r; |
|
3496 } |
|
3497 SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr()); |
|
3498 gTest.Printf(_L("TestTransientHandling: numDependents = %d\n"),numDependents); |
|
3499 for(TUint i=0; i<numDependents; i++,tempPtr++) |
|
3500 { |
|
3501 gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d\n"),tempPtr->iResourceId); |
|
3502 gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d\n"),tempPtr->iDependencyPriority); |
|
3503 } |
|
3504 buffer.Close(); |
|
3505 } |
|
3506 |
|
3507 // 3) Repeat the read the number of dependencies without reading the dependency information |
|
3508 // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady |
|
3509 // Then call to read the dependency information (with re-loading) should be successful |
|
3510 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3511 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone) |
|
3512 { |
|
3513 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); |
|
3514 return r; |
|
3515 } |
|
3516 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); |
|
3517 if(numDependents > 0) |
|
3518 { |
|
3519 RBuf8 buffer; |
|
3520 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) |
|
3521 return KErrGeneral; |
|
3522 buffer.SetLength(0); |
|
3523 |
|
3524 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady) |
|
3525 { |
|
3526 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); |
|
3527 return KErrGeneral; |
|
3528 } |
|
3529 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents, ETrue))!=KErrNone) |
|
3530 { |
|
3531 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); |
|
3532 return KErrGeneral; |
|
3533 } |
|
3534 SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr()); |
|
3535 for(TUint i=0; i<numDependents; i++,tempPtr++) |
|
3536 { |
|
3537 gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d"),tempPtr->iResourceId); |
|
3538 gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d"),tempPtr->iDependencyPriority); |
|
3539 } |
|
3540 buffer.Close(); |
|
3541 } |
|
3542 |
|
3543 // 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size should |
|
3544 // return error KErrArgument |
|
3545 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3546 if(numDependents > 0) |
|
3547 { |
|
3548 RBuf8 buffer; |
|
3549 if((buffer.Create((numDependents-1)*sizeof(SResourceDependencyInfo)))!=KErrNone) |
|
3550 return KErrGeneral; |
|
3551 buffer.SetLength(0); |
|
3552 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrArgument) |
|
3553 { |
|
3554 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); |
|
3555 return KErrGeneral; |
|
3556 } |
|
3557 // Ensure misleading result is not returned |
|
3558 r=KErrNone; |
|
3559 buffer.Close(); |
|
3560 } |
|
3561 } |
|
3562 |
|
3563 |
|
3564 // |
|
3565 // All resource data tests |
|
3566 // |
|
3567 |
|
3568 gTest.Printf(_L("TestTransientHandling: All resource data tests ...\n")); |
|
3569 testNo=1; |
|
3570 |
|
3571 // 5) Attempt to read the resource information without having previously loaded it. |
|
3572 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3573 { |
|
3574 TUint numResources = 0; |
|
3575 r = gChannel.GetNoOfResources(numResources, EFalse); // EFalse - don't load the resource info |
|
3576 if(r!=KErrNone) |
|
3577 { |
|
3578 gTest.Printf(_L("GetNoOfResources returned %d\n"),r); |
|
3579 return r; |
|
3580 } |
|
3581 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
3582 // and reference via an RSimplePointerArray |
|
3583 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
3584 for(TUint i=0;i<numResources;i++) |
|
3585 { |
|
3586 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3587 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3588 { |
|
3589 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3590 } |
|
3591 } |
|
3592 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady) |
|
3593 { |
|
3594 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); |
|
3595 return KErrGeneral; |
|
3596 } |
|
3597 else |
|
3598 r=KErrNone; // Ensure misleading result is not propagated |
|
3599 infoPtrs.Close(); |
|
3600 } |
|
3601 |
|
3602 // 6) Read the number of resources (and, by default, read the resource information) |
|
3603 // Subsequent call to read the resource information (without re-loading) should return be successful |
|
3604 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3605 { |
|
3606 TUint numResources = 0; |
|
3607 if((r=gChannel.GetNoOfResources(numResources))!=KErrNone) |
|
3608 { |
|
3609 gTest.Printf(_L("GetNoOfResources returned %d\n"),r); |
|
3610 return r; |
|
3611 } |
|
3612 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
3613 // and reference via an RSimplePointerArray |
|
3614 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
3615 for(TUint i=0;i<numResources;i++) |
|
3616 { |
|
3617 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3618 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3619 { |
|
3620 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3621 } |
|
3622 } |
|
3623 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNone) |
|
3624 { |
|
3625 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); |
|
3626 return r; |
|
3627 } |
|
3628 infoPtrs.Close(); |
|
3629 } |
|
3630 |
|
3631 // 7) Repeat the read the number of resources without reading the resource information |
|
3632 // Subsequent call to read the resource information (without re-loading) should return error KErrNotReady |
|
3633 // Then call to read the resource information (with re-loading) should be successful |
|
3634 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3635 { |
|
3636 TUint numResources = 0; |
|
3637 if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info |
|
3638 { |
|
3639 gTest.Printf(_L("GetNoOfResources returned %d\n"),r); |
|
3640 return r; |
|
3641 } |
|
3642 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
3643 // and reference via an RSimplePointerArray |
|
3644 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
3645 for(TUint i=0;i<numResources;i++) |
|
3646 { |
|
3647 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3648 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3649 { |
|
3650 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3651 } |
|
3652 } |
|
3653 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady) |
|
3654 { |
|
3655 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); |
|
3656 return KErrGeneral; |
|
3657 } |
|
3658 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources,ETrue))!=KErrNone) |
|
3659 { |
|
3660 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); |
|
3661 return r; |
|
3662 } |
|
3663 else |
|
3664 infoPtrs.Close(); |
|
3665 } |
|
3666 |
|
3667 |
|
3668 // 8) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should |
|
3669 // return error KErrArgument |
|
3670 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3671 { |
|
3672 TUint numResources = 0; |
|
3673 if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info |
|
3674 { |
|
3675 gTest.Printf(_L("GetNoOfResources returned %d\n"),r); |
|
3676 return r; |
|
3677 } |
|
3678 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects |
|
3679 // and reference via an RSimplePointerArray |
|
3680 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources - 1); |
|
3681 for(TUint i=0;i<(numResources-1);i++) |
|
3682 { |
|
3683 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3684 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3685 { |
|
3686 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3687 } |
|
3688 } |
|
3689 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrArgument) |
|
3690 { |
|
3691 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); |
|
3692 return KErrGeneral; |
|
3693 } |
|
3694 // Ensure misleading result is not returned |
|
3695 r=KErrNone; |
|
3696 infoPtrs.Close(); |
|
3697 } |
|
3698 |
|
3699 // |
|
3700 // Specific resource data tests |
|
3701 // |
|
3702 |
|
3703 gTest.Printf(_L("TestTransientHandling: Resource-specific data tests ...\n")); |
|
3704 testNo=1; |
|
3705 |
|
3706 // 9) Attempt to read the resource information without having previously loaded it. |
|
3707 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3708 { |
|
3709 TUint numClients = 0; |
|
3710 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info |
|
3711 { |
|
3712 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); |
|
3713 return r; |
|
3714 } |
|
3715 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects |
|
3716 // and reference via an RSimplePointerArray |
|
3717 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients); |
|
3718 for(TUint i=0;i<numClients;i++) |
|
3719 { |
|
3720 TClientInfoBuf *info = new TClientInfoBuf(); |
|
3721 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3722 { |
|
3723 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3724 } |
|
3725 } |
|
3726 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady) |
|
3727 { |
|
3728 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r); |
|
3729 return KErrGeneral; |
|
3730 } |
|
3731 else |
|
3732 r=KErrNone; // Ensure misleading result is not propagated |
|
3733 infoPtrs.Close(); |
|
3734 } |
|
3735 |
|
3736 // 10) Read the number of clients (and, by default, read the client information) |
|
3737 // Subsequent call to read the client information (without re-loading) should return be successful |
|
3738 // Call to read the information for a resourceID with zero clients (without re-loading) should return KErrNone, numClients==0 |
|
3739 // Call to read the information for a resourceID with one or more clients (without re-loading) should return KErrNotReady |
|
3740 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3741 { |
|
3742 TUint numClients = 0; |
|
3743 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info |
|
3744 { |
|
3745 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); |
|
3746 return r; |
|
3747 } |
|
3748 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects |
|
3749 // and reference via an RSimplePointerArray |
|
3750 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients); |
|
3751 for(TUint i=0;i<numClients;i++) |
|
3752 { |
|
3753 TClientInfoBuf *info = new TClientInfoBuf(); |
|
3754 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3755 { |
|
3756 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3757 } |
|
3758 } |
|
3759 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNone) |
|
3760 { |
|
3761 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r); |
|
3762 return r; |
|
3763 } |
|
3764 if(((r=gChannel.GetInfoOnClientsUsingResource((gLongLatencyResource+1), numClients, &infoPtrs, EFalse))!=KErrNone) || (numClients!=0)) |
|
3765 { |
|
3766 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1) returned %d\n"),r); |
|
3767 if(numClients!=0) |
|
3768 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1), %d clients\n"),numClients); |
|
3769 return KErrGeneral; |
|
3770 } |
|
3771 if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady) |
|
3772 { |
|
3773 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r); |
|
3774 return r; |
|
3775 } |
|
3776 infoPtrs.Close(); |
|
3777 } |
|
3778 |
|
3779 |
|
3780 // 11) Repeat the read the number of clients without reading the client information |
|
3781 // Subsequent call to read the client information (without re-loading) should return error KErrNotReady |
|
3782 // Then call to read the client information (with re-loading) should be successful |
|
3783 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3784 { |
|
3785 TUint numClients = 0; |
|
3786 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info |
|
3787 { |
|
3788 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); |
|
3789 return r; |
|
3790 } |
|
3791 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects |
|
3792 // and reference via an RSimplePointerArray |
|
3793 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients); |
|
3794 for(TUint i=0;i<numClients;i++) |
|
3795 { |
|
3796 TClientInfoBuf *info = new TClientInfoBuf(); |
|
3797 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3798 { |
|
3799 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3800 } |
|
3801 } |
|
3802 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady) |
|
3803 { |
|
3804 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r); |
|
3805 return KErrGeneral; |
|
3806 } |
|
3807 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse, ETrue))!=KErrNone) |
|
3808 { |
|
3809 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r); |
|
3810 return r; |
|
3811 } |
|
3812 |
|
3813 infoPtrs.Close(); |
|
3814 } |
|
3815 |
|
3816 // 12) To support the following test (and specific resource data tests, below) need a second channel to be using the resource |
|
3817 _LIT(tempStr1,"ExtraChan1"); |
|
3818 TBufC<16> tempName1(tempStr1); |
|
3819 RBusDevResManUs channelTwo; |
|
3820 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) |
|
3821 { |
|
3822 gTest.Printf(_L("Failed to open channelTwo, %d\n"),r); |
|
3823 channelTwo.Close(); |
|
3824 return r; |
|
3825 } |
|
3826 if ((r=channelTwo.Initialise(1,1,1))!=KErrNone) |
|
3827 { |
|
3828 gTest.Printf(_L("Failed to Initialise channelTwo, %d\n"),r); |
|
3829 channelTwo.Close(); |
|
3830 return r; |
|
3831 } |
|
3832 // Attempt to change the resource level |
|
3833 // Get initial state |
|
3834 TRequestStatus status; |
|
3835 TBool cached = gUseCached; |
|
3836 TInt readValue; |
|
3837 TInt levelOwnerId = 0; |
|
3838 channelTwo.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); |
|
3839 User::WaitForRequest(status); |
|
3840 r=status.Int(); |
|
3841 if(r != KErrNone) |
|
3842 { |
|
3843 gTest.Printf(_L("GetResourceState for gSharedResource completed with = 0x%x\n"),r); |
|
3844 return r; |
|
3845 } |
|
3846 // Write updated state |
|
3847 TUint newLevel = (TUint)(readValue + gSharedResStateDelta); |
|
3848 channelTwo.ChangeResourceState(status,gSharedResource,newLevel); |
|
3849 User::WaitForRequest(status); |
|
3850 r=status.Int(); |
|
3851 if(r != KErrNone) |
|
3852 { |
|
3853 gTest.Printf(_L("ChangeResourceState forgSharedResource completed with %d\n"),r); |
|
3854 return r; |
|
3855 } |
|
3856 |
|
3857 // Attempt to read the client information (without re-loading) with a buffer of insufficient size should |
|
3858 // return error KErrArgument |
|
3859 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3860 { |
|
3861 TUint numClients = 0; |
|
3862 if((r=gChannel.GetNumClientsUsingResource(gSharedResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info |
|
3863 { |
|
3864 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); |
|
3865 channelTwo.Close(); |
|
3866 return r; |
|
3867 } |
|
3868 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects |
|
3869 // and reference via an RSimplePointerArray |
|
3870 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients-1); |
|
3871 for(TUint i=0;i<(numClients-1);i++) |
|
3872 { |
|
3873 TClientInfoBuf *info = new TClientInfoBuf(); |
|
3874 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3875 { |
|
3876 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3877 channelTwo.Close(); |
|
3878 } |
|
3879 } |
|
3880 if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrArgument) |
|
3881 { |
|
3882 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r); |
|
3883 channelTwo.Close(); |
|
3884 return KErrGeneral; |
|
3885 } |
|
3886 // Ensure misleading result is not returned |
|
3887 r=KErrNone; |
|
3888 infoPtrs.Close(); |
|
3889 } |
|
3890 |
|
3891 |
|
3892 // |
|
3893 // Specific resource data tests |
|
3894 // |
|
3895 |
|
3896 gTest.Printf(_L("TestTransientHandling: Client-specific data tests ...\n")); |
|
3897 testNo=1; |
|
3898 |
|
3899 // These tests require a client name |
|
3900 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit; |
|
3901 name8Bit.Copy(gTestName); |
|
3902 TClientName* clientName = (TClientName*)&name8Bit; |
|
3903 #if _DEBUG |
|
3904 TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit; |
|
3905 clientName16Bit.Copy(*clientName); |
|
3906 clientName16Bit.SetLength(clientName->Length()); |
|
3907 gTest.Printf(_L("Invoking TestTransientHandling client-specific data tests with %S \n"),&clientName16Bit); |
|
3908 #endif |
|
3909 // 13) Attempt to read the resource information without having previously loaded it. |
|
3910 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3911 { |
|
3912 TUint numResources = 0; |
|
3913 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // EFalse - don't load data |
|
3914 { |
|
3915 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
3916 return r; |
|
3917 } |
|
3918 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects |
|
3919 // and reference via an RSimplePointerArray |
|
3920 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
3921 for(TUint i=0;i<numResources;i++) |
|
3922 { |
|
3923 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3924 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3925 { |
|
3926 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3927 } |
|
3928 } |
|
3929 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady) |
|
3930 { |
|
3931 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r); |
|
3932 return KErrGeneral; |
|
3933 } |
|
3934 else |
|
3935 r=KErrNone; // Ensure misleading result is not propagated |
|
3936 infoPtrs.Close(); |
|
3937 } |
|
3938 |
|
3939 // 14) To support the following test need a third channel |
|
3940 _LIT(tempStr2,"ExtraChan2"); |
|
3941 TBufC<16> tempName2(tempStr2); |
|
3942 RBusDevResManUs channelThree; |
|
3943 if((r=OpenChannel(tempName2, channelThree))!=KErrNone) |
|
3944 { |
|
3945 gTest.Printf(_L("Failed to open channelThree, %d\n"),r); |
|
3946 channelTwo.Close(); |
|
3947 return r; |
|
3948 } |
|
3949 // Read the number of resources (and, by default, read the resource information) |
|
3950 // Subsequent call to read the resource information (without re-loading) should return be successful |
|
3951 // Call to read the information for a client name with zero resource requirements (without re-loading) should return KErrNone, numResources==0 |
|
3952 // Call to read the information for a client name with one or more resource requirements (without re-loading) should return KErrNotReady |
|
3953 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
3954 { |
|
3955 TUint numResources = 0; |
|
3956 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data |
|
3957 { |
|
3958 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
3959 return r; |
|
3960 } |
|
3961 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects |
|
3962 // and reference via an RSimplePointerArray |
|
3963 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
3964 for(TUint i=0;i<numResources;i++) |
|
3965 { |
|
3966 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
3967 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
3968 { |
|
3969 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
3970 } |
|
3971 } |
|
3972 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNone) |
|
3973 { |
|
3974 gTest.Printf(_L("TestTransientHandling: gChannel GetInfoOnClientsUsingResource returned %d\n"),r); |
|
3975 return KErrGeneral; |
|
3976 } |
|
3977 TUint dumResources=0; |
|
3978 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit2; |
|
3979 name8Bit2.Copy(tempName2); |
|
3980 TClientName* clientName2 = (TClientName*)&name8Bit2; |
|
3981 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName2, dumResources, &infoPtrs))!=KErrNone) |
|
3982 { |
|
3983 gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource returned %d\n"),r); |
|
3984 return KErrGeneral; |
|
3985 } |
|
3986 if(dumResources!=0) |
|
3987 { |
|
3988 gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource dumResources=%d\n"),dumResources); |
|
3989 return KErrGeneral; |
|
3990 } |
|
3991 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit1; |
|
3992 name8Bit1.Copy(tempName1); |
|
3993 TClientName* clientName1 = (TClientName*)&name8Bit1; |
|
3994 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName1, numResources, &infoPtrs))!=KErrNotReady) |
|
3995 { |
|
3996 gTest.Printf(_L("TestTransientHandling: tempName1 GetInfoOnClientsUsingResource returned %d\n"),r); |
|
3997 return KErrGeneral; |
|
3998 } |
|
3999 |
|
4000 infoPtrs.Close(); |
|
4001 } |
|
4002 |
|
4003 |
|
4004 // 15) Repeat the read the number of resources without reading the resource information |
|
4005 // Subsequent call to read the resources information (without re-loading) should return error KErrNotReady |
|
4006 // Then call to read the resources information (with re-loading) should be successful |
|
4007 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
4008 { |
|
4009 TUint numResources = 0; |
|
4010 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // don't load data |
|
4011 { |
|
4012 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
4013 return r; |
|
4014 } |
|
4015 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects |
|
4016 // and reference via an RSimplePointerArray |
|
4017 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources); |
|
4018 for(TUint i=0;i<numResources;i++) |
|
4019 { |
|
4020 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
4021 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
4022 { |
|
4023 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
4024 } |
|
4025 } |
|
4026 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady) |
|
4027 { |
|
4028 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r); |
|
4029 return KErrGeneral; |
|
4030 } |
|
4031 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs, ETrue))!=KErrNone) |
|
4032 { |
|
4033 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r); |
|
4034 return r; |
|
4035 } |
|
4036 infoPtrs.Close(); |
|
4037 } |
|
4038 |
|
4039 |
|
4040 // 16) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should |
|
4041 // return error KErrArgument |
|
4042 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); |
|
4043 { |
|
4044 TUint numResources = 0; |
|
4045 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data |
|
4046 { |
|
4047 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); |
|
4048 return r; |
|
4049 } |
|
4050 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects |
|
4051 // and reference via an RSimplePointerArray |
|
4052 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources-1); |
|
4053 for(TUint i=0;i<(numResources-1);i++) |
|
4054 { |
|
4055 TResourceInfoBuf *info = new TResourceInfoBuf(); |
|
4056 if((r=infoPtrs.Insert(info, i))!=KErrNone) |
|
4057 { |
|
4058 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); |
|
4059 } |
|
4060 } |
|
4061 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrArgument) |
|
4062 { |
|
4063 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r); |
|
4064 return KErrGeneral; |
|
4065 } |
|
4066 |
|
4067 // Ensure misleading result is not returned |
|
4068 r=KErrNone; |
|
4069 infoPtrs.Close(); |
|
4070 } |
|
4071 |
|
4072 channelTwo.Close(); |
|
4073 channelThree.Close(); |
|
4074 |
|
4075 return r; |
|
4076 } |
|
4077 |
|
4078 |
|
4079 EXPORT_C TInt E32Main() |
|
4080 // |
|
4081 // Main |
|
4082 // |
|
4083 { |
|
4084 gTest.Start(_L("Test Power Resource Manager user side API\n")); |
|
4085 |
|
4086 TInt r = KErrNone; |
|
4087 |
|
4088 // Test attempted load of PDD |
|
4089 gTest.Next(_L("**Load PDD\n")); |
|
4090 r=User::LoadPhysicalDevice(PDD_NAME); |
|
4091 if((r!=KErrNone)&&(r!=KErrAlreadyExists)) |
|
4092 { |
|
4093 gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r); |
|
4094 } |
|
4095 else |
|
4096 { |
|
4097 // Test attempted load of LDD |
|
4098 gTest.Next(_L("**Load LDD\n")); |
|
4099 r=User::LoadLogicalDevice(LDD_NAME); |
|
4100 if((r!=KErrNone)&&(r!=KErrAlreadyExists)) |
|
4101 gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r); |
|
4102 } |
|
4103 if((r==KErrNone)||(r==KErrAlreadyExists)) |
|
4104 { |
|
4105 r = KErrNone; // Re-initialise in case set to KErrAlreadyExists |
|
4106 // |
|
4107 // Need a channel open for the following tests |
|
4108 gTest.Next(_L("**OpenAndRegisterChannel\n")); |
|
4109 r=OpenAndRegisterChannel(); |
|
4110 if (r==KErrNone) |
|
4111 { |
|
4112 // Get the version of the ResourceController |
|
4113 TUint version; |
|
4114 if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone) |
|
4115 { |
|
4116 gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r); |
|
4117 return r; |
|
4118 } |
|
4119 gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version); |
|
4120 } |
|
4121 if (r==KErrNone) |
|
4122 { |
|
4123 gTest.Next(_L("**TestThreadExclusiveAccess\n")); |
|
4124 r=TestThreadExclusiveAccess(); |
|
4125 } |
|
4126 if (r==KErrNone) |
|
4127 { |
|
4128 gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n")); |
|
4129 r=TestGetClientGetResourceInfo(); |
|
4130 } |
|
4131 if (r==KErrNone) |
|
4132 { |
|
4133 gTest.Next(_L("**TestGetSetResourceStateOps\n")); |
|
4134 r=TestGetSetResourceStateOps(); |
|
4135 } |
|
4136 if (r==KErrNone) |
|
4137 { |
|
4138 gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n")); |
|
4139 r=TestGetClientGetResourceInfo(); |
|
4140 } |
|
4141 if (r==KErrNone) |
|
4142 { |
|
4143 gTest.Next(_L("**TestGetSetResourceStateQuota\n")); |
|
4144 r=TestGetSetResourceStateQuota(); |
|
4145 } |
|
4146 if (r==KErrNone) |
|
4147 { |
|
4148 gTest.Next(_L("**TestNotificationOps\n")); |
|
4149 r=TestNotificationOps(); |
|
4150 } |
|
4151 if (r==KErrNone) |
|
4152 { |
|
4153 gTest.Next(_L("**TestNotificationQuota\n")); |
|
4154 r=TestNotificationQuota(); |
|
4155 } |
|
4156 if (r==KErrNone) |
|
4157 { |
|
4158 // Should be no change since last invocation (assuming that |
|
4159 // no clients other than those in this test) |
|
4160 gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n")); |
|
4161 r=TestGetClientGetResourceInfo(); |
|
4162 } |
|
4163 if (r==KErrNone) |
|
4164 { |
|
4165 gTest.Next(_L("**TestAdditionalThread\n")); |
|
4166 r=TestAdditionalThread(); |
|
4167 } |
|
4168 if (r==KErrNone) |
|
4169 { |
|
4170 gTest.Next(_L("**TestTransientHandling\n")); |
|
4171 r=TestTransientHandling(); |
|
4172 } |
|
4173 } |
|
4174 gChannel.Close(); |
|
4175 |
|
4176 User::FreeLogicalDevice(KLddRootName); |
|
4177 User::FreePhysicalDevice(PDD_NAME); |
|
4178 User::After(100000); // Allow idle thread to run for driver unloading |
|
4179 |
|
4180 gTest.End(); |
|
4181 return r; |
|
4182 } |
|
4183 |