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