pimappservices/calendar/tsrc/tcal_gsentry.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-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 "caltestlib.h"
       
    17 #include "tcal_gsentry_testdata.h"
       
    18 
       
    19 #include <calentry.h>
       
    20 #include <calentryview.h>
       
    21 #include <calinstance.h>
       
    22 #include <calinstanceview.h>
       
    23 #include <calrrule.h>
       
    24 #include <e32test.h>
       
    25 
       
    26 _LIT(KFormatDate, "%D%M%Y%/0%1%/1%2%/2%3%/3");
       
    27 _LIT(KCalendarFile, "tCal_GsEntry");
       
    28 
       
    29 class CDummyCalendarApp : public CBase
       
    30 	{
       
    31 public:
       
    32 	static CDummyCalendarApp* NewLC();
       
    33 	~CDummyCalendarApp();
       
    34 	void DoTestL();
       
    35 	
       
    36 private:
       
    37 	CDummyCalendarApp();
       
    38 	void ConstructL();
       
    39 	
       
    40 	void OpenCleanFileL();
       
    41     void FillDefaultDatabaseL(TInt aTestCount, TBool aFloating, TBool aSummerTime = EFalse);
       
    42 	void ExtractFromDatabaseL();
       
    43 	
       
    44     void ExtractEntriesL(TBool aCompareWithExpectedNum = EFalse, TInt aExpectedNum = 0);
       
    45 	void ExtractInstancesL();
       
    46 	void ExtractNonExistentEntryL();
       
    47 
       
    48 
       
    49 private: // member data
       
    50 	CCalTestLibrary* iTestLib;
       
    51 	CCalInstanceView* iInstanceView;
       
    52 	CCalEntryView* iEntryView;
       
    53 	TTestDataStruct* iCurrentTestData;
       
    54 	};
       
    55 
       
    56 CDummyCalendarApp* CDummyCalendarApp::NewLC()
       
    57 	{
       
    58 	CDummyCalendarApp* self = new (ELeave) CDummyCalendarApp();
       
    59 	
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL();
       
    62 
       
    63 	return (self);
       
    64 	}
       
    65 	
       
    66 CDummyCalendarApp::~CDummyCalendarApp()
       
    67 	{
       
    68 	delete iTestLib;
       
    69 	delete iCurrentTestData;
       
    70 	}
       
    71 
       
    72 CDummyCalendarApp::CDummyCalendarApp()
       
    73 	{
       
    74 	}
       
    75 
       
    76 void CDummyCalendarApp::ConstructL()
       
    77 	{
       
    78 	iTestLib = CCalTestLibrary::NewL();
       
    79 	}
       
    80 
       
    81 void CDummyCalendarApp::OpenCleanFileL()
       
    82 	{
       
    83 	iTestLib->ReplaceFileL(KCalendarFile);
       
    84 	iTestLib->OpenFileL(KCalendarFile);
       
    85 	
       
    86 	iInstanceView = &iTestLib->SynCGetInstanceViewL();
       
    87 	iEntryView = &iTestLib->SynCGetEntryViewL();
       
    88 	}
       
    89 	
       
    90 void CDummyCalendarApp::FillDefaultDatabaseL(TInt aTestCount, TBool aFloating, TBool aSummerTime)
       
    91 	{
       
    92 	if (iCurrentTestData)
       
    93 		{
       
    94 		delete iCurrentTestData;
       
    95 		iCurrentTestData = NULL;
       
    96 		}
       
    97    	iCurrentTestData = CTestData::GetTestDataL((CTestData::TTestNumber)aTestCount, iInstanceView, iEntryView, aFloating, aSummerTime);
       
    98 	}
       
    99 
       
   100 static void ResetAndDestroyCalEntryArray(TAny* aPtr)
       
   101 	{
       
   102 	if (aPtr)
       
   103 		{
       
   104 		RPointerArray<CCalEntry>* array = static_cast<RPointerArray<CCalEntry>*>(aPtr);
       
   105 		array->ResetAndDestroy();
       
   106 		}
       
   107 	}
       
   108 	
       
   109 // Helper method
       
   110 // Extract all entries given by Guids in iCurrentTestData
       
   111 void CDummyCalendarApp::ExtractEntriesL(TBool aCompareWithExpectedNum, TInt aExpectedNum)
       
   112 	{
       
   113 	// Extract entries by the GUIDs given in current-test-data's iGuids
       
   114 	for(TInt a = 0; a < iCurrentTestData->iGuidsToExtract.Count(); a++)
       
   115 		{
       
   116 		TPtrC8 guid = iCurrentTestData->iGuidsToExtract[a];
       
   117 		
       
   118 		RPointerArray<CCalEntry> entryArray;
       
   119 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyCalEntryArray, &entryArray));
       
   120 		iEntryView->FetchL(guid, entryArray);
       
   121 		
       
   122 		test.Printf(_L("%d GS entries fetched\n"), entryArray.Count());
       
   123 
       
   124         if (aCompareWithExpectedNum)
       
   125             {
       
   126             test.Printf(_L("%d entries were expected"), aExpectedNum);
       
   127             test(entryArray.Count() == aExpectedNum);
       
   128             }
       
   129 
       
   130 		CCalEntry* entryPtr;
       
   131 		for(TInt a = 0; a < entryArray.Count(); a++)
       
   132 			{
       
   133 			entryPtr = entryArray[a];
       
   134 			if(a==0)
       
   135 				{
       
   136 				test.Printf(_L("Parent -> SeqNum:%d\n"), entryPtr->SequenceNumberL());
       
   137 				}
       
   138 			else
       
   139 				{
       
   140 				TBuf<16> recIdTimeBuf;
       
   141 				TTime recIdTime = entryPtr->RecurrenceIdL().TimeLocalL();
       
   142 				recIdTime.FormatL(recIdTimeBuf, KFormatDate());
       
   143 				
       
   144 				test.Printf(_L("Child  -> SeqNum:%d, RecID: %S\n"), entryPtr->SequenceNumberL(), &recIdTimeBuf);
       
   145 				}
       
   146 			}
       
   147 		
       
   148 		CleanupStack::Pop(); // TCleanupItem(ResetAndDestroyCalEntryArray, &entryArray)
       
   149 		entryArray.ResetAndDestroy();
       
   150 		}
       
   151 	}
       
   152 	
       
   153 // Helper method
       
   154 // Extract all instances given by Guids in iCurrentTestData
       
   155 void CDummyCalendarApp::ExtractInstancesL()
       
   156 	{
       
   157 	TCalTime startDate;
       
   158 	startDate.SetTimeLocalL(iCurrentTestData->iStartDate);
       
   159 	TCalTime endDate;
       
   160 	endDate.SetTimeLocalL(iCurrentTestData->iEndDate);
       
   161 
       
   162 	CalCommon::TCalTimeRange timeRange(startDate, endDate);
       
   163 	
       
   164 	RPointerArray<CCalInstance> instanceArray;
       
   165 	
       
   166 	if (iCurrentTestData->iSearchString)
       
   167 		{
       
   168 		CCalInstanceView::TCalSearchParams searchParams(*iCurrentTestData->iSearchString, iCurrentTestData->iSearchBehaviour);
       
   169 		
       
   170 		iInstanceView->FindInstanceL(instanceArray, 
       
   171 									(CalCommon::TCalViewFilter)iCurrentTestData->iFilter, 
       
   172 									timeRange, 
       
   173 									searchParams);
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		iInstanceView->FindInstanceL(instanceArray, 
       
   178 							(CalCommon::TCalViewFilter)iCurrentTestData->iFilter, 
       
   179 							timeRange);		
       
   180 		}
       
   181 	
       
   182 	TBuf<26> startBuf;
       
   183 	TBuf<26> endBuf;
       
   184 	startDate.TimeLocalL().FormatL(startBuf,KFormatDate());
       
   185 	endDate.TimeLocalL().FormatL(endBuf,KFormatDate());
       
   186 	
       
   187 	test.Printf(_L("Checking instances between %S and %S\n"), &startBuf, &endBuf);
       
   188 	
       
   189 	if (instanceArray.Count() == 0)
       
   190 		{
       
   191 		test.Printf(_L("No instances found\n"));
       
   192 		}
       
   193 	else
       
   194 		{
       
   195 		TInt instanceCount = 0;
       
   196 		TTime instTime;
       
   197 		TBuf<26> instBuf;
       
   198 
       
   199 		while (instanceCount < instanceArray.Count())
       
   200 			{
       
   201 			CCalInstance* inst = instanceArray[instanceCount];
       
   202 			CleanupStack::PushL(inst);
       
   203 
       
   204 			instTime = inst->Time().TimeLocalL();
       
   205 			instTime.FormatL(instBuf,KFormatDate());
       
   206 	
       
   207 			TBuf<62> rptType;
       
   208 			TCalRRule rptDef;
       
   209 			if (!inst->Entry().GetRRuleL(rptDef))
       
   210 				{
       
   211 				rptType.Copy(_L("One off"));
       
   212 				}
       
   213 			else
       
   214 				{
       
   215 				switch (rptDef.Type())
       
   216 					{
       
   217 					case TCalRRule::EDaily:
       
   218 						rptType.Format(_L("Daily every %d days"), rptDef.Interval());
       
   219 						break;
       
   220 					case TCalRRule::EWeekly:
       
   221 						rptType.Format(_L("Weekly every %d weeks"), rptDef.Interval());
       
   222 						break;
       
   223 					case TCalRRule::EMonthly:
       
   224 						rptType.Format(_L("MonthlyByDates every %d months"), rptDef.Interval());
       
   225 						break;
       
   226 					case TCalRRule::EYearly:
       
   227 						rptType.Format(_L("YearlyByDate every %d years"), rptDef.Interval());
       
   228 						break;
       
   229 					default:
       
   230 						ASSERT(0);
       
   231 						break;
       
   232 					}
       
   233 				}
       
   234 				
       
   235 			test.Printf(_L("One instance is on %S, %d:%d - %S"), &instBuf, instTime.DateTime().Hour(), instTime.DateTime().Minute(), &rptType);
       
   236 			
       
   237 			if (iCurrentTestData->iTimes.Find(instTime) == KErrNotFound)
       
   238 				{
       
   239 				test.Printf(_L("THIS ENTRY WAS NOT EXPECTED\n"));
       
   240 				test(0);
       
   241 				}
       
   242 				
       
   243 			instanceCount++;
       
   244 			CleanupStack::Pop(inst);
       
   245 			}
       
   246 			
       
   247 		if (iCurrentTestData->iFunction)
       
   248 			ASSERT(iCurrentTestData->iFunction->CallBack() == 0);
       
   249 		}
       
   250 
       
   251 	if (instanceArray.Count() != iCurrentTestData->iTimes.Count())
       
   252 		{
       
   253 		test.Printf(_L("Some expected entries were not found!\n"));
       
   254 		test(0);	
       
   255 		}
       
   256 		
       
   257 	instanceArray.ResetAndDestroy();
       
   258 	}
       
   259 	
       
   260 void CDummyCalendarApp::ExtractFromDatabaseL()
       
   261 	{
       
   262 	// Print test's description
       
   263 	// Check if description field is longer than 124 characters and split the print if it is.
       
   264 	// (printf does not seem to handle string length > 124)
       
   265 	TInt len(iCurrentTestData->iDescription.Length());
       
   266 	if(len > 124)
       
   267 		{
       
   268 		TInt num(len / 124);
       
   269 		TBuf<TTestDataStruct::KDescriptionLen> tmpBuff(iCurrentTestData->iDescription);
       
   270 		for(TInt i = 0; i < num; ++i)
       
   271 			{
       
   272 			test.Printf(_L("%.124S"), &tmpBuff);
       
   273 			tmpBuff.Delete(0, 124);
       
   274 			}
       
   275 		if(tmpBuff.Length())
       
   276 			{
       
   277 			test.Printf(_L("%S\n"), &tmpBuff);
       
   278 			}
       
   279 		}
       
   280 	else
       
   281 		{
       
   282 		test.Printf(_L("TEST: %S\n"), &iCurrentTestData->iDescription);
       
   283 		}	
       
   284 
       
   285 	if(iCurrentTestData->iTestType == TTestDataStruct::EEntryTest)
       
   286 		{
       
   287 		ExtractEntriesL();
       
   288 		}
       
   289 		
       
   290 	else if(iCurrentTestData->iTestType == TTestDataStruct::EInstanceTest)
       
   291 		{
       
   292 		ExtractInstancesL();
       
   293 		}
       
   294 	}
       
   295 
       
   296 void CDummyCalendarApp::ExtractNonExistentEntryL()
       
   297 	{
       
   298 	RPointerArray<CCalEntry> entryArray;
       
   299 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyCalEntryArray, &entryArray));
       
   300 	
       
   301 	// Passing string type UID parameter and expecting entryArray to be empty
       
   302 	iEntryView->FetchL( _L8("myuid"), entryArray);
       
   303 	test(entryArray.Count() == 0);
       
   304 	entryArray.Reset();
       
   305 	
       
   306 	// Passing integer type UID parameter and expecting entryArray to be empty
       
   307 	iEntryView->FetchL( _L8("10"), entryArray);
       
   308 	test(entryArray.Count() == 0);
       
   309 	
       
   310 	CleanupStack::Pop(); // TCleanupItem(ResetAndDestroyCalEntryArray, &entryArray)
       
   311 	entryArray.ResetAndDestroy();
       
   312 	}
       
   313 
       
   314 
       
   315 void CDummyCalendarApp::DoTestL()
       
   316 	{
       
   317 	TInt testCount(0);
       
   318 	
       
   319 	while (testCount < CTestData::ENumberOfTestsForFixedAndFloating)
       
   320 		{
       
   321 		OpenCleanFileL();
       
   322 		FillDefaultDatabaseL(testCount, EFalse);
       
   323 		ExtractFromDatabaseL();
       
   324 		testCount++;
       
   325 		iTestLib->CleanDatabaseL();
       
   326 		}
       
   327 
       
   328 	// repeat the above test for floating entry
       
   329 	/**
       
   330 	@SYMTestCaseID PIM-TCAL-GSENTRY-Floating_Parent_And_Child_Entry-0001
       
   331 	@SYMTestCaseDesc Create floating parent and child entries
       
   332 	@SYMFssID App-Engines/CalInterimAPI/Data.007
       
   333 	@SYMTestStatus Implemented
       
   334 	@SYMTestPriority Medium
       
   335 	@SYMTestActions Create floating parent and child entries with various combination of repeating rule, excption dates, and RDates. 
       
   336 	Store the entries, then check that the expected instances can be retrieved.
       
   337 	@SYMTestExpectedResults The check shows that the instances defined by the repeated rule and exception dates and RDates are found
       
   338 	@SYMTestType CT	
       
   339 	*/
       
   340 	testCount = 0;
       
   341 	while (testCount < CTestData::ENumberOfTests)
       
   342 		{
       
   343 		OpenCleanFileL();
       
   344 		FillDefaultDatabaseL(testCount, ETrue);
       
   345 		ExtractFromDatabaseL();
       
   346 		testCount++;
       
   347 		iTestLib->CleanDatabaseL();
       
   348 		}
       
   349 
       
   350     //Test with Local floating time the replacement of existing child entry
       
   351     OpenCleanFileL();
       
   352     //Fill the database with entries in LocalFloating format and with August dates
       
   353     //to get difference between UTC and Local time
       
   354     FillDefaultDatabaseL(CTestData::EReplaceExistingChild, ETrue, ETrue);
       
   355     ExtractEntriesL(ETrue, 3);//check the entries count, it should be 3
       
   356 
       
   357 	//Test added for DEF069038
       
   358 	ExtractNonExistentEntryL();
       
   359 	}
       
   360 
       
   361 
       
   362 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       
   363  * DoTestL()
       
   364  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
       
   365 	
       
   366 static void DoTestL()
       
   367 	{
       
   368 	CDummyCalendarApp* app = CDummyCalendarApp::NewLC();
       
   369 	
       
   370 
       
   371 	TPerformanceTimer timer(test);
       
   372 	timer.Start();
       
   373 
       
   374 
       
   375 	// Run the test suite
       
   376 
       
   377 	app->DoTestL();
       
   378 	
       
   379 	
       
   380 	timer.Stop();
       
   381 	test.Printf(_L("Done\n"));
       
   382 	// printout performance time
       
   383 	timer.PrintOut();
       
   384 	
       
   385 
       
   386 	CleanupStack::PopAndDestroy(app);
       
   387 	}
       
   388 
       
   389 
       
   390 /**
       
   391 
       
   392 @SYMTestCaseID     PIM-TCAL-GSENTRY-0001
       
   393 
       
   394 */
       
   395 
       
   396 TInt E32Main()
       
   397     {
       
   398 	__UHEAP_MARK;
       
   399 
       
   400 	test.Start(_L("@SYMTESTCaseID:PIM-TCAL-GSENTRY-0001 Calendar Interim API Group Scheduling test suite"));
       
   401 
       
   402 	test.Title();
       
   403 
       
   404 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
   405 	if (!trapCleanup)
       
   406 		{
       
   407 		return KErrNoMemory;
       
   408 		}
       
   409 
       
   410 	CActiveScheduler* scheduler = new CActiveScheduler();
       
   411 	if (!scheduler)
       
   412 		{
       
   413 		delete trapCleanup;
       
   414 		return KErrNoMemory;
       
   415 		}
       
   416 	CActiveScheduler::Install(scheduler);	
       
   417 
       
   418 	TRAPD(ret, DoTestL());
       
   419 	test(ret == KErrNone);
       
   420 	
       
   421 	delete scheduler;
       
   422 	delete trapCleanup;	
       
   423 
       
   424 	test.End();
       
   425 	test.Close();
       
   426 
       
   427 	__UHEAP_MARKEND;
       
   428 
       
   429 	return (KErrNone);
       
   430     }
       
   431