pimappservices/calendar/tsrc/t_vcal5OOM.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 <e32test.h>
       
    17 #include <e32std.h>
       
    18 #include <s32file.h>
       
    19 
       
    20 #include <caldataexchange.h>
       
    21 #include <calentryview.h>
       
    22 #include <calrrule.h>
       
    23 #include <calalarm.h>
       
    24 #include <caliterator.h>
       
    25 #include <caldataformat.h>
       
    26 #include <calsession.h>
       
    27 
       
    28 #include "caltestlib.h"
       
    29 #include "caltestoom.h"
       
    30 
       
    31 LOCAL_D RTest test(_L("T_VCAL5OOM"));
       
    32 _LIT8(KOOMEntryGuid,  "OOM_Entry_Guid");
       
    33 
       
    34 _LIT(KTestCalendarFile,	"c:t_vcal5oom");
       
    35 _LIT(KVCalFile,			"c:\\t_vcal5oom.vcs");
       
    36 
       
    37 class CTestApp : public CBase, public MCalTestOomCallBack
       
    38 	{
       
    39 public:
       
    40 	enum TOOMTestCase
       
    41 		{
       
    42 		ETestAllEntry,
       
    43 		ETestTemporaryEntry,
       
    44 		EAmountTestCases
       
    45 		};
       
    46 public:
       
    47 	static CTestApp* NewL();
       
    48 	~CTestApp();
       
    49 	
       
    50 	void CreateAppointmentL();
       
    51 	void CreateAnniversaryEntryL();
       
    52 	void CreateTimedAlarmedApptEntryL();
       
    53 	
       
    54 	CCalEntry* CreateTodoLC(TBool isOOMTest);
       
    55 	
       
    56 	void ExportAsVCalendarL(const TDesC& aVCalendarFile);
       
    57 	void ExportAsVCalendarL(const TDesC& aVCalendarFile, CCalEntry* aEntry);
       
    58 	
       
    59 	void DoOomTestL();
       
    60 	
       
    61 	
       
    62 public: // from MCalOomTestCallBack
       
    63 	void OomTestL(TType aType, TInt aFailAt);
       
    64 	
       
    65 private:
       
    66 	void ConstructL();
       
    67 
       
    68 private:
       
    69 	CCalTestLibrary* iCalTestLib; //owned
       
    70 	
       
    71 	TInt iOOMTestCase;
       
    72 	};
       
    73 	
       
    74 CTestApp* CTestApp::NewL()
       
    75 	{
       
    76 	CTestApp* self = new(ELeave) CTestApp;
       
    77 	CleanupStack::PushL(self);
       
    78 	self->ConstructL();
       
    79 	CleanupStack::Pop(self);
       
    80 	return self;
       
    81 	}
       
    82 	
       
    83 void CTestApp::ConstructL()
       
    84 	{
       
    85 	iCalTestLib = CCalTestLibrary::NewL();
       
    86 	iCalTestLib->ReplaceFileL(KTestCalendarFile);
       
    87 	iCalTestLib->OpenFileL(KTestCalendarFile);
       
    88 	}
       
    89 		
       
    90 CTestApp::~CTestApp()
       
    91 	{
       
    92 	delete iCalTestLib;
       
    93 	}
       
    94 	
       
    95 void CTestApp::DoOomTestL()
       
    96 	{
       
    97 	CCalSession& calSession = iCalTestLib->GetSession();
       
    98 	
       
    99 	for (iOOMTestCase = 0 ; iOOMTestCase < EAmountTestCases; ++iOOMTestCase)
       
   100 		{
       
   101 		test.Printf(_L("Starting oom test %d\n"), iOOMTestCase);
       
   102 		CalTestOom::OutOfMemoryTestL(*this, EClient, calSession);
       
   103 		CalTestOom::OutOfMemoryTestL(*this, EServer, calSession);
       
   104 		}
       
   105 	}
       
   106 	
       
   107 void CTestApp::OomTestL(TType /*aType*/, TInt /*aFailAt*/)
       
   108 	{
       
   109 	test.Printf(_L("."));
       
   110 	
       
   111 	switch (iOOMTestCase)
       
   112 		{
       
   113 		case ETestAllEntry:
       
   114 			{
       
   115 			ExportAsVCalendarL(KVCalFile);
       
   116 			}
       
   117 			break;
       
   118 		case ETestTemporaryEntry:
       
   119 			{
       
   120 			CCalEntry* entry = CreateTodoLC(ETrue);
       
   121 			ExportAsVCalendarL(KVCalFile, entry);
       
   122 			CleanupStack::PopAndDestroy(entry);
       
   123 			}
       
   124 			break;
       
   125 		default:
       
   126 			{
       
   127 			User::Leave(KErrGeneral);
       
   128 			}
       
   129 		}
       
   130 	}
       
   131 
       
   132 // Create an appointment with Unicode text
       
   133 //
       
   134 void CTestApp::CreateAppointmentL()
       
   135 	{
       
   136 	TTime today;
       
   137 	today.HomeTime();
       
   138 	TCalTime startTime;
       
   139 	startTime.SetTimeLocalL(TDateTime(today.DateTime().Year(),today.DateTime().Month(),today.DateTime().Day(),9,0,0,0));
       
   140 	TCalTime endTime;
       
   141 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(60));
       
   142 	HBufC8* guid = NULL;
       
   143 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid);
       
   144 	CleanupStack::PushL(entry);
       
   145 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   146 	TBuf16<60> apptSummary;
       
   147 	apptSummary.AppendFormat(_L16("Here are some European letters: %c%c%c%c%c%c%c%c%c%c. "), 0x0117, 0x010d, 0x00f1, 0x00df, 0x00d8, 0x0142, 0x0151, 0x016f, 0x0131, 0x00c9);
       
   148 	entry->SetSummaryL(apptSummary);
       
   149 	
       
   150 	RPointerArray<CCalEntry> entryArray;
       
   151 	CleanupClosePushL(entryArray);
       
   152 	entryArray.AppendL(entry);
       
   153 	TInt numSuc;
       
   154 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   155 	CleanupStack::PopAndDestroy(); // entryArray.Close()
       
   156 	CleanupStack::PopAndDestroy(entry);
       
   157 	}
       
   158 
       
   159 // Create a repeating entry.
       
   160 // The repeat is set for yearly on June 24th starting in 1998, with the exception of 24/06/2000
       
   161 //
       
   162 void CTestApp::CreateAnniversaryEntryL()
       
   163 	{
       
   164 	HBufC8* guid = NULL;
       
   165 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAnniv, guid);
       
   166 	CleanupStack::PushL(entry);
       
   167 	TBuf16<60> text;
       
   168 	text.AppendFormat(_L16("Here are some Han characters: %c%c%c%c%c%c%c%c%c%c. "),   0x7f0c, 0x7a92, 0x6d90, 0x6272, 0x5934, 0x5973, 0x55ce, 0x516c, 0x4ec0, 0x4e00);
       
   169 	entry->SetSummaryL(text);
       
   170 	TCalTime annivTime;
       
   171 	annivTime.SetTimeLocalL(TTime(TDateTime(1998,EJune,24,0,0,0,0)));
       
   172 	
       
   173 	entry->SetStartAndEndTimeL(annivTime, annivTime);  
       
   174 	
       
   175 	TCalRRule rRule(TCalRRule::EYearly);
       
   176 	
       
   177 	rRule.SetDtStart(annivTime);  
       
   178 	TCalTime maxTime;
       
   179 	maxTime.SetTimeUtcL(TCalTime::MaxTime());
       
   180 	rRule.SetUntil(maxTime);
       
   181 	rRule.SetInterval(1);
       
   182 	entry->SetRRuleL(rRule);
       
   183 	
       
   184 	TCalTime exception;
       
   185 	exception.SetTimeLocalL(TTime(TDateTime(2000,EJune,24,0,0,0,0)));
       
   186 	RArray<TCalTime> exceptions;
       
   187 	CleanupClosePushL(exceptions);
       
   188 	exceptions.AppendL(exception);
       
   189 	entry->SetExceptionDatesL(exceptions);
       
   190 	CleanupStack::PopAndDestroy(&exceptions);
       
   191 	
       
   192 	RPointerArray<CCalEntry> entryArray;
       
   193 	CleanupClosePushL(entryArray);
       
   194 	entryArray.AppendL(entry);
       
   195 	TInt numSuc;
       
   196 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   197 	
       
   198 	CleanupStack::PopAndDestroy(); // entryArray.Close()
       
   199 	CleanupStack::PopAndDestroy(entry); //entry
       
   200 	}
       
   201 
       
   202 
       
   203 // Create an alarmed appointment
       
   204 //
       
   205 void CTestApp::CreateTimedAlarmedApptEntryL()
       
   206 	{
       
   207 	TTime today;
       
   208 	today.HomeTime();
       
   209 	TCalTime startTime;
       
   210 	startTime.SetTimeLocalL(TDateTime(today.DateTime().Year(),today.DateTime().Month(),today.DateTime().Day(),10,0,0,0));
       
   211 	TCalTime endTime;
       
   212 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(90));
       
   213 	HBufC8* guid = NULL;
       
   214 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid);
       
   215 	CleanupStack::PushL(entry);
       
   216 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   217 	TBuf16<60> text;
       
   218 	text.AppendFormat(_L16("Here are some Japanese kana: %c%c%c%c%c%c%c%c%c%c. "),    0x30a2, 0x30c0, 0x30d5, 0x30b7, 0x30ba, 0x3091, 0x3093, 0x3055, 0x3074, 0x3080);
       
   219 	entry->SetSummaryL(text);
       
   220 
       
   221 	CCalAlarm* alarm = CCalAlarm::NewL();
       
   222 	CleanupStack::PushL(alarm);
       
   223 	alarm->SetTimeOffset(TTimeIntervalMinutes(15));
       
   224 	TBuf16<30> alarmName;
       
   225 	alarmName.AppendFormat(_L16("%c%c%c%c%c%c%c%c%c%c. "),    0x03a3, 0x03bf, 0x03bc, 0x03b4, 0x03b5, 0x0345, 0x03a9, 0x0392, 0x0395, 0x03a1);
       
   226 	alarm->SetAlarmSoundNameL(alarmName);
       
   227 	entry->SetAlarmL(alarm);
       
   228 	CleanupStack::PopAndDestroy(alarm);
       
   229 	
       
   230 	RPointerArray<CCalEntry> entryArray;
       
   231 	CleanupClosePushL(entryArray);
       
   232 	entryArray.AppendL(entry);
       
   233 	TInt numSuc;
       
   234 	
       
   235 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   236 	
       
   237 	CleanupStack::PopAndDestroy(); // entryArray.Close()
       
   238 	CleanupStack::PopAndDestroy(entry);
       
   239 	}
       
   240 
       
   241 CCalEntry* CTestApp::CreateTodoLC(TBool isOOMTest)
       
   242 	{
       
   243 	HBufC8* guid = NULL; 
       
   244 	
       
   245 	CCalEntry* todo = NULL;
       
   246 	if(isOOMTest)
       
   247 		{
       
   248 		guid = KOOMEntryGuid().AllocLC();
       
   249 		todo = CCalEntry::NewL(CCalEntry::ETodo, guid, CCalEntry::EMethodAdd, 0);
       
   250 		CleanupStack::Pop(guid);
       
   251 		}
       
   252 	else
       
   253 		{
       
   254 		todo = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guid);
       
   255 		}
       
   256 
       
   257 	CleanupStack::PushL(todo);
       
   258 	TTime now;		  
       
   259 	now.UniversalTime();
       
   260 	
       
   261 	TCalTime startTime;
       
   262 	startTime.SetTimeLocalL(now + TTimeIntervalDays(5));
       
   263 	TCalTime endTime;
       
   264 	endTime.SetTimeLocalL(now + TTimeIntervalDays(5) + TTimeIntervalMinutes(500));
       
   265 	
       
   266 	todo->SetStartAndEndTimeL(startTime, endTime);
       
   267 	
       
   268 	TBuf16<60> text;
       
   269 	text.AppendFormat(_L16("A Selection of Dingbats: %c%c%c%c%c%c%c%c%c "), 0x2780, 0x270d, 0x27ab, 0x2704, 0x2706, 0x2707, 0x272d, 0x2729, 0x270f, 0x278b);
       
   270 	todo->SetSummaryL(text);
       
   271 	TCalTime now2;
       
   272 	now2.SetTimeLocalL(now);
       
   273 	todo->SetCompletedL(ETrue, now2);
       
   274 	
       
   275 	return todo;
       
   276 	}
       
   277 
       
   278 void CTestApp::ExportAsVCalendarL(const TDesC& aVCalendarFile)
       
   279 	{
       
   280 	RPointerArray<CCalEntry> entryArray;
       
   281 	CleanupResetAndDestroyPushL(entryArray);
       
   282 
       
   283 	CCalIter* calIter = NULL;
       
   284 	calIter = CCalIter::NewL(iCalTestLib->GetSession());
       
   285 	CleanupStack::PushL(calIter);
       
   286 	
       
   287 	for (TDesC8* guid = const_cast<TDesC8*>(&calIter->FirstL());
       
   288 			guid->CompareF(KNullDesC8) != 0;
       
   289 			guid = const_cast<TDesC8*>(&calIter->NextL()))
       
   290 		{
       
   291 			iCalTestLib->SynCGetEntryViewL().FetchL(*guid, entryArray);
       
   292 		}
       
   293 		
       
   294 	CleanupStack::PopAndDestroy(calIter);
       
   295 	
       
   296 	RFile outFile;
       
   297 	CleanupClosePushL(outFile);
       
   298 
       
   299 	User::LeaveIfError(outFile.Replace(iCalTestLib->FileSession(), aVCalendarFile, EFileWrite));
       
   300 
       
   301 
       
   302 	RFileWriteStream writeStream(outFile);
       
   303 	CleanupClosePushL(writeStream);
       
   304 	
       
   305 	CCalDataExchange* dataExchange = NULL;
       
   306 	dataExchange = CCalDataExchange::NewL(iCalTestLib->GetSession());
       
   307 	CleanupStack::PushL(dataExchange);
       
   308 	
       
   309 	dataExchange->ExportL(KUidVCalendar, writeStream, entryArray);
       
   310 	
       
   311 	CleanupStack::PopAndDestroy(dataExchange);
       
   312 	CleanupStack::PopAndDestroy(); // writeStream.Close()
       
   313 	CleanupStack::PopAndDestroy(); // outFile.Close()
       
   314 	CleanupStack::PopAndDestroy(); // entryArray.Close()
       
   315 	}
       
   316 
       
   317 void CTestApp::ExportAsVCalendarL(const TDesC& aVCalendarStream, CCalEntry* aEntry)
       
   318 	{
       
   319 	RFile outfile;
       
   320 	CleanupClosePushL(outfile);
       
   321 	User::LeaveIfError(outfile.Replace(iCalTestLib->FileSession(),aVCalendarStream,EFileWrite));
       
   322 	
       
   323 	RFileWriteStream writeStream(outfile);
       
   324 	CleanupClosePushL(writeStream);
       
   325 	
       
   326 	RPointerArray<CCalEntry> entryArray;
       
   327 	CleanupClosePushL(entryArray);
       
   328 	entryArray.AppendL(aEntry);
       
   329 
       
   330 	CCalDataExchange* dataExchange = NULL;
       
   331 	dataExchange = CCalDataExchange::NewL(iCalTestLib->GetSession());
       
   332 
       
   333 	CleanupStack::PushL(dataExchange);
       
   334 	dataExchange->ExportL(KUidVCalendar, writeStream, entryArray);
       
   335 	
       
   336 	writeStream.CommitL();
       
   337 	
       
   338 	CleanupStack::PopAndDestroy(dataExchange);
       
   339 	CleanupStack::PopAndDestroy(); // entryArray.Close();
       
   340 	CleanupStack::PopAndDestroy(); // writeStream.Close();
       
   341 	CleanupStack::PopAndDestroy(); // outfile.Close();
       
   342 	}	
       
   343 
       
   344 
       
   345 
       
   346 static void doMainL()
       
   347 	{
       
   348 	CTestApp* testApp = CTestApp::NewL();
       
   349 	CleanupStack::PushL(testApp);
       
   350 	
       
   351 	// create entries	
       
   352 	testApp->CreateAppointmentL();
       
   353 	testApp->CreateAnniversaryEntryL();
       
   354 	testApp->CreateTimedAlarmedApptEntryL();
       
   355 	
       
   356 	// export a vCalendar stream
       
   357 
       
   358 	test.Next(_L("Exporting all entries"));
       
   359 
       
   360 	testApp->ExportAsVCalendarL(KVCalFile);
       
   361 	
       
   362 	// export a single vCalendar object
       
   363 
       
   364 	test.Next(_L("Exporting a single vTodo object"));
       
   365 
       
   366 	CCalEntry* todo = testApp->CreateTodoLC(EFalse);
       
   367 	testApp->ExportAsVCalendarL(KVCalFile, todo);
       
   368 	CleanupStack::PopAndDestroy(todo);
       
   369 	
       
   370 	// Start the oom tests
       
   371 	
       
   372 	test.Next(_L("Starting the oom tests"));
       
   373 
       
   374 	testApp->DoOomTestL();
       
   375 
       
   376 	CleanupStack::PopAndDestroy(testApp);
       
   377 	}
       
   378 
       
   379 static void CleanupFilesL()
       
   380 	{
       
   381 	CCalTestLibrary* testLibrary = CCalTestLibrary::NewL(EFalse);
       
   382 	CleanupStack::PushL(testLibrary);
       
   383 	testLibrary->DeleteFileL(KVCalFile, EFalse);
       
   384 
       
   385 	CleanupStack::PopAndDestroy(testLibrary);
       
   386 	}
       
   387 	
       
   388 /**
       
   389 
       
   390 @SYMTestCaseID     PIM-T-VCAL5OOM-0001
       
   391 
       
   392 */
       
   393 
       
   394 TInt E32Main()
       
   395 	{	
       
   396 	__UHEAP_MARK;
       
   397 	test.Start(_L("@SYMTESTCaseID:PIM-T-VCAL5OOM-0001 T_VCAL5OOM"));
       
   398 
       
   399 	test.Title();
       
   400 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   401 	CActiveScheduler::Install(scheduler);
       
   402 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   403 	TRAPD(ret,doMainL());	
       
   404 	test(ret==KErrNone);
       
   405 	TRAP_IGNORE(CleanupFilesL());
       
   406 	delete theCleanup;	
       
   407 	delete scheduler;
       
   408 	test.End();
       
   409 	test.Close();
       
   410 	__UHEAP_MARKEND;
       
   411 	return(KErrNone);
       
   412 	}