phonebookengines_old/contactsmodel/tsrc/T_GROUPS.CPP
branchGCC_SURGE
changeset 41 d11de32a5e6f
parent 40 b46a585f6909
equal deleted inserted replaced
38:11319788d38f 41:d11de32a5e6f
       
     1 // Copyright (c) 1997-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 #include <e32test.h>
       
    17 #include <f32file.h>
       
    18 #include <s32file.h>
       
    19 
       
    20 #include <cntdb.h>
       
    21 
       
    22 #include <cntitem.h>
       
    23 #include <cntfield.h>
       
    24 #include <cntfldst.h>
       
    25 #include <bautils.h>
       
    26 #include <barsc.h>
       
    27 #include <barsread.h>
       
    28 #include <cntmodel.rsg>
       
    29 #include "T_UTILS.H"
       
    30 #include <hal.h>
       
    31 #include "CntClient.h"
       
    32 
       
    33 #pragma warning(disable:4239) // group label warning
       
    34 
       
    35 CCntTest* CntTest=NULL;
       
    36 LOCAL_D RTest test(_L("T_GROUPS"));
       
    37 TInt CCntClient::iObservers = 0;
       
    38 
       
    39 const TPtrC KDatabaseFileName=_L("C:T_GROUP");
       
    40 const TPtrC KTestName=_L("Test Name No %d");
       
    41 const TPtrC KTestAddress=_L("Test Address No %d");
       
    42 const TPtrC KTestFamilyName=_L("Test Family Name No %d");
       
    43 const TPtrC KLongLabel = _L("New Long Label");
       
    44 const TPtrC KGroupLabel = _L("Group Label No%d");
       
    45 const TPtrC KTestEmail = _L("Test@Email.com No %d");
       
    46 const TPtrC KTestCountry = _L("Test Country No %d");
       
    47 const TPtrC KTestCompany = _L("Test Company No %d");
       
    48 const TInt KLargeSizeRecords=50;
       
    49 const TInt KFamilySizeRecords=20;
       
    50 
       
    51 
       
    52 #define KCardGivenName _L("Given Name #%d")
       
    53 #define KCardFamilyName _L("Family Name #%d")
       
    54 #define KCardFieldText _L("Card id %d, text field #%d")
       
    55 #define KCardFieldEditedText _L("UPDATED Card id %d, text field #%d")
       
    56 
       
    57 
       
    58 //
       
    59 //
       
    60 //	SUPPORT MODULES 
       
    61 //
       
    62 //
       
    63 
       
    64 GLDEF_C void Panic(TInt aPanic)
       
    65 //
       
    66 // Panic the thread with CNTMODEL as the category
       
    67 //
       
    68 	{
       
    69 	User::Panic(_L("T_GROUP"),aPanic);
       
    70 	}
       
    71 
       
    72 LOCAL_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName)
       
    73 //
       
    74 // Set the contents of a text field, creating the field if required
       
    75 //
       
    76 	{
       
    77 	CContactItemFieldSet& fieldSet=aItem.CardFields();
       
    78 	const TInt pos=fieldSet.Find(aType);
       
    79 	if (pos!=KErrNotFound)
       
    80 		fieldSet[pos].TextStorage()->SetTextL(aName);
       
    81 	else
       
    82 		Panic(KErrGeneral);
       
    83 	}
       
    84 
       
    85 LOCAL_C void PopulateDatabaseL(TInt aNumberToPopulate, TBool aPhoneNumbers)
       
    86 //
       
    87 // Create and populate the database
       
    88 //
       
    89 	{
       
    90 	TTime before;
       
    91 	before.UniversalTime();
       
    92 	CContactItem* templ = CntTest->Db()->ReadContactL(0);
       
    93 	CleanupStack::PushL(templ);
       
    94 	for (TInt ii=0;ii<aNumberToPopulate;ii++)
       
    95 		{
       
    96 		CContactItem* item=CContactCard::NewLC(templ);
       
    97 		TBuf<16> name;
       
    98 		name.Format(KTestName,ii);
       
    99    		SetNameL(*item,KUidContactFieldGivenName,name);
       
   100 		if (aPhoneNumbers)
       
   101 			{
       
   102 			TBuf<20> number;
       
   103 			switch(ii%3)
       
   104 				{
       
   105 				case 0:
       
   106 					number.Format(_L("0171-%03d %04d"),(ii*9)%1000,((ii+11)*23)%10000);
       
   107 					break;
       
   108 				case 1:
       
   109 					number.Format(_L("%04d:%04d:%04d:%04d"),(ii*123)%10000,(ii*666)%10000,(ii*234)%10000);
       
   110 					break;
       
   111 				case 2:
       
   112 					number.Format(_L("+00%d-%03d %04d"),(ii*123)%100,(ii*13)%1000,((ii+13)*17)%10000);
       
   113 					break;
       
   114 				}
       
   115    			SetNameL(*item,KUidContactFieldPhoneNumber,number);
       
   116 			if (!(ii%2))
       
   117 				{
       
   118 				number.Format(_L("0181-%03d %04d"),(ii*8)%1000,((ii+11)*22)%10000);
       
   119 	   			SetNameL(*item,KUidContactFieldPhoneNumber,number);
       
   120 				number.Format(_L("01734-%06d"),(ii*123456)%1000000);
       
   121 	   			SetNameL(*item,KUidContactFieldPhoneNumber,number);
       
   122 				}
       
   123 			}
       
   124 		TBuf<32> address;
       
   125 		address.Format(KTestAddress,ii);
       
   126 		SetNameL(*item,KUidContactFieldAddress,address);
       
   127 //
       
   128 		TBuf<32> familyName;
       
   129 		familyName.Format(KTestFamilyName,ii);
       
   130 		SetNameL(*item,KUidContactFieldFamilyName,familyName);
       
   131 //
       
   132 		TBuf<32> email;
       
   133 		email.Format(KTestEmail,ii);
       
   134 		SetNameL(*item,KUidContactFieldEMail,email);
       
   135 //
       
   136 		TBuf<32> country;
       
   137 		country.Format(KTestCountry,ii);
       
   138 		SetNameL(*item,KUidContactFieldCountry,country);
       
   139 //	
       
   140 		TBuf<32> company;
       
   141 		company.Format(KTestCompany,ii);
       
   142 		SetNameL(*item,KUidContactFieldCompanyName,company);
       
   143 //	
       
   144 		CntTest->Db()->AddNewContactL(*item); //templ
       
   145 		CleanupStack::PopAndDestroy(); // item
       
   146 //	
       
   147 		if (ii%100==0)
       
   148 			{
       
   149 			test.Printf(_L("."));	// Just to show some life
       
   150 			CntTest->Db()->CompactL();
       
   151 			}
       
   152 
       
   153 		}
       
   154 	CleanupStack::PopAndDestroy();
       
   155 	CntTest->Db()->SetDateFormatTextL(_L("%E%D%X%N%Y %1 %2 %3"));
       
   156 	CntTest->Db()->CompactL();
       
   157 	TTime after;
       
   158 	after.UniversalTime();
       
   159 	TTimeIntervalSeconds secondsTaken;
       
   160 	after.SecondsFrom(before,secondsTaken);
       
   161 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   162 	test.Printf(_L("\n"));	
       
   163 	//test.Getch();
       
   164 	}
       
   165 
       
   166 
       
   167 //
       
   168 //
       
   169 //	TEST MODULES 
       
   170 //
       
   171 //
       
   172 
       
   173 
       
   174 LOCAL_C void CreateBasicContactGroups()
       
   175 	{
       
   176 	test.Next(_L("Create Basic Groups"));
       
   177 	__ASSERT_ALWAYS(CntTest->Db()->GroupCount()==0,Panic(KErrGeneral));
       
   178 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(_L("New Group"));
       
   179 	CContactItem* newGroup2 = CntTest->Db()->CreateContactGroupL();
       
   180 	CleanupStack::PushL(newGroup);
       
   181 	CleanupStack::PushL(newGroup2);
       
   182 	CntTest->CloseDatabase();
       
   183 	CntTest->OpenDatabaseL();
       
   184 	test(CntTest->Db()->GroupCount()==2);
       
   185 	CleanupStack::PopAndDestroy(2); // newGroup newGroup2
       
   186 	}
       
   187 
       
   188 LOCAL_C void CreateGroupFromAClientL(CCntClient& aCntClient)
       
   189 	{
       
   190 	test.Next(_L("Create a basic group"));
       
   191 	CContactItem* tempGroup = aCntClient.Db()->CreateContactGroupL(_L("New Group"));
       
   192 	delete tempGroup ;
       
   193 	CActiveScheduler::Start();
       
   194 	}
       
   195 
       
   196 LOCAL_C void DeleteBasicContactGroups()
       
   197 	{
       
   198 	test.Next(_L("Delete Basic Groups"));
       
   199 	TInt groupCount = CntTest->Db()->GroupCount();
       
   200 	__ASSERT_ALWAYS(groupCount==2,Panic(KErrGeneral));
       
   201 	CContactIdArray* groupIdList = CntTest->Db()->GetGroupIdListL();
       
   202 	CleanupStack::PushL(groupIdList);
       
   203 	test(groupIdList->Count()==2);
       
   204 //
       
   205 	for (TInt ii=0; ii< groupIdList->Count();ii++)
       
   206 		CntTest->Db()->DeleteContactL((*groupIdList)[ii]);
       
   207 	test(CntTest->Db()->CountL()==0); //own card
       
   208 	CContactIdArray* newGroupIdList = CntTest->Db()->GetGroupIdListL();
       
   209 	test(newGroupIdList->Count()==0);
       
   210 	delete newGroupIdList;
       
   211 	CleanupStack::PopAndDestroy(); //groupIdList;
       
   212 	}	
       
   213 
       
   214 LOCAL_C void CheckBasicPopulatedGroup()
       
   215 	{
       
   216 	test.Next(_L("Populate Basic Group"));
       
   217 	CntTest->CloseDatabase();
       
   218 	CntTest->DeleteDatabaseL();
       
   219 	CntTest->CreateDatabaseL();
       
   220 	TRAP_IGNORE(PopulateDatabaseL(KFamilySizeRecords,ETrue));
       
   221 	
       
   222 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupLC(_L("Family Group"));
       
   223 	TContactItemId groupId = newGroup->Id();
       
   224 	for(TInt ii=2;ii<12;ii++)
       
   225 		{
       
   226 		CntTest->Db()->AddContactToGroupL(ii,groupId);
       
   227 		}
       
   228 	CntTest->CloseDatabase();
       
   229 	CntTest->OpenDatabaseL();
       
   230 //
       
   231 	CContactItem* familyGroup = CntTest->Db()->ReadContactLC(groupId);
       
   232 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,familyGroup)->ItemsContainedLC();
       
   233 	test(memberArray->Count()==10);
       
   234 //
       
   235 	CContactItem* familyMember = CntTest->Db()->ReadContactLC(2);
       
   236 	CContactIdArray* groups = STATIC_CAST(CContactCard*, familyMember)->GroupsJoinedLC();
       
   237 	test(groups->Count()==1);
       
   238 	TContactItemId memberShip = (*groups)[0];
       
   239 	test(memberShip==groupId);
       
   240 	CleanupStack::PopAndDestroy(5); 
       
   241 	// newGroup familyGroup memberArray familyMember groups
       
   242 	}
       
   243 
       
   244 
       
   245 LOCAL_C void CheckRemoveMember()
       
   246 	{
       
   247 	test.Next(_L("Remove Group Member a check Persist"));
       
   248 //
       
   249 	CContactItem* familyMember = CntTest->Db()->ReadContactLC(2);
       
   250 	CContactIdArray* groups = STATIC_CAST(CContactCard*, familyMember)->GroupsJoinedLC();
       
   251 	test(groups->Count()>=1);
       
   252 	TContactItemId memberShip = (*groups)[0];
       
   253 	CContactItem* group = CntTest->Db()->ReadContactLC(memberShip);
       
   254 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,group)->ItemsContainedLC();
       
   255 	TInt memberCount1 = memberArray->Count();
       
   256 //
       
   257 	CntTest->Db()->RemoveContactFromGroupL(*familyMember, *group);
       
   258 	CleanupStack::PopAndDestroy(); // group
       
   259 //
       
   260 	CContactItem* changedGroup = CntTest->Db()->ReadContactLC(memberShip);
       
   261 	CContactIdArray* newMemberArray = STATIC_CAST(CContactGroup*,changedGroup)->ItemsContainedLC();
       
   262 	test(newMemberArray->Count()==memberCount1-1);
       
   263 	CleanupStack::PopAndDestroy(5); // familyMember groups changedGroup newMemberArray memberarray
       
   264 	}
       
   265 
       
   266 LOCAL_C void CheckRemoveGroup()
       
   267 	{
       
   268 	test.Next(_L("Remove Group check Persist"));
       
   269 //
       
   270 	CContactIdArray* groupIdList = CntTest->Db()->GetGroupIdListL();
       
   271 	CleanupStack::PushL(groupIdList);
       
   272 	CContactItem* group = CntTest->Db()->ReadContactLC((*groupIdList)[0]);
       
   273 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,group)->ItemsContainedLC();
       
   274 //
       
   275 	CContactItem* member = CntTest->Db()->ReadContactLC((*memberArray)[0]);
       
   276 	CContactIdArray* memberShipArray = STATIC_CAST(CContactCard*, member)->GroupsJoinedLC();
       
   277 	__ASSERT_ALWAYS(memberShipArray->Count()==1,Panic(KErrGeneral));
       
   278 	test((*memberShipArray)[0]==(*groupIdList)[0]);
       
   279 //
       
   280 	CntTest->Db()->DeleteContactL((*groupIdList)[0]);
       
   281 //
       
   282 	CContactItem* newMember = CntTest->Db()->ReadContactLC((*memberArray)[0]);
       
   283 	CContactIdArray* newMemberShipArray = STATIC_CAST(CContactCard*, newMember)->GroupsJoinedLC();
       
   284 	test(newMemberShipArray->Count()==0);
       
   285 //
       
   286 	CleanupStack::PopAndDestroy(7); // groupidList group memberArray member memberShipArray newMember newMemberShipArray
       
   287 	}
       
   288 
       
   289 LOCAL_C void CheckLargePopulatedGroup()
       
   290 	{
       
   291 	test.Next(_L("Create MANY Contacts"));
       
   292 	CntTest->CloseDatabase();
       
   293 	CntTest->DeleteDatabaseL();
       
   294 	CntTest->CreateDatabaseL();
       
   295 	TRAP_IGNORE(PopulateDatabaseL(KLargeSizeRecords,ETrue));
       
   296 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(_L("Large Group"));
       
   297 	CleanupStack::PushL(newGroup);
       
   298 	TContactItemId groupId = newGroup->Id();
       
   299 	test.Next(_L("Add MANY Contacts to a Group"));
       
   300 	TTime before;
       
   301 	before.UniversalTime();
       
   302 	for(TInt ii=1;ii<KLargeSizeRecords+1;ii++)
       
   303 		{
       
   304 		CntTest->Db()->AddContactToGroupL(ii, groupId); //*tempContact,*newGroup);
       
   305 		if (ii%100==0)
       
   306 			test.Printf(_L("."));	// Just to show some life
       
   307 		}
       
   308 	test(TestGroupStateL(CntTest->Db(),1,KLargeSizeRecords));
       
   309 	TTime after;
       
   310 	after.UniversalTime();
       
   311 	TTimeIntervalSeconds secondsTaken;
       
   312 	after.SecondsFrom(before,secondsTaken);
       
   313 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   314 	test.Printf(_L("\n"));	
       
   315 	//test.Getch();
       
   316 	CntTest->CloseDatabase();
       
   317 	CntTest->OpenDatabaseL();
       
   318 //
       
   319 	CContactItem* familyGroup = CntTest->Db()->ReadContactL(groupId);
       
   320 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,familyGroup)->ItemsContainedLC();
       
   321 	test(memberArray->Count()==KLargeSizeRecords);
       
   322 	delete familyGroup;
       
   323 //
       
   324 	CContactItem* familyMember = CntTest->Db()->ReadContactL(2);
       
   325 	CContactIdArray* groups = STATIC_CAST(CContactCard*, familyMember)->GroupsJoinedLC();
       
   326 	test(groups->Count()==1);
       
   327 	TContactItemId memberShip = (*groups)[0];
       
   328 	test(memberShip==groupId);
       
   329 	delete familyMember;
       
   330 	CleanupStack::PopAndDestroy(3); // newGroup groups memberArray
       
   331 	}
       
   332 
       
   333 LOCAL_C void DeleteGroupMembersCheckPersist()
       
   334 	{
       
   335 	test.Next(_L("Delete Group Members Check Persist"));
       
   336 //
       
   337 	TTime before;
       
   338 	before.UniversalTime();
       
   339 	for(TInt ii=1;ii<KLargeSizeRecords+1;ii++)
       
   340 		{
       
   341 		CntTest->Db()->DeleteContactL(ii);
       
   342 		if (ii%100==0)
       
   343 			test.Printf(_L("."));	// Just to show some life
       
   344 		}
       
   345 	TTime after;
       
   346 	after.UniversalTime();
       
   347 	TTimeIntervalSeconds secondsTaken;
       
   348 	after.SecondsFrom(before,secondsTaken);
       
   349 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   350 	test.Printf(_L("\n"));	
       
   351 	//test.Getch();
       
   352 //
       
   353 	CContactIdArray* groups = CntTest->Db()->GetGroupIdListL();
       
   354 	CleanupStack::PushL(groups);
       
   355 	CContactItem* group = CntTest->Db()->ReadContactL((*groups)[0]);
       
   356 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,group)->ItemsContainedLC();
       
   357 	test(memberArray->Count()==0);
       
   358 	delete group;
       
   359 	CleanupStack::PopAndDestroy(2); // groups memberArray
       
   360 	}
       
   361 
       
   362 
       
   363 LOCAL_C void CreateManyGroups()
       
   364 	{
       
   365 	test.Next(_L("Populate Database"));
       
   366 	CntTest->CloseDatabase();
       
   367 	CntTest->DeleteDatabaseL();
       
   368 	CntTest->CreateDatabaseL();
       
   369 	// add 5 new contacts
       
   370 	TRAP_IGNORE(PopulateDatabaseL(5,ETrue));
       
   371 //
       
   372 	test.Next(_L("Create MANY Groups"));
       
   373 	TTime before;
       
   374 	before.UniversalTime();
       
   375 	for(TInt ii=0;ii<KLargeSizeRecords;ii++)
       
   376 		{
       
   377 		TBuf<32> label;
       
   378 		label.Format(KGroupLabel,ii);
       
   379 		CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(label);
       
   380 		if (ii%100==0)
       
   381 				test.Printf(_L("."));	// Just to show some life
       
   382 		delete newGroup;
       
   383 		}
       
   384 	TTime after;
       
   385 	after.UniversalTime();
       
   386 	TTimeIntervalSeconds secondsTaken;
       
   387 	after.SecondsFrom(before,secondsTaken);
       
   388 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   389 	test.Printf(_L("\n"));	
       
   390 	//test.Getch();
       
   391 	test(CntTest->Db()->GroupCount()==KLargeSizeRecords);
       
   392 //
       
   393 	test.Next(_L("Add 5 Contacts to MANY Groups"));
       
   394 	before.UniversalTime();
       
   395 	for(TInt jj=1;jj<6;jj++)
       
   396 	// add cards to all groups
       
   397 		{
       
   398 		CContactItem* contact = CntTest->Db()->ReadContactL(jj);
       
   399 		CleanupStack::PushL(contact);
       
   400 		for(TInt gg=6;gg<KLargeSizeRecords+6;gg++)	// assume knowledge of group ids..
       
   401 			{
       
   402 			CntTest->Db()->AddContactToGroupL(jj,gg);	//*contact,*group);
       
   403 			if (gg%100==0)
       
   404 				test.Printf(_L("."));	// Just to show some life
       
   405 			}
       
   406 		CleanupStack::PopAndDestroy(); // contact
       
   407 		}
       
   408 	after.UniversalTime();
       
   409 	after.SecondsFrom(before,secondsTaken);
       
   410 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   411 	test.Printf(_L("\n"));	
       
   412 	test(TestGroupStateL(CntTest->Db(),KLargeSizeRecords,5*KLargeSizeRecords));
       
   413 	//test.Getch();
       
   414 
       
   415 //
       
   416 	test.Next(_L("Check Contacts Group membership"));
       
   417 	before.UniversalTime();
       
   418 	for(TInt gg=1;gg<6;gg++)
       
   419 	//	check cards membership
       
   420 		{
       
   421 		CContactItem* contact = CntTest->Db()->ReadContactLC(gg);
       
   422 		CContactIdArray* groups = STATIC_CAST(CContactCard*, contact)->GroupsJoinedLC();
       
   423 		test(groups->Count()==KLargeSizeRecords);
       
   424 		CleanupStack::PopAndDestroy(2); // contact groups
       
   425 		}
       
   426 	after.UniversalTime();
       
   427 	after.SecondsFrom(before,secondsTaken);
       
   428 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   429 	test.Printf(_L("\n"));	
       
   430 	//test.Getch();
       
   431 
       
   432 	}
       
   433 
       
   434 
       
   435 LOCAL_C void DeleteManyGroups()
       
   436 	{
       
   437 //
       
   438 	test.Next(_L("Delete MANY Groups"));
       
   439 	TTime before;
       
   440 	before.UniversalTime();
       
   441 	for(TInt ii=6;ii<KLargeSizeRecords+6;ii++)
       
   442 		{
       
   443 		CntTest->Db()->DeleteContactL(ii);
       
   444 		if (ii%100==0)
       
   445 				test.Printf(_L("."));	// Just to show some life
       
   446 		}
       
   447 	TTime after;
       
   448 	after.UniversalTime();
       
   449 	TTimeIntervalSeconds secondsTaken;
       
   450 	after.SecondsFrom(before,secondsTaken);
       
   451 	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
       
   452 	test.Printf(_L("\n"));	
       
   453 	//test.Getch();
       
   454 
       
   455 //
       
   456 	test.Next(_L("Test Card Membership Update"));
       
   457 	test(CntTest->Db()->CountL()==5); // 5 contacts + own card
       
   458 	for(TInt jj=1;jj<6;jj++)
       
   459 	// add cards to all groups
       
   460 		{
       
   461 		CContactItem* contact = CntTest->Db()->ReadContactLC(jj);
       
   462 		CContactIdArray* groups = STATIC_CAST(CContactCard*, contact)->GroupsJoinedLC();
       
   463 		test(groups->Count()==0);
       
   464 		CleanupStack::PopAndDestroy(2); // contact groups
       
   465 		}
       
   466 	CntTest->Db()->CompactL();
       
   467 	}
       
   468 
       
   469 
       
   470 LOCAL_C void AddCardToCard()
       
   471 	{
       
   472 //
       
   473 	test.Next(_L("Add Card to Card"));
       
   474 	// assumes Prior Knowldege of contacts 2 & 3 (both are cards)
       
   475 	CntTest->Db()->AddContactToGroupL(2,3);	
       
   476 //
       
   477 	}	
       
   478 	
       
   479 
       
   480 LOCAL_C void AddGroupToCard()
       
   481 	{
       
   482 //
       
   483 	test.Next(_L("Group to Card"));
       
   484 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupL(_L("New Group"));
       
   485 	TContactItemId tempId = newGroup->Id();
       
   486 	delete newGroup;
       
   487 	// assumes Prior Knowldege of contact 3 (is a card)
       
   488 	CntTest->Db()->AddContactToGroupL(tempId,3);	
       
   489 //
       
   490 	}
       
   491 
       
   492 
       
   493 LOCAL_C void AddBadCardToGroup()
       
   494 	{
       
   495 //
       
   496 	test.Next(_L("Add unknown Card to group"));
       
   497 	// where id 19 does not exist (assumes knowledge of KLargeSizeRecords+6 as a group)
       
   498 	CntTest->Db()->AddContactToGroupL(KLargeSizeRecords+9,KLargeSizeRecords+6);	
       
   499 //
       
   500 	}
       
   501 
       
   502 LOCAL_C void AddCardToBadGroup()
       
   503 	{
       
   504 //
       
   505 	test.Next(_L("Add Card to Unknown group"));
       
   506 	// where id 19 does not exist
       
   507 	CntTest->Db()->AddContactToGroupL(3,KLargeSizeRecords+9);	
       
   508 //
       
   509 	}
       
   510 
       
   511 
       
   512 LOCAL_C void AddCardToGroupTwice()
       
   513 	{
       
   514 //
       
   515 	test.Next(_L("Add Card to group Twice"));
       
   516 	// assumes Prior Knowldege of KLargeSizeRecords+6 is a group
       
   517 	CntTest->Db()->AddContactToGroupL(3,KLargeSizeRecords+6);	
       
   518 	CntTest->Db()->AddContactToGroupL(3,KLargeSizeRecords+6);	
       
   519 //
       
   520 	}
       
   521 
       
   522 LOCAL_C void AddFieldToGroup()
       
   523 	{
       
   524 //
       
   525 	test.Next(_L("Add Field to Group"));
       
   526 	// assumes Prior Knowldege of KLargeSizeRecords+6 is a group
       
   527 	CContactItem* group = CntTest->Db()->OpenContactL(KLargeSizeRecords+6);	
       
   528 	CleanupStack::PushL(group);
       
   529 	CContactItemField* field=CContactItemField::NewLC(KStorageTypeText);
       
   530 	field->SetMapping(KUidContactFieldVCardMapUnusedN);
       
   531 	field->TextStorage()->SetTextL(_L("Test Field"));
       
   532 	group->AddFieldL(*field);
       
   533 //
       
   534 	CntTest->Db()->CommitContactL(*group);
       
   535 	CntTest->CloseDatabase();
       
   536 	CntTest->OpenDatabaseL();
       
   537 	CContactItem* group2 = CntTest->Db()->OpenContactL(KLargeSizeRecords+6);	
       
   538 	CContactItemFieldSet& tempFieldSet = group2->CardFields();
       
   539 	test(tempFieldSet.Count()==2);
       
   540 	CntTest->Db()->CloseContactL(KLargeSizeRecords+6);
       
   541 	delete group2;
       
   542 	CleanupStack::Pop(); // field
       
   543 	CleanupStack::PopAndDestroy();  // group
       
   544 	}
       
   545 
       
   546 
       
   547 LOCAL_C void SetGroupLabel()
       
   548 	{
       
   549 //
       
   550 	test.Next(_L("Set Group Label"));
       
   551 	// assumes Prior Knowldege of KLargeSizeRecords+6 is a group
       
   552 	CContactIdArray* groupIds = CntTest->Db()->GetGroupIdListL();
       
   553 	CleanupStack::PushL(groupIds);
       
   554 	CContactItem* group = CntTest->Db()->OpenContactL((*groupIds)[0]);	
       
   555 	CleanupStack::PushL(group);
       
   556 	TBuf<32> label;
       
   557 		label.Format(KGroupLabel,1);
       
   558 	STATIC_CAST(CContactGroup*,group)->SetGroupLabelL(label);
       
   559 //
       
   560 	CntTest->Db()->CommitContactL(*group);
       
   561 	CntTest->CloseDatabase();
       
   562 	CntTest->OpenDatabaseL();
       
   563 	CContactItem* group2 = CntTest->Db()->ReadContactLC(KLargeSizeRecords+6,*CntTest->Db()->AllFieldsView());
       
   564 	TPtrC testLabel = STATIC_CAST(CContactGroup*,group2)->GetGroupLabelL();
       
   565 	test(testLabel==label);
       
   566 	//delete group2;
       
   567 	CleanupStack::PopAndDestroy(3);  // group groupIds group2
       
   568 	}
       
   569 
       
   570 LOCAL_C void ChangeGroupLabel()
       
   571 	{
       
   572 	test.Next(_L("Change Group Label"));
       
   573 	// assumes Prior Knowldege of KLargeSizeRecords+6 is a group
       
   574 	CContactIdArray* groupIds = CntTest->Db()->GetGroupIdListL();
       
   575 	CleanupStack::PushL(groupIds);
       
   576 	CContactItem* group = CntTest->Db()->OpenContactL((*groupIds)[0]);	
       
   577 	CleanupStack::PushL(group);
       
   578 	TBuf<32> label;
       
   579 		label.Format(KGroupLabel,1);
       
   580 	STATIC_CAST(CContactGroup*,group)->SetGroupLabelL(_L("Glenns Group"));
       
   581 //
       
   582 	CntTest->Db()->CommitContactL(*group);
       
   583 	CntTest->CloseDatabase();
       
   584 	CntTest->OpenDatabaseL();
       
   585 	CContactItem* group2 = CntTest->Db()->ReadContactLC(KLargeSizeRecords+6,*CntTest->Db()->AllFieldsView());
       
   586 	TPtrC testLabel = STATIC_CAST(CContactGroup*,group2)->GetGroupLabelL();
       
   587 	test(testLabel==_L("Glenns Group"));
       
   588 	//delete group2;
       
   589 	CleanupStack::PopAndDestroy(3);  // group groupIds group2
       
   590 	}
       
   591 
       
   592 // Extended to provide coverage for defect 
       
   593 // EDNBWHE-4HXCXM "group retains link to a nested group after it has been deleted"
       
   594 //
       
   595 LOCAL_C void CheckNestedGroup()
       
   596 	{	
       
   597 	test.Next(_L("Check Nested Group"));
       
   598 	CntTest->CloseDatabase();
       
   599 	CntTest->DeleteDatabaseL();
       
   600 	CntTest->CreateDatabaseL();
       
   601 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupLC(_L("Family Group"));
       
   602 	TContactItemId groupId = newGroup->Id();
       
   603 	
       
   604 	CContactItem* nestedGroup = CntTest->Db()->CreateContactGroupLC(_L("nested Group"));
       
   605 	TContactItemId nestedGroupId = nestedGroup->Id();
       
   606 
       
   607 	CntTest->Db()->AddContactToGroupL(nestedGroupId,groupId);
       
   608 
       
   609 	CntTest->CloseDatabase();
       
   610 	CntTest->OpenDatabaseL();
       
   611 
       
   612 	CContactItem* familyGroup = CntTest->Db()->ReadContactLC(groupId);
       
   613 	CContactIdArray* memberArray = STATIC_CAST(CContactGroup*,familyGroup)->ItemsContainedLC();
       
   614 	test(memberArray->Count()==1);
       
   615 
       
   616 	CContactItem* newNestedGroup = CntTest->Db()->ReadContactLC(nestedGroupId);
       
   617 	CContactIdArray* nestedMemberArray = STATIC_CAST(CContactGroup*,newNestedGroup)->ItemsContainedLC();
       
   618 	test(nestedMemberArray->Count()==0); //fails as count = 0
       
   619 
       
   620 	CContactIdArray* groups = STATIC_CAST(CContactGroup*, newNestedGroup)->GroupsJoinedLC();
       
   621 	test(groups->Count()==1); 
       
   622 	
       
   623 	TContactItemId memberShip = (*groups)[0];
       
   624 	test(memberShip==groupId);
       
   625 	
       
   626 	// If delete a group member, then retrieve the group from the database, 
       
   627 	// group.contactCount() is the same and group.getContacts() includes a 
       
   628 	// null entry where the deleted group member was.
       
   629 	CntTest->Db()->DeleteContactL(nestedGroupId);
       
   630 	CContactItem* newFamilyGroup  = CntTest->Db()->ReadContactLC(groupId);
       
   631 	CContactIdArray* newMemberArray = STATIC_CAST(CContactGroup*,newFamilyGroup )->ItemsContainedLC();
       
   632 	test(newMemberArray->Count()==0);		//fails
       
   633 	
       
   634 	CleanupStack::PopAndDestroy(9); 
       
   635 	// newGroup, nestedGroup, familyGroup memberArray newMemberArray newNestedGroup, newFamilyGroup  nestedMemberArray, groups
       
   636 	}
       
   637 
       
   638 
       
   639 
       
   640 
       
   641 // Helper function for RenameDefectL() below.  Sets a sort ordering for the database.
       
   642 //
       
   643 LOCAL_C void SetSortOrderL(CContactDatabase& aDb, TFieldType aFieldType)
       
   644 	{
       
   645 	CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
       
   646 	CleanupStack::PushL(sortOrder);
       
   647 	sortOrder->AppendL(CContactDatabase::TSortPref(aFieldType,CContactDatabase::TSortPref::EAsc));
       
   648 	aDb.SortL(sortOrder);
       
   649 	CleanupStack::Pop();	// sortOrder
       
   650 	}
       
   651 
       
   652 
       
   653 // This tests tries to reproduce defect 
       
   654 // EDNRTRN-4J5C5E "Groups in Cntmodel cannot be renamed.." 
       
   655 //
       
   656 // This defect was caused because groups weren't included in the view and
       
   657 // MoveInSortArrayL doesn't check that the contact item will be in the 
       
   658 // iSortedItems list (this list depends on the view chosen).
       
   659 //
       
   660 LOCAL_C void RenameDefectL()
       
   661 	{
       
   662 	test.Next(_L("Rename a group"));
       
   663 	CntTest->CloseDatabase();
       
   664 	CntTest->DeleteDatabaseL();
       
   665 
       
   666 	CContactDatabase* db=CntTest->CreateDatabaseL();
       
   667 	_LIT(KCntmodelOriginalName,"Original");
       
   668 	_LIT(KCntmodelRevisedName,"Revised");
       
   669 	CContactItem* newGroup = CntTest->Db()->CreateContactGroupLC(KCntmodelOriginalName);
       
   670 	TContactItemId groupId = newGroup->Id();
       
   671 	CleanupStack::PopAndDestroy(); //newGroup
       
   672 
       
   673 	TContactItemId contactA=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("a"));
       
   674 	TContactItemId contactB=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("b"));
       
   675 	CntTest->Db()->AddContactToGroupL(contactA,groupId);
       
   676 	CntTest->Db()->AddContactToGroupL(contactB,groupId);
       
   677 
       
   678 	CntTest->Db()->SetDbViewContactType(KUidContactCard);
       
   679 	CntTest->Db()->SortedItemsL(); // ensures theres a iSortedItems
       
   680 	SetSortOrderL(*db,TUid::Uid(KUidContactFieldDefinedTextValue));		// required so that the comparision 
       
   681 
       
   682 	CContactGroup* group = static_cast<CContactGroup*>(CntTest->Db()->OpenContactL(groupId));	
       
   683 	CleanupStack::PushL(group);
       
   684 	group->SetGroupLabelL(KCntmodelRevisedName);
       
   685 	CntTest->Db()->CommitContactL(*group);
       
   686 	CntTest->Db()->CloseContactL(groupId);
       
   687 	CleanupStack::PopAndDestroy(); //group
       
   688 
       
   689 	CContactItem* revisedGroup = CntTest->Db()->ReadContactLC(groupId,*CntTest->Db()->AllFieldsView());
       
   690 	TPtrC testLabel = static_cast<CContactGroup*>(revisedGroup)->GetGroupLabelL();
       
   691 	test(testLabel==KCntmodelRevisedName);
       
   692 	CleanupStack::PopAndDestroy(); //revisedGroup
       
   693 	}
       
   694 
       
   695 // This tests reproduces defect 
       
   696 // BET-4YDGB3 "Contacts crashes when creating two entries"
       
   697 //
       
   698 // This was caused because the CContactTables::ContactType() method uses the 
       
   699 // iCurrentIdInIdentityTable to determine which contact should be used to read 
       
   700 // the type information from. This member stores the last contact ID to be read 
       
   701 // from the identity table. However, since AddContactToGroupL() doesn't read any 
       
   702 // information from the identity table, the value set in iCurrentIdInIdentityTable 
       
   703 // should be set to KErrNotFound so that the correct contact from main CONTACTS table 
       
   704 // is used.
       
   705 //
       
   706 LOCAL_C void QuartzGroupDefectL()
       
   707 	{
       
   708 	test.Next(_L("Quartz defect"));
       
   709 	CntTest->CloseDatabase();
       
   710 	CntTest->DeleteDatabaseL();
       
   711 
       
   712 	CContactDatabase* db=CntTest->CreateDatabaseL();
       
   713 
       
   714 	_LIT(KCntmodelGroupAll,"All");
       
   715 	CContactItem* group = db->CreateContactGroupLC(KCntmodelGroupAll);
       
   716 	TContactItemId groupId = group->Id();
       
   717 	CleanupStack::PopAndDestroy(group); 
       
   718 	
       
   719 
       
   720 	CntTest->Db()->SetDbViewContactType(KUidContactCard);
       
   721 	CntTest->Db()->SortedItemsL(); // ensures theres a iSortedItems
       
   722 	SetSortOrderL(*db,TUid::Uid(KUidContactFieldDefinedTextValue));		// required so that the comparision 
       
   723 	
       
   724 	TContactItemId contactB=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("B"));
       
   725 	CntTest->Db()->AddContactToGroupL(contactB,groupId);
       
   726 	
       
   727 	TContactItemId contactA=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("A"));
       
   728 	CntTest->Db()->AddContactToGroupL(contactA,groupId);
       
   729 	}
       
   730 
       
   731 // Regression testcode for MAT-5B7JD4 "AddContactToGroupL()/RemoveContactFromGroupL() does not update 
       
   732 // object passed as argument"
       
   733 //
       
   734 LOCAL_C void GroupAddRemoveTestL()
       
   735 	{
       
   736 	test.Next(_L("Group addition/removal defect"));
       
   737 	CntTest->CloseDatabase();
       
   738 	CntTest->DeleteDatabaseL();
       
   739 	CContactDatabase* db=CntTest->CreateDatabaseL();
       
   740 
       
   741 	_LIT(KCntmodelGroup,"MyGroup");
       
   742 	CContactItem* group = db->CreateContactGroupLC(KCntmodelGroup);
       
   743 	TContactItemId groupId = group->Id();
       
   744 	
       
   745 	TContactItemId itemId=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("C"));
       
   746 	CContactItem* item = CntTest->Db()->ReadContactLC(itemId);
       
   747 
       
   748 	CntTest->Db()->AddContactToGroupL(*item,*group);
       
   749 	// write change to database
       
   750 	const CContactIdArray* groupsJoined = STATIC_CAST(CContactItemPlusGroup*,item)->GroupsJoined();
       
   751 	test(groupsJoined->Find(groupId)==0);
       
   752 	const CContactIdArray* itemsContained = STATIC_CAST(CContactGroup*,group)->ItemsContained();
       
   753 	test(itemsContained->Find(itemId)==0);
       
   754 	
       
   755 	CntTest->Db()->RemoveContactFromGroupL(*item,*group);
       
   756 	test(STATIC_CAST(CContactItemPlusGroup*,item)->GroupsJoined()->Find(groupId)!=0);
       
   757 	test(STATIC_CAST(CContactGroup*,group)->ItemsContained()->Find(itemId)!=0);
       
   758 
       
   759 	CleanupStack::PopAndDestroy(item);
       
   760 	CleanupStack::PopAndDestroy(group); 
       
   761 	}
       
   762 
       
   763 void CompareGroupListL(CCntClient& cntClient1, CCntClient& cntClient2)
       
   764 	{
       
   765 	CContactItem* group1 = NULL;
       
   766 	CContactItem* group2 = NULL;
       
   767 	CContactIdArray* ids1 = cntClient1.Db()->GetGroupIdListL();
       
   768 	CleanupStack::PushL(ids1);
       
   769 	CContactIdArray* ids2 = cntClient2.Db()->GetGroupIdListL();
       
   770 	CleanupStack::PushL(ids2);
       
   771 	TInt groupCount = ids1->Count();
       
   772 	test(cntClient1.Db()->GroupCount()==cntClient1.Db()->GroupCount());
       
   773 	for (TInt i=0;i<groupCount;i++)
       
   774 		{
       
   775 		group1 = cntClient1.Db()->ReadContactLC((*ids1)[groupCount-1]);
       
   776 		group2 = cntClient2.Db()->ReadContactLC((*ids2)[groupCount-1]);
       
   777 		test(group1->LastModified() == group2->LastModified());
       
   778 		test(group1->Id() == group2->Id());
       
   779 		test(group1->Type() == group2->Type());
       
   780 		CleanupStack::PopAndDestroy(2,group1);// group2
       
   781 		}
       
   782 	CleanupStack::PopAndDestroy(2,ids1);//ids2
       
   783 	}
       
   784 
       
   785 LOCAL_C void TestGroupNotificationsAndGroupIdListUpdateL()
       
   786 	{
       
   787 	test.Next(_L("Test for group addition notification for multifle clients (defect INC018191) "));
       
   788 	// Open DB from cntClient1
       
   789 	CCntClient* cntClient1 = new(ELeave) CCntClient(test,KDatabaseFileName);
       
   790 	CleanupStack::PushL(cntClient1);
       
   791 	cntClient1->CreateDatabaseL();
       
   792 		
       
   793 	// Open DB from cntClient2
       
   794 	CCntClient* cntClient2 = new(ELeave) CCntClient(test,KDatabaseFileName);
       
   795 	CleanupStack::PushL(cntClient2);								
       
   796 	cntClient2->OpenDatabaseL();
       
   797 	
       
   798 	// Check that no group is visible from both clients
       
   799 	CContactIdArray * ids1 = cntClient1->Db()->GetGroupIdListL();
       
   800 	CleanupStack::PushL(ids1);										
       
   801 	CContactIdArray * ids2 = cntClient2->Db()->GetGroupIdListL();
       
   802 	CleanupStack::PushL(ids2);	
       
   803 	test(ids1->Count()==0);
       
   804 	test(ids2->Count()==0);
       
   805 	CleanupStack::PopAndDestroy(2,ids1);// ids2 
       
   806 	ids1=NULL;
       
   807 	ids2=NULL;
       
   808 
       
   809 	// Create a group from the first client
       
   810 	TRAPD(err,CreateGroupFromAClientL(*cntClient1));	//start the Active Scheduler and then stop it in the event handler
       
   811 	test(err==KErrNone);
       
   812 
       
   813 	// Check that the newly added group can be seen by both clients and it is the same object  
       
   814 	test(cntClient1->Db()->GroupCount()==1);
       
   815 	test(cntClient2->Db()->GroupCount()==1);
       
   816 	CompareGroupListL(*cntClient1,*cntClient2);
       
   817 	
       
   818 	// Create a group from the second client
       
   819 	TRAP(err,CreateGroupFromAClientL(*cntClient2));		//start the Active Scheduler and then stop it in the event handler
       
   820 	test(err==KErrNone);
       
   821 
       
   822 	// Check that now 2 groups can be seen from both clients ..
       
   823 	CompareGroupListL(*cntClient1,*cntClient2);
       
   824 	test(cntClient1->Db()->GroupCount()==2);
       
   825 	test(cntClient2->Db()->GroupCount()==2);
       
   826 
       
   827 	// Now close the database from the two clients and re-open it from a third client
       
   828 	// and chech that there are still 2 groups 
       
   829 	cntClient1->CloseDatabase();
       
   830 	cntClient2->CloseDatabase();
       
   831 	
       
   832 	CleanupStack::PopAndDestroy(2,cntClient1);// cntClient1, cntClient2
       
   833 
       
   834 	CCntClient* cntClient3 = new(ELeave) CCntClient(test,KDatabaseFileName);
       
   835 	CleanupStack::PushL(cntClient3);								
       
   836 	cntClient3->OpenDatabaseL();
       
   837 	test(cntClient3->Db()->GroupCount()==2);
       
   838 	CleanupStack::PopAndDestroy(cntClient3);
       
   839 	cntClient3 = NULL;
       
   840 	}
       
   841 
       
   842 LOCAL_C void TestReadContactTextDefL() // Added to test changes made for DEF065476 and DEF065477
       
   843 	{
       
   844 	test.Next(_L("Testing ReadContactTextDef ( Defect DEF065476 and DEF065477 )"));
       
   845 	CntTest->CloseDatabase();
       
   846 	CntTest->DeleteDatabaseL();
       
   847 	CContactDatabase* db=CntTest->CreateDatabaseL();
       
   848 
       
   849 	_LIT(KContactGroup,"ContactGroup");
       
   850 	CContactItem* group = db->CreateContactGroupLC(KContactGroup);
       
   851 	TContactItemId groupId = group->Id();
       
   852 
       
   853 	TBuf<128> scratchBuf;
       
   854 	CntTest->Db()->ReadContactTextDefL(groupId, scratchBuf);
       
   855 	test(scratchBuf==KContactGroup);
       
   856 
       
   857 	test.Printf(_L("The Group name is %S\n"), &scratchBuf);
       
   858 
       
   859 	CleanupStack::PopAndDestroy(group); 
       
   860 	}
       
   861 	
       
   862 LOCAL_C void AsyncDbOpenFollowedByAddGroupL()
       
   863 	{
       
   864 	test.Next(_L("Async database open & group creating"));
       
   865 
       
   866 		
       
   867 	TRequestStatus requestStatus(0);
       
   868 	CContactOpenOperation* op = CContactDatabase::Open(KDatabaseFileName, requestStatus); 
       
   869 	// note: op doesn't have to be on CS
       
   870 	User::WaitForRequest(requestStatus);
       
   871 	CContactDatabase* database = op->TakeDatabase();
       
   872 	delete op;
       
   873 	CleanupStack::PushL(database);
       
   874 	
       
   875 	CContactItem* tempGroup = database->CreateContactGroupL(_L("New Group"));
       
   876 	delete tempGroup;
       
   877 	CleanupStack::PopAndDestroy(database);
       
   878 	}	
       
   879 
       
   880 //
       
   881 //
       
   882 //	MAIN DISPATCH MODULE
       
   883 //
       
   884 //
       
   885 
       
   886 /**
       
   887 
       
   888 @SYMTestCaseID     PIM-T-GROUPS-0001
       
   889 
       
   890 */
       
   891 
       
   892 void DoTestsL()
       
   893     {
       
   894 //	HAL::SetAutoSwitchOffBehavior(ESwitchOffDisabled);
       
   895 	test.Start(_L("@SYMTESTCaseID:PIM-T-GROUPS-0001 Create new database"));
       
   896 	TRAPD(err,CntTest->CreateDatabaseL());
       
   897 	test(err==KErrNone);
       
   898 	CntTest->CloseDatabase();
       
   899 	TRAP(err,CntTest->OpenDatabaseL());
       
   900 	test(err==KErrNone);
       
   901 	TRAP(err,CreateBasicContactGroups());
       
   902 	test(err==KErrNone);
       
   903 	TRAP(err,DeleteBasicContactGroups());
       
   904 	test(err==KErrNone);
       
   905 	TRAP(err,CheckBasicPopulatedGroup());
       
   906 	test(err==KErrNone);
       
   907 	TRAP(err,CheckRemoveMember());
       
   908 	test(err==KErrNone);
       
   909 	TRAP(err,CheckRemoveGroup());
       
   910 	test(err==KErrNone);
       
   911 	TRAP(err,CheckLargePopulatedGroup());
       
   912 	test(err==KErrNone);
       
   913 	TRAP(err,DeleteGroupMembersCheckPersist());
       
   914 	test(err==KErrNone);
       
   915 	TRAP(err,CreateManyGroups());
       
   916 	test(err==KErrNone);
       
   917 	TRAP(err,DeleteManyGroups());
       
   918 	test(err==KErrNone);
       
   919 	// error checking
       
   920 	TRAP(err,AddCardToCard());
       
   921 	test(err==KErrNotSupported);
       
   922 	TRAP(err,AddGroupToCard());
       
   923 	test(err==KErrNotSupported);
       
   924 	TRAP(err,AddBadCardToGroup());
       
   925 	test(err==KErrNotFound);
       
   926 	TRAP(err,AddCardToBadGroup());
       
   927 	test(err==KErrNotFound);
       
   928 	TRAP(err,AddCardToGroupTwice());
       
   929 	test(err==KErrNone);
       
   930 	TRAP(err,AddFieldToGroup());
       
   931 	test(err==KErrNone);
       
   932 	TRAP(err,SetGroupLabel());
       
   933 	test(err==KErrNone);
       
   934 	TRAP(err,ChangeGroupLabel());
       
   935 	test(err==KErrNone);
       
   936 	TRAP(err,CheckNestedGroup());
       
   937 	test(err==KErrNone);
       
   938 	TRAP(err,RenameDefectL());
       
   939 	test(err==KErrNone);
       
   940 	TRAP(err,QuartzGroupDefectL());
       
   941 	test(err==KErrNone);
       
   942 	TRAP(err,GroupAddRemoveTestL());
       
   943 	test(err==KErrNone);
       
   944 	TRAP(err, TestReadContactTextDefL());
       
   945 	test(err==KErrNone);
       
   946 	CntTest->CloseDatabase();
       
   947 	TRAP(err,TestGroupNotificationsAndGroupIdListUpdateL());	//Test case for defect INC018191
       
   948 	test(err==KErrNone);
       
   949 	TRAP(err, AsyncDbOpenFollowedByAddGroupL());
       
   950 	test(err==KErrNone);
       
   951 	test.Next(_L("Delete database"));
       
   952 	TRAP(err,CntTest->DeleteDatabaseL());
       
   953 	test(err==KErrNone);
       
   954     }
       
   955 
       
   956 GLDEF_C TInt E32Main()
       
   957 	{
       
   958 	__UHEAP_MARK;
       
   959     CntTest=new(ELeave) CCntTest;
       
   960 	CntTest->ConstructL(test,KDatabaseFileName);
       
   961     TRAPD(err,DoTestsL());
       
   962 	CntTest->EndTestLib(err);
       
   963 	__UHEAP_MARKEND;
       
   964 	return KErrNone;
       
   965     }