|
1 // Copyright (c) 2004-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 @SYMPREQ PREQ1132 PREQ1187 |
|
18 @SYMComponent app-engines_cntmodel |
|
19 @SYMAuthor Simon Mellor, JamesCl |
|
20 @SYMTestStatus Implemented |
|
21 @SYMTestType CT |
|
22 |
|
23 @SYMTestCaseDesc Tests the performance of a bulk delete operation on a corporate-profile |
|
24 database of 1000 contacts. |
|
25 |
|
26 @SYMTestActions Measures the time taken to perform a bulk delete on the contacts database |
|
27 by passing a CContactIdArray to: |
|
28 -- CContactDatabase::DeleteContactsL() |
|
29 |
|
30 @SYMTestExpectedResults Test case will run without leaving and will output timing information. |
|
31 |
|
32 */ |
|
33 |
|
34 #include "T_PerfBulkDelete.h" |
|
35 #include "../T_UTILS.H" |
|
36 #include <cntitem.h> |
|
37 |
|
38 // Constants |
|
39 _LIT(KDbPathName,"C:Contacts.cdb"); |
|
40 const TPtrC KDbPath( (KDbPathName) ); |
|
41 |
|
42 _LIT(KOutputFormat,"Bulk Delete, deleting %d of %d contacts, took: %d s %03d\n"); |
|
43 _LIT(KOutputFormat2, "Db size before/after delete: %d / %d bytes\n"); |
|
44 |
|
45 |
|
46 CDeleteMany::CDeleteMany() |
|
47 { |
|
48 } |
|
49 |
|
50 CDeleteMany::~CDeleteMany() |
|
51 { |
|
52 delete iDb; |
|
53 } |
|
54 |
|
55 CDeleteMany* CDeleteMany::NewLC(RTest& aTest) |
|
56 { |
|
57 CDeleteMany* self = new(ELeave) CDeleteMany(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(aTest); |
|
60 return(self); |
|
61 } |
|
62 |
|
63 void CDeleteMany::ConstructL(RTest& aTest) |
|
64 { |
|
65 iTest = &aTest; |
|
66 iDb = CContactDatabase::OpenL(KDbPath); |
|
67 CCntTest::ProfileReset(0, 59); |
|
68 } |
|
69 |
|
70 /* |
|
71 Creates a random array of numbers corresponding to the Contacts Id in the |
|
72 Contacts model. No Contact Id is repeated |
|
73 */ |
|
74 void CDeleteMany::CreateRandomIdArrayL(CContactIdArray& aUids, TInt aNumIds, TInt aNumEntriesInDb) |
|
75 { |
|
76 TTime now; |
|
77 now.UniversalTime(); |
|
78 TInt64 KRandomSeed = now.DateTime().MicroSecond(); |
|
79 |
|
80 TInt uid(0); |
|
81 for(TInt i = 0; i < aNumIds; ++i) |
|
82 { |
|
83 uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1; |
|
84 while(aUids.Find(uid) != KErrNotFound) |
|
85 { |
|
86 uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1; |
|
87 } |
|
88 aUids.AddL(uid); |
|
89 } |
|
90 } |
|
91 |
|
92 /** |
|
93 Static convenience cleanup method copied from CSmlContactsDba |
|
94 */ |
|
95 void CDeleteMany::CleanupPtrArray(TAny* aCArrayPtr) |
|
96 { |
|
97 CArrayPtr<CContactItem>* array = reinterpret_cast<CArrayPtr<CContactItem>*>(aCArrayPtr); |
|
98 array->ResetAndDestroy(); |
|
99 delete array; |
|
100 } |
|
101 |
|
102 |
|
103 /** |
|
104 Main test routine. Calls and times CContactDatabase::DeleteContactsL |
|
105 */ |
|
106 void CDeleteMany::DelDataL(TInt aEntryCount, TInt aNumEntriesInDb, TInt aNumMsToGet20ItemsFromView) |
|
107 { |
|
108 TInt dbSizeBefore = iDb->FileSize(); |
|
109 |
|
110 CContactIdArray* idArray = CContactIdArray::NewLC(); |
|
111 |
|
112 // create an array of random, non-repeating contact ids |
|
113 CreateRandomIdArrayL(*idArray, aEntryCount, aNumEntriesInDb); |
|
114 |
|
115 TCntPerfTimer timer; |
|
116 timer.StartTimer(); |
|
117 iDb->DeleteContactsL(*idArray); |
|
118 timer.StopTimer(); |
|
119 |
|
120 CleanupStack::PopAndDestroy(); // idArray |
|
121 |
|
122 const TInt KTransactionSize(50); // num records deleted in a transaction |
|
123 |
|
124 // add in number of screen updates need in UI: (time to fetch 20 view items) * number of transactions |
|
125 TInt result = timer.Result() + |
|
126 (aNumMsToGet20ItemsFromView * ( (aEntryCount / KTransactionSize) + (aEntryCount % 20 ? 1 : 0) ) ); |
|
127 |
|
128 |
|
129 TBuf<64> formattable; |
|
130 formattable.Format(KOutputFormat, aEntryCount, aNumEntriesInDb, result / 1000000, (result / 1000) % 1000); |
|
131 iTest->Printf(formattable); |
|
132 formattable.Format(KOutputFormat2, dbSizeBefore, iDb->FileSize()); |
|
133 iTest->Printf(formattable); |
|
134 } |