|
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 "TestImpExvCardSuiteStepBase.h" |
|
17 #include "TestImpExvCardSuiteDefs.h" |
|
18 |
|
19 CTestImpExvCardSuiteStepBase::~CTestImpExvCardSuiteStepBase() |
|
20 { |
|
21 } |
|
22 |
|
23 CTestImpExvCardSuiteStepBase::CTestImpExvCardSuiteStepBase() |
|
24 { |
|
25 } |
|
26 |
|
27 void CTestImpExvCardSuiteStepBase::OpenVCFAndImportItemL(TBuf<80> aPath, RFs aFsSession, TInt aIndex) |
|
28 { |
|
29 User::LeaveIfError(aFsSession.Connect()); |
|
30 CleanupClosePushL(aFsSession); |
|
31 RFileReadStream readVCFStream; |
|
32 |
|
33 // Format buf to hold relevant vcf file |
|
34 TBuf<100> buf; |
|
35 buf.Zero(); |
|
36 #ifdef __WINS__ |
|
37 buf.Append(_L("c:")); |
|
38 #else |
|
39 TFileName processFileName = RProcess().FileName(); |
|
40 TParsePtrC parse(processFileName); |
|
41 buf.Append(parse.Drive()); |
|
42 #endif |
|
43 buf.Append(aPath); |
|
44 buf.AppendNum(aIndex); |
|
45 buf.Append(_L(".vcf")); |
|
46 |
|
47 // Open vcf file |
|
48 User::LeaveIfError(readVCFStream.Open(aFsSession, buf, EFileRead)); |
|
49 |
|
50 TBuf<MAX_TEXT_MESSAGE> message; |
|
51 message.Format(KOpenVCFFile, &buf); |
|
52 INFO_PRINTF1(message); |
|
53 |
|
54 CleanupClosePushL(readVCFStream); |
|
55 |
|
56 // Imports the vCard |
|
57 ImportCardL(readVCFStream); |
|
58 |
|
59 CleanupStack::PopAndDestroy(); // pop readVCFStream |
|
60 aFsSession.Close(); |
|
61 CleanupStack::PopAndDestroy(); // pop aFsSession |
|
62 } |
|
63 |
|
64 void CTestImpExvCardSuiteStepBase::ImportCardL(RReadStream& aReadStream) |
|
65 { |
|
66 INFO_PRINTF1(_L("Importing vCard.....")); |
|
67 |
|
68 CVCardToContactsAppConverter* converter=new(ELeave) CVCardToContactsAppConverter; |
|
69 CleanupStack::PushL(converter); // converter |
|
70 |
|
71 CParserVCard* vCard= CParserVCard::NewL(); |
|
72 CleanupStack::PushL(vCard); |
|
73 TInt err = KErrNone; |
|
74 TRAP(err, vCard->InternalizeL(aReadStream)); |
|
75 User::LeaveIfError(err); |
|
76 |
|
77 CContactItem* contactItem = NULL; |
|
78 |
|
79 // the CContactVCardConverter::ELocalTime must be used, so the program expects a local time |
|
80 contactItem = converter->GetVCardAsContactItemLC(*vCard, CVCardToContactsAppConverter::EPreserveAllProperties, 0); |
|
81 |
|
82 // the time would be automatically converted to UTC by the production codes |
|
83 iTimeFromImport = (*contactItem).LastModified(); |
|
84 |
|
85 CleanupStack::PopAndDestroy(3); // GetVCardAsContactItemLC, vCard & converter |
|
86 INFO_PRINTF1(_L("Imported to Contact Entry")); |
|
87 } |
|
88 |
|
89 void CTestImpExvCardSuiteStepBase::OpenBDAYVCFAndImportItemL(TBuf<80> aPath,TInt aIndex) |
|
90 { |
|
91 // Format buf to hold relevant vcf file |
|
92 TFileName fileName; |
|
93 #ifdef __WINS__ |
|
94 fileName.Append(_L("c:")); |
|
95 #else |
|
96 TFileName processFileName = RProcess().FileName(); |
|
97 TParsePtrC parse(processFileName); |
|
98 fileName.Append(parse.Drive()); |
|
99 #endif |
|
100 fileName.Append(aPath); |
|
101 fileName.AppendNum(aIndex); |
|
102 fileName.Append(_L(".vcf")); |
|
103 |
|
104 RFs fs; |
|
105 User::LeaveIfError(fs.Connect()); // push fs |
|
106 CleanupClosePushL(fs); |
|
107 RFileReadStream readVCFStream; |
|
108 User::LeaveIfError(readVCFStream.Open(fs, fileName, EFileRead)); // opens vcf file |
|
109 |
|
110 TBuf<MAX_TEXT_MESSAGE> message; |
|
111 message.Format(KOpenVCFFile, &fileName); |
|
112 INFO_PRINTF1(message); |
|
113 |
|
114 CleanupClosePushL(readVCFStream); // readVCFStream |
|
115 |
|
116 ImportBDAYCardL(readVCFStream); |
|
117 |
|
118 CleanupStack::PopAndDestroy(); // pop readVCFStream |
|
119 fs.Close(); |
|
120 CleanupStack::PopAndDestroy(); // pop fs |
|
121 } |
|
122 |
|
123 void CTestImpExvCardSuiteStepBase::ImportBDAYCardL(RReadStream& aReadStream) |
|
124 { |
|
125 INFO_PRINTF1(_L("Importing vCard.....")); |
|
126 |
|
127 |
|
128 CVCardToContactsAppConverter* converter=new(ELeave) CVCardToContactsAppConverter; |
|
129 CleanupStack::PushL(converter); // converter |
|
130 |
|
131 CParserVCard* vCard= CParserVCard::NewL(); |
|
132 CleanupStack::PushL(vCard); |
|
133 TInt err = KErrNone; |
|
134 TRAP(err, vCard->InternalizeL(aReadStream)); |
|
135 User::LeaveIfError(err); |
|
136 |
|
137 CContactItem* contactItem = NULL; |
|
138 |
|
139 // set to local time |
|
140 contactItem = converter->GetVCardAsContactItemLC(*vCard, CVCardToContactsAppConverter::EPreserveAllProperties, CContactVCardConverter::ELocalTime); |
|
141 |
|
142 CContactItemFieldSet& cardFields = contactItem->CardFields(); |
|
143 |
|
144 INFO_PRINTF1(_L("Looking for Birthday field in Contact entry.....")); |
|
145 TInt pos = cardFields.Find(KUidContactFieldBirthday); |
|
146 |
|
147 if (pos==KErrNotFound) |
|
148 { |
|
149 INFO_PRINTF1(_L("Birthday field not found in Contact entry")); |
|
150 iBDayFromImport = NULL; |
|
151 } |
|
152 else |
|
153 { |
|
154 INFO_PRINTF1(_L("Birthday field found in Contact entry")); |
|
155 CContactItemField& itemField = cardFields[pos]; |
|
156 |
|
157 CContactDateField* dateTimeField = itemField.DateTimeStorage(); |
|
158 CleanupStack::PushL(dateTimeField); |
|
159 |
|
160 iBDayFromImport = dateTimeField->Time(); |
|
161 |
|
162 CleanupStack::Pop(); |
|
163 } |
|
164 |
|
165 INFO_PRINTF1(_L("Imported to Contact Entry")); |
|
166 |
|
167 CleanupStack::PopAndDestroy(3); |
|
168 } |
|
169 |
|
170 void CTestImpExvCardSuiteStepBase::ExportItemL(TBuf<80> aPath, TBool aAddBDay) |
|
171 { |
|
172 OpenDBL(); |
|
173 |
|
174 TContactItemId itemId; |
|
175 RFs fsSession; |
|
176 RFileWriteStream fileStream; |
|
177 |
|
178 CContactIdArray* idArray = NULL; |
|
179 CContactCard* contactAdded = NULL; |
|
180 TTime now; |
|
181 |
|
182 User::LeaveIfError(fsSession.Connect()); |
|
183 CleanupClosePushL(fsSession); |
|
184 |
|
185 idArray = CContactIdArray::NewL(); |
|
186 |
|
187 CleanupStack::PushL(idArray); // idArray |
|
188 |
|
189 fsSession.MkDirAll(aPath); |
|
190 User::LeaveIfError(fileStream.Replace(fsSession, aPath, EFileWrite)); |
|
191 |
|
192 contactAdded = CContactCard::NewL(); |
|
193 |
|
194 CleanupStack::PushL(contactAdded); // contactAdded |
|
195 |
|
196 contactAdded->IncAccessCount(); |
|
197 |
|
198 // ADD BDAY |
|
199 if (aAddBDay) |
|
200 { |
|
201 CContactItemFieldSet& fieldSet=contactAdded->CardFields(); |
|
202 const TInt pos=fieldSet.Find(KUidContactFieldBirthday); |
|
203 |
|
204 if (pos!=KErrNotFound) |
|
205 { |
|
206 fieldSet[pos].DateTimeStorage()->SetTime(iBDayLocal); |
|
207 } |
|
208 else |
|
209 { |
|
210 CContactItemField* field=CContactItemField::NewLC(KStorageTypeDateTime,KUidContactFieldBirthday); |
|
211 field->SetMapping(KUidContactFieldVCardMapBDAY); |
|
212 field->DateTimeStorage()->SetTime(iBDayLocal); |
|
213 contactAdded->AddFieldL(*field); |
|
214 |
|
215 CleanupStack::Pop(); // field |
|
216 } |
|
217 } |
|
218 |
|
219 SetNameL(*contactAdded, KUidContactFieldGivenName, _L("toby"), ETrue); |
|
220 SetNameL(*contactAdded, KUidContactFieldPhoneNumber, _L("6041233214"), ETrue); |
|
221 |
|
222 User::After(3000000); |
|
223 |
|
224 // There is no need to call SetLastModifed because |
|
225 // That function will be call by ExportSelectedContactsL below |
|
226 now.UniversalTime(); |
|
227 iRecordedTime = now; |
|
228 |
|
229 INFO_PRINTF1(_L("Adding contact to Database.....")); |
|
230 itemId = iDb->AddNewContactL(*contactAdded); |
|
231 INFO_PRINTF1(_L("Contact Added to Database")); |
|
232 CleanupStack::PopAndDestroy(contactAdded); // contactAdded |
|
233 contactAdded = NULL; |
|
234 |
|
235 idArray->InsertL(0, itemId); |
|
236 |
|
237 INFO_PRINTF1(_L("Exporting Contact.....")); |
|
238 iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, fileStream, CContactVCardConverter::EDefault, ETrue); |
|
239 INFO_PRINTF1(_L("Exported Contact")); |
|
240 fileStream.CommitL(); |
|
241 fileStream.Close(); |
|
242 |
|
243 CleanupStack::PopAndDestroy(idArray); // idArray |
|
244 fsSession.Close(); |
|
245 CleanupStack::PopAndDestroy(); // fsSession |
|
246 CloseDB(); |
|
247 } |
|
248 |
|
249 void CTestImpExvCardSuiteStepBase::ImportItemL(TBuf<80> aPath, TBool aImportBDay) |
|
250 { |
|
251 RFs fs; |
|
252 User::LeaveIfError(fs.Connect()); // push fs |
|
253 CleanupClosePushL(fs); |
|
254 RFileReadStream readVCFStream; |
|
255 |
|
256 INFO_PRINTF1(_L("Opening exported vcf file to import, to check REV property")); |
|
257 |
|
258 User::LeaveIfError(readVCFStream.Open(fs, aPath, EFileRead)); |
|
259 |
|
260 TBuf<MAX_TEXT_MESSAGE> message; |
|
261 message.Format(KOpenVCFFile, &KExportRevUTCFile); |
|
262 INFO_PRINTF1(message); |
|
263 |
|
264 CleanupClosePushL(readVCFStream); // readVCFStream |
|
265 |
|
266 if (aImportBDay) |
|
267 { |
|
268 ImportBDAYCardL(readVCFStream); |
|
269 } |
|
270 else |
|
271 { |
|
272 ImportCardL(readVCFStream); |
|
273 } |
|
274 |
|
275 CleanupStack::PopAndDestroy(); // readVCFStream |
|
276 CleanupStack::PopAndDestroy(); // pop fs |
|
277 } |
|
278 |
|
279 void CTestImpExvCardSuiteStepBase::OpenDBL() |
|
280 { |
|
281 if(iDb == NULL) |
|
282 { |
|
283 INFO_PRINTF1(_L("Opening Contacts Database.....")); |
|
284 iDb = CContactDatabase::ReplaceL(); |
|
285 INFO_PRINTF1(_L("Opened Contacts Database")); |
|
286 } |
|
287 } |
|
288 |
|
289 void CTestImpExvCardSuiteStepBase::CloseDB() |
|
290 { |
|
291 delete iDb; |
|
292 iDb = NULL; |
|
293 } |
|
294 |
|
295 void CTestImpExvCardSuiteStepBase::SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName, TBool aAddField) |
|
296 // |
|
297 // Set the contents of a text field, creating the field if required |
|
298 // |
|
299 { |
|
300 CContactItemFieldSet& fieldSet=aItem.CardFields(); |
|
301 const TInt pos=fieldSet.Find(aType); |
|
302 if (!aAddField && pos!=KErrNotFound) |
|
303 { |
|
304 fieldSet[pos].TextStorage()->SetTextL(aName); |
|
305 } |
|
306 else |
|
307 { |
|
308 CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType); |
|
309 field->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
310 field->TextStorage()->SetTextL(aName); |
|
311 aItem.AddFieldL(*field); |
|
312 CleanupStack::Pop(); // field |
|
313 } |
|
314 } |
|
315 |
|
316 TTime CTestImpExvCardSuiteStepBase::FormatDateTime(const TDesC& aParamString) |
|
317 { |
|
318 // Format of buffer to construct a TTime is YYYYMMDD:HHMMSS (15 characters). |
|
319 // TTime uses zero-based values for month and day - which is confusing for scripting. |
|
320 // In our script, we use actual month and day numbers to make things simpler so we |
|
321 // must modify the string here to take account of this. |
|
322 TBuf<32> buf; |
|
323 TInt m, d; |
|
324 |
|
325 buf.Zero(); |
|
326 buf.Copy(aParamString.Left(4)); // The year |
|
327 TLex lexMonth = aParamString.Mid(4, 2); |
|
328 lexMonth.Val(m); |
|
329 TLex lexDay = aParamString.Mid(6, 2); |
|
330 lexDay.Val(d); |
|
331 buf.AppendFormat(_L("%02d%02d"), m - 1, d - 1); // The month and day |
|
332 buf.Append(aParamString.Right(7)); |
|
333 |
|
334 return TTime(buf); |
|
335 } |
|
336 |
|
337 TPtrC CTestImpExvCardSuiteStepBase::GetExpectedUTCFromIniL(TInt numberOfCases,TBuf<80> aConfig, TBool aExpectedBDay) |
|
338 { |
|
339 TPtrC expectedUTC; |
|
340 TPtrC expectedBDAY; |
|
341 |
|
342 TPtrC config = aConfig; |
|
343 HBufC *configval = HBufC::NewLC(config.Length()+2); |
|
344 |
|
345 TPtr configSection = configval->Des(); |
|
346 |
|
347 configSection.Append(config); |
|
348 configSection.AppendNum(numberOfCases); |
|
349 |
|
350 if (aExpectedBDay) |
|
351 { |
|
352 GetStringFromConfig(configSection,KExpectedBDay,expectedBDAY); |
|
353 CleanupStack::PopAndDestroy(configval); |
|
354 return expectedBDAY; |
|
355 } |
|
356 else |
|
357 { |
|
358 GetStringFromConfig(configSection,KExpectedUTC,expectedUTC); |
|
359 CleanupStack::PopAndDestroy(configval); |
|
360 return expectedUTC; |
|
361 } |
|
362 } |
|
363 |