pimappservices/calendar/tsrc/t_recurrence.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 <f32file.h>
       
    18 #include <s32file.h>
       
    19 
       
    20 #include <calentry.h>
       
    21 #include <caldataexchange.h>
       
    22 #include <caldataformat.h>
       
    23 #include <calrrule.h>
       
    24 
       
    25 #include "caltestlib.h"
       
    26 #include "t_recurrence.h"
       
    27 
       
    28 _LIT(KTestFile, "c:t_recurrence");
       
    29 
       
    30 static RTest test(_L("t_recurrence"));
       
    31 	
       
    32 CTestApp* CTestApp::NewL()
       
    33 	{
       
    34 	CTestApp* self = new(ELeave) CTestApp;
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL();
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}	
       
    40 	
       
    41 void CTestApp::ConstructL()
       
    42 	{
       
    43 	iCalTestLib = CCalTestLibrary::NewL();
       
    44 	iCalTestLib->ReplaceFileL(KTestFile());
       
    45 	iCalTestLib->OpenFileL(KTestFile());
       
    46 	}
       
    47 	
       
    48 CTestApp::~CTestApp()
       
    49 	{
       
    50 	delete iCalTestLib;
       
    51 	}
       
    52 
       
    53 
       
    54 void CTestApp::RunTestL(const TDesC8& aVCalFile, TInt aNumberOfOccurences, TTime aEndTime, TBool aExpectedImport)
       
    55 	{
       
    56 	test.Next(_L("Import repeat rule test"));
       
    57 
       
    58 	RPointerArray<CCalEntry> entryArray;
       
    59 	CleanupResetAndDestroyPushL(entryArray);
       
    60 	iCalTestLib->ImportL(aVCalFile, entryArray);//31 Jan, 31 Mar, 31 May, 31 July, 31 Jan 5 matched months but last 7 months to reach the end so agnmodel returns 7
       
    61 	
       
    62 	if (aExpectedImport)
       
    63 		{
       
    64 		test.Printf(_L("Impoted %d entries\n"), entryArray.Count());
       
    65 		test(entryArray.Count() == 1);
       
    66 		
       
    67 		test.Printf(entryArray[0]->SummaryL());
       
    68 
       
    69 		TCalRRule rRule;
       
    70 		
       
    71 		if (aNumberOfOccurences == 0)
       
    72 			{
       
    73 			test (entryArray[0]->GetRRuleL(rRule));
       
    74 			test(rRule.Count() == 0);
       
    75 			test(rRule.Until().TimeLocalL() == TCalTime::MaxTime());
       
    76 			}
       
    77 		else if (aNumberOfOccurences > 1)
       
    78 			{	
       
    79 			test (entryArray[0]->GetRRuleL(rRule));
       
    80 			TInt instances = rRule.Count();
       
    81 
       
    82 			test.Printf( _L("Instances found %d\n"), instances);
       
    83 			test(instances == aNumberOfOccurences);
       
    84 			
       
    85 			TDateTime dt(rRule.Until().TimeLocalL().DateTime());
       
    86 		
       
    87 			test.Printf(_L("The end time of the repeat rule is %d:%d %d/%d/%d \n"), dt.Hour(), dt.Minute(), dt.Day(), dt.Month(), dt.Year());
       
    88 				
       
    89 			if(aEndTime != Time::NullTTime())
       
    90 				{
       
    91 				test(rRule.Until().TimeLocalL() == aEndTime);
       
    92 				}
       
    93 			}
       
    94 		else
       
    95 			{
       
    96 			test(!entryArray[0]->GetRRuleL(rRule));
       
    97 			test.Printf(_L("The repeat was not added because the second instance was passed max date.\n"));	
       
    98 			}
       
    99 			
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		test(entryArray.Count() == 0);
       
   104 		}
       
   105 	
       
   106 	CleanupStack::PopAndDestroy(&entryArray);
       
   107 	}
       
   108 
       
   109 static void RunTestsL()
       
   110 	{
       
   111 	CTestApp* testApp = CTestApp::NewL();
       
   112 	CleanupStack::PushL(testApp);
       
   113 
       
   114 	testApp->RunTestL(KWeekly,				KWeeklyCount,				Time::NullTTime(),		1);
       
   115 	testApp->RunTestL(KMonthlyByDate1,		KMonthlyByDateCount1,		Time::NullTTime(), 		1);
       
   116 	testApp->RunTestL(KMonthlyByDate2,		KMonthlyByDateCount2,		Time::NullTTime(), 		1);
       
   117 	testApp->RunTestL(KMonthlyByDate3,		KMonthlyByDateCount3,		Time::NullTTime(), 		1);
       
   118 	testApp->RunTestL(KMonthlyByDays1,		KMonthlyByDaysCount1,		Time::NullTTime(), 		1);
       
   119 	testApp->RunTestL(KMonthlyByDays2,		KMonthlyByDaysCount2, 		Time::NullTTime(), 		1);
       
   120 	testApp->RunTestL(KMonthlyByDays3,		KMonthlyByDaysCount3,		Time::NullTTime(), 		1);
       
   121 	testApp->RunTestL(KYearlyByDate1, 		KYearlyByDateCount1,		Time::NullTTime(), 		1);
       
   122 	testApp->RunTestL(KYearlyByDate2, 		KYearlyByDateCount2,		Time::NullTTime(), 		1);
       
   123 	testApp->RunTestL(KYearlyByDate3, 		KYearlyByDateCount3,		Time::NullTTime(), 		1);
       
   124 	testApp->RunTestL(KMonthlyByDates31,	KMonthlyByDates31Count,		Time::NullTTime(), 		1);
       
   125 	
       
   126 	// Test importing repeats that pass the agenda max time
       
   127 	testApp->RunTestL(KDailyOver1,			KDailyOverCount1,			Time::NullTTime(), 		1);
       
   128 	testApp->RunTestL(KDailyOver2,			KDailyOverCount2,			Time::NullTTime(), 		0);
       
   129 	testApp->RunTestL(KMonthlyByDateOver1,	KMonthlyByDateOverCount1,	KMonthlyByDateOverEndDay1, 		1);
       
   130 	testApp->RunTestL(KMonthlyByDateOver2,	KMonthlyByDateOverCount2,	Time::NullTTime(), 		1);
       
   131 	testApp->RunTestL(KYearlyByDateOver1,	KYearlyByDateOverCount1,	Time::NullTTime(), 		1);
       
   132 	testApp->RunTestL(KYearlyByDateOver2,	KYearlyByDateOverCount2,	Time::NullTTime(), 		1);
       
   133 	testApp->RunTestL(KWeeklyOver1,			KWeeklyOverCount1,			Time::NullTTime(), 		1);
       
   134 	testApp->RunTestL(KWeeklyOver2,			KWeeklyOverCount2,			Time::NullTTime(), 		1);
       
   135 	testApp->RunTestL(KAfterMaxDate,		KAfterMaxDateCount,			Time::NullTTime(), 		0);
       
   136 	
       
   137 	CleanupStack::PopAndDestroy(testApp);
       
   138 	}
       
   139 
       
   140 
       
   141 /**
       
   142 
       
   143 @SYMTestCaseID     PIM-T-RECURRENCE-0001
       
   144 
       
   145 */
       
   146 
       
   147 TInt E32Main()
       
   148 	{
       
   149 	__UHEAP_MARK;
       
   150 	test.Start(_L("@SYMTESTCaseID:PIM-T-RECURRENCE-0001 t_recurrence"));
       
   151 
       
   152 	test.Title();
       
   153 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   154 	CActiveScheduler::Install(scheduler);
       
   155 	
       
   156 	CTrapCleanup* cleanupTrap = CTrapCleanup::New();
       
   157 	
       
   158 	TRAPD(ret, RunTestsL());
       
   159 	test(ret==KErrNone);
       
   160 	
       
   161 	delete cleanupTrap;
       
   162 	delete scheduler;
       
   163 	
       
   164 	test.End();
       
   165 	test.Close();
       
   166 	
       
   167 	__UHEAP_MARKEND;
       
   168 	return KErrNone;
       
   169 	}
       
   170 
       
   171