summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/cntperftest/src/testcontactviewunderlyingviewupdatestep.cpp
blob: 2b8ac0e3d5cd9070aad931e0b2dc14c2a54e1de8 (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
/*
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* 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: 
*
*/

 
#include "testcontactviewunderlyingviewupdatestep.h"

/**
 * Test Step Constructor
 */
CTestContactViewUnderlyingViewUpdateStep::CTestContactViewUnderlyingViewUpdateStep()
:CTestContactViewDatabaseUtilitiesStep()
	{
	// Mandatory call to base class method to set up the human readable name for logging.		
	SetTestStepName(KTestContactViewUnderLyingViewUpdateStep);	
	}			

/**
 * Base class pure virtual.
 * This function sets up the work envirnoment required by the test step
 * @return EPass or EFail indicating the result of the test step preamble operation.
 */
TVerdict CTestContactViewUnderlyingViewUpdateStep::doTestStepPreambleL()
	{
	CTestContactViewDatabaseUtilitiesStep::doTestStepPreambleL();
	return TestStepResult();
	}

/**
 *Base class pure virtual.
 *@return EPass or EFail indicating the result of the test step.
 */
TVerdict CTestContactViewUnderlyingViewUpdateStep::doTestStepL()
	{
	ConstructViewsL();
	ReadIniAndConstructViewUpdateObjectsL();	
	ReadIniAndConstructViewValidationObjectsL();	
	RemoveContactsFromTheUnderLyingViewsL();
	ListenForViewEventsAndValidateL();
 	ValidateViewCountL();
	return TestStepResult();
	}	

/**
 * Reads data specified in the ini file and constructs all relevant view update objects
 * These view update objects serve as source for performing underlying view update operations
 */
void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewUpdateObjectsL()
	{
	_LIT(KListOfViewsToBeRemoved, "ListOfViewsToBeUpdated");
	TPtrC listOfViewsToBeUpdated;
	TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeRemoved, listOfViewsToBeUpdated));

	RArray<TPtrC>	sections;
	CleanupClosePushL(sections);
	ViewUtilityReference().TokenizeStringL(listOfViewsToBeUpdated, sections);

	for ( TInt i = 0; i < sections.Count(); ++i )
		{
		TViewModificationData viewModificationData;

		// Here data is read from the ini file about various contact view update operations
		// to be performed. This information comprises of view to be updated and number of contacts
		// to be removed in the specified view
		_LIT(KContactViewType, "ViewType");
		TPtrC contactViewTypeString;
		GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString);
		viewModificationData.SetViewType(contactViewTypeString);

		_LIT(KContactViewIndex, "ViewIndex");
		TInt contactViewIndex;
		GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex);
		viewModificationData.SetViewIndex(contactViewIndex);

		_LIT(KNumberOfContactToBeRemoved, "NumberOfContactsToBeRemoved");
		TInt numberOfContactsToBeRemoved;
		GetIntFromConfig(sections[i], KNumberOfContactToBeRemoved, numberOfContactsToBeRemoved);
		viewModificationData.SetNumberOfContactsToBeRemoved(numberOfContactsToBeRemoved);

		iViewUpdateArray.AppendL(viewModificationData);
		}

	CleanupStack::PopAndDestroy(&sections); 
	}
	
	
/**
 * Reads data specified in the ini file and constructs all view validation objects
 */
void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewValidationObjectsL()
	{
	_LIT(KListOfViewsToBeValidated, "ListOfViewsToBeValidated");
	TPtrC listOfViewsToBeRemoved;
	TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeValidated, listOfViewsToBeRemoved));

	RArray<TPtrC>	sections;
	CleanupClosePushL(sections);
	ViewUtilityReference().TokenizeStringL(listOfViewsToBeRemoved, sections);

	for ( TInt i = 0; i < sections.Count(); ++i )
		{
		TViewValidationData ViewValidationData;

		_LIT(KContactViewType, "ViewType");
		TPtrC contactViewTypeString;
		GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString);
		ViewValidationData.SetViewType(contactViewTypeString);

		_LIT(KContactViewIndex, "ViewIndex");
		TInt contactViewIndex;
		GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex);
		ViewValidationData.SetViewIndex(contactViewIndex);

		_LIT(KUpdatedViewCount, "UpdatedViewCount");
		TInt updatedViewCount = 0;
		GetIntFromConfig(sections[i], KUpdatedViewCount, updatedViewCount);
		ViewValidationData.SetExpectedViewCount(updatedViewCount);

		iViewValidationArray.AppendL(ViewValidationData);
		}

	CleanupStack::PopAndDestroy(&sections); 
	}



/**
 * Removes contacts from the underlying view based on the data available with contact view update objects
 */ 
