os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/test_bed/Transition.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-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 //
    15 
    16 #include <ecom/test_bed/transition.h>
    17 #include <ecom/test_bed/datalogger.h>
    18 #include <ecom/test_bed/testbeddefinitions.h>
    19 
    20 EXPORT_C CTransition::CTransition(const TDesC&					aTransitionId, 
    21 										CUnitTestContext&		aUTContext,
    22 										TTransitionValidator&	aValidator) 
    23 :	CActive(CActive::EPriorityStandard),
    24 iTransitionId(aTransitionId),
    25 iUTContext(aUTContext),
    26 iValidator(aValidator),
    27 iTransitionInfo(iTransitionId, iUTContext.DataLogger()) 
    28 	{
    29 	CActiveScheduler::Add(this);
    30 	}
    31 
    32 
    33 EXPORT_C CTransition::~CTransition()
    34 	{
    35 	Cancel();
    36 	}
    37 
    38 
    39 EXPORT_C void CTransition::SetStartStateL()
    40 	{
    41 	// Do nothing here
    42 	}
    43 
    44 
    45 EXPORT_C const TDesC& CTransition::TransitionId() const
    46 	{
    47 	return iTransitionId;
    48 	}
    49 
    50 EXPORT_C void CTransition::DoCancel()
    51 	{
    52 	// Complete the unit test so that this test will now finish
    53 	// if the transition has not finished then we haven't even had to chance
    54 	// to run yet so complete the UnitTest with a Cancel message
    55 	// If the transition has finished then we must have an outstanding async
    56 	// transition so Complete the observer to ensure it gets removed from the list
    57 	// of outstanding transitions
    58 	if(!iTransitionFinished)
    59 		User::RequestComplete(iUnitTestStatus, KTestBedTestCancel);
    60 	else
    61 		iUTContext.TransitionObserver().Complete(*this, KTestBedTestCancel);
    62 	}
    63 
    64 
    65 EXPORT_C void CTransition::RunTransition(TRequestStatus* aUnitTestStatus)
    66 	{
    67 	iUnitTestStatus = aUnitTestStatus;
    68 	iTransitionFinished = EFalse;
    69 
    70 	// Reset the iRepeat flag - if this transition should be repeated it will be
    71 	// set during the execution of TransitMethodL().
    72 	iRepeatThis = EFalse;
    73 
    74 	if(!iValidator.ValidatePreConditions())
    75 		{
    76 		User::RequestComplete(iUnitTestStatus, KTestBedFailedPreConditions);
    77 		}
    78 	else
    79 		{
    80 		SetActive();
    81 		TRequestStatus* status = &iStatus;
    82 		User::RequestComplete(status, KErrNone);
    83 		}
    84 	}
    85 
    86 EXPORT_C void CTransition::RunL()
    87 	{
    88 	iUTContext.TransitionObserver().SetCurrentTransition(*this);
    89 	if(!iTransitionFinished)
    90 		{
    91 		++iTransitionInfo.iIteration;
    92 		TransitMethodL();
    93 		iTransitionFinished = ETrue;
    94 		PostTransitionCleanup();		// Allow the derived transition class to do something before
    95 										// PostCondition validation.
    96 
    97 		// If the user called an asynchronous function then SetActive so that we run again
    98 		// when the async function completes
    99 		iAsyncTransition = iStatus == KRequestPending;
   100 		if(iAsyncTransition)
   101 			{
   102 			SetActive();
   103 			}
   104 
   105 		TTestBedAsyncState asyncState = iAsyncTransition ? EAsyncCalled : EAsyncCompleted;
   106 		if(!iValidator.ValidatePostConditions(asyncState))
   107 			{
   108 			if(iAsyncTransition)
   109 				{
   110 				//Cancel the request
   111 				Cancel();
   112 				}
   113 			User::RequestComplete(iUnitTestStatus, KTestBedFailedPostConditions);
   114 			}
   115 		else if(iAsyncTransition)
   116 			User::RequestComplete(iUnitTestStatus, KTestBedAsynchronousTransition);
   117 		else if(iRepeatThis)
   118 			User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
   119 		else
   120 			User::RequestComplete(iUnitTestStatus, KErrNone);
   121 		}
   122 	else
   123 		{
   124 		if(iAsyncTransition && !iValidator.ValidatePostConditions(EAsyncCompleted))
   125 			iUTContext.TransitionObserver().Complete(*this, KTestBedFailedPostConditions);
   126 		else
   127 			iUTContext.TransitionObserver().Complete(*this, KErrNone);
   128 		}
   129 	}
   130 
   131 EXPORT_C const TTransitionInfo& CTransition::TransitionInfo() const
   132 	{
   133 	return iTransitionInfo;
   134 	}
   135 
   136 EXPORT_C void CTransition::RepeatOnce()
   137 	{
   138 	iRepeatThis = ETrue;
   139 	}
   140 
   141 EXPORT_C TInt CTransition::RunError(TInt aErrorCode)
   142 	{
   143 	// Record the leave and signal completed with a leave code
   144 	_LIT(KTransitionRunError, "CTransition::TransitMethodL() leaving error %d.");
   145 	iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, aErrorCode);
   146 
   147 	iLeaveError = aErrorCode;
   148 	// Check if the leave is associated with a repeat request
   149 	// I.e. it was an execution path test from a stub.
   150 	if(iLeaveError == KTestBedRepeatTest && iRepeatThis)
   151 		User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
   152 	else
   153 		User::RequestComplete(iUnitTestStatus, KTestBedTestLeft);
   154 	return KErrNone;
   155 	}
   156 
   157 EXPORT_C TBool CTransition::IsBlockingTransition() const
   158 	{
   159 	return iBlockingTransition;
   160 	}
   161 
   162 EXPORT_C void CTransition::SetBlockingTransition(TBool aBlocking)
   163 	{
   164 	iBlockingTransition = aBlocking;
   165 	}
   166 
   167 EXPORT_C TInt CTransition::GetErrorCode() const
   168 	{
   169 	return iLeaveError;
   170 	}
   171 
   172 EXPORT_C void CTransition::PostTransitionCleanup()
   173 	{
   174 	// Default behaviour is to do nothing
   175 	}