phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/ViewDefAnyFieldsTest.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 
       
    22 #include <test/testexecutelog.h>
       
    23 #include <cntfldst.h>
       
    24 #include "ClientServer.h"
       
    25 #include "ViewDefAnyFieldsTest.h"
       
    26 #include "CNTSTD.H"
       
    27 
       
    28 _LIT(KRun1,"SingleConfig");
       
    29 _LIT(KRun2,"UniqueConfig");
       
    30 _LIT(KRun3,"RepeatConfig");
       
    31 
       
    32 _LIT(KTest1,"Testing all uids in viewdef in single configurations...");
       
    33 _LIT(KTest2,"Testing all uids in viewdef in multiple unique configurations...");
       
    34 _LIT(KTest3,"Testing all uids in viewdef in multiple repeat configurations...");
       
    35 
       
    36 //Number of contacts
       
    37 CViewDefAnyFieldsTest::CViewDefAnyFieldsTest() 
       
    38 						: CViewDefBase(1)
       
    39 	{
       
    40 	// Call base class method to set up the human readable name for logging
       
    41 	SetTestStepName(SharedConstants::KViewDefAnyFieldsTest);
       
    42 	}
       
    43 
       
    44 TVerdict CViewDefAnyFieldsTest::doTestStepL()
       
    45 	{
       
    46 	
       
    47 	__UHEAP_MARK;
       
    48 	
       
    49 	
       
    50 	InitializeL();
       
    51 	iIterate->Reset();
       
    52 	
       
    53 	const TDesC &run = ConfigSection();
       
    54 	
       
    55 	if( run == KRun1 )
       
    56 		{
       
    57 		INFO_PRINTF1(KTest1);
       
    58 		doAnyFieldsTestL(iIterate->NextL());
       
    59 		}
       
    60 	else if( run == KRun2 )
       
    61 		{
       
    62 		INFO_PRINTF1(KTest2);
       
    63 		doUniqueUidsTestL(iIterate->NextL());
       
    64 		}
       
    65 	else if( run == KRun3 )
       
    66 		{
       
    67 		//this panics as only one instance of a uid is allowed within a viewdef
       
    68 		//only panics in debug mode
       
    69 		#ifdef _DEBUG
       
    70 		
       
    71 		INFO_PRINTF1(KTest3);
       
    72 		doIdenticalUidsTestL(iIterate->NextL());
       
    73 		
       
    74 		#else
       
    75 		
       
    76 		INFO_PRINTF1(KTest3);
       
    77 		_LIT(KTestPanic,"TestPanic");
       
    78 		User::Panic(KTestPanic, ECntPanicDuplicateViewFields);
       
    79 		
       
    80 		#endif
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		MissngTestPanic();
       
    85 		}
       
    86 	
       
    87 	Cleanup();
       
    88 	
       
    89 	__UHEAP_MARKEND;
       
    90 	
       
    91 	return TestStepResult();
       
    92 	}
       
    93 	
       
    94 /**
       
    95 tests loading aCid with different viewdefs, it is tested with all possible uids for each viewdef,
       
    96 check to see that expected fields are excluded/included
       
    97 */
       
    98 void CViewDefAnyFieldsTest::doAnyFieldsTestL(const TContactItemId &aCid)
       
    99 	{
       
   100 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   101 	SetContactFieldsL(*iContactItem);	
       
   102 	CommitL();
       
   103 	/*viewdefs ignore primary mappings stored as mapping in contenttype rather
       
   104 	than within the array*/
       
   105 	SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse), 0, 0);
       
   106 	//hidden is reversed
       
   107 	SINGLECOMPARE( FieldCountCompL(aCid, *iViewMI, ETrue, ETrue), 0, 0 );
       
   108 	//"all" hidden fields are excluded
       
   109 	SINGLECOMPARE( FieldCountCompL(aCid, *iViewIM, EFalse, ETrue, ETrue), 0, 0 );
       
   110 	//"all" hidden fields are excluded
       
   111 	SINGLECOMPARE( FieldCountCompL(aCid, *iViewMM, ETrue, ETrue, ETrue), 0, 0 );
       
   112 	}
       
   113 	
       
   114 /**
       
   115 attempt to load aCid with viewdef containing multiple(2) unique(existing) uids, 
       
   116 check to see that expected fields are excluded/included
       
   117 */
       
   118 void CViewDefAnyFieldsTest::doUniqueUidsTestL(const TContactItemId &aCid)
       
   119 	{
       
   120 	OpenL(aCid,*iViewAll, EFalse);//ETrue);
       
   121 	SetContactFieldsL(*iContactItem);	
       
   122 	CommitL();
       
   123 	//multiple uniques uids
       
   124 	SINGLECOMPARE( MultipleUidCountCompL(aCid, *iViewII, EFalse, EFalse),0 ,0 );
       
   125 	}
       
   126 /**
       
   127 attempt to load aCid with viewdef containing multiple identical uids, this test
       
   128 will panic in debug mode as CContactItemViewDef does not allow multiple identical uids
       
   129 */
       
   130 void CViewDefAnyFieldsTest::doIdenticalUidsTestL(const TContactItemId &aCid)
       
   131 	{
       
   132 	OpenL(aCid,*iViewAll, EFalse);// ETrue);
       
   133 	SetContactFieldsL(*iContactItem);	
       
   134 	CommitL();
       
   135 	//multiple identical uids
       
   136 	SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse, EFalse, ETrue), 0 , 0 );
       
   137 	}
       
   138 
       
   139 TBool CViewDefAnyFieldsTest::FieldCountCompL(	const TContactItemId &aCid,
       
   140 												CContactItemViewDef &aView, 
       
   141 												const TBool aExcludeN, 
       
   142 												const TBool aExcludeH,
       
   143 												const TBool aZeroH,
       
   144 												const TBool aMultiple)
       
   145 	{
       
   146 	TBool SingleTestResult = EFalse;
       
   147 	TBool OverallTestResult = EFalse;
       
   148 	
       
   149 	TInt countM = 0;
       
   150 	TInt countR = 0;
       
   151 	TInt fieldsIV = 0;
       
   152 	TInt emptyfsM = 0;
       
   153 	TInt emptyfsR = 0;
       
   154 	TInt hcountM = 0;
       
   155 	TInt hcountR = 0;
       
   156 	TInt hfieldsIV = 0;
       
   157 	
       
   158 	TInt length = 0;
       
   159 	
       
   160 	length = iExistingUidsArray->Count();
       
   161 	
       
   162 	for(TInt i = 0, j = 0; i < length;)
       
   163 		{
       
   164 		OverallTestResult = EFalse;
       
   165 		if( (*iExistingUidsArray)[i] == 0 )
       
   166 			{
       
   167 			++i;
       
   168 			continue;
       
   169 			}
       
   170 		aView.AddL(TUid::Uid((*iExistingUidsArray)[i]));
       
   171 		
       
   172 		ReadL(aCid,*iViewAll,EFalse);
       
   173 		FieldsInView(aView, fieldsIV, hfieldsIV);
       
   174 		countR = iFields->Count();
       
   175 		hcountR = CountHiddenFields(*iFields);
       
   176 		emptyfsR = CountEmpty(*iFields);
       
   177 		Close();
       
   178 		
       
   179 		ReadMinimalL(aCid, aView, *iDefView,EFalse);
       
   180 		countM = iFields->Count();
       
   181 		hcountM = CountHiddenFields(*iFields);
       
   182 		emptyfsM = CountEmpty(*iFields);
       
   183 		Close();
       
   184 		
       
   185 		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsM, i, 0 );
       
   186 		OverallTestResult = SingleTestResult;
       
   187 		
       
   188 		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsR, i, 0 );
       
   189 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   190 		
       
   191 		SingleTestResult = INTCOMPARE( hcountR , >,  0 , i, 0 );
       
   192 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   193 		
       
   194 		
       
   195 		if(aExcludeN)
       
   196 			{
       
   197 			SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , i, 0 );
       
   198 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   199 			}
       
   200 		else
       
   201 			{
       
   202 			SingleTestResult = INTCOMPARE( fieldsIV  , ==,  (countM - hcountM) , i, 0 );
       
   203 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   204 			}
       
   205 		if(aExcludeH)
       
   206 			{
       
   207 			if( aZeroH)
       
   208 				{
       
   209 				SingleTestResult = INTCOMPARE( 0 , ==,  hcountM, i, 0 );
       
   210 				OverallTestResult = OverallTestResult && SingleTestResult;	
       
   211 				}
       
   212 			else
       
   213 				{
       
   214 				SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==,  hcountM , i, 0 );
       
   215 				OverallTestResult = OverallTestResult && SingleTestResult;
       
   216 				}
       
   217 			}
       
   218 		else
       
   219 			{
       
   220 			SingleTestResult = INTCOMPARE( hcountM , ==,  hfieldsIV , i, 0 );
       
   221 			OverallTestResult = OverallTestResult && SingleTestResult;	
       
   222 			}
       
   223 		
       
   224 		
       
   225 		if(!OverallTestResult)
       
   226 			{
       
   227 			break;
       
   228 			}
       
   229 			
       
   230 		if(aMultiple)
       
   231 			{
       
   232 			++j;
       
   233 			if(4 == j)
       
   234 				{
       
   235 				j = 0;
       
   236 				++i;
       
   237 				aView.Reset();
       
   238 				}
       
   239 			}
       
   240 		else
       
   241 			{
       
   242 			++i;
       
   243 			aView.Reset();
       
   244 			}
       
   245 			
       
   246 		countM = 0;
       
   247 		countR = 0;
       
   248 		fieldsIV = 0;
       
   249 		emptyfsM = 0;
       
   250 		emptyfsR = 0;
       
   251 		hcountM = 0;
       
   252 		hcountR = 0;
       
   253 		hfieldsIV = 0;
       
   254 		
       
   255 		}
       
   256 	return OverallTestResult;
       
   257 	}
       
   258 
       
   259 TBool CViewDefAnyFieldsTest::MultipleUidCountCompL(	const TContactItemId &aCid,
       
   260 													CContactItemViewDef &aView, 
       
   261 													const TBool aExcludeN, 
       
   262 													const TBool aExcludeH
       
   263 													)
       
   264 	{
       
   265 	TBool SingleTestResult = EFalse;
       
   266 	TBool OverallTestResult = EFalse;
       
   267 	
       
   268 	const TInt KManyUids = 1;//number of additional uids
       
   269 	TInt countM = 0;
       
   270 	TInt countR = 0;
       
   271 	TInt fieldsIV = 0;
       
   272 	TInt emptyfsM = 0;
       
   273 	TInt emptyfsR = 0;
       
   274 	TInt hcountM = 0;
       
   275 	TInt hcountR = 0;
       
   276 	TInt hfieldsIV = 0;
       
   277 	
       
   278 	const TInt length = iExistingUidsArray->Count()-1;
       
   279 	
       
   280 	for(TInt i = 0; i < length;)
       
   281 		{
       
   282 		OverallTestResult = EFalse;
       
   283 		AddMultipleUidsL(aView, i, KManyUids);
       
   284 		
       
   285 		ReadL(aCid,*iViewAll,EFalse);
       
   286 		
       
   287 		FieldsInView(aView, fieldsIV, hfieldsIV);
       
   288 				
       
   289 		countR = iFields->Count();
       
   290 		hcountR = CountHiddenFields(*iFields);
       
   291 		emptyfsR = CountEmpty(*iFields);
       
   292 		Close();
       
   293 		
       
   294 		ReadMinimalL(aCid, aView, *iDefView, EFalse);
       
   295 		countM = iFields->Count();
       
   296 		hcountM = CountHiddenFields(*iFields);
       
   297 		emptyfsM = CountEmpty(*iFields);
       
   298 		Close();
       
   299 		
       
   300 		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsM, i, 0 ); 
       
   301 		OverallTestResult = SingleTestResult;
       
   302 		
       
   303 		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsR, i, 0 ); 
       
   304 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   305 		
       
   306 		SingleTestResult = INTCOMPARE( hcountR , >,  0 , i, 0 ); 
       
   307 		OverallTestResult = OverallTestResult && SingleTestResult;
       
   308 		
       
   309 		if(aExcludeN)
       
   310 			{
       
   311 			SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , i, 0 );
       
   312 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   313 			}
       
   314 		else
       
   315 			{
       
   316 			SingleTestResult = INTCOMPARE( fieldsIV  , ==,  (countM - hcountM) , i, 0 );
       
   317 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   318 			}
       
   319 		if(aExcludeH)
       
   320 			{
       
   321 			SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==,  hcountM , i, 0 );
       
   322 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   323 			}
       
   324 		else
       
   325 			{
       
   326 			SingleTestResult = INTCOMPARE( hcountM , ==,  hfieldsIV , i, 0 );
       
   327 			OverallTestResult = OverallTestResult && SingleTestResult;
       
   328 			}
       
   329 		
       
   330 		if(!OverallTestResult)
       
   331 			{
       
   332 			break;
       
   333 			}
       
   334 			
       
   335 		countM = 0;
       
   336 		countR = 0;
       
   337 		fieldsIV = 0;
       
   338 		emptyfsM = 0;
       
   339 		emptyfsR = 0;
       
   340 		hcountM = 0;
       
   341 		hcountR = 0;
       
   342 		hfieldsIV = 0;
       
   343 		
       
   344 		}
       
   345 	return OverallTestResult;
       
   346 	}
       
   347