void CTestContactViewUnderlyingViewUpdateStep::RemoveContactsFromTheUnderLyingViewsL()
	{
	for(TInt i = 0; i < iViewUpdateArray.Count(); ++i)
		{
		TViewModificationData contactViewValidationObject = iViewUpdateArray[i];		
		CContactViewBase* contactView = ViewCollectionReference().GetDesiredView
							(contactViewValidationObject.ViewTypeInStringFormat(), contactViewValidationObject.ViewIndex());
	

		RArray<TContactItemId> contactItemIdArray;
		CleanupClosePushL(contactItemIdArray);
		
		for(TInt j = 0; j < contactViewValidationObject.NumberOfContactsToBeRemoved(); ++j)
			{
			TContactItemId contactItemId = contactView->AtL(j);
			contactItemIdArray.AppendL(contactItemId);
			}

		for(TInt j = 0; j < contactItemIdArray.Count(); ++j)
			{
			DatabaseReference().DeleteContactL(contactItemIdArray[j]);
			}
			
		CleanupStack::PopAndDestroy(&contactItemIdArray); 
		}
	}

/** 
 * Listens for contact view notifications and validates that only remove contact item events are received
 */
void CTestContactViewUnderlyingViewUpdateStep::ListenForViewEventsAndValidateL()
	{
	TContactViewEvent contactViewEvent;
	while(CTestContactViewDatabaseUtilitiesStep::ListenForViewEventsL(contactViewEvent))
		{
		if(contactViewEvent.iEventType != TContactViewEvent::EItemRemoved)
			{
			_LIT(KUndesiredContactViewEvent, " An undesired contact view event i.e. a contact view event other than remove item contact event was received was received : %d");
			ERR_PRINTF2(KUndesiredContactViewEvent, contactViewEvent.iEventType);
			SetTestStepResult(EFail);
			}
		}		
	}

/**
 * Validates the contact view count against expected data specified in the contact view validation objects
 */
void CTestContactViewUnderlyingViewUpdateStep::ValidateViewCountL()
	{
	for(TInt i = 0; i < iViewValidationArray.Count(); ++i)
		{
		TViewValidationData validationInfo =	iViewValidationArray[i];
		CContactViewBase* contactView = ViewCollectionReference().GetDesiredView(validationInfo.ViewTypeInStringFormat(), validationInfo.ViewIndex());

		if(contactView->CountL() != validationInfo.ExpectedViewCount())
			{
			_LIT(KErrContactViewMisMatch, "The contact view doesnt reflect the desired view count \n");
			ERR_PRINTF1(KErrContactViewMisMatch);
			
			_LIT(KInfoViewCountData, "The expected view count is %d while the actual view count is %d \n");
			INFO_PRINTF3(KInfoViewCountData, validationInfo.ExpectedViewCount(), contactView->CountL());
			
			SetTestStepResult(EFail);
			}
		}
	}

/**
 * Converts the view type information in TViewData::TContactViewType to string format 
 */
void TViewData::ConvertViewTypeToString(TViewData::TContactViewType aViewType, TDes& aViewTypeInString)
	{
	if ( aViewType == TViewData::ELocalView )
		{
		aViewTypeInString.Copy(KLocalView);
		}
	else if ( aViewType == TViewData::ERemoteView)
		{
		aViewTypeInString.Copy(KRemoteView);
		}
	else if ( aViewType == TViewData::ENamedRemoteView)
		{
		aViewTypeInString.Copy(KNamedRemoteView);
		}
	else if ( aViewType == TViewData::EGroupView)
		{
		aViewTypeInString.Copy(KGroupView);
		}
	else if ( aViewType == TViewData::EFindView)
		{
		aViewTypeInString.Copy(KFindView);
		}
	else if ( aViewType == TViewData::EFilteredView)
		{
		aViewTypeInString.Copy(KFilteredView);
		}
	else if ( aViewType == TViewData::EConcatenatedView)
		{
		aViewTypeInString.Copy(KConcatenatedView);
		}
	else if ( aViewType == TViewData::ESubView)
		{
		aViewTypeInString.Copy(KSubView);
		}
	}

/**
 * Converts the view type information available in string format to  TViewData::TContactViewType
 * @param aViewTypeString view type information in string format
 * @return TViewData::TContactViewType - view type information in TViewData::TContactViewType format
 */
TViewData::TContactViewType TViewData::ConvertViewType(const TPtrC& aViewTypeString)
	{
	TViewData::TContactViewType viewType = TViewData::ELocalView;

	if ( aViewTypeString.Compare(KLocalView) == 0 )
		{
		viewType = TViewData::ELocalView;
		}
	else if ( aViewTypeString.Compare(KRemoteView) == 0 )
		{
		viewType = TViewData::ERemoteView;
		}
	else if ( aViewTypeString.Compare(KNamedRemoteView) == 0 )
		{
		viewType = TViewData::ENamedRemoteView;
		}
	else if ( aViewTypeString.Compare(KGroupView) == 0 )
		{
		viewType = TViewData::EGroupView;
		}
	else if ( aViewTypeString.Compare(KFindView) == 0 )
		{
		viewType = TViewData::EFindView;
		}
	else if ( aViewTypeString.Compare(KFilteredView) == 0 )
		{
		viewType = TViewData::EFilteredView;
		}
	else if ( aViewTypeString.Compare(KConcatenatedView) == 0 )
		{
		viewType = TViewData::EConcatenatedView;
		}
	else if ( aViewTypeString.Compare(KSubView) == 0 )
		{
		viewType = TViewData::ESubView;
		}

	return 	viewType;
	}