|
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 "TestContactViewDatabaseUtilitiesStep.h" |
|
17 |
|
18 /** |
|
19 * Test Step Destructor |
|
20 */ |
|
21 CTestContactViewDatabaseUtilitiesStep::~CTestContactViewDatabaseUtilitiesStep() |
|
22 { |
|
23 if(iContactUtility) |
|
24 { |
|
25 delete iContactUtility; |
|
26 } |
|
27 if(iContactViewCollection) |
|
28 { |
|
29 delete iContactViewCollection; |
|
30 } |
|
31 if(iDb) |
|
32 { |
|
33 delete iDb; |
|
34 } |
|
35 if(iScheduler) |
|
36 { |
|
37 delete iScheduler; |
|
38 } |
|
39 } |
|
40 |
|
41 /** |
|
42 * Test Step preamble function, setups the environment required for the test step |
|
43 */ |
|
44 TVerdict CTestContactViewDatabaseUtilitiesStep::doTestStepPreambleL() |
|
45 { |
|
46 iPimTestServer.Connect(); |
|
47 CopyDatabaseL(); |
|
48 InstallActiveSchedularL(); |
|
49 OpenDataBaseL(); |
|
50 SetupUtilityL(); |
|
51 return TestStepResult(); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Test Step postamble function, part of cleanup activity for the test step |
|
56 */ |
|
57 TVerdict CTestContactViewDatabaseUtilitiesStep::doTestStepPostambleL() |
|
58 { |
|
59 iPimTestServer.Close(); |
|
60 CloseDatabaseL(); |
|
61 UnInstallActiveSchedularL(); |
|
62 return TestStepResult(); |
|
63 } |
|
64 |
|
65 |
|
66 /** |
|
67 * Installs active schedular in the current thread |
|
68 */ |
|
69 void CTestContactViewDatabaseUtilitiesStep::InstallActiveSchedularL() |
|
70 { |
|
71 iScheduler = new (ELeave) CActiveScheduler; |
|
72 CActiveScheduler::Install(iScheduler); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Allocates necessary utility objects |
|
77 */ |
|
78 void CTestContactViewDatabaseUtilitiesStep::SetupUtilityL() |
|
79 { |
|
80 iContactViewCollection = CContactViewCollection::NewL(); |
|
81 CTestStep* self = static_cast<CTestStep*>(this); |
|
82 iContactUtility = CContactUtilitiesCollection::NewL(*self, DatabaseReference(), ViewCollectionReference()); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Opens the desired database file based on ini data mentioned in the ini file |
|
87 */ |
|
88 void CTestContactViewDatabaseUtilitiesStep::OpenDataBaseL() |
|
89 { |
|
90 TBool createDataBase = EFalse; |
|
91 TPtrC dbName; |
|
92 GetBoolFromConfig(ConfigSection(), SharedConstants::KCreateDataBase, createDataBase); |
|
93 GetStringFromConfig(ConfigSection(), SharedConstants::KDbName, dbName); |
|
94 iDb = CreateAndOpenDataBaseL(dbName, createDataBase); |
|
95 } |
|
96 |
|
97 /** |
|
98 * Create or open the contact database |
|
99 * @param aDbName database to be created/opened |
|
100 * @return CContactDatabase* |
|
101 */ |
|
102 CContactDatabase* CTestContactViewDatabaseUtilitiesStep::CreateAndOpenDataBaseL(const TPtrC& aDbName, TBool aCreateDataBase) |
|
103 { |
|
104 HBufC* dbName = HBufC::NewLC(aDbName.Length()); |
|
105 dbName->Des().Copy(aDbName); |
|
106 CContactDatabase* cntDb = NULL; |
|
107 if( aCreateDataBase ) |
|
108 { |
|
109 TInt err = 0; |
|
110 // Replace the existing database and opens it |
|
111 if( aDbName != KNullDesC() ) |
|
112 { |
|
113 TRAP(err, cntDb = CContactDatabase::ReplaceL(dbName->Des())); |
|
114 } |
|
115 else //if database name is not given then create and open the default DB |
|
116 { |
|
117 TRAP(err, cntDb = CContactDatabase::ReplaceL()); |
|
118 } |
|
119 |
|
120 if( err != KErrNone ) |
|
121 { |
|
122 ERR_PRINTF2(KErrInCreateDataBase, err); |
|
123 SetTestStepResult(EFail); |
|
124 SetTestStepError(err); |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 TRAPD(err, cntDb = CContactDatabase::OpenL(dbName->Des())); |
|
130 if( err != KErrNone ) |
|
131 { |
|
132 ERR_PRINTF2(KErrInOpen, err); |
|
133 SetTestStepResult(EFail); |
|
134 SetTestStepError(err); |
|
135 } |
|
136 } |
|
137 CleanupStack::PopAndDestroy(dbName); |
|
138 return cntDb; |
|
139 } |
|
140 |
|
141 /** |
|
142 * Constructs the desired contact views based on the data specified in the ini file |
|
143 */ |
|
144 void CTestContactViewDatabaseUtilitiesStep::ConstructViewsL() |
|
145 { |
|
146 TPtrC listOfViews; |
|
147 GetStringFromConfig(ConfigSection(), SharedConstants::KListOfViews, listOfViews); |
|
148 RArray<TPtrC> sections; |
|
149 CleanupClosePushL(sections); |
|
150 iContactUtility->TokenizeStringL(listOfViews, sections); |
|
151 iContactUtility->ConstructViewsL(sections); |
|
152 CleanupStack::PopAndDestroy(§ions); |
|
153 } |
|
154 |
|
155 /** |
|
156 * Retrieves the desired contact view observer and listens for contact view notifications |
|
157 * @param aEvent - A TContactViewEvent object that will be updated with the notification received |
|
158 * @return TBool - An indication whether notification was received or not |
|
159 */ |
|
160 TBool CTestContactViewDatabaseUtilitiesStep::ListenForViewEventsL(TContactViewEvent& aEvent) |
|
161 { |
|
162 const TInt KNotificationTimeout = 10; // ms |
|
163 TInt desiredViewIndex = 0; |
|
164 _LIT(KDesiredViewIndex, "DesiredViewIndex"); |
|
165 GetIntFromConfig(ConfigSection(), KDesiredViewIndex, desiredViewIndex); |
|
166 |
|
167 TPtrC desiredViewType; |
|
168 _LIT(KDesiredViewType, "DesiredViewType"); |
|
169 GetStringFromConfig(ConfigSection(), KDesiredViewType, desiredViewType); |
|
170 |
|
171 CContactViewEventQueue& contactViewObserver = |
|
172 ViewCollectionReference().GetDesiredViewObserver(desiredViewType, desiredViewIndex); |
|
173 |
|
174 return (contactViewObserver.ListenForEvent(KNotificationTimeout,aEvent)); |
|
175 } |
|
176 |
|
177 /* Here we are trying add blank groups in the database |
|
178 * Say some 1000 thousand groups are added to the database |
|
179 */ |
|
180 void CTestContactViewDatabaseUtilitiesStep::AddGroupsInDatabaseL() |
|
181 { |
|
182 _LIT(KNumOfGroups, "numofgroups"); |
|
183 TInt numOfGroups = 0; |
|
184 GetIntFromConfig(ConfigSection(), KNumOfGroups, numOfGroups); |
|
185 |
|
186 for(TInt i = 0; i < numOfGroups; ++i) |
|
187 { |
|
188 CContactItem* contactGroup = DatabaseReference().CreateContactGroupL(); |
|
189 delete contactGroup; |
|
190 } |
|
191 } |
|
192 |
|
193 |
|
194 /* In this section, we edit the desired number of groups in the database |
|
195 * Set label for them and associate them with desired number of groups |
|
196 * With this database updation, group views can be constructed and accessed |
|
197 */ |
|
198 void CTestContactViewDatabaseUtilitiesStep::IterateThroAllGroupSectionsAndUpdateL() |
|
199 { |
|
200 _LIT(KListOfGroupsSectionsString, "listofgroupsections"); |
|
201 TPtrC listOfGroupsSectionsString; |
|
202 GetStringFromConfig(ConfigSection(), KListOfGroupsSectionsString, listOfGroupsSectionsString); |
|
203 |
|
204 RArray<TPtrC> listOfGroupsSections; |
|
205 CleanupClosePushL(listOfGroupsSections); |
|
206 ViewUtilityReference().TokenizeStringL(listOfGroupsSectionsString, listOfGroupsSections); |
|
207 |
|
208 CCntFilter* filter = CCntFilter::NewL(); |
|
209 CleanupStack::PushL(filter); |
|
210 filter->SetContactFilterTypeGroup(ETrue); |
|
211 DatabaseReference().FilterDatabaseL(*filter); |
|
212 |
|
213 for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i ) |
|
214 { |
|
215 CContactIdArray* idArray = filter->iIds; |
|
216 TContactItemId groupId = (*idArray)[i]; |
|
217 CContactItem* group = DatabaseReference().OpenContactL(groupId); |
|
218 CleanupStack::PushL(group); |
|
219 CContactGroup* newGroup = static_cast<CContactGroup*>(group); |
|
220 UpdateGroupsL(listOfGroupsSections[i], *newGroup); |
|
221 DatabaseReference().CommitContactL(*group); |
|
222 DatabaseReference().CloseContactL(groupId); |
|
223 CleanupStack::PopAndDestroy(group); |
|
224 } |
|
225 |
|
226 CleanupStack::PopAndDestroy(2, &listOfGroupsSections); |
|
227 } |
|
228 |
|
229 |
|
230 /** |
|
231 * Updates the specified group with details like group name, number of contacts in the group |
|
232 * @param aGroupSection - section in the ini file contains necessary details for group update |
|
233 * @param aGroup - Group to be updated |
|
234 */ |
|
235 void CTestContactViewDatabaseUtilitiesStep::UpdateGroupsL(const TPtrC& aGroupSection, CContactGroup& aGroup) |
|
236 { |
|
237 _LIT(KGroupName, "groupname"); |
|
238 TPtrC groupName; |
|
239 GetStringFromConfig(aGroupSection, KGroupName, groupName); |
|
240 |
|
241 aGroup.SetGroupLabelL(groupName); |
|
242 |
|
243 _LIT(KNumOfContacts, "numofcontacts"); |
|
244 TInt numOfContacts; |
|
245 GetIntFromConfig(aGroupSection, KNumOfContacts, numOfContacts); |
|
246 |
|
247 CCntFilter* filter = CCntFilter::NewL(); |
|
248 CleanupStack::PushL(filter); |
|
249 filter->SetContactFilterTypeCard(ETrue); |
|
250 DatabaseReference().FilterDatabaseL(*filter); |
|
251 |
|
252 for(TInt i = 0; i < numOfContacts; ++i) |
|
253 { |
|
254 CContactIdArray* idArray = filter->iIds; |
|
255 TContactItemId contactItemId = (*idArray)[i]; |
|
256 CContactItem* contactItem = DatabaseReference().OpenContactL(contactItemId); |
|
257 CleanupStack::PushL(contactItem); |
|
258 TRAP_IGNORE(DatabaseReference().RemoveContactFromGroupL(*contactItem, aGroup)); |
|
259 TRAP_IGNORE(DatabaseReference().AddContactToGroupL(*contactItem, aGroup)); |
|
260 CleanupStack::PopAndDestroy(contactItem); |
|
261 DatabaseReference().CloseContactL(contactItemId); |
|
262 } |
|
263 |
|
264 CleanupStack::PopAndDestroy(filter); |
|
265 } |
|
266 |
|
267 |
|
268 /** |
|
269 * Closes the relevant contacts database file |
|
270 */ |
|
271 void CTestContactViewDatabaseUtilitiesStep::CloseDatabaseL() |
|
272 { |
|
273 if(iContactUtility) |
|
274 { |
|
275 delete iContactUtility; |
|
276 iContactUtility = NULL; |
|
277 } |
|
278 if(iContactViewCollection) |
|
279 { |
|
280 delete iContactViewCollection; |
|
281 iContactViewCollection = NULL; |
|
282 } |
|
283 if(iDb) |
|
284 { |
|
285 delete iDb; |
|
286 iDb=NULL; |
|
287 } |
|
288 } |
|
289 |
|
290 /** |
|
291 * Uninstall scheduler in the current thread |
|
292 */ |
|
293 void CTestContactViewDatabaseUtilitiesStep::UnInstallActiveSchedularL() |
|
294 { |
|
295 if(iScheduler) |
|
296 { |
|
297 delete iScheduler; |
|
298 iScheduler = NULL; |
|
299 } |
|
300 } |
|
301 |
|
302 /** |
|
303 * Handle to the current database in operation |
|
304 * @return CContactDatabase& - Reference to current database in operation |
|
305 */ |
|
306 CContactDatabase& CTestContactViewDatabaseUtilitiesStep::DatabaseReference() |
|
307 { |
|
308 return *iDb; |
|
309 } |
|
310 |
|
311 /** |
|
312 * Handle to the contact view collection |
|
313 * @return CContactViewCollection& - Reference to current contact view collection |
|
314 */ |
|
315 CContactViewCollection& CTestContactViewDatabaseUtilitiesStep::ViewCollectionReference() |
|
316 { |
|
317 return *iContactViewCollection; |
|
318 } |
|
319 |
|
320 /** |
|
321 * Handle to the contact view utilities |
|
322 * @return CContactUtilitiesCollection& - Reference to current contact view utilities collection |
|
323 */ |
|
324 CContactUtilitiesCollection& CTestContactViewDatabaseUtilitiesStep::ViewUtilityReference() |
|
325 { |
|
326 return *iContactUtility; |
|
327 } |
|
328 |
|
329 /** |
|
330 * Handle to the Pim Test Server |
|
331 * @return RPIMTestServer& - Reference to Pim Test Server |
|
332 */ |
|
333 RPIMTestServer& CTestContactViewDatabaseUtilitiesStep::PimTestServerReference() |
|
334 { |
|
335 return iPimTestServer; |
|
336 } |
|
337 |
|
338 /** |
|
339 * Copies database files across folders |
|
340 */ |
|
341 void CTestContactViewDatabaseUtilitiesStep::CopyDatabaseL() |
|
342 { |
|
343 _LIT(KSourcePath, "sourcepath"); |
|
344 TPtrC sourcePathString; |
|
345 GetStringFromConfig(ConfigSection(), KSourcePath, sourcePathString); |
|
346 |
|
347 _LIT(KDestinationPath, "destinationpath"); |
|
348 TPtrC destinationPathString; |
|
349 GetStringFromConfig(ConfigSection(), KDestinationPath, destinationPathString); |
|
350 |
|
351 if(sourcePathString != KNullDesC && destinationPathString != KNullDesC) |
|
352 { |
|
353 TRAP_IGNORE(PimTestServerReference().CopyFileL(sourcePathString, destinationPathString)); |
|
354 } |
|
355 } |