summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/testimpexvcard/src/testcontactspbapexportperformance.cpp
blob: 587c74b9c07f76a294b9d9c166e1534af5cf1a93 (plain)
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
/*
* 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 "testcontactspbapexportperformance.h"
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
#include "cntdb_internal.h"
#endif

CTestContactsPBAPExportPerformance::~CTestContactsPBAPExportPerformance()
/**
 * Destructor
 */
	{
	}

CTestContactsPBAPExportPerformance::CTestContactsPBAPExportPerformance()
/**
 * 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(KTestContactsPBAPExportPerformance);
	}

TVerdict CTestContactsPBAPExportPerformance::doTestStepPreambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	INFO_PRINTF1(_L("Start Performance test"));
	
	iScheduler = new (ELeave) CActiveScheduler;
	CActiveScheduler::Install(iScheduler);
	
	SetTestStepResult(EPass);
	return TestStepResult();
	}

TVerdict CTestContactsPBAPExportPerformance::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 */
	{
	TestPerformanceL();
	return TestStepResult();
	}
	
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
TVerdict CTestContactsPBAPExportPerformance::doTestStepPostambleL()
 	{
	CActiveScheduler::Install(NULL);
	delete iScheduler;
	
	INFO_PRINTF1(_L("Completed Performance test "));
	return TestStepResult();
	}

void CTestContactsPBAPExportPerformance::TestPerformanceL()
	{
	// Retreive the file name to be exported
   	RFs fsSession;
	RFileWriteStream writeStream;
	CleanupClosePushL(writeStream);
	
	// connect to file system
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);
	
	TPtrC exportTo;
	GetStringFromConfig(ConfigSection(), KExportTo, exportTo);
		
   	// Makes one or more directories.
   	fsSession.MkDirAll(exportTo);
   	
	// Replaces a single file with another
	User::LeaveIfError(writeStream.Replace(fsSession, exportTo, EFileWrite));
		
	INFO_PRINTF1(_L("Exporting Contact....."));

	// Existing database
   	TPtrC databaseFile(_L("C:contactDb.cdb"));
	
	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;
   	
	// Open existing database
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);
	
	CCntFilter* exportFilter = CCntFilter::NewL();
	CleanupStack::PushL(exportFilter);
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;	
		
	CleanupStack::PushL(idArray);
	
	TPtrC standard;
	GetStringFromConfig(ConfigSection(), KStandard, standard);
		
	if(standard.Compare(KOldApi) == 0)
		{
		// Take the base time taken, using the existing/old API
		ExportWithOldApiL(dBase, idArray, writeStream);
		}
	else if(standard.Compare(KV21) == 0)
		{
		// Take the time taken by the new PBAP export API for 2.1 export
		ExportWithPBAPVersionL(dBase, KV21, idArray, writeStream);
		}
	
	else if(standard.Compare(KV30) == 0)
		{
		// Take the time taken by the new PBAP export API for 3.0 export
		ExportWithPBAPVersionL(dBase, KV30, idArray, writeStream);
		}
		
	INFO_PRINTF1(_L("Exported Contact"));
	
	INFO_PRINTF2(_L("Total number of contacts in database %d "), dBase->CountL());
	
	// Cleanup
    CleanupStack::Pop(idArray);
    CleanupStack::PopAndDestroy(exportFilter);

    CleanupStack::PopAndDestroy(dBase);
    CleanupStack::PopAndDestroy(&fsSession);
    CleanupStack::PopAndDestroy(&writeStream);
	}

/** Exports a vCard with old Api(without PBAP support) to note the time taken by the Api 
@param	aDBase The database to export from
@param	aIdArray The contact item ID array to export from database
@param  aWriteStream The write stream to write to
*/	
void CTestContactsPBAPExportPerformance::ExportWithOldApiL(CContactDatabase* aDBase, CContactIdArray* aIdArray, RFileWriteStream& aWriteStream)
	{
	TTimeIntervalMicroSeconds timeTaken;
	TInt64 baseTime;
	NOW(startTime);
	aDBase->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *aIdArray, aWriteStream, 0);
	NOW(endTime);
	
	aWriteStream.CommitL();
	aWriteStream.Close();
	timeTaken = endTime.MicroSecondsFrom(startTime);
		
	baseTime = timeTaken.Int64();
	
	_LIT(KFormat,"%Li");	 
	TBuf<KBufLength> buf;
	buf.Format(KFormat, baseTime);
	TPtrC ptr(buf);
	INFO_PRINTF2(_L("Base Time taken: %Li"), baseTime);
	WriteStringToConfig(ConfigSection(), KBaseTime, ptr); 
	}

/** Exports a vCard with the specified version(with PBAP support) to note the time taken by the Api 
@param	aDBase The database to export from
@param  aVersion The PBAP version to export 
@param	aIdArray The contact item ID array to export from database
@param  aWriteStream The write stream to write to
*/	
void CTestContactsPBAPExportPerformance::ExportWithPBAPVersionL(CContactDatabase* aDBase, const TDesC& aVersion, CContactIdArray* aIdArray, RFileWriteStream& aWriteStream)
	{
	TTimeIntervalMicroSeconds timeTaken;
	TInt64 finalTime;
	TInt64 baseTime;
	TPtrC baseValue;
	
	TVCardVersion version = EPBAPVCard21;
	
	if(aVersion.Compare(KVersion30) == 0)
		{
		version = EPBAPVCard30;	
		}
	
	TInt64 contactFilter = 0;
	
	NOW(startTime);
	aDBase->ExportSelectedContactsL(TUid::Uid(KUidPBAPVCardConvImpl), *aIdArray, aWriteStream, 0, contactFilter, NULL, version ,1);
	NOW(endTime);
	aWriteStream.CommitL();
	aWriteStream.Close();
	timeTaken = endTime.MicroSecondsFrom(startTime);
	finalTime = timeTaken.Int64();
		
	GetStringFromConfig(KExportvCardPerformanceOld, KBaseTime, baseValue);
	TLex lexBuf(baseValue);
	lexBuf.Val(baseTime);
	
	INFO_PRINTF2(_L("Time taken: %Li"), finalTime);
	
	INFO_PRINTF2(_L("Time diff b/w base and final: %Li"), finalTime-baseTime);
		
	if(finalTime > (baseTime+(KTolerance*baseTime)))
		{
		ERR_PRINTF1(_L("Time taken has exceeded the expected limit"));
		SetTestStepResult(EFail);		
		}
	else
		{
		INFO_PRINTF1(_L("Time taken is lower than expected limit"));
		}
	
	}