|
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 "CompactAndRecoverStep.h" |
|
22 #include "PerformanceFunctionalityDefs.h" |
|
23 #include <cntfilt.h> |
|
24 |
|
25 #define KNumberOfContacts 10 |
|
26 |
|
27 _LIT(KRun1,"CRUD"); |
|
28 _LIT(KRun2,"Transaction"); |
|
29 _LIT(KRun3,"Simple"); |
|
30 _LIT(KRun4,"AsyncOpen"); |
|
31 |
|
32 _LIT(KTest1, "CRUD tests"); |
|
33 _LIT(KTest2, "Transaction tests"); |
|
34 _LIT(KTest3, "Simple operations test"); |
|
35 _LIT(KTest4, "Asynchronous Open recovery test"); |
|
36 |
|
37 |
|
38 _LIT(KCompleteSteps, "Complete all active steps Test"); |
|
39 _LIT(KCancelSteps, "Cancel active steps Test"); |
|
40 |
|
41 _LIT(KRecover, "Recover_" ); |
|
42 _LIT(KComplete, "Complete_" ); |
|
43 _LIT(KCompleteAndRecover, "CNR_" ); |
|
44 |
|
45 |
|
46 |
|
47 CCompactAndRecoverStep::CCompactAndRecoverStep() : CPerformanceFunctionalityBase(KNumberOfContacts) |
|
48 { |
|
49 SetTestStepName(KCompactAndRecoverStep); |
|
50 } |
|
51 |
|
52 TVerdict CCompactAndRecoverStep::doTestStepPostambleL() |
|
53 { |
|
54 CLEAR( iContactOpenOperation ); |
|
55 return CPerformanceFunctionalityBase::doTestStepPostambleL(); |
|
56 } |
|
57 |
|
58 void CCompactAndRecoverStep::InitializeL() |
|
59 { |
|
60 CPerformanceFunctionalityBase::InitializeL(); |
|
61 iContactsDatabase2 = CContactDatabase::OpenL(); |
|
62 //set timeout to 0, to minimize waits within the test |
|
63 iContactsDatabase->SetOperationTimeOutL(0); |
|
64 iContactsDatabase2->SetOperationTimeOutL(0); |
|
65 } |
|
66 |
|
67 void CCompactAndRecoverStep::Cleanup() |
|
68 { |
|
69 CLEAR( iContactsDatabase2 ); |
|
70 CPerformanceFunctionalityBase::Cleanup(); |
|
71 } |
|
72 |
|
73 void CCompactAndRecoverStep::PreTestL() |
|
74 { |
|
75 const TDesC &KSection = ConfigSection(); |
|
76 //read recover flag passed in section paramter |
|
77 iRecoverFlag = ( KSection.Find( KRecover ) == 0 ); |
|
78 //read complete flag passed in section paramter |
|
79 iCompleteSteps = ( KSection.Find( KComplete ) == 0 ); |
|
80 |
|
81 if( !iRecoverFlag && !iCompleteSteps ) |
|
82 { |
|
83 iRecoverFlag = iCompleteSteps = ( KSection.Find( KCompleteAndRecover ) == 0 ); |
|
84 } |
|
85 } |
|
86 |
|
87 TVerdict CCompactAndRecoverStep::doTestStepL() |
|
88 { |
|
89 #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
90 return EPass; |
|
91 #else |
|
92 __UHEAP_MARK; |
|
93 InitializeL(); |
|
94 _LIT(KPrintStart, "CCompactAndRecoverStep::doTestStepL()"); |
|
95 INFO_PRINTF1(KPrintStart); //Block start |
|
96 iIterate->Reset(); |
|
97 |
|
98 const TDesC &run = ConfigSection(); |
|
99 |
|
100 if( run.Find( KRun1 ) > KErrNotFound ) |
|
101 { |
|
102 INFO_PRINTF1( KTest1 ); |
|
103 TestWrapperL( &CCompactAndRecoverStep::CRUDOperationsL, KErrNotReady, KErrNotReady, KErrNone, KErrNotReady ); |
|
104 } |
|
105 else if( run.Find( KRun2 ) > KErrNotFound ) |
|
106 { |
|
107 INFO_PRINTF1( KTest2 ); |
|
108 TestWrapperL( &CCompactAndRecoverStep::TransactionOperations, KErrNotReady, KErrNotReady, KErrNone, KErrNotReady ); |
|
109 } |
|
110 else if( run.Find( KRun3 ) > KErrNotFound ) |
|
111 { |
|
112 INFO_PRINTF1( KTest3 ); |
|
113 TestWrapperL( &CCompactAndRecoverStep::SimpleOperationsL, KErrAccessDenied, KErrNone, KErrNone, KErrNone ); |
|
114 } |
|
115 else if( run.Find( KRun4 ) > KErrNotFound ) |
|
116 { |
|
117 INFO_PRINTF1( KTest4 ); |
|
118 OpenAsyncTestL(); |
|
119 } |
|
120 else |
|
121 { |
|
122 MissingTestPanic(); |
|
123 } |
|
124 |
|
125 Cleanup(); |
|
126 __UHEAP_MARKEND; |
|
127 |
|
128 return TestStepResult(); |
|
129 #endif |
|
130 } |
|
131 |
|
132 /** |
|
133 Test wrapper for performing all comapct and recover tests |
|
134 start recover/compress |
|
135 perfrom database operations, expecting recover/compress errors |
|
136 end recover compress |
|
137 perform database operations again, expecting no errors |
|
138 */ |
|
139 void CCompactAndRecoverStep::TestWrapperL( |
|
140 void (CCompactAndRecoverStep::*aOperations)(const TInt ), |
|
141 const TInt aErr, |
|
142 const TInt aErr2, |
|
143 const TInt aErr3, |
|
144 const TInt aErr4 ) |
|
145 { |
|
146 if(iCompleteSteps) |
|
147 { |
|
148 INFO_PRINTF1(KCompleteSteps); |
|
149 } |
|
150 else |
|
151 { |
|
152 INFO_PRINTF1(KCancelSteps); |
|
153 } |
|
154 |
|
155 //start compress/recover |
|
156 if( iRecoverFlag ) |
|
157 { |
|
158 StartRecoverL(); |
|
159 } |
|
160 else |
|
161 { |
|
162 StartCompressL(); |
|
163 } |
|
164 |
|
165 //perfrom database operations |
|
166 #ifdef _DEBUG |
|
167 |
|
168 (this->*aOperations)( iRecoverFlag ? aErr : aErr2 ); |
|
169 (void)aErr3; |
|
170 (void)aErr4; |
|
171 |
|
172 #else |
|
173 |
|
174 (this->*aOperations)( iRecoverFlag? aErr3 : aErr4 ); |
|
175 (void)aErr; |
|
176 (void)aErr2; |
|
177 |
|
178 #endif |
|
179 |
|
180 //end recover / compress |
|
181 if( iRecoverFlag ) |
|
182 { |
|
183 EndRecoverL(); |
|
184 } |
|
185 else |
|
186 { |
|
187 EndCompressL(); |
|
188 } |
|
189 |
|
190 CContactDatabase *temp = iContactsDatabase2; |
|
191 iContactsDatabase2 = iContactsDatabase; |
|
192 iContactsDatabase = temp; |
|
193 |
|
194 //perfrom database operations expecting no errors |
|
195 (this->*aOperations)( KErrNone ); |
|
196 |
|
197 temp = iContactsDatabase2; |
|
198 iContactsDatabase2 = iContactsDatabase; |
|
199 iContactsDatabase = temp; |
|
200 } |
|
201 |
|
202 /** |
|
203 Performs and Traps database crud(Create, read, update, delete) operations |
|
204 all operations should leave with aError |
|
205 */ |
|
206 void CCompactAndRecoverStep::CRUDOperationsL(const TInt aError) |
|
207 { |
|
208 _LIT(KPrintErrors,"Expected error: %d and Observed error: %d"); |
|
209 TContactItemId con1 = iIterate->NextL(); |
|
210 CContactItem *contactItem1 = NULL; |
|
211 |
|
212 TRAPD( err, |
|
213 contactItem1 = iContactsDatabase->ReadContactLC(con1); |
|
214 CleanupStack::PopAndDestroy( contactItem1 ); |
|
215 ); |
|
216 TESTPRINT(aError == err); |
|
217 INFO_PRINTF3(KPrintErrors, aError, err); |
|
218 |
|
219 TRAP( err, |
|
220 contactItem1 = iContactsDatabase->OpenContactLX(con1); |
|
221 CleanupStack::PushL(contactItem1); |
|
222 iContactsDatabase->CommitContactL(*contactItem1); |
|
223 CleanupStack::PopAndDestroy( contactItem1 ); |
|
224 CleanupStack::Pop( );//lock |
|
225 ); |
|
226 TESTPRINT(aError == err); |
|
227 INFO_PRINTF3(KPrintErrors, aError, err); |
|
228 |
|
229 CContactCard* contact = CContactCard::NewLC(iTemplate); |
|
230 TRAP(err, contactItem1 = iContactsDatabase->UpdateContactLC(con1, contact); |
|
231 CleanupStack::PopAndDestroy(contactItem1); |
|
232 ); |
|
233 CleanupStack::PopAndDestroy( contact ); |
|
234 TESTPRINT(aError == err); |
|
235 INFO_PRINTF3(KPrintErrors, aError, err); |
|
236 |
|
237 TRAP( err, |
|
238 AddEmptyContactsL(1, EFalse); |
|
239 ); |
|
240 TESTPRINT(aError == err); |
|
241 INFO_PRINTF3(KPrintErrors, aError, err); |
|
242 |
|
243 TRAP( err, |
|
244 DeleteContactL(con1, EFalse); |
|
245 ); |
|
246 TESTPRINT(aError == err); |
|
247 INFO_PRINTF3(KPrintErrors, aError, err); |
|
248 } |
|
249 |
|
250 /** |
|
251 Performs and Traps database transaction operations |
|
252 all operations should leave with aError |
|
253 */ |
|
254 void CCompactAndRecoverStep::TransactionOperations(const TInt aError) |
|
255 { |
|
256 _LIT(KPrintErrors,"Expected error: %d and Observed error: %d"); |
|
257 |
|
258 //begin transaction |
|
259 TRAPD(err, iContactsDatabase->DatabaseBeginL(EFalse); ); |
|
260 TESTPRINT(aError == err); |
|
261 INFO_PRINTF3(KPrintErrors, aError, err); |
|
262 |
|
263 //perfrom crud operation |
|
264 TRAP_IGNORE( AddEmptyContactsL(1, EFalse) ); |
|
265 |
|
266 //commit transaction |
|
267 TRAP(err, iContactsDatabase->DatabaseCommitL(EFalse); ); |
|
268 TESTPRINT(aError == err); |
|
269 INFO_PRINTF3(KPrintErrors, aError, err); |
|
270 |
|
271 //begin transaction |
|
272 TRAP(err, iContactsDatabase->DatabaseBeginL(EFalse); ); |
|
273 TESTPRINT(aError == err); |
|
274 INFO_PRINTF3(KPrintErrors, aError, err); |
|
275 |
|
276 //perfrom crud operation |
|
277 TRAP_IGNORE( AddEmptyContactsL(1, EFalse) ); |
|
278 |
|
279 //rollback transaction |
|
280 TRAP(err, |
|
281 iContactsDatabase->DatabaseRollback(); |
|
282 User::After( 100000 ); |
|
283 ); |
|
284 //rollback can't leave |
|
285 TESTPRINT( KErrNone == err); |
|
286 INFO_PRINTF3(KPrintErrors, KErrNone, err); |
|
287 } |
|
288 |
|
289 /** |
|
290 Performs and Traps simple database operations |
|
291 all operations should leave with aError |
|
292 */ |
|
293 void CCompactAndRecoverStep::SimpleOperationsL(const TInt aError) |
|
294 { |
|
295 _LIT(KPrintErrors,"Expected error: %d and Observed error: %d"); |
|
296 |
|
297 const TContactItemId KOwnCardId = iContactsDatabase->OwnCardId(); |
|
298 TESTPRINT( KOwnCardId == -1 ); |
|
299 |
|
300 CCntFilter *filter = CCntFilter::NewL(); |
|
301 TRAPD(err, iContactsDatabase->FilterDatabaseL( *filter ); ); |
|
302 CLEAR( filter ); |
|
303 TESTPRINT(aError == err); |
|
304 INFO_PRINTF3(KPrintErrors, aError, err); |
|
305 } |
|
306 |
|
307 /** |
|
308 Start asynchronous open while in compress/recover state |
|
309 end compress/recover state |
|
310 wait for open to be successfully completed |
|
311 */ |
|
312 void CCompactAndRecoverStep::OpenAsyncTestL() |
|
313 { |
|
314 _LIT(KOpenAsync, "Open Async"); |
|
315 _LIT(KEndAsync, "End Async"); |
|
316 iCompleteSteps = EFalse; |
|
317 |
|
318 StartRecoverL(); |
|
319 ALLPRINT(KOpenAsync); |
|
320 iContactOpenOperation = CContactDatabase::Open(iStatus); |
|
321 EndRecoverL(); |
|
322 User::WaitForRequest(iStatus); |
|
323 CLEAR( iContactOpenOperation ); |
|
324 ALLPRINT( KEndAsync ); |
|
325 |
|
326 StartCompressL(); |
|
327 ALLPRINT(KOpenAsync); |
|
328 iContactOpenOperation = CContactDatabase::Open(iStatus); |
|
329 EndCompressL(); |
|
330 User::WaitForRequest(iStatus); |
|
331 CLEAR( iContactOpenOperation ); |
|
332 ALLPRINT( KEndAsync ); |
|
333 } |
|
334 |
|
335 |
|
336 |