summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/perffuncsuite/src/compactandrecoverstep.cpp
blob: 84a94b426042b46b36d44df3930722b435f95826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


/**
 @file 
 @publishedAll
 @released
*/
#include "compactandrecoverstep.h"
#include "performancefunctionalitydefs.h"
#include <cntfilt.h>

#define KNumberOfContacts 10

_LIT(KRun1,"CRUD");
_LIT(KRun2,"Transaction");
_LIT(KRun3,"Simple");
_LIT(KRun4,"AsyncOpen");

_LIT(KTest1, "CRUD tests");
_LIT(KTest2, "Transaction tests");
_LIT(KTest3, "Simple operations test");
_LIT(KTest4, "Asynchronous Open recovery test");


_LIT(KCompleteSteps, "Complete all active steps Test");
_LIT(KCancelSteps, "Cancel active steps Test");

_LIT(KRecover, "Recover_" );
_LIT(KComplete, "Complete_" );
_LIT(KCompleteAndRecover, "CNR_" );



CCompactAndRecoverStep::CCompactAndRecoverStep()  : CPerformanceFunctionalityBase(KNumberOfContacts)
	{
	SetTestStepName(KCompactAndRecoverStep);
	}
	
TVerdict CCompactAndRecoverStep::doTestStepPostambleL()
	{
	CLEAR( iContactOpenOperation );	
	return CPerformanceFunctionalityBase::doTestStepPostambleL();
	}
	
void CCompactAndRecoverStep::InitializeL()
	{
	CPerformanceFunctionalityBase::InitializeL();
	iContactsDatabase2 = CContactDatabase::OpenL();
	//set timeout to 0, to minimize waits within the test
	iContactsDatabase->SetOperationTimeOutL(0);
	iContactsDatabase2->SetOperationTimeOutL(0);
	}

void CCompactAndRecoverStep::Cleanup()
	{
	CLEAR( iContactsDatabase2 );
	CPerformanceFunctionalityBase::Cleanup();
	}
	
void CCompactAndRecoverStep::PreTestL()
	{
	const TDesC &KSection = ConfigSection();
	//read recover flag passed in section paramter
	iRecoverFlag = ( KSection.Find( KRecover ) == 0 );
	//read complete flag passed in section paramter
	iCompleteSteps = ( KSection.Find( KComplete ) == 0 );
	
	if( !iRecoverFlag && !iCompleteSteps )
		{
		iRecoverFlag = iCompleteSteps = ( KSection.Find( KCompleteAndRecover ) == 0 );
		}
	}

TVerdict CCompactAndRecoverStep::doTestStepL()
	{
#ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__
	return EPass;
#else	
	__UHEAP_MARK;
	InitializeL();
	_LIT(KPrintStart, "CCompactAndRecoverStep::doTestStepL()");
	INFO_PRINTF1(KPrintStart);  //Block start 
	iIterate->Reset();

	const TDesC &run = ConfigSection();
	
	if( run.Find( KRun1 ) > KErrNotFound )
		{
		INFO_PRINTF1( KTest1 );
		TestWrapperL( &CCompactAndRecoverStep::CRUDOperationsL, KErrNotReady, KErrNotReady, KErrNone, KErrNotReady );
		}
	else if( run.Find( KRun2 ) > KErrNotFound )
		{
		INFO_PRINTF1( KTest2 );
		TestWrapperL(  &CCompactAndRecoverStep::TransactionOperations, KErrNotReady, KErrNotReady, KErrNone, KErrNotReady );
		}
	else if( run.Find( KRun3 ) > KErrNotFound )
		{
		INFO_PRINTF1( KTest3 );
		TestWrapperL(  &CCompactAndRecoverStep::SimpleOperationsL, KErrAccessDenied, KErrNone, KErrNone, KErrNone );
		}
	else if( run.Find( KRun4 ) > KErrNotFound )
		{
		INFO_PRINTF1( KTest4 );
		OpenAsyncTestL();
		}
	else
		{
		MissingTestPanic();
		}
		
	Cleanup();
	__UHEAP_MARKEND;

	return TestStepResult();
#endif
	}
	
/**
Test wrapper for performing all comapct and recover tests
start recover/compress
perfrom database operations, expecting recover/compress errors
end recover compress
perform database operations again, expecting no errors
*/
void CCompactAndRecoverStep::TestWrapperL(
									void (CCompactAndRecoverStep::*aOperations)(const TInt ), 
									const TInt aErr, 
									const TInt aErr2, 
									const TInt aErr3, 
									const TInt aErr4 )
	{
	if(iCompleteSteps)
		{
		INFO_PRINTF1(KCompleteSteps);
		}
	else
		{
		INFO_PRINTF1(KCancelSteps);
		}
	
	//start compress/recover	
	if( iRecoverFlag )
		{
		StartRecoverL();
		}
	else
		{
		StartCompressL();
		}
	
	//perfrom database operations	
	#ifdef _DEBUG
	
	(this->*aOperations)( iRecoverFlag ? aErr : aErr2 );
	(void)aErr3;
	(void)aErr4;
	
	#else
	
	(this->*aOperations)( iRecoverFlag? aErr3 : aErr4 );
	(void)aErr;
	(void)aErr2;
	
	#endif
	
	//end recover / compress
	if( iRecoverFlag )
		{
		EndRecoverL();
		}
	else
		{
		EndCompressL();
		}
		
	CContactDatabase *temp = iContactsDatabase2;
	iContactsDatabase2 = iContactsDatabase;
	iContactsDatabase = temp;
	
	//perfrom database operations expecting no errors
	(this->*aOperations)( KErrNone );
	
	temp = iContactsDatabase2;
	iContactsDatabase2 = iContactsDatabase;
	iContactsDatabase = temp;
	}

/**
Performs and Traps database crud(Create, read, update, delete) operations
all operations should leave with aError
*/
void CCompactAndRecoverStep::CRUDOperationsL(const TInt aError)
	{
	_LIT(KPrintErrors,"Expected error: %d and Observed error: %d");
	TContactItemId con1 = iIterate->NextL();
	CContactItem *contactItem1 = NULL;

	TRAPD( err, 
			contactItem1 = iContactsDatabase->ReadContactLC(con1);
			CleanupStack::PopAndDestroy( contactItem1 );
			);
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	TRAP( err, 
		contactItem1 = iContactsDatabase->OpenContactLX(con1);
		CleanupStack::PushL(contactItem1);
		iContactsDatabase->CommitContactL(*contactItem1);
		CleanupStack::PopAndDestroy( contactItem1 );
		CleanupStack::Pop( );//lock
		);
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	CContactCard* contact = CContactCard::NewLC(iTemplate);
	TRAP(err, contactItem1 = iContactsDatabase->UpdateContactLC(con1, contact); 
		  CleanupStack::PopAndDestroy(contactItem1);
	);
	CleanupStack::PopAndDestroy( contact );
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	TRAP( err, 
			AddEmptyContactsL(1, EFalse);
			);
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	TRAP( err, 
			DeleteContactL(con1, EFalse);
			);
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	}

/**
Performs and Traps database transaction operations
all operations should leave with aError
*/
void CCompactAndRecoverStep::TransactionOperations(const TInt aError)
	{
	_LIT(KPrintErrors,"Expected error: %d and Observed error: %d");
	
	//begin transaction	
	TRAPD(err,	iContactsDatabase->DatabaseBeginL(EFalse); );
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	//perfrom crud operation
	TRAP_IGNORE( AddEmptyContactsL(1, EFalse) );
	
	//commit transaction
	TRAP(err,	iContactsDatabase->DatabaseCommitL(EFalse); );
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);	
	
	//begin transaction	
	TRAP(err,	iContactsDatabase->DatabaseBeginL(EFalse); );
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	
	//perfrom crud operation
	TRAP_IGNORE( AddEmptyContactsL(1, EFalse) );
	
	//rollback transaction
	TRAP(err,	
	        iContactsDatabase->DatabaseRollback();
	        User::After( 100000 );
	         );
	//rollback can't leave
	TESTPRINT( KErrNone == err);
	INFO_PRINTF3(KPrintErrors, KErrNone, err);
	}
	
/**
Performs and Traps simple database operations
all operations should leave with aError
*/
void CCompactAndRecoverStep::SimpleOperationsL(const TInt aError)
	{
	_LIT(KPrintErrors,"Expected error: %d and Observed error: %d");
	
	const TContactItemId KOwnCardId = iContactsDatabase->OwnCardId();
	TESTPRINT( KOwnCardId == -1 );
	
	CCntFilter *filter = CCntFilter::NewL();
	TRAPD(err,	iContactsDatabase->FilterDatabaseL( *filter ); );
	CLEAR( filter );
	TESTPRINT(aError == err);
	INFO_PRINTF3(KPrintErrors, aError, err);
	}

/**
Start asynchronous open while in compress/recover state
end compress/recover state
wait for open to be successfully completed
*/	
void CCompactAndRecoverStep::OpenAsyncTestL()
	{
	_LIT(KOpenAsync, "Open Async");
	_LIT(KEndAsync, "End Async");
	iCompleteSteps = EFalse;
	
	StartRecoverL();
	ALLPRINT(KOpenAsync);
	iContactOpenOperation = CContactDatabase::Open(iStatus);
	EndRecoverL();	
	User::WaitForRequest(iStatus);
	CLEAR( iContactOpenOperation );
	ALLPRINT( KEndAsync );	
	
	StartCompressL();
	ALLPRINT(KOpenAsync);
	iContactOpenOperation = CContactDatabase::Open(iStatus);
	EndCompressL();	
	User::WaitForRequest(iStatus);
	CLEAR( iContactOpenOperation );
	ALLPRINT( KEndAsync );	
	}