pimappservices/calendar/tsrc/TestCalIndexFile/src/TestCalIndexFileModifyEntryStep.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 "TestCalIndexFileModifyEntryStep.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 <calentry.h>
       
    28 #include <calentryview.h>
       
    29 #include "caltestlib.h"
       
    30 
       
    31 
       
    32 CTestCalIndexFileModifyEntryStep::~CTestCalIndexFileModifyEntryStep()
       
    33 /**
       
    34  * Destructor
       
    35  */
       
    36 	{
       
    37 	}
       
    38 
       
    39 CTestCalIndexFileModifyEntryStep::CTestCalIndexFileModifyEntryStep()
       
    40 /**
       
    41  * Constructor
       
    42  */
       
    43 	{
       
    44 	SetTestStepName(KTestCalIndexFileModifyEntryStep);
       
    45 	}
       
    46 
       
    47 TVerdict CTestCalIndexFileModifyEntryStep::doTestStepPostambleL()
       
    48 	{
       
    49 	return TestStepResult();
       
    50 	}
       
    51 
       
    52 TVerdict CTestCalIndexFileModifyEntryStep::doTestStepL()
       
    53 	{
       
    54 	// this method assumes a pass. Checks that fail will stop
       
    55 	// the test step
       
    56 	
       
    57 	SetUpCalDirL();
       
    58 	
       
    59 	AddCalendarFileL();
       
    60 	AddIndexFileL();
       
    61 	OpenAgendaL();
       
    62 	
       
    63 	// use the base class version of ValidateDbContentsL as 
       
    64 	// we have not deleted the entry yet
       
    65 	if (!CTestCalIndexFileStepBase::ValidateDbContentsL())
       
    66 		{
       
    67 		INFO_PRINTF1(_L("Modify Entry Step Failed validating DB contents before entry modification"));
       
    68 		CloseAgendaL();
       
    69 		SetTestStepResult(EFail);
       
    70 		return EFail;
       
    71 		}
       
    72 		
       
    73 	ModifyEntryL();
       
    74 	// The index file should be deleted as it is now out of date.
       
    75 	// It will be rebuilt when the session closes.
       
    76 	if (CheckIndexFilePresentL())
       
    77 		{
       
    78 		INFO_PRINTF1(_L("Modify Entry Step Failed - index file present when dirty"));
       
    79 		CloseAgendaL();
       
    80 		SetTestStepResult(EFail);
       
    81 		return EFail;
       
    82 		}
       
    83 		
       
    84 	CloseAgendaL();
       
    85 	if (!CheckIndexFilePresentL())
       
    86 		{
       
    87 		INFO_PRINTF1(_L("Modify Entry Step Failed - no index file created after modify and close"));
       
    88 		SetTestStepResult(EFail);
       
    89 		return EFail;
       
    90 		}
       
    91 		
       
    92 	// make sure the added entry is still there
       
    93 	OpenAgendaL();
       
    94 	if (!ValidateDbContentsL())
       
    95 		{
       
    96 		INFO_PRINTF1(_L("Modify Entry Step Failed validating DB contents after modification"));
       
    97 		CloseAgendaL();
       
    98 		SetTestStepResult(EFail);
       
    99 		return EFail;
       
   100 		}	
       
   101 	CloseAgendaL();
       
   102 
       
   103 	SetTestStepResult(EPass);
       
   104 	return EPass;
       
   105 	}
       
   106 
       
   107 void CTestCalIndexFileModifyEntryStep::ModifyEntryL()
       
   108 	{
       
   109 	TPtrC entryString;
       
   110 	TBool readRes = EFalse;
       
   111 	readRes = GetStringFromConfig(ConfigSection(), KModifyEntry, entryString);
       
   112 	if (!readRes)
       
   113 		{
       
   114 		INFO_PRINTF1(_L("Error in CTestCalIndexFileModifyEntryStep::ModifyEntryL - entrytomodify not found in config file"));
       
   115 		User::Leave(KErrNotFound);
       
   116 		}
       
   117 	CConfigTestEntryInfo* inf = new(ELeave)CConfigTestEntryInfo();
       
   118 	CleanupStack::PushL(inf);
       
   119 	ParseEntryStringL(*inf, entryString);
       
   120 				
       
   121 	//  see if we can find a match in the database using an instance view
       
   122 		
       
   123 		CCalProgress* progress = new(ELeave)CCalProgress;
       
   124 		CleanupStack::PushL(progress);  
       
   125 	
       
   126 		CCalInstanceView* view = CCalInstanceView::NewL(*iSession, *progress);
       
   127 		CleanupStack::PushL(view);
       
   128 		
       
   129 		CActiveScheduler::Start();
       
   130 		
       
   131 		CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts;
       
   132 		switch (inf->iType)
       
   133 			{
       
   134 			case (CCalEntry::EAppt):
       
   135 				filter = CalCommon::EIncludeAppts;
       
   136 				break;
       
   137 			case (CCalEntry::ETodo):
       
   138 				filter = CalCommon::EIncludeCompletedTodos | CalCommon::EIncludeIncompletedTodos;
       
   139 				break;
       
   140 			case (CCalEntry::EEvent):
       
   141 				filter = CalCommon::EIncludeEvents;
       
   142 				break;
       
   143 			case (CCalEntry::EReminder):
       
   144 				filter = CalCommon::EIncludeReminder;
       
   145 				break;
       
   146 			case (CCalEntry::EAnniv):
       
   147 				filter = CalCommon::EIncludeAnnivs;
       
   148 				break;
       
   149 			default:
       
   150 				User::Leave(KErrCorrupt);
       
   151 				break;
       
   152 			}
       
   153 		RPointerArray<CCalInstance> instances;
       
   154 		CleanupClosePushL(instances);
       
   155 
       
   156 		// look for instances between (startdate -1 day) and
       
   157 		// (enddate + 1 day)
       
   158 		TTimeIntervalDays oneDay(1);
       
   159 		TTime beginTTime = (inf->iStartTime) - oneDay;
       
   160 		TTime endTTime = (inf->iEndTime) + oneDay;
       
   161 		TCalTime begin;
       
   162 		begin.SetTimeUtcL(beginTTime);
       
   163 		TCalTime end;
       
   164 		end.SetTimeUtcL(endTTime);
       
   165 		CalCommon::TCalTimeRange timerange(begin, end);	
       
   166 		
       
   167 		view->FindInstanceL(instances, filter, timerange);
       
   168 		
       
   169 		TInt counter = 0;
       
   170 		TInt max = instances.Count();
       
   171 		INFO_PRINTF2(_L("%d instances to compare against"),max);
       
   172 		TBool found = EFalse;
       
   173 		while ((found == EFalse) && (counter < max))
       
   174 			{
       
   175 			INFO_PRINTF2(_L("compare modify info to entry %d"), (counter+1));
       
   176 			if (inf->CompareToEntryL((instances[counter])->Entry()))
       
   177 				{
       
   178 				INFO_PRINTF2(_L("Entry info matched instance %d"), (counter+1));
       
   179 				found = ETrue;
       
   180 				
       
   181 				CCalProgress* progress1 = new(ELeave)CCalProgress;
       
   182 				CleanupStack::PushL(progress1);  
       
   183 				
       
   184 				CCalEntryView* eView = CCalEntryView::NewL(*iSession, *progress);
       
   185 				CleanupStack::PushL(eView);
       
   186 				
       
   187 				CActiveScheduler::Start();
       
   188 
       
   189 				CCalEntry* eEntry = &((instances[counter])->Entry());
       
   190 				eEntry->SetDescriptionL(KTCIModifiedText());
       
   191 				RPointerArray<CCalEntry> eList;
       
   192 				CleanupResetAndDestroyPushL(eList);
       
   193 				eList.Reset();
       
   194 				TInt numChanged = 0;
       
   195 				eList.Append(eEntry);
       
   196 				eView->UpdateL(eList, numChanged);
       
   197 				if (numChanged != 1)
       
   198 					{
       
   199 					INFO_PRINTF1(_L("Error modifiying entry"));
       
   200 					User::Leave(KErrGeneral);
       
   201 					}
       
   202 				CleanupStack::PopAndDestroy(&eList);
       
   203 				CleanupStack::PopAndDestroy(2);
       
   204 				}
       
   205 			else
       
   206 				{
       
   207 				counter++;
       
   208 				}
       
   209 			}
       
   210 		CleanupStack::PopAndDestroy(&instances);
       
   211 		CleanupStack::PopAndDestroy(view);
       
   212 		CleanupStack::PopAndDestroy(progress);
       
   213 	
       
   214 	CleanupStack::PopAndDestroy(inf);
       
   215 	
       
   216 	if (!found)
       
   217 		{
       
   218 		INFO_PRINTF1(_L("Could not find entrytomodify in database"));
       
   219 		User::Leave(KErrNotFound);
       
   220 		}
       
   221 	}
       
   222 	
       
   223 
       
   224 void CTestCalIndexFileModifyEntryStep::GetEntryInfoFromConfigL(RPointerArray<CConfigTestEntryInfo>& aEntriesInfo, TInt& aNumEntries, TBool aPerformCrudOps)
       
   225 	{
       
   226 	// first get the default entries from the file
       
   227 	CTestCalIndexFileStepBase::GetEntryInfoFromConfigL(aEntriesInfo, aNumEntries, aPerformCrudOps);
       
   228 	
       
   229 	if (aPerformCrudOps)
       
   230 		{
       
   231 		TInt entryToMod;
       
   232 		TBool readRes = EFalse;
       
   233 		readRes = GetIntFromConfig(ConfigSection(), KNumModifyEntry, entryToMod);
       
   234 		if (!readRes)
       
   235 			{
       
   236 			INFO_PRINTF1(_L("Error in CTestCalIndexFileModifyEntryStep::GetEntryInfoFromConfigL - entrynumtomodify not found in config file"));
       
   237 			User::Leave(KErrNotFound);
       
   238 			}
       
   239 			
       
   240 		if (entryToMod >= aNumEntries)
       
   241 			{
       
   242 			INFO_PRINTF1(_L("Error in CTestCalIndexFileDeleteEntryStep::GetEntryInfoFromConfigL - entrynumtomodify too big"));
       
   243 			User::Leave(KErrTooBig);
       
   244 			}
       
   245 
       
   246 		iEntryNumToMod = entryToMod-1;
       
   247 		CConfigTestEntryInfo* entryInfo = aEntriesInfo[iEntryNumToMod];
       
   248 		
       
   249 		TInt len = KTCIModifiedText().Length();
       
   250 		if (entryInfo->iDescription)
       
   251 			{
       
   252 			delete entryInfo->iDescription;
       
   253 			entryInfo->iDescription = NULL;
       
   254 			}
       
   255 		entryInfo->iDescription = HBufC::NewL(len);
       
   256 		*(entryInfo->iDescription) = KTCIModifiedText();
       
   257 
       
   258 		}
       
   259 	}