commonappservices/alarmservertest/TestMultipleAlarmsSuite/src/TestAlarmContentOOMStep.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 CTestAlarmContentOOMStep class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // User Include
       
    24 #include "TestAlarmContentOOMStep.h"
       
    25 
       
    26 // System Include
       
    27 #include <calalarm.h>
       
    28 
       
    29 /**
       
    30 Constructor. Sets the test step name. Testserver reference passed to make use 
       
    31 of TEF's method of sharing data between test steps
       
    32 @internalTechnology
       
    33 @test
       
    34 */
       
    35 CTestAlarmContentOOMStep::CTestAlarmContentOOMStep(CTestMultipleAlarmsServer& aTestServer) 
       
    36 : CTestAssociatedDataStep(aTestServer)
       
    37 	{
       
    38 	//Call base class method to set human readable name for test step
       
    39 	SetTestStepName(KTestAlarmContentOOMStep);
       
    40 	}
       
    41 
       
    42 /**
       
    43 Base class pure virtual.
       
    44 @return		EPass or EFail indicating the result of the test step.
       
    45 @internalTechnology
       
    46 @test
       
    47 */
       
    48 TVerdict CTestAlarmContentOOMStep::doTestStepL()
       
    49 	{
       
    50 	TestOOML();
       
    51 	return TestStepResult();
       
    52 	}
       
    53 	
       
    54 /**
       
    55 Tests accessing the calendar entry and retreiving the alarm content
       
    56 in an OOM loop
       
    57 @internalTechnology
       
    58 @test
       
    59 */	
       
    60 void CTestAlarmContentOOMStep::TestOOML()
       
    61 	{
       
    62 	TInt error = KErrNone;
       
    63 	TInt failRate = 0;
       
    64 	do
       
    65 		{// The OOM loop
       
    66 		++failRate;
       
    67 		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
       
    68 		__UHEAP_MARK;
       
    69 		
       
    70 		// Do the tests
       
    71 		TRAP(error, GetAllAlarmContentsL());
       
    72 		
       
    73 		__UHEAP_MARKEND;
       
    74 		__UHEAP_RESET;
       
    75 		
       
    76 		if(error != KErrNone && error != KErrNoMemory)
       
    77 			{
       
    78 			INFO_PRINTF3(_L("Unexpected error occured in %S: %D"), &TestStepName(), error);
       
    79 			SetTestStepResult(EFail);
       
    80 			break;
       
    81 			}
       
    82 		}while(error != KErrNone);
       
    83 	}
       
    84 	
       
    85 /**
       
    86 Retreives all the alarm control objects, that the alert server is 
       
    87 maintaining currently and does the test
       
    88 @internalTechnology
       
    89 @test
       
    90 */	
       
    91 void CTestAlarmContentOOMStep::GetAllAlarmContentsL()
       
    92 	{
       
    93 	RPointerArray<MEikServAlarm> alarmControlList = TestServer()->AlarmControlsManager()->GetAlarmControlListL();
       
    94 	for(TInt index = 0; index < alarmControlList.Count(); ++index)
       
    95 		{
       
    96 		CDummyAlarmControl* alarmControl = dynamic_cast<CDummyAlarmControl*>(alarmControlList[index]);
       
    97 		DoGetAlarmContentL(alarmControl);
       
    98 		}
       
    99 	}
       
   100 	
       
   101 /**
       
   102 Accesses the calendar entry associated with the alarm control object, and
       
   103 retrieves its alarm content
       
   104 @internalTechnology
       
   105 @test
       
   106 */	
       
   107 void CTestAlarmContentOOMStep::DoGetAlarmContentL(CDummyAlarmControl* aAlarmControl)
       
   108 	{
       
   109 	CCalEntryId* entryId = NULL;
       
   110 	if(GetEntryIdL(aAlarmControl->AlarmMessage(), entryId))
       
   111 		{
       
   112 		CCalEntry* calEntry = NULL;
       
   113 		CleanupStack::PushL(entryId);
       
   114 		
       
   115 		CCalSession* calSession = CreateAndInitializeCalSessionL(EFalse);
       
   116 		CleanupStack::PushL(calSession);
       
   117 		
       
   118 		if(!GetCalEntryL(entryId, calEntry, calSession))
       
   119 			{// An unexpected situation, that must not occur
       
   120 			ERR_PRINTF2(_L("The calendar entry was not found for %S. Failing the test..."), &(aAlarmControl->AlarmMessage()));
       
   121 			SetTestStepResult(EFail);
       
   122 			}
       
   123 		else
       
   124 			{
       
   125 			CleanupStack::PushL(calEntry);
       
   126 			
       
   127 			// Get the alarm content
       
   128 			CCalAlarm* alarm = calEntry->AlarmL();
       
   129 			
       
   130 			// Do nothing with it. Clean up.
       
   131 			CleanupStack::PopAndDestroy(calEntry);	
       
   132 			delete alarm;
       
   133 			}
       
   134 		CleanupStack::PopAndDestroy(2, entryId); // calSession, entryId
       
   135 		}
       
   136 		
       
   137 	}