phonebookengines/contactsmodel/tsrc/performance/T_PerfInitialSync.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2004-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 /**
       
    17 @SYMPREQ                  PREQ1187
       
    18 @SYMComponent             app-engines_cntmodel
       
    19 @SYMAuthor                Simon Mellor, JamesCl
       
    20 @SYMTestStatus            Implemented
       
    21 @SYMTestType              CT
       
    22 
       
    23 @SYMTestCaseDesc          Tests the performance of an initial sync to an empty contacts database
       
    24 						  by importing a corporate-profile database of 1000 contacts from a vcard
       
    25 						  file. The test mimics the way the SyncML code performs and initial sync.
       
    26 
       
    27 @SYMTestActions           Measures the time taken to import a vcard file of the 1000 contacts, 
       
    28 						  using the following calls on the contacts database:
       
    29 						  -- CContactDatabase::DatabaseBeginL()
       
    30 						  -- CContactDatabase::DatabaseCommitL()
       
    31 						  -- CContactDatabase::ImportContactsL()
       
    32 						  -- CContactDatabase::CompactL()
       
    33 
       
    34 @SYMTestExpectedResults   Test case will run without leaving and will output timing information.
       
    35 
       
    36 */
       
    37 
       
    38 #include "T_PerfInitialSync.h"
       
    39 #include "../T_UTILS.H"
       
    40 #include <cntvcard.h>
       
    41 #include <cntitem.h>
       
    42 #include <f32file.h>
       
    43 #include <e32svr.h>
       
    44 #include <coreappstest/testserver.h>
       
    45 
       
    46 _LIT(KDbPathName,"c:\\private\\10003A73\\Contacts.cdb");
       
    47 _LIT(KDatabaseName, "c:Contacts.cdb");
       
    48 _LIT(KOutputFormat,"Initial Sync of %d contacts took: %d s %03d \n");
       
    49 
       
    50 // After how many imports a CompactL() be called 
       
    51 const TInt KCompactResolution = 32; // matches the SyncML code
       
    52 
       
    53 CAddBench::CAddBench()
       
    54 	{
       
    55 	} 
       
    56 
       
    57 CAddBench::~CAddBench()
       
    58 	{
       
    59 	delete iDb;
       
    60 	iFs.Close();
       
    61 	}  
       
    62 
       
    63 CAddBench* CAddBench::NewLC(RTest& aTest)
       
    64 	{
       
    65 	CAddBench* self = new (ELeave) CAddBench();
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL(aTest);
       
    68 	return(self);
       
    69 	}  
       
    70 
       
    71 void CAddBench::ConstructL(RTest& aTest)
       
    72 	{
       
    73 	iTest = &aTest;
       
    74 	User::LeaveIfError(iFs.Connect());
       
    75 
       
    76 	_LIT(KInitialSyncTestTitle, "\nBeginning Initial Sync testing...\n");
       
    77 	iTest->Printf(KInitialSyncTestTitle);
       
    78 	
       
    79 	RPIMTestServer serv;
       
    80 	CleanupClosePushL(serv);
       
    81     User::LeaveIfError(serv.Connect());
       
    82     TRAPD (KErr, serv.DeleteFileL(KDbPathName));
       
    83     
       
    84 	if (!( ((KErr == KErrNotFound) || (KErr == KErrNone)) || (KErr == KErrPathNotFound)))
       
    85 		{
       
    86 		User::Leave(KErr);
       
    87 		}
       
    88 	CleanupStack::PopAndDestroy(&serv);	
       
    89 		
       
    90 	CreateEmptyDBL();
       
    91 	} 
       
    92 	
       
    93 /**
       
    94 	This routine mimics calls made by CSmlContactsDba::ImportContactL v2 (called 
       
    95 	from CSmlContactsDba::AddItemL).  
       
    96 	The routine simluates single VCards being added one at a time.
       
    97 */
       
    98 void CAddBench::ImportFileL(const TDesC& aFilename, TInt aNumEntries)
       
    99 	{
       
   100 	iNumContacts = aNumEntries;
       
   101 	RFileReadStream aReadStream;
       
   102 	CleanupClosePushL(aReadStream);
       
   103 	
       
   104 	User::LeaveIfError(aReadStream.Open(iFs,aFilename,EFileRead));
       
   105 
       
   106 	iDb->DatabaseBeginL(EFalse);
       
   107 
       
   108 	for (TInt counter = 0; counter < aNumEntries; ++counter)
       
   109 		{		
       
   110 		TBool importOK = ETrue;		
       
   111 				
       
   112 		// import one contact from the file
       
   113 		CArrayPtr<CContactItem>* entryArray = iDb->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),
       
   114 																	aReadStream,
       
   115 																	importOK,
       
   116 															    	(CContactVCardConverter::EImportSingleContact | 
       
   117 															    		CContactVCardConverter::EConnectWhitespace | 
       
   118 															    		CContactVCardConverter::EIgnoreUid));
       
   119 
       
   120 		CleanupStack::PushL(TCleanupItem(CleanupPtrArray, entryArray));
       
   121 
       
   122 		if (!importOK)
       
   123 			{			
       
   124  				User::Leave(KErrNotFound);
       
   125 			}
       
   126 			
       
   127 									
       
   128 		if ((counter > 0) && ((counter % KCompactResolution) == 0) )
       
   129 			{	
       
   130 			iDb->DatabaseCommitL(EFalse);
       
   131 			iDb->CompactL();
       
   132 			iDb->DatabaseBeginL(EFalse);
       
   133 			}
       
   134 		CContactItem* contact = entryArray->At(0);
       
   135 		iTime = contact->LastModified();					
       
   136 		CleanupStack::PopAndDestroy(entryArray);			
       
   137 		}
       
   138 
       
   139 	iDb->DatabaseCommitL(EFalse);
       
   140 
       
   141 	CleanupStack::PopAndDestroy(&aReadStream);	
       
   142 	aReadStream.Close();
       
   143 	}
       
   144 	
       
   145 /**
       
   146 	Static convenience cleanup method copied from CSmlContactsDba  
       
   147 */
       
   148 void CAddBench::CleanupPtrArray(TAny* aCArrayPtr)
       
   149 	{ 
       
   150 	CArrayPtr<CContactItem>* array = reinterpret_cast<CArrayPtr<CContactItem>*>(aCArrayPtr);
       
   151 	array->ResetAndDestroy();
       
   152 	delete array;
       
   153 	}
       
   154 
       
   155 /** 
       
   156 	Replace the current db with an empty one - ie start from scratch
       
   157 */
       
   158 void CAddBench::CreateEmptyDBL()
       
   159 	{
       
   160 	delete iDb;
       
   161 	iDb = NULL;
       
   162 	iDb = CContactDatabase::ReplaceL(KDatabaseName);
       
   163 	}
       
   164 
       
   165 void CAddBench::DoSyncL(TInt aEntryCount, const TDesC& aVCardLoc )
       
   166 	{
       
   167 	TFileName path;
       
   168 	path.Append(aVCardLoc);	
       
   169 	
       
   170 	TCntPerfTimer timer;
       
   171 	timer.StartTimer();	
       
   172 	ImportFileL(aVCardLoc, aEntryCount);
       
   173 	timer.StopTimer();	
       
   174 
       
   175 	TInt result = timer.Result();	
       
   176 	TBuf<64> formattable;
       
   177 	formattable.Format(KOutputFormat, iNumContacts, result / 1000000, (result / 1000) % 1000);
       
   178 	iTest->Printf(formattable);
       
   179 	}