|
1 // Copyright (c) 2005-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 "TestUpdateMultipleContactsStep.h" |
|
17 #include "TestContactSuiteServer.h" |
|
18 #include <cntitem.h> |
|
19 #include <cntfield.h> |
|
20 #include <cntfldst.h> |
|
21 #include <cntdef.h> |
|
22 #include <cntdb.h> |
|
23 #include <commdb.h> |
|
24 |
|
25 |
|
26 TInt CTestUpdateMultipleContactsStep::iStorage[]= |
|
27 { |
|
28 KStorageTypeText, KStorageTypeText, KStorageTypeDateTime, KStorageTypeText,KStorageTypeText,KStorageTypeText,KStorageTypeText |
|
29 }; |
|
30 |
|
31 TUid CTestUpdateMultipleContactsStep::iFieldUid[]= |
|
32 { |
|
33 KUidContactFieldAssistant, KUidContactFieldPhoneNumber, KUidContactFieldAnniversary,KUidContactFieldSpouse,KUidContactFieldChildren,KUidContactFieldClass,KUidContactFieldDepartmentName |
|
34 }; |
|
35 |
|
36 TUid CTestUpdateMultipleContactsStep::iVcardUid[]= |
|
37 { |
|
38 KUidContactFieldVCardMapAssistant, KUidContactFieldVCardMapAssistantTel, KUidContactFieldVCardMapAnniversary, KUidContactFieldVCardMapSpouse,KUidContactFieldVCardMapChildren,KUidContactFieldVCardMapClass,KUidContactFieldVCardMapDepartment |
|
39 }; |
|
40 |
|
41 CTestUpdateMultipleContactsStep::~CTestUpdateMultipleContactsStep() |
|
42 /** |
|
43 * Destructor |
|
44 */ |
|
45 { |
|
46 |
|
47 } |
|
48 |
|
49 CTestUpdateMultipleContactsStep::CTestUpdateMultipleContactsStep() |
|
50 /** |
|
51 * Constructor |
|
52 */ |
|
53 { |
|
54 // **MUST** call SetTestStepName in the constructor as the controlling |
|
55 // framework uses the test step name immediately following construction to set |
|
56 // up the step's unique logging ID. |
|
57 SetTestStepName(KTestUpdateMultipleContactsStep); |
|
58 } |
|
59 |
|
60 TVerdict CTestUpdateMultipleContactsStep::doTestStepPreambleL() |
|
61 /** |
|
62 * @return - TVerdict code |
|
63 * Override of base class virtual |
|
64 */ |
|
65 { |
|
66 iScheduler = new (ELeave) CActiveScheduler; |
|
67 CActiveScheduler::Install(iScheduler); |
|
68 SetTestStepResult(EPass); |
|
69 return TestStepResult(); |
|
70 } |
|
71 |
|
72 TVerdict CTestUpdateMultipleContactsStep::doTestStepL() |
|
73 /** |
|
74 * @return - TVerdict code |
|
75 * Override of base class pure virtual |
|
76 */ |
|
77 { |
|
78 TPtrC fieldName,fieldVal, fieldMultiple; |
|
79 if (!GetStringFromConfig(ConfigSection(), KIniFieldName, fieldName)) |
|
80 { |
|
81 ERR_PRINTF1(_L("Unable to read fieldname from ini file")); |
|
82 SetTestStepResult(EFail); |
|
83 } |
|
84 else |
|
85 { |
|
86 if(KErrNone == fieldName.Compare(KAssistance)) |
|
87 { |
|
88 //Get the Field value |
|
89 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
90 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]); |
|
91 } |
|
92 else if(KErrNone == fieldName.Compare(KAssistanceTel)) |
|
93 { |
|
94 //Get the Field value |
|
95 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
96 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]); |
|
97 } |
|
98 else if(KErrNone == fieldName.Compare(KAnniversary)) |
|
99 { |
|
100 //Get the Field value |
|
101 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
102 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]); |
|
103 } |
|
104 else if(KErrNone == fieldName.Compare(KSpouse)) |
|
105 { |
|
106 //Get the Field value |
|
107 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
108 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]); |
|
109 } |
|
110 else if(KErrNone == fieldName.Compare(KChildren)) |
|
111 { |
|
112 //Get the Field value |
|
113 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
114 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]); |
|
115 } |
|
116 else if(KErrNone == fieldName.Compare(KClass)) |
|
117 { |
|
118 //Get the Field value |
|
119 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
120 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]); |
|
121 } |
|
122 else if(KErrNone == fieldName.Compare(KDepartment)) |
|
123 { |
|
124 //Get the Field value |
|
125 GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal); |
|
126 CreateAndUpdateMultipleContactsL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]); |
|
127 } |
|
128 else |
|
129 { |
|
130 ERR_PRINTF1(_L("Invalid fieldname")); |
|
131 SetTestStepResult(EFail); |
|
132 } |
|
133 } |
|
134 return TestStepResult(); |
|
135 } |
|
136 |
|
137 /** Create Multiple Contact Item with field and Add all contact |
|
138 * Item to Contact database. Update the multiple contact item field value and |
|
139 * verify field is being updated. |
|
140 * aValue - field value |
|
141 * @param aStorageType - Storage type of each field |
|
142 * @param aContFieldUid - Uid of Contact field |
|
143 * @param avCardMapUid - Uid of vCard |
|
144 * @return - void |
|
145 */ |
|
146 void CTestUpdateMultipleContactsStep::CreateAndUpdateMultipleContactsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap) |
|
147 { |
|
148 TPtrC value, updateVal, getUpdateValue; |
|
149 CContactDatabase *dBase = NULL; |
|
150 _LIT(KTestDbName, "c:contactmultiple.cdb"); |
|
151 TInt year, month, day,noOfCI; |
|
152 TContactItemId id = 0; |
|
153 RArray <TInt> idArray; |
|
154 CleanupClosePushL(idArray); |
|
155 |
|
156 //replace existing database name |
|
157 dBase = CContactDatabase::ReplaceL(KTestDbName); |
|
158 |
|
159 //Get the number of contact item from ini file |
|
160 GetIntFromConfig(ConfigSection(), KNoOfContactItem, noOfCI); |
|
161 |
|
162 //Get the int value |
|
163 GetIntFromConfig(ConfigSection(), KIniYear, year); |
|
164 GetIntFromConfig(ConfigSection(), KIniMonth, month); |
|
165 GetIntFromConfig(ConfigSection(), KIniDay, day); |
|
166 |
|
167 // Create contact item and add field to it |
|
168 for(TInt range=0;range<noOfCI;range++) |
|
169 { |
|
170 CContactItem* item = CContactCard::NewLC(); |
|
171 CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid); |
|
172 CleanupStack::PushL(field); |
|
173 field->SetMapping(avCardMap); |
|
174 if(aStorageType==KStorageTypeDateTime) |
|
175 { |
|
176 TDateTime date(year,(TMonth)month,day,0,0,0,0); |
|
177 field->DateTimeStorage()->SetTime(date); |
|
178 } |
|
179 else |
|
180 { |
|
181 field->TextStorage()->SetTextL(aValue); |
|
182 } |
|
183 item->AddFieldL(*field); |
|
184 CleanupStack::Pop(field); |
|
185 |
|
186 // add contact item to database |
|
187 id = dBase->AddNewContactL(*item); |
|
188 idArray.Append(id); |
|
189 CleanupStack::PopAndDestroy(item); |
|
190 } |
|
191 dBase->CloseContactL(id); |
|
192 |
|
193 // Get the value from ini file for update |
|
194 GetStringFromConfig(ConfigSection(), KIniUpdatedvalue, updateVal); |
|
195 GetIntFromConfig(ConfigSection(), KIniUpdateYear, year); |
|
196 GetIntFromConfig(ConfigSection(), KIniUpdateMonth, month); |
|
197 GetIntFromConfig(ConfigSection(), KIniUpdateDay, day); |
|
198 |
|
199 // update multiple contact item field value |
|
200 CContactItem *readItem = NULL; |
|
201 for(TInt readContact=0;readContact<noOfCI;readContact++) |
|
202 { |
|
203 readItem = dBase->ReadContactLC(idArray[readContact]); |
|
204 CContactItemFieldSet& ContactFieldSet = readItem->CardFields(); |
|
205 TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap); |
|
206 if(pos != KErrNotFound) |
|
207 { |
|
208 if(aStorageType==KStorageTypeDateTime) |
|
209 { |
|
210 // update the field value |
|
211 TDateTime date(year,(TMonth)month,day,0,0,0,0); |
|
212 ContactFieldSet[pos].DateTimeStorage()->SetTime(date); |
|
213 ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos); |
|
214 |
|
215 // verify the updated field value |
|
216 TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap); |
|
217 TDateTime result=ContactFieldSet[upadtePos].DateTimeStorage()->Time().DateTime(); |
|
218 if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) |
|
219 { |
|
220 SetTestStepResult(EPass); |
|
221 } |
|
222 else |
|
223 { |
|
224 SetTestStepResult(EFail); |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 // Update the field value |
|
230 ContactFieldSet[pos].TextStorage()->SetTextL(updateVal); |
|
231 ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos); |
|
232 |
|
233 // verify the field is being updated |
|
234 TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap); |
|
235 getUpdateValue.Set(ContactFieldSet[upadtePos].TextStorage()->Text()); |
|
236 |
|
237 //set the results |
|
238 if(getUpdateValue.Compare(updateVal)==0 ) |
|
239 { |
|
240 SetTestStepResult(EPass); |
|
241 } |
|
242 else |
|
243 { |
|
244 SetTestStepResult(EFail); |
|
245 } |
|
246 } |
|
247 } |
|
248 CleanupStack::PopAndDestroy(readItem); |
|
249 } |
|
250 CleanupStack::PopAndDestroy(&idArray); |
|
251 delete dBase; |
|
252 } |
|
253 TVerdict CTestUpdateMultipleContactsStep::doTestStepPostambleL() |
|
254 /** |
|
255 * @return - TVerdict code |
|
256 * Override of base class virtual |
|
257 */ |
|
258 { |
|
259 CActiveScheduler::Install(NULL); |
|
260 delete iScheduler; |
|
261 return TestStepResult(); |
|
262 } |
|
263 |
|
264 |