|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Example CTestStep derived implementation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file NoMemoryStep.cpp |
|
20 @internalTechnology |
|
21 */ |
|
22 #include "nomemorystep.h" |
|
23 #include "te_lbsapisuitedefs.h" |
|
24 |
|
25 #include "lcfsbucommondefinitions.h" |
|
26 |
|
27 #include <lbs.h> |
|
28 #include <lbssatellite.h> |
|
29 |
|
30 #include <s32mem.h> |
|
31 |
|
32 CNoMemoryStep::~CNoMemoryStep() |
|
33 /** |
|
34 * Destructor |
|
35 */ |
|
36 { |
|
37 } |
|
38 |
|
39 CNoMemoryStep::CNoMemoryStep() |
|
40 /** |
|
41 * Constructor |
|
42 */ |
|
43 { |
|
44 // **MUST** call SetTestStepName in the constructor as the controlling |
|
45 // framework uses the test step name immediately following construction to set |
|
46 // up the step's unique logging ID. |
|
47 SetTestStepName(KNoMemoryStep); |
|
48 } |
|
49 |
|
50 TVerdict CNoMemoryStep::doTestStepPreambleL() |
|
51 /** |
|
52 * @return - TVerdict code |
|
53 * Override of base class virtual |
|
54 */ |
|
55 { |
|
56 CTe_LbsApiSuiteStepBase::doTestStepPreambleL(); |
|
57 if (TestStepResult()!=EPass) |
|
58 return TestStepResult(); |
|
59 // process some pre setting to this test step then set SetTestStepResult to EFail or Epass. |
|
60 SetTestStepResult(EPass); |
|
61 return TestStepResult(); |
|
62 } |
|
63 |
|
64 |
|
65 TVerdict CNoMemoryStep::doTestStepL() |
|
66 /** |
|
67 * @return - TVerdict code |
|
68 * Override of base class pure virtual |
|
69 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
70 * not leave. That being the case, the current test result value will be EPass. |
|
71 */ |
|
72 { |
|
73 if (TestStepResult()==EPass) |
|
74 { |
|
75 TInt test; |
|
76 if(!GetIntFromConfig(ConfigSection(),KTe_LbsApiSuiteInt,test)) |
|
77 { |
|
78 // Leave if there's any error. |
|
79 User::Leave(KErrNotFound); |
|
80 } |
|
81 SetTestStepResult(EPass); |
|
82 StartL(test); |
|
83 } |
|
84 return TestStepResult(); |
|
85 } |
|
86 |
|
87 |
|
88 |
|
89 TVerdict CNoMemoryStep::doTestStepPostambleL() |
|
90 /** |
|
91 * @return - TVerdict code |
|
92 * Override of base class virtual |
|
93 */ |
|
94 { |
|
95 // process something post setting to the test step |
|
96 // uncomment the following line if you have common post setting to all the test steps in there |
|
97 // CTe_LbsApiSuiteStepBase::doTestStepPostambleL(); |
|
98 // uncomment the following line if you have post process or remove the following line if no post process |
|
99 // SetTestStepResult(EPass); // or EFail |
|
100 return TestStepResult(); |
|
101 } |
|
102 |
|
103 void CNoMemoryStep::StartL (TInt aIndex) |
|
104 { |
|
105 switch (aIndex) |
|
106 { |
|
107 case 0: |
|
108 OOM_RPositionServer_Open_NoMemoryL (); |
|
109 break; |
|
110 case 1: |
|
111 OOM_RPositioner_OpenL (); |
|
112 break; |
|
113 case 2: |
|
114 OOM_RPositioner_SetRequestorL (); |
|
115 break; |
|
116 case 3: |
|
117 OOM_CRequestor_ConstructionL (); |
|
118 break; |
|
119 case 4: |
|
120 OOM_CRequestor_SetRequestorL (); |
|
121 break; |
|
122 case 5: |
|
123 OOM_CRequestor_StreamingL (); |
|
124 break; |
|
125 case 6: |
|
126 OOM_RRequestorStack_StreamingL (); |
|
127 break; |
|
128 case 7: |
|
129 OOM_HPositionGenericInfo_ConstructionL (); |
|
130 break; |
|
131 default: |
|
132 break; |
|
133 } |
|
134 } |
|
135 |
|
136 |
|
137 #define DO_OOM_CUSTOMISED_LOOP(aType, aCreationCode, aDeletionCode, aLoopStartCode, aLoopEndCode) \ |
|
138 { \ |
|
139 aType; \ |
|
140 TInt failureRate; \ |
|
141 TBool doContinue = ETrue; \ |
|
142 for (failureRate = 1; doContinue; failureRate++) \ |
|
143 { \ |
|
144 aLoopStartCode; \ |
|
145 __UHEAP_SETFAIL(RHeap::EFailNext, failureRate); \ |
|
146 __UHEAP_MARK; \ |
|
147 \ |
|
148 TInt err; \ |
|
149 TRAP(err, aCreationCode); \ |
|
150 if (err != KErrNoMemory) \ |
|
151 { \ |
|
152 aDeletionCode; \ |
|
153 doContinue = EFalse; \ |
|
154 } \ |
|
155 \ |
|
156 __UHEAP_MARKEND; \ |
|
157 __UHEAP_RESET; \ |
|
158 aLoopEndCode; \ |
|
159 } \ |
|
160 CHECK( failureRate > 2 ); \ |
|
161 message.Format(_L("Checked %d allocations in \"%s\""), failureRate-2, L## #aCreationCode); \ |
|
162 LOG_DES(message); \ |
|
163 } |
|
164 |
|
165 |
|
166 #define DO_OOM(aType, aCreationCode, aDeletionCode) \ |
|
167 DO_OOM_CUSTOMISED_LOOP(aType, aCreationCode, aDeletionCode, (void) 0, (void) 0) |
|
168 |
|
169 |
|
170 // |
|
171 // |
|
172 // RPositionServer |
|
173 // |
|
174 // |
|
175 |
|
176 //1.1.6 Connect with No Memory |
|
177 void CNoMemoryStep::OOM_RPositionServer_Open_NoMemoryL() |
|
178 { |
|
179 DECLARE_ERROR_LOGGING; |
|
180 StandardPrepareL(); |
|
181 |
|
182 RPositionServer server; |
|
183 |
|
184 // connect |
|
185 __UHEAP_SETFAIL(RHeap::EFailNext, 1); |
|
186 __UHEAP_MARK; |
|
187 CHECK_EQUAL_(KErrNoMemory, server.Connect()); |
|
188 __UHEAP_MARKEND; |
|
189 __UHEAP_RESET; |
|
190 |
|
191 StandardCleanup(); |
|
192 } |
|
193 |
|
194 |
|
195 // |
|
196 // |
|
197 // RPositioner |
|
198 // |
|
199 // |
|
200 |
|
201 //1.10.7 Open with No Memory |
|
202 void CNoMemoryStep::OOM_RPositioner_OpenL() |
|
203 { |
|
204 DECLARE_ERROR_LOGGING; |
|
205 StandardPrepareL(); |
|
206 |
|
207 RPositionServer server; |
|
208 User::LeaveIfError(server.Connect()); |
|
209 CleanupClosePushL(server); |
|
210 |
|
211 RPositioner positioner; |
|
212 |
|
213 // open by default |
|
214 __UHEAP_SETFAIL(RHeap::EFailNext, 1); |
|
215 __UHEAP_MARK; |
|
216 CHECK_EQUAL_(KErrNoMemory, positioner.Open(server)); |
|
217 __UHEAP_MARKEND; |
|
218 __UHEAP_RESET; |
|
219 |
|
220 // by module id |
|
221 TPositionModuleId moduleId; |
|
222 server.GetDefaultModuleId(moduleId); |
|
223 __UHEAP_SETFAIL(RHeap::EFailNext, 1); |
|
224 __UHEAP_MARK; |
|
225 CHECK_EQUAL_(KErrNoMemory, positioner.Open(server, moduleId)); |
|
226 __UHEAP_MARKEND; |
|
227 __UHEAP_RESET; |
|
228 |
|
229 // by criteria |
|
230 TPositionCriteria criteria; |
|
231 criteria.ResetCriteria(); // defaults |
|
232 __UHEAP_SETFAIL(RHeap::EFailNext, 1); |
|
233 __UHEAP_MARK; |
|
234 CHECK_EQUAL_(KErrNoMemory, positioner.Open(server, criteria)); |
|
235 __UHEAP_MARKEND; |
|
236 __UHEAP_RESET; |
|
237 |
|
238 CleanupStack::PopAndDestroy(); |
|
239 |
|
240 StandardCleanup(); |
|
241 } |
|
242 |
|
243 |
|
244 //1.13.5 SetRequestor Stack with No Memory |
|
245 void CNoMemoryStep::OOM_RPositioner_SetRequestorL() |
|
246 { |
|
247 DECLARE_ERROR_LOGGING; |
|
248 StandardPrepareL(); |
|
249 |
|
250 RPositionServer server; |
|
251 User::LeaveIfError(server.Connect()); |
|
252 CleanupClosePushL(server); |
|
253 |
|
254 RPositioner positioner; |
|
255 CHECK_EQUAL_(KErrNone, positioner.Open(server)); |
|
256 CleanupClosePushL(positioner); |
|
257 |
|
258 RRequestorStack stack; |
|
259 CRequestor* requestor = NULL; |
|
260 |
|
261 // All Accepted |
|
262 requestor = CRequestor::NewLC( |
|
263 CRequestor::ERequestorContact, |
|
264 DUMMY_REQUESTOR_FORMAT_ACCEPTED2, |
|
265 DUMMY_REQUESTOR_NAME_ACCEPTED2); |
|
266 stack.Append(requestor); |
|
267 requestor = CRequestor::NewLC( |
|
268 CRequestor::ERequestorService, |
|
269 DUMMY_REQUESTOR_FORMAT_ACCEPTED1, |
|
270 DUMMY_REQUESTOR_NAME_ACCEPTED1); |
|
271 stack.Append(requestor); |
|
272 |
|
273 // set requestor stack |
|
274 __UHEAP_SETFAIL(RHeap::EFailNext, 1); |
|
275 __UHEAP_MARK; |
|
276 |
|
277 CHECK_EQUAL_(KErrNoMemory, positioner.SetRequestor(stack)); |
|
278 CHECK_EQUAL_(KErrNone, positioner.SetRequestor(stack)); |
|
279 |
|
280 __UHEAP_MARKEND; |
|
281 __UHEAP_RESET; |
|
282 |
|
283 CleanupStack::Pop(2); // requestors |
|
284 CleanupStack::PopAndDestroy(2); // server & positioner |
|
285 stack.ResetAndDestroy(); |
|
286 |
|
287 StandardCleanup(); |
|
288 } |
|
289 |
|
290 |
|
291 // |
|
292 // |
|
293 // CRequestor |
|
294 // |
|
295 // |
|
296 |
|
297 // 8.2.4. Constructors with No Memory |
|
298 void CNoMemoryStep::OOM_CRequestor_ConstructionL() |
|
299 { |
|
300 DECLARE_ERROR_LOGGING; |
|
301 StandardPrepareL(); |
|
302 |
|
303 _LIT(KRequestorData, "+441223719800"); |
|
304 |
|
305 // New |
|
306 CRequestor* requestor = NULL; |
|
307 TBool doContinue = ETrue; |
|
308 TInt failureRate = 0; |
|
309 |
|
310 for (failureRate = 1; doContinue; failureRate++) |
|
311 { |
|
312 __UHEAP_SETFAIL(RHeap::EFailNext, failureRate); |
|
313 __UHEAP_MARK; |
|
314 |
|
315 TInt err; |
|
316 TRAP(err, |
|
317 User::LeaveIfNull(requestor = |
|
318 CRequestor::New(CRequestor::ERequestorContact, |
|
319 CRequestor::EFormatTelephone, |
|
320 KRequestorData)); |
|
321 ); |
|
322 |
|
323 if (err != KErrNoMemory) |
|
324 { |
|
325 delete requestor; |
|
326 doContinue = EFalse; |
|
327 } |
|
328 |
|
329 __UHEAP_MARKEND; |
|
330 __UHEAP_RESET; |
|
331 } |
|
332 CHECK( failureRate > 2 ); |
|
333 message.Format(_L("Checked %d allocations in \"New\""), failureRate-2); |
|
334 LOG_DES(message); |
|
335 |
|
336 // NewL |
|
337 doContinue = ETrue; |
|
338 for (failureRate = 1; doContinue; failureRate++) |
|
339 { |
|
340 __UHEAP_SETFAIL(RHeap::EFailNext, failureRate); |
|
341 __UHEAP_MARK; |
|
342 |
|
343 TInt err; |
|
344 TRAP(err, |
|
345 requestor = CRequestor::NewL(CRequestor::ERequestorContact, |
|
346 CRequestor::EFormatTelephone, |
|
347 KRequestorData); |
|
348 ); |
|
349 |
|
350 if (err != KErrNoMemory) |
|
351 { |
|
352 delete requestor; |
|
353 doContinue = EFalse; |
|
354 } |
|
355 |
|
356 __UHEAP_MARKEND; |
|
357 __UHEAP_RESET; |
|
358 } |
|
359 CHECK( failureRate > 2 ); |
|
360 message.Format(_L("Checked %d allocations in \"NewL\""), failureRate-2); |
|
361 LOG_DES(message); |
|
362 |
|
363 // NewLC |
|
364 doContinue = ETrue; |
|
365 for (failureRate = 1; doContinue; failureRate++) |
|
366 { |
|
367 __UHEAP_SETFAIL(RHeap::EFailNext, failureRate); |
|
368 __UHEAP_MARK; |
|
369 |
|
370 TInt err; |
|
371 TRAP(err, |
|
372 requestor = CRequestor::NewLC(CRequestor::ERequestorContact, |
|
373 CRequestor::EFormatTelephone, |
|
374 KRequestorData); |
|
375 CleanupStack::Pop(requestor); |
|
376 ); |
|
377 |
|
378 if (err != KErrNoMemory) |
|
379 { |
|
380 delete requestor; |
|
381 doContinue = EFalse; |
|
382 } |
|
383 |
|
384 __UHEAP_MARKEND; |
|
385 __UHEAP_RESET; |
|
386 } |
|
387 CHECK( failureRate > 2 ); |
|
388 message.Format(_L("Checked %d allocations in \"NewLC\""), failureRate-2); |
|
389 LOG_DES(message); |
|
390 |
|
391 StandardCleanup(); |
|
392 } |
|
393 |
|
394 |
|
395 // 8.2.5. SetRequestor with No Memory |
|
396 void CNoMemoryStep::OOM_CRequestor_SetRequestorL() |
|
397 { |
|
398 DECLARE_ERROR_LOGGING; |
|
399 StandardPrepareL(); |
|
400 |
|
401 _LIT(KRequestorData, "+441223719800"); |
|
402 _LIT(KRequestorData2, "+44122371980101"); |
|
403 |
|
404 // NOTE, this is a special case where the CRequestor is created at the start, then |
|
405 // its member data is replaced (which is tested under OOM conditions). |
|
406 DO_OOM( |
|
407 CRequestor* requestor = CRequestor::NewLC(CRequestor::ERequestorContact, CRequestor::EFormatTelephone, KRequestorData), |
|
408 requestor->SetRequestorL(CRequestor::ERequestorContact, CRequestor::EFormatTelephone, KRequestorData2), |
|
409 CleanupStack::PopAndDestroy(requestor) |
|
410 ); |
|
411 |
|
412 StandardCleanup(); |
|
413 } |
|
414 |
|
415 |
|
416 // 8.3.3. Streaming with NoMemory |
|
417 void CNoMemoryStep::OOM_CRequestor_StreamingL() |
|
418 { |
|
419 DECLARE_ERROR_LOGGING; |
|
420 StandardPrepareL(); |
|
421 |
|
422 _LIT(KRequestorData, "+441223719800"); |
|
423 CRequestor* requestor = NULL; |
|
424 |
|
425 requestor = CRequestor::NewLC(CRequestor::ERequestorContact, CRequestor::EFormatTelephone, KRequestorData); |
|
426 TBuf8<100> buffer; |
|
427 RDesWriteStream writeStrm(buffer); |
|
428 CleanupClosePushL(writeStrm); |
|
429 TInt err; |
|
430 TRAP(err, writeStrm << *requestor); |
|
431 CleanupStack::PopAndDestroy(&writeStrm); |
|
432 |
|
433 // Internalize |
|
434 DO_OOM_CUSTOMISED_LOOP |
|
435 ( |
|
436 (void) 0, |
|
437 strm >> *requestor, |
|
438 delete requestor, |
|
439 RDesReadStream strm(buffer); CleanupClosePushL(strm), |
|
440 CleanupStack::PopAndDestroy(&strm) |
|
441 ); |
|
442 |
|
443 CleanupStack::Pop(requestor); |
|
444 |
|
445 // Construction |
|
446 DO_OOM_CUSTOMISED_LOOP |
|
447 ( |
|
448 (void) 0, |
|
449 requestor = CRequestor::NewL(strm), |
|
450 delete requestor, |
|
451 RDesReadStream strm(buffer); CleanupClosePushL(strm), |
|
452 CleanupStack::PopAndDestroy(&strm) |
|
453 ); |
|
454 |
|
455 StandardCleanup(); |
|
456 } |
|
457 |
|
458 |
|
459 // |
|
460 // |
|
461 // RRequestorStack |
|
462 // |
|
463 // |
|
464 |
|
465 void CleanupResetAndDestroy(TAny* aArray) |
|
466 { |
|
467 reinterpret_cast<RRequestorStack*>(aArray)->ResetAndDestroy(); |
|
468 } |
|
469 |
|
470 |
|
471 // 8.1.3. Streaming with No Memory |
|
472 void CNoMemoryStep::OOM_RRequestorStack_StreamingL() |
|
473 { |
|
474 DECLARE_ERROR_LOGGING; |
|
475 StandardPrepareL(); |
|
476 |
|
477 _LIT(KRequestorData, "+441223719800"); |
|
478 const TInt KNumberOfRequestors = 3; |
|
479 RRequestorStack stack; |
|
480 CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy, &stack)); |
|
481 TInt i; |
|
482 for (i = 0; i < KNumberOfRequestors; i++) |
|
483 User::LeaveIfError(stack.Append(NULL)); |
|
484 for (i = 0; i < KNumberOfRequestors; i++) |
|
485 stack[i] = CRequestor::NewL(CRequestor::ERequestorContact, CRequestor::EFormatTelephone, KRequestorData); |
|
486 |
|
487 TBuf8<100> buffer; |
|
488 RDesWriteStream writeStrm(buffer); |
|
489 CleanupClosePushL(writeStrm); |
|
490 TInt err; |
|
491 TRAP(err, writeStrm << stack); |
|
492 CleanupStack::PopAndDestroy(&writeStrm); |
|
493 |
|
494 CleanupStack::PopAndDestroy(&stack); |
|
495 CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy, &stack)); |
|
496 |
|
497 DO_OOM_CUSTOMISED_LOOP |
|
498 ( |
|
499 (void) 0, |
|
500 strm >> stack, |
|
501 stack.ResetAndDestroy(), |
|
502 RDesReadStream strm(buffer); CleanupClosePushL(strm), |
|
503 CleanupStack::PopAndDestroy(&strm) |
|
504 ); |
|
505 |
|
506 CleanupStack::Pop(&stack); |
|
507 |
|
508 StandardCleanup(); |
|
509 } |
|
510 |
|
511 |
|
512 // |
|
513 // |
|
514 // HPositionGenericInfo |
|
515 // |
|
516 // |
|
517 |
|
518 // 3.2.2. NoMemory Construction |
|
519 void CNoMemoryStep::OOM_HPositionGenericInfo_ConstructionL() |
|
520 { |
|
521 DECLARE_ERROR_LOGGING; |
|
522 StandardPrepareL(); |
|
523 |
|
524 // New |
|
525 DO_OOM |
|
526 ( |
|
527 HPositionGenericInfo* genInfo = NULL, |
|
528 User::LeaveIfNull(genInfo = HPositionGenericInfo::New(10)), |
|
529 delete genInfo |
|
530 ); |
|
531 // NewL |
|
532 DO_OOM |
|
533 ( |
|
534 HPositionGenericInfo* genInfo = NULL, |
|
535 genInfo = HPositionGenericInfo::NewL(10), |
|
536 delete genInfo |
|
537 ); |
|
538 // NewLC |
|
539 DO_OOM |
|
540 ( |
|
541 HPositionGenericInfo* genInfo = NULL, |
|
542 genInfo = HPositionGenericInfo::NewLC(10); |
|
543 CleanupStack::Pop(genInfo), |
|
544 delete genInfo |
|
545 ); |
|
546 |
|
547 StandardCleanup(); |
|
548 } |
|
549 |