phonebookengines/contactsmodel/tsrc/cntmodel2/T_CProgressNotification.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 #include "cntdb.h" 
       
    19 
       
    20 #include "T_CProgressNotification.h"
       
    21 
       
    22 /* 
       
    23 3 steps to create test
       
    24 ======================
       
    25 1	Derive from MContactUiCompactObserver
       
    26 2	Get an instance fo the activebase class via - CContactActiveCompress* CContactDatabase::CreateCompressorLC()
       
    27 3	Call CContactActiveCompress::SetObserver to recieve notifications
       
    28 */	
       
    29 
       
    30 _LIT(KTestDbName, "c:T_CProgressNotification.cdb");
       
    31 	
       
    32 void CProgressNotificationTest::AddContactsL(TInt aNoOfCnts)
       
    33 	{
       
    34 	TInt max = KMaxArraySize < aNoOfCnts ? KMaxArraySize : aNoOfCnts;
       
    35 	// Add contacts
       
    36 	CContactItem* cntItem = NULL;
       
    37 	for (TInt ii = 0; ii < max; ++ii)
       
    38 		{
       
    39 		cntItem = iCntItemBldr->GetCntItemLC();
       
    40 		iIDarray[ii] = iCntDb->AddNewContactL(*cntItem);
       
    41 		CleanupStack::PopAndDestroy(cntItem);
       
    42 		}
       
    43 	}
       
    44 	
       
    45 void CProgressNotificationTest::DeleteContactsL(TInt aNoOfCnts)
       
    46 	{
       
    47 	TInt max = KMaxArraySize < aNoOfCnts ? KMaxArraySize : aNoOfCnts;
       
    48 	//Remove the contacts
       
    49 	for (TInt ii = 0; ii < max; ++ii)
       
    50 		{
       
    51 		iCntDb->DeleteContactL(iIDarray[ii]);
       
    52 		iIDarray[ii] = 0;
       
    53 		}
       
    54 	}
       
    55 	
       
    56 	
       
    57 void CProgressNotificationTest::HandleError(TInt aError)
       
    58 	{
       
    59 	iTest->Printf(_L(" - Received Compress Recover ERROR code:  %d \r\n"), aError);
       
    60 	(*iTest)(EFalse); //Panic here
       
    61 	}
       
    62 
       
    63 	
       
    64 
       
    65 void CProgressNotificationTest::Step(TInt aStep)
       
    66 	{
       
    67 	iTest->Printf(_L(" - Recieved Compress/Recover Event - Step: %d \r\n"), aStep);
       
    68 	iSteps = aStep;
       
    69 
       
    70 	if(aStep > 0 && iActiveCompress != NULL) 
       
    71 		{
       
    72 		if(!(iActiveCompress->StepsTogo() > 0 ))
       
    73 			{
       
    74 			iTest->Printf(_L(" ---- *****ERROR**** Compress Test Error - StepsTogo should be greater than zero \r\n"));
       
    75 			(*iTest)(EFalse); //Panic here
       
    76 			}
       
    77 		}
       
    78 	}
       
    79 	
       
    80 
       
    81 void CProgressNotificationTest::RunCompressNotifyTestL()
       
    82 	{
       
    83   	iTest->Start(_L("Compress Test"));
       
    84 
       
    85 	if (iActiveCompress)
       
    86 		delete iActiveCompress;
       
    87 	iActiveCompress = iCntDb->CreateCompressorLC();
       
    88 	CleanupStack::Pop(iActiveCompress);
       
    89 	
       
    90 	// check if first step is greater than 0; CreateCompressorLC should have started the compression
       
    91 	if(!(iActiveCompress->StepsTogo() > 0 ))
       
    92 		{
       
    93 		iTest->Printf(_L(" ---- *****ERROR**** Compress Test Error - StepsTogo should be greater than zero \r\n"));
       
    94 		(*iTest)(EFalse); //Panic here
       
    95 		}
       
    96 
       
    97 	iActiveCompress->SetObserver(static_cast<MContactUiCompactObserver*>(this));
       
    98 	while(iActiveCompress->Step()) {};
       
    99 	
       
   100 	iTest->End(); //If we are here test completed with success
       
   101 	}
       
   102 	
       
   103 	
       
   104 void CProgressNotificationTest::RunCompressNotifyCancelTestL()	
       
   105 	{
       
   106   	iTest->Start(_L("Compress CANCEL Test"));
       
   107 
       
   108 	if (iActiveCompress)
       
   109 		delete iActiveCompress;
       
   110 	iActiveCompress = iCntDb->CreateCompressorLC();
       
   111 	CleanupStack::Pop(iActiveCompress);
       
   112 	
       
   113 	iActiveCompress->SetObserver(static_cast<MContactUiCompactObserver*>(this));
       
   114 	iActiveCompress->Step();
       
   115 	TInt halfSteps = iSteps/2;
       
   116 	
       
   117 	while (iSteps > halfSteps)
       
   118 		{
       
   119 		iActiveCompress->Step();
       
   120 		}
       
   121 
       
   122 	delete iActiveCompress;
       
   123 	iActiveCompress = NULL;
       
   124 	
       
   125 	iTest->End(); //If we are here test completed with success
       
   126 	}
       
   127 	
       
   128 	
       
   129 void CProgressNotificationTest::RunRecoverNotifyCancelTestL()
       
   130 	{
       
   131 	iTest->Start(_L("Recover CANCEL Test"));
       
   132 	
       
   133 	iCntDb->DamageDatabaseL(0x666);
       
   134 	
       
   135 	if (iCntDb->IsDamaged() == EFalse)
       
   136 		{
       
   137 		iTest->Printf(_L(" ---- DATABASE IS NOT DAMAGED For Test ---- \r\n"));	
       
   138 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__		
       
   139 		(*iTest)(EFalse); //Panic here
       
   140 #else
       
   141 		return;  // test has no meaning with SQLite
       
   142 #endif		
       
   143 		}
       
   144 	
       
   145 	if (iActiveRecover)
       
   146 		delete iActiveRecover;
       
   147 	iActiveRecover = iCntDb->CreateRecoverLC();
       
   148 	CleanupStack::Pop(iActiveRecover);
       
   149 	
       
   150 	iActiveRecover->SetObserver(static_cast<MContactUiCompactObserver*>(this));
       
   151 	
       
   152 	//do only one step
       
   153 	iActiveRecover->Step();
       
   154 	
       
   155 	if (iCntDb->IsDamaged() == EFalse)
       
   156 		{
       
   157 		iTest->Printf(_L(" ---- DATABASE IS NOT DAMAGED For Test ---- \r\n"));	
       
   158 		(*iTest)(EFalse); //Panic here
       
   159 		}
       
   160 		
       
   161 	TRAPD(err, AddContactsL(1));
       
   162 	if(err == KErrNone)
       
   163 		{
       
   164 		iTest->Printf(_L(" ---- *****ERROR**** recover cancellation does not works ---- \r\n"));	
       
   165 		(*iTest)(EFalse); //Panic here
       
   166 		}
       
   167 
       
   168 	//recover stop in destructor
       
   169 	delete iActiveRecover;
       
   170 	iActiveRecover = NULL;	
       
   171 	
       
   172 	iCntDb->RecoverL();
       
   173 	
       
   174 	iTest->End(); //If we are here test completed with success
       
   175 	}
       
   176 
       
   177 	
       
   178 void CProgressNotificationTest::RunRecoverNotifyTestL()
       
   179 	{
       
   180 	iTest->Start(_L("Recover Test"));
       
   181 	
       
   182 	iCntDb->DamageDatabaseL(0x666);
       
   183 	if (iCntDb->IsDamaged())
       
   184 		{
       
   185 		iTest->Printf(_L(" ---- DATABASE IS DAMAGED ---- \r\n"));	
       
   186 		}
       
   187 	
       
   188   	if (iActiveRecover)
       
   189 		delete iActiveRecover;
       
   190 	iActiveRecover = iCntDb->CreateRecoverLC();
       
   191 	CleanupStack::Pop(iActiveRecover);
       
   192 	
       
   193 	iActiveRecover->SetObserver(static_cast<MContactUiCompactObserver*>(this));
       
   194 	while(iActiveRecover->Step()) {};	
       
   195 	
       
   196 	if (iCntDb->IsDamaged())
       
   197 		{
       
   198 		iTest->Printf(_L(" ----*****ERROR**** DATABASE IS STILL DAMAGED ---- \r\n"));	
       
   199 		(*iTest)(EFalse); //Panic here
       
   200 		}
       
   201 		
       
   202 	iTest->End(); //If we are here test completed with success
       
   203 	}
       
   204 
       
   205 	
       
   206 CProgressNotificationTest* CProgressNotificationTest::NewLC()
       
   207 	{
       
   208 	CProgressNotificationTest* self = new (ELeave) CProgressNotificationTest();
       
   209 	CleanupStack::PushL(self);
       
   210 	self->ConstructL();
       
   211 	return self;		
       
   212 	}
       
   213 	
       
   214 CProgressNotificationTest::CProgressNotificationTest()
       
   215 	{}
       
   216 	
       
   217 
       
   218 void CProgressNotificationTest::ConstructL()
       
   219 	{
       
   220 	// For multi-threaded test harness.
       
   221 	iTest = new(ELeave) RTest(_L(""));
       
   222 
       
   223 	iCntDb = CContactDatabase::ReplaceL(KTestDbName); // Default Database.
       
   224 	const CContactTemplate& sysTempl(GetSysTemplateL() );
       
   225 	iCntItemBldr = CCntItemBuilder::NewLC(sysTempl);
       
   226 	CleanupStack::Pop(iCntItemBldr);
       
   227 	}
       
   228 
       
   229 CProgressNotificationTest::~CProgressNotificationTest()
       
   230 	{
       
   231 	iTest->Close();
       
   232 	delete iTest;
       
   233 	
       
   234 	delete iCntDb;
       
   235 	delete iGoldenTemplate;
       
   236 	delete iCntItemBldr;
       
   237 
       
   238 	delete iActiveCompress;
       
   239 	delete iActiveRecover;
       
   240 	TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KTestDbName));
       
   241 	}
       
   242 
       
   243 const CContactTemplate& CProgressNotificationTest::GetSysTemplateL()
       
   244 	{
       
   245 	if (!iGoldenTemplate)
       
   246 		{
       
   247 		CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
       
   248 		matchAll->AddL(KUidContactFieldMatchAll);
       
   249 
       
   250 		iGoldenTemplate = static_cast<CContactTemplate*>(iCntDb->ReadContactL(iCntDb->TemplateId(), *matchAll));
       
   251 		CleanupStack::PopAndDestroy(matchAll);
       
   252 		}
       
   253 	return *iGoldenTemplate;
       
   254 	} 
       
   255   	
       
   256