pimappservices/calendar/tsrc/unit/src/TestCalInterimApiDCCreateEntries.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 "TestCalInterimApiDCCreateEntries.h"
       
    17 #include "TestCalInterimApiDefines.h"
       
    18 #include <fbs.h>
       
    19 #include <e32math.h>
       
    20 #include <calcategory.h>
       
    21 #include <caldataformat.h>
       
    22 
       
    23 _LIT8(KAlarmExportTestGUID1, "AlarmExportTestGUID1");
       
    24 _LIT8(KAlarmExportTestGUID2, "AlarmExportTestGUID2");
       
    25 _LIT8(KAlarmExportTestGUID3, "AlarmExportTestGUID3");
       
    26 
       
    27 CTestCalInterimApiDCCreateEntries::~CTestCalInterimApiDCCreateEntries()
       
    28 /**
       
    29  * Destructor
       
    30  */
       
    31 	{
       
    32 	delete iEntryView;
       
    33 	delete iSession;
       
    34 	}
       
    35 
       
    36 CTestCalInterimApiDCCreateEntries::CTestCalInterimApiDCCreateEntries()
       
    37 /**
       
    38  * Constructor
       
    39  */
       
    40 	{
       
    41 	SetTestStepName(KTestCalInterimApiDCCreateEntries);
       
    42 	}
       
    43 
       
    44 TVerdict CTestCalInterimApiDCCreateEntries::doTestStepPreambleL()
       
    45 	{
       
    46 	INFO_PRINTF1(_L("Start Alarm Exporting/Importing Tests"));
       
    47 	SetTestStepResult(EPass);
       
    48 	return TestStepResult();
       
    49 	}
       
    50 
       
    51 TVerdict CTestCalInterimApiDCCreateEntries::doTestStepPostambleL()
       
    52 	{
       
    53 	return TestStepResult();
       
    54 	}
       
    55 
       
    56 TVerdict CTestCalInterimApiDCCreateEntries::doTestStepL()
       
    57 	{
       
    58 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
    59 	CleanupStack::PushL(scheduler);  
       
    60 	CActiveScheduler::Install(scheduler);
       
    61 
       
    62 	iSession  = CCalSession::NewL();
       
    63 	
       
    64 	CTestCalInterimApiDCCallbackForAlarms* alarmCallback = CTestCalInterimApiDCCallbackForAlarms::NewL(this);
       
    65 	CleanupStack::PushL(alarmCallback); 
       
    66 
       
    67 	OpenSessionFileL();
       
    68 	iEntryView = CCalEntryView::NewL(*iSession,*alarmCallback);
       
    69 	
       
    70 	SetTestStepResult(EPass);
       
    71 	
       
    72 	CActiveScheduler::Add(alarmCallback);
       
    73 	CActiveScheduler::Start();
       
    74 	
       
    75 	
       
    76 	// We have an entry view now. We will create some entries, then export 
       
    77 	// them.
       
    78 	RPointerArray<CCalEntry> firstEntryArray;
       
    79 	CleanupStack::PushL(TCleanupItem(CloseAndDeleteRPtrArrayEntries, &firstEntryArray));
       
    80 
       
    81 	firstEntryArray.Reset();
       
    82 	TUint seqNo = 1;
       
    83 	TInt numEntriesToBeStored = 0;
       
    84 	
       
    85 	//
       
    86 	// Entry with no alarm
       
    87 	//
       
    88 	HBufC8* pGUID1= KAlarmExportTestGUID1().AllocLC();
       
    89 	CCalEntry* entry1 = CCalEntry::NewL(CCalEntry::EAppt, pGUID1,
       
    90 	                                    CCalEntry::EMethodAdd, seqNo);
       
    91 	CleanupStack::PushL(entry1);                                   
       
    92 	firstEntryArray.AppendL(entry1);
       
    93 	CleanupStack::Pop(entry1);
       
    94 
       
    95 	CleanupStack::Pop(pGUID1); // entry takes ownership
       
    96 	TDateTime entryStart1(2006, EMarch, 8, 10, 0, 0, 0);
       
    97 	TCalTime  calStart1;
       
    98 	calStart1.SetTimeLocalL(entryStart1);
       
    99 	TDateTime entryStop1(2006, EMarch, 8, 11, 0, 0, 0);
       
   100 	TCalTime calStop1;
       
   101 	calStop1.SetTimeLocalL(entryStop1);
       
   102 	entry1->SetStartAndEndTimeL(calStart1, calStop1);
       
   103 
       
   104 	numEntriesToBeStored++;
       
   105 	
       
   106 	//									
       
   107 	// Entry with basic alarm (sound) only
       
   108 	//
       
   109 	seqNo++;
       
   110 	HBufC8* pGUID2= KAlarmExportTestGUID2().AllocLC();
       
   111 	CCalEntry* entry2 = CCalEntry::NewL(CCalEntry::EAppt, pGUID2,
       
   112 	                                    CCalEntry::EMethodAdd, seqNo);
       
   113 	CleanupStack::PushL(entry2);
       
   114 	firstEntryArray.AppendL(entry2); 
       
   115 	CleanupStack::Pop(entry2);                                   
       
   116 	CleanupStack::Pop(pGUID2); // entry takes ownership
       
   117 	TDateTime entryStart2(2006, EMarch, 7, 10, 0, 0, 0);
       
   118 	TCalTime  calStart2;
       
   119 	calStart2.SetTimeLocalL(entryStart2);
       
   120 	TDateTime entryStop2(2006, EMarch, 7, 11, 0, 0, 0);
       
   121 	TCalTime calStop2;
       
   122 	calStop2.SetTimeLocalL(entryStop2);
       
   123 	entry2->SetStartAndEndTimeL(calStart2, calStop2);
       
   124 
       
   125 	CCalAlarm* alarm2 = CCalAlarm::NewL();
       
   126 	CleanupStack::PushL(alarm2);
       
   127 	alarm2->SetAlarmSoundNameL(_L("c:\\mysound"));
       
   128 	alarm2->SetTimeOffset(100);
       
   129 	entry2->SetAlarmL(alarm2);
       
   130 	numEntriesToBeStored++;
       
   131 
       
   132 	//
       
   133 	// Entry with Rich alarm (URL) only
       
   134 	//
       
   135 	seqNo++;
       
   136 	HBufC8* pGUID3= KAlarmExportTestGUID3().AllocLC();
       
   137 	CCalEntry* entry3 = CCalEntry::NewL(CCalEntry::EAppt, pGUID3,
       
   138 	                                    CCalEntry::EMethodAdd, seqNo);
       
   139 	CleanupStack::PushL(entry3);                                   
       
   140 	firstEntryArray.AppendL(entry3);
       
   141 	CleanupStack::Pop(entry3);
       
   142 	CleanupStack::Pop(pGUID3); // entry takes ownership
       
   143 	TDateTime entryStart3(2006, EApril, 7, 10, 0, 0, 0);
       
   144 	TCalTime  calStart3;
       
   145 	calStart3.SetTimeLocalL(entryStart3);
       
   146 	TDateTime entryStop3(2006, EApril, 7, 11, 0, 0, 0);
       
   147 	TCalTime calStop3;
       
   148 	calStop3.SetTimeLocalL(entryStop3);
       
   149 	entry3->SetStartAndEndTimeL(calStart3, calStop3);
       
   150 	                                    
       
   151 	                                    
       
   152 	CCalAlarm* alarm3 = CCalAlarm::NewL();
       
   153 	CleanupStack::PushL(alarm3);
       
   154 	_LIT8(KAlarmURL1, "http://www.symbian.com");
       
   155 	_LIT8(KAlarmURLType, "text/http");
       
   156 	
       
   157 	CCalContent* richData3 = CCalContent::NewL();
       
   158 	CleanupStack::PushL(richData3);
       
   159 	
       
   160 	HBufC8* urlContentBuf3 = HBufC8::NewL(KAlarmURL1().Length());
       
   161 	CleanupStack::PushL(urlContentBuf3);
       
   162 	*urlContentBuf3 = KAlarmURL1();
       
   163 	
       
   164 	HBufC8* urlTypeBuf3 = HBufC8::NewL(KAlarmURLType().Length());
       
   165 	CleanupStack::PushL(urlTypeBuf3);
       
   166 	*urlTypeBuf3 = KAlarmURLType();
       
   167 	
       
   168 	richData3->SetContentL(urlContentBuf3, urlTypeBuf3, CCalContent::EDispositionUrl);
       
   169 	CleanupStack::Pop(2, urlContentBuf3); // SetRichDataContentL takes ownership
       
   170 
       
   171 	alarm3->SetAlarmAction(richData3); //takes ownership
       
   172 	CleanupStack::Pop(richData3);
       
   173 	entry3->SetAlarmL(alarm3);
       
   174 	numEntriesToBeStored++;
       
   175 	
       
   176 
       
   177 	//store the entries and check
       
   178 	TInt numEntriesStored = 0;
       
   179 	iEntryView->StoreL(firstEntryArray, numEntriesStored);
       
   180 	if (numEntriesStored != numEntriesToBeStored)
       
   181 		{
       
   182 		_LIT(KEntryMatchErr, "Num Entries Stored (%d) does not match num entries created (%d)");
       
   183 		INFO_PRINTF3(KEntryMatchErr, numEntriesStored, numEntriesToBeStored);
       
   184 		CleanupStack::PopAndDestroy(5, scheduler);
       
   185 		SetTestStepResult(EFail);
       
   186 		return TestStepResult();
       
   187 		}
       
   188 	
       
   189 
       
   190 	CleanupStack::PopAndDestroy(5, scheduler);
       
   191 	
       
   192 	return TestStepResult();
       
   193 	}
       
   194 
       
   195 	
       
   196 
       
   197 
       
   198 
       
   199 void CTestCalInterimApiDCCreateEntries::OpenSessionFileL()
       
   200 	{
       
   201 	TBuf<MAX_TEXT_MESSAGE> buffer;
       
   202 	buffer.Format(KCreateNewAgendaFile, &KAgendaFile);
       
   203 	INFO_PRINTF1(buffer);
       
   204 	TRAPD(err, iSession->CreateCalFileL(KAgendaFile));
       
   205 	if (KErrAlreadyExists==err)
       
   206 		{
       
   207 		iSession->DeleteCalFileL(KAgendaFile);
       
   208 		iSession->CreateCalFileL(KAgendaFile);	
       
   209 		}
       
   210 	iSession->OpenL(KAgendaFile());
       
   211 	}
       
   212 
       
   213 
       
   214 void CTestCalInterimApiDCCreateEntries::CloseAndDeleteRPtrArrayEntries(TAny* aObject)	
       
   215 	{
       
   216 	RPointerArray<CCalEntry>* array=REINTERPRET_CAST(RPointerArray<CCalEntry>*,aObject);
       
   217 
       
   218 	TInt count = array->Count();
       
   219 	for (TInt i=0; i < count; i++)
       
   220 		{
       
   221 		delete (*array)[i];
       
   222 		}
       
   223 	array->Close();
       
   224 	}
       
   225 
       
   226 void CTestCalInterimApiDCCreateEntries::CloseAndDeleteRPtrArrayAlarms(TAny* aObject)	
       
   227 	{
       
   228 	RPointerArray<CCalAlarm>* array=REINTERPRET_CAST(RPointerArray<CCalAlarm>*,aObject);
       
   229 
       
   230 	TInt count = array->Count();
       
   231 	for (TInt i=0; i < count; i++)
       
   232 		{
       
   233 		delete (*array)[i];
       
   234 		}
       
   235 	array->Close();
       
   236 	}
       
   237 
       
   238 CTestCalInterimApiDCCallbackForAlarms* CTestCalInterimApiDCCallbackForAlarms::NewL(CTestCalInterimApiDCCreateEntries* aParent)
       
   239 	{
       
   240 	CTestCalInterimApiDCCallbackForAlarms* self = new (ELeave) CTestCalInterimApiDCCallbackForAlarms(aParent);
       
   241 	return self;
       
   242 	}
       
   243 	
       
   244 CTestCalInterimApiDCCallbackForAlarms::~CTestCalInterimApiDCCallbackForAlarms()
       
   245 	{
       
   246 	Cancel();
       
   247 	}
       
   248 
       
   249 CTestCalInterimApiDCCallbackForAlarms::CTestCalInterimApiDCCallbackForAlarms(CTestCalInterimApiDCCreateEntries* aParent)
       
   250 	: CActive(EPriorityHigh), iTestCalInterimApiSuiteStep(aParent)
       
   251 	{
       
   252 	}
       
   253     
       
   254 void CTestCalInterimApiDCCallbackForAlarms::Start()
       
   255 	{
       
   256 	if (!IsActive())
       
   257 		{
       
   258 		SetActive();
       
   259 		}	
       
   260 
       
   261 	TRequestStatus* status = &iStatus;
       
   262 	User::RequestComplete(status,KErrNone);
       
   263 	}
       
   264 
       
   265 void CTestCalInterimApiDCCallbackForAlarms::Progress(TInt /*aPercentageCompleted*/)
       
   266 	{
       
   267 	}
       
   268 	
       
   269 void CTestCalInterimApiDCCallbackForAlarms::Completed(TInt /*aComplete*/)
       
   270 	{
       
   271 	Start();
       
   272 	}
       
   273 	
       
   274 TBool CTestCalInterimApiDCCallbackForAlarms::NotifyProgress()
       
   275 	{
       
   276 	return ETrue;
       
   277 	}
       
   278 	
       
   279  void CTestCalInterimApiDCCallbackForAlarms::DoCancel()
       
   280 	{
       
   281 	Close();
       
   282 	}
       
   283 	
       
   284 void CTestCalInterimApiDCCallbackForAlarms::RunL()
       
   285 	{
       
   286 	Close();
       
   287 	}
       
   288 	
       
   289 void CTestCalInterimApiDCCallbackForAlarms::Close()
       
   290 	{
       
   291 	CActiveScheduler::Stop();
       
   292 	}
       
   293 
       
   294