|
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 "TestDeleteMultipleContactsStep.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 CTestDeleteMultipleContactsStep::iStorage[]= |
|
27 { |
|
28 KStorageTypeText, KStorageTypeText, KStorageTypeDateTime, KStorageTypeText,KStorageTypeText,KStorageTypeText,KStorageTypeText |
|
29 }; |
|
30 |
|
31 TUid CTestDeleteMultipleContactsStep::iFieldUid[]= |
|
32 { |
|
33 KUidContactFieldAssistant, KUidContactFieldPhoneNumber, KUidContactFieldAnniversary,KUidContactFieldSpouse,KUidContactFieldChildren,KUidContactFieldClass,KUidContactFieldDepartmentName |
|
34 }; |
|
35 |
|
36 TUid CTestDeleteMultipleContactsStep::iVcardUid[]= |
|
37 { |
|
38 KUidContactFieldVCardMapAssistant, KUidContactFieldVCardMapAssistantTel, KUidContactFieldVCardMapAnniversary, KUidContactFieldVCardMapSpouse,KUidContactFieldVCardMapChildren,KUidContactFieldVCardMapClass,KUidContactFieldVCardMapDepartment |
|
39 }; |
|
40 |
|
41 CTestDeleteMultipleContactsStep::~CTestDeleteMultipleContactsStep() |
|
42 /** |
|
43 * Destructor |
|
44 */ |
|
45 { |
|
46 |
|
47 } |
|
48 |
|
49 CTestDeleteMultipleContactsStep::CTestDeleteMultipleContactsStep() |
|
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(KTestDeleteMultipleContactsStep); |
|
58 } |
|
59 |
|
60 TVerdict CTestDeleteMultipleContactsStep::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 CTestDeleteMultipleContactsStep::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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 CreateAndDeleteMultipleContactsL(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 then Delete the multiple contact item field. |
|
139 * aValue - field value |
|
140 * @param aStorageType - Storage type of each field |
|
141 * @param aContFieldUid - Uid of Contact field |
|
142 * @param avCardMapUid - Uid of vCard |
|
143 * @return - void |
|
144 */ |
|
145 void CTestDeleteMultipleContactsStep::CreateAndDeleteMultipleContactsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap) |
|
146 { |
|
147 TPtrC value, updateVal, getUpdateValue; |
|
148 CContactDatabase *dBase; |
|
149 _LIT(KTestDbName, "c:contactmultiple.cdb"); |
|
150 TInt year, month, day,noOfCI; |
|
151 TContactItemId id = 0; |
|
152 RArray <TInt> idArray; |
|
153 CleanupClosePushL(idArray); |
|
154 |
|
155 //replace existing database name |
|
156 dBase = CContactDatabase::ReplaceL(KTestDbName); |
|
157 |
|
158 //Get the number of contact item from ini file |
|
159 GetIntFromConfig(ConfigSection(), KNoOfContactItem, noOfCI); |
|
160 |
|
161 //Get the int value |
|
162 GetIntFromConfig(ConfigSection(), KIniYear, year); |
|
163 GetIntFromConfig(ConfigSection(), KIniMonth, month); |
|
164 GetIntFromConfig(ConfigSection(), KIniDay, day); |
|
165 |
|
166 // Create contact item and add field to it |
|
167 for(TInt range=0;range<noOfCI;range++) |
|
168 { |
|
169 CContactItem* item = CContactCard::NewLC(); |
|
170 CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid); |
|
171 CleanupStack::PushL(field); |
|
172 field->SetMapping(avCardMap); |
|
173 if(aStorageType==KStorageTypeDateTime) |
|
174 { |
|
175 TDateTime date(year,(TMonth)month,day,0,0,0,0); |
|
176 field->DateTimeStorage()->SetTime(date); |
|
177 } |
|
178 else |
|
179 { |
|
180 field->TextStorage()->SetTextL(aValue); |
|
181 } |
|
182 item->AddFieldL(*field); |
|
183 CleanupStack::Pop(field); |
|
184 |
|
185 // add contact item to database |
|
186 id = dBase->AddNewContactL(*item); |
|
187 idArray.Append(id); |
|
188 CleanupStack::PopAndDestroy(item); |
|
189 } |
|
190 dBase->CloseContactL(id); |
|
191 |
|
192 // delete multiple contact item field |
|
193 CContactItem *readItem = NULL; |
|
194 for(TInt readContact=0;readContact<noOfCI;readContact++) |
|
195 { |
|
196 readItem = dBase->ReadContactLC(idArray[readContact]); |
|
197 CContactItemFieldSet& ContactFieldSet = readItem->CardFields(); |
|
198 TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap); |
|
199 if(pos != KErrNotFound) |
|
200 { |
|
201 ContactFieldSet.Remove(pos); |
|
202 SetTestStepResult(EPass); |
|
203 } |
|
204 else |
|
205 { |
|
206 ERR_PRINTF1(_L("field not deleted")); |
|
207 SetTestStepResult(EFail); |
|
208 } |
|
209 CleanupStack::PopAndDestroy(readItem); |
|
210 } |
|
211 INFO_PRINTF1(_L("Field deleted successfully")); |
|
212 |
|
213 //cleanup |
|
214 CleanupStack::PopAndDestroy(&idArray); |
|
215 delete dBase; |
|
216 } |
|
217 TVerdict CTestDeleteMultipleContactsStep::doTestStepPostambleL() |
|
218 /** |
|
219 * @return - TVerdict code |
|
220 * Override of base class virtual |
|
221 */ |
|
222 { |
|
223 CActiveScheduler::Install(NULL); |
|
224 delete iScheduler; |
|
225 return TestStepResult(); |
|
226 } |
|
227 |
|
228 |