pimappservices/calendar/tsrc/TestCalIndexFile/src/TestCalIndexFileDeleteAllStep.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 #include "TestCalIndexFileDeleteAllStep.h"
       
    17 #include "TestCalIndexFileDefs.h"
       
    18 #include <fbs.h>
       
    19 #include <e32math.h>
       
    20 #include <calcategory.h>
       
    21 #include <caldataexchange.h>
       
    22 #include <caldataformat.h>
       
    23 #include <calsession.h>
       
    24 #include <s32file.h>
       
    25 #include <calinstance.h>
       
    26 #include <calinstanceview.h>
       
    27 #include "caltestlib.h"
       
    28 
       
    29 CTestCalIndexFileDeleteAllStep::~CTestCalIndexFileDeleteAllStep()
       
    30 /**
       
    31  * Destructor
       
    32  */
       
    33 	{
       
    34 	}
       
    35 
       
    36 CTestCalIndexFileDeleteAllStep::CTestCalIndexFileDeleteAllStep()
       
    37 /**
       
    38  * Constructor
       
    39  */
       
    40 	{
       
    41 	SetTestStepName(KTestCalIndexFileDeleteAllStep);
       
    42 	}
       
    43 
       
    44 TVerdict CTestCalIndexFileDeleteAllStep::doTestStepPostambleL()
       
    45 	{
       
    46 	return TestStepResult();
       
    47 	}
       
    48 
       
    49 TVerdict CTestCalIndexFileDeleteAllStep::doTestStepL()
       
    50 	{
       
    51 	// this method assumes a pass. Checks that fail will stop
       
    52 	// the test step
       
    53 	
       
    54 	SetUpCalDirL();
       
    55 	
       
    56 	AddCalendarFileL();
       
    57 	AddIndexFileL();
       
    58 	OpenAgendaL();
       
    59 	
       
    60 	// use the base class version of ValidateDbContentsL as 
       
    61 	// we have not deleted the entries yet
       
    62 	if (!CTestCalIndexFileStepBase::ValidateDbContentsL())
       
    63 		{
       
    64 		INFO_PRINTF1(_L("Delete Entry Step Failed validating DB contents before entry deletion"));
       
    65 		CloseAgendaL();
       
    66 		SetTestStepResult(EFail);
       
    67 		return EFail;
       
    68 		}
       
    69 		
       
    70 	DeleteAllEntriesL();
       
    71 	// The index file should be deleted as it is now out of date.
       
    72 	// It will be rebuilt when the session closes.
       
    73 	if (CheckIndexFilePresentL())
       
    74 		{
       
    75 		INFO_PRINTF1(_L("Delete All Step Failed - index file present when dirty"));
       
    76 		CloseAgendaL();
       
    77 		SetTestStepResult(EFail);
       
    78 		return EFail;
       
    79 		}
       
    80 		
       
    81 	CloseAgendaL();
       
    82 	if (!CheckIndexFilePresentL())
       
    83 		{
       
    84 		INFO_PRINTF1(_L("Delete All Step Failed - no index file created after delete and close"));
       
    85 		SetTestStepResult(EFail);
       
    86 		return EFail;
       
    87 		}
       
    88 		
       
    89 	// make sure there are no entries is left
       
    90 	OpenAgendaL();
       
    91 	if (!ValidateDbContentsL())
       
    92 		{
       
    93 		INFO_PRINTF1(_L("Delete All Step Failed validating DB contents after deletion"));
       
    94 		CloseAgendaL();
       
    95 		SetTestStepResult(EFail);
       
    96 		return EFail;
       
    97 		}	
       
    98 	CloseAgendaL();
       
    99 
       
   100 	SetTestStepResult(EPass);
       
   101 	return EPass;
       
   102 	}
       
   103 
       
   104 
       
   105 
       
   106 void CTestCalIndexFileDeleteAllStep::DeleteAllEntriesL()
       
   107 	{
       
   108 	
       
   109 
       
   110 	INFO_PRINTF1(_L("enter CTestCalIndexFileDeleteAllStep::DeleteAllEntriesL()"));
       
   111 	// for each entry in the database validate ALL relevant
       
   112 	// fields against info for the entry in the ini file
       
   113 	TInt numEntries;
       
   114 	TBool readRes = EFalse;
       
   115 	readRes = GetIntFromConfig(ConfigSection(),KTCINumEntries, numEntries);
       
   116 	if (!readRes)
       
   117 		{
       
   118 		INFO_PRINTF1(_L("Error in CTestCalIndexFileStepBase::ValidateDbContentsL - numentriespresent not found in config file"));
       
   119 		User::Leave(KErrNotFound);
       
   120 		}
       
   121 	
       
   122 	if (numEntries == 0)
       
   123 		{
       
   124 		return;
       
   125 		}
       
   126 	
       
   127 	RPointerArray<CConfigTestEntryInfo> entriesInfo;	
       
   128 	CleanupResetAndDestroyPushL(entriesInfo);	
       
   129 
       
   130 	GetEntryInfoFromConfigL(entriesInfo, numEntries, EFalse);
       
   131 			
       
   132 	// for each entry in the list of entries, see if we can find a 
       
   133 	// match in the database using an instance view
       
   134 	for (TInt j = 0; j < numEntries; j++)
       
   135 		{
       
   136 		INFO_PRINTF2(_L("Trying to validate entry info - %d"),(j+1));
       
   137 		CConfigTestEntryInfo* infoToUse = entriesInfo[j];
       
   138 		
       
   139 		CCalProgress* progress = new(ELeave)CCalProgress;
       
   140 		CleanupStack::PushL(progress);  //1
       
   141 	
       
   142 		CCalInstanceView* view = CCalInstanceView::NewL(*iSession, *progress);
       
   143 		CleanupStack::PushL(view); //2
       
   144 		
       
   145 		CActiveScheduler::Start();
       
   146 		
       
   147 		CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts;
       
   148 		switch (infoToUse->iType)
       
   149 			{
       
   150 			case (CCalEntry::EAppt):
       
   151 				filter = CalCommon::EIncludeAppts;
       
   152 				break;
       
   153 			case (CCalEntry::ETodo):
       
   154 				filter = CalCommon::EIncludeCompletedTodos | CalCommon::EIncludeIncompletedTodos;
       
   155 				break;
       
   156 			case (CCalEntry::EEvent):
       
   157 				filter = CalCommon::EIncludeEvents;
       
   158 				break;
       
   159 			case (CCalEntry::EReminder):
       
   160 				filter = CalCommon::EIncludeReminder;
       
   161 				break;
       
   162 			case (CCalEntry::EAnniv):
       
   163 				filter = CalCommon::EIncludeAnnivs;
       
   164 				break;
       
   165 			default:
       
   166 				User::Leave(KErrCorrupt);
       
   167 				break;
       
   168 			}
       
   169 		RPointerArray<CCalInstance> instances;
       
   170 		CleanupClosePushL (instances);
       
   171 				
       
   172 		// look for instances between (startdate -1 day) and
       
   173 		// (enddate + 1 day)
       
   174 		TTimeIntervalDays oneDay(1);
       
   175 		TTime beginTTime = (infoToUse->iStartTime) - oneDay;
       
   176 		TTime endTTime = (infoToUse->iEndTime) + oneDay;
       
   177 		TCalTime begin;
       
   178 		begin.SetTimeUtcL(beginTTime);
       
   179 		TCalTime end;
       
   180 		end.SetTimeUtcL(endTTime);
       
   181 		CalCommon::TCalTimeRange timerange(begin, end);	
       
   182 		
       
   183 		view->FindInstanceL(instances, filter, timerange);
       
   184 		
       
   185 		TInt count = instances.Count();
       
   186 		for (TInt i = 0 ; i < count; i++)
       
   187 			{
       
   188 			TRAP_IGNORE(view->DeleteL(instances[i], CalCommon::EThisAndAll));
       
   189 			}
       
   190 
       
   191 		CleanupStack::PopAndDestroy(&instances);
       
   192 		CleanupStack::PopAndDestroy(view);
       
   193 		CleanupStack::PopAndDestroy(progress);
       
   194 		
       
   195 		}
       
   196 	CleanupStack::PopAndDestroy(&entriesInfo);
       
   197 	INFO_PRINTF1(_L("exit CTestCalIndexFileDeleteAllStep::DeleteAllEntriesL()"));	
       
   198 	}
       
   199 	
       
   200 TBool CTestCalIndexFileDeleteAllStep::ValidateDbContentsL()
       
   201 	{
       
   202 	CCalProgress* progress = new(ELeave)CCalProgress;
       
   203 	CleanupStack::PushL(progress);  //1
       
   204 
       
   205 	CCalInstanceView* view = CCalInstanceView::NewL(*iSession, *progress);
       
   206 	CleanupStack::PushL(view); //2
       
   207 	
       
   208 	CActiveScheduler::Start();
       
   209 	
       
   210 	CalCommon::TCalViewFilter filter = CalCommon::EIncludeAll;
       
   211 	RPointerArray<CCalInstance> instances;
       
   212 	CleanupResetAndDestroyPushL(instances);
       
   213 		
       
   214 	// Safe to look for everything since DB should be empty
       
   215 	TCalTime begin;
       
   216 	begin.SetTimeUtcL(TCalTime::MinTime());
       
   217 	TCalTime end;
       
   218 	end.SetTimeUtcL(TCalTime::MaxTime());
       
   219 	CalCommon::TCalTimeRange timerange(begin, end);	
       
   220 	
       
   221 	view->FindInstanceL(instances, filter, timerange);
       
   222 	
       
   223 	if (instances.Count() != 0)
       
   224 		{
       
   225 		INFO_PRINTF2(_L("CTestCalIndexFileDeleteAllStep::ValidateDbContentsL found %d entries"), instances.Count());
       
   226 		User::Leave(KErrGeneral);
       
   227 		}
       
   228 	CleanupStack::PopAndDestroy(&instances);
       
   229 	CleanupStack::PopAndDestroy(view);
       
   230 	CleanupStack::PopAndDestroy(progress);
       
   231 
       
   232 	return ETrue;
       
   233 	}