|
1 // Copyright (c) 2004-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 <e32property.h> |
|
17 #include <app-services/private/cbackuprestorenotification.h> |
|
18 |
|
19 // |
|
20 // Forward declarations. |
|
21 // |
|
22 class CContactsClient; |
|
23 class MBackupRestoreObserver; |
|
24 class CBackupHelper; |
|
25 |
|
26 |
|
27 // |
|
28 // MBackupRestoreObserver. |
|
29 // |
|
30 class MBackupRestoreObserver |
|
31 { |
|
32 public: |
|
33 virtual void ContactsBackupRestoreObserver(CContactsClient& aContactClient, const TBool aRestore, const TBool aStart) = 0; |
|
34 }; |
|
35 |
|
36 |
|
37 /* |
|
38 CContactsClient |
|
39 This class models, through its public methods, various Contacts client behaviours. |
|
40 It is derived from CActive so that it can safely respond to Backup & Restore notifications |
|
41 - e.g. closing a database in the notification handler causes a panic. (The active object |
|
42 delivering the notification is deleted whilst it is running, and cannot recover.) |
|
43 Instead the active object must be set to run - and the RunL method can safely close the database. |
|
44 If called, the RunL also closes any contact or view that is open. |
|
45 */ |
|
46 class CContactsClient : public CActive, public MContactDbObserver, public MContactUiCompactObserver, public MIdleFindObserver |
|
47 { |
|
48 public: |
|
49 static CContactsClient* NewLC(const TDesC& aDatabaseName, MBackupRestoreObserver* aObserver, MContactViewObserver& aContactViewObserver, TBool aCloseForBackup); |
|
50 ~CContactsClient(); |
|
51 |
|
52 void StartActiveClose(); |
|
53 void CloseDatabase(); |
|
54 void OpenDatabaseL(); |
|
55 |
|
56 const TDesC& DatabaseName(); |
|
57 TBool IsOpen(); |
|
58 |
|
59 void OpenLocalViewL(); |
|
60 void OpenRemoteViewL(); |
|
61 void CloseViews(); |
|
62 |
|
63 void OpenContactL(TContactItemId aContactId); |
|
64 void CommitContactL(TContactItemId aContactId); |
|
65 void CloseContacts(); |
|
66 void ReadContactL(); |
|
67 void FindPhoneNumberL(); |
|
68 |
|
69 void StartAsyncFindL(); |
|
70 void StartActiveCompactL(); |
|
71 void StartActiveRecoverL(); |
|
72 void StartIdleSorterL(TRequestStatus& aStatus); |
|
73 |
|
74 void CompleteAsyncFindL(); |
|
75 void CompleteActiveCompactL(); |
|
76 void CompleteActiveRecoverL(); |
|
77 |
|
78 |
|
79 // Speed Dial Check, Remove and Set - for testing cntmodel.ini is Backed up and Restored correctly |
|
80 void CheckSpeedDialSetL(TContactItemId aContactId, TInt aSpeedDialPosition); |
|
81 void RemoveSpeedDialL(TContactItemId aContactId, TInt aSpeedDialPosition); |
|
82 void SetSpeedDialL(TContactItemId aContactId, TInt aSpeedDialPosition); |
|
83 |
|
84 TBool IsCloseForBackup(); |
|
85 |
|
86 // class MContactUiCompactObserver |
|
87 public: |
|
88 void Step(TInt aStep); |
|
89 void HandleError(TInt aError); |
|
90 |
|
91 // class MIdleFindObserver |
|
92 void IdleFindCallback(); |
|
93 |
|
94 private: |
|
95 CContactsClient(MBackupRestoreObserver* aObserver, MContactViewObserver& aContactViewObserver, TBool aCloseForBackup); |
|
96 void ConstructL(const TDesC& aDatabaseName); |
|
97 |
|
98 // from MContactDbObserver - observed for Backup & Restore events |
|
99 void HandleDatabaseEventL(TContactDbObserverEvent aEvent); |
|
100 |
|
101 // CActive |
|
102 void RunL(); |
|
103 void DoCancel(); |
|
104 |
|
105 private: |
|
106 MBackupRestoreObserver* iObserver; |
|
107 MContactViewObserver& iContactViewObserver; |
|
108 HBufC* iDbName; |
|
109 CContactDatabase* iDb; |
|
110 CContactChangeNotifier* iNotifier; |
|
111 TBool iDatabaseIsOpen; |
|
112 TBool iCloseForBackup; |
|
113 RPointerArray<CContactItem> iOpenContacts; |
|
114 TBool iRestore; |
|
115 CContactLocalView* iLocalView; |
|
116 CContactRemoteView* iRemoteView; |
|
117 // resources for Async CContactDatabase operations |
|
118 CIdleFinder* iIdleFinder; |
|
119 CContactActiveRecover* iActiveRecover; |
|
120 CContactActiveCompress* iActiveCompress; |
|
121 CContactItemFieldDef* iItemFieldDef; |
|
122 }; |
|
123 |
|
124 |
|
125 /* |
|
126 CBackupTestConductor. |
|
127 This class controls the whole unit test framework: |
|
128 + Creating and populating test databases |
|
129 + Checking backup registration policy file is present on drize Z: |
|
130 + Checking Secure Backup has processed the policy file as intended |
|
131 + exercising through CBackupTestFramework a variety of Backup & Restore with a variety of client behaviours |
|
132 + Cleaning up after the test |
|
133 */ |
|
134 class CBackupTestConductor: public CBase |
|
135 { |
|
136 public: |
|
137 static CBackupTestConductor* NewL(); |
|
138 void RunTestsL(); |
|
139 ~CBackupTestConductor(); |
|
140 static void DeleteDatabases(); |
|
141 |
|
142 private: |
|
143 CBackupTestConductor(); |
|
144 void ConstructL(); |
|
145 |
|
146 // database creation / checking / cleanup |
|
147 void CreateDatabasesL(); |
|
148 void PopulateDatabaseL(CContactDatabase* aDb,const TDesC& aFileName); |
|
149 void ShowFieldsL(CContactDatabase* aDb); |
|
150 |
|
151 // check that the database backup policy is on the C: drive |
|
152 TBool CheckXMLBackupRegistrationExistsL(); |
|
153 |
|
154 private: |
|
155 // first and last contact ids added to each database |
|
156 TContactItemId iFirstContactId; |
|
157 TContactItemId iLastContactId; |
|
158 }; |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 class CBackupTestFramework : public CTimer, public MBackupRestoreObserver, public MContactViewObserver |
|
164 { |
|
165 public: |
|
166 static CBackupTestFramework* NewLC(); |
|
167 |
|
168 void DoBackupRestoreTestsL(); |
|
169 void BackupRestoreTestL(); |
|
170 |
|
171 |
|
172 enum TClientActivity |
|
173 { |
|
174 // activities that do not block backup / restore |
|
175 EIdleClient, |
|
176 ERestoreCorruptDbTest, |
|
177 EOpenLocalView, |
|
178 EOpenRemoteView, |
|
179 // activities that can block backup / restore |
|
180 EOpenOneContactForEdit, |
|
181 EOpenTwoContactsForEdit, |
|
182 EContactsAsyncFind, |
|
183 EContactsActiveCompact, |
|
184 EContactsActiveRecover, |
|
185 EContactsIdleSorter, |
|
186 EContactsIniFileTest, |
|
187 EOpenRemoteViewOneContactForEdit, |
|
188 EMultipleOpenOneContactForEdit |
|
189 }; |
|
190 |
|
191 enum TClientCloseForBackup |
|
192 { |
|
193 EAllOpenForBackup, |
|
194 EAllCloseForBackup, |
|
195 EHalfCloseForBackup |
|
196 }; |
|
197 |
|
198 struct TBackupRestoreTestCase |
|
199 { |
|
200 const TText* iTestTitle; |
|
201 TInt iNumDatabases; |
|
202 TInt iClientsPerDatabase; |
|
203 TClientActivity iActivity; |
|
204 TBool iExpectedBackupSuccess; |
|
205 TClientCloseForBackup iCloseForBackup; |
|
206 conn::TBackupIncType iBackupIncType; |
|
207 }; |
|
208 |
|
209 |
|
210 CContactsClient* NewDatabaseClientL(const TDesC& aDatabaseName, TBool aCloseForBackup); |
|
211 |
|
212 // These methods implement the Use Case under test |
|
213 TBool PrepareBackupClientTestCaseL(TRequestStatus& aStatus); |
|
214 TBool PrepareTestCaseL(const TDesC& aDatabaseName, TRequestStatus& aStatus); |
|
215 |
|
216 void PreBackupNotificationActionsL(); |
|
217 void PostBackupActionsL(); |
|
218 void PreRestoreNotificationActionsL(); |
|
219 void PostRestoreActionsL(); |
|
220 |
|
221 void ReconnectBackupClientTestCaseL(); |
|
222 void CheckConnectionAfterBackupForTestCaseL(); |
|
223 |
|
224 |
|
225 ~CBackupTestFramework(); |
|
226 |
|
227 // from MBackupRestoreObserver |
|
228 void ContactsBackupRestoreObserver(CContactsClient& aContactClient, const TBool aRestore, const TBool aStart); |
|
229 |
|
230 // from MContactViewObserver - observed for View Unavailable and Ready events |
|
231 void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
232 |
|
233 private: |
|
234 // all steps in the Backup and Restore test cycle |
|
235 enum TBackupRestoreSteps |
|
236 { |
|
237 // Backup test steps |
|
238 EPreBackup, |
|
239 ENotifyBackupStart, |
|
240 ECheckBackupStartNotifications, |
|
241 EDoBackup, |
|
242 ENotifyBackupEnd, |
|
243 ECheckBackupEndNotifications, |
|
244 EPostBackup, |
|
245 EFinishedBackup, |
|
246 // Restore test steps |
|
247 EPreRestore, |
|
248 ENotifyRestoreStart, |
|
249 ECheckRestoreStartNotifications, |
|
250 EDoRestore, |
|
251 ENotifyRestoreEnd, |
|
252 ECheckRestoreEndNotifications, |
|
253 EPostRestore, |
|
254 EFinishedRestore, |
|
255 }; |
|
256 private: |
|
257 CBackupTestFramework(); |
|
258 void ConstructL(); |
|
259 |
|
260 // From CActive. |
|
261 void RunL(); |
|
262 TInt RunError(TInt aError); |
|
263 |
|
264 |
|
265 private: |
|
266 const CBackupTestFramework::TBackupRestoreTestCase* iTestCase; |
|
267 TInt iTestError; |
|
268 TInt iClientNotifications; |
|
269 TInt iViewReadyCount; |
|
270 TInt iViewUnavailableCount; |
|
271 TBackupRestoreSteps iTestStep; |
|
272 CBackupHelper* iBackupHelper; |
|
273 RPIMTestServer iTestServ; |
|
274 |
|
275 RPointerArray<CContactsClient> iContactClientSession; |
|
276 }; |
|
277 |
|
278 |
|
279 class CBackupHelper : CBase |
|
280 { |
|
281 public: |
|
282 static CBackupHelper* NewL(RPIMTestServer& aTestServer); |
|
283 |
|
284 ~CBackupHelper(); |
|
285 |
|
286 void StartBackupL(conn::TBURPartType aBURPartType, conn::TBackupIncType aBackupIncType); |
|
287 void EndBackupL(); |
|
288 |
|
289 void StartRestoreL(); |
|
290 void EndRestoreL(); |
|
291 |
|
292 TBool SimulateIniBackup(); |
|
293 TBool SimulateDbBackup(); |
|
294 TBool SimulateIniRestore(); |
|
295 TBool SimulateDbRestore(); |
|
296 TBool SimulateDamagedDbRestore(); |
|
297 |
|
298 private: |
|
299 CBackupHelper(RPIMTestServer& aTestServer); |
|
300 void ConstructL(); |
|
301 |
|
302 private: |
|
303 TDriveList iDriveList; |
|
304 conn::CSBEClient* iBackupClient; |
|
305 RPIMTestServer& iTestServ; |
|
306 }; |
|
307 |