os/persistentdata/featuremgmt/featuremgr/test/shared/src/efm_featurenotifierstepbase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/test/shared/src/efm_featurenotifierstepbase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,191 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Implementation of the base class for capability aware test steps. 
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalComponent
    1.24 + @test
    1.25 +*/
    1.26 +
    1.27 +#include "efm_featurenotifierstepbase.h"
    1.28 +
    1.29 +static TInt WaitCallBack( TAny* aSelf )
    1.30 +	{
    1.31 +	if( aSelf )
    1.32 +		{
    1.33 +		TWaitInfo* info = static_cast<TWaitInfo*>( aSelf );
    1.34 +		if( info->iPeriodic )
    1.35 +			{
    1.36 +			info->iPeriodic->Cancel();
    1.37 +			}
    1.38 +		if( info->iWait )
    1.39 +			{
    1.40 +			if( info->iWait->IsStarted() )
    1.41 +				{
    1.42 +				info->iWait->AsyncStop();
    1.43 +				}
    1.44 +			}
    1.45 +		}
    1.46 +	
    1.47 +	return KErrNone;
    1.48 +	}
    1.49 +
    1.50 +
    1.51 +void CFeatureNotifierStepBase::WaitL( TInt aIntervalInMicorseconds )
    1.52 +	{
    1.53 +	TWaitInfo info;
    1.54 +	
    1.55 +	// Construct periodic
    1.56 +	CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityStandard );
    1.57 +	CleanupStack::PushL( periodic );
    1.58 +	info.iPeriodic = periodic;
    1.59 +	
    1.60 +	// Construct active scheduler wait
    1.61 +	CActiveSchedulerWait* wait = new( ELeave ) CActiveSchedulerWait;
    1.62 +	CleanupStack::PushL( wait );
    1.63 +	info.iWait = wait;
    1.64 +	iWait = wait;
    1.65 +	
    1.66 +	// Start timer and wait
    1.67 +	TCallBack cb( WaitCallBack, &info );
    1.68 +	periodic->Start( aIntervalInMicorseconds, aIntervalInMicorseconds, cb );
    1.69 +	wait->Start();
    1.70 +	
    1.71 +	// Cleanup
    1.72 +	CleanupStack::PopAndDestroy( wait );
    1.73 +	CleanupStack::PopAndDestroy( periodic );
    1.74 +	}
    1.75 +
    1.76 +
    1.77 +TVerdict CFeatureNotifierStepBase::doTestStepPreambleL(void)
    1.78 +	{
    1.79 +	CEFMConfigurableTestStepBase::doTestStepPreambleL();
    1.80 +	iSched= new(ELeave) CActiveScheduler;
    1.81 +	CActiveScheduler::Install(iSched);		
    1.82 +	TInt err = icontrol.Open();
    1.83 +	TESTDIAGNOSTICERROR(err==KErrNone, 
    1.84 +		 _L("RFeatureControl::Open failed: error = %d"), err);
    1.85 +	return TestStepResult();
    1.86 +	}
    1.87 +
    1.88 +TVerdict CFeatureNotifierStepBase::doTestStepPostambleL(void)
    1.89 +	{
    1.90 +	CEFMConfigurableTestStepBase::doTestStepPostambleL();
    1.91 +	CActiveScheduler::Install(NULL);
    1.92 +	delete iSched;
    1.93 +	icontrol.Close();
    1.94 +	return TestStepResult();		
    1.95 +	}
    1.96 +
    1.97 +
    1.98 +void CFeatureNotifierStepBase :: HandleNotifyChange( TFeatureChangeType /* aType */ , TFeatureEntry /* aFeature */ )
    1.99 +	{
   1.100 +	iWait->AsyncStop();
   1.101 +	iNotifyCompleted = ETrue;	
   1.102 +	}
   1.103 +	
   1.104 +void CFeatureNotifierStepBase:: HandleNotifyError( TInt aError )
   1.105 +   {
   1.106 +   INFO_PRINTF2(_L("CFeatureNotifier::HandleNotifyError %d"),aError);
   1.107 +   SetTestStepResult(EFail);
   1.108 +   }
   1.109 +
   1.110 +
   1.111 +void CFeatureNotifierStepBase::CheckNotifyRequestResultL(TUid aUid)
   1.112 +	{
   1.113 +	TInt err = icontrol.SetFeature( aUid, KChangeData );
   1.114 +	WaitL(KWaitDelay);
   1.115 +	if (iLowCap)	   
   1.116 +	   {
   1.117 +	   //if we are running in the low capabilities environment we don't expect the feature 
   1.118 +	   //to be modified and notification to be issued
   1.119 +	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   1.120 +			  _L("RFeatureControl::SetFeature - KErrPermissionDenied expected; error = %d"),err);	   
   1.121 +	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   1.122 +			  _L("Feature notification should not be issued due to insufficient capabilities"));
   1.123 +	   }
   1.124 +	else
   1.125 +	   {
   1.126 +		//if test environment has WDD capability then SetFeature should succeed and feature 
   1.127 +		//change notification should be issued
   1.128 +	   TESTDIAGNOSTICERROR(err == KErrNone,
   1.129 +				  _L("RFeatureControl::SetFeature - KErrNone expected; error = %d"),err);	   
   1.130 +	   TESTDIAGNOSTIC(iNotifyCompleted,	   
   1.131 +				  _L("Feature notification is expected to be issued"));
   1.132 +	   }
   1.133 +	}
   1.134 +
   1.135 +void CFeatureNotifierStepBase::CheckNotifyCancelResultL(TUid aUid)
   1.136 +	{
   1.137 +	TInt err = icontrol.SetFeature( aUid, KChangeData );
   1.138 +	WaitL(KWaitDelay);
   1.139 +	if (iLowCap)	   
   1.140 +	   {
   1.141 +	   //if we are running in the low capabilities environment we don't expect the feature 
   1.142 +	   //to be modified and notification to be issued
   1.143 +	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   1.144 +			_L("RFeatureControl::SetFeature - KErrPermissionDenied expected; error = %d"),err);
   1.145 +	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   1.146 +			_L("Feature notification should not be issued due to insufficient capabilities"));	   
   1.147 +	   }
   1.148 +	else
   1.149 +	   {
   1.150 +		//if test environment has WDD capability then SetFeature should succeed and feature 
   1.151 +		//change notification should be issued
   1.152 +	   TESTDIAGNOSTICERROR(err == KErrNone,
   1.153 +			_L("RFeatureControl::SetFeature - KErrNone expected; error = %d"),err);					
   1.154 +	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   1.155 +			_L("Feature notification should not be issued as the natification has been cancelled"));
   1.156 +	   }
   1.157 +	}
   1.158 +	
   1.159 +void CFeatureNotifierStepBase::CheckDeleteNotificationResultL(TUid aUid)
   1.160 +	{
   1.161 +	TInt err = icontrol.DeleteFeature(aUid);
   1.162 +   
   1.163 +	if (iLowCap)	   
   1.164 +	   {
   1.165 +	   //if we are running in the low capabilities environment we don't expect the feature 
   1.166 +	   //to be modified and notification to be issued
   1.167 +	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   1.168 +			  _L("RFeatureControl::DeleteFeature - KErrPermissionDenied expected; error = %d"),err);
   1.169 +	   }
   1.170 +	else
   1.171 +	   {	
   1.172 +		TESTDIAGNOSTICERROR(err == KErrNone, 
   1.173 +			 _L("RFeatureControl::DeleteFeature - KErrNone or KErrAlreadyExists expected; error = %d"),err);			 
   1.174 +		}
   1.175 +   
   1.176 +   	WaitL(KWaitDelay);
   1.177 +   
   1.178 +   	if (iLowCap)	   
   1.179 +	   {
   1.180 +	   
   1.181 +	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   1.182 +			  _L("Feature notification should not be issued due to insufficient capabilities"));
   1.183 +	   }
   1.184 +	   
   1.185 +	else
   1.186 +		{
   1.187 +		TESTDIAGNOSTIC(iNotifyCompleted,	   
   1.188 +				  _L("Feature notification is expected to be issued"));	
   1.189 +   
   1.190 +		}	
   1.191 +	}
   1.192 +
   1.193 +
   1.194 +