phonebookengines/contactsmodel/tsrc/t_cviewcontact.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2003-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 <s32mem.h>
       
    18 #include <cntdb.h>
       
    19 #include <cntviewbase.h>
       
    20 #include "T_UTILS.H"
       
    21 
       
    22 _LIT(KTestName,"T_CVIEWCONTACT");
       
    23 
       
    24 #ifdef SYMIAN_SECURE_DBMS
       
    25 _LIT(KDatabaseFileName,"C:\\T_CVIEWCONTACT");
       
    26 #else
       
    27 _LIT(KDatabaseFileName,"C:\\T_CVIEWCONTACT");
       
    28 #endif
       
    29 
       
    30 CCntTest* CntTest=NULL;
       
    31 LOCAL_D RTest test(KTestName);
       
    32 
       
    33 const TContactItemId KContactId = 5;
       
    34 const TContactItemId KModifiedContactId = 6;
       
    35 _LIT(KContactName,"ContactName");
       
    36 _LIT(KContactSurname,"ContactSurname");
       
    37 
       
    38 /** 
       
    39  * Test different construction methods.
       
    40  */
       
    41 LOCAL_C void TestConstructionL()
       
    42 	{
       
    43 	CViewContact* contact = CViewContact::NewLC(KContactId);
       
    44 
       
    45 	CViewContact* contact2 = CViewContact::NewL(*contact);
       
    46 	delete contact2;
       
    47 	CleanupStack::PopAndDestroy(contact);
       
    48 	}
       
    49 
       
    50 /** 
       
    51  * Test other CViewContact methods.
       
    52  */
       
    53 LOCAL_C void TestMiscMethodsL()
       
    54 	{
       
    55 	CViewContact* contact = CViewContact::NewLC(KContactId);
       
    56 	test(contact->Id()==KContactId);
       
    57 	contact->SetId(KModifiedContactId);
       
    58 	test(contact->Id()==KModifiedContactId);
       
    59 	contact->SetContactType(CViewContact::EContactItem);
       
    60 	test(contact->ContactType()==CViewContact::EContactItem);
       
    61 	contact->SetContactType(CViewContact::EGroup);
       
    62 	test(contact->ContactType()==CViewContact::EGroup);
       
    63 	CleanupStack::PopAndDestroy(contact);
       
    64 	}
       
    65 
       
    66 /** 
       
    67  * Test case 1
       
    68  * Add an empty Field when the existing iFieldTextBuf is empty
       
    69  * Action : Add an empty Field (i.e. length = 0) when the existing iFieldTextBuf is empty
       
    70  * Result : Empty field added
       
    71  */
       
    72 LOCAL_C void AddEmptyFieldL()
       
    73 	{
       
    74 	CViewContact* contact = CViewContact::NewLC(KContactId);
       
    75 	contact->AddFieldL(KNullDesC);
       
    76 	test(contact->FieldCount()==1);
       
    77 	test(contact->Field(0)==KNullDesC);
       
    78 	CleanupStack::PopAndDestroy(contact);
       
    79 	}
       
    80 
       
    81 /** 
       
    82  * Test case 2
       
    83  * Add an empty Field when the existing iFieldTextBuf is not empty 
       
    84  * Action : Add an empty Field (i.e. length = 0) when the existing iFieldTextBuf contains some fields already
       
    85  * Result : Empty field added
       
    86  */
       
    87 LOCAL_C void AddFieldL()
       
    88 	{
       
    89 	CViewContact* contact = CViewContact::NewLC(KContactId);
       
    90 	contact->AddFieldL(KContactName);
       
    91 	contact->AddFieldL(KContactSurname);
       
    92 	contact->AddFieldL(KNullDesC);
       
    93 	test(contact->FieldCount()==3);
       
    94 	test(contact->Field(0)==KContactName);
       
    95 	test(contact->Field(1)==KContactSurname);
       
    96 	test(contact->Field(2)==KNullDesC);
       
    97 	CleanupStack::PopAndDestroy(contact);
       
    98 	}
       
    99 
       
   100 /** 
       
   101  * Test case 3
       
   102  * Add an empty Field when OOM 
       
   103  * Action : Add an empty Field (i.e. length = 0) when OOM  
       
   104  * Result : Empty field added, iFieldTextBuf is unchanged
       
   105  */
       
   106 LOCAL_C void OomAddEmptyFieldL()
       
   107 	{
       
   108 	TInt ret=KErrNoMemory;
       
   109 	TInt failAt=0;	  
       
   110 	while (ret!=KErrNone)
       
   111 		{
       
   112 		failAt++;
       
   113 		__UHEAP_SETFAIL(RHeap::EDeterministic,failAt);
       
   114 		__UHEAP_MARK;			
       
   115 		TRAP(ret, AddEmptyFieldL());
       
   116 		if (ret!=KErrNone)
       
   117 			{
       
   118 			__UHEAP_MARKEND;
       
   119 			}
       
   120 		__UHEAP_RESET;
       
   121 		if (ret!=KErrNoMemory&&ret!=KErrNone)
       
   122 			{
       
   123 			test.Printf(_L("Non standard error: %d\n"),ret);
       
   124 			test.Getch();
       
   125 			}
       
   126 		test(ret==KErrNoMemory||ret==KErrNone);
       
   127 		}
       
   128 	}
       
   129 
       
   130 /**
       
   131 
       
   132 @SYMTestCaseID     PIM-T-CVIEWCONTACT-0001
       
   133 
       
   134 */
       
   135 
       
   136 LOCAL_C void DoTestsL()
       
   137     {
       
   138 	test.Start(_L("@SYMTESTCaseID:PIM-T-CVIEWCONTACT-0001 Tests for CViewContact"));
       
   139 
       
   140 	TestConstructionL();
       
   141 	TestMiscMethodsL();
       
   142 	AddFieldL();
       
   143 	AddEmptyFieldL();
       
   144 	OomAddEmptyFieldL();
       
   145 	}
       
   146 
       
   147 GLDEF_C TInt E32Main()
       
   148 	{
       
   149     CntTest=new(ELeave) CCntTest;
       
   150 	CntTest->ConstructL(test,KDatabaseFileName);
       
   151     TRAPD(err,DoTestsL());
       
   152 	CntTest->EndTestLib(err);
       
   153 	return KErrNone;
       
   154     }