os/persistentdata/featuremgmt/featuremgr/test/shared/src/efm_featurenotifierstepbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-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 // Implementation of the base class for capability aware test steps. 
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalComponent
    21  @test
    22 */
    23 
    24 #include "efm_featurenotifierstepbase.h"
    25 
    26 static TInt WaitCallBack( TAny* aSelf )
    27 	{
    28 	if( aSelf )
    29 		{
    30 		TWaitInfo* info = static_cast<TWaitInfo*>( aSelf );
    31 		if( info->iPeriodic )
    32 			{
    33 			info->iPeriodic->Cancel();
    34 			}
    35 		if( info->iWait )
    36 			{
    37 			if( info->iWait->IsStarted() )
    38 				{
    39 				info->iWait->AsyncStop();
    40 				}
    41 			}
    42 		}
    43 	
    44 	return KErrNone;
    45 	}
    46 
    47 
    48 void CFeatureNotifierStepBase::WaitL( TInt aIntervalInMicorseconds )
    49 	{
    50 	TWaitInfo info;
    51 	
    52 	// Construct periodic
    53 	CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityStandard );
    54 	CleanupStack::PushL( periodic );
    55 	info.iPeriodic = periodic;
    56 	
    57 	// Construct active scheduler wait
    58 	CActiveSchedulerWait* wait = new( ELeave ) CActiveSchedulerWait;
    59 	CleanupStack::PushL( wait );
    60 	info.iWait = wait;
    61 	iWait = wait;
    62 	
    63 	// Start timer and wait
    64 	TCallBack cb( WaitCallBack, &info );
    65 	periodic->Start( aIntervalInMicorseconds, aIntervalInMicorseconds, cb );
    66 	wait->Start();
    67 	
    68 	// Cleanup
    69 	CleanupStack::PopAndDestroy( wait );
    70 	CleanupStack::PopAndDestroy( periodic );
    71 	}
    72 
    73 
    74 TVerdict CFeatureNotifierStepBase::doTestStepPreambleL(void)
    75 	{
    76 	CEFMConfigurableTestStepBase::doTestStepPreambleL();
    77 	iSched= new(ELeave) CActiveScheduler;
    78 	CActiveScheduler::Install(iSched);		
    79 	TInt err = icontrol.Open();
    80 	TESTDIAGNOSTICERROR(err==KErrNone, 
    81 		 _L("RFeatureControl::Open failed: error = %d"), err);
    82 	return TestStepResult();
    83 	}
    84 
    85 TVerdict CFeatureNotifierStepBase::doTestStepPostambleL(void)
    86 	{
    87 	CEFMConfigurableTestStepBase::doTestStepPostambleL();
    88 	CActiveScheduler::Install(NULL);
    89 	delete iSched;
    90 	icontrol.Close();
    91 	return TestStepResult();		
    92 	}
    93 
    94 
    95 void CFeatureNotifierStepBase :: HandleNotifyChange( TFeatureChangeType /* aType */ , TFeatureEntry /* aFeature */ )
    96 	{
    97 	iWait->AsyncStop();
    98 	iNotifyCompleted = ETrue;	
    99 	}
   100 	
   101 void CFeatureNotifierStepBase:: HandleNotifyError( TInt aError )
   102    {
   103    INFO_PRINTF2(_L("CFeatureNotifier::HandleNotifyError %d"),aError);
   104    SetTestStepResult(EFail);
   105    }
   106 
   107 
   108 void CFeatureNotifierStepBase::CheckNotifyRequestResultL(TUid aUid)
   109 	{
   110 	TInt err = icontrol.SetFeature( aUid, KChangeData );
   111 	WaitL(KWaitDelay);
   112 	if (iLowCap)	   
   113 	   {
   114 	   //if we are running in the low capabilities environment we don't expect the feature 
   115 	   //to be modified and notification to be issued
   116 	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   117 			  _L("RFeatureControl::SetFeature - KErrPermissionDenied expected; error = %d"),err);	   
   118 	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   119 			  _L("Feature notification should not be issued due to insufficient capabilities"));
   120 	   }
   121 	else
   122 	   {
   123 		//if test environment has WDD capability then SetFeature should succeed and feature 
   124 		//change notification should be issued
   125 	   TESTDIAGNOSTICERROR(err == KErrNone,
   126 				  _L("RFeatureControl::SetFeature - KErrNone expected; error = %d"),err);	   
   127 	   TESTDIAGNOSTIC(iNotifyCompleted,	   
   128 				  _L("Feature notification is expected to be issued"));
   129 	   }
   130 	}
   131 
   132 void CFeatureNotifierStepBase::CheckNotifyCancelResultL(TUid aUid)
   133 	{
   134 	TInt err = icontrol.SetFeature( aUid, KChangeData );
   135 	WaitL(KWaitDelay);
   136 	if (iLowCap)	   
   137 	   {
   138 	   //if we are running in the low capabilities environment we don't expect the feature 
   139 	   //to be modified and notification to be issued
   140 	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   141 			_L("RFeatureControl::SetFeature - KErrPermissionDenied expected; error = %d"),err);
   142 	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   143 			_L("Feature notification should not be issued due to insufficient capabilities"));	   
   144 	   }
   145 	else
   146 	   {
   147 		//if test environment has WDD capability then SetFeature should succeed and feature 
   148 		//change notification should be issued
   149 	   TESTDIAGNOSTICERROR(err == KErrNone,
   150 			_L("RFeatureControl::SetFeature - KErrNone expected; error = %d"),err);					
   151 	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   152 			_L("Feature notification should not be issued as the natification has been cancelled"));
   153 	   }
   154 	}
   155 	
   156 void CFeatureNotifierStepBase::CheckDeleteNotificationResultL(TUid aUid)
   157 	{
   158 	TInt err = icontrol.DeleteFeature(aUid);
   159    
   160 	if (iLowCap)	   
   161 	   {
   162 	   //if we are running in the low capabilities environment we don't expect the feature 
   163 	   //to be modified and notification to be issued
   164 	   TESTDIAGNOSTICERROR(err == KErrPermissionDenied,	   
   165 			  _L("RFeatureControl::DeleteFeature - KErrPermissionDenied expected; error = %d"),err);
   166 	   }
   167 	else
   168 	   {	
   169 		TESTDIAGNOSTICERROR(err == KErrNone, 
   170 			 _L("RFeatureControl::DeleteFeature - KErrNone or KErrAlreadyExists expected; error = %d"),err);			 
   171 		}
   172    
   173    	WaitL(KWaitDelay);
   174    
   175    	if (iLowCap)	   
   176 	   {
   177 	   
   178 	   TESTDIAGNOSTIC(!iNotifyCompleted,	   
   179 			  _L("Feature notification should not be issued due to insufficient capabilities"));
   180 	   }
   181 	   
   182 	else
   183 		{
   184 		TESTDIAGNOSTIC(iNotifyCompleted,	   
   185 				  _L("Feature notification is expected to be issued"));	
   186    
   187 		}	
   188 	}
   189 
   190 
   191