phonebookengines/contactsmodel/tsrc/performance/T_PerfSyncDelete.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 // This is a performance test harness measuring a sync deletion of 
       
    15 // a proportion of Contacts in the default database.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <cntvcard.h>
       
    20 #include <cntitem.h>
       
    21 #include <f32file.h>
       
    22 #include <s32mem.h>
       
    23 #include "T_PerfSyncDelete.h"
       
    24 #include "../T_UTILS.H"
       
    25 
       
    26 // Constants
       
    27 
       
    28 _LIT(KDbName,"C:Contacts.cdb");
       
    29 
       
    30 const TPtrC KDbPath((KDbName)); 
       
    31 const TInt KCompactResolution = 16;
       
    32 _LIT(KOutputFormat,"Sync Delete took: %d s %03d deleting %d of %d Contacts\n");
       
    33 
       
    34 CSyncDelete::CSyncDelete(TInt64 aSeed)
       
    35 	{
       
    36 	iRandSeed = aSeed;
       
    37 	} 
       
    38 
       
    39 CSyncDelete::~CSyncDelete()
       
    40 	{
       
    41 	delete iDb;
       
    42 	iFs.Close();
       
    43 	} 
       
    44 	
       
    45 CSyncDelete* CSyncDelete::NewLC(RTest& aTest, TInt64 ranSeed)
       
    46 	{;
       
    47 	CSyncDelete* self = new (ELeave) CSyncDelete(ranSeed);
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aTest);
       
    50 	return(self);
       
    51 	}  
       
    52 
       
    53 void CSyncDelete::ConstructL(RTest& aTest)
       
    54 	{
       
    55 	iTest = &aTest;
       
    56 	iDb = CContactDatabase::OpenL(KDbPath);
       
    57 	User::LeaveIfError(iFs.Connect());
       
    58 	CCntTest::ProfileReset(0, 59);
       
    59 	} 
       
    60 
       
    61 TBool CSyncDelete::ExistsInArray(const CArrayFix<TInt>& aArr, TInt aSize, TInt aNum)
       
    62 /**
       
    63     Returns whether aNum exists in aArr from 0 to aSize in the aArr array
       
    64 */
       
    65 	{
       
    66 	for(TInt i = 0; i < aSize; ++i)
       
    67 		{
       
    68 		if (aNum == aArr[i])
       
    69 			{
       
    70 			return ETrue;
       
    71 			}
       
    72 		}
       
    73 	return EFalse;
       
    74 	}
       
    75 	
       
    76 void CSyncDelete::CreateRandomIdArray(CArrayFix<TInt>& aUids, TInt aNumIds, TInt aNumEntriesInDb)
       
    77 /*
       
    78 	Creates a random array of numbers corresponding to the uids in the 
       
    79 	Contacts model.  No UID is repeated  
       
    80 */
       
    81 	{
       
    82 	for(TInt i = 0; i < aNumIds; ++i)
       
    83 		{
       
    84 		TInt uid = Math::Rand(iRandSeed)%(aNumEntriesInDb-1)+1;
       
    85 		while(ExistsInArray(aUids,i,uid))
       
    86 			{
       
    87 			uid = Math::Rand(iRandSeed)%(aNumEntriesInDb-1)+1;
       
    88 			}
       
    89 		aUids[i] = uid;		
       
    90 		}
       
    91 	}
       
    92 	
       
    93 void CSyncDelete::CleanupPtrArray(TAny* aCArrayPtr)
       
    94 /**
       
    95 	Static convenience cleanup method copied from CSmlContactsDba  
       
    96 */
       
    97 	{ 
       
    98 	CArrayPtr<CContactItem>* array = reinterpret_cast<CArrayPtr<CContactItem>*>(aCArrayPtr);
       
    99 	array->ResetAndDestroy();
       
   100 	delete array;
       
   101 	}	
       
   102 
       
   103 void CSyncDelete::DoSyncL(TInt aEntryCount, TInt aNumEntriesInDb)
       
   104 /** This routine deleted aEntryCount of aNumEntriesInDb where the Ids to delete are 
       
   105     generated at random.  This harness does not tests Sync Update
       
   106 */	
       
   107 	{
       
   108 	// create an array of random, non-repeating contact ids
       
   109 	CArrayFixFlat<TInt>* uids = new(ELeave) CArrayFixFlat<TInt>(aEntryCount);
       
   110 	CleanupStack::PushL(uids);
       
   111 	uids->ResizeL(aEntryCount);	
       
   112 	CreateRandomIdArray(*uids,aEntryCount,aNumEntriesInDb);
       
   113 	
       
   114 	// Most SML servers perform all the delete operations followed by all the
       
   115 	// update operations (or vice verca) rather than intermingling the 2
       
   116 	// operations. We are only interested in the deletion aspect at this state.
       
   117 	//
       
   118 	CCntTest::ProfileStart(0);
       
   119 	for (TInt i = 0; i < aEntryCount; ++i)
       
   120 		{		;
       
   121 		const TContactItemId KEntryId = static_cast<TContactItemId>((*uids)[i]); 
       
   122 		iDb->DeleteContactL(KEntryId);
       
   123 		
       
   124 		if ((i > 0) && ((i % KCompactResolution) == 0)) 
       
   125 			{
       
   126 			iDb->CompactL();
       
   127 			}
       
   128 		}
       
   129 	CleanupStack::PopAndDestroy(uids);	
       
   130 	CCntTest::ProfileEnd(0);
       
   131 	
       
   132 	TCntProfile p[1];
       
   133 	TBuf<64> formattable;
       
   134 	TInt sec;
       
   135 	TInt msec; 
       
   136 	
       
   137 	CCntTest::ProfileResult(&p[0],0,1);	
       
   138 	sec = p[0].iTime/1000000;
       
   139 	msec = (p[0].iTime/1000)%1000;
       
   140 	formattable.Format(KOutputFormat, sec, msec, aEntryCount, aNumEntriesInDb);
       
   141 	iTest->Printf(formattable);
       
   142 	}