|
1 // Copyright (c) 2007-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 #include "TestContactViewUnderLyingViewUpdateStep.h" |
|
17 |
|
18 /** |
|
19 * Test Step Constructor |
|
20 */ |
|
21 CTestContactViewUnderlyingViewUpdateStep::CTestContactViewUnderlyingViewUpdateStep() |
|
22 :CTestContactViewDatabaseUtilitiesStep() |
|
23 { |
|
24 // Mandatory call to base class method to set up the human readable name for logging. |
|
25 SetTestStepName(KTestContactViewUnderLyingViewUpdateStep); |
|
26 } |
|
27 |
|
28 /** |
|
29 * Base class pure virtual. |
|
30 * This function sets up the work envirnoment required by the test step |
|
31 * @return EPass or EFail indicating the result of the test step preamble operation. |
|
32 */ |
|
33 TVerdict CTestContactViewUnderlyingViewUpdateStep::doTestStepPreambleL() |
|
34 { |
|
35 CTestContactViewDatabaseUtilitiesStep::doTestStepPreambleL(); |
|
36 return TestStepResult(); |
|
37 } |
|
38 |
|
39 /** |
|
40 *Base class pure virtual. |
|
41 *@return EPass or EFail indicating the result of the test step. |
|
42 */ |
|
43 TVerdict CTestContactViewUnderlyingViewUpdateStep::doTestStepL() |
|
44 { |
|
45 ConstructViewsL(); |
|
46 ReadIniAndConstructViewUpdateObjectsL(); |
|
47 ReadIniAndConstructViewValidationObjectsL(); |
|
48 RemoveContactsFromTheUnderLyingViewsL(); |
|
49 ListenForViewEventsAndValidateL(); |
|
50 ValidateViewCountL(); |
|
51 return TestStepResult(); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Reads data specified in the ini file and constructs all relevant view update objects |
|
56 * These view update objects serve as source for performing underlying view update operations |
|
57 */ |
|
58 void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewUpdateObjectsL() |
|
59 { |
|
60 _LIT(KListOfViewsToBeRemoved, "ListOfViewsToBeUpdated"); |
|
61 TPtrC listOfViewsToBeUpdated; |
|
62 TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeRemoved, listOfViewsToBeUpdated)); |
|
63 |
|
64 RArray<TPtrC> sections; |
|
65 CleanupClosePushL(sections); |
|
66 ViewUtilityReference().TokenizeStringL(listOfViewsToBeUpdated, sections); |
|
67 |
|
68 for ( TInt i = 0; i < sections.Count(); ++i ) |
|
69 { |
|
70 TViewModificationData viewModificationData; |
|
71 |
|
72 // Here data is read from the ini file about various contact view update operations |
|
73 // to be performed. This information comprises of view to be updated and number of contacts |
|
74 // to be removed in the specified view |
|
75 _LIT(KContactViewType, "ViewType"); |
|
76 TPtrC contactViewTypeString; |
|
77 GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString); |
|
78 viewModificationData.SetViewType(contactViewTypeString); |
|
79 |
|
80 _LIT(KContactViewIndex, "ViewIndex"); |
|
81 TInt contactViewIndex; |
|
82 GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex); |
|
83 viewModificationData.SetViewIndex(contactViewIndex); |
|
84 |
|
85 _LIT(KNumberOfContactToBeRemoved, "NumberOfContactsToBeRemoved"); |
|
86 TInt numberOfContactsToBeRemoved; |
|
87 GetIntFromConfig(sections[i], KNumberOfContactToBeRemoved, numberOfContactsToBeRemoved); |
|
88 viewModificationData.SetNumberOfContactsToBeRemoved(numberOfContactsToBeRemoved); |
|
89 |
|
90 iViewUpdateArray.AppendL(viewModificationData); |
|
91 } |
|
92 |
|
93 CleanupStack::PopAndDestroy(§ions); |
|
94 } |
|
95 |
|
96 |
|
97 /** |
|
98 * Reads data specified in the ini file and constructs all view validation objects |
|
99 */ |
|
100 void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewValidationObjectsL() |
|
101 { |
|
102 _LIT(KListOfViewsToBeValidated, "ListOfViewsToBeValidated"); |
|
103 TPtrC listOfViewsToBeRemoved; |
|
104 TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeValidated, listOfViewsToBeRemoved)); |
|
105 |
|
106 RArray<TPtrC> sections; |
|
107 CleanupClosePushL(sections); |
|
108 ViewUtilityReference().TokenizeStringL(listOfViewsToBeRemoved, sections); |
|
109 |
|
110 for ( TInt i = 0; i < sections.Count(); ++i ) |
|
111 { |
|
112 TViewValidationData ViewValidationData; |
|
113 |
|
114 _LIT(KContactViewType, "ViewType"); |
|
115 TPtrC contactViewTypeString; |
|
116 GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString); |
|
117 ViewValidationData.SetViewType(contactViewTypeString); |
|
118 |
|
119 _LIT(KContactViewIndex, "ViewIndex"); |
|
120 TInt contactViewIndex; |
|
121 GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex); |
|
122 ViewValidationData.SetViewIndex(contactViewIndex); |
|
123 |
|
124 _LIT(KUpdatedViewCount, "UpdatedViewCount"); |
|
125 TInt updatedViewCount = 0; |
|
126 GetIntFromConfig(sections[i], KUpdatedViewCount, updatedViewCount); |
|
127 ViewValidationData.SetExpectedViewCount(updatedViewCount); |
|
128 |
|
129 iViewValidationArray.AppendL(ViewValidationData); |
|
130 } |
|
131 |
|
132 CleanupStack::PopAndDestroy(§ions); |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 /** |
|
138 * Removes contacts from the underlying view based on the data available with contact view update objects |
|
139 */ |
|
140 void CTestContactViewUnderlyingViewUpdateStep::RemoveContactsFromTheUnderLyingViewsL() |
|
141 { |
|
142 for(TInt i = 0; i < iViewUpdateArray.Count(); ++i) |
|
143 { |
|
144 TViewModificationData contactViewValidationObject = iViewUpdateArray[i]; |
|
145 CContactViewBase* contactView = ViewCollectionReference().GetDesiredView |
|
146 (contactViewValidationObject.ViewTypeInStringFormat(), contactViewValidationObject.ViewIndex()); |
|
147 |
|
148 |
|
149 RArray<TContactItemId> contactItemIdArray; |
|
150 CleanupClosePushL(contactItemIdArray); |
|
151 |
|
152 for(TInt j = 0; j < contactViewValidationObject.NumberOfContactsToBeRemoved(); ++j) |
|
153 { |
|
154 TContactItemId contactItemId = contactView->AtL(j); |
|
155 contactItemIdArray.AppendL(contactItemId); |
|
156 } |
|
157 |
|
158 for(TInt j = 0; j < contactItemIdArray.Count(); ++j) |
|
159 { |
|
160 DatabaseReference().DeleteContactL(contactItemIdArray[j]); |
|
161 } |
|
162 |
|
163 CleanupStack::PopAndDestroy(&contactItemIdArray); |
|
164 } |
|
165 } |
|
166 |
|
167 /** |
|
168 * Listens for contact view notifications and validates that only remove contact item events are received |
|
169 */ |
|
170 void CTestContactViewUnderlyingViewUpdateStep::ListenForViewEventsAndValidateL() |
|
171 { |
|
172 TContactViewEvent contactViewEvent; |
|
173 while(CTestContactViewDatabaseUtilitiesStep::ListenForViewEventsL(contactViewEvent)) |
|
174 { |
|
175 if(contactViewEvent.iEventType != TContactViewEvent::EItemRemoved) |
|
176 { |
|
177 _LIT(KUndesiredContactViewEvent, " An undesired contact view event i.e. a contact view event other than remove item contact event was received was received : %d"); |
|
178 ERR_PRINTF2(KUndesiredContactViewEvent, contactViewEvent.iEventType); |
|
179 SetTestStepResult(EFail); |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 /** |
|
185 * Validates the contact view count against expected data specified in the contact view validation objects |
|
186 */ |
|
187 void CTestContactViewUnderlyingViewUpdateStep::ValidateViewCountL() |
|
188 { |
|
189 for(TInt i = 0; i < iViewValidationArray.Count(); ++i) |
|
190 { |
|
191 TViewValidationData validationInfo = iViewValidationArray[i]; |
|
192 CContactViewBase* contactView = ViewCollectionReference().GetDesiredView(validationInfo.ViewTypeInStringFormat(), validationInfo.ViewIndex()); |
|
193 |
|
194 if(contactView->CountL() != validationInfo.ExpectedViewCount()) |
|
195 { |
|
196 _LIT(KErrContactViewMisMatch, "The contact view doesnt reflect the desired view count \n"); |
|
197 ERR_PRINTF1(KErrContactViewMisMatch); |
|
198 |
|
199 _LIT(KInfoViewCountData, "The expected view count is %d while the actual view count is %d \n"); |
|
200 INFO_PRINTF3(KInfoViewCountData, validationInfo.ExpectedViewCount(), contactView->CountL()); |
|
201 |
|
202 SetTestStepResult(EFail); |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 /** |
|
208 * Converts the view type information in TViewData::TContactViewType to string format |
|
209 */ |
|
210 void TViewData::ConvertViewTypeToString(TViewData::TContactViewType aViewType, TDes& aViewTypeInString) |
|
211 { |
|
212 if ( aViewType == TViewData::ELocalView ) |
|
213 { |
|
214 aViewTypeInString.Copy(KLocalView); |
|
215 } |
|
216 else if ( aViewType == TViewData::ERemoteView) |
|
217 { |
|
218 aViewTypeInString.Copy(KRemoteView); |
|
219 } |
|
220 else if ( aViewType == TViewData::ENamedRemoteView) |
|
221 { |
|
222 aViewTypeInString.Copy(KNamedRemoteView); |
|
223 } |
|
224 else if ( aViewType == TViewData::EGroupView) |
|
225 { |
|
226 aViewTypeInString.Copy(KGroupView); |
|
227 } |
|
228 else if ( aViewType == TViewData::EFindView) |
|
229 { |
|
230 aViewTypeInString.Copy(KFindView); |
|
231 } |
|
232 else if ( aViewType == TViewData::EFilteredView) |
|
233 { |
|
234 aViewTypeInString.Copy(KFilteredView); |
|
235 } |
|
236 else if ( aViewType == TViewData::EConcatenatedView) |
|
237 { |
|
238 aViewTypeInString.Copy(KConcatenatedView); |
|
239 } |
|
240 else if ( aViewType == TViewData::ESubView) |
|
241 { |
|
242 aViewTypeInString.Copy(KSubView); |
|
243 } |
|
244 } |
|
245 |
|
246 /** |
|
247 * Converts the view type information available in string format to TViewData::TContactViewType |
|
248 * @param aViewTypeString view type information in string format |
|
249 * @return TViewData::TContactViewType - view type information in TViewData::TContactViewType format |
|
250 */ |
|
251 TViewData::TContactViewType TViewData::ConvertViewType(const TPtrC& aViewTypeString) |
|
252 { |
|
253 TViewData::TContactViewType viewType = TViewData::ELocalView; |
|
254 |
|
255 if ( aViewTypeString.Compare(KLocalView) == 0 ) |
|
256 { |
|
257 viewType = TViewData::ELocalView; |
|
258 } |
|
259 else if ( aViewTypeString.Compare(KRemoteView) == 0 ) |
|
260 { |
|
261 viewType = TViewData::ERemoteView; |
|
262 } |
|
263 else if ( aViewTypeString.Compare(KNamedRemoteView) == 0 ) |
|
264 { |
|
265 viewType = TViewData::ENamedRemoteView; |
|
266 } |
|
267 else if ( aViewTypeString.Compare(KGroupView) == 0 ) |
|
268 { |
|
269 viewType = TViewData::EGroupView; |
|
270 } |
|
271 else if ( aViewTypeString.Compare(KFindView) == 0 ) |
|
272 { |
|
273 viewType = TViewData::EFindView; |
|
274 } |
|
275 else if ( aViewTypeString.Compare(KFilteredView) == 0 ) |
|
276 { |
|
277 viewType = TViewData::EFilteredView; |
|
278 } |
|
279 else if ( aViewTypeString.Compare(KConcatenatedView) == 0 ) |
|
280 { |
|
281 viewType = TViewData::EConcatenatedView; |
|
282 } |
|
283 else if ( aViewTypeString.Compare(KSubView) == 0 ) |
|
284 { |
|
285 viewType = TViewData::ESubView; |
|
286 } |
|
287 |
|
288 return viewType; |
|
289 } |