commonappservices/alarmservertest/TestMultipleAlarmsSuite/src/TestCleanupStep.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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 // Contains implementation of CTestCleanupStep class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // User Includes
       
    24 #include "TestCleanupStep.h"
       
    25 #include "ProgressCallBack.h"
       
    26 
       
    27 // System Includes
       
    28 #include <asclisession.h>
       
    29 
       
    30 #ifdef SYMBIAN_CALENDAR_V2
       
    31 #include <calalarm.h>
       
    32 #else
       
    33 #include <agmalarm.h>
       
    34 #endif
       
    35 
       
    36 /**
       
    37 Constructor. Sets the test step name. Testserver reference passed to make use 
       
    38 of TEF's method of sharing data between test steps
       
    39 @internalTechnology
       
    40 @test
       
    41 */
       
    42 CTestCleanupStep::CTestCleanupStep(CTestMultipleAlarmsServer& aTestServer) 
       
    43 : CTestBaseStep(aTestServer)
       
    44 	{
       
    45 	//Call base class method to set human readable name for test step
       
    46 	SetTestStepName(KTestCleanupStep);
       
    47 	}
       
    48 
       
    49 /**
       
    50 Base class pure virtual.
       
    51 @return		EPass or EFail indicating the result of the test step.
       
    52 @internalTechnology
       
    53 @test
       
    54 */
       
    55 TVerdict CTestCleanupStep::doTestStepL()
       
    56 	{
       
    57 	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
       
    58 	CActiveScheduler::Install(sched);
       
    59 	
       
    60 	TRAPD(error, DoCleanupL());
       
    61 	PrintIfError(error);
       
    62 	
       
    63 	delete sched;
       
    64 	return TestStepResult();
       
    65 	}
       
    66 	
       
    67 /**
       
    68 Calls the cleanup functions
       
    69 @internalTechnology
       
    70 @test
       
    71 */
       
    72 void CTestCleanupStep::DoCleanupL()
       
    73 	{
       
    74 	CCalSession* calSession = NULL;
       
    75 	TRAPD(error, calSession = CreateAndInitializeCalSessionL(EFalse));
       
    76 	
       
    77 	if(error == KErrNone)
       
    78 		{
       
    79 		CleanupStack::PushL(calSession);
       
    80 		CCalEntryView* calEntryView = CreateEntryViewL(calSession);
       
    81 		CleanupStack::PushL(calEntryView);
       
    82 	
       
    83 		DeleteCalEntriesL(calEntryView);
       
    84 	
       
    85 		CleanupStack::PopAndDestroy(2, calSession);	// calEntryView and calSession
       
    86 		}
       
    87 	
       
    88 	if(TestServer()->AlertServer())
       
    89 		{
       
    90 		DeleteAlarmsL();	
       
    91 		}
       
    92 	}
       
    93 		
       
    94 /**
       
    95 Cleans up all the calendar entries. As the tests deal only with imminent alarms
       
    96 this function makes an assumption and cleans up all the entries that are due 
       
    97 between the time-range of last year to next year
       
    98 @internalTechnology
       
    99 @test
       
   100 */
       
   101 void CTestCleanupStep::DeleteCalEntriesL(CCalEntryView* aCalEntryView)
       
   102 	{
       
   103 	// Initialize time range to last year - next year
       
   104 	TTime now;
       
   105 	now.HomeTime();
       
   106 	TCalTime startTime;
       
   107 	TCalTime endTime;
       
   108 	startTime.SetTimeLocalL(now - TTimeIntervalYears(1));
       
   109 	endTime.SetTimeLocalL(now + TTimeIntervalYears(1));
       
   110 	CalCommon::TCalTimeRange calTimeRange(startTime, endTime);
       
   111 	
       
   112 	TRequestStatus status;
       
   113 	CProgressCallBack* progress = new (ELeave) CProgressCallBack(status);
       
   114 	CleanupStack::PushL(progress);
       
   115 
       
   116 	// Delete entries
       
   117 	aCalEntryView->DeleteL(calTimeRange, CalCommon::EIncludeAll, *progress);
       
   118 
       
   119 	// Wait till delete is over
       
   120 	StartActiveSchedAndWaitL(status);
       
   121 	
       
   122 	CleanupStack::PopAndDestroy(progress);
       
   123 	}
       
   124 	
       
   125 /**
       
   126 Cleans up all the alarms created by the agenda engine
       
   127 @internalTechnology
       
   128 @test
       
   129 */
       
   130 void CTestCleanupStep::DeleteAlarmsL() 
       
   131 	{
       
   132 	// Connect to the Alarm Server
       
   133 	RASCliSession asCliSession;
       
   134 	asCliSession = RASCliSession();
       
   135 	User::LeaveIfError(asCliSession.Connect());
       
   136 	User::LeaveIfError(asCliSession.AlarmDeleteAllByCategory(KUidAgendaModelAlarmCategory, EFalse));
       
   137 	asCliSession.Close();
       
   138 	}