1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file contains all functions that can be called from cfg file. |
|
15 * These functions call the necessary methods for getting the operation done and |
|
16 * writes the output to the Log. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <e32svr.h> |
|
24 #include<BADESCA.H> |
|
25 #include <StifParser.h> |
|
26 #include <Stiftestinterface.h> |
|
27 #include "TestCntDataStoreExtn.h" |
|
28 #include <utf.h> |
|
29 #include <f32file.h> |
|
30 #include <e32base.h> |
|
31 |
|
32 _LIT8(KContact1, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Contact;Test1;;;\r\nTEL;CELL:1234567890\r\nEND:VCARD\r\n"); |
|
33 _LIT8(KContact2, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Contact;Test2;;;\r\nTEL;CELL:0987654321\r\nEND:VCARD\r\n"); |
|
34 _LIT8(KContact3, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Contact;Test3;;;\r\nTEL;CELL:1324576809\r\nEND:VCARD\r\n"); |
|
35 _LIT8(KContact4, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Contact;Test4;;;\r\nTEL;CELL:0897645321\r\nEND:VCARD\r\n"); |
|
36 _LIT8(KContact5, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Contact;Test5;;;\r\nTEL;CELL:1432586790\r\nEND:VCARD\r\n"); |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CTestCntDataStoreExtn::Delete |
|
42 // Delete here all resources allocated and opened from test methods. |
|
43 // Called from destructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CTestCntDataStoreExtn::Delete() |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CTestCntDataStoreExtn::RunMethodL |
|
53 // Run specified method. Contains also table of test mothods and their names. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TInt CTestCntDataStoreExtn::RunMethodL( |
|
57 CStifItemParser& aItem ) |
|
58 { |
|
59 |
|
60 static TStifFunctionInfo const KFunctions[] = |
|
61 { |
|
62 ENTRY( "ExportContacts" , CTestCntDataStoreExtn::ExportContactsL ), |
|
63 ENTRY( "ImportContacts" , CTestCntDataStoreExtn::ImportContactsL ), |
|
64 ENTRY( "ReadContact" , CTestCntDataStoreExtn::ReadContactL ), |
|
65 ENTRY( "ListContacts" , CTestCntDataStoreExtn::ListContactsL ), |
|
66 ENTRY( "DeleteContact" , CTestCntDataStoreExtn::DeleteContactL ), |
|
67 ENTRY( "DeleteContacts" , CTestCntDataStoreExtn::DeleteContactsL ), |
|
68 ENTRY( "DeleteAllContacts", CTestCntDataStoreExtn::DeleteAllContactsL ), |
|
69 ENTRY( "ListStores" , CTestCntDataStoreExtn::ListStoresL ), |
|
70 ENTRY( "MachineID" , CTestCntDataStoreExtn::MachineIdL ), |
|
71 }; |
|
72 |
|
73 const TInt count = sizeof( KFunctions ) / |
|
74 sizeof( TStifFunctionInfo ); |
|
75 |
|
76 return RunInternalL( KFunctions, count, aItem ); |
|
77 |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CTestCntDataStoreExtn::ListContactsL |
|
82 // Method to List contacts |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 TInt CTestCntDataStoreExtn::ListContactsL( CStifItemParser& aItem ) |
|
86 { |
|
87 iLog->Log( _L("ListContactsL Begin") ); |
|
88 |
|
89 if( iEntryArray ) |
|
90 { |
|
91 iEntryArray->Reset(); |
|
92 TRAPD( err, iCntDataStoreExtension->ListContactsL( iEntryArray ) ); |
|
93 if( err ) |
|
94 { |
|
95 return KErrGeneral; |
|
96 } |
|
97 } |
|
98 else |
|
99 { |
|
100 return KErrGeneral; |
|
101 } |
|
102 iLog->Log( _L("ListContactsL End") ); |
|
103 return KErrNone; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CTestCntDataStoreExtn::ExportContactsL |
|
108 // Method to export contacts |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TInt CTestCntDataStoreExtn::ExportContactsL( CStifItemParser& aItem ) |
|
112 { |
|
113 iLog->Log( _L("ExportContactsL Begin") ); |
|
114 |
|
115 TInt ret = KErrNone; |
|
116 if( iEntryArray ) |
|
117 { |
|
118 if( iEntryArray->Count() > 0 ) |
|
119 { |
|
120 for( TInt count = 0; count < iEntryArray->Count(); count++ ) |
|
121 { |
|
122 CBufBase* tempData = CBufFlat::NewL( 1024 ); |
|
123 TRAPD( err, ret = iCntDataStoreExtension->ExportContactsL( iEntryArray->At(count), *tempData ) ); |
|
124 delete tempData; |
|
125 if ( err || ret ) |
|
126 { |
|
127 return KErrGeneral; |
|
128 } |
|
129 } |
|
130 } |
|
131 else |
|
132 { |
|
133 return KErrGeneral; |
|
134 } |
|
135 } |
|
136 else |
|
137 { |
|
138 return KErrGeneral; |
|
139 } |
|
140 |
|
141 iLog->Log( _L("ExportContactsL End") ); |
|
142 return KErrNone; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CTestCntDataStoreExtn::ImportContactsL |
|
147 // Method to import contacts |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CTestCntDataStoreExtn::ImportContactsL( CStifItemParser& aItem ) |
|
151 { |
|
152 iLog->Log( _L("ImportContactsL Begin") ); |
|
153 |
|
154 HBufC8* cntbuf = HBufC8::NewL(500); |
|
155 CArrayFixFlat<TUid>* entryArray = NULL; |
|
156 |
|
157 *cntbuf = KContact1; |
|
158 |
|
159 TPtr8 ptr = cntbuf->Des(); |
|
160 ptr.Append(KContact2); |
|
161 ptr.Append(KContact3); |
|
162 ptr.Append(KContact4); |
|
163 ptr.Append(KContact5); |
|
164 |
|
165 TRAPD( ret, entryArray = iCntDataStoreExtension->ImportContactsL(*cntbuf) ); |
|
166 delete cntbuf; |
|
167 |
|
168 |
|
169 if( ret || (entryArray == NULL) ) |
|
170 { |
|
171 iLog->Log( _L("ImportContactsL Error") ); |
|
172 return KErrGeneral; |
|
173 } |
|
174 |
|
175 delete entryArray; |
|
176 |
|
177 iLog->Log( _L("ImportContactsL End") ); |
|
178 return KErrNone; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CTestCntDataStoreExtn::ReadContactL |
|
183 // Method to read contact |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TInt CTestCntDataStoreExtn::ReadContactL( CStifItemParser& aItem ) |
|
187 { |
|
188 iLog->Log( _L("ReadContactL Begin") ); |
|
189 if( iEntryArray ) |
|
190 { |
|
191 if( iEntryArray->Count() > 0 ) |
|
192 { |
|
193 TInt ret( KErrNone ); |
|
194 for( TInt count = 0; count < iEntryArray->Count(); count++ ) |
|
195 { |
|
196 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
|
197 TRAPD(err, ret = iCntDataStoreExtension->ReadContactL( iEntryArray->At(count), contactitem )); |
|
198 delete contactitem; |
|
199 if( err || ret ) |
|
200 { |
|
201 return KErrGeneral; |
|
202 } |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 return KErrGeneral; |
|
208 } |
|
209 } |
|
210 else |
|
211 { |
|
212 return KErrGeneral; |
|
213 } |
|
214 |
|
215 iLog->Log( _L("ReadContactL End") ); |
|
216 return KErrNone; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CTestCntDataStoreExtn::DeleteContactL |
|
221 // Method to delete contact |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TInt CTestCntDataStoreExtn::DeleteContactL( CStifItemParser& aItem ) |
|
225 { |
|
226 iLog->Log( _L("DeleteContactL Begin") ); |
|
227 |
|
228 if( iEntryArray ) |
|
229 { |
|
230 if( iEntryArray->Count() > 0 ) |
|
231 { |
|
232 TBool ret; |
|
233 for( TInt count = 0; count < iEntryArray->Count(); count++ ) |
|
234 { |
|
235 TRAPD( err, ret = iCntDataStoreExtension->DeleteContactL( iEntryArray->At(count) ) ); |
|
236 if( err || ( ret == EFalse) ) |
|
237 { |
|
238 return KErrGeneral; |
|
239 } |
|
240 } |
|
241 } |
|
242 else |
|
243 { |
|
244 return KErrGeneral; |
|
245 } |
|
246 } |
|
247 else |
|
248 { |
|
249 return KErrGeneral; |
|
250 } |
|
251 iEntryArray->Reset(); |
|
252 iLog->Log( _L("DeleteContactL End") ); |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CTestCntDataStoreExtn::DeleteContacts |
|
258 // Method to delete contacts |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CTestCntDataStoreExtn::DeleteContactsL( CStifItemParser& aItem ) |
|
262 { |
|
263 iLog->Log( _L("DeleteContactsL Begin") ); |
|
264 |
|
265 if( iEntryArray ) |
|
266 { |
|
267 if( iEntryArray->Count() > 0 ) |
|
268 { |
|
269 TBool ret; |
|
270 TRAPD( err, ret = iCntDataStoreExtension->DeleteContactsL( iEntryArray ) ); |
|
271 if( err || ( ret == EFalse) ) |
|
272 { |
|
273 return KErrGeneral; |
|
274 } |
|
275 } |
|
276 else |
|
277 { |
|
278 return KErrGeneral; |
|
279 } |
|
280 } |
|
281 else |
|
282 { |
|
283 return KErrGeneral; |
|
284 } |
|
285 iEntryArray->Reset(); |
|
286 iLog->Log( _L("DeleteContactsL End") ); |
|
287 return KErrNone; |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CTestCntDataStoreExtn::DeleteAllContactsL |
|
292 // Method to delete all contacts |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CTestCntDataStoreExtn::DeleteAllContactsL( CStifItemParser& aItem ) |
|
296 { |
|
297 iLog->Log( _L("DeleteAllContacts Begin") ); |
|
298 |
|
299 if( iEntryArray ) |
|
300 { |
|
301 if( iEntryArray->Count() > 0 ) |
|
302 { |
|
303 TBool ret; |
|
304 TRAPD( err, ret = iCntDataStoreExtension->DeleteAllContactsL() ); |
|
305 if( err || ( ret == EFalse) ) |
|
306 { |
|
307 return KErrGeneral; |
|
308 } |
|
309 } |
|
310 else |
|
311 { |
|
312 return KErrGeneral; |
|
313 } |
|
314 } |
|
315 else |
|
316 { |
|
317 return KErrGeneral; |
|
318 } |
|
319 iEntryArray->Reset(); |
|
320 iLog->Log( _L("DeleteAllContactsL End") ); |
|
321 return KErrNone; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CTestCntDataStoreExtn::ListStoresL |
|
326 // Method to list stores |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 TInt CTestCntDataStoreExtn::ListStoresL( CStifItemParser& aItem ) |
|
330 { |
|
331 iLog->Log( _L("ListStoresL Begin") ); |
|
332 |
|
333 CDesCArray* cntStores = new (ELeave) CDesCArrayFlat(1); |
|
334 TRAPD( err, iCntDataStoreExtension->ListStoresL( cntStores ) ); |
|
335 delete cntStores; |
|
336 if(err ) |
|
337 { |
|
338 return KErrGeneral; |
|
339 } |
|
340 |
|
341 iLog->Log( _L("ListStoresL End") ); |
|
342 return KErrNone; |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CTestCntDataStoreExtn::MachineIdL |
|
347 // Method to fetch machine id |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 TInt CTestCntDataStoreExtn::MachineIdL( CStifItemParser& aItem ) |
|
351 { |
|
352 iLog->Log( _L("MachineIdL Begin") ); |
|
353 TRAPD( err, iCntDataStoreExtension->MachineIdL( ) ); |
|
354 if(err) |
|
355 { |
|
356 return KErrGeneral; |
|
357 } |
|
358 iLog->Log( _L("MachineIdL End") ); |
|
359 return KErrNone; |
|
360 } |
|
361 |
|
362 // End of File |
|