|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 #include "TransactionsStep.h" |
|
22 #include "PerformanceFunctionalityDefs.h" |
|
23 |
|
24 _LIT(KVcardFile,"c:\\ExportedContacts.vcf"); |
|
25 const TInt KTransactionSize = 16;//number of crud operations performed within a transaction |
|
26 |
|
27 //number of contacts used by transaction performance |
|
28 const TInt KMinContacts = 10; |
|
29 const TInt KMidContacts = 100; |
|
30 const TInt KManyContacts = 300; |
|
31 const TInt KMaxContacts = 1000; |
|
32 |
|
33 const TInt KPerfIter = 1;//number of times performance tests are repeated to get a more accurate average |
|
34 const TInt KMediumFields = 10;//number of fields to use when a contact is partially filled |
|
35 const TInt KManyFields = 69;//number of (template-derived) fields in a Contact Item |
|
36 |
|
37 _LIT(KRun1,"Nested"); |
|
38 _LIT(KRun2,"EmptyCommit"); |
|
39 _LIT(KRun3,"EmptyRevert"); |
|
40 _LIT(KRun4,"UpdateCommit"); |
|
41 _LIT(KRun5,"UpdateRevert"); |
|
42 _LIT(KRun6,"CreateCommit"); |
|
43 _LIT(KRun7,"CreatRevert"); |
|
44 _LIT(KRun8,"DeleteCommit"); |
|
45 _LIT(KRun9,"DeleteRevert"); |
|
46 _LIT(KRun10,"CudCommit"); |
|
47 _LIT(KRun11,"CudRevert"); |
|
48 _LIT(KRun12,"EmptyPerfomance"); |
|
49 _LIT(KRun13,"EmptyEmptyPerformance"); |
|
50 _LIT(KRun14,"MediumPerformance"); |
|
51 _LIT(KRun15,"MediumEmptyPerformance"); |
|
52 _LIT(KRun16,"FullPerformance"); |
|
53 _LIT(KRun17,"FullEmptyPerformance"); |
|
54 _LIT(KRun18,"MultipleCommit"); |
|
55 _LIT(KRun19,"TransactionMultiple"); |
|
56 |
|
57 _LIT(KTest1, "Nested Transaction tests"); |
|
58 _LIT(KTest2, "Empty; Commit Transaction tests"); |
|
59 _LIT(KTest3, "Empty; Revert Transaction tests"); |
|
60 _LIT(KTest4, "Update; Commit Transaction tests"); |
|
61 _LIT(KTest5, "Update; Revert Transaction tests"); |
|
62 _LIT(KTest6, "Create; Commit Transaction tests"); |
|
63 _LIT(KTest7, "Create; Revert Transaction tests"); |
|
64 _LIT(KTest8, "Delete; Commit Transaction tests"); |
|
65 _LIT(KTest9, "Delete; Revert Transaction tests"); |
|
66 _LIT(KTest10, "Many CUD; Commit Transaction tests"); |
|
67 _LIT(KTest11, "Many CUD; Revert Transaction tests"); |
|
68 _LIT(KTest12, "***Empty fields; Performance Transaction tests***"); |
|
69 _LIT(KTest13, "***Empty fields, Empty DB; Performance Transaction tests***"); |
|
70 _LIT(KTest14, "***Medium fields; Performance Transaction tests***"); |
|
71 _LIT(KTest15, "***Medium fields, Empty DB; Performance Transaction tests***"); |
|
72 _LIT(KTest16, "***Full fields; Performance Transaction tests***"); |
|
73 _LIT(KTest17, "***Full fields, Empty DB; Performance Transaction tests***"); |
|
74 _LIT(KTest18, "Multiple commit test"); |
|
75 _LIT(KTest19, "Transaction Multiple commit test"); |
|
76 |
|
77 //number of contacts used by this test step |
|
78 #define KNumberOfContacts 10 |
|
79 |
|
80 #ifdef __WINSCW__ |
|
81 #define KMaxTimeAllowed 500 //seconds, minimum performance |
|
82 #else |
|
83 #define KMaxTimeAllowed 10000 //hardware is much slower |
|
84 #endif |
|
85 |
|
86 #define KNumCUDOperations 3 |
|
87 |
|
88 _LIT(KMinContactsPrint,"$Min contacts$"); |
|
89 _LIT(KMidContactsPrint,"$Mid contacts$"); |
|
90 _LIT(KManyContactsPrint,"$Many contacts$"); |
|
91 _LIT(KMaxContactsPrint,"$Max contacts$"); |
|
92 |
|
93 |
|
94 CTransactionsStep::CTransactionsStep(CPerformanceFunctionalityTestsSuite &aParent) : CPerformanceFunctionalityBase(KNumberOfContacts, aParent) |
|
95 { |
|
96 SetTestStepName(KTransactionsStep); |
|
97 } |
|
98 |
|
99 TVerdict CTransactionsStep::doTestStepPostambleL() |
|
100 { |
|
101 const TInt error = iParent->Fs().Delete(KVcardFile); |
|
102 if( KErrNotFound != error && KErrNone != KErrNone ) |
|
103 { |
|
104 _LIT(KDeleteError,"Unexpected error when deleting vcard file, error: %d"); |
|
105 ERR_PRINTF2(KDeleteError, error); |
|
106 } |
|
107 return CPerformanceFunctionalityBase::doTestStepPostambleL(); |
|
108 } |
|
109 |
|
110 void CTransactionsStep::PreTestL() |
|
111 { |
|
112 User::LeaveIfError( iParent->Fs().Connect() ); |
|
113 } |
|
114 |
|
115 |
|
116 TVerdict CTransactionsStep::doTestStepL() |
|
117 /** |
|
118 * @return - TVerdict code |
|
119 * Override of base class pure virtual |
|
120 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
121 * not leave. That being the case, the current test result value will be EPass. |
|
122 */ |
|
123 { |
|
124 __UHEAP_MARK; |
|
125 InitializeL(); |
|
126 _LIT(KStartTest,"CTransactionsStep::doTestStepL()"); |
|
127 ALLPRINT(KStartTest); //Block start |
|
128 iIterate->Reset(); |
|
129 |
|
130 const TDesC &run = ConfigSection(); |
|
131 |
|
132 if( run == KRun1 ) |
|
133 { |
|
134 ALLPRINT(KTest1); |
|
135 NestedTransactionTestL(); |
|
136 } |
|
137 else if( run == KRun2 ) |
|
138 { |
|
139 ALLPRINT(KTest2); |
|
140 EmptyCommitTransactionTestL(EFalse); |
|
141 } |
|
142 else if( run == KRun3 ) |
|
143 { |
|
144 ALLPRINT(KTest3); |
|
145 EmptyCommitTransactionTestL(ETrue); |
|
146 } |
|
147 else if( run == KRun4 ) |
|
148 { |
|
149 ALLPRINT(KTest4); |
|
150 UpdateCommitTransactionTestL(EFalse); |
|
151 } |
|
152 else if( run == KRun5 ) |
|
153 { |
|
154 ALLPRINT(KTest5); |
|
155 UpdateCommitTransactionTestL(ETrue); |
|
156 } |
|
157 else if( run == KRun6 ) |
|
158 { |
|
159 ALLPRINT(KTest6); |
|
160 CreateCommitTransactionTestL(EFalse); |
|
161 } |
|
162 else if( run == KRun7 ) |
|
163 { |
|
164 ALLPRINT(KTest7); |
|
165 CreateCommitTransactionTestL(ETrue); |
|
166 } |
|
167 else if( run == KRun8 ) |
|
168 { |
|
169 ALLPRINT(KTest8); |
|
170 DeleteCommitTransactionTestL(EFalse); |
|
171 } |
|
172 else if( run == KRun9 ) |
|
173 { |
|
174 ALLPRINT(KTest9); |
|
175 DeleteCommitTransactionTestL(ETrue); |
|
176 } |
|
177 else if( run == KRun10 ) |
|
178 { |
|
179 ALLPRINT(KTest10); |
|
180 ManyUpdateCommitTransactionTestL(EFalse); |
|
181 } |
|
182 else if( run == KRun11 ) |
|
183 { |
|
184 ALLPRINT(KTest11); |
|
185 ManyUpdateCommitTransactionTestL(ETrue); |
|
186 } |
|
187 else if( run == KRun12 ) |
|
188 { |
|
189 ALLPRINT(KTest12); |
|
190 EmptyTransactionPerformanceTestL( EFalse); |
|
191 } |
|
192 else if( run == KRun13 ) |
|
193 { |
|
194 ALLPRINT(KTest13); |
|
195 EmptyTransactionPerformanceTestL( ETrue ); |
|
196 } |
|
197 else if( run == KRun14 ) |
|
198 { |
|
199 ALLPRINT(KTest14); |
|
200 MediumTransactionPerformanceTestL( EFalse); |
|
201 } |
|
202 else if( run == KRun15 ) |
|
203 { |
|
204 ALLPRINT(KTest15); |
|
205 MediumTransactionPerformanceTestL( ETrue); |
|
206 } |
|
207 else if( run == KRun16 ) |
|
208 { |
|
209 ALLPRINT(KTest16); |
|
210 FullTransactionPerformanceTestL( EFalse); |
|
211 } |
|
212 else if( run == KRun17 ) |
|
213 { |
|
214 ALLPRINT(KTest17); |
|
215 FullTransactionPerformanceTestL( ETrue); |
|
216 } |
|
217 else if( run == KRun18 ) |
|
218 { |
|
219 ALLPRINT(KTest18); |
|
220 MultipleCommitTestL( EFalse); |
|
221 } |
|
222 else if( run == KRun19 ) |
|
223 { |
|
224 ALLPRINT(KTest19); |
|
225 MultipleCommitTestL( ETrue); |
|
226 } |
|
227 else |
|
228 { |
|
229 MissingTestPanic(); |
|
230 } |
|
231 |
|
232 Cleanup(); |
|
233 __UHEAP_MARKEND; |
|
234 |
|
235 return TestStepResult(); |
|
236 } |
|
237 |
|
238 /** |
|
239 if in revert mode rollback transaction, otherwise commit |
|
240 */ |
|
241 void CTransactionsStep::EndTransactionL(const TBool aRevert) |
|
242 { |
|
243 if(aRevert) |
|
244 { |
|
245 iContactsDatabase->DatabaseRollback(); |
|
246 CleanupStack::Pop(); |
|
247 if( iContactsDatabase->IsDamaged() ) |
|
248 { |
|
249 iContactsDatabase->RecoverL(); |
|
250 } |
|
251 } |
|
252 else |
|
253 { |
|
254 iContactsDatabase->DatabaseCommitLP(EFalse); |
|
255 } |
|
256 } |
|
257 |
|
258 void CTransactionsStep::NestedTransactionTestL() |
|
259 { |
|
260 TContactItemId cid = iIterate->NextL(); |
|
261 |
|
262 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
263 iContactsDatabase->DatabaseBeginLC(ETrue); |
|
264 OpenL(cid); |
|
265 SetFieldL(1, GetFieldL(KStringFields, KField, 1) ); |
|
266 CommitL(ETrue); |
|
267 iContactsDatabase->DatabaseCommitLP(ETrue); |
|
268 OpenL(cid); |
|
269 SetFieldL(2, GetFieldL(KStringFields, KField, 2) ); |
|
270 CommitL(ETrue); |
|
271 EndTransactionL(ETrue); |
|
272 |
|
273 iIterate->Reset(); |
|
274 TInt err = KErrNone; |
|
275 TInt k = 0; |
|
276 TESTPRINT( iContactsDatabase->CountL() == iContacts ); |
|
277 |
|
278 for( k = 0; k < iContacts; ++k) |
|
279 { |
|
280 TRAP(err, ReadL( iIterate->NextL() ) ); |
|
281 TESTPRINTI( KErrNone == err, k ); |
|
282 TESTPRINTI( CheckAllFieldsL(KNullDesC), k ); |
|
283 CloseL( ETrue ); |
|
284 } |
|
285 } |
|
286 |
|
287 void CTransactionsStep::EmptyCommitTransactionTestL(const TBool aRevert) |
|
288 { |
|
289 CPerformanceFunctionalityBase::InitializeL(); |
|
290 |
|
291 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
292 EndTransactionL(aRevert); |
|
293 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
294 ReadL( iIterate->NextL() ); |
|
295 EndTransactionL(aRevert); |
|
296 CloseL( ETrue ); |
|
297 |
|
298 iIterate->Reset(); |
|
299 TInt i = 0; |
|
300 for(; i < iContacts; ++i) |
|
301 { |
|
302 ReadL( iIterate->NextL() ); |
|
303 TESTPRINTI( CheckAllFieldsL(KNullDesC), i ); |
|
304 CloseL( ETrue ); |
|
305 } |
|
306 |
|
307 } |
|
308 |
|
309 void CTransactionsStep::UpdateCommitTransactionTestL(const TBool aRevert) |
|
310 { |
|
311 CPerformanceFunctionalityBase::InitializeL(); |
|
312 |
|
313 const TContactItemId cid = iIterate->NextL(); |
|
314 const TContactItemId cid2 = iIterate->NextL(); |
|
315 |
|
316 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
317 OpenL( cid ); |
|
318 SetAllFieldsL( GetNextFieldL(KStringFields, KField, ETrue) ); |
|
319 CommitL(ETrue); |
|
320 EndTransactionL(aRevert); |
|
321 |
|
322 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
323 ReadL( cid2 ); |
|
324 SetAllFieldsL( GetNextFieldL(KStringFields, KField, EFalse) ); |
|
325 iContactsDatabase->UpdateContactLC(cid2, iContactItem); |
|
326 CleanupStack::PopAndDestroy(); |
|
327 CloseL( ETrue ); |
|
328 EndTransactionL(aRevert); |
|
329 |
|
330 if(aRevert) |
|
331 { |
|
332 iIterate->Reset(); |
|
333 TInt i = 0; |
|
334 for(; i < iContacts; ++i) |
|
335 { |
|
336 ReadL( iIterate->NextL() ); |
|
337 TESTPRINTI( CheckAllFieldsL(KNullDesC), i ); |
|
338 CloseL( ETrue ); |
|
339 } |
|
340 } |
|
341 else |
|
342 { |
|
343 ReadL( cid ); |
|
344 TESTPRINT( CheckAllFieldsL( GetNextFieldL(KStringFields, KField, ETrue) ) ); |
|
345 CloseL( ETrue ); |
|
346 |
|
347 ReadL( cid2 ); |
|
348 TESTPRINT( CheckAllFieldsL( GetNextFieldL(KStringFields, KField, EFalse) ) ); |
|
349 CloseL( ETrue ); |
|
350 } |
|
351 } |
|
352 |
|
353 void CTransactionsStep::CreateCommitTransactionTestL(const TBool aRevert) |
|
354 { |
|
355 iContacts = 0; |
|
356 CPerformanceFunctionalityBase::InitializeL(); |
|
357 |
|
358 CContactItemFieldSet& templateFields = iTemplate->CardFields(); |
|
359 TInt fieldsCount = templateFields.Count() - 1; |
|
360 |
|
361 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
362 |
|
363 iContacts = 2; |
|
364 TInt k = 0; |
|
365 CContactCard* contact = CContactCard::NewLC(iTemplate); |
|
366 for(; k < iContacts; k++) |
|
367 { |
|
368 iIterate->AddL( iContactsDatabase->doAddNewContactL(*contact,EFalse,ETrue) ); |
|
369 } |
|
370 CleanupStack::PopAndDestroy(contact); |
|
371 |
|
372 EndTransactionL(aRevert); |
|
373 |
|
374 if(aRevert) |
|
375 { |
|
376 iIterate->Reset(); |
|
377 TInt err = KErrNone; |
|
378 TESTPRINT( iContactsDatabase->CountL() == 0 ); |
|
379 |
|
380 for( k = 0; k < iContacts; ++k) |
|
381 { |
|
382 TRAP(err, ReadL( iIterate->NextL() ) ); |
|
383 TESTPRINTI( KErrNotFound == err, k ); |
|
384 CloseL( ETrue ); |
|
385 } |
|
386 } |
|
387 else |
|
388 { |
|
389 iIterate->Reset(); |
|
390 TESTPRINT( ( iContactsDatabase->CountL() == iContacts ) ); |
|
391 |
|
392 for(k = 0; k < iContacts; ++k) |
|
393 { |
|
394 ReadL( iIterate->NextL() ); |
|
395 TESTPRINTI( iFields->Count() == fieldsCount, k ); |
|
396 TESTPRINTI( CheckAllFieldsL(KNullDesC), k ); |
|
397 CloseL( ETrue ); |
|
398 } |
|
399 } |
|
400 } |
|
401 |
|
402 void CTransactionsStep::DeleteCommitTransactionTestL(const TBool aRevert) |
|
403 { |
|
404 iContacts = 10; |
|
405 CPerformanceFunctionalityBase::InitializeL(); |
|
406 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
407 |
|
408 TInt k = 0; |
|
409 for(; k < iContacts; k++) |
|
410 { |
|
411 iContactsDatabase->doDeleteContactL(iIterate->NextL(), ETrue, ETrue); |
|
412 } |
|
413 |
|
414 EndTransactionL(aRevert); |
|
415 |
|
416 if(aRevert) |
|
417 { |
|
418 TESTPRINT( iContactsDatabase->CountL() == iContacts ); |
|
419 iIterate->Reset(); |
|
420 TInt err = KErrNone; |
|
421 for(k = 0; k < iContacts; ++k) |
|
422 { |
|
423 TRAP(err, ReadL( iIterate->NextL() ) ); |
|
424 TESTPRINTI( KErrNone == err, k ); |
|
425 TESTPRINTI( CheckAllFieldsL( KNullDesC ), k ); |
|
426 CloseL( ETrue ); |
|
427 } |
|
428 } |
|
429 else |
|
430 { |
|
431 TESTPRINT( iContactsDatabase->CountL() == 0 ); |
|
432 |
|
433 iIterate->Reset(); |
|
434 TInt err = KErrNone; |
|
435 for(k = 0; k < iContacts; ++k) |
|
436 { |
|
437 TRAP(err, ReadL( iIterate->NextL() ) ); |
|
438 TESTPRINTI( KErrNotFound == err, k ); |
|
439 CloseL( ETrue ); |
|
440 } |
|
441 iIterate->Clear(); |
|
442 } |
|
443 } |
|
444 |
|
445 void CTransactionsStep::ManyUpdateCommitTransactionTestL( const TBool aRevert ) |
|
446 { |
|
447 iContacts = 1000; |
|
448 CPerformanceFunctionalityBase::InitializeL(); |
|
449 RCntList backuplist; |
|
450 backuplist.CopyL( *iIterate ); |
|
451 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
452 |
|
453 TInt added = 0; |
|
454 TInt deleted = 0; |
|
455 TInt updated = 0; |
|
456 TInt k = 0; |
|
457 for(; k < iContacts; k++) |
|
458 { |
|
459 switch( k % KNumCUDOperations ) |
|
460 { |
|
461 case ( EOpen ): |
|
462 { |
|
463 OpenL( iIterate->NextL() ); |
|
464 //if setting first contact read first field from stringfields section |
|
465 //otherwise read next field in list of fields stored in ini file secion |
|
466 SetAllFieldsL( GetNextFieldL(KStringFields, KField, 0 == k ) ); |
|
467 CommitL(ETrue); |
|
468 ++updated; |
|
469 } |
|
470 break; |
|
471 case ( EUpdate ): |
|
472 { |
|
473 TContactItemId cid = iIterate->NextL(); |
|
474 ReadL( cid ); |
|
475 //if setting first contact read first field from stringfields section |
|
476 //otherwise read next field in list of fields stored in ini file secion |
|
477 SetAllFieldsL( GetNextFieldL(KStringFields, KField, 0 == k ) ); |
|
478 iContactsDatabase->UpdateContactLC(cid, iContactItem); |
|
479 CleanupStack::PopAndDestroy(); |
|
480 CloseL( ETrue ); |
|
481 ++updated; |
|
482 } |
|
483 break; |
|
484 case ( EAddDelete ): |
|
485 { |
|
486 DeleteContactL( iIterate->NextL(), ETrue ); |
|
487 //iterator position is shifted back, so that next nextL call is correct |
|
488 iIterate->PreviousL(); |
|
489 ++deleted; |
|
490 //Empty contact is appended to the database, |
|
491 //Contact id is stored at the end of iterator list not at current iterator position |
|
492 AddEmptyContactsL( 1, ETrue ); |
|
493 ++added; |
|
494 } |
|
495 break; |
|
496 default: |
|
497 { |
|
498 _LIT(KInvalidTest, "Invalid Case"); |
|
499 User::Panic(KInvalidTest, 555); |
|
500 } |
|
501 break; |
|
502 } |
|
503 } |
|
504 |
|
505 EndTransactionL(aRevert); |
|
506 TESTPRINT( iContactsDatabase->CountL() == iContacts ); |
|
507 |
|
508 CContactItemFieldSet& templateFields = iTemplate->CardFields(); |
|
509 TInt fieldsCount = templateFields.Count() - 1; |
|
510 |
|
511 if(aRevert) |
|
512 { |
|
513 //if transaction is reverted / rolledback, all contacts should be |
|
514 //unchanged, i.e. they should all contain empty fields only |
|
515 backuplist.Reset(); |
|
516 TInt err = KErrNone; |
|
517 for(k = 0; k < iContacts; ++k) |
|
518 { |
|
519 TRAP(err, ReadL( backuplist.NextL() ) ); |
|
520 TESTPRINTI( KErrNone == err, k ); |
|
521 TESTPRINTI( CheckAllFieldsL( KNullDesC ), k ); |
|
522 CloseL( ETrue ); |
|
523 } |
|
524 } |
|
525 else |
|
526 { |
|
527 iIterate->Reset(); |
|
528 //all updated contact should contain the appropriated updated field value |
|
529 for(k = 0; k < updated; ++k) |
|
530 { |
|
531 ReadL( iIterate->NextL() ); |
|
532 TESTPRINTI(iFields->Count() == fieldsCount, k); |
|
533 //if reading first contact read first field from stringfields section |
|
534 //otherwise read next field in list of fields stored in ini file secion |
|
535 TESTPRINTI( CheckAllFieldsL( GetNextFieldL(KStringFields, KField, 0 == k ) ), k ); |
|
536 CloseL( ETrue ); |
|
537 } |
|
538 |
|
539 //all newly added contacts, should contain empty fields only. |
|
540 for(k = 0; k < added; ++k) |
|
541 { |
|
542 ReadL( iIterate->NextL() ); |
|
543 TESTPRINTI( iFields->Count() == fieldsCount, k); |
|
544 TESTPRINTI( CheckAllFieldsL( KNullDesC ), k); |
|
545 CloseL( ETrue ); |
|
546 } |
|
547 } |
|
548 } |
|
549 |
|
550 void CTransactionsStep::TransactionPerformanceL( const TBool aDelete, |
|
551 const FieldFullness aField, |
|
552 const TInt aContacts, |
|
553 TReal &aDiffseconds, |
|
554 TReal &aCumseconds) |
|
555 { |
|
556 iContacts = ( ( aContacts / KTransactionSize ) + 1 ) * KTransactionSize ; |
|
557 TInt64 cumlative = 0; |
|
558 TInt64 diff = 0; |
|
559 TTime startT; |
|
560 TTime finishT; |
|
561 TTime start; |
|
562 TTime finish; |
|
563 |
|
564 TInt j = 0; |
|
565 for(; j < KPerfIter; ++j) |
|
566 { |
|
567 CPerformanceFunctionalityBase::InitializeL(); |
|
568 ModifyContactsL(aField); |
|
569 ExportVcardL( aDelete, KVcardFile ); |
|
570 RFileReadStream rfrs; |
|
571 CleanupClosePushL( rfrs ); |
|
572 User::LeaveIfError( rfrs.Open( iParent->Fs(), KVcardFile, EFileRead | EFileShareAny ) ); |
|
573 |
|
574 TInt i = 0; |
|
575 start.UniversalTime(); |
|
576 for(; i < iContacts; i+=KTransactionSize) |
|
577 { |
|
578 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
579 ImportVcardL(KTransactionSize, rfrs); |
|
580 startT.UniversalTime(); |
|
581 iContactsDatabase->DatabaseCommitLP(EFalse); |
|
582 finishT.UniversalTime(); |
|
583 cumlative += ( finishT.MicroSecondsFrom( startT ).Int64() ); |
|
584 } |
|
585 finish.UniversalTime(); |
|
586 diff += ( finish.MicroSecondsFrom(start).Int64() ); |
|
587 CleanupStack::PopAndDestroy(&rfrs); |
|
588 } |
|
589 User::LeaveIfError( iParent->Fs().Delete(KVcardFile) ); |
|
590 |
|
591 aDiffseconds = (TReal) diff / (1000000 * KPerfIter); |
|
592 aCumseconds = (TReal) cumlative / (1000000 * KPerfIter); |
|
593 |
|
594 _LIT(KMicroPerformance, "Micro performance: %d"); |
|
595 _LIT(KSecondsPerformance, "performance in seconds: %f"); |
|
596 _LIT(KCommitPerformance, "commit performance in seconds: %f"); |
|
597 ALLPRINT2(KMicroPerformance, diff); |
|
598 ALLPRINT2(KSecondsPerformance, aDiffseconds ); |
|
599 ALLPRINT2(KCommitPerformance, aCumseconds ); |
|
600 } |
|
601 |
|
602 void CTransactionsStep::EmptyTransactionPerformanceTestL(const TBool aDelete) |
|
603 { |
|
604 TReal diffsecondsMax = 0; |
|
605 TReal commitsecondsMax = 0; |
|
606 |
|
607 _LIT(KMaxContactsPrint,"$Max contacts$"); |
|
608 ALLPRINT(KMaxContactsPrint); |
|
609 TransactionPerformanceL(aDelete, EEmpty, KMaxContacts, diffsecondsMax, commitsecondsMax); |
|
610 |
|
611 TESTPRINT( diffsecondsMax < KMaxTimeAllowed ); |
|
612 } |
|
613 |
|
614 void CTransactionsStep::MediumTransactionPerformanceTestL(const TBool aDelete) |
|
615 { |
|
616 TReal diffsecondsMin = 0; |
|
617 TReal commitsecondsMin = 0; |
|
618 TReal diffsecondsMid = 0; |
|
619 TReal commitsecondsMid = 0; |
|
620 TReal diffsecondsMan = 0; |
|
621 TReal commitsecondsMan = 0; |
|
622 TReal diffsecondsMax = 0; |
|
623 TReal commitsecondsMax = 0; |
|
624 |
|
625 ALLPRINT(KMinContactsPrint); |
|
626 TransactionPerformanceL(aDelete, EMedium, KMinContacts, diffsecondsMin, commitsecondsMin); |
|
627 ALLPRINT(KMidContactsPrint); |
|
628 TransactionPerformanceL(aDelete, EMedium, KMidContacts, diffsecondsMid, commitsecondsMid); |
|
629 ALLPRINT(KManyContactsPrint); |
|
630 TransactionPerformanceL(aDelete, EMedium, KManyContacts, diffsecondsMan, commitsecondsMan); |
|
631 ALLPRINT(KMaxContactsPrint); |
|
632 TransactionPerformanceL(aDelete, EMedium, KMaxContacts, diffsecondsMax, commitsecondsMax); |
|
633 |
|
634 |
|
635 TESTPRINT( diffsecondsMax < KMaxTimeAllowed ); |
|
636 } |
|
637 |
|
638 void CTransactionsStep::FullTransactionPerformanceTestL(const TBool aDelete) |
|
639 { |
|
640 TReal diffsecondsMin = 0; |
|
641 TReal commitsecondsMin = 0; |
|
642 TReal diffsecondsMid = 0; |
|
643 TReal commitsecondsMid = 0; |
|
644 TReal diffsecondsMan = 0; |
|
645 TReal commitsecondsMan = 0; |
|
646 TReal diffsecondsMax = 0; |
|
647 #ifdef __WINSCW__ |
|
648 TReal commitsecondsMax = 0; |
|
649 #endif |
|
650 |
|
651 ALLPRINT(KMinContactsPrint); |
|
652 TransactionPerformanceL(aDelete, EFull, KMinContacts, diffsecondsMin, commitsecondsMin); |
|
653 ALLPRINT(KMidContactsPrint); |
|
654 TransactionPerformanceL(aDelete, EFull, KMidContacts, diffsecondsMid, commitsecondsMid); |
|
655 ALLPRINT(KManyContactsPrint); |
|
656 TransactionPerformanceL(aDelete, EFull, KManyContacts, diffsecondsMan, commitsecondsMan); |
|
657 //is too slow on hardware, also takes up too much disk space |
|
658 #ifdef __WINSCW__ |
|
659 ALLPRINT(KMaxContactsPrint); |
|
660 TransactionPerformanceL(aDelete, EFull, KMaxContacts, diffsecondsMax, commitsecondsMax); |
|
661 #endif |
|
662 |
|
663 TESTPRINT( diffsecondsMax < KMaxTimeAllowed ); |
|
664 } |
|
665 |
|
666 void CTransactionsStep::MultipleCommitTestL(const TBool aTrans) |
|
667 { |
|
668 iContacts = 40; |
|
669 CPerformanceFunctionalityBase::InitializeL(); |
|
670 if(aTrans) |
|
671 { |
|
672 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
673 } |
|
674 MultipleCommitL(aTrans); |
|
675 if(aTrans) |
|
676 { |
|
677 EndTransactionL(EFalse); |
|
678 } |
|
679 TInt k = 0; |
|
680 iIterate->Reset(); |
|
681 for(; k < iContacts; ++k) |
|
682 { |
|
683 ReadL( iIterate->NextL() ); |
|
684 TESTPRINTI( CheckAllFieldsL( GetNextFieldL(KStringFields, KField, 0 == k ) ), k ); |
|
685 CloseL( ETrue ); |
|
686 } |
|
687 } |
|
688 |
|
689 /** |
|
690 destroy array from within cleanupstack |
|
691 */ |
|
692 static void ArrayCleanup(TAny *aArray) |
|
693 { |
|
694 RPointerArray<CContactItem> *parray = static_cast< RPointerArray<CContactItem> * >(aArray); |
|
695 parray->ResetAndDestroy(); |
|
696 } |
|
697 |
|
698 void CTransactionsStep::MultipleCommitL(const TBool aTrans) |
|
699 { |
|
700 RPointerArray<CContactItem> itemarray( 500, 512 ); |
|
701 TCleanupItem tclean(ArrayCleanup,&itemarray); |
|
702 CleanupStack::PushL( tclean ); |
|
703 TInt k = 0; |
|
704 iIterate->Reset(); |
|
705 for(; k < iContacts; ++k) |
|
706 { |
|
707 itemarray.Append( iContactsDatabase->OpenContactLX( iIterate->NextL(), *iViewAll ) ); |
|
708 iFields = &( itemarray[k]->CardFields() ); |
|
709 SetAllFieldsL( GetNextFieldL(KStringFields, KField, 0 == k ) ); |
|
710 } |
|
711 |
|
712 iIterate->Reset(); |
|
713 if(aTrans) |
|
714 { |
|
715 for( k = iContacts - 1; k >=0 ; --k ) |
|
716 { |
|
717 iContactsDatabase->doCommitContactL(*itemarray[k], ETrue, ETrue ); |
|
718 CleanupStack::Pop(); |
|
719 } |
|
720 } |
|
721 else |
|
722 { |
|
723 for( k = iContacts - 1; k >=0 ; --k ) |
|
724 { |
|
725 iContactsDatabase->CommitContactL(*itemarray[k]); |
|
726 CleanupStack::Pop(); |
|
727 } |
|
728 } |
|
729 CleanupStack::PopAndDestroy();//tclean |
|
730 } |
|
731 |
|
732 /** |
|
733 populates all contacts either moderately, fully, or not at all |
|
734 */ |
|
735 void CTransactionsStep::ModifyContactsL(const FieldFullness aField) |
|
736 { |
|
737 if(aField == EEmpty) |
|
738 { |
|
739 return; |
|
740 } |
|
741 iIterate->Reset(); |
|
742 TInt j = 0; |
|
743 for(; j < iContacts; ++j) |
|
744 { |
|
745 OpenL(iIterate->NextL()); |
|
746 if(aField == EFull) |
|
747 { |
|
748 SetAllFieldsL( GetFieldL(KStringFields, KField, 2) ); |
|
749 } |
|
750 else |
|
751 { |
|
752 SetManyFieldsL(GetFieldL(KStringFields, KField, 4) , KMediumFields); |
|
753 } |
|
754 CommitL(EFalse); |
|
755 } |
|
756 } |
|
757 |