File: testcontactspbapexport.cpp

package info (click to toggle)
qtmobility 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 169,300 kB
  • ctags: 92,483
  • sloc: cpp: 759,105; ansic: 16,292; xml: 5,054; sh: 920; perl: 369; makefile: 167
file content (396 lines) | stat: -rw-r--r-- 9,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/*
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include "testcontactspbapexport.h"

CTestContactsPBAPExport::~CTestContactsPBAPExport()
/**
 * Destructor
 */
	{
	delete iExportObj;
	}

CTestContactsPBAPExport::CTestContactsPBAPExport()
/**
 * Constructor
 */
	{
	// **MUST** call SetTestStepName in the constructor as the controlling
	// framework uses the test step name immediately following construction to set
	// up the step's unique logging ID.
	SetTestStepName(KTestContactsPBAPExport);
	}

TVerdict CTestContactsPBAPExport::doTestStepPreambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	INFO_PRINTF1(_L("Start export of vCards"));

	iScheduler = new (ELeave) CActiveScheduler;
	CActiveScheduler::Install(iScheduler);

	SetTestStepResult(EPass);
	return TestStepResult();
	}

TVerdict CTestContactsPBAPExport::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 */
	{
	ExportContactsL();
	return TestStepResult();
	}

TVerdict CTestContactsPBAPExport::doTestStepPostambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	CActiveScheduler::Install(NULL);
	delete iScheduler;

	INFO_PRINTF1(_L("Completed export of vCards "));
	return TestStepResult();
	}

void CTestContactsPBAPExport::ExportContactsL()
	{
	TInt err = KErrNone;
	// Retrieve the file name to which contact item is to be exported
   	RFs fsSession;
	RFileWriteStream writeStream;

	// connect to file system
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);

	GetInputFromIni();

   	// Makes one or more directories.
   	fsSession.MkDirAll(iExportTo);

	// Replaces a single file with another
	User::LeaveIfError(writeStream.Replace(fsSession, iExportTo, EFileWrite));

	INFO_PRINTF1(_L("Exporting Contact....."));

	// Existing database
   	TPtrC databaseFile(_L("C:contactDb.cdb"));

	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;

	// Open the existing database
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);

	// Create Utility class object, to export the contact from database
	CTestStep* self = static_cast<CTestStep*>(this);
	iExportObj = new(ELeave) CContactsPBAPExportUtilityClass(self);

	SetFilterL();

	CCntFilter* exportFilter = CCntFilter::NewL();
	CleanupStack::PushL(exportFilter);

	// Get all the contacts from the database to export
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;
	CleanupStack::PushL(idArray);

	if(iDamageDb)
		{
		#ifdef _DEBUG
		#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
		TRAPD(err1,dBase->DamageDatabaseL(0x666));
		if(err1 == KErrNone)
			{
			TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			INFO_PRINTF2(_L("Err:%d"),err);
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			if(dBase->IsDamaged())
				{
				dBase->RecoverL();
				}
			}
		else
			{
			INFO_PRINTF2(_L("Could not damage database Err:"),err1);
			}
		#else
			SetTestStepResult(EPass);
		#endif
		#endif
		}
    else
	    {
	    if(iInvalidFileSystem)
		    {
		    #ifdef _DEBUG
		    fsSession.SetErrorCondition(KErrNotReady);
		    TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			fsSession.SetErrorCondition(KErrNone);
			#endif
			}
	    else
			{
			if(!iSetOOM)
				{
				if(idArray->Count() > 0)
					{
					for(TInt i=0; i<idArray->Count() ; i++)
						{
						TInt dCount = dBase->CountL();
						if(i>=dCount)
							{
							break;
							}

						// temporary array used to export one contact at a time
						CContactIdArray* tempIdArray = CContactIdArray::NewL();
						CleanupStack::PushL(tempIdArray);
						tempIdArray->AddL((*idArray)[i]);
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, tempIdArray, writeStream, iContactFilter));

						if(err != KErrNone )
							{
							if(err != KErrNotFound)
								{
								SetTestStepError(err);
								}
							}

						CleanupStack::PopAndDestroy(tempIdArray);
						}
					}
				else
					{
					if(idArray->Count()==0)
						{
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
						if(err != KErrNone)
							{
							SetTestStepError(err);
							}
						}
					}

				}
			else
				{
				TInt tryCount = 1;
				for ( ;; )
					{
					__UHEAP_SETFAIL(RHeap::EDeterministic, tryCount);
					TRAP(err, iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));

					if ( err == KErrNone )
						{
						__UHEAP_RESET;
						INFO_PRINTF1(_L("OOM testing of CContactDatabase::ExportSelectedContactsL Api is done"));
						break;
						}
					if ( err != KErrNoMemory )
						{
						INFO_PRINTF2(_L("The unexpected error code is:%d"),err);
						SetTestStepResult(EFail);
						break;
						}
					__UHEAP_SETFAIL(RHeap::ENone, 0);
					tryCount++;
					}
				}
			}
	    }

	CleanupStack::Pop(idArray);
	CleanupStack::PopAndDestroy(exportFilter);

	INFO_PRINTF1(_L("Exported Contact"));
	writeStream.CommitL();
	writeStream.Close();

	INFO_PRINTF2(_L("Total number of contacts in database %d "), dBase->CountL());

	// Cleanup
	CleanupStack::PopAndDestroy(dBase);
    CleanupStack::PopAndDestroy(&fsSession);
	}

// Gets the input from ini file
void CTestContactsPBAPExport::GetInputFromIni()
	{
	iSetOOM = EFalse;
	GetStringFromConfig(ConfigSection(), KStandard, iStandard);
	GetStringFromConfig(ConfigSection(), KExportTo, iExportTo);
	GetStringFromConfig(ConfigSection(), KFilter, iFilter);
	// For OOM testing
	GetBoolFromConfig(ConfigSection(), KSetOOM, iSetOOM);
	GetBoolFromConfig(ConfigSection(), KDamageDb, iDamageDb);
	GetBoolFromConfig(ConfigSection(), KInvalidFileSystem, iInvalidFileSystem);
	GetBoolFromConfig(ConfigSection(), KFilterBitsFutureUse, iFilterBitsFutureUse);
	GetBoolFromConfig(ConfigSection(), KSetFilterOnlyFutureUse, iSetFilterOnlyFutureUse);
	}

// Sets the filter with the properties specified in ini file
void CTestContactsPBAPExport::SetFilterL()
	{
	if(iFilterBitsFutureUse)
		{
		iContactFilter = KFilterBitsForFutureUse;
		}
	else
		{
		if(iSetFilterOnlyFutureUse)
			{
			iContactFilter = KFilterBitsOnlyForFutureUse;
			}
		else
			{
			// Set the filter with the values given in ini file
			RArray<TPtrC>	filterList;
			CleanupClosePushL(filterList);
			iExportObj->TokenizeStringL(iFilter, filterList);

			iContactFilter = 0;
			const TInt count = filterList.Count();

			for(TInt i = 0;i < count;i++)
				{
				if(filterList[i].Compare(KVersion) == 0)
					{
					iContactFilter |= ETokenIdVersion;
					}
				if(filterList[i].Compare(KNameVal) == 0)
					{
					iContactFilter |= ETokenIdN;
					}
				if(filterList[i].Compare(KFirstName) == 0)
					{
					iContactFilter |= ETokenIdFn;
					}
				if(filterList[i].Compare(KTel) == 0)
					{
					iContactFilter |= ETokenIdTel;
					}
				if(filterList[i].Compare(KPhoto) == 0)
					{
					iContactFilter |= ETokenIdPhoto;
					}
				if(filterList[i].Compare(KBday) == 0)
					{
					iContactFilter |= ETokenIdBday;
					}
				if(filterList[i].Compare(KAdr) == 0)
					{
					iContactFilter |= ETokenIdAdr;
					}
				if(filterList[i].Compare(KLabel) == 0)
					{
					iContactFilter |= ETokenIdLabel;
					}
				if(filterList[i].Compare(KEmail) == 0)
					{
					iContactFilter |= ETokenIdEmail;
					}
				if(filterList[i].Compare(KMailer) == 0)
					{
					iContactFilter |= ETokenIdMailer;
					}
				if(filterList[i].Compare(KTitle) == 0)
					{
					iContactFilter |= ETokenIdTitle;
					}
				if(filterList[i].Compare(KRole) == 0)
					{
					iContactFilter |= ETokenIdRole;
					}
				if(filterList[i].Compare(KLogo) == 0)
					{
					iContactFilter |= ETokenIdLogo;
					}
				if(filterList[i].Compare(KOrg) == 0)
					{
					iContactFilter |= ETokenIdOrg;
					}
				if(filterList[i].Compare(KNote) == 0)
					{
					iContactFilter |= ETokenIdNote;
					}
				if(filterList[i].Compare(KRev) == 0)
					{
					iContactFilter |= ETokenIdRev;
					}
				if(filterList[i].Compare(KSound) == 0)
					{
					iContactFilter |= ETokenIdSound;
					}
				if(filterList[i].Compare(KUrl) == 0)
					{
					iContactFilter |= ETokenIdUrl;
					}
				if(filterList[i].Compare(KUid) == 0)
					{
					iContactFilter |= ETokenIdUid;
					}
				if(filterList[i].Compare(KKey) == 0)
					{
					iContactFilter |= ETokenIdKey;
					}
				if(filterList[i].Compare(KTZ) == 0)
					{
					iContactFilter |= ETokenIdTz;
					}
				if(filterList[i].Compare(KGeo) == 0)
					{
					iContactFilter |= ETokenIdGeo;
					}
				if(filterList[i].Compare(KAgent) == 0)
					{
					iContactFilter |= ETokenIdAgent;
					}
				}
			CleanupStack::Pop();
			filterList.Close();
			}
		}
	}