|
1 // Copyright (c) 2001-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 <cntview.h> |
|
17 #include "cntviewprivate.h" |
|
18 #include "t_utils2.h" |
|
19 |
|
20 |
|
21 // |
|
22 // Forward declarations. |
|
23 // |
|
24 |
|
25 class CSortChecker; |
|
26 class CTestBase; |
|
27 class CViewCreator; |
|
28 class CContactAdder; |
|
29 class CContactRemover; |
|
30 class CViewExerciser; |
|
31 class CSortOrderChanger; |
|
32 class CUnsortableContactAdder; |
|
33 class CContactOwnCardRemover; |
|
34 class CContactOwnCardModifier; |
|
35 // |
|
36 // CTestConductor. |
|
37 // |
|
38 |
|
39 class CTestConductor : public CActive, public MContactViewObserver |
|
40 { |
|
41 public: |
|
42 static CTestConductor* NewL(); |
|
43 ~CTestConductor(); |
|
44 void NextTest(); |
|
45 private: |
|
46 CTestConductor(); |
|
47 void ConstructL(); |
|
48 private: // From CActive. |
|
49 void RunL(); |
|
50 void DoCancel(); |
|
51 TInt RunError(TInt aError); |
|
52 private: // From MContactViewObserver. |
|
53 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
54 private: |
|
55 void ExerciseViewPreferencesL(const CContactViewBase* aViewToTest,TContactViewPreferences aPrefsToTest); |
|
56 private: |
|
57 enum TTest |
|
58 { |
|
59 ECreateLocalView, |
|
60 EAddInitialContacts, |
|
61 EExerciseLocalView_1, |
|
62 ECreateLocalNamedView, |
|
63 EExerciseLocalNamedView_1, |
|
64 EAddMoreContacts_1, |
|
65 EExerciseLocalView_2, |
|
66 EExerciseLocalNamedView_2, |
|
67 ECreateRemoteView1, |
|
68 EExerciseRemoteView1, |
|
69 ECreateRemoteView2, |
|
70 EExerciseRemoteView2, |
|
71 ECreateNamedRemoteView1, |
|
72 EExerciseNamedRemoteView1, |
|
73 ECreateNamedRemoteView2, |
|
74 EExerciseNamedRemoteView2, |
|
75 ECreateSubViewLessThanA, |
|
76 EExerciseSubViewLessThanA, |
|
77 ECreateSubViewAbc, |
|
78 EExerciseSubViewAbc, |
|
79 ECreateSubViewDef, |
|
80 EExerciseSubViewDef, |
|
81 ECreateSubViewGhi, |
|
82 EExerciseSubViewGhi, |
|
83 ECreateSubViewJkl, |
|
84 EExerciseSubViewJkl, |
|
85 ECreateSubViewGreaterThanOrEqualToM, |
|
86 EExerciseSubViewGreaterThanOrEqualToM, |
|
87 ECreateConcatenatedView, |
|
88 EExerciseConcatenatedView, |
|
89 EChangeSortOrder1, |
|
90 EChangeSortOrder2, |
|
91 EChangeSortOrder3, |
|
92 EExerciseAllAffectedViews, |
|
93 EAddMoreContacts_2, |
|
94 EExerciseAllViews_1, |
|
95 ERemoveSomeContacts, |
|
96 EExerciseAllViews_2, |
|
97 EAllViewsOutOfBoundsAccess, |
|
98 ECreateLocalViewWithUnsortableAtEnd, |
|
99 EAddUnsortableContacts, |
|
100 EExerciseLocalViewWithUnsortableAtEnd, |
|
101 EAddFreshLocalView, |
|
102 EExerciseFreshLocalView, |
|
103 EAddSomeMoreUnsortableContacts, |
|
104 EExerciseViewForPrefsAgain, |
|
105 EAddWhiteSpaceContacts, |
|
106 EExerciseWhiteSpaceContacts, |
|
107 ERemoveOwnCardContact, |
|
108 EModifyOwnCardContact, |
|
109 ESearchForEuroChar, |
|
110 ENumTests |
|
111 }; |
|
112 public: |
|
113 RFs iFs; |
|
114 CLog* iLog; |
|
115 CContactDatabase* iDb; |
|
116 CSortChecker* iSortChecker; |
|
117 RContactViewSortOrder iSortOrder_1; |
|
118 RContactViewSortOrder iSortOrder_2; |
|
119 RContactViewSortOrder iSortOrder_3; |
|
120 RContactViewSortOrder iSortOrder_4; |
|
121 CContactLocalView* iLocalView; |
|
122 CContactLocalView* iFreshLocalView; |
|
123 CContactNamedLocalView* iNamedLocalView; |
|
124 CContactSubView* iSubViewLessThanA; |
|
125 CContactSubView* iSubViewAbc; |
|
126 CContactSubView* iSubViewDef; |
|
127 CContactSubView* iSubViewGhi; |
|
128 CContactSubView* iSubViewJkl; |
|
129 CContactSubView* iSubViewGreaterThanOrEqualToM; |
|
130 CContactConcatenatedView* iConcatenatedView; |
|
131 CContactRemoteView* iRemoteView_1; |
|
132 CContactRemoteView* iRemoteView_2; |
|
133 CContactNamedRemoteView* iNamedRemoteView_1; |
|
134 CContactNamedRemoteView* iNamedRemoteView_2; |
|
135 CContactFindView* iLocalFindView; |
|
136 CContactFindView* iRemoteFindView; |
|
137 CContactLocalView* iLocalViewWithViewPreferences; |
|
138 CRandomContactGenerator* iRandomGenerator; |
|
139 RArray<TContactItemId> iTestIds; |
|
140 private: |
|
141 CViewCreator* iViewCreator; |
|
142 CContactAdder* iContactAdder; |
|
143 CContactRemover* iContactRemover; |
|
144 CViewExerciser* iViewExerciser; |
|
145 CSortOrderChanger* iSortOrderChanger; |
|
146 CContactOwnCardRemover* iOwnCardRemover; |
|
147 CContactOwnCardModifier* iOwnCardModifier; |
|
148 TInt iCurrentTestNumber; |
|
149 CTestBase* iCurrentTestObject; |
|
150 CPtrC16Array* iFindDesArray; |
|
151 CPtrC16Array* iFindDesArray2; |
|
152 CUnsortableContactAdder* iUnsortableAdder; |
|
153 TInt iTestError; |
|
154 }; |
|
155 |
|
156 |
|
157 // |
|
158 // CSortChecker. |
|
159 // |
|
160 |
|
161 class CSortChecker : public CBase |
|
162 { |
|
163 public: |
|
164 enum TSortOrder |
|
165 { |
|
166 EFirstNameLastName, |
|
167 ELastNameFirstName |
|
168 }; |
|
169 enum TCriteria |
|
170 { |
|
171 ELessThan, |
|
172 ELessThanOrEqualTo, |
|
173 EGreaterThan, |
|
174 EGreaterThanOrEqualTo |
|
175 }; |
|
176 public: |
|
177 static CSortChecker* NewL(CTestConductor& aConductor); |
|
178 ~CSortChecker(); |
|
179 void AddContactL(const TDesC& aFirstName,const TDesC& aLastName); |
|
180 void RemoveContactL(const TDesC& aFirstName,const TDesC& aLastName); |
|
181 TPtrC ContactAt(TSortOrder aOrder,TInt aIndex) const; |
|
182 TInt Count() const; |
|
183 TInt Count(TSortOrder aOrder,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const; |
|
184 TInt CountLow(TSortOrder aOrder,const TDesC& aHighBoundary) const; |
|
185 TInt CountHigh(TSortOrder aOrder,const TDesC& aLowBoundary) const; |
|
186 void Sort(); |
|
187 void CheckSort(TSortOrder aOrder,const TDesC& aName,TInt aIndex) const; |
|
188 void CheckSortLowSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aHighBoundary) const; |
|
189 void CheckSortHighSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary) const; |
|
190 void CheckSortSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const; |
|
191 private: |
|
192 CSortChecker(CTestConductor& aConductor); |
|
193 void ConstructL(); |
|
194 TInt FindIndex(TSortOrder aOrder,const TDesC& aBoundary,TCriteria aCriteria) const; |
|
195 static TInt Compare(const HBufC& aFirst, const HBufC& aSecond); |
|
196 static TInt CompareWithoutIgnoringSpacesL(const HBufC& aFirst, const HBufC& aSecond); |
|
197 static void RemoveCharacterFromDescriptor(const TChar aChar, TDes& aDes); |
|
198 static TBool Match(const HBufC& aFirst,const HBufC& aSecond); |
|
199 private: |
|
200 CTestConductor& iConductor; |
|
201 TCollationMethod* iCollateMethod; |
|
202 RPointerArray<HBufC> iSortedFirstLast; |
|
203 RPointerArray<HBufC> iSortedLastFirst; |
|
204 }; |
|
205 |
|
206 |
|
207 // |
|
208 // CTestBase. |
|
209 // |
|
210 |
|
211 class CTestBase : public CBase |
|
212 { |
|
213 public: |
|
214 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent)=0; |
|
215 protected: |
|
216 CTestBase(CTestConductor& aConductor); |
|
217 protected: |
|
218 CTestConductor& iConductor; |
|
219 }; |
|
220 |
|
221 |
|
222 // |
|
223 // CViewCreator. |
|
224 // |
|
225 |
|
226 class CViewCreator : public CTestBase |
|
227 { |
|
228 public: |
|
229 static CViewCreator* NewL(CTestConductor& aConductor); |
|
230 CContactLocalView* CreateLocalViewL(const RContactViewSortOrder& aSortOrder); |
|
231 CContactLocalView* CreateLocalViewL(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aViewPrefs); |
|
232 CContactNamedLocalView* CreateNamedLocalViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder); |
|
233 CContactRemoteView* CreateRemoteViewL(const RContactViewSortOrder& aSortOrder); |
|
234 CContactNamedRemoteView* CreateNamedRemoteViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder); |
|
235 CContactSubView* CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aBoundary); |
|
236 CContactSubView* CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aLowBoundary,const TDesC& aHighBoundary); |
|
237 CContactConcatenatedView* CreateConcatenatedViewL(RPointerArray<CContactViewBase>& aComponentViews); |
|
238 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
239 private: |
|
240 CViewCreator(CTestConductor& aConductor); |
|
241 CContactViewBase* iView; |
|
242 }; |
|
243 |
|
244 |
|
245 // |
|
246 // CContactAdder. |
|
247 // |
|
248 |
|
249 class CContactAdder : public CTestBase |
|
250 { |
|
251 public: |
|
252 static CContactAdder* NewL(CTestConductor& aConductor); |
|
253 ~CContactAdder(); |
|
254 void AddContactsL(const TDesC& aFileName,TInt aNumViews); |
|
255 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
256 static TBool ReadNamePairL(RFile aFile,TDes& aFirstName,TDes& aLastName); |
|
257 private: |
|
258 CContactAdder(CTestConductor& aConductor); |
|
259 void ConstructL(); |
|
260 void AddOneContactL(); |
|
261 private: |
|
262 RFs iFs; |
|
263 RFile iFile; |
|
264 CContactTemplate* iTemplate; |
|
265 TBool iFinished; |
|
266 TInt iNumViews; |
|
267 TInt iNumNotifications; |
|
268 }; |
|
269 |
|
270 |
|
271 // |
|
272 // CContactRemover. |
|
273 // |
|
274 |
|
275 class CContactRemover : public CTestBase |
|
276 { |
|
277 public: |
|
278 static CContactRemover* NewL(CTestConductor& aConductor); |
|
279 ~CContactRemover(); |
|
280 void RemoveContactsL(const TDesC& aFileName,TInt aNumViews); |
|
281 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
282 private: |
|
283 CContactRemover(CTestConductor& aConductor); |
|
284 void ConstructL(); |
|
285 void RemoveOneContactL(); |
|
286 private: |
|
287 RFs iFs; |
|
288 RFile iFile; |
|
289 TBool iFinished; |
|
290 TInt iNumViews; |
|
291 TInt iNumNotifications; |
|
292 }; |
|
293 |
|
294 |
|
295 // |
|
296 // CViewExerciser. |
|
297 // |
|
298 |
|
299 class CViewExerciser : public CTestBase |
|
300 { |
|
301 public: |
|
302 static CViewExerciser* NewL(CTestConductor& aConductor); |
|
303 void ProfileViewL(CContactViewBase& aView); |
|
304 void ExerciseViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView); |
|
305 void ExerciseSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aLowBoundary,const TDesC& aHighBoundary); |
|
306 void ExerciseLowSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aLowBoundary); |
|
307 void ExerciseHighSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aHighBoundary); |
|
308 void QueueNextTestWhenComplete(TBool aQueue); |
|
309 ~CViewExerciser(); |
|
310 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
311 private: |
|
312 CViewExerciser(CTestConductor& aConductor); |
|
313 void GetComparisonStringL(const TContactItemId aContactId, const CSortChecker::TSortOrder aSortOrder, TDes& aContactInfo); |
|
314 void ConstructL(); |
|
315 private: |
|
316 CContactTextDef* iTextDef_FirstLast; |
|
317 CContactTextDef* iTextDef_LastFirst; |
|
318 TBool iQueue; |
|
319 }; |
|
320 |
|
321 |
|
322 // |
|
323 // CSortOrderChanger. |
|
324 // |
|
325 |
|
326 class CSortOrderChanger : public CTestBase |
|
327 { |
|
328 public: |
|
329 static CSortOrderChanger* NewL(CTestConductor& aConductor); |
|
330 void ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedLocalView& aView,TInt aNumViews); |
|
331 void ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedRemoteView& aView,TInt aNumViews); |
|
332 ~CSortOrderChanger(); |
|
333 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
334 private: |
|
335 CSortOrderChanger(CTestConductor& aConductor); |
|
336 private: |
|
337 CContactTextDef* iTextDef; |
|
338 TInt iNumViews; |
|
339 TInt iNumNotifications; |
|
340 }; |
|
341 |
|
342 // |
|
343 // CContactAdder. |
|
344 // |
|
345 |
|
346 class CUnsortableContactAdder : public CTestBase |
|
347 { |
|
348 public: |
|
349 static CUnsortableContactAdder* NewL(CTestConductor& aConductor,const CContactViewBase& aView); |
|
350 ~CUnsortableContactAdder(); |
|
351 void AddContactsL(TInt aNumberOfContact,TContactViewPreferences aContactTypes); |
|
352 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
353 inline void SetNumContactExpected(TInt aNoContact) {iNumContacts=aNoContact;} |
|
354 inline TInt NumContactsExpected() {return iNumContacts;} |
|
355 private: |
|
356 CUnsortableContactAdder(CTestConductor& aConductor,const CContactViewBase& aView); |
|
357 void ConstructL(); |
|
358 private: |
|
359 TBool iFinished; |
|
360 TInt iNumContacts; |
|
361 TInt iNumNotifications; |
|
362 const CContactViewBase* iView; |
|
363 }; |
|
364 |
|
365 /** Removes an own card item and checks it is removed correctly */ |
|
366 class CContactOwnCardRemover : public CTestBase |
|
367 { |
|
368 public: |
|
369 CContactOwnCardRemover(CTestConductor& aConductor); |
|
370 ~CContactOwnCardRemover(); |
|
371 void RemoveOwnCardL(const CContactViewBase& aView); |
|
372 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
373 private: |
|
374 TInt iOriginalCount; |
|
375 const CContactViewBase* iView; |
|
376 }; |
|
377 |
|
378 /** Modifies an own card item and checks changes are picked up correctly */ |
|
379 class CContactOwnCardModifier : public CTestBase |
|
380 { |
|
381 public: |
|
382 CContactOwnCardModifier(CTestConductor& aConductor); |
|
383 ~CContactOwnCardModifier(); |
|
384 void ModifyOwnCardL(const CContactViewBase& aView); |
|
385 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
386 private: |
|
387 TInt iOriginalCount; |
|
388 const CContactViewBase* iView; |
|
389 TInt iNotificationsReceived; |
|
390 }; |