pimappservices/calendar/tsrc/TOOMFET.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 <conpics.h>
       
    18 #include <e32test.h>
       
    19 #include <badesca.h>
       
    20 
       
    21 #include <calentryview.h>
       
    22 #include <calrrule.h>
       
    23 
       
    24 #include "caltestlib.h"
       
    25 #include "caltestoom.h"
       
    26 
       
    27 RTest test(_L("TOOMFET"));
       
    28 
       
    29 static const TTime _1Jan96(TDateTime(1996,EJanuary,2,0,0,0,0));
       
    30 
       
    31 _LIT(KTestCalendarFile, "TOOMFET");
       
    32 
       
    33 class CTestApp : public CBase, public MCalTestOomCallBack
       
    34 	{
       
    35 public:
       
    36 	static CTestApp* NewL();
       
    37 	~CTestApp();
       
    38 	
       
    39 	void AddSomeEntriesL();
       
    40 	void FetchEntriesL(TInt aGuid, const TDesC& aTitle);
       
    41 	void StoreEntryL(const CCalEntry* aEntry);
       
    42 
       
    43 private:
       
    44 	void ConstructL();
       
    45 
       
    46 public: // from MCalOomTestCallBack
       
    47 	void OomTestSetupL();
       
    48 	void OomTestL(TType aType, TInt aFailAt);
       
    49 
       
    50 private:
       
    51 	CCalTestLibrary* iCalTestLib;
       
    52 	CDesC8Array* iGuids;
       
    53 
       
    54 	TInt iGuidToFetch;
       
    55 	const TDesC* iTitle;
       
    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 iGuids;
       
    79 	delete iCalTestLib;
       
    80 	}
       
    81 	
       
    82 void CTestApp::StoreEntryL(const CCalEntry* aEntry)
       
    83 	{
       
    84 	RPointerArray<CCalEntry> entryArray;
       
    85 	CleanupClosePushL(entryArray);
       
    86 	entryArray.AppendL(aEntry);
       
    87 	TInt numSuc;
       
    88 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
    89 	test(numSuc == entryArray.Count());
       
    90 	CleanupStack::PopAndDestroy(&entryArray);
       
    91 	}
       
    92 
       
    93 void CTestApp::AddSomeEntriesL()
       
    94 	{
       
    95 	HBufC8* guidAppt = NULL;
       
    96 	CCalEntry* appt = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidAppt);
       
    97 	CleanupStack::PushL(appt);
       
    98 	iGuids->AppendL(*guidAppt);
       
    99 	
       
   100 	HBufC8* guidEvent = NULL;
       
   101 	CCalEntry* event = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidEvent);
       
   102 	CleanupStack::PushL(event);
       
   103 	iGuids->AppendL(*guidEvent);
       
   104 	
       
   105 	HBufC8* guidAnniv = NULL;
       
   106 	CCalEntry* anniv = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidAnniv);
       
   107 	CleanupStack::PushL(anniv);
       
   108 	iGuids->AppendL(*guidAnniv);
       
   109 	
       
   110 	HBufC8* guidTodo = NULL;
       
   111 	CCalEntry* todo = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidTodo);
       
   112 	CleanupStack::PushL(todo);
       
   113 	iGuids->AppendL(*guidTodo);
       
   114 
       
   115 	appt->SetSummaryL(_L("A"));
       
   116 	iCalTestLib->SetEntryStartAndEndTimeL(appt, _1Jan96, _1Jan96 + TTimeIntervalMinutes(60));
       
   117 	
       
   118 	TCalRRule rRuleAppt(TCalRRule::EDaily);
       
   119 	// set rRule start
       
   120 	TCalTime startTime;
       
   121 	startTime.SetTimeLocalL(_1Jan96);
       
   122 	rRuleAppt.SetDtStart(startTime);
       
   123 	
       
   124 	// set rRule end
       
   125 	TCalTime endTime;
       
   126 	endTime.SetTimeLocalL(_1Jan96 + TTimeIntervalDays(30));
       
   127 	rRuleAppt.SetUntil(endTime);
       
   128 	
       
   129 	rRuleAppt.SetInterval(4);
       
   130 	
       
   131 	appt->SetRRuleL(rRuleAppt);
       
   132 
       
   133 	StoreEntryL(appt);
       
   134 	
       
   135 		
       
   136 	event->SetSummaryL(_L("xE"));
       
   137 	iCalTestLib->SetEntryStartAndEndTimeL(event, _1Jan96, _1Jan96);
       
   138 	
       
   139 	StoreEntryL(event);
       
   140 
       
   141 	anniv->SetSummaryL(_L("xN"));
       
   142 	iCalTestLib->SetEntryStartAndEndTimeL(anniv, _1Jan96, _1Jan96);
       
   143 	StoreEntryL(anniv);
       
   144 
       
   145 	todo->SetSummaryL(_L("xT"));
       
   146 	iCalTestLib->SetEntryStartAndEndTimeL(todo, _1Jan96, _1Jan96);
       
   147 	StoreEntryL(todo);
       
   148 
       
   149 	
       
   150 	// The first 4 entries will be	put into the first stream, by adding some other entries
       
   151 	// so that another stream is used it means fetching when the entries being tested are both
       
   152 	// loaded in memory and not in memory can both be tested
       
   153 	
       
   154 	const TInt KNumExtraEntries(14);
       
   155 	for (TInt i(0) ; i < KNumExtraEntries ; ++i)
       
   156 		{
       
   157 		HBufC8* guid = NULL;
       
   158 		CCalEntry* scrapEvent = iCalTestLib->CreateCalEntryL(CCalEntry::EEvent, guid);
       
   159 		CleanupStack::PushL(scrapEvent);
       
   160 		iCalTestLib->SetEntryStartAndEndTimeL(scrapEvent, _1Jan96, _1Jan96);
       
   161 		scrapEvent->SetSummaryL(_L("Scrap"));
       
   162 		StoreEntryL(scrapEvent);
       
   163 		if ( i == KNumExtraEntries - 1 )
       
   164 			{
       
   165 			// store the guid of the last of these entries
       
   166 			iGuids->AppendL(*guid);
       
   167 			}
       
   168 		CleanupStack::PopAndDestroy(scrapEvent);
       
   169 		}
       
   170 		
       
   171 	CleanupStack::PopAndDestroy(todo);
       
   172 	CleanupStack::PopAndDestroy(anniv);
       
   173 	CleanupStack::PopAndDestroy(event);
       
   174 	CleanupStack::PopAndDestroy(appt);
       
   175 	}
       
   176 
       
   177 void CTestApp::OomTestSetupL()
       
   178 	{
       
   179 	}
       
   180 	
       
   181 void CTestApp::OomTestL(TType /*aType*/, TInt /*aFailAt*/)
       
   182 	{
       
   183 	test.Printf(_L("."));
       
   184 	RPointerArray<CCalEntry> entryArray;
       
   185 	CleanupResetAndDestroyPushL(entryArray);
       
   186 	iCalTestLib->SynCGetEntryViewL().FetchL((*iGuids)[iGuidToFetch], entryArray);
       
   187 	if (entryArray.Count() == 0)
       
   188 		{
       
   189 		User::Leave(KErrNoMemory);
       
   190 		}
       
   191 	else
       
   192 		{
       
   193 		test(entryArray.Count() == 1);
       
   194 		}
       
   195 	
       
   196 	// test that the summary is correct
       
   197 	TBuf<1> title;
       
   198 	title.Append(entryArray[0]->SummaryL().Left(1));
       
   199 	//test(title == *iTitle);
       
   200 	
       
   201 	CleanupStack::PopAndDestroy(); //entryArray.ResetAndDestroy();
       
   202 	}
       
   203 
       
   204 void CTestApp::FetchEntriesL(TInt aGuidToFetch, const TDesC& aTitle)
       
   205 	{ 
       
   206 	// fetch an entry from another stream so that the one we are testing will not be loaded in memory
       
   207 	RPointerArray<CCalEntry> entryArray;
       
   208 	CleanupResetAndDestroyPushL(entryArray);
       
   209 	iCalTestLib->SynCGetEntryViewL().FetchL((*iGuids)[iGuids->Count() - 1], entryArray); // the last entry that was added will be in a different stream
       
   210 	CleanupStack::PopAndDestroy(); //entryArray.ResetAndDestroy();
       
   211 
       
   212 	iGuidToFetch = aGuidToFetch;
       
   213 	iTitle = &aTitle;
       
   214 
       
   215 	CCalSession& calSession = iCalTestLib->GetSession();
       
   216 	// fetch it once
       
   217 	CalTestOom::OutOfMemoryTestL(*this, EClient, calSession);
       
   218 	// now that its been fetched it should be in memory, so fetching it again will execute different code
       
   219 	CalTestOom::OutOfMemoryTestL(*this, EClient, calSession);
       
   220 	
       
   221 	// fetch it once
       
   222 	CalTestOom::OutOfMemoryTestL(*this, EServer, calSession);
       
   223 	// now that its been fetched it should be in memory, so fetching it again will execute different code
       
   224 	CalTestOom::OutOfMemoryTestL(*this, EServer, calSession);
       
   225 	}
       
   226 
       
   227 
       
   228 static void doMainL()
       
   229 	{
       
   230 	CTestApp* testApp = CTestApp::NewL();
       
   231 	CleanupStack::PushL(testApp);
       
   232 
       
   233 	test.Next(_L("Adding entries ..."));
       
   234 
       
   235 	testApp->AddSomeEntriesL();
       
   236 	test.Next(_L("testing appt"));
       
   237 
       
   238 	testApp->FetchEntriesL(0,_L("A"));
       
   239 	test.Next(_L("testing event"));
       
   240 
       
   241 	testApp->FetchEntriesL(1,_L("E"));
       
   242 	test.Next(_L("testing anniv"));
       
   243 
       
   244 	testApp->FetchEntriesL(2,_L("N"));
       
   245 	test.Next(_L("testing todo"));
       
   246 
       
   247 	testApp->FetchEntriesL(3,_L("T"));
       
   248 /*
       
   249 	test.Next(_L("Now testing with fast storing"));
       
   250 
       
   251 	//view->Model()->SetBufferedStoring(ETrue);
       
   252 	CAgnAppt* appt=AgnTest->CreateApptLC();
       
   253 	appt->RichTextL()->InsertL(0,_L("xA"));
       
   254 	appt->SetStartAndEndDateTime(_1Jan96);
       
   255 	view->Model()->AddEntryL(appt);
       
   256 	CleanupStack::PopAndDestroy(appt);
       
   257 	FetchEntriesL(view,TAgnInstanceId(apptId,_1Jan96),_L("A"));
       
   258 */
       
   259 	CleanupStack::PopAndDestroy(testApp);
       
   260 	}
       
   261 
       
   262 
       
   263 /**
       
   264 
       
   265 @SYMTestCaseID     PIM-TOOMFET-0001
       
   266 
       
   267 */
       
   268 
       
   269 TInt E32Main()
       
   270 	{	
       
   271 
       
   272 	__UHEAP_MARK;
       
   273 	test.Start(_L("@SYMTESTCaseID:PIM-TOOMFET-0001 TOOMFET.CPP"));
       
   274 
       
   275 	test.Title();
       
   276 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   277 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
   278 	CActiveScheduler::Install(scheduler);
       
   279 	TRAPD(ret,doMainL());	
       
   280 	delete scheduler;
       
   281 	test(ret==KErrNone);
       
   282 	delete theCleanup;
       
   283 	test.End();
       
   284 	test.Close();
       
   285 	__UHEAP_MARKEND;
       
   286 	return(KErrNone);
       
   287 	}
       
   288