summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/cntperftest/src/viewdefanyfieldstest.cpp
blob: 2d04c936b7cf1cb4fe14160a35040723ae5cdae0 (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
/*
* 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 <test/testexecutelog.h>
#include <cntfldst.h>
#include "clientserver.h"
#include "viewdefanyfieldstest.h"
#include "cntstd.h"

_LIT(KRun1,"SingleConfig");
_LIT(KRun2,"UniqueConfig");
_LIT(KRun3,"RepeatConfig");

_LIT(KTest1,"Testing all uids in viewdef in single configurations...");
_LIT(KTest2,"Testing all uids in viewdef in multiple unique configurations...");
_LIT(KTest3,"Testing all uids in viewdef in multiple repeat configurations...");

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

TVerdict CViewDefAnyFieldsTest::doTestStepL()
	{
	
	__UHEAP_MARK;
	
	
	InitializeL();
	iIterate->Reset();
	
	const TDesC &run = ConfigSection();
	
	if( run == KRun1 )
		{
		INFO_PRINTF1(KTest1);
		doAnyFieldsTestL(iIterate->NextL());
		}
	else if( run == KRun2 )
		{
		INFO_PRINTF1(KTest2);
		doUniqueUidsTestL(iIterate->NextL());
		}
	else if( run == KRun3 )
		{
		//this panics as only one instance of a uid is allowed within a viewdef
		//only panics in debug mode
		#ifdef _DEBUG
		
		INFO_PRINTF1(KTest3);
		doIdenticalUidsTestL(iIterate->NextL());
		
		#else
		
		INFO_PRINTF1(KTest3);
		_LIT(KTestPanic,"TestPanic");
		User::Panic(KTestPanic, ECntPanicDuplicateViewFields);
		
		#endif
		}
	else
		{
		MissngTestPanic();
		}
	
	Cleanup();
	
	__UHEAP_MARKEND;
	
	return TestStepResult();
	}
	
/**
tests loading aCid with different viewdefs, it is tested with all possible uids for each viewdef,
check to see that expected fields are excluded/included
*/
void CViewDefAnyFieldsTest::doAnyFieldsTestL(const TContactItemId &aCid)
	{
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	SetContactFieldsL(*iContactItem);	
	CommitL();
	/*viewdefs ignore primary mappings stored as mapping in contenttype rather
	than within the array*/
	SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse), 0, 0);
	//hidden is reversed
	SINGLECOMPARE( FieldCountCompL(aCid, *iViewMI, ETrue, ETrue), 0, 0 );
	//"all" hidden fields are excluded
	SINGLECOMPARE( FieldCountCompL(aCid, *iViewIM, EFalse, ETrue, ETrue), 0, 0 );
	//"all" hidden fields are excluded
	SINGLECOMPARE( FieldCountCompL(aCid, *iViewMM, ETrue, ETrue, ETrue), 0, 0 );
	}
	
/**
attempt to load aCid with viewdef containing multiple(2) unique(existing) uids, 
check to see that expected fields are excluded/included
*/
void CViewDefAnyFieldsTest::doUniqueUidsTestL(const TContactItemId &aCid)
	{
	OpenL(aCid,*iViewAll, EFalse);//ETrue);
	SetContactFieldsL(*iContactItem);	
	CommitL();
	//multiple uniques uids
	SINGLECOMPARE( MultipleUidCountCompL(aCid, *iViewII, EFalse, EFalse),0 ,0 );
	}
/**
attempt to load aCid with viewdef containing multiple identical uids, this test
will panic in debug mode as CContactItemViewDef does not allow multiple identical uids
*/
void CViewDefAnyFieldsTest::doIdenticalUidsTestL(const TContactItemId &aCid)
	{
	OpenL(aCid,*iViewAll, EFalse);// ETrue);
	SetContactFieldsL(*iContactItem);	
	CommitL();
	//multiple identical uids
	SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse, EFalse, ETrue), 0 , 0 );
	}

TBool CViewDefAnyFieldsTest::FieldCountCompL(	const TContactItemId &aCid,
												CContactItemViewDef &aView, 
												const TBool aExcludeN, 
												const TBool aExcludeH,
												const TBool aZeroH,
												const TBool aMultiple)
	{
	TBool SingleTestResult = EFalse;
	TBool OverallTestResult = EFalse;
	
	TInt countM = 0;
	TInt countR = 0;
	TInt fieldsIV = 0;
	TInt emptyfsM = 0;
	TInt emptyfsR = 0;
	TInt hcountM = 0;
	TInt hcountR = 0;
	TInt hfieldsIV = 0;
	
	TInt length = 0;
	
	length = iExistingUidsArray->Count();
	
	for(TInt i = 0, j = 0; i < length;)
		{
		OverallTestResult = EFalse;
		if( (*iExistingUidsArray)[i] == 0 )
			{
			++i;
			continue;
			}
		aView.AddL(TUid::Uid((*iExistingUidsArray)[i]));
		
		ReadL(aCid,*iViewAll,EFalse);
		FieldsInView(aView, fieldsIV, hfieldsIV);
		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();
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsM, i, 0 );
		OverallTestResult = SingleTestResult;
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsR, i, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		SingleTestResult = INTCOMPARE( hcountR , >,  0 , i, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		
		if(aExcludeN)
			{
			SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		else
			{
			SingleTestResult = INTCOMPARE( fieldsIV  , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		if(aExcludeH)
			{
			if( aZeroH)
				{
				SingleTestResult = INTCOMPARE( 0 , ==,  hcountM, i, 0 );
				OverallTestResult = OverallTestResult && SingleTestResult;	
				}
			else
				{
				SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==,  hcountM , i, 0 );
				OverallTestResult = OverallTestResult && SingleTestResult;
				}
			}
		else
			{
			SingleTestResult = INTCOMPARE( hcountM , ==,  hfieldsIV , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;	
			}
		
		
		if(!OverallTestResult)
			{
			break;
			}
			
		if(aMultiple)
			{
			++j;
			if(4 == j)
				{
				j = 0;
				++i;
				aView.Reset();
				}
			}
		else
			{
			++i;
			aView.Reset();
			}
			
		countM = 0;
		countR = 0;
		fieldsIV = 0;
		emptyfsM = 0;
		emptyfsR = 0;
		hcountM = 0;
		hcountR = 0;
		hfieldsIV = 0;
		
		}
	return OverallTestResult;
	}

TBool CViewDefAnyFieldsTest::MultipleUidCountCompL(	const TContactItemId &aCid,
													CContactItemViewDef &aView, 
													const TBool aExcludeN, 
													const TBool aExcludeH
													)
	{
	TBool SingleTestResult = EFalse;
	TBool OverallTestResult = EFalse;
	
	const TInt KManyUids = 1;//number of additional uids
	TInt countM = 0;
	TInt countR = 0;
	TInt fieldsIV = 0;
	TInt emptyfsM = 0;
	TInt emptyfsR = 0;
	TInt hcountM = 0;
	TInt hcountR = 0;
	TInt hfieldsIV = 0;
	
	const TInt length = iExistingUidsArray->Count()-1;
	
	for(TInt i = 0; i < length;)
		{
		OverallTestResult = EFalse;
		AddMultipleUidsL(aView, i, KManyUids);
		
		ReadL(aCid,*iViewAll,EFalse);
		
		FieldsInView(aView, fieldsIV, hfieldsIV);
				
		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();
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsM, i, 0 ); 
		OverallTestResult = SingleTestResult;
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsR, i, 0 ); 
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		SingleTestResult = INTCOMPARE( hcountR , >,  0 , i, 0 ); 
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		if(aExcludeN)
			{
			SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		else
			{
			SingleTestResult = INTCOMPARE( fieldsIV  , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		if(aExcludeH)
			{
			SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==,  hcountM , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		else
			{
			SingleTestResult = INTCOMPARE( hcountM , ==,  hfieldsIV , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		
		if(!OverallTestResult)
			{
			break;
			}
			
		countM = 0;
		countR = 0;
		fieldsIV = 0;
		emptyfsM = 0;
		emptyfsR = 0;
		hcountM = 0;
		hcountR = 0;
		hfieldsIV = 0;
		
		}
	return OverallTestResult;
	}