summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/cntperftest/src/viewdefcustomfieldstest.cpp
blob: 1edd46a1217dcfcf16a4d0c354637cdc356fcef7 (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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
* 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 <e32panic.h>
#include <test/testexecutelog.h>
#include <cntfldst.h>
#include "clientserver.h"
#include "viewdefcustomfieldstest.h"

_LIT(KRun1,"AllLabelUid");
_LIT(KRun2,"AllNewFields");
_LIT(KRun3,"AllOnlyNew");
_LIT(KRun4,"ExistingLabelUid");
_LIT(KRun5,"ExistingNewFields");
_LIT(KRun6,"ExistingOnlyNew");

_LIT(KTest1,"Testing KUidContactFieldMatchAll in viewdef with custom labels/uids...");
_LIT(KTest2,"Testing KUidContactFieldMatchAll in viewdef with new fields...");
_LIT(KTest3,"Testing KUidContactFieldMatchAll in viewdef with only new fields...");
_LIT(KTest4,"Testing Multiple Exisiting & Custom Uids in viewdef with custom labels/uids...");
_LIT(KTest5,"Testing Multiple Exisiting & Custom Uids in viewdef with new fields...");
_LIT(KTest6,"Testing Multiple Exisiting & Custom Uids in viewdef with only new fields...");

const static TInt KCustomUidCount = 100;

//Number of contacts
CViewDefCustomFieldsTest::CViewDefCustomFieldsTest():CViewDefBase(1)
/**
 * Constructor
 */
	{
	// Call base class method to set up the human readable name for logging
	SetTestStepName(SharedConstants::KViewDefCustomFieldsTest);
	}

TVerdict CViewDefCustomFieldsTest::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 */
	{
	
	__UHEAP_MARK;
		
	InitializeL();
	iIterate->Reset();
	
	const TDesC &run = ConfigSection();
	
	if( run == KRun1 )
		{
		INFO_PRINTF1(KTest1);
		MatchAllTestsL( iIterate->NextL() );
		}
	else if( run == KRun2 )
		{
		INFO_PRINTF1(KTest2);
		NewFieldsMATestsL( iIterate->NextL(), EFalse );
		}
	else if( run == KRun3 )
		{
		INFO_PRINTF1(KTest3);
		NewFieldsMATestsL( iIterate->NextL(), ETrue );
		}
	else if( run == KRun4 )
		{
		INFO_PRINTF1(KTest4);
		ManyUidsTestsL( iIterate->NextL() );
		}
	else if( run == KRun5 )
		{
		INFO_PRINTF1(KTest5);
		NewFieldsMUITestsL( iIterate->NextL(), EFalse );
		}
	else if( run == KRun6 )
		{
		INFO_PRINTF1(KTest6);
		NewFieldsMUITestsL( iIterate->NextL(), ETrue );
		}
	else
		{
		MissngTestPanic();
		}
	
	Cleanup();
	
	__UHEAP_MARKEND;
	
	return TestStepResult();
	}

void CViewDefCustomFieldsTest::MatchAllTestsL(const TContactItemId &aCid)
	{
	TInt fields = 0;
	
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	SetContactFieldsL(*iContactItem);
	SetContactLabelsL(*iContactItem);
	AddUIDsL(*iFields,TestConstants::KInitialUID);
	fields = iFields->Count();	
	CommitL();

	iViewII->AddL(KUidContactFieldMatchAll);
	iViewIM->AddL(KUidContactFieldMatchAll);
	iViewMM->AddL(KUidContactFieldMatchAll);
	
	SINGLECOMPARE( doAllMatchL( aCid, *iViewII, fields, EFalse, EFalse ), 0, 0 );
	SINGLECOMPARE( doAllMatchL( aCid, *iViewIM, fields, EFalse, ETrue ), 0, 0 );
	SINGLECOMPARE( doAllMatchL( aCid, *iViewMM, fields, ETrue, ETrue ), 0, 0 );
	
	iViewII->Reset();
	iViewIM->Reset();
	iViewMM->Reset();
	}

void CViewDefCustomFieldsTest::NewFieldsMATestsL(const TContactItemId &aCid, const TBool aOnlyNew)
	{
	TInt fields = 0;
	const static TInt newFields = 10;
	
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	if(aOnlyNew)
		{
		iFields->Reset();
		}
	for(TInt i = 0, uids = TestConstants::KAltUID; i < newFields; i++, uids++)
		{
		AddNewFieldL( *iFields, TestConstants::KShortString, TFieldType::Uid(uids) );
		}
	SetContactFieldsL(*iContactItem);
	fields = iFields->Count();	
	CommitL();

	iViewII->AddL(KUidContactFieldMatchAll);
	iViewIM->AddL(KUidContactFieldMatchAll);
	iViewMM->AddL(KUidContactFieldMatchAll);
	
	SINGLECOMPARE( doAllMatchL( aCid, *iViewII, fields, EFalse, EFalse, aOnlyNew ), 0, 0  );
	SINGLECOMPARE( doAllMatchL( aCid, *iViewIM, fields, EFalse, ETrue, aOnlyNew ), 0, 0  );
	SINGLECOMPARE( doAllMatchL( aCid, *iViewMM, fields, ETrue, ETrue, aOnlyNew ), 0, 0  );
	
	iViewII->Reset();
	iViewIM->Reset();
	iViewMM->Reset();
	}


TBool CViewDefCustomFieldsTest::doAllMatchL(const TContactItemId &aCid, const CContactItemViewDef &aView,
											const TInt aFieldCount, const TBool aZeroN, 
											const TBool aZeroH, const TBool aNew )
	{
	TBool SingleTestResult = EFalse;
	TBool OverallTestResult = ETrue;
	
	TInt countM = 0;
	TInt countR = 0;
	TInt emptyfsM = 0;
	TInt emptyfsR = 0;
	TInt hcountM = 0;
	TInt hcountR = 0;
	
	ReadL(aCid,*iViewAll,EFalse);
	countR = iFields->Count();
	hcountR = CountHiddenFields(*iFields);
	emptyfsR = CountEmpty(*iFields);
	Close();
	
	ReadMinimalL(aCid, aView, *iDefView, EFalse);
	countM = iFields->Count();
	hcountM = CountHiddenFields(*iFields);
	emptyfsM = CountEmpty(*iFields);
	Close();
	
	if(aNew)
		{
		countR -= emptyfsR;
		emptyfsR = 0;
		hcountR = 0;
		}
	
	SingleTestResult = INTCOMPARE(countR , ==,  aFieldCount, 0, 0 ); 
	OverallTestResult = OverallTestResult && SingleTestResult;
	
	SingleTestResult = INTCOMPARE(emptyfsM , ==,  0, 0, 0 ); 
	OverallTestResult = OverallTestResult && SingleTestResult;
	
	SingleTestResult = INTCOMPARE(emptyfsR , ==,  0, 0, 0 );
	
	if(aZeroN)
		{
		SingleTestResult = INTCOMPARE( (countM - hcountM), <=, 0, 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
	else
		{
		SingleTestResult = INTCOMPARE( (countM - hcountM) , ==,  (countR - hcountR) , 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
		
	if(aZeroH)
		{
		SingleTestResult = INTCOMPARE(hcountM , ==,  0, 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
	else
		{
		SingleTestResult = INTCOMPARE(hcountR , ==,  hcountM, 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
		
	return OverallTestResult;
	
	}

void CViewDefCustomFieldsTest::ManyUidsTestsL(const TContactItemId &aCid)
	{
	TInt fields = 0;
	
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	SetContactFieldsL(*iContactItem);
	SetContactLabelsL(*iContactItem);
	AddUIDsL(*iFields,TestConstants::KInitialUID);
	fields = iFields->Count();	
	CommitL();

	const TInt length = iExistingUidsArray->Count() - 1;
	TInt i(0);
	for(; i < length;)
		{	
		AddMultipleUidsL(*iViewII, i, 1);
		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, 0 );
		iViewII->Reset();
		}
		
	const TInt flength = KCustomUidCount - 1;
	for(i = 0; i < flength;)
		{	
		AddMultipleCustomUidsL(*iViewII, i, 1);
		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, i );
		iViewII->Reset();
		}
	}

void CViewDefCustomFieldsTest::NewFieldsMUITestsL(const TContactItemId &aCid, const TBool aOnlyNew)
	{
	TInt fields = 0;
	const static TInt newFields = 10;
	
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	if(aOnlyNew)
		{
		iFields->Reset();
		}
	TInt i(0);
	for(TInt uids = TestConstants::KInitialUID; i < newFields; i++, uids++)
		{
		AddNewFieldL( *iFields, TestConstants::KShortString, TFieldType::Uid(uids) );
		}
	SetContactFieldsL(*iContactItem);
	fields = iFields->Count();	
	CommitL();

	const TInt length = iExistingUidsArray->Count()-1;
	for(i = 0; i < length;)
		{	
		AddMultipleUidsL(*iViewII, i, 1);
		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ) , i, 0 );
		iViewII->Reset();
		}
		
	const TInt flength = KCustomUidCount - 1;
	for(i = 0; i < flength;)
		{	
		AddMultipleCustomUidsL(*iViewII, i, 1);
		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, 0 );
		iViewII->Reset();
		}
	}
	
TBool CViewDefCustomFieldsTest::doManyUidsL(const TContactItemId &aCid, const CContactItemViewDef &aView,
											const TInt aFieldCount, const TBool aExcludeN, 
											const TBool aExcludeH )
	{
	TBool SingleTestResult = EFalse;
	TBool OverallTestResult = ETrue;
	
	TInt countM = 0;
	TInt countR = 0;
	TInt fieldsIV = 0;

	TInt emptyfsR = 0;
	TInt hcountM = 0;
	TInt hcountR = 0;
	TInt hfieldsIV = 0;
	
	ReadL(aCid,*iViewAll,EFalse);
	FieldsInView(aView, fieldsIV, hfieldsIV, ETrue);
	countR = iFields->Count();
	hcountR = CountHiddenFields(*iFields);
	emptyfsR = CountEmpty(*iFields);
	Close();
	
	ReadMinimalL(aCid, aView, *iDefView, EFalse);
	countM = iFields->Count();
	hcountM = CountHiddenFields(*iFields);

	Close();
	
	SingleTestResult = INTCOMPARE( (countR - emptyfsR) , ==,  aFieldCount, 0, 0 ); 
	OverallTestResult = OverallTestResult && SingleTestResult;
	
	if(aExcludeN)
		{
		SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , 0, 0 ); 
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
	else
		{
		SingleTestResult = INTCOMPARE(  fieldsIV  , ==,  (countM - hcountM) , 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
	if(aExcludeH)
		{
		SingleTestResult = INTCOMPARE(  (hcountR - hfieldsIV) , ==,  hcountM , 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
	else
		{
		SingleTestResult = INTCOMPARE(  hcountM , ==,  hfieldsIV , 0, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		}
		
	return OverallTestResult;
	}

void CViewDefCustomFieldsTest::AddMultipleCustomUidsL( CContactItemViewDef &aView, TInt &aPos, const TInt &aMany )
	{
	
	static TInt lastPlace = 0;	
	aView.Reset();
	aView.AddL( TUid::Uid( TestConstants::KInitialUID + aPos ) );
	
	for(TInt i = 0; (lastPlace < KCustomUidCount) && (i < aMany); ++lastPlace, ++i)
		{
		if(lastPlace == aPos)
			{
			--i;
			continue;
			}
		aView.AddL( TUid::Uid( TestConstants::KInitialUID + lastPlace ) );
		}
	if( lastPlace == KCustomUidCount )
		{
		lastPlace = 0;
		++aPos;//this should never equal count
		_LIT(KNextCustom,"nextCustom %d");
		INFO_PRINTF2(KNextCustom, aPos);
		}
		
	}