|
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 CSortOrderChanger; |
|
31 class CUnsortableContactAdder; |
|
32 // |
|
33 // CTestConductor. |
|
34 // |
|
35 |
|
36 class CTestConductor : public CActive, public MContactViewObserver |
|
37 { |
|
38 public: |
|
39 static CTestConductor* NewL(); |
|
40 ~CTestConductor(); |
|
41 void NextTest(); |
|
42 private: |
|
43 CTestConductor(); |
|
44 void ConstructL(); |
|
45 private: // From CActive. |
|
46 void RunL(); |
|
47 TInt RunError(TInt aError); |
|
48 void DoCancel(); |
|
49 private: // From MContactViewObserver. |
|
50 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
51 private: |
|
52 void ExerciseViewPreferencesL(const CContactViewBase* aViewToTest,TContactViewPreferences aPrefsToTest); |
|
53 private: |
|
54 enum TTest |
|
55 { |
|
56 EAsyncOpen, |
|
57 EAsyncOpened, |
|
58 ECreateLocalView, |
|
59 EAddInitialContacts, |
|
60 ECreateLocalViewWithPlugin, |
|
61 ECreateRemoteView, |
|
62 ECreateRemoteViewWithPlugin, |
|
63 ECriteriaSearchForStringInLocal, |
|
64 ECriteriaSearchForStringInLocalWithPlugin, |
|
65 ECriteriaSearchForStringInRemote, |
|
66 ECriteriaSearchForStringInRemoteWithPlugin, |
|
67 EPrefixSearchForStringInLocal, |
|
68 EPrefixSearchForStringInLocalWithPlugin, |
|
69 EPrefixSearchForStringInRemote, |
|
70 EPrefixSearchForStringInRemoteWithPlugin, |
|
71 ENumTests |
|
72 }; |
|
73 public: |
|
74 CContactOpenOperation* iContactOpenOperation; |
|
75 RFs iFs; |
|
76 CLog* iLog; |
|
77 CContactDatabase* iDb; |
|
78 CSortChecker* iSortChecker; |
|
79 RContactViewSortOrder iSortOrder; |
|
80 CContactLocalView* iLocalView; |
|
81 CContactLocalView* iLocalViewWithPlugin; |
|
82 CContactRemoteView* iRemoteView; |
|
83 CContactRemoteView* iRemoteViewWithPlugin; |
|
84 CRandomContactGenerator* iRandomGenerator; |
|
85 RArray<TContactItemId> iTestIds; |
|
86 private: |
|
87 CViewCreator* iViewCreator; |
|
88 CContactAdder* iContactAdder; |
|
89 CContactRemover* iContactRemover; |
|
90 CSortOrderChanger* iSortOrderChanger; |
|
91 TInt iCurrentTestNumber; |
|
92 CTestBase* iCurrentTestObject; |
|
93 CPtrC16Array* iFindDesArray; |
|
94 CPtrC16Array* iFindDesArray2; |
|
95 CUnsortableContactAdder* iUnsortableAdder; |
|
96 TInt iTestError; |
|
97 }; |
|
98 |
|
99 |
|
100 // |
|
101 // CSortChecker. |
|
102 // |
|
103 |
|
104 class CSortChecker : public CBase |
|
105 { |
|
106 public: |
|
107 enum TSortOrder |
|
108 { |
|
109 EFirstNameLastName, |
|
110 ELastNameFirstName |
|
111 }; |
|
112 enum TCriteria |
|
113 { |
|
114 ELessThan, |
|
115 ELessThanOrEqualTo, |
|
116 EGreaterThan, |
|
117 EGreaterThanOrEqualTo |
|
118 }; |
|
119 public: |
|
120 static CSortChecker* NewL(CTestConductor& aConductor); |
|
121 ~CSortChecker(); |
|
122 void AddContactL(const TDesC& aFirstName,const TDesC& aLastName); |
|
123 void RemoveContactL(const TDesC& aFirstName,const TDesC& aLastName); |
|
124 TPtrC ContactAt(TSortOrder aOrder,TInt aIndex) const; |
|
125 TInt Count() const; |
|
126 TInt Count(TSortOrder aOrder,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const; |
|
127 TInt CountLow(TSortOrder aOrder,const TDesC& aHighBoundary) const; |
|
128 TInt CountHigh(TSortOrder aOrder,const TDesC& aLowBoundary) const; |
|
129 void Sort(); |
|
130 void CheckSort(TSortOrder aOrder,const TDesC& aName,TInt aIndex) const; |
|
131 void CheckSortLowSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aHighBoundary) const; |
|
132 void CheckSortHighSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary) const; |
|
133 void CheckSortSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const; |
|
134 private: |
|
135 CSortChecker(CTestConductor& aConductor); |
|
136 void ConstructL(); |
|
137 TInt FindIndex(TSortOrder aOrder,const TDesC& aBoundary,TCriteria aCriteria) const; |
|
138 static TInt Compare(const HBufC& aFirst, const HBufC& aSecond); |
|
139 static TInt CompareWithoutIgnoringSpacesL(const HBufC& aFirst, const HBufC& aSecond); |
|
140 static void RemoveCharacterFromDescriptor(const TChar aChar, TDes& aDes); |
|
141 static TBool Match(const HBufC& aFirst,const HBufC& aSecond); |
|
142 private: |
|
143 CTestConductor& iConductor; |
|
144 TCollationMethod* iCollateMethod; |
|
145 RPointerArray<HBufC> iSortedFirstLast; |
|
146 RPointerArray<HBufC> iSortedLastFirst; |
|
147 }; |
|
148 |
|
149 |
|
150 // |
|
151 // CTestBase. |
|
152 // |
|
153 |
|
154 class CTestBase : public CBase |
|
155 { |
|
156 public: |
|
157 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent)=0; |
|
158 protected: |
|
159 CTestBase(CTestConductor& aConductor); |
|
160 protected: |
|
161 CTestConductor& iConductor; |
|
162 }; |
|
163 |
|
164 |
|
165 // |
|
166 // CViewCreator. |
|
167 // |
|
168 |
|
169 class CViewCreator : public CTestBase |
|
170 { |
|
171 public: |
|
172 static CViewCreator* NewL(CTestConductor& aConductor); |
|
173 CContactLocalView* CreateLocalViewL(const RContactViewSortOrder& aSortOrder); |
|
174 CContactLocalView* CreateLocalViewL(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aViewPrefs); |
|
175 CContactNamedLocalView* CreateNamedLocalViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder); |
|
176 CContactRemoteView* CreateRemoteViewL(const RContactViewSortOrder& aSortOrder); |
|
177 CContactNamedRemoteView* CreateNamedRemoteViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder); |
|
178 CContactSubView* CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aBoundary); |
|
179 CContactSubView* CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aLowBoundary,const TDesC& aHighBoundary); |
|
180 CContactConcatenatedView* CreateConcatenatedViewL(RPointerArray<CContactViewBase>& aComponentViews); |
|
181 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
182 private: |
|
183 CViewCreator(CTestConductor& aConductor); |
|
184 CContactViewBase* iView; |
|
185 }; |
|
186 |
|
187 |
|
188 // |
|
189 // CContactAdder. |
|
190 // |
|
191 |
|
192 class CContactAdder : public CTestBase |
|
193 { |
|
194 public: |
|
195 static CContactAdder* NewL(CTestConductor& aConductor); |
|
196 ~CContactAdder(); |
|
197 void AddContactsL(const TDesC& aFileName,TInt aNumViews); |
|
198 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
199 static TBool ReadNamePairL(RFile aFile,TDes& aFirstName,TDes& aLastName); |
|
200 private: |
|
201 CContactAdder(CTestConductor& aConductor); |
|
202 void ConstructL(); |
|
203 void AddOneContactL(); |
|
204 private: |
|
205 RFs iFs; |
|
206 RFile iFile; |
|
207 CContactTemplate* iTemplate; |
|
208 TBool iFinished; |
|
209 TInt iNumViews; |
|
210 TInt iNumNotifications; |
|
211 }; |
|
212 |
|
213 |
|
214 // |
|
215 // CContactRemover. |
|
216 // |
|
217 |
|
218 class CContactRemover : public CTestBase |
|
219 { |
|
220 public: |
|
221 static CContactRemover* NewL(CTestConductor& aConductor); |
|
222 ~CContactRemover(); |
|
223 void RemoveContactsL(const TDesC& aFileName,TInt aNumViews); |
|
224 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
225 private: |
|
226 CContactRemover(CTestConductor& aConductor); |
|
227 void ConstructL(); |
|
228 void RemoveOneContactL(); |
|
229 private: |
|
230 RFs iFs; |
|
231 RFile iFile; |
|
232 TBool iFinished; |
|
233 TInt iNumViews; |
|
234 TInt iNumNotifications; |
|
235 }; |
|
236 |
|
237 class CSortOrderChanger : public CTestBase |
|
238 { |
|
239 public: |
|
240 static CSortOrderChanger* NewL(CTestConductor& aConductor); |
|
241 void ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedLocalView& aView,TInt aNumViews); |
|
242 void ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedRemoteView& aView,TInt aNumViews); |
|
243 ~CSortOrderChanger(); |
|
244 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
245 private: |
|
246 CSortOrderChanger(CTestConductor& aConductor); |
|
247 private: |
|
248 CContactTextDef* iTextDef; |
|
249 TInt iNumViews; |
|
250 TInt iNumNotifications; |
|
251 }; |
|
252 |
|
253 // |
|
254 // CContactAdder. |
|
255 // |
|
256 |
|
257 class CUnsortableContactAdder : public CTestBase |
|
258 { |
|
259 public: |
|
260 static CUnsortableContactAdder* NewL(CTestConductor& aConductor,const CContactViewBase& aView); |
|
261 ~CUnsortableContactAdder(); |
|
262 void AddContactsL(TInt aNumberOfContact,TContactViewPreferences aContactTypes); |
|
263 virtual void HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
264 inline void SetNumContactExpected(TInt aNoContact) {iNumContacts=aNoContact;} |
|
265 inline TInt NumContactsExpected() {return iNumContacts;} |
|
266 private: |
|
267 CUnsortableContactAdder(CTestConductor& aConductor,const CContactViewBase& aView); |
|
268 void ConstructL(); |
|
269 private: |
|
270 TBool iFinished; |
|
271 TInt iNumContacts; |
|
272 TInt iNumNotifications; |
|
273 const CContactViewBase* iView; |
|
274 }; |