phonebookengines/contactsmodel/tsrc/Integration/PerfFuncSuite/src/RandomBlobStep.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-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  @file 
       
    18  @publishedAll
       
    19  @released
       
    20 */
       
    21 #include <cntfldst.h>
       
    22 #include "RandomBlobStep.h"
       
    23 #include "PerformanceFunctionalityDefs.h"
       
    24 
       
    25 const TInt KKByte = 1024;
       
    26 
       
    27 _LIT(KRun1,"BlobTests");
       
    28 _LIT(KRun2,"MaxBlob");
       
    29 
       
    30 _LIT(KTest1, "Blobs tests");
       
    31 _LIT(KTest2, "Max Blob size test");
       
    32 
       
    33 #define KNumberOfContacts 10
       
    34 
       
    35 CRandomBlobStep::CRandomBlobStep() : CPerformanceFunctionalityBase( KNumberOfContacts )
       
    36 	{
       
    37 	SetTestStepName(KRandomBlobStep);
       
    38 	TTime time;
       
    39 	time.UniversalTime();
       
    40 	iSeed = time.Int64();
       
    41 	}
       
    42 
       
    43 TVerdict CRandomBlobStep::doTestStepL()
       
    44 	{
       
    45 	__UHEAP_MARK;
       
    46 	InitializeL();
       
    47 	_LIT(KDoStepPrint,"CRandomBlobStep::doTestStepL()");
       
    48 	INFO_PRINTF1(KDoStepPrint);  //Block start 
       
    49 	
       
    50 	const TDesC &run = ConfigSection();
       
    51 	
       
    52 	if( run == KRun1 )
       
    53 		{
       
    54 		INFO_PRINTF1(KTest1);
       
    55 		BlobTestL();
       
    56 		}
       
    57 	else if( run == KRun2 )
       
    58 		{
       
    59 		INFO_PRINTF1(KTest2);
       
    60 		MaxBlobTestL();
       
    61 		}
       
    62 	else
       
    63 		{
       
    64 		MissingTestPanic();
       
    65 		}
       
    66 	Cleanup();
       
    67 	__UHEAP_MARKEND;
       
    68 
       
    69 	return TestStepResult();
       
    70 	}
       
    71 
       
    72 /**
       
    73 creates a blob with the specified size and fills it with random values
       
    74 */
       
    75 HBufC8 *CRandomBlobStep::RandomBlobLC(const TInt aSize)
       
    76 	{
       
    77 	
       
    78 	HBufC8 *buf = HBufC8::NewLC( aSize );
       
    79 	TPtr8 tptr8 = buf->Des();
       
    80 		
       
    81 	for( TInt i = 0; i < aSize; ++i)
       
    82 		{
       
    83 		tptr8.Append( TChar( static_cast<TUint>( Math::Rand(iSeed) % 256 ) ) );
       
    84 		}
       
    85 
       
    86 	return buf;
       
    87 	}
       
    88 
       
    89 /**
       
    90 sets the value of all blobs in a contact (aCid) with aBuf
       
    91 */
       
    92 void CRandomBlobStep::SetAllBlobsL(const TContactItemId aCid, const HBufC8 &aBuf)
       
    93 	{
       
    94 	OpenL( aCid );
       
    95 	TInt length = iFields->Count();
       
    96 	for( TInt i = 0; i < length; ++i )
       
    97 		{
       
    98 		if( (*iFields)[i].StorageType() == KStorageTypeStore )
       
    99 			{
       
   100 			(*iFields)[i].StoreStorage()->SetThingL(aBuf);
       
   101 			}
       
   102 		}
       
   103 	CommitL( EFalse );
       
   104 	}
       
   105 
       
   106 /**
       
   107 checks that all blobs in aCid match aBuf
       
   108 */
       
   109 TBool CRandomBlobStep::CheckAllBlobsL(const TContactItemId aCid, const HBufC8 &aBuf)
       
   110 	{
       
   111 	TBool SingleTestResult 	= EFalse;
       
   112 	TBool OverallTestResult = EFalse;
       
   113 	ReadL( aCid );
       
   114 	TInt length = iFields->Count();
       
   115 	for( TInt i = 0; i < length; ++i )
       
   116 		{
       
   117 		if( (*iFields)[i].StorageType() == KStorageTypeStore )
       
   118 			{
       
   119 			TDesC8 *thething = (*iFields)[i].StoreStorage()->Thing();
       
   120 			TESTPRINTI( SingleTestResult = ( thething != NULL ), i );
       
   121 			OverallTestResult = SingleTestResult;
       
   122 			TESTPRINTI( SingleTestResult = ( (*iFields)[i].StoreStorage()->Thing()->Compare(aBuf) == 0 ), i );
       
   123 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   124 			}
       
   125 		}
       
   126 	CloseL( EFalse );
       
   127 	return OverallTestResult;
       
   128 	}
       
   129 
       
   130 void CRandomBlobStep::BlobTestL()
       
   131 	{
       
   132 	TAutoClose< RPointerArray< HBufC8 > > blobs;
       
   133 	
       
   134 	//test for 0 bytes, empty descriptor fails
       
   135 	blobs.iObj.AppendL( RandomBlobLC( 1 ) );//1 byte
       
   136 	blobs.iObj.AppendL( RandomBlobLC( KKByte ) );//1 kbyte
       
   137 	blobs.iObj.AppendL( RandomBlobLC( 10 * KKByte ) ); //10 kbytes
       
   138 	blobs.iObj.AppendL( RandomBlobLC( 50 * KKByte ) ); //50 kbytes
       
   139 	blobs.iObj.AppendL( RandomBlobLC( 100 * KKByte ) ); //100 kbytes
       
   140 	
       
   141 	TContactItemId cid = 0;
       
   142 	TInt length = blobs.iObj.Count();
       
   143 	TInt i = 0;
       
   144 	
       
   145 	iIterate->Reset();
       
   146 	for(; i < length; ++i )
       
   147 		{
       
   148 		cid = iIterate->NextL();
       
   149 		SetAllBlobsL( cid, *(blobs.iObj[i]) );
       
   150 		}
       
   151 	
       
   152 	iIterate->Reset();
       
   153 	for( i = 0; i < length; ++i )
       
   154 		{
       
   155 		cid = iIterate->NextL();
       
   156 		TESTPRINTI( CheckAllBlobsL( cid, *(blobs.iObj[i]) ), i);
       
   157 		}
       
   158 		
       
   159 	for( i = length - 1; i >= 0; --i )
       
   160 		{
       
   161 		CleanupStack::PopAndDestroy( blobs.iObj[i] );
       
   162 		}
       
   163 	}
       
   164 
       
   165 //increments the size of blobs created by 1 kb until a failiure occurs
       
   166 void CRandomBlobStep::MaxBlobTestL()
       
   167 	{
       
   168 	TBool SetSuccess = EFalse;
       
   169 	HBufC8 *theblob = NULL;
       
   170 	
       
   171 	TContactItemId cid = iIterate->NextL();
       
   172 	TInt i = 0;
       
   173 	TInt err = KErrNone;
       
   174 
       
   175 	for( i = 1; (i < KKByte); ++i )
       
   176 		{
       
   177 		theblob = RandomBlobLC( i * KKByte );
       
   178 		TRAP( err, SetAllBlobsL( cid, *theblob ) );
       
   179 		if( (KErrNone != err) &&  (KErrNoMemory != err) )
       
   180 			{
       
   181 			User::Leave( err );
       
   182 			}
       
   183 		else if( KErrNoMemory == err )
       
   184 			{
       
   185 			SetSuccess = EFalse;
       
   186 			}
       
   187 		else
       
   188 			{
       
   189 			TESTPRINTI( SetSuccess = CheckAllBlobsL( cid, *theblob ), i );
       
   190 			}
       
   191 			
       
   192 		CleanupStack::PopAndDestroy( theblob );
       
   193 		theblob = NULL;
       
   194 		
       
   195 		if( !SetSuccess )
       
   196 			{
       
   197 			break;
       
   198 			}
       
   199 		}
       
   200 	
       
   201 	_LIT(KMaxSizePrint,"Max size is %d KiloBytes");
       
   202 	INFO_PRINTF2(KMaxSizePrint, SetSuccess ? i : --i);
       
   203 	}
       
   204 
       
   205