phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/ViewDefBase.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 <e32panic.h>
       
    23 #include <test/testexecutelog.h>
       
    24 #include <cntfldst.h>
       
    25 #include "ViewDefBase.h"
       
    26 
       
    27 
       
    28 //Number of contacts
       
    29 CViewDefBase::CViewDefBase(const TInt aContacts):CCntBaseStep(aContacts)
       
    30 	{
       
    31 	}
       
    32 
       
    33 /**More items to be initilized within the uheap macro pair*/	
       
    34 void CViewDefBase::InitializeL()
       
    35 	{
       
    36 	
       
    37 	CCntBaseStep::InitializeL();
       
    38 	
       
    39 	iViewII = CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
       
    40 	CContactItemViewDef::EIncludeHiddenFields);
       
    41 	
       
    42 	iViewIM = CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
       
    43 	CContactItemViewDef::EMaskHiddenFields);
       
    44 	
       
    45 	iViewMI = CContactItemViewDef::NewL(CContactItemViewDef::EMaskFields,
       
    46 	CContactItemViewDef::EIncludeHiddenFields);
       
    47 	
       
    48 	iViewMM = CContactItemViewDef::NewL(CContactItemViewDef::EMaskFields,
       
    49 	CContactItemViewDef::EMaskHiddenFields);
       
    50 	
       
    51 	iDefView=CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
       
    52 	CContactItemViewDef::EMaskHiddenFields);
       
    53 	iDefView->AddL(KUidContactFieldMatchAll);
       
    54 	
       
    55 	}
       
    56 
       
    57 /**More items to be cleaned up within the uheap macro pair*/		
       
    58 void CViewDefBase::Cleanup()
       
    59 	{
       
    60 	CCntBaseStep::Cleanup();
       
    61 	
       
    62 	delete iViewII;
       
    63 	iViewII = NULL;
       
    64 	delete iViewIM;
       
    65 	iViewIM = NULL;
       
    66 	delete iViewMI;
       
    67 	iViewMI = NULL;
       
    68 	delete iViewMM;
       
    69 	iViewMM = NULL;
       
    70 	delete iDefView;
       
    71 	iDefView = NULL;
       
    72 	}
       
    73 
       
    74 /**returns the number of nonhidden, hidden and empty fields,
       
    75 that match aView for the current contact item*/	
       
    76 void CViewDefBase::FieldsInView(const CContactItemViewDef &aView, TInt &aRetNormal, 
       
    77 								TInt &aRetHidden, const TBool aHasEmpty)
       
    78 	{
       
    79 	TInt length = 0;
       
    80 	length = iFields->Count();
       
    81 	
       
    82 	for(TInt i = 0; i < length; )
       
    83 		{
       
    84 		if( !( (*iFields)[i].Storage()->IsFull() ) )
       
    85 			{
       
    86 			if(aHasEmpty)
       
    87 				{
       
    88 				++i;
       
    89 				continue;
       
    90 				}
       
    91 			else
       
    92 				{
       
    93 				_LIT(KUnfullView,"FieldsInView field is not full");
       
    94 				User::Panic(KUnfullView, EInvariantFalse);
       
    95 				}
       
    96 			}
       
    97 		if( ( i = FindInFieldSet(aView, i) ) != KErrNotFound )
       
    98 			{
       
    99 			if( (*iFields)[i].IsHidden() )
       
   100 				{
       
   101 				++aRetHidden;
       
   102 				}
       
   103 			else
       
   104 				{
       
   105 				++aRetNormal;
       
   106 				}
       
   107 			++i;
       
   108 			}
       
   109 		else
       
   110 			{
       
   111 			break;
       
   112 			}
       
   113 		}
       
   114 	
       
   115 	}
       
   116 
       
   117 /**returns the position of the next field that matches aView for the current contact item,
       
   118 returns KErrNotFound when it reaches end of fieldset or if it doesnt find a match*/		
       
   119 TInt CViewDefBase::FindInFieldSet(const CContactItemViewDef &aView, const TInt &aFrom)
       
   120 	{
       
   121 	const TInt length = iFields->Count();
       
   122 	const TInt viewLength = aView.Count();
       
   123 	CContentType * ctype = NULL;
       
   124 	TUid tuidback = KUidContactFieldNone;
       
   125 	TBool allUids = EFalse;
       
   126 	
       
   127 	for(TInt i = aFrom; i < length; i++ )
       
   128 		{
       
   129 		ctype = CONST_CAST( CContentType *, &((*iFields)[i].ContentType()) );
       
   130 		tuidback = ctype->Mapping();
       
   131 		ctype->SetMapping(KUidContactFieldNone);//contain now should ignore mapping
       
   132 		allUids = EFalse;
       
   133 		
       
   134 		for(TInt k = 0; k < viewLength; ++k)
       
   135 			{	
       
   136 			if( ctype->ContainsFieldType( aView[k] ) )
       
   137 				{
       
   138 				allUids = ETrue;
       
   139 				break;
       
   140 				}
       
   141 			}
       
   142 		ctype->SetMapping(tuidback);
       
   143 		if(allUids)
       
   144 			{
       
   145 			return i;
       
   146 			}
       
   147 		}
       
   148 	return KErrNotFound;
       
   149 	}
       
   150 
       
   151 /**adds a pair of existing uids, in every possible combination, to aView, 
       
   152 aView is reset before the pair are added to aview.if aMany is greater than one, more than a pair
       
   153 of uids are added but not in every possible combination*/		
       
   154 void CViewDefBase::AddMultipleUidsL( CContactItemViewDef &aView, TInt &aPos, const TInt &aMany )
       
   155 	{
       
   156 	
       
   157 	static TInt lastPlace = 0;
       
   158 	const static TInt count = iExistingUidsArray->Count();	
       
   159 	aView.Reset();
       
   160 	aView.AddL( TUid::Uid( (*iExistingUidsArray)[aPos] ) );
       
   161 	
       
   162 	for(TInt i = 0; (lastPlace < count) && (i < aMany); ++lastPlace, ++i)
       
   163 		{
       
   164 		if(lastPlace == aPos || ((*iExistingUidsArray)[lastPlace] == 0) )
       
   165 			{
       
   166 			--i;
       
   167 			continue;
       
   168 			}
       
   169 		aView.AddL( TUid::Uid( (*iExistingUidsArray)[lastPlace] ) );
       
   170 		}
       
   171 	if( lastPlace == count )
       
   172 		{
       
   173 		lastPlace = 0;
       
   174 		++aPos;//this should never equal count
       
   175 		_LIT(KNext,"next %d");
       
   176 		INFO_PRINTF2(KNext, aPos);
       
   177 		if( (aPos < count) && ((*iExistingUidsArray)[aPos] == 0) )
       
   178 			{
       
   179 			++aPos;
       
   180 			}
       
   181 		}
       
   182 		
       
   183 	}
       
   184 
       
   185