buildverification/smoketest/agenda/Src/TestAgendaAddAppt.cpp
branchRCL_3
changeset 10 4ca382093dae
parent 5 6beaa9cf4752
child 11 493058e57c8c
equal deleted inserted replaced
5:6beaa9cf4752 10:4ca382093dae
     1 // Copyright (c) 2006-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 // This contains CTestAgendaAddAppt
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <test/testexecuteclient.h>
       
    19 #include <calentry.h>
       
    20 #include <calalarm.h> 
       
    21 
       
    22 
       
    23 #include "TestAgendaAddAppt.h"
       
    24 
       
    25 _LIT(KCount,		"count");
       
    26 _LIT(KYear,			"year%d");
       
    27 _LIT(KMonth,		"month%d");
       
    28 _LIT(KDay,			"day%d");
       
    29 _LIT(KHour,			"hour%d");
       
    30 _LIT(KMinute,		"min%d");
       
    31 _LIT(KDuration,		"duration%d");
       
    32 _LIT(KMessage,		"message%d");
       
    33 _LIT(KAlarm,		"alarm%d");
       
    34 _LIT(KAlarmSound,	"alarmsound%d");
       
    35 
       
    36 // constructor
       
    37 CTestAgendaAddAppt::CTestAgendaAddAppt()
       
    38 	{
       
    39 	SetTestStepName(_L("AddAppt"));
       
    40 	}
       
    41 
       
    42 // destructor
       
    43 CTestAgendaAddAppt::~CTestAgendaAddAppt()
       
    44 	{
       
    45 	}
       
    46 
       
    47 // Each test step must supply a implementation for doTestStepL
       
    48 enum TVerdict CTestAgendaAddAppt::doTestStepL( void )
       
    49 	{
       
    50 	// Printing to the console and log file
       
    51 	INFO_PRINTF1(_L("TEST-> ADDING APPOINTMENT ENTRIES"));
       
    52 
       
    53 	OpenDatabaseL();
       
    54 	if ( TestStepResult() == EPass )
       
    55 		{
       
    56 		TRAPD(r, AddEntriesL());
       
    57 		if (r!=KErrNone)
       
    58 			SetTestStepResult(EFail);
       
    59 		}
       
    60 	CleanupDatabase();
       
    61 
       
    62 	// test steps return a result
       
    63 	return TestStepResult();
       
    64 	}
       
    65 	
       
    66 // Destroy the RPointerArray
       
    67 void DestroyRPointerArray(TAny* aPtr)
       
    68         {
       
    69         RPointerArray<CCalEntry>* self = static_cast<RPointerArray<CCalEntry>*> (aPtr);
       
    70         self->ResetAndDestroy();
       
    71         }
       
    72 
       
    73 
       
    74 void CTestAgendaAddAppt::AddEntriesL( void )
       
    75 	{
       
    76 	TInt	count=1;
       
    77 	if ( !GetIntFromConfig(ConfigSection(), KCount, count) )
       
    78 		count=1;
       
    79 
       
    80 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
    81 	TInt	year;
       
    82 	TInt	month;
       
    83 	TInt	day;
       
    84 	TInt	hour;
       
    85 	TInt	minute;
       
    86 	TInt	duration;
       
    87 	TInt	alarm;
       
    88 	TPtrC	ptrAlarmSound;
       
    89 	TPtrC	ptrMessage;
       
    90 	TBuf<KMaxDateStringLength> dateString;
       
    91 	_LIT(KDateString,"%*E%*D%X%*N%*Y %1 %2 '%3");
       
    92 
       
    93 	RPointerArray<CCalEntry> array;
       
    94     CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array));
       
    95 
       
    96 	for (TInt entry=0; entry<count && TestStepResult() == EPass; )
       
    97 		{
       
    98 		TTime	today;
       
    99 		today.HomeTime();
       
   100 
       
   101 		tempStore.Format(KYear(), ++entry);
       
   102 		if ( !GetIntFromConfig(ConfigSection(), tempStore, year) )
       
   103 			year=today.DateTime().Year();
       
   104 
       
   105 		tempStore.Format(KMonth(), entry);
       
   106 		if ( !GetIntFromConfig(ConfigSection(), tempStore, month) )
       
   107 			month=today.DateTime().Month();
       
   108 
       
   109 		tempStore.Format(KDay(), entry);
       
   110 		if ( !GetIntFromConfig(ConfigSection(), tempStore, day) )
       
   111 			day=today.DateTime().Day();
       
   112 		else
       
   113 			--day;
       
   114 
       
   115 		tempStore.Format(KHour(), entry);
       
   116 		if ( !GetIntFromConfig(ConfigSection(), tempStore, hour) )
       
   117 			hour=today.DateTime().Hour();
       
   118 
       
   119 		tempStore.Format(KMinute(), entry);
       
   120 		if ( !GetIntFromConfig(ConfigSection(), tempStore, minute) )
       
   121 			minute=0;
       
   122 
       
   123 		tempStore.Format(KDuration(), entry);
       
   124 		if ( !GetIntFromConfig(ConfigSection(), tempStore, duration) )
       
   125 			duration=30;
       
   126 
       
   127 		tempStore.Format(KMessage(), entry);
       
   128 		GetStringFromConfig(ConfigSection(), tempStore, ptrMessage);
       
   129 
       
   130 		TTime		startTime(TDateTime(year, TMonth(month-1+EJanuary), day, hour, minute,0,0));
       
   131 		startTime.FormatL(dateString,KDateString);
       
   132 	  	INFO_PRINTF2(_L("Start date is  %S"), &dateString);
       
   133 
       
   134 		TTime		endTime = startTime + TTimeIntervalMinutes(duration);
       
   135 		endTime.FormatL(dateString,KDateString);
       
   136 	  	INFO_PRINTF2(_L("End date is  %S"), &dateString);
       
   137 
       
   138 		
       
   139 		HBufC8* uid = HBufC8::NewLC(255);
       
   140 		TPtr8 uidP = uid->Des();
       
   141 		uidP.Append(count);
       
   142 		
       
   143 		CCalEntry* calEntry = CCalEntry::NewL(CCalEntry::EAppt, uid, CCalEntry::EMethodNone, 0);
       
   144 		
       
   145 		CleanupStack::Pop(); //uid
       
   146 		CleanupStack::PushL(calEntry);
       
   147 		
       
   148 		TCalTime calStartTime, calEndTime;
       
   149 		
       
   150 		calStartTime.SetTimeLocalL(startTime);
       
   151 		calEndTime.SetTimeLocalL(endTime);
       
   152 		
       
   153 		calEntry->SetStartAndEndTimeL(calStartTime, calEndTime);
       
   154 		
       
   155 		tempStore.Format(KAlarm(), entry);
       
   156 		if ( GetIntFromConfig(ConfigSection(), tempStore, alarm) )
       
   157 			{
       
   158 			TTimeIntervalMinutes	currentTime((hour*60) + minute);
       
   159 			TTimeIntervalMinutes	alarmTime(currentTime.Int());
       
   160 			
       
   161 			CCalAlarm* calAlarm = CCalAlarm::NewL();
       
   162 			CleanupStack::PushL(calAlarm);
       
   163 			
       
   164 			calAlarm->SetTimeOffset(alarmTime);
       
   165 			
       
   166 			tempStore.Format(KAlarmSound(), entry);
       
   167 			if ( GetStringFromConfig(ConfigSection(), tempStore, ptrAlarmSound) )
       
   168 				calAlarm->SetAlarmSoundNameL(ptrAlarmSound);
       
   169 			else
       
   170 				calAlarm->SetAlarmSoundNameL(_L("Bells"));
       
   171 			
       
   172 			calEntry->SetAlarmL(calAlarm);
       
   173 			CleanupStack::PopAndDestroy(); //calAlarm
       
   174 			}
       
   175 		//Store in the array
       
   176 		array.AppendL(calEntry);
       
   177 		
       
   178 		CleanupStack::Pop(); //calEntry
       
   179 		}
       
   180 		INFO_PRINTF1(_L("About to store appointments now"));
       
   181 		TInt success(0);
       
   182 		TRAPD(storeError, iCalEntryViewBase->StoreL(array, success));
       
   183 		INFO_PRINTF2(_L("Store result is %d"), storeError);
       
   184 		if (success != count && storeError == KErrNone)
       
   185 		    {
       
   186 			SetTestStepResult(EFail);
       
   187 		    } 
       
   188 		
       
   189 		CleanupStack::PopAndDestroy(&array);
       
   190 		
       
   191 	}