|
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 #define __E32TEST_EXTENSION__ |
|
17 #include <e32test.h> |
|
18 #include "d_prmacctst.h" |
|
19 |
|
20 _LIT8(KTestToc, "TOC"); |
|
21 _LIT8(KTestTac1, "TAC1"); |
|
22 _LIT8(KTestTac2, "TAC2"); |
|
23 _LIT8(KTestTac3, "TAC3"); |
|
24 |
|
25 // The number of test values for multi-level resources |
|
26 static const TInt KTestMultiLevelValues = 10; |
|
27 |
|
28 // Bit 16 in the resource ID indicates that the resource has dependencies |
|
29 static const TUint32 KTestIdHasDependencies = 0x00010000; |
|
30 static const TInt KTestMaxDependencies = 256; |
|
31 |
|
32 static const TInt KTestResourceNotInUse = -1; |
|
33 |
|
34 // structure for holding ResId and ResPrty |
|
35 struct SResDepInfo |
|
36 { |
|
37 TUint iResourceId; |
|
38 TUint8 iDependencyPriority; |
|
39 }; |
|
40 class CTestPrmAccTst : public CBase |
|
41 { |
|
42 public: |
|
43 CTestPrmAccTst(); |
|
44 ~CTestPrmAccTst(); |
|
45 TInt DoTestPreamble(); |
|
46 void DoTest(); |
|
47 void DoTestPostamble(); |
|
48 protected: |
|
49 TBool ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget); |
|
50 void TestEnumerateResources(); |
|
51 void TestSingleUserResources(TInt aResourceNo); |
|
52 void TestSharedResources(TInt aResourceNo); |
|
53 void TestBinaryResources(TInt aResourceNo); |
|
54 void TestMultilevelResources(TInt aResourceNo); |
|
55 void TestLatency(TInt aResourceNo); |
|
56 void TestSense(TInt aResourceNo); |
|
57 void TestCustomSense(TInt aResourceNo); |
|
58 void TestDefaultPowerResumption(); |
|
59 void TestDependenciesAreDeclared(TInt aResourceNo); |
|
60 private: |
|
61 enum TBinary |
|
62 { |
|
63 EBinaryOff = 0, |
|
64 EBinaryOn = 1 |
|
65 }; |
|
66 protected: |
|
67 RTest test; |
|
68 private: |
|
69 // The test PRM clients |
|
70 RPrmIf iToc; // Test Observer Client (never owns any resource) |
|
71 RPrmIf iTac1; // Active clients... |
|
72 RPrmIf iTac2; |
|
73 RPrmIf iTac3; |
|
74 RPrmIf iKextc; // The Kernel Extension Client (owns Single User Resources) |
|
75 // |
|
76 TBool iIsPrmSupported; |
|
77 // |
|
78 RBuf8 iResources; |
|
79 TUint iNoResources; |
|
80 // |
|
81 static CTestPrmAccTst* iSingletonInstance; |
|
82 }; |
|
83 |
|
84 CTestPrmAccTst::CTestPrmAccTst() |
|
85 :test(_L("T_PRMACCTST")), |
|
86 iIsPrmSupported(EFalse), |
|
87 iNoResources(0) |
|
88 { |
|
89 } |
|
90 |
|
91 CTestPrmAccTst::~CTestPrmAccTst() |
|
92 { |
|
93 iResources.Close(); |
|
94 TInt r = User::FreeLogicalDevice(KPrmIfLddName); |
|
95 test(r==KErrNone); |
|
96 #ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
97 r = User::FreePhysicalDevice(_L("resourcecontrollerextended.pdd")); |
|
98 test(r==KErrNone); |
|
99 #endif |
|
100 User::After(100000); |
|
101 } |
|
102 |
|
103 /* ---------------------------------------------------------------------------- |
|
104 @SYMTestCaseID PBASE-PRMACCTST-ENUMRES-0559 |
|
105 @SYMTestCaseDesc Ensure current resource state of PRM is correctly listed |
|
106 @SYMREQ REQ7751 |
|
107 @SYMPREQ PREQ1398 |
|
108 @SYMTestPriority Critical |
|
109 @SYMTestActions |
|
110 1. Display all resources and their properties |
|
111 2. Ensure the resource state range is coherent |
|
112 @SYMTestExpectedResults |
|
113 1. All resources are shown with the correct properties |
|
114 2. Min <= Default <= Max and Min < Max if Negative Sense |
|
115 Min >= Default >= Max and Max > Min if Positive Sense |
|
116 Binary resources states are '0' or '1' |
|
117 */ |
|
118 |
|
119 void CTestPrmAccTst::TestEnumerateResources() |
|
120 { |
|
121 test.Printf(_L("Id Resource name C LG LS T U S DefltLvl MinLevel MaxLevel\n")); |
|
122 test.Printf(_L("--------+--------------------------------+-+--+--+--+--+-+--------+--------+--------\n")); |
|
123 TInt i; |
|
124 for (i = 0; i < (TInt) iNoResources; i++) |
|
125 { |
|
126 TResInfo& res = *((TResInfo*) iResources.Ptr() + i); |
|
127 |
|
128 // Display properties |
|
129 test.Printf(_L("%08x "), res.iResourceId); |
|
130 test_Compare(res.iResourceName->Length(), <=, KNameMaxLength); |
|
131 TBuf<KNameMaxLength> tmp; |
|
132 tmp.Copy(*res.iResourceName); |
|
133 test.Printf(_L("%-.32S "), &tmp); |
|
134 // |
|
135 if (res.iClass == TResInfo::EPhysical) |
|
136 { |
|
137 test.Printf(_L("P ")); |
|
138 } |
|
139 else if (res.iClass == TResInfo::ELogical) |
|
140 { |
|
141 test.Printf(_L("L ")); |
|
142 } |
|
143 else |
|
144 { |
|
145 test(EFalse); |
|
146 } |
|
147 // |
|
148 if (res.iLatencyGet == TResInfo::EInstantaneous) |
|
149 { |
|
150 test.Printf(_L("In ")); |
|
151 } |
|
152 else if (res.iLatencyGet == TResInfo::ELongLatency) |
|
153 { |
|
154 test.Printf(_L("Lo ")); |
|
155 } |
|
156 else |
|
157 { |
|
158 test(EFalse); |
|
159 } |
|
160 // |
|
161 if (res.iLatencySet == TResInfo::EInstantaneous) |
|
162 { |
|
163 test.Printf(_L("In ")); |
|
164 } |
|
165 else if (res.iLatencySet == TResInfo::ELongLatency) |
|
166 { |
|
167 test.Printf(_L("Lo ")); |
|
168 } |
|
169 else |
|
170 { |
|
171 test(EFalse); |
|
172 } |
|
173 // |
|
174 if (res.iType == TResInfo::EBinary) |
|
175 { |
|
176 test.Printf(_L("B ")); |
|
177 } |
|
178 else if (res.iType == TResInfo::EMultiLevel) |
|
179 { |
|
180 test.Printf(_L("ML ")); |
|
181 } |
|
182 else if (res.iType == TResInfo::EMultiProperty) |
|
183 { |
|
184 test.Printf(_L("MP ")); |
|
185 } |
|
186 else |
|
187 { |
|
188 test(EFalse); |
|
189 } |
|
190 // |
|
191 if (res.iUsage == TResInfo::ESingleUse) |
|
192 { |
|
193 test.Printf(_L("SU ")); |
|
194 } |
|
195 else if (res.iUsage == TResInfo::EShared) |
|
196 { |
|
197 test.Printf(_L("Sh ")); |
|
198 } |
|
199 else |
|
200 { |
|
201 test(EFalse); |
|
202 } |
|
203 // |
|
204 if (res.iSense == TResInfo::EPositive) |
|
205 { |
|
206 test.Printf(_L("+ ")); |
|
207 } |
|
208 else if (res.iSense == TResInfo::ENegative) |
|
209 { |
|
210 test.Printf(_L("- ")); |
|
211 } |
|
212 else if (res.iSense == TResInfo::ECustom) |
|
213 { |
|
214 test.Printf(_L("C ")); |
|
215 } |
|
216 else |
|
217 { |
|
218 test(EFalse); |
|
219 } |
|
220 // |
|
221 test.Printf(_L("%08x "), res.iDefaultLevel); |
|
222 test.Printf(_L("%08x "), res.iMinLevel); |
|
223 test.Printf(_L("%08x\n"), res.iMaxLevel); |
|
224 |
|
225 // Retrieve resource dependencies |
|
226 if (res.iResourceId & KTestIdHasDependencies) |
|
227 { |
|
228 RBuf8 deplist; |
|
229 deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies); |
|
230 iToc.GetResourceDependencies(res.iResourceId, deplist); |
|
231 TInt j; |
|
232 test.Printf(_L(" Direct Dependencies:")); |
|
233 SResDepInfo* ptr = (SResDepInfo*)deplist.Ptr(); |
|
234 for (j = 0; j < (TInt) (deplist.Length() / sizeof(SResDepInfo)); j++, ptr++) |
|
235 { |
|
236 test.Printf(_L("ResourceId: %08x"), ptr->iResourceId); |
|
237 test.Printf(_L("Resource Priority: %08x"), ptr->iDependencyPriority); |
|
238 } |
|
239 test.Printf(_L("\n")); |
|
240 deplist.Close(); |
|
241 } |
|
242 test.Printf(_L("C:Class,P:Physical,L:Logical")); |
|
243 test.Printf(_L("LG/LS:Latency Get/Set,In:Instantaneous,Lo:Long Latency")); |
|
244 test.Printf(_L("T:Type,MP:Multiproperty,ML:Multilevel,B:Binary")); |
|
245 test.Printf(_L("U:Usage,SU:Single-User,Sh:Shared")); |
|
246 test.Printf(_L("S:Sense,+:Positive,-:Negative,C:Custom")); |
|
247 |
|
248 // Ensure the state range of the resource does not contradict its properties |
|
249 if (res.iType == TResInfo::EBinary) |
|
250 { |
|
251 if (res.iSense == TResInfo::EPositive) |
|
252 { |
|
253 test(res.iMinLevel == EBinaryOff); |
|
254 test(res.iMaxLevel == EBinaryOn); |
|
255 } |
|
256 else if (res.iSense == TResInfo::ENegative) |
|
257 { |
|
258 test(res.iMinLevel == EBinaryOn); |
|
259 test(res.iMaxLevel == EBinaryOff); |
|
260 } |
|
261 else if (res.iSense == TResInfo::ECustom) |
|
262 { |
|
263 test(res.iMinLevel == EBinaryOff || res.iMinLevel == EBinaryOn); |
|
264 test(res.iMaxLevel == EBinaryOff || res.iMaxLevel == EBinaryOn); |
|
265 test_Compare(res.iMinLevel, !=, res.iMaxLevel); |
|
266 } |
|
267 test((res.iDefaultLevel == EBinaryOff) || (res.iDefaultLevel == EBinaryOn)); |
|
268 } |
|
269 // Level range must respect resource sense |
|
270 if (res.iSense == TResInfo::EPositive) |
|
271 { |
|
272 test_Compare(res.iMinLevel, <=, res.iMaxLevel); |
|
273 test_Compare(res.iMinLevel, <=, res.iDefaultLevel); |
|
274 test_Compare(res.iDefaultLevel, <=, res.iMaxLevel); |
|
275 test_Compare(res.iMinLevel, <, res.iMaxLevel); |
|
276 } |
|
277 else if (res.iSense == TResInfo::ENegative) |
|
278 { |
|
279 test_Compare(res.iMinLevel, >=, res.iMaxLevel); |
|
280 test_Compare(res.iMinLevel, >=, res.iDefaultLevel); |
|
281 test_Compare(res.iDefaultLevel, >=, res.iMaxLevel); |
|
282 test_Compare(res.iMinLevel, >, res.iMaxLevel); |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 /* ---------------------------------------------------------------------------- |
|
288 @SYMTestCaseID PBASE-PRMACCTST-SINGLEUSER-0560 |
|
289 @SYMTestCaseDesc Ensure Single User resources can only be used by one client |
|
290 at a time |
|
291 @SYMREQ REQ7751 |
|
292 @SYMPREQ PREQ1398 |
|
293 @SYMTestPriority High |
|
294 @SYMTestActions |
|
295 Pre-condition: |
|
296 The resource is not in use |
|
297 For each Single User resource: |
|
298 1. Register TAC1 & TAC2 |
|
299 2. TAC1 changes resource state |
|
300 3. TAC2 changes resource state |
|
301 4. De-register TAC1 |
|
302 --- |
|
303 5. Register TAC1 |
|
304 6. TAC2 changes resource state |
|
305 7. TAC1 changes resource state |
|
306 8. De-register TAC1 & TAC2 |
|
307 @SYMTestExpectedResults |
|
308 1. Clients registered |
|
309 2. Resource state changed |
|
310 3. KErrAccessDenied as there is already one registered client |
|
311 4. Client de-registered |
|
312 --- |
|
313 5. Client registered |
|
314 6. Resource state changed |
|
315 7. KErrAccessDenied as there is already one registered client |
|
316 8. Both clients de-registered |
|
317 */ |
|
318 |
|
319 void CTestPrmAccTst::TestSingleUserResources(TInt aResourceNo) |
|
320 { |
|
321 test.Printf(_L("---Single-User ")); |
|
322 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
323 // Test pre-condition: resource not in use |
|
324 TInt levelowner; |
|
325 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
326 test_KErrNone(r); |
|
327 if (levelowner != KTestResourceNotInUse) |
|
328 { |
|
329 test.Printf(_L("Not tested (Single-User resource already in use)\n")); |
|
330 return; |
|
331 } |
|
332 // Define two test values |
|
333 TInt state; |
|
334 r = iToc.GetResourceState(res.iResourceId, state); |
|
335 test_KErrNone(r); |
|
336 // |
|
337 TInt tstval1; |
|
338 TInt tstval2; |
|
339 if (state == res.iMinLevel) |
|
340 { |
|
341 tstval1 = res.iMaxLevel; |
|
342 tstval2 = res.iMinLevel; |
|
343 } |
|
344 else |
|
345 { |
|
346 tstval1 = res.iMinLevel; |
|
347 tstval2 = res.iMaxLevel; |
|
348 } |
|
349 // Test starts here |
|
350 r = iTac1.Open(); |
|
351 test_KErrNone(r); |
|
352 r = iTac2.Open(); |
|
353 test_KErrNone(r); |
|
354 r = iTac1.RegisterClient(KTestTac1); |
|
355 test_KErrNone(r); |
|
356 r = iTac2.RegisterClient(KTestTac2); |
|
357 test_KErrNone(r); |
|
358 // |
|
359 r = iTac1.ChangeResourceState(res.iResourceId, tstval1); |
|
360 test_KErrNone(r); |
|
361 r = iTac1.GetResourceState(res.iResourceId, state); |
|
362 test_KErrNone(r); |
|
363 test_Equal(tstval1, state); |
|
364 r = iTac2.GetResourceState(res.iResourceId, state); |
|
365 test_KErrNone(r); |
|
366 test_Equal(tstval1, state); |
|
367 r = iTac2.ChangeResourceState(res.iResourceId, tstval2); |
|
368 test_Equal(KErrAccessDenied, r); // TAC2 cannot change the resource state |
|
369 // |
|
370 r = iTac1.DeRegisterClient(); |
|
371 test_KErrNone(r); |
|
372 r = iTac1.RegisterClient(KTestTac1); |
|
373 test_KErrNone(r); |
|
374 r = iTac2.ChangeResourceState(res.iResourceId, tstval2); |
|
375 test_KErrNone(r); |
|
376 r = iTac1.GetResourceState(res.iResourceId, state); |
|
377 test_KErrNone(r); // TAC1 can still access the resource state... |
|
378 test_Equal(tstval2, state); |
|
379 r = iTac1.ChangeResourceState(res.iResourceId, tstval1); |
|
380 test_Equal(KErrAccessDenied, r); // ... but cannot change it |
|
381 r = iTac2.GetResourceState(res.iResourceId, state); |
|
382 test_KErrNone(r); |
|
383 test_Equal(tstval2, state); // The resource state remains unchanged indeed |
|
384 // |
|
385 r = iTac1.DeRegisterClient(); |
|
386 test_KErrNone(r); |
|
387 r = iTac2.DeRegisterClient(); |
|
388 test_KErrNone(r); |
|
389 iTac1.Close(); |
|
390 iTac2.Close(); |
|
391 test.Printf(_L("\n")); |
|
392 } |
|
393 |
|
394 /* ---------------------------------------------------------------------------- |
|
395 @SYMTestCaseID PBASE-PRMACCTST-SHARED-0561 |
|
396 @SYMTestCaseDesc Ensure a Shared Resources can be changed by several |
|
397 clients |
|
398 @SYMREQ REQ7751 |
|
399 @SYMPREQ PREQ1398 |
|
400 @SYMTestPriority High |
|
401 @SYMTestActions |
|
402 Pre-conditions: |
|
403 If in use, resource state is not equal to max level |
|
404 Resource is not Custom Sense |
|
405 For each Shared resource: |
|
406 1. Register TOC, TAC1 & TAC2 |
|
407 2. TAC1 changes resource state to level1 |
|
408 3. TAC2 changes resource state to level2 |
|
409 4. TAC2 changes resource state to level1 |
|
410 5. TAC1 changes resource state to level2 |
|
411 6. De-register TOC, TAC1 & TAC2 |
|
412 @SYMTestExpectedResults |
|
413 1. Clients registered |
|
414 2. Resource state changed |
|
415 3. Resource state changed |
|
416 4. Resource state changed |
|
417 5. Resource state changed |
|
418 6. Clients de-registered |
|
419 */ |
|
420 |
|
421 void CTestPrmAccTst::TestSharedResources(TInt aResourceNo) |
|
422 { |
|
423 test.Printf(_L("---Shared ")); |
|
424 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
425 // Test pre-conditions |
|
426 if (res.iSense == TResInfo::ECustom) |
|
427 { |
|
428 test.Printf(_L("Not tested (Custom sense resource)\n")); |
|
429 return; |
|
430 } |
|
431 // |
|
432 TInt state; |
|
433 TInt r = iToc.GetResourceState(res.iResourceId, state); |
|
434 test_KErrNone(r); |
|
435 TInt levelowner; |
|
436 r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
437 test_KErrNone(r); |
|
438 // |
|
439 if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel) |
|
440 { |
|
441 test.Printf(_L("Not tested: Resource is already at maximum level\n")); |
|
442 return; |
|
443 } |
|
444 // Define two test values |
|
445 TInt tstval1; |
|
446 TInt tstval2; |
|
447 if (levelowner != KTestResourceNotInUse) |
|
448 { |
|
449 // Resource already in use |
|
450 tstval1 = state; |
|
451 tstval2 = res.iMaxLevel; |
|
452 } |
|
453 else |
|
454 { |
|
455 // Resource not in use |
|
456 tstval1 = res.iMinLevel; |
|
457 tstval2 = res.iMaxLevel; |
|
458 } |
|
459 // Test starts here |
|
460 r = iTac1.Open(); |
|
461 test_KErrNone(r); |
|
462 r = iTac2.Open(); |
|
463 test_KErrNone(r); |
|
464 r = iTac1.RegisterClient(KTestTac1); |
|
465 test_KErrNone(r); |
|
466 r = iTac2.RegisterClient(KTestTac2); |
|
467 test_KErrNone(r); |
|
468 // |
|
469 r = iTac1.ChangeResourceState(res.iResourceId, tstval1); |
|
470 test_KErrNone(r); |
|
471 r = iToc.GetResourceState(res.iResourceId, state); |
|
472 test_KErrNone(r); |
|
473 test_Equal(tstval1, state); |
|
474 // |
|
475 r = iTac2.ChangeResourceState(res.iResourceId, tstval2); |
|
476 test_KErrNone(r); |
|
477 r = iToc.GetResourceState(res.iResourceId, state); |
|
478 test_KErrNone(r); |
|
479 test_Equal(tstval2, state); |
|
480 // |
|
481 r = iTac2.ChangeResourceState(res.iResourceId, tstval1); |
|
482 test_KErrNone(r); |
|
483 r = iToc.GetResourceState(res.iResourceId, state); |
|
484 test_KErrNone(r); |
|
485 test_Equal(tstval1, state); |
|
486 // |
|
487 r = iTac1.ChangeResourceState(res.iResourceId, tstval2); |
|
488 test_KErrNone(r); |
|
489 r = iToc.GetResourceState(res.iResourceId, state); |
|
490 test_KErrNone(r); |
|
491 test_Equal(tstval2, state); |
|
492 // |
|
493 r = iTac1.DeRegisterClient(); |
|
494 test_KErrNone(r); |
|
495 r = iTac2.DeRegisterClient(); |
|
496 test_KErrNone(r); |
|
497 // |
|
498 iTac1.Close(); |
|
499 iTac2.Close(); |
|
500 test.Printf(_L("\n")); |
|
501 } |
|
502 |
|
503 /* ---------------------------------------------------------------------------- |
|
504 @SYMTestCaseID PBASE-PRMACCTST-BINARY-0562 |
|
505 @SYMTestCaseDesc Ensure Binary Resources function as expected |
|
506 @SYMREQ REQ7751 |
|
507 @SYMPREQ PREQ1398 |
|
508 @SYMTestPriority High |
|
509 @SYMTestActions |
|
510 Pre-conditions: |
|
511 Resource not in use, or... |
|
512 If Shared/Positive Sense, current resource must be off |
|
513 If Shared/Negative Sense, current resource must be on |
|
514 Resource is not Custom Sense |
|
515 For each Binary resource: |
|
516 1. Register TAC1 |
|
517 2. Turn resource off and toggle resource state several times |
|
518 3. De-register TAC1 |
|
519 @SYMTestExpectedResults |
|
520 1. Client registered |
|
521 2. Resource state changes as expected |
|
522 3. De-register TAC1 |
|
523 */ |
|
524 |
|
525 void CTestPrmAccTst::TestBinaryResources(TInt aResourceNo) |
|
526 { |
|
527 test.Printf(_L("---Binary ")); |
|
528 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
529 // Test pre-conditions |
|
530 if (res.iSense == TResInfo::ECustom) |
|
531 { |
|
532 test.Printf(_L("Not tested (Custom sense resource)\n")); |
|
533 return; |
|
534 } |
|
535 TInt state; |
|
536 TInt r = iToc.GetResourceState(res.iResourceId, state); |
|
537 test_KErrNone(r); |
|
538 TInt levelowner; |
|
539 r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
540 test_KErrNone(r); |
|
541 // |
|
542 if (levelowner != KTestResourceNotInUse) |
|
543 { |
|
544 if (res.iUsage == TResInfo::ESingleUse) |
|
545 { |
|
546 test.Printf(_L("Not tested (Single-User resource already in use)\n")); |
|
547 return; |
|
548 } |
|
549 if (res.iSense == TResInfo::EPositive && state == EBinaryOn) |
|
550 { |
|
551 test.Printf(_L("Not tested (Positive sense resource is already on)\n")); |
|
552 return; |
|
553 } |
|
554 if (res.iSense == TResInfo::ENegative && state == EBinaryOff) |
|
555 { |
|
556 test.Printf(_L("Not tested (Negative sense resource is already off)\n")); |
|
557 return; |
|
558 } |
|
559 } |
|
560 // Test starts here |
|
561 r = iTac1.Open(); |
|
562 test_KErrNone(r); |
|
563 r = iTac1.RegisterClient(KTestTac1); |
|
564 test_KErrNone(r); |
|
565 |
|
566 // Turn Resource off |
|
567 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff); |
|
568 test_KErrNone(r); |
|
569 r = iToc.GetResourceState(res.iResourceId, state); |
|
570 test_KErrNone(r); |
|
571 test_Equal(EBinaryOff, state); |
|
572 |
|
573 // Turn it on |
|
574 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOn); |
|
575 test_KErrNone(r); |
|
576 r = iToc.GetResourceState(res.iResourceId, state); |
|
577 test_KErrNone(r); |
|
578 test_Equal(EBinaryOn, state); |
|
579 |
|
580 // Turn it off |
|
581 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff); |
|
582 test_KErrNone(r); |
|
583 r = iToc.GetResourceState(res.iResourceId, state); |
|
584 test_KErrNone(r); |
|
585 test_Equal(EBinaryOff, state); |
|
586 // |
|
587 r = iTac1.DeRegisterClient(); |
|
588 test_KErrNone(r); |
|
589 iTac1.Close(); |
|
590 test.Printf(_L("\n")); |
|
591 } |
|
592 |
|
593 /* ---------------------------------------------------------------------------- |
|
594 @SYMTestCaseID PBASE-PRMACCTST-MULTILEVEL-0563 |
|
595 @SYMTestCaseDesc Ensure Multi-Level Resources function as expected |
|
596 @SYMREQ REQ7751 |
|
597 @SYMPREQ PREQ1398 |
|
598 @SYMTestPriority High |
|
599 @SYMTestActions |
|
600 Pre-condition: |
|
601 If in use, resource state is not equal to max level |
|
602 If in use, resource is not Single-User |
|
603 Resource is not Custom Sense |
|
604 For each Multi-Level resource: |
|
605 1. Register TOC and TAC1 |
|
606 2. Define a number of gradually increasing (or decreasing if negative |
|
607 sense resource) test values across the range of valid states. Attempt |
|
608 to change the resource state to each of these values. |
|
609 3. De-register TOC and TAC1 |
|
610 @SYMTestExpectedResults |
|
611 1. Clients registered |
|
612 2. Resource state should be changed to the test value if this value is |
|
613 accepted by the PSL. If not, the resource state should be changed to |
|
614 the minimum valid value that satisfies this requirement. |
|
615 3. Clients de-registered |
|
616 */ |
|
617 |
|
618 void CTestPrmAccTst::TestMultilevelResources(TInt aResourceNo) |
|
619 { |
|
620 test.Printf(_L("---Multi-level ")); |
|
621 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
622 // Test pre-conditions |
|
623 if (res.iSense == TResInfo::ECustom) |
|
624 { |
|
625 test.Printf(_L("Not tested (Custom sense resource)\n")); |
|
626 return; |
|
627 } |
|
628 TInt state; |
|
629 TInt r = iToc.GetResourceState(res.iResourceId, state); |
|
630 test_KErrNone(r); |
|
631 TInt levelowner; |
|
632 r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
633 test_KErrNone(r); |
|
634 // |
|
635 if (levelowner != KTestResourceNotInUse) |
|
636 { |
|
637 if (state == res.iMaxLevel) |
|
638 { |
|
639 test.Printf(_L("Not tested (Resource is already at maximum level)\n")); |
|
640 return; |
|
641 } |
|
642 if (res.iUsage == TResInfo::ESingleUse) |
|
643 { |
|
644 test.Printf(_L("Not tested (Single-User resource already in use)\n")); |
|
645 return; |
|
646 } |
|
647 } |
|
648 // Define test values |
|
649 TInt tstval[KTestMultiLevelValues]; |
|
650 TInt i; |
|
651 for (i = 0; i < KTestMultiLevelValues; i++) |
|
652 { |
|
653 if (levelowner == KTestResourceNotInUse) |
|
654 { |
|
655 // If resource is not in use, we can use the entire state range |
|
656 tstval[i] = res.iMinLevel + i * (res.iMaxLevel - res.iMinLevel) / (KTestMultiLevelValues - 1); |
|
657 } |
|
658 else |
|
659 { |
|
660 // Or else we are limited to the Current State-MaxLevel range |
|
661 tstval[i] = state + i * (res.iMaxLevel - state) / (KTestMultiLevelValues - 1); |
|
662 } |
|
663 } |
|
664 test_Compare(tstval[0], !=, tstval[KTestMultiLevelValues - 1]); |
|
665 // Test starts here |
|
666 r = iTac1.Open(); |
|
667 test_KErrNone(r); |
|
668 r = iTac1.RegisterClient(KTestTac1); |
|
669 test_KErrNone(r); |
|
670 // |
|
671 for (i = 0; i < KTestMultiLevelValues; i++) |
|
672 { |
|
673 r = iTac1.ChangeResourceState(res.iResourceId, tstval[i]); |
|
674 test_KErrNone(r); |
|
675 r = iToc.GetResourceState(res.iResourceId, state); |
|
676 test_KErrNone(r); |
|
677 // Resource state should be equal to the test value |
|
678 // or to the first valid value that satisfies the request |
|
679 if (res.iSense == TResInfo::EPositive) |
|
680 { |
|
681 test_Compare(state, >=, tstval[i]); |
|
682 } |
|
683 else |
|
684 { |
|
685 test_Compare(state, <=, tstval[i]); |
|
686 } |
|
687 test.Printf(_L(".")); |
|
688 } |
|
689 // |
|
690 r = iTac1.DeRegisterClient(); |
|
691 test_KErrNone(r); |
|
692 iTac1.Close(); |
|
693 test.Printf(_L("\n")); |
|
694 } |
|
695 |
|
696 /* ---------------------------------------------------------------------------- |
|
697 @SYMTestCaseID PBASE-PRMACCTST-LATENCY-0564 |
|
698 @SYMTestCaseDesc Ensure instantaneous resource change state instantaneously |
|
699 @SYMREQ REQ7751 |
|
700 @SYMPREQ PREQ1398 |
|
701 @SYMTestPriority High |
|
702 @SYMTestActions |
|
703 Pre-condition: |
|
704 If in use, resource is not Single-User |
|
705 If in use, resource state is not equal to max level |
|
706 If in use, resource is not Custom Sense |
|
707 For each Multi-Level resource: |
|
708 1. Register TAC1 |
|
709 2. TAC1 changes resource state to max value (async) |
|
710 3. Immediately afterwards, TAC1 gets resource state (sync) |
|
711 4. Wait for callback function |
|
712 5. TAC1 changes resource state to min value (async) |
|
713 6. Immediately afterwards, TAC1 gets resource state (sync) |
|
714 7. Wait for callback function |
|
715 8. De-register TAC1 |
|
716 @SYMTestExpectedResults |
|
717 1. Client registered |
|
718 2. No error reported. |
|
719 3. If resource is Instantaneous Set, then the resource state is equal to |
|
720 the new state. If Long Latency Set, then the state is either the old or |
|
721 the new state. |
|
722 4. Callback function is called. |
|
723 5. No error reported. |
|
724 6. If resource is Instantaneous Set, then the resource state is equal to |
|
725 the new state. If Long Latency Set, then the state is either the old or |
|
726 the new state. |
|
727 7. Callback function is called. |
|
728 8. Client de-registered. |
|
729 */ |
|
730 |
|
731 void CTestPrmAccTst::TestLatency(TInt aResourceNo) |
|
732 { |
|
733 test.Printf(_L("---Latency ")); |
|
734 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
735 // Test pre-conditions |
|
736 if (res.iSense == TResInfo::ECustom) |
|
737 { |
|
738 test.Printf(_L("Not tested (Custom sense resource)\n")); |
|
739 return; |
|
740 } |
|
741 TInt state; |
|
742 TInt r = iToc.GetResourceState(res.iResourceId, state); |
|
743 test_KErrNone(r); |
|
744 TInt levelowner; |
|
745 r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
746 test_KErrNone(r); |
|
747 // |
|
748 if (levelowner != KTestResourceNotInUse) |
|
749 { |
|
750 if (state == res.iMaxLevel) |
|
751 { |
|
752 test.Printf(_L("Not tested (Resource is already at maximum level)\n")); |
|
753 return; |
|
754 } |
|
755 if (res.iUsage == TResInfo::ESingleUse) |
|
756 { |
|
757 test.Printf(_L("Not tested (Single-User resource already in use)\n")); |
|
758 return; |
|
759 } |
|
760 } |
|
761 // Define the two test values |
|
762 TInt tstval1; |
|
763 TInt tstval2; |
|
764 if (levelowner != KTestResourceNotInUse) |
|
765 { |
|
766 // Resource in use |
|
767 tstval1 = res.iMaxLevel; |
|
768 tstval2 = state; |
|
769 } |
|
770 else |
|
771 { |
|
772 tstval1 = res.iMaxLevel; |
|
773 tstval2 = res.iMinLevel; |
|
774 } |
|
775 // Test starts here |
|
776 r = iTac1.Open(); |
|
777 test_KErrNone(r); |
|
778 r = iTac1.RegisterClient(KTestTac1); |
|
779 test_KErrNone(r); |
|
780 // |
|
781 TTestResourceStateBuf buf; |
|
782 buf().iResourceId = res.iResourceId; |
|
783 buf().iNewState = tstval1; |
|
784 TRequestStatus rs; |
|
785 TInt tmpstate; |
|
786 iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate); |
|
787 User::WaitForRequest(rs); |
|
788 test_KErrNone(rs.Int()); |
|
789 if (res.iLatencySet == TResInfo::EInstantaneous) |
|
790 { |
|
791 test_Equal(tstval1, tmpstate); // Temp state is equal to the new state |
|
792 } |
|
793 else if (tmpstate != state) // Temp state is not necessarily equal to the new state |
|
794 { |
|
795 test_Equal(tstval1, tmpstate); |
|
796 } |
|
797 TInt newstate; |
|
798 r = iToc.GetResourceState(res.iResourceId, newstate); |
|
799 test_KErrNone(r); |
|
800 test_Equal(tstval1, newstate); |
|
801 // |
|
802 buf().iNewState = tstval2; |
|
803 iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate); |
|
804 User::WaitForRequest(rs); |
|
805 test_KErrNone(rs.Int()); |
|
806 if (res.iLatencySet == TResInfo::EInstantaneous) |
|
807 { |
|
808 test_Equal(tstval2, tmpstate); // Temp state is equal to the new state |
|
809 } |
|
810 else if (tmpstate != tstval1) // Temp state is not necessarily equal to the new state |
|
811 { |
|
812 test_Equal(tstval2, tmpstate); |
|
813 } |
|
814 r = iToc.GetResourceState(res.iResourceId, newstate); |
|
815 test_KErrNone(r); |
|
816 test_Equal(tstval2, newstate); |
|
817 // |
|
818 r = iTac1.DeRegisterClient(); |
|
819 test_KErrNone(r); |
|
820 iTac1.Close(); |
|
821 test.Printf(_L("\n")); |
|
822 } |
|
823 |
|
824 /* ---------------------------------------------------------------------------- |
|
825 @SYMTestCaseID PBASE-PRMACCTST-SENSE-0565 |
|
826 @SYMTestCaseDesc Ensure Negative and Positive Sense resources behave as |
|
827 expected |
|
828 @SYMREQ REQ7751 |
|
829 @SYMPREQ PREQ1398 |
|
830 @SYMTestPriority High |
|
831 @SYMTestActions |
|
832 Pre-condition: |
|
833 Resource is Shared |
|
834 If in use, resource state is not equal to max level |
|
835 For each Positive or Negative Sense resource: |
|
836 1. Register TOC, TAC1, TAC2 and TAC3 |
|
837 2. Define three distincts test values, s1, s2 and s3, that correspond to |
|
838 actual resource states in the PSL. s1 and s3 are at opposite ends of |
|
839 the range of states the resource can be set to. s2 is an intermediate |
|
840 state. It might not always be possible to find a distinct value for s2 |
|
841 (if the resource is binary or if its current use is limiting the number |
|
842 of states the resource can be set to). In this case, s2 = s1. |
|
843 3. TAC1 sets resource state to s1 |
|
844 4. TAC2 sets resource state to s2 |
|
845 5. TAC3 sets resource state to s3 |
|
846 6. De-register TAC2 |
|
847 7. De-register TAC3 |
|
848 8. De-register TAC1 and register TAC1, TAC2 and TAC3 again. |
|
849 9. TAC1 sets resource state to s1 |
|
850 10. TAC3 sets resource state to s3 |
|
851 11. TAC2 sets resource state to s2 |
|
852 12. De-register TAC3. |
|
853 13. TAC3 sets resource state to s3 |
|
854 14. De-register TOC, TAC1, TAC2 and TAC3 |
|
855 @SYMTestExpectedResults |
|
856 1. Clients registered |
|
857 2. s1 <= s2 < s3 |
|
858 3. Resource state set to s1 |
|
859 4. Resource state set to s2 |
|
860 5. Resource state set to s3 |
|
861 6. Resource state remains unchanged (TAC3 owns level) |
|
862 7. Resource state returns to s1 (TAC1 now owns level) |
|
863 8. Clients registered |
|
864 9. Resource state set to s1 |
|
865 10. Resource state set to s3 |
|
866 11. Resource state remains unchanged (TAC3 owns level) |
|
867 12. Resource state changes to s2 (TAC2 now owns level) |
|
868 13. Resource state set to s3 |
|
869 14. Clients de-registered |
|
870 */ |
|
871 |
|
872 void CTestPrmAccTst::TestSense(TInt aResourceNo) |
|
873 { |
|
874 test.Printf(_L("---Sense ")); |
|
875 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
876 // Test pre-conditions |
|
877 if (res.iUsage != TResInfo::EShared) |
|
878 { |
|
879 test.Printf(_L("Not tested: Resource is Single-User\n")); |
|
880 return; |
|
881 } |
|
882 // |
|
883 TInt state; |
|
884 TInt r = iToc.GetResourceState(res.iResourceId, state); |
|
885 test_KErrNone(r); |
|
886 TInt levelowner; |
|
887 r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
888 test_KErrNone(r); |
|
889 // |
|
890 if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel) |
|
891 { |
|
892 test.Printf(_L("Not tested (Resource is already at maximum level)\n")); |
|
893 return; |
|
894 } |
|
895 // Define three test values |
|
896 r = iTac1.Open(); |
|
897 test_KErrNone(r); |
|
898 r = iTac1.RegisterClient(KTestTac1); |
|
899 test_KErrNone(r); |
|
900 TInt tstval1; |
|
901 TInt tstval2; |
|
902 TInt tstval3; |
|
903 if (levelowner == KTestResourceNotInUse) |
|
904 { |
|
905 tstval1 = res.iMinLevel; |
|
906 } |
|
907 else |
|
908 { |
|
909 tstval1 = state; |
|
910 } |
|
911 tstval3 = res.iMaxLevel; |
|
912 // Attempt to find a distinct intermediate value by dichotomy |
|
913 tstval2 = tstval3; |
|
914 while ((tstval2 - tstval1 < -1) || (tstval2 - tstval1 > 1)) |
|
915 { |
|
916 tstval2 -= (tstval2 - tstval1 + (res.iSense == TResInfo::EPositive ? 1 : 0)) / 2; |
|
917 r = iTac1.ChangeResourceState(res.iResourceId, tstval2); |
|
918 test_KErrNone(r); |
|
919 r = iTac1.GetResourceState(res.iResourceId, state); |
|
920 test_KErrNone(r); |
|
921 } |
|
922 if (state == tstval1 && res.iType == TResInfo::EMultiLevel) |
|
923 { |
|
924 test.Printf(_L("(Could not find three distincts test values)")); |
|
925 } |
|
926 tstval2 = state; |
|
927 r = iTac1.DeRegisterClient(); |
|
928 test_KErrNone(r); |
|
929 iTac1.Close(); |
|
930 |
|
931 // Test starts here |
|
932 r = iTac1.Open(); |
|
933 test_KErrNone(r); |
|
934 r = iTac2.Open(); |
|
935 test_KErrNone(r); |
|
936 r = iTac3.Open(); |
|
937 test_KErrNone(r); |
|
938 r = iTac1.RegisterClient(KTestTac1); |
|
939 test_KErrNone(r); |
|
940 r = iTac2.RegisterClient(KTestTac2); |
|
941 test_KErrNone(r); |
|
942 r = iTac3.RegisterClient(KTestTac3); |
|
943 test_KErrNone(r); |
|
944 |
|
945 // Set resource state to the first test value |
|
946 r = iTac1.ChangeResourceState(res.iResourceId, tstval1); |
|
947 test_KErrNone(r); |
|
948 r = iToc.GetResourceState(res.iResourceId, state); |
|
949 test_KErrNone(r); |
|
950 test_Equal(tstval1, state); |
|
951 |
|
952 // Set resource state to middle test value |
|
953 r = iTac2.ChangeResourceState(res.iResourceId, tstval2); |
|
954 test_KErrNone(r); |
|
955 r = iToc.GetResourceState(res.iResourceId, state); |
|
956 test_KErrNone(r); |
|
957 test_Equal(tstval2, state); |
|
958 |
|
959 // Set resource to the third test value |
|
960 r = iTac3.ChangeResourceState(res.iResourceId, tstval3); |
|
961 test_KErrNone(r); |
|
962 r = iToc.GetResourceState(res.iResourceId, state); |
|
963 test_KErrNone(r); |
|
964 test_Equal(tstval3, state); |
|
965 |
|
966 // De-register second client |
|
967 r = iTac2.DeRegisterClient(); |
|
968 test_KErrNone(r); |
|
969 r = iToc.GetResourceState(res.iResourceId, state); |
|
970 test_KErrNone(r); |
|
971 test_Equal(tstval3, state); // state remains unchanged |
|
972 |
|
973 // De-register third client |
|
974 r = iTac3.DeRegisterClient(); |
|
975 test_KErrNone(r); |
|
976 r = iToc.GetResourceState(res.iResourceId, state); |
|
977 test_KErrNone(r); |
|
978 test_Equal(tstval1, state); // state changes |
|
979 |
|
980 // De-register and register all clients again |
|
981 r = iTac1.DeRegisterClient(); |
|
982 test_KErrNone(r); |
|
983 r = iTac1.RegisterClient(KTestTac1); |
|
984 test_KErrNone(r); |
|
985 r = iTac2.RegisterClient(KTestTac2); |
|
986 test_KErrNone(r); |
|
987 r = iTac3.RegisterClient(KTestTac3); |
|
988 test_KErrNone(r); |
|
989 |
|
990 // Set resource state to the first test value |
|
991 r = iTac1.ChangeResourceState(res.iResourceId, tstval1); |
|
992 test_KErrNone(r); |
|
993 r = iToc.GetResourceState(res.iResourceId, state); |
|
994 test_KErrNone(r); |
|
995 test_Equal(tstval1, state); |
|
996 |
|
997 // Set resource to the third test value |
|
998 r = iTac3.ChangeResourceState(res.iResourceId, tstval3); |
|
999 test_KErrNone(r); |
|
1000 r = iToc.GetResourceState(res.iResourceId, state); |
|
1001 test_KErrNone(r); |
|
1002 test_Equal(tstval3, state); |
|
1003 |
|
1004 // Set resource state to middle test value |
|
1005 r = iTac2.ChangeResourceState(res.iResourceId, tstval2); |
|
1006 test_KErrNone(r); |
|
1007 r = iToc.GetResourceState(res.iResourceId, state); |
|
1008 test_KErrNone(r); |
|
1009 test_Equal(tstval3, state); // state does not change |
|
1010 |
|
1011 // De-register client holding resource |
|
1012 r = iTac3.DeRegisterClient(); |
|
1013 test_KErrNone(r); |
|
1014 r = iToc.GetResourceState(res.iResourceId, state); |
|
1015 test_KErrNone(r); |
|
1016 test_Equal(tstval2, state); |
|
1017 |
|
1018 // Register client again |
|
1019 r = iTac3.RegisterClient(KTestTac3); |
|
1020 test_KErrNone(r); |
|
1021 r = iTac3.ChangeResourceState(res.iResourceId, tstval3); |
|
1022 test_KErrNone(r); |
|
1023 r = iToc.GetResourceState(res.iResourceId, state); |
|
1024 test_KErrNone(r); |
|
1025 test_Equal(tstval3, state); |
|
1026 |
|
1027 // |
|
1028 r = iTac3.DeRegisterClient(); |
|
1029 test_KErrNone(r); |
|
1030 r = iTac2.DeRegisterClient(); |
|
1031 test_KErrNone(r); |
|
1032 r = iTac1.DeRegisterClient(); |
|
1033 test_KErrNone(r); |
|
1034 iTac3.Close(); |
|
1035 iTac2.Close(); |
|
1036 iTac1.Close(); |
|
1037 test.Printf(_L("\n")); |
|
1038 } |
|
1039 |
|
1040 /* ---------------------------------------------------------------------------- |
|
1041 @SYMTestCaseID PBASE-PRMACCTST-CUSTOMSENSE-0566 |
|
1042 @SYMTestCaseDesc Ensure the Custom Sense function is implemented |
|
1043 @SYMREQ REQ7751 |
|
1044 @SYMPREQ PREQ1398 |
|
1045 @SYMTestPriority High |
|
1046 @SYMTestActions |
|
1047 For each Custom Sense resource: |
|
1048 1. Register TAC1 |
|
1049 2. Attempt to set the state of the resource to its current state. The |
|
1050 purpose of this test action is to ensure that the PSL's custom function |
|
1051 for this resource has been implemented. If the custom function is not |
|
1052 present, the PIL will generate a panic. |
|
1053 3. De-register TAC1 |
|
1054 @SYMTestExpectedResults |
|
1055 1. Client registered |
|
1056 2. The resource change request does not cause a panic. |
|
1057 3. Client de-registered |
|
1058 */ |
|
1059 |
|
1060 void CTestPrmAccTst::TestCustomSense(TInt aResourceNo) |
|
1061 { |
|
1062 test.Printf(_L("---Custom Sense")); |
|
1063 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
1064 TInt r = iTac1.Open(); |
|
1065 test_KErrNone(r); |
|
1066 r = iTac1.RegisterClient(KTestTac1); |
|
1067 test_KErrNone(r); |
|
1068 // |
|
1069 TInt state; |
|
1070 r = iTac1.GetResourceState(res.iResourceId, state); |
|
1071 test_KErrNone(r); |
|
1072 r = iTac1.ChangeResourceState(res.iResourceId, state); |
|
1073 test_KErrNone(r); |
|
1074 // |
|
1075 r = iTac1.DeRegisterClient(); |
|
1076 test_KErrNone(r); |
|
1077 iTac1.Close(); |
|
1078 test.Printf(_L("\n")); |
|
1079 } |
|
1080 |
|
1081 /* ---------------------------------------------------------------------------- |
|
1082 @SYMTestCaseID PBASE-PRMACCTST-POWERRESUMPTION-0567 |
|
1083 @SYMTestCaseDesc Ensure resources go back to their default state when not in |
|
1084 use |
|
1085 @SYMREQ REQ7751 |
|
1086 @SYMPREQ PREQ1398 |
|
1087 @SYMTestPriority High |
|
1088 @SYMTestActions |
|
1089 Pre-condition: |
|
1090 Resource not in use |
|
1091 Not a Custom Sense resource |
|
1092 For each resource: |
|
1093 1. Register TAC1 |
|
1094 2. Set resource state to something that is not the default level |
|
1095 3. De-register TAC1 |
|
1096 4. Register TOC |
|
1097 5. Get resource state |
|
1098 6. De-register TOC |
|
1099 @SYMTestExpectedResults |
|
1100 1. Client registered |
|
1101 2. Resource state changed |
|
1102 3. Client de-registered |
|
1103 4. Client registered |
|
1104 5. Resource state is at the default level |
|
1105 6. Client de-registered |
|
1106 */ |
|
1107 |
|
1108 void CTestPrmAccTst::TestDefaultPowerResumption() |
|
1109 { |
|
1110 TInt i; |
|
1111 for (i = 0; i < (TInt) iNoResources; i++) |
|
1112 { |
|
1113 TResInfo& res = *((TResInfo*) iResources.Ptr() + i); |
|
1114 test.Printf(_L("Resource %08x "), res.iResourceId); |
|
1115 TInt levelowner; |
|
1116 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
1117 test_KErrNone(r); |
|
1118 |
|
1119 // Test pre-condition: resource not in use |
|
1120 if (levelowner != KTestResourceNotInUse) |
|
1121 { |
|
1122 test.Printf(_L("Not tested (already in use)\n")); |
|
1123 continue; |
|
1124 } |
|
1125 if (res.iSense == TResInfo::ECustom) |
|
1126 { |
|
1127 test.Printf(_L("Not tested (custom sense)\n")); |
|
1128 continue; |
|
1129 } |
|
1130 |
|
1131 // Define a test value |
|
1132 TInt tstval; |
|
1133 if (res.iDefaultLevel == res.iMaxLevel) |
|
1134 { |
|
1135 tstval = res.iMinLevel; |
|
1136 } |
|
1137 else |
|
1138 { |
|
1139 tstval = res.iMaxLevel; |
|
1140 } |
|
1141 |
|
1142 // Test starts here |
|
1143 r = iTac1.Open(); |
|
1144 test_KErrNone(r); |
|
1145 r = iTac1.RegisterClient(KTestTac1); |
|
1146 test_KErrNone(r); |
|
1147 // Change resource state |
|
1148 TInt state; |
|
1149 r = iToc.GetResourceState(res.iResourceId, state); |
|
1150 test_KErrNone(r); |
|
1151 test_Equal(res.iDefaultLevel, state); |
|
1152 r = iTac1.ChangeResourceState(res.iResourceId, tstval); |
|
1153 test_KErrNone(r); |
|
1154 r = iToc.GetResourceState(res.iResourceId, state); |
|
1155 test_KErrNone(r); |
|
1156 test_Equal(tstval, state); |
|
1157 // De-register active client so resource is freed |
|
1158 r = iTac1.DeRegisterClient(); |
|
1159 test_KErrNone(r); |
|
1160 iTac1.Close(); |
|
1161 // Read both cached and actual values |
|
1162 TInt cached; |
|
1163 r = iToc.GetResourceStateCached(res.iResourceId, cached); |
|
1164 test_KErrNone(r); |
|
1165 r = iToc.GetResourceState(res.iResourceId, state); |
|
1166 test_KErrNone(r); |
|
1167 test_Equal(cached, state); |
|
1168 test_Equal(res.iDefaultLevel, state); |
|
1169 test.Printf(_L("\n")); |
|
1170 } |
|
1171 // |
|
1172 test.Printf(_L("\n")); |
|
1173 } |
|
1174 |
|
1175 /* ---------------------------------------------------------------------------- |
|
1176 @SYMTestCaseID PBASE-PRMACCTST-DEPENDENCIESDECLARED-0568 |
|
1177 @SYMTestCaseDesc Ensure all actual resources dependencies have been declared |
|
1178 @SYMREQ REQ7751 |
|
1179 @SYMPREQ PREQ1398 |
|
1180 @SYMTestPriority High |
|
1181 @SYMTestActions |
|
1182 Pre-condition: |
|
1183 Resource not in use |
|
1184 Not a Custom Sense resource |
|
1185 For each resource: |
|
1186 1. Register TOC & TAC1 |
|
1187 2. Get state of all resources |
|
1188 3. Set the state of the resource under test state to something that is not |
|
1189 the default level |
|
1190 4. Get state of all resource |
|
1191 5. De-register TAC1 & TOC |
|
1192 @SYMTestExpectedResults |
|
1193 1. Clients registered |
|
1194 2. None |
|
1195 3. Resource state changed |
|
1196 4. Only resources with a direct or indirect dependency on the resource |
|
1197 under test have changed. |
|
1198 5. Client de-registered |
|
1199 */ |
|
1200 |
|
1201 TBool CTestPrmAccTst::ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget) |
|
1202 { |
|
1203 // Get Reference on current resource node |
|
1204 TBool r = EFalse; |
|
1205 if (aCurrentResourceId & KTestIdHasDependencies) |
|
1206 { |
|
1207 // Get dependencies of current resources |
|
1208 RBuf8 deplist; |
|
1209 deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies); |
|
1210 r = iToc.GetResourceDependencies(aCurrentResourceId, deplist); |
|
1211 if (r) |
|
1212 { |
|
1213 test.Printf(_L("ERROR: aCurrentResourceId==%08x"), aCurrentResourceId); |
|
1214 test_KErrNone(r); |
|
1215 } |
|
1216 TInt i; |
|
1217 SResDepInfo *ptr = (SResDepInfo*)deplist.Ptr(); |
|
1218 for (i = 0; i < (TInt) (deplist.Length() / sizeof(SResDepInfo)); i++, ptr++) |
|
1219 { |
|
1220 TInt depid = ptr->iResourceId; |
|
1221 if (depid == aResourceIdTarget) |
|
1222 { |
|
1223 // We've got a match |
|
1224 r = ETrue; |
|
1225 } |
|
1226 else if (depid == aResourceIdOrig) |
|
1227 { |
|
1228 // No going back to parent node |
|
1229 continue; |
|
1230 } |
|
1231 else |
|
1232 { |
|
1233 // Recurse down the tree |
|
1234 r = ResourceInterdependency(aCurrentResourceId, depid, aResourceIdTarget); |
|
1235 } |
|
1236 if (r) |
|
1237 { |
|
1238 break; |
|
1239 } |
|
1240 } |
|
1241 deplist.Close(); |
|
1242 } |
|
1243 return r; |
|
1244 } |
|
1245 |
|
1246 void CTestPrmAccTst::TestDependenciesAreDeclared(TInt aResourceNo) |
|
1247 { |
|
1248 test.Printf(_L("---Test all dependencies are declared\n")); |
|
1249 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); |
|
1250 // |
|
1251 TInt levelowner; |
|
1252 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); |
|
1253 test_KErrNone(r); |
|
1254 // Test pre-condition: resource not in use |
|
1255 if (levelowner != KTestResourceNotInUse) |
|
1256 { |
|
1257 test.Printf(_L("Not tested (already in use)\n")); |
|
1258 return; |
|
1259 } |
|
1260 if (res.iSense == TResInfo::ECustom) |
|
1261 { |
|
1262 test.Printf(_L("Not tested (custom sense)\n")); |
|
1263 return; |
|
1264 } |
|
1265 // Define a test value |
|
1266 TInt tstval; |
|
1267 if (res.iDefaultLevel == res.iMaxLevel) |
|
1268 { |
|
1269 tstval = res.iMinLevel; |
|
1270 } |
|
1271 else |
|
1272 { |
|
1273 tstval = res.iMaxLevel; |
|
1274 } |
|
1275 |
|
1276 // Test starts here |
|
1277 // Save current state of all resources; |
|
1278 RArray<TInt> oldstate; |
|
1279 TInt i; |
|
1280 TInt state; |
|
1281 for (i = 0; i < (TInt) iNoResources; i++) |
|
1282 { |
|
1283 TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i); |
|
1284 r = iToc.GetResourceState(tmpres.iResourceId, state); |
|
1285 test_KErrNone(r); |
|
1286 r = oldstate.Append(state); |
|
1287 test_KErrNone(r); |
|
1288 } |
|
1289 // |
|
1290 r = iTac1.Open(); |
|
1291 test_KErrNone(r); |
|
1292 r = iTac1.RegisterClient(KTestTac1); |
|
1293 test_KErrNone(r); |
|
1294 |
|
1295 // Change resource state |
|
1296 r = iToc.GetResourceState(res.iResourceId, state); |
|
1297 test_KErrNone(r); |
|
1298 test_Equal(res.iDefaultLevel, state); |
|
1299 r = iTac1.ChangeResourceState(res.iResourceId, tstval); |
|
1300 test_KErrNone(r); |
|
1301 r = iToc.GetResourceState(res.iResourceId, state); |
|
1302 test_KErrNone(r); |
|
1303 test_Equal(tstval, state); |
|
1304 |
|
1305 // Now we check that resources with no dependency on resource under test |
|
1306 // have not changed |
|
1307 for (i = 0; i < (TInt) iNoResources; i++) |
|
1308 { |
|
1309 test.Printf(_L(".")); |
|
1310 if (i == aResourceNo) |
|
1311 { |
|
1312 continue; |
|
1313 } |
|
1314 TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i); |
|
1315 r = iToc.GetResourceState(tmpres.iResourceId, state); |
|
1316 test_KErrNone(r); |
|
1317 if (!ResourceInterdependency(0, res.iResourceId, tmpres.iResourceId) && |
|
1318 (state != oldstate[i])) |
|
1319 { |
|
1320 test.Printf(_L("Resource %08x has changed!\n"), tmpres.iResourceId); |
|
1321 test_Equal(state, oldstate[i]); |
|
1322 } |
|
1323 } |
|
1324 test.Printf(_L("\n")); |
|
1325 |
|
1326 // De-register active client |
|
1327 r = iTac1.DeRegisterClient(); |
|
1328 test_KErrNone(r); |
|
1329 iTac1.Close(); |
|
1330 // |
|
1331 oldstate.Close(); |
|
1332 } |
|
1333 |
|
1334 TInt CTestPrmAccTst::DoTestPreamble() |
|
1335 { |
|
1336 test.Title(); |
|
1337 test.Start(_L("Preamble")); |
|
1338 |
|
1339 // Load Device Driver |
|
1340 TInt r; |
|
1341 #ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
1342 test.Printf(_L("Load Simulated PSL PDD\n")); |
|
1343 r = User::LoadPhysicalDevice(_L("RESOURCECONTROLLEREXTENDED.PDD")); |
|
1344 if (r == KErrNotFound) |
|
1345 { |
|
1346 test.Printf(_L("RESOURCECONTROLLEREXTENDED.PDD not found\nTest skipped\n")); |
|
1347 return r; |
|
1348 } |
|
1349 if (r) |
|
1350 { |
|
1351 test_Equal(KErrAlreadyExists, r); |
|
1352 test.Printf(_L("Already loaded\n")); |
|
1353 } |
|
1354 test.Printf(_L("Load test LDD\n")); |
|
1355 r = User::LoadLogicalDevice(_L("D_PRMACCTSTSIM.LDD")); |
|
1356 if (r) |
|
1357 { |
|
1358 test_Equal(KErrAlreadyExists, r); |
|
1359 test.Printf(_L("Already loaded\n")); |
|
1360 } |
|
1361 #else |
|
1362 test.Printf(_L("Load test LDD\n")); |
|
1363 r = User::LoadLogicalDevice(_L("D_PRMACCTST.LDD")); |
|
1364 if (r) |
|
1365 { |
|
1366 test_Equal(KErrAlreadyExists, r); |
|
1367 test.Printf(_L("Already loaded\n")); |
|
1368 } |
|
1369 #endif // RESOURCE_MANAGER_SIMULATED_PSL |
|
1370 |
|
1371 // Check if Device Driver was loaded as a Kernel Extension |
|
1372 iKextc.Open(); |
|
1373 TUint clientId; |
|
1374 r = iKextc.GetKernelExtClientId(clientId); |
|
1375 test_KErrNone(r); |
|
1376 if (!clientId) |
|
1377 { |
|
1378 test.Printf(_L("No Kernel extension PRM client\n")); |
|
1379 iKextc.Close(); |
|
1380 } |
|
1381 else |
|
1382 { |
|
1383 // De-register client so Single User resources can be tested |
|
1384 r = iKextc.OpenClient(clientId); |
|
1385 test_KErrNone(r); |
|
1386 r = iKextc.DeRegisterClient(); |
|
1387 test_KErrNone(r); |
|
1388 iKextc.Close(); |
|
1389 } |
|
1390 |
|
1391 // Register TOC (always on - de-registered in test postamble) |
|
1392 r = iToc.Open(); |
|
1393 test_KErrNone(r); |
|
1394 r = iToc.RegisterClient(KTestToc); |
|
1395 test_KErrNone(r); |
|
1396 |
|
1397 // Get resources info |
|
1398 r = iToc.GetTotalNumberOfResources(iNoResources); |
|
1399 test_KErrNone(r); |
|
1400 test.Printf(_L("Resources found: %d\n"), iNoResources); |
|
1401 if (iNoResources > 0) |
|
1402 { |
|
1403 r = iResources.Create(iNoResources * sizeof(TResInfo)); |
|
1404 test_KErrNone(r); |
|
1405 test.Printf(_L("Retrieving information on resources\n")); |
|
1406 r = iToc.GetInfoOnResourcesInUseByClient(0, iResources); |
|
1407 test_KErrNone(r); |
|
1408 iIsPrmSupported = ETrue; |
|
1409 } |
|
1410 else |
|
1411 { |
|
1412 test.Printf(_L("No resource found.\n")); |
|
1413 } |
|
1414 return KErrNone; |
|
1415 } |
|
1416 |
|
1417 void CTestPrmAccTst::DoTest() |
|
1418 { |
|
1419 if (!iIsPrmSupported) |
|
1420 { |
|
1421 return; |
|
1422 } |
|
1423 // |
|
1424 test.Next(_L("Enumerate Resources")); |
|
1425 TestEnumerateResources(); |
|
1426 // |
|
1427 TInt i; |
|
1428 test.Next(_L("Resource Properties")); |
|
1429 for (i = 0; i < (TInt) iNoResources; i++) |
|
1430 { |
|
1431 TResInfo& res = *((TResInfo*) iResources.Ptr() + i); |
|
1432 test.Printf(_L("+++Resource %08x\n"), res.iResourceId); |
|
1433 // |
|
1434 if (res.iUsage == TResInfo::ESingleUse) |
|
1435 { |
|
1436 TestSingleUserResources(i); |
|
1437 } |
|
1438 else if (res.iUsage == TResInfo::EShared) |
|
1439 { |
|
1440 TestSharedResources(i); |
|
1441 } |
|
1442 // |
|
1443 if (res.iType == TResInfo::EBinary) |
|
1444 { |
|
1445 TestBinaryResources(i); |
|
1446 } |
|
1447 else if (res.iType == TResInfo::EMultiLevel) |
|
1448 { |
|
1449 TestMultilevelResources(i); |
|
1450 } |
|
1451 // |
|
1452 TestLatency(i); |
|
1453 // |
|
1454 if ((res.iSense == TResInfo::EPositive) || (res.iSense == TResInfo::ENegative)) |
|
1455 { |
|
1456 TestSense(i); |
|
1457 } |
|
1458 else if (res.iSense == TResInfo::ECustom) |
|
1459 { |
|
1460 TestCustomSense(i); |
|
1461 } |
|
1462 } |
|
1463 // |
|
1464 test.Next(_L("Default Power Resumption")); |
|
1465 TestDefaultPowerResumption(); |
|
1466 // |
|
1467 test.Next(_L("PRM Extension - Dependencies")); |
|
1468 for (i = 0; i < (TInt) iNoResources; i++) |
|
1469 { |
|
1470 TResInfo& res = *((TResInfo*) iResources.Ptr() + i); |
|
1471 if (res.iResourceId & KTestIdHasDependencies) |
|
1472 { |
|
1473 test.Printf(_L("+++Resource %08x\n"), res.iResourceId); |
|
1474 TestDependenciesAreDeclared(i); |
|
1475 } |
|
1476 } |
|
1477 } |
|
1478 |
|
1479 void CTestPrmAccTst::DoTestPostamble() |
|
1480 { |
|
1481 test.Next(_L("Postamble")); |
|
1482 if (iToc.Handle()) |
|
1483 { |
|
1484 TInt r = iToc.DeRegisterClient(); |
|
1485 test_KErrNone(r); |
|
1486 iToc.Close(); |
|
1487 } |
|
1488 test.End(); |
|
1489 test.Close(); |
|
1490 } |
|
1491 |
|
1492 GLDEF_C TInt MainL() |
|
1493 { |
|
1494 CTestPrmAccTst* testapp; |
|
1495 testapp = new (ELeave) CTestPrmAccTst(); |
|
1496 CleanupStack::PushL(testapp); |
|
1497 if (testapp->DoTestPreamble() == KErrNone) |
|
1498 { |
|
1499 testapp->DoTest(); |
|
1500 } |
|
1501 testapp->DoTestPostamble(); |
|
1502 CleanupStack::PopAndDestroy(testapp); |
|
1503 return KErrNone; |
|
1504 } |
|
1505 |
|
1506 GLDEF_C TInt E32Main() |
|
1507 { |
|
1508 __UHEAP_MARK; |
|
1509 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
1510 if(cleanup == NULL) |
|
1511 { |
|
1512 return KErrNoMemory; |
|
1513 } |
|
1514 TRAP_IGNORE(MainL()); |
|
1515 delete cleanup; |
|
1516 __UHEAP_MARKEND; |
|
1517 return KErrNone; |
|
1518 } |