phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/ViewDefCustomFieldsTest.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
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 
       
    22 #include <e32panic.h>
       
    23 #include <test/testexecutelog.h>
       
    24 #include <cntfldst.h>
       
    25 #include "ClientServer.h"
       
    26 #include "ViewDefCustomFieldsTest.h"
       
    27 
       
    28 _LIT(KRun1,"AllLabelUid");
       
    29 _LIT(KRun2,"AllNewFields");
       
    30 _LIT(KRun3,"AllOnlyNew");
       
    31 _LIT(KRun4,"ExistingLabelUid");
       
    32 _LIT(KRun5,"ExistingNewFields");
       
    33 _LIT(KRun6,"ExistingOnlyNew");
       
    34 
       
    35 _LIT(KTest1,"Testing KUidContactFieldMatchAll in viewdef with custom labels/uids...");
       
    36 _LIT(KTest2,"Testing KUidContactFieldMatchAll in viewdef with new fields...");
       
    37 _LIT(KTest3,"Testing KUidContactFieldMatchAll in viewdef with only new fields...");
       
    38 _LIT(KTest4,"Testing Multiple Exisiting & Custom Uids in viewdef with custom labels/uids...");
       
    39 _LIT(KTest5,"Testing Multiple Exisiting & Custom Uids in viewdef with new fields...");
       
    40 _LIT(KTest6,"Testing Multiple Exisiting & Custom Uids in viewdef with only new fields...");
       
    41 
       
    42 const static TInt KCustomUidCount = 100;
       
    43 
       
    44 //Number of contacts
       
    45 CViewDefCustomFieldsTest::CViewDefCustomFieldsTest():CViewDefBase(1)
       
    46 /**
       
    47  * Constructor
       
    48  */
       
    49 	{
       
    50 	// Call base class method to set up the human readable name for logging
       
    51 	SetTestStepName(SharedConstants::KViewDefCustomFieldsTest);
       
    52 	}
       
    53 
       
    54 TVerdict CViewDefCustomFieldsTest::doTestStepL()
       
    55 /**
       
    56  * @return - TVerdict code
       
    57  * Override of base class pure virtual
       
    58  */
       
    59 	{
       
    60 	
       
    61 	__UHEAP_MARK;
       
    62 		
       
    63 	InitializeL();
       
    64 	iIterate->Reset();
       
    65 	
       
    66 	const TDesC &run = ConfigSection();
       
    67 	
       
    68 	if( run == KRun1 )
       
    69 		{
       
    70 		INFO_PRINTF1(KTest1);
       
    71 		MatchAllTestsL( iIterate->NextL() );
       
    72 		}
       
    73 	else if( run == KRun2 )
       
    74 		{
       
    75 		INFO_PRINTF1(KTest2);
       
    76 		NewFieldsMATestsL( iIterate->NextL(), EFalse );
       
    77 		}
       
    78 	else if( run == KRun3 )
       
    79 		{
       
    80 		INFO_PRINTF1(KTest3);
       
    81 		NewFieldsMATestsL( iIterate->NextL(), ETrue );
       
    82 		}
       
    83 	else if( run == KRun4 )
       
    84 		{
       
    85 		INFO_PRINTF1(KTest4);
       
    86 		ManyUidsTestsL( iIterate->NextL() );
       
    87 		}
       
    88 	else if( run == KRun5 )
       
    89 		{
       
    90 		INFO_PRINTF1(KTest5);
       
    91 		NewFieldsMUITestsL( iIterate->NextL(), EFalse );
       
    92 		}
       
    93 	else if( run == KRun6 )
       
    94 		{
       
    95 		INFO_PRINTF1(KTest6);
       
    96 		NewFieldsMUITestsL( iIterate->NextL(), ETrue );
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		MissngTestPanic();
       
   101 		}
       
   102 	
       
   103 	Cleanup();
       
   104 	
       
   105 	__UHEAP_MARKEND;
       
   106 	
       
   107 	return TestStepResult();
       
   108 	}
       
   109 
       
   110 void CViewDefCustomFieldsTest::MatchAllTestsL(const TContactItemId &aCid)
       
   111 	{
       
   112 	TInt fields = 0;
       
   113 	
       
   114 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   115 	SetContactFieldsL(*iContactItem);
       
   116 	SetContactLabelsL(*iContactItem);
       
   117 	AddUIDsL(*iFields,TestConstants::KInitialUID);
       
   118 	fields = iFields->Count();	
       
   119 	CommitL();
       
   120 
       
   121 	iViewII->AddL(KUidContactFieldMatchAll);
       
   122 	iViewIM->AddL(KUidContactFieldMatchAll);
       
   123 	iViewMM->AddL(KUidContactFieldMatchAll);
       
   124 	
       
   125 	SINGLECOMPARE( doAllMatchL( aCid, *iViewII, fields, EFalse, EFalse ), 0, 0 );
       
   126 	SINGLECOMPARE( doAllMatchL( aCid, *iViewIM, fields, EFalse, ETrue ), 0, 0 );
       
   127 	SINGLECOMPARE( doAllMatchL( aCid, *iViewMM, fields, ETrue, ETrue ), 0, 0 );
       
   128 	
       
   129 	iViewII->Reset();
       
   130 	iViewIM->Reset();
       
   131 	iViewMM->Reset();
       
   132 	}
       
   133 
       
   134 void CViewDefCustomFieldsTest::NewFieldsMATestsL(const TContactItemId &aCid, const TBool aOnlyNew)
       
   135 	{
       
   136 	TInt fields = 0;
       
   137 	const static TInt newFields = 10;
       
   138 	
       
   139 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   140 	if(aOnlyNew)
       
   141 		{
       
   142 		iFields->Reset();
       
   143 		}
       
   144 	for(TInt i = 0, uids = TestConstants::KAltUID; i < newFields; i++, uids++)
       
   145 		{
       
   146 		AddNewFieldL( *iFields, TestConstants::KShortString, TFieldType::Uid(uids) );
       
   147 		}
       
   148 	SetContactFieldsL(*iContactItem);
       
   149 	fields = iFields->Count();	
       
   150 	CommitL();
       
   151 
       
   152 	iViewII->AddL(KUidContactFieldMatchAll);
       
   153 	iViewIM->AddL(KUidContactFieldMatchAll);
       
   154 	iViewMM->AddL(KUidContactFieldMatchAll);
       
   155 	
       
   156 	SINGLECOMPARE( doAllMatchL( aCid, *iViewII, fields, EFalse, EFalse, aOnlyNew ), 0, 0  );
       
   157 	SINGLECOMPARE( doAllMatchL( aCid, *iViewIM, fields, EFalse, ETrue, aOnlyNew ), 0, 0  );
       
   158 	SINGLECOMPARE( doAllMatchL( aCid, *iViewMM, fields, ETrue, ETrue, aOnlyNew ), 0, 0  );
       
   159 	
       
   160 	iViewII->Reset();
       
   161 	iViewIM->Reset();
       
   162 	iViewMM->Reset();
       
   163 	}
       
   164 
       
   165 
       
   166 TBool CViewDefCustomFieldsTest::doAllMatchL(const TContactItemId &aCid, const CContactItemViewDef &aView,
       
   167 											const TInt aFieldCount, const TBool aZeroN, 
       
   168 											const TBool aZeroH, const TBool aNew )
       
   169 	{
       
   170 	TBool SingleTestResult = EFalse;
       
   171 	TBool OverallTestResult = ETrue;
       
   172 	
       
   173 	TInt countM = 0;
       
   174 	TInt countR = 0;
       
   175 	TInt emptyfsM = 0;
       
   176 	TInt emptyfsR = 0;
       
   177 	TInt hcountM = 0;
       
   178 	TInt hcountR = 0;
       
   179 	
       
   180 	ReadL(aCid,*iViewAll,EFalse);
       
   181 	countR = iFields->Count();
       
   182 	hcountR = CountHiddenFields(*iFields);
       
   183 	emptyfsR = CountEmpty(*iFields);
       
   184 	Close();
       
   185 	
       
   186 	ReadMinimalL(aCid, aView, *iDefView, EFalse);
       
   187 	countM = iFields->Count();
       
   188 	hcountM = CountHiddenFields(*iFields);
       
   189 	emptyfsM = CountEmpty(*iFields);
       
   190 	Close();
       
   191 	
       
   192 	if(aNew)
       
   193 		{
       
   194 		countR -= emptyfsR;
       
   195 		emptyfsR = 0;
       
   196 		hcountR = 0;
       
   197 		}
       
   198 	
       
   199 	SingleTestResult = INTCOMPARE(countR , ==,  aFieldCount, 0, 0 ); 
       
   200 	OverallTestResult = OverallTestResult && SingleTestResult;
       
   201 	
       
   202 	SingleTestResult = INTCOMPARE(emptyfsM , ==,  0, 0, 0 ); 
       
   203 	OverallTestResult = OverallTestResult && SingleTestResult;
       
   204 	
       
   205 	SingleTestResult = INTCOMPARE(emptyfsR , ==,  0, 0, 0 );
       
   206 	
       
   207 	if(aZeroN)
       
   208 		{
       
   209 		SingleTestResult = INTCOMPARE( (countM - hcountM), <=, 0, 0, 0 );
       
   210 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		SingleTestResult = INTCOMPARE( (countM - hcountM) , ==,  (countR - hcountR) , 0, 0 );
       
   215 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   216 		}
       
   217 		
       
   218 	if(aZeroH)
       
   219 		{
       
   220 		SingleTestResult = INTCOMPARE(hcountM , ==,  0, 0, 0 );
       
   221 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   222 		}
       
   223 	else
       
   224 		{
       
   225 		SingleTestResult = INTCOMPARE(hcountR , ==,  hcountM, 0, 0 );
       
   226 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   227 		}
       
   228 		
       
   229 	return OverallTestResult;
       
   230 	
       
   231 	}
       
   232 
       
   233 void CViewDefCustomFieldsTest::ManyUidsTestsL(const TContactItemId &aCid)
       
   234 	{
       
   235 	TInt fields = 0;
       
   236 	
       
   237 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   238 	SetContactFieldsL(*iContactItem);
       
   239 	SetContactLabelsL(*iContactItem);
       
   240 	AddUIDsL(*iFields,TestConstants::KInitialUID);
       
   241 	fields = iFields->Count();	
       
   242 	CommitL();
       
   243 
       
   244 	const TInt length = iExistingUidsArray->Count() - 1;
       
   245 	TInt i(0);
       
   246 	for(; i < length;)
       
   247 		{	
       
   248 		AddMultipleUidsL(*iViewII, i, 1);
       
   249 		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, 0 );
       
   250 		iViewII->Reset();
       
   251 		}
       
   252 		
       
   253 	const TInt flength = KCustomUidCount - 1;
       
   254 	for(i = 0; i < flength;)
       
   255 		{	
       
   256 		AddMultipleCustomUidsL(*iViewII, i, 1);
       
   257 		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, i );
       
   258 		iViewII->Reset();
       
   259 		}
       
   260 	}
       
   261 
       
   262 void CViewDefCustomFieldsTest::NewFieldsMUITestsL(const TContactItemId &aCid, const TBool aOnlyNew)
       
   263 	{
       
   264 	TInt fields = 0;
       
   265 	const static TInt newFields = 10;
       
   266 	
       
   267 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   268 	if(aOnlyNew)
       
   269 		{
       
   270 		iFields->Reset();
       
   271 		}
       
   272 	TInt i(0);
       
   273 	for(TInt uids = TestConstants::KInitialUID; i < newFields; i++, uids++)
       
   274 		{
       
   275 		AddNewFieldL( *iFields, TestConstants::KShortString, TFieldType::Uid(uids) );
       
   276 		}
       
   277 	SetContactFieldsL(*iContactItem);
       
   278 	fields = iFields->Count();	
       
   279 	CommitL();
       
   280 
       
   281 	const TInt length = iExistingUidsArray->Count()-1;
       
   282 	for(i = 0; i < length;)
       
   283 		{	
       
   284 		AddMultipleUidsL(*iViewII, i, 1);
       
   285 		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ) , i, 0 );
       
   286 		iViewII->Reset();
       
   287 		}
       
   288 		
       
   289 	const TInt flength = KCustomUidCount - 1;
       
   290 	for(i = 0; i < flength;)
       
   291 		{	
       
   292 		AddMultipleCustomUidsL(*iViewII, i, 1);
       
   293 		SINGLECOMPARE( doManyUidsL( aCid, *iViewII, fields, EFalse, EFalse ), i, 0 );
       
   294 		iViewII->Reset();
       
   295 		}
       
   296 	}
       
   297 	
       
   298 TBool CViewDefCustomFieldsTest::doManyUidsL(const TContactItemId &aCid, const CContactItemViewDef &aView,
       
   299 											const TInt aFieldCount, const TBool aExcludeN, 
       
   300 											const TBool aExcludeH )
       
   301 	{
       
   302 	TBool SingleTestResult = EFalse;
       
   303 	TBool OverallTestResult = ETrue;
       
   304 	
       
   305 	TInt countM = 0;
       
   306 	TInt countR = 0;
       
   307 	TInt fieldsIV = 0;
       
   308 
       
   309 	TInt emptyfsR = 0;
       
   310 	TInt hcountM = 0;
       
   311 	TInt hcountR = 0;
       
   312 	TInt hfieldsIV = 0;
       
   313 	
       
   314 	ReadL(aCid,*iViewAll,EFalse);
       
   315 	FieldsInView(aView, fieldsIV, hfieldsIV, ETrue);
       
   316 	countR = iFields->Count();
       
   317 	hcountR = CountHiddenFields(*iFields);
       
   318 	emptyfsR = CountEmpty(*iFields);
       
   319 	Close();
       
   320 	
       
   321 	ReadMinimalL(aCid, aView, *iDefView, EFalse);
       
   322 	countM = iFields->Count();
       
   323 	hcountM = CountHiddenFields(*iFields);
       
   324 
       
   325 	Close();
       
   326 	
       
   327 	SingleTestResult = INTCOMPARE( (countR - emptyfsR) , ==,  aFieldCount, 0, 0 ); 
       
   328 	OverallTestResult = OverallTestResult && SingleTestResult;
       
   329 	
       
   330 	if(aExcludeN)
       
   331 		{
       
   332 		SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , 0, 0 ); 
       
   333 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   334 		}
       
   335 	else
       
   336 		{
       
   337 		SingleTestResult = INTCOMPARE(  fieldsIV  , ==,  (countM - hcountM) , 0, 0 );
       
   338 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   339 		}
       
   340 	if(aExcludeH)
       
   341 		{
       
   342 		SingleTestResult = INTCOMPARE(  (hcountR - hfieldsIV) , ==,  hcountM , 0, 0 );
       
   343 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   344 		}
       
   345 	else
       
   346 		{
       
   347 		SingleTestResult = INTCOMPARE(  hcountM , ==,  hfieldsIV , 0, 0 );
       
   348 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   349 		}
       
   350 		
       
   351 	return OverallTestResult;
       
   352 	}
       
   353 
       
   354 void CViewDefCustomFieldsTest::AddMultipleCustomUidsL( CContactItemViewDef &aView, TInt &aPos, const TInt &aMany )
       
   355 	{
       
   356 	
       
   357 	static TInt lastPlace = 0;	
       
   358 	aView.Reset();
       
   359 	aView.AddL( TUid::Uid( TestConstants::KInitialUID + aPos ) );
       
   360 	
       
   361 	for(TInt i = 0; (lastPlace < KCustomUidCount) && (i < aMany); ++lastPlace, ++i)
       
   362 		{
       
   363 		if(lastPlace == aPos)
       
   364 			{
       
   365 			--i;
       
   366 			continue;
       
   367 			}
       
   368 		aView.AddL( TUid::Uid( TestConstants::KInitialUID + lastPlace ) );
       
   369 		}
       
   370 	if( lastPlace == KCustomUidCount )
       
   371 		{
       
   372 		lastPlace = 0;
       
   373 		++aPos;//this should never equal count
       
   374 		_LIT(KNextCustom,"nextCustom %d");
       
   375 		INFO_PRINTF2(KNextCustom, aPos);
       
   376 		}
       
   377 		
       
   378 	}
       
   379