pimappservices/calendar/tsrc/TOOMDEL.CPP
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 1997-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 <s32file.h>
       
    17 #include <e32test.h>
       
    18 #include <badesca.h>
       
    19 
       
    20 #include <calrrule.h>
       
    21 #include <calentryview.h>
       
    22 
       
    23 #include "caltestlib.h"
       
    24 #include "caltestoom.h"
       
    25 
       
    26 RTest test(_L("TOOMDEL"));
       
    27 _LIT(KTestCalendarFile, "toomdel");
       
    28 
       
    29 const TInt KNumEntriesInStream(16);
       
    30 
       
    31 static const TTime _1Jan96(TDateTime(1996,EJanuary,2,0,0,0,0));
       
    32 
       
    33 class CTestApp : public CBase, public MCalTestOomCallBack
       
    34 	{
       
    35 public:
       
    36 	static CTestApp* NewL();
       
    37 	~CTestApp();
       
    38 	
       
    39 	void AddScrapEntriesL(TInt aNumEntries);
       
    40 	void AddEntriesL(TBool aCreateAnotherStream);
       
    41 	void DeleteEntryL(TInt aEntryToDelete, TBool aTestWithoutBeingLoaded);
       
    42 	void ReOpenFileL();
       
    43 	void StoreEntryL(const CCalEntry* aEntry);
       
    44 
       
    45 private:
       
    46 	void ConstructL();
       
    47 	
       
    48 public:
       
    49 	void OomTestL(TType aType, TInt aFailAt);
       
    50 
       
    51 private:
       
    52 	CCalTestLibrary* iCalTestLib;
       
    53 	CDesC8Array* iGuids;
       
    54 	
       
    55 	TInt iEntryToDelete;
       
    56 	};
       
    57 	
       
    58 CTestApp* CTestApp::NewL()
       
    59 	{
       
    60 	CTestApp* self = new(ELeave) CTestApp;
       
    61 	CleanupStack::PushL(self);
       
    62 	self->ConstructL();
       
    63 	CleanupStack::Pop(self);
       
    64 	return self;
       
    65 	}
       
    66 	
       
    67 void CTestApp::ConstructL()
       
    68 	{
       
    69 	iCalTestLib = CCalTestLibrary::NewL();
       
    70 	iCalTestLib->ReplaceFileL(KTestCalendarFile);
       
    71 	iCalTestLib->OpenFileL(KTestCalendarFile);
       
    72 	
       
    73 	iGuids = new(ELeave) CDesC8ArrayFlat(8);
       
    74 	}
       
    75 		
       
    76 CTestApp::~CTestApp()
       
    77 	{
       
    78 	delete iCalTestLib;
       
    79 	}
       
    80 	
       
    81 void CTestApp::StoreEntryL(const CCalEntry* aEntry)
       
    82 	{
       
    83 	RPointerArray<CCalEntry> entryArray;
       
    84 	CleanupClosePushL(entryArray);
       
    85 	entryArray.AppendL(aEntry);
       
    86 	TInt numSuc;
       
    87 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
    88 	test(numSuc == entryArray.Count());
       
    89 	CleanupStack::PopAndDestroy(&entryArray);
       
    90 	}
       
    91 	
       
    92 void CTestApp::ReOpenFileL()
       
    93 	{
       
    94 	iCalTestLib->OpenFileL(KTestCalendarFile);
       
    95 	}
       
    96 	
       
    97 void CTestApp::AddScrapEntriesL(TInt aNumEntries)
       
    98 	{
       
    99 	for (TInt i(0) ; i < aNumEntries ; ++i)
       
   100 		{
       
   101 		HBufC8* guidScrap = NULL;
       
   102 		CCalEntry* scrap = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidScrap);
       
   103 		CleanupStack::PushL(scrap);
       
   104 		scrap->SetSummaryL(_L("Scrap"));
       
   105 		iCalTestLib->SetEntryStartAndEndTimeL(scrap, _1Jan96, _1Jan96 + TTimeIntervalMinutes(60));
       
   106 		StoreEntryL(scrap);
       
   107 		CleanupStack::PopAndDestroy(scrap);
       
   108 		}
       
   109 	}
       
   110 
       
   111 void CTestApp::AddEntriesL(TBool aCreateAnotherStream)
       
   112 	{
       
   113 	iGuids->Reset();
       
   114 	
       
   115 	HBufC8* guidAppt = NULL;
       
   116 	CCalEntry* appt = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidAppt);
       
   117 	CleanupStack::PushL(appt);
       
   118 	iGuids->AppendL(*guidAppt);
       
   119 	
       
   120 	HBufC8* guidDayNote = NULL;
       
   121 	CCalEntry* dayNote = iCalTestLib->CreateCalEntryL(CCalEntry::EReminder, guidDayNote);
       
   122 	CleanupStack::PushL(dayNote);
       
   123 	iGuids->AppendL(*guidDayNote);
       
   124 	
       
   125 	HBufC8* guidEvent = NULL;
       
   126 	CCalEntry* event = iCalTestLib->CreateCalEntryL(CCalEntry::EEvent, guidEvent);
       
   127 	CleanupStack::PushL(event);
       
   128 	iGuids->AppendL(*guidEvent);
       
   129 	
       
   130 	HBufC8* guidAnniv = NULL;
       
   131 	CCalEntry* anniv = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidAnniv);
       
   132 	CleanupStack::PushL(anniv);
       
   133 	iGuids->AppendL(*guidAnniv);
       
   134 	
       
   135 	HBufC8* guidTodo = NULL;
       
   136 	CCalEntry* todo = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidTodo);
       
   137 	CleanupStack::PushL(todo);
       
   138 	iGuids->AppendL(*guidTodo);
       
   139 
       
   140 	
       
   141 	AddScrapEntriesL(KNumEntriesInStream);
       
   142 	AddScrapEntriesL(KNumEntriesInStream - 1);
       
   143 		
       
   144 	appt->SetSummaryL(_L("Appt"));
       
   145 	iCalTestLib->SetEntryStartAndEndTimeL(appt, _1Jan96, _1Jan96 + TTimeIntervalMinutes(60));
       
   146 	TCalRRule rRule(TCalRRule::EDaily);
       
   147 	TCalTime rRuleStartTime;
       
   148 	rRuleStartTime.SetTimeLocalL(_1Jan96);
       
   149 	TCalTime rRuleEndTime;
       
   150 	rRuleEndTime.SetTimeUtcL(_1Jan96 + TTimeIntervalDays(30));
       
   151 	rRule.SetDtStart(rRuleStartTime);
       
   152 	rRule.SetUntil(rRuleEndTime);
       
   153 	rRule.SetInterval(4);
       
   154 	appt->SetRRuleL(rRule);
       
   155 		
       
   156 	StoreEntryL(appt);
       
   157 
       
   158 	AddScrapEntriesL(KNumEntriesInStream - 1);
       
   159 	
       
   160 	iCalTestLib->SetEntryStartAndEndTimeL(dayNote, _1Jan96, _1Jan96);
       
   161 	dayNote->SetSummaryL(_L("Day note"));
       
   162 	
       
   163 	StoreEntryL(dayNote);
       
   164 		
       
   165 	AddScrapEntriesL(KNumEntriesInStream - 1);
       
   166 	
       
   167 	iCalTestLib->SetEntryStartAndEndTimeL(event, _1Jan96, _1Jan96);
       
   168 	event->SetSummaryL(_L("Event"));
       
   169 	
       
   170 	StoreEntryL(event);	
       
   171 
       
   172 	AddScrapEntriesL(KNumEntriesInStream - 1);
       
   173 	
       
   174 	iCalTestLib->SetEntryStartAndEndTimeL(anniv, _1Jan96, _1Jan96);
       
   175 	anniv->SetSummaryL(_L("Anniv"));
       
   176 	StoreEntryL(anniv);
       
   177 
       
   178 	AddScrapEntriesL(KNumEntriesInStream - 1);
       
   179 	
       
   180 	iCalTestLib->SetEntryStartAndEndTimeL(todo, _1Jan96, _1Jan96);
       
   181 	todo->SetSummaryL(_L("Todo"));
       
   182 	StoreEntryL(todo);
       
   183 	
       
   184 	// By adding some other entries
       
   185 	// so that another stream is used it means fetching when the entries being tested are both
       
   186 	// loaded in memory and not in memory can both be tested
       
   187 	if (aCreateAnotherStream)
       
   188 		{
       
   189 		AddScrapEntriesL(30);
       
   190 		HBufC8* guidScrap = NULL;
       
   191 		CCalEntry* scrap = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidScrap);
       
   192 		CleanupStack::PushL(scrap);
       
   193 		iGuids->AppendL(*guidScrap);
       
   194 		scrap->SetSummaryL(_L("Scrap"));
       
   195 		iCalTestLib->SetEntryStartAndEndTimeL(scrap, _1Jan96, _1Jan96 + TTimeIntervalMinutes(60));
       
   196 		StoreEntryL(scrap);
       
   197 		CleanupStack::PopAndDestroy(scrap);
       
   198 		}
       
   199 
       
   200 	CleanupStack::PopAndDestroy(todo);
       
   201 	CleanupStack::PopAndDestroy(anniv);
       
   202 	CleanupStack::PopAndDestroy(event);
       
   203 	CleanupStack::PopAndDestroy(dayNote);
       
   204 	CleanupStack::PopAndDestroy(appt);
       
   205 	}
       
   206 	
       
   207 void CTestApp::OomTestL(TType /*aType*/, TInt /*aFailAt*/)
       
   208 	{
       
   209 	test.Printf(_L("."));
       
   210 	CDesC8Array* guids = new(ELeave) CDesC8ArrayFlat(8);
       
   211 	CleanupStack::PushL(guids);
       
   212 	guids->AppendL((*iGuids)[iEntryToDelete]);
       
   213 	iCalTestLib->SynCGetEntryViewL().DeleteL(*guids);
       
   214 	CleanupStack::PopAndDestroy(guids);
       
   215 	}
       
   216 
       
   217 
       
   218 void CTestApp::DeleteEntryL(TInt aEntryToDelete, TBool aTestWithoutBeingLoaded)
       
   219 	{
       
   220 	if (aTestWithoutBeingLoaded)
       
   221 		{
       
   222 		test.Printf(_L("fetch the entry to be deleted\n"));
       
   223 		// fetch an entry from another stream so that the one we are testing will not be loaded in memory,
       
   224 		// causing it to be fetched first
       
   225 		RPointerArray<CCalEntry> entryArray;
       
   226 		CleanupResetAndDestroyPushL(entryArray);
       
   227 		iCalTestLib->SynCGetEntryViewL().FetchL((*iGuids)[iGuids->Count()-1], entryArray);
       
   228 		CleanupStack::PopAndDestroy(&entryArray);
       
   229 		}
       
   230 	
       
   231 	test.Printf(_L("start the oom delete\n"));
       
   232 	iEntryToDelete = aEntryToDelete;
       
   233 	CCalSession& calSession = iCalTestLib->GetSession();
       
   234 	TRAPD(err, CalTestOom::OutOfMemoryTestL(*this, EClient, calSession));
       
   235 	test(err == KErrNone || err ==KErrNotFound);
       
   236 	TRAP(err, CalTestOom::OutOfMemoryTestL(*this, EServer, calSession));
       
   237 	test(err == KErrNone || err ==KErrNotFound);
       
   238 	}
       
   239 
       
   240 
       
   241 
       
   242 static void doMainL()
       
   243 	{
       
   244 	CTestApp* testApp = CTestApp::NewL();
       
   245 	CleanupStack::PushL(testApp);
       
   246 
       
   247 	test.Next(_L("Adding entries ..."));
       
   248 
       
   249 	testApp->AddEntriesL(ETrue);
       
   250 	
       
   251 	test.Next(_L("testing day appt"));
       
   252 
       
   253 	testApp->DeleteEntryL(0, ETrue);
       
   254 
       
   255 	test.Next(_L("testing day note"));
       
   256 
       
   257 	testApp->DeleteEntryL(1, ETrue);
       
   258 
       
   259 	test.Next(_L("testing event"));
       
   260 
       
   261 	testApp->DeleteEntryL(2, ETrue);
       
   262 
       
   263 	test.Next(_L("testing anniv"));
       
   264 
       
   265 	testApp->DeleteEntryL(3, ETrue);
       
   266 	
       
   267 	test.Next(_L("testing todo"));
       
   268 
       
   269 	testApp->DeleteEntryL(4, ETrue);
       
   270 
       
   271 	testApp->ReOpenFileL();
       
   272 	
       
   273 	test.Next(_L("Adding entries ..."));
       
   274 
       
   275 	testApp->AddEntriesL(EFalse);
       
   276 	
       
   277 	test.Next(_L("testing appt"));
       
   278 
       
   279 	testApp->DeleteEntryL(0, EFalse);
       
   280 
       
   281 	test.Next(_L("testing day note"));
       
   282 
       
   283 	testApp->DeleteEntryL(1 ,EFalse);
       
   284 
       
   285 	test.Next(_L("testing event"));
       
   286 
       
   287 	testApp->DeleteEntryL(2, EFalse);
       
   288 
       
   289 	test.Next(_L("testing anniv"));
       
   290 
       
   291 	testApp->DeleteEntryL(3, EFalse);
       
   292 
       
   293 	test.Next(_L("testing todo"));
       
   294 
       
   295 	testApp->DeleteEntryL(4, EFalse);
       
   296 
       
   297 	CleanupStack::PopAndDestroy(testApp);
       
   298 	}
       
   299 
       
   300 /**
       
   301 
       
   302 @SYMTestCaseID     PIM-TOOMDEL-0001
       
   303 
       
   304 */
       
   305 
       
   306 TInt E32Main()
       
   307 	{	
       
   308 
       
   309 	__UHEAP_MARK;
       
   310 	test.Start(_L("@SYMTESTCaseID:PIM-TOOMDEL-0001 TOOMDEL.CPP"));
       
   311 
       
   312 	test.Title();
       
   313 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   314 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   315 	CActiveScheduler::Install(scheduler);
       
   316 	TRAPD(ret,doMainL());
       
   317 	delete scheduler;	
       
   318 	if (ret != KErrNone)
       
   319 		test.Printf(_L("ret is:%d\n"),ret);
       
   320 	test(ret==KErrNone);
       
   321 	delete theCleanup;
       
   322 	test.End();
       
   323 	test.Close();
       
   324 	__UHEAP_MARKEND;
       
   325 	return(KErrNone);
       
   326 	}
       
   327