|
1 // Copyright (c) 2003-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 // UpdateForSync Test module |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 //#include <e32def.h> |
|
20 #include <e32test.h> |
|
21 #include <cntdef.hrh> |
|
22 #include <cntdef.h> |
|
23 #include <cntitem.h> |
|
24 #include <cntfield.h> |
|
25 #include <cntfldst.h> |
|
26 #include <e32svr.h> |
|
27 #include <f32file.h> |
|
28 #include "t_utils2.h" |
|
29 #include "T_UTILS.H" |
|
30 |
|
31 _LIT(KTestName, "T_UPDATEFORSYNC"); |
|
32 _LIT(KLogFileName, "UpdateForSyncProfile.log"); |
|
33 |
|
34 LOCAL_D RTest test(KTestName); |
|
35 |
|
36 |
|
37 class CProfiler : public CBase |
|
38 { |
|
39 public: |
|
40 static CProfiler* NewLC(RTest& aTest); |
|
41 ~CProfiler(); |
|
42 |
|
43 void StartProfile(); |
|
44 void EndProfile(); |
|
45 private: |
|
46 RFs iFs; |
|
47 CLog* iLog; |
|
48 }; |
|
49 |
|
50 CProfiler* CProfiler::NewLC(RTest& aTest) |
|
51 { |
|
52 CProfiler* self=new(ELeave) CProfiler(); |
|
53 CleanupStack::PushL(self); |
|
54 User::LeaveIfError(self->iFs.Connect()); |
|
55 self->iLog=CLog::NewL(aTest,KLogFileName); |
|
56 return self; |
|
57 } |
|
58 |
|
59 CProfiler::~CProfiler() |
|
60 { |
|
61 delete iLog; |
|
62 iFs.Close(); |
|
63 } |
|
64 |
|
65 void CProfiler::StartProfile() |
|
66 { |
|
67 CCntTest::ProfileReset(0,1); |
|
68 CCntTest::ProfileStart(0); |
|
69 } |
|
70 |
|
71 void CProfiler::EndProfile() |
|
72 { |
|
73 CCntTest::ProfileEnd(0); |
|
74 TCntProfile profile[1]; |
|
75 CCntTest::ProfileResult(profile,0,1); |
|
76 _LIT(KProfileFormat,"Total %d.%03d sec (%d hits)\n"); |
|
77 RDebug::Print(KProfileFormat,profile[0].iTime/1000000, profile[0].iTime%1000000, profile[0].iCount); |
|
78 iLog->LogLine(KProfileFormat,profile[0].iTime/1000000, profile[0].iTime%1000000, profile[0].iCount); |
|
79 } |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 LOCAL_C void DoTestEmailKeepDefaultPropertyL() |
|
85 { |
|
86 _LIT(KFieldValue,"email@dummy.com"); |
|
87 _LIT(KNewFieldValue,"newemail@dummy.com"); |
|
88 |
|
89 |
|
90 CContactItemFieldSet* fieldSet=CContactItemFieldSet::NewLC(); |
|
91 |
|
92 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
93 field->TextStorage()->SetTextL(KFieldValue()); |
|
94 field->SetMapping(KUidContactFieldVCardMapEMAILINTERNET); |
|
95 field->AddFieldTypeL(KUidContactFieldEMail); |
|
96 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
97 fieldSet->AddL(*field); //take ownership |
|
98 CleanupStack::Pop(field); |
|
99 |
|
100 field=CContactItemField::NewLC(KStorageTypeText); |
|
101 field->TextStorage()->SetTextL(KNewFieldValue()); |
|
102 field->SetMapping(KUidContactFieldVCardMapEMAILINTERNET); |
|
103 field->AddFieldTypeL(KUidContactFieldEMail); |
|
104 |
|
105 |
|
106 fieldSet->UpdateFieldSyncL(*field,1); |
|
107 |
|
108 //Check that default property was not dropped |
|
109 __ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidContactFieldVCardMapPREF),User::Leave(KErrGeneral)); |
|
110 //Check that field was updated properly |
|
111 __ASSERT_ALWAYS((*fieldSet)[0].TextStorage()->Text()==KNewFieldValue(),User::Leave(KErrGeneral)); |
|
112 |
|
113 |
|
114 CleanupStack::PopAndDestroy(2,fieldSet); //field |
|
115 } |
|
116 |
|
117 |
|
118 LOCAL_C void DoTestPhoneKeepDefaultPropertyL() |
|
119 { |
|
120 _LIT(KFieldValue,"+447700900000"); |
|
121 _LIT(KNewFieldValue,"+447700900001"); |
|
122 |
|
123 CContactItemFieldSet* fieldSet=CContactItemFieldSet::NewLC(); |
|
124 |
|
125 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
126 field->TextStorage()->SetTextL(KFieldValue()); |
|
127 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
128 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
129 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
130 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
131 fieldSet->AddL(*field); //take ownership |
|
132 CleanupStack::Pop(field); |
|
133 |
|
134 field=CContactItemField::NewLC(KStorageTypeText); |
|
135 field->TextStorage()->SetTextL(KNewFieldValue()); |
|
136 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
137 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
138 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
139 |
|
140 fieldSet->UpdateFieldSyncL(*field,1); |
|
141 |
|
142 //Check that default property was not dropped |
|
143 __ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidContactFieldVCardMapPREF),User::Leave(KErrGeneral)); |
|
144 //Check that field was updated properly |
|
145 __ASSERT_ALWAYS((*fieldSet)[0].TextStorage()->Text()==KNewFieldValue(),User::Leave(KErrGeneral)); |
|
146 |
|
147 CleanupStack::PopAndDestroy(2,fieldSet); //field |
|
148 } |
|
149 |
|
150 LOCAL_C void DoTestPhoneKeepSpeedDialPropertyL() |
|
151 { |
|
152 _LIT(KFieldValue,"+447700900002"); |
|
153 _LIT(KNewFieldValue,"+447700900003"); |
|
154 |
|
155 CContactItemFieldSet* fieldSet=CContactItemFieldSet::NewLC(); |
|
156 |
|
157 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
158 field->TextStorage()->SetTextL(KFieldValue()); |
|
159 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
160 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
161 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
162 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
163 field->AddFieldTypeL(KUidSpeedDialFive); |
|
164 fieldSet->AddL(*field); //take ownership |
|
165 CleanupStack::Pop(field); |
|
166 |
|
167 field=CContactItemField::NewLC(KStorageTypeText); |
|
168 field->TextStorage()->SetTextL(KNewFieldValue()); |
|
169 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
170 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
171 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
172 |
|
173 fieldSet->UpdateFieldSyncL(*field,1); |
|
174 |
|
175 //Check that default property was not dropped |
|
176 __ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidContactFieldVCardMapPREF),User::Leave(KErrGeneral)); |
|
177 //Check that speed dial property was not dropped |
|
178 __ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidSpeedDialFive),User::Leave(KErrGeneral)); |
|
179 //Check that field was updated properly |
|
180 __ASSERT_ALWAYS((*fieldSet)[0].TextStorage()->Text()==KNewFieldValue(),User::Leave(KErrGeneral)); |
|
181 |
|
182 CleanupStack::PopAndDestroy(2,fieldSet); //field |
|
183 } |
|
184 |
|
185 void DoTestPhoneKeepVoiceDialPropertyL() |
|
186 { |
|
187 _LIT(KFieldValue,"+447700900004"); |
|
188 _LIT(KNewFieldValue,"+447700900005"); |
|
189 |
|
190 CContactItemFieldSet* fieldSet=CContactItemFieldSet::NewLC(); |
|
191 |
|
192 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
193 field->TextStorage()->SetTextL(KFieldValue()); |
|
194 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
195 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
196 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
197 //field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
198 field->AddFieldTypeL(KUidContactsVoiceDialField); |
|
199 fieldSet->AddL(*field); //take ownership |
|
200 CleanupStack::Pop(field); |
|
201 |
|
202 field=CContactItemField::NewLC(KStorageTypeText); |
|
203 field->TextStorage()->SetTextL(KNewFieldValue()); |
|
204 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
205 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
206 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
207 |
|
208 fieldSet->UpdateFieldSyncL(*field,1); |
|
209 |
|
210 //Check that default property was not dropped |
|
211 //__ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidContactFieldVCardMapPREF),User::Leave(KErrGeneral)); |
|
212 //Check that speed dial property was not dropped |
|
213 __ASSERT_ALWAYS((*fieldSet)[0].ContentType().ContainsFieldType(KUidContactsVoiceDialField),User::Leave(KErrGeneral)); |
|
214 //Check that field was updated properly |
|
215 __ASSERT_ALWAYS((*fieldSet)[0].TextStorage()->Text()==KNewFieldValue(),User::Leave(KErrGeneral)); |
|
216 |
|
217 CleanupStack::PopAndDestroy(2,fieldSet); //field |
|
218 |
|
219 } |
|
220 |
|
221 |
|
222 void DoProfilingL() |
|
223 { |
|
224 _LIT(KFieldValue,"+447700900006"); |
|
225 _LIT(KNewFieldValue,"+447700900007"); |
|
226 |
|
227 CProfiler* profiler=CProfiler::NewLC(test); |
|
228 |
|
229 CContactItemFieldSet* fieldSet=CContactItemFieldSet::NewLC(); |
|
230 |
|
231 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); |
|
232 field->TextStorage()->SetTextL(KFieldValue()); |
|
233 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
234 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
235 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
236 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
237 fieldSet->AddL(*field); //take ownership |
|
238 CleanupStack::Pop(field); |
|
239 |
|
240 field=CContactItemField::NewLC(KStorageTypeText); |
|
241 field->TextStorage()->SetTextL(KFieldValue()); |
|
242 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
243 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
244 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
245 field->AddFieldTypeL(KUidContactFieldVCardMapCELL); |
|
246 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
247 fieldSet->AddL(*field); //take ownership |
|
248 CleanupStack::Pop(field); |
|
249 |
|
250 field=CContactItemField::NewLC(KStorageTypeText); |
|
251 field->TextStorage()->SetTextL(KFieldValue()); |
|
252 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
253 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
254 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
255 field->AddFieldTypeL(KUidContactFieldVCardMapCELL); |
|
256 field->AddFieldTypeL(KUidContactFieldVCardMapWORK); |
|
257 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
258 fieldSet->AddL(*field); //take ownership |
|
259 CleanupStack::Pop(field); |
|
260 |
|
261 field=CContactItemField::NewLC(KStorageTypeText); |
|
262 field->TextStorage()->SetTextL(KFieldValue()); |
|
263 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
264 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
265 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
266 field->AddFieldTypeL(KUidContactFieldVCardMapWORK); |
|
267 field->AddFieldTypeL(KUidContactFieldVCardMapPREF); |
|
268 fieldSet->AddL(*field); //take ownership |
|
269 CleanupStack::Pop(field); |
|
270 |
|
271 |
|
272 field=CContactItemField::NewLC(KStorageTypeText); |
|
273 field->TextStorage()->SetTextL(KNewFieldValue()); |
|
274 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
275 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
276 //field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
277 field->AddFieldTypeL(KUidContactFieldVCardMapWORK); |
|
278 |
|
279 |
|
280 |
|
281 profiler->StartProfile(); |
|
282 for (TInt i=0;i<1000;i++) |
|
283 { |
|
284 fieldSet->UpdateFieldSyncL(*field,1); |
|
285 } |
|
286 profiler->EndProfile(); |
|
287 CleanupStack::PopAndDestroy(3,profiler); //fieldset, field |
|
288 } |
|
289 |
|
290 /** |
|
291 |
|
292 @SYMTestCaseID PIM-T-UPDATEFORSYNC-0001 |
|
293 |
|
294 */ |
|
295 |
|
296 LOCAL_C void DoTestsL() |
|
297 { |
|
298 test.Start(_L("@SYMTESTCaseID:PIM-T-UPDATEFORSYNC-0001 T_UPDATEFORSYNC")); |
|
299 |
|
300 |
|
301 DoProfilingL(); |
|
302 |
|
303 DoTestEmailKeepDefaultPropertyL(); |
|
304 DoTestPhoneKeepDefaultPropertyL(); |
|
305 DoTestPhoneKeepSpeedDialPropertyL(); |
|
306 DoTestPhoneKeepVoiceDialPropertyL(); |
|
307 |
|
308 |
|
309 test.End(); |
|
310 } |
|
311 |
|
312 GLDEF_C TInt E32Main() |
|
313 { |
|
314 // Init |
|
315 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
316 if (!cleanupStack) |
|
317 { |
|
318 return KErrNoMemory; |
|
319 } |
|
320 |
|
321 // Run the tests |
|
322 __UHEAP_MARK; |
|
323 TRAPD(err, DoTestsL()); |
|
324 test.Close(); //avoid memory leak |
|
325 __UHEAP_MARKEND; |
|
326 // Cleanup |
|
327 |
|
328 if (err) |
|
329 { |
|
330 User::Panic(_L("T_UpdateForSync Failed !"),err); |
|
331 } |
|
332 |
|
333 delete cleanupStack; |
|
334 return err; |
|
335 } |