|
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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains CTestContactsAddEntries |
|
15 // |
|
16 // |
|
17 |
|
18 // Epoc include |
|
19 #include <TestExecuteLog.h> |
|
20 |
|
21 // User include |
|
22 #include "TestContactsAddEntries.h" |
|
23 #include "TestContact.h" |
|
24 |
|
25 /*@{*/ |
|
26 /// Literal constants |
|
27 _LIT(KCardTemplateName, "TestTemplate"); |
|
28 _LIT(KCount, "count"); |
|
29 _LIT(KFirstName, "firstname%d"); |
|
30 _LIT(KLastName, "lastname%d"); |
|
31 _LIT(KCompanyName, "company%d"); |
|
32 _LIT(KJobTitle, "job%d"); |
|
33 _LIT(KWorkPhone, "workphone%d"); |
|
34 _LIT(KWorkMobile, "workmobile%d"); |
|
35 _LIT(KHomePhone, "homephone%d"); |
|
36 _LIT(KHomeMobile, "homemobile%d"); |
|
37 _LIT(KFax, "fax%d"); |
|
38 _LIT(KWorkEmailAddress, "workemail%d"); |
|
39 _LIT(KInternetAddress, "internet%d"); |
|
40 _LIT(KStreet, "street%d"); |
|
41 _LIT(KTown, "town%d"); |
|
42 _LIT(KCounty, "county%d"); |
|
43 _LIT(KPostCode, "postcode%d"); |
|
44 _LIT(KCountry, "country%d"); |
|
45 _LIT(KNotes, "notes%d"); |
|
46 _LIT(KNickName, "nickName%d"); |
|
47 _LIT(KPictureName, "picturename%d"); |
|
48 _LIT(KGroupName, "groupname%d"); |
|
49 _LIT(KTemplateName, "templatename%d"); |
|
50 _LIT(KOneFieldTemplate, "OneFieldTemplate"); |
|
51 /*@}*/ |
|
52 |
|
53 |
|
54 CTestContactsAddEntries::CTestContactsAddEntries() |
|
55 /** |
|
56 Default Constructor |
|
57 */ |
|
58 { |
|
59 SetTestStepName(_L("AddEntries")); |
|
60 } |
|
61 |
|
62 CTestContactsAddEntries::~CTestContactsAddEntries() |
|
63 /** |
|
64 Destructor |
|
65 */ |
|
66 { |
|
67 } |
|
68 |
|
69 // Each test step must supply a implementation for doTestStepL |
|
70 enum TVerdict CTestContactsAddEntries::doTestStepL() |
|
71 /** |
|
72 invoked by the test execute framework for exercising the |
|
73 functionality under test |
|
74 @return EPass: The test passed succesfully; |
|
75 EFail: The test failed; |
|
76 EInconclusive: The result of the test was inconclusive; |
|
77 ETestSuiteError: Error in the test suite; |
|
78 EAbort: The test was aborted; |
|
79 EIgnore: The test was unexecuted |
|
80 @leave system wide error codes |
|
81 */ |
|
82 { |
|
83 |
|
84 // Printing to the console and log file |
|
85 INFO_PRINTF1(_L("Contacts Add Entries Test")); |
|
86 |
|
87 OpenDatabase(); |
|
88 if ( TestStepResult() == EPass ) |
|
89 { |
|
90 TRAPD(r, AddEntriesL()); |
|
91 if (r!=KErrNone) |
|
92 { |
|
93 ERR_PRINTF2(_L("Test step failed with error code = %d"), r); |
|
94 SetTestStepResult(EFail); |
|
95 } |
|
96 } |
|
97 CleanupDatabase(); |
|
98 |
|
99 // test steps return a result |
|
100 return TestStepResult(); |
|
101 } |
|
102 |
|
103 void CTestContactsAddEntries::AddEntriesL() |
|
104 /** |
|
105 This function adds contact entries to the database depending on entry type. |
|
106 If the entry contains the group name then the contact will be added to the |
|
107 particular group specified in the entry. If the entry contains the template |
|
108 name then the contact item depending on the specified template name will be |
|
109 created and added to the database. |
|
110 |
|
111 @leave system wide error code |
|
112 */ |
|
113 { |
|
114 TBool groupExists = EFalse; |
|
115 TBool templateFound = EFalse; |
|
116 TInt count=1; |
|
117 |
|
118 if ( !GetIntFromConfig(ConfigSection(), KCount, count) ) |
|
119 { |
|
120 count=1; |
|
121 } |
|
122 |
|
123 INFO_PRINTF2(_L("Number of Entries to Add = %d"), count); |
|
124 |
|
125 TBuf<KMaxScriptLineLength> tempStore; |
|
126 TPtrC ptrString; |
|
127 |
|
128 /******************************************************************* |
|
129 To Create a contact card template depending upon the contact item |
|
130 on which the new template's field set is based. The template name |
|
131 on which the new template is based is read from the ini file. |
|
132 *******************************************************************/ |
|
133 |
|
134 for (TInt entry=0; entry<count; ) |
|
135 { |
|
136 CContactItem* item = NULL; |
|
137 |
|
138 // The entry contains the template name |
|
139 tempStore.Format(KTemplateName(), ++entry); |
|
140 if (!GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
141 { |
|
142 INFO_PRINTF2(_L("Entry %d has no Template Name"), entry); |
|
143 item = iDatabase->CreateContactCardTemplateLC(KCardTemplateName); |
|
144 } |
|
145 else |
|
146 { |
|
147 INFO_PRINTF2(_L("Template Name = %S"), &ptrString); |
|
148 CContactIdArray* templateList = NULL; |
|
149 CContactItem* tempTemplate = NULL; |
|
150 |
|
151 // Returns a copy of the database's template ID list |
|
152 templateList = iDatabase->GetCardTemplateIdListL(); |
|
153 CleanupStack::PushL(templateList); |
|
154 |
|
155 // Returns the number of contact card templates that currently exist in the database. |
|
156 TInt tCount = iDatabase->TemplateCount(); |
|
157 INFO_PRINTF2(_L("Number of existing templates = %d"), tCount); |
|
158 |
|
159 // Search for template in the template ID list |
|
160 for(TInt i = 0; i<tCount && templateFound == EFalse;i++) |
|
161 { |
|
162 // Reads a contact item |
|
163 tempTemplate = STATIC_CAST(CContactItem*, iDatabase->ReadContactLC((*templateList)[i])); |
|
164 |
|
165 // Gets the label for a contact card template. |
|
166 TPtrC tempLabel = STATIC_CAST(CContactCardTemplate*,tempTemplate)->GetTemplateLabelL(); |
|
167 |
|
168 // Compare the template label |
|
169 if(!(tempLabel.Compare(ptrString))) |
|
170 { |
|
171 INFO_PRINTF2(_L("Template %S found"), &tempLabel); |
|
172 |
|
173 // Creates a contact card template and adds it to the database |
|
174 item = iDatabase->CreateContactCardTemplateLC(tempTemplate,tempLabel); |
|
175 |
|
176 // Compare the template label with OneFieldTemplate and add field to it. |
|
177 if(!(tempLabel.Compare(KOneFieldTemplate))) |
|
178 { |
|
179 // Allocates and constructs a contact item field |
|
180 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName); |
|
181 item->AddFieldL(*field); |
|
182 CleanupStack::Pop(field); // field |
|
183 } |
|
184 CleanupStack::Pop(item); |
|
185 templateFound = ETrue; |
|
186 } |
|
187 CleanupStack::PopAndDestroy(tempTemplate); |
|
188 } |
|
189 |
|
190 if (!templateFound) |
|
191 { |
|
192 ERR_PRINTF2(_L("Ini Template %S does not match existing templates"), &ptrString); |
|
193 SetTestStepResult(EFail); |
|
194 } |
|
195 |
|
196 // Set templateFound to false for next entry |
|
197 templateFound = EFalse; |
|
198 |
|
199 CleanupStack::PopAndDestroy(templateList); |
|
200 CleanupStack::PushL(item); |
|
201 } |
|
202 |
|
203 CTestContact* contact=CTestContact::NewLC(*item); |
|
204 |
|
205 tempStore.Format(KFirstName(), entry); |
|
206 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
207 { |
|
208 INFO_PRINTF2(_L("firstname = %S"), &ptrString); |
|
209 contact->SetFirstNameL(ptrString); |
|
210 } |
|
211 |
|
212 tempStore.Format(KNickName(), entry); |
|
213 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
214 { |
|
215 INFO_PRINTF2(_L("NickName = %S"), &ptrString); |
|
216 TRAPD(err, contact->SetNickNameL(ptrString)); |
|
217 if ( err != KErrNone ) |
|
218 { |
|
219 ERR_PRINTF2(_L("SetNickNameL Leave = %d"), err); |
|
220 SetTestStepResult(EFail); |
|
221 } |
|
222 } |
|
223 |
|
224 tempStore.Format(KLastName(), entry); |
|
225 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
226 { |
|
227 INFO_PRINTF2(_L("lastname = %S"), &ptrString); |
|
228 contact->SetLastNameL(ptrString); |
|
229 } |
|
230 |
|
231 tempStore.Format(KCompanyName(), entry); |
|
232 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
233 { |
|
234 INFO_PRINTF2(_L("company = %S"), &ptrString); |
|
235 contact->SetCompanyNameL(ptrString); |
|
236 } |
|
237 |
|
238 tempStore.Format(KJobTitle(), entry); |
|
239 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
240 { |
|
241 INFO_PRINTF2(_L("job = %S"), &ptrString); |
|
242 contact->SetJobTitleL(ptrString); |
|
243 } |
|
244 |
|
245 tempStore.Format(KWorkPhone(), entry); |
|
246 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
247 { |
|
248 INFO_PRINTF2(_L("work phone = %S"), &ptrString); |
|
249 contact->SetWorkPhoneL(ptrString); |
|
250 } |
|
251 |
|
252 tempStore.Format(KWorkMobile(), entry); |
|
253 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
254 { |
|
255 INFO_PRINTF2(_L("work mobile = %S"), &ptrString); |
|
256 contact->SetWorkMobileL(ptrString); |
|
257 } |
|
258 |
|
259 tempStore.Format(KHomePhone(), entry); |
|
260 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
261 { |
|
262 INFO_PRINTF2(_L("home phone = %S"), &ptrString); |
|
263 contact->SetHomePhoneL(ptrString); |
|
264 } |
|
265 |
|
266 tempStore.Format(KHomeMobile(), entry); |
|
267 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
268 { |
|
269 INFO_PRINTF2(_L("home mobile = %S"), &ptrString); |
|
270 contact->SetHomeMobileL(ptrString); |
|
271 } |
|
272 |
|
273 tempStore.Format(KFax(), entry); |
|
274 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
275 { |
|
276 INFO_PRINTF2(_L("fax = %S"), &ptrString); |
|
277 contact->SetFaxL(ptrString); |
|
278 } |
|
279 |
|
280 tempStore.Format(KWorkEmailAddress(), entry); |
|
281 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
282 { |
|
283 INFO_PRINTF2(_L("work email = %S"), &ptrString); |
|
284 contact->SetWorkEmailAddressL(ptrString); |
|
285 } |
|
286 |
|
287 tempStore.Format(KInternetAddress(), entry); |
|
288 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
289 { |
|
290 INFO_PRINTF2(_L("internet = %S"), &ptrString); |
|
291 contact->SetInternetAddressL(ptrString); |
|
292 } |
|
293 |
|
294 tempStore.Format(KStreet(), entry); |
|
295 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
296 { |
|
297 INFO_PRINTF2(_L("street = %S"), &ptrString); |
|
298 contact->SetStreetL(ptrString); |
|
299 } |
|
300 |
|
301 tempStore.Format(KTown(), entry); |
|
302 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
303 { |
|
304 INFO_PRINTF2(_L("town = %S"), &ptrString); |
|
305 contact->SetTownL(ptrString); |
|
306 } |
|
307 |
|
308 tempStore.Format(KCounty(), entry); |
|
309 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
310 { |
|
311 INFO_PRINTF2(_L("county = %S"), &ptrString); |
|
312 contact->SetCountyL(ptrString); |
|
313 } |
|
314 |
|
315 tempStore.Format(KPostCode(), entry); |
|
316 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
317 { |
|
318 INFO_PRINTF2(_L("post code = %S"), &ptrString); |
|
319 contact->SetPostCodeL(ptrString); |
|
320 } |
|
321 |
|
322 tempStore.Format(KCountry(), entry); |
|
323 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
324 { |
|
325 INFO_PRINTF2(_L("country = %S"), &ptrString); |
|
326 contact->SetCountryL(ptrString); |
|
327 } |
|
328 |
|
329 tempStore.Format(KNotes(), entry); |
|
330 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
331 { |
|
332 INFO_PRINTF2(_L("notes = %S"), &ptrString); |
|
333 contact->SetNotesL(ptrString); |
|
334 } |
|
335 |
|
336 tempStore.Format(KPictureName(), entry); |
|
337 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
338 { |
|
339 INFO_PRINTF2(_L("Picture Name = %S"), &ptrString); |
|
340 |
|
341 HBufC8* pictureName8 = HBufC8::NewLC(ptrString.Length()); |
|
342 pictureName8->Des().Copy(ptrString); |
|
343 |
|
344 contact->SetPictureL(*pictureName8); |
|
345 |
|
346 CleanupStack::PopAndDestroy(pictureName8); |
|
347 } |
|
348 |
|
349 tempStore.Format(KGroupName(), entry); |
|
350 if (GetStringFromConfig(ConfigSection(), tempStore, ptrString)) |
|
351 { |
|
352 INFO_PRINTF2(_L("Group Name = %S"), &ptrString); |
|
353 |
|
354 // Flag for adding contacts to group. |
|
355 groupExists = ETrue; |
|
356 } |
|
357 |
|
358 const TContactItemId id = iDatabase->AddNewContactL(contact->ContactItem()); |
|
359 |
|
360 /******************************************************************** |
|
361 This is for adding the contact entry to the specified group. |
|
362 ********************************************************************/ |
|
363 if(groupExists) |
|
364 { |
|
365 INFO_PRINTF1(_L("Adding Item ")); |
|
366 CContactIdArray* groupList = NULL; |
|
367 |
|
368 // Returns a copy of the database's group ID list |
|
369 groupList = iDatabase->GetGroupIdListL(); |
|
370 CleanupStack::PushL(groupList); |
|
371 |
|
372 // Returns the number of groups that currently exist in the database |
|
373 TInt groupCount = iDatabase->GroupCount(); |
|
374 |
|
375 |
|
376 // Search for the group |
|
377 for(TInt i = 0; i<groupCount;i++) |
|
378 { |
|
379 // Reads a contact item |
|
380 CContactGroup* group = STATIC_CAST(CContactGroup*, iDatabase->ReadContactLC((*groupList)[i])); |
|
381 |
|
382 // Gets the contact item's ID. |
|
383 const TContactItemId groupId1 = group->Id(); |
|
384 |
|
385 // Gets the group label. |
|
386 TPtrC label = group->GetGroupLabelL(); |
|
387 // Compare the group label with group name read from ini file. |
|
388 if(!(label.Compare(ptrString))) |
|
389 { |
|
390 /** |
|
391 Sets a contact item which already exists in the database |
|
392 to be a member of a contact group |
|
393 */ |
|
394 iDatabase->AddContactToGroupL(id, groupId1); |
|
395 INFO_PRINTF1(_L("Item added successfully")); |
|
396 groupExists = EFalse; |
|
397 } |
|
398 CleanupStack::PopAndDestroy(group); |
|
399 |
|
400 } |
|
401 CleanupStack::PopAndDestroy(groupList); |
|
402 } |
|
403 |
|
404 CleanupStack::PopAndDestroy(contact); |
|
405 CleanupStack::PopAndDestroy(item); |
|
406 |
|
407 } |
|
408 } |