phonebookengines/contactsmodel/tsrc/cntmodel2/T_TemplateCache.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2005-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 #include <e32test.h>
       
    18 
       
    19 _LIT(KTestName, "T_TemplateCache Test"); // Used by Testhelper - gives an warning under ARMv5
       
    20 
       
    21 
       
    22 #include "..\..\..\CntServer2\Client\inc\rcntmodel.h"
       
    23 #include <NbCntTestLib.h>
       
    24 #include <CNTDEF.H>
       
    25 #include <cntitem.h>
       
    26 
       
    27 #include "testhelpers.h"
       
    28 #include "CContactPrivate.h"
       
    29 
       
    30 /**
       
    31 
       
    32 @SYMTestCaseID     PIM-T-TEMPLATECACHE-0001
       
    33 
       
    34 */
       
    35 
       
    36 LOCAL_C void DoTestsL()
       
    37 	{
       
    38     CleanupClosePushL(test);
       
    39 	test.Start(_L("@SYMTESTCaseID:PIM-T-TEMPLATECACHE-0001 ----------- State Tests ----------"));
       
    40 
       
    41 
       
    42    	__UHEAP_MARK;
       
    43 
       
    44 	RCntModel cntClient; 
       
    45 	cntClient.ConnectL();
       
    46 	cntClient.OpenDatabase();
       
    47 	
       
    48 	CCntTemplateCache* templateCache = CCntTemplateCache::NewL(cntClient);
       
    49 	CleanupStack::PushL(templateCache);
       
    50 	
       
    51 	CContactIdArray* cardTemplateIds = CContactIdArray::NewLC();
       
    52 	// Add 15 templates
       
    53 	CContactTemplate* contactTemplate = NULL;
       
    54 	TInt ii = 0;
       
    55 	for (; ii < 15; ++ii)
       
    56 		{
       
    57 		contactTemplate = CContactTemplate::NewLC();
       
    58 		cardTemplateIds->AddL(cntClient.CreateContactL(*contactTemplate));
       
    59 		CleanupStack::PopAndDestroy(); // contactTemplate
       
    60 		}
       
    61 		
       
    62 	// Create a contactItem
       
    63 	CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(templateCache->SystemTemplateL()));
       
    64 	CContactItem* cntItem 		 = cntItemBldr->GetCntItemLC();
       
    65 	/*TContactItemId cntId  		 = */cntClient.CreateContactL(*cntItem);
       
    66 
       
    67 	ii = 0;
       
    68 	for (; ii < 15; ++ii)
       
    69 		{
       
    70 		cntItem->SetTemplateRefId((*cardTemplateIds)[ii]);
       
    71 		templateCache->MergeWithTemplateL(*cntItem);
       
    72 		// Merge a second time... the template should now be cached
       
    73 		templateCache->MergeWithTemplateL(*cntItem);
       
    74 		}
       
    75 	
       
    76 	
       
    77 	CleanupStack::PopAndDestroy(cntItem);
       
    78 	CleanupStack::PopAndDestroy(cntItemBldr);
       
    79 	CleanupStack::PopAndDestroy(cardTemplateIds);
       
    80 	CleanupStack::PopAndDestroy(templateCache);
       
    81 	cntClient.Close();
       
    82 	
       
    83 	__UHEAP_MARKEND;
       
    84 
       
    85   	test.Next(_L("---- All Tests Completed OK ----"));
       
    86 
       
    87 
       
    88 	test.End();
       
    89     CleanupStack::PopAndDestroy(1); // test.Close
       
    90 	}
       
    91 
       
    92 
       
    93 
       
    94 GLDEF_C TInt E32Main()
       
    95 	{
       
    96     // Init
       
    97     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
    98   	if (!cleanupStack)
       
    99       return KErrNoMemory;
       
   100         
       
   101     CActiveScheduler* activeScheduler = new CActiveScheduler;
       
   102     if (!activeScheduler)
       
   103         return KErrNoMemory;
       
   104     CActiveScheduler::Install(activeScheduler);
       
   105 
       
   106     // Run the tests
       
   107     __UHEAP_MARK;
       
   108     TRAPD(err, DoTestsL());
       
   109     __UHEAP_MARKEND;
       
   110 
       
   111 	test(__NB_failures == 0);
       
   112 		
       
   113     // Cleanup
       
   114     delete activeScheduler;
       
   115  	delete cleanupStack;
       
   116 	activeScheduler = NULL;
       
   117 	cleanupStack = NULL;
       
   118 	
       
   119 	return err;
       
   120     }