phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/UnifiedSingular.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 "UnifiedSingular.h"
       
    26 #include "ClientServer.h"
       
    27 
       
    28 _LIT(KNewFieldsTest,"NewFields");
       
    29 _LIT(KTest1,"Adding empty new fields test...");
       
    30 
       
    31 CUnifiedSingular::CUnifiedSingular()
       
    32 			: CCntBaseStep(200)//Number of contacts
       
    33 	{
       
    34 	// Call base class method to set up the human readable name for logging
       
    35 	SetTestStepName(SharedConstants::KUnifiedSingular);
       
    36 	}
       
    37 
       
    38 TVerdict CUnifiedSingular::doTestStepL()
       
    39 	{
       
    40 	
       
    41 //Comment out all the tests for sqlite version because it tests against the 
       
    42 //field content based on fields position which is not part of cntmodel contract.
       
    43 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ 
       
    44 	__UHEAP_MARK;
       
    45 	
       
    46 	InitializeL();
       
    47 	
       
    48 	iIterate->Reset();
       
    49 	
       
    50 	const TDesC &KSectionName = ConfigSection();
       
    51 	
       
    52 
       
    53 	if( KSectionName == KNewFieldsTest )
       
    54 		{
       
    55 		INFO_PRINTF1(KTest1);
       
    56 		EmptyNewFieldTestL(iIterate->NextL());
       
    57 		}
       
    58 	else
       
    59 		{
       
    60 		MissngTestPanic();
       
    61 		}
       
    62 	Cleanup();
       
    63 	
       
    64 	__UHEAP_MARKEND;
       
    65 #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__
       
    66 	
       
    67 	return TestStepResult();
       
    68 	}
       
    69 
       
    70 
       
    71 
       
    72 
       
    73 /*performs a single set on a field, set label, add uid, or add new field, set value*/
       
    74 void CUnifiedSingular::SetSingularL(const TContactItemId &aCid, const TInt &aPos, 
       
    75 const TUnitType &aType, const TInt32 &aUid, const TDesC &aLabel, 
       
    76 CContentType ** const aCtype, const TBool aEmpty)
       
    77 	{
       
    78 	CContactItem *cedit = NULL;
       
    79 	cedit = iContactsDatabase->OpenContactLX(aCid,*iViewAll);
       
    80 	CleanupStack::PushL(cedit);
       
    81 	CContactItemFieldSet &fields = cedit->CardFields();
       
    82 	TBool rptType = EFalse;
       
    83 	const TFieldType &tfield = TFieldType::Uid(aUid);
       
    84 	switch(aType)
       
    85 		{
       
    86 		case EAddUid:
       
    87 			{
       
    88 			CContactItemField &field = fields[aPos];
       
    89 			rptType = field.ContentType().ContainsFieldType( tfield ) && (field.ContentType().Mapping() != tfield);
       
    90 			field.AddFieldTypeL( tfield );
       
    91 			*aCtype = CContentType::NewL( field.ContentType() );
       
    92 			if(rptType)
       
    93 				{
       
    94 				(*aCtype)->RemoveFieldType(tfield);
       
    95 				}
       
    96 			CleanupStack::PushL(*aCtype);
       
    97 			}
       
    98 		break;
       
    99 		case ESetLabel:
       
   100 			SetLabelL(fields,aPos,aLabel);
       
   101 		break;
       
   102 		case EAddField:
       
   103 			AddNewFieldL( fields, aLabel, TFieldType::Uid(aUid),aEmpty );
       
   104 		break;
       
   105 		case ESetFieldValue:
       
   106 			SetFieldL(fields,aPos,aLabel);
       
   107 		break;
       
   108 		default:
       
   109 			{
       
   110 			_LIT(KSetSingular,"setsingular");
       
   111 			User::Panic(KSetSingular,EInvariantFalse);
       
   112 			}
       
   113 		break;
       
   114 		}
       
   115 	iContactsDatabase->CommitContactL(*cedit);
       
   116 	if(aCtype)
       
   117 		{
       
   118 		CleanupStack::Pop(*aCtype);
       
   119 		}
       
   120 	CleanupStack::PopAndDestroy(cedit);
       
   121 	CleanupStack::Pop();
       
   122 	cedit = NULL;
       
   123 	}
       
   124 	
       
   125 /*performs a single check on a field, check label, check uid, or check new field*/
       
   126 TBool CUnifiedSingular::CheckSingularL(const TContactItemId &aCid, const TInt &aPos, 
       
   127 const TUnitType &aType, const TInt32 &aUid, const CContentType &aCtype, const TDesC &aLabel, 
       
   128 const TBool aEmpty)
       
   129 	{
       
   130 	TBool ret=EFalse;
       
   131 	
       
   132 	CContactItem *cedit = NULL;
       
   133 	cedit = iContactsDatabase->ReadContactLC(aCid,*iViewAll);
       
   134 	CContactItemFieldSet &fields = cedit->CardFields();
       
   135 	switch(aType)
       
   136 		{
       
   137 		case EAddUid:
       
   138 			{
       
   139 			_LIT(KInvalidField, "Following field contains incorrect uids:");
       
   140 			const CContentType &ctype = fields[aPos].ContentType();
       
   141 			ret = SINGLECOMPARE( CompareCTypes(ctype,aCtype),0,0 );
       
   142 			if(!ret)
       
   143 				{
       
   144 				const TPtrC KFieldLabel = fields[aPos].Label();
       
   145 				ERR_PRINTF1( KInvalidField);
       
   146 				ERR_PRINTF1( KFieldLabel);
       
   147 				}
       
   148 			}
       
   149 		break;
       
   150 		case ESetLabel:
       
   151 			ret = STRINGCOMPARE( fields[aPos].Label(), ==, aLabel,0,0 );
       
   152 		break;
       
   153 		case EAddField:
       
   154 			ret = SINGLECOMPARE(  CheckNewFieldL( fields, aPos, TFieldType::Uid(aUid),aEmpty ),0,0 );
       
   155 		break;
       
   156 		default:
       
   157 			{
       
   158 			_LIT(KCheckSingular,"checksingular");
       
   159 			User::Panic(KCheckSingular,EInvariantFalse);
       
   160 			}
       
   161 		break;
       
   162 		}
       
   163 	iContactsDatabase->CloseContactL(aCid);
       
   164 	CleanupStack::PopAndDestroy(cedit);
       
   165 	cedit = NULL;
       
   166 	
       
   167 	return ret;
       
   168 	}
       
   169 	
       
   170 /*compares atype2 to atype1, must be equal length, and all atype2 items must be contained within
       
   171 atype1*/
       
   172 TBool CUnifiedSingular::CompareCTypes(const CContentType &aType1,const CContentType &aType2)
       
   173 	{
       
   174 	TBool ret = EFalse;
       
   175 	TInt length = aType1.FieldTypeCount();
       
   176 	if(length != aType2.FieldTypeCount() )
       
   177 		{
       
   178 		SINGLECOMPARE( ret,0,0 );
       
   179 		return ret;
       
   180 		}
       
   181 	
       
   182 	for(TInt i = 0; i<length; i++)
       
   183 		{
       
   184 		if( !aType1.ContainsFieldType(aType2.FieldType(i)) )
       
   185 			{
       
   186 			SINGLECOMPARE( ret, i,0 );
       
   187 			return ret;
       
   188 			}
       
   189 		}
       
   190 	ret = ETrue;
       
   191 	return ret;
       
   192 	}
       
   193 	
       
   194 /*
       
   195 add new field without value, then commit, field is not stored
       
   196 */
       
   197 void CUnifiedSingular::EmptyNewFieldTestL(const TContactItemId &aCid)
       
   198 	{
       
   199 	CContactItem *cedit = NULL;
       
   200 	cedit = iContactsDatabase->ReadContactLC(aCid,*iViewAll);
       
   201 	CContactItemFieldSet &fields = cedit->CardFields();
       
   202 	TInt length = fields.Count();
       
   203 	iContactsDatabase->CloseContactL(aCid);
       
   204 	CleanupStack::PopAndDestroy(cedit);
       
   205 	cedit = NULL;
       
   206 	CContentType * ctype = NULL;
       
   207 	
       
   208 	for(int i=0, uids = TestConstants::KAltUID;i < length; uids++, i++)
       
   209 		{
       
   210 		SetSingularL(aCid,i,EAddField,uids,TestConstants::KLongString,NULL,ETrue);
       
   211 		SINGLECOMPARE( CheckSingularL(aCid,length+i,EAddField,uids,*ctype,KNullDesC,ETrue), i,0 );
       
   212 		}
       
   213 		
       
   214 	}
       
   215 
       
   216 
       
   217