sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: EXPORT_C CTransition::CTransition(const TDesC& aTransitionId, sl@0: CUnitTestContext& aUTContext, sl@0: TTransitionValidator& aValidator) sl@0: : CActive(CActive::EPriorityStandard), sl@0: iTransitionId(aTransitionId), sl@0: iUTContext(aUTContext), sl@0: iValidator(aValidator), sl@0: iTransitionInfo(iTransitionId, iUTContext.DataLogger()) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CTransition::~CTransition() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CTransition::SetStartStateL() sl@0: { sl@0: // Do nothing here sl@0: } sl@0: sl@0: sl@0: EXPORT_C const TDesC& CTransition::TransitionId() const sl@0: { sl@0: return iTransitionId; sl@0: } sl@0: sl@0: EXPORT_C void CTransition::DoCancel() sl@0: { sl@0: // Complete the unit test so that this test will now finish sl@0: // if the transition has not finished then we haven't even had to chance sl@0: // to run yet so complete the UnitTest with a Cancel message sl@0: // If the transition has finished then we must have an outstanding async sl@0: // transition so Complete the observer to ensure it gets removed from the list sl@0: // of outstanding transitions sl@0: if(!iTransitionFinished) sl@0: User::RequestComplete(iUnitTestStatus, KTestBedTestCancel); sl@0: else sl@0: iUTContext.TransitionObserver().Complete(*this, KTestBedTestCancel); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CTransition::RunTransition(TRequestStatus* aUnitTestStatus) sl@0: { sl@0: iUnitTestStatus = aUnitTestStatus; sl@0: iTransitionFinished = EFalse; sl@0: sl@0: // Reset the iRepeat flag - if this transition should be repeated it will be sl@0: // set during the execution of TransitMethodL(). sl@0: iRepeatThis = EFalse; sl@0: sl@0: if(!iValidator.ValidatePreConditions()) sl@0: { sl@0: User::RequestComplete(iUnitTestStatus, KTestBedFailedPreConditions); sl@0: } sl@0: else sl@0: { sl@0: SetActive(); sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CTransition::RunL() sl@0: { sl@0: iUTContext.TransitionObserver().SetCurrentTransition(*this); sl@0: if(!iTransitionFinished) sl@0: { sl@0: ++iTransitionInfo.iIteration; sl@0: TransitMethodL(); sl@0: iTransitionFinished = ETrue; sl@0: PostTransitionCleanup(); // Allow the derived transition class to do something before sl@0: // PostCondition validation. sl@0: sl@0: // If the user called an asynchronous function then SetActive so that we run again sl@0: // when the async function completes sl@0: iAsyncTransition = iStatus == KRequestPending; sl@0: if(iAsyncTransition) sl@0: { sl@0: SetActive(); sl@0: } sl@0: sl@0: TTestBedAsyncState asyncState = iAsyncTransition ? EAsyncCalled : EAsyncCompleted; sl@0: if(!iValidator.ValidatePostConditions(asyncState)) sl@0: { sl@0: if(iAsyncTransition) sl@0: { sl@0: //Cancel the request sl@0: Cancel(); sl@0: } sl@0: User::RequestComplete(iUnitTestStatus, KTestBedFailedPostConditions); sl@0: } sl@0: else if(iAsyncTransition) sl@0: User::RequestComplete(iUnitTestStatus, KTestBedAsynchronousTransition); sl@0: else if(iRepeatThis) sl@0: User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest); sl@0: else sl@0: User::RequestComplete(iUnitTestStatus, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: if(iAsyncTransition && !iValidator.ValidatePostConditions(EAsyncCompleted)) sl@0: iUTContext.TransitionObserver().Complete(*this, KTestBedFailedPostConditions); sl@0: else sl@0: iUTContext.TransitionObserver().Complete(*this, KErrNone); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C const TTransitionInfo& CTransition::TransitionInfo() const sl@0: { sl@0: return iTransitionInfo; sl@0: } sl@0: sl@0: EXPORT_C void CTransition::RepeatOnce() sl@0: { sl@0: iRepeatThis = ETrue; sl@0: } sl@0: sl@0: EXPORT_C TInt CTransition::RunError(TInt aErrorCode) sl@0: { sl@0: // Record the leave and signal completed with a leave code sl@0: _LIT(KTransitionRunError, "CTransition::TransitMethodL() leaving error %d."); sl@0: iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, aErrorCode); sl@0: sl@0: iLeaveError = aErrorCode; sl@0: // Check if the leave is associated with a repeat request sl@0: // I.e. it was an execution path test from a stub. sl@0: if(iLeaveError == KTestBedRepeatTest && iRepeatThis) sl@0: User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest); sl@0: else sl@0: User::RequestComplete(iUnitTestStatus, KTestBedTestLeft); sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TBool CTransition::IsBlockingTransition() const sl@0: { sl@0: return iBlockingTransition; sl@0: } sl@0: sl@0: EXPORT_C void CTransition::SetBlockingTransition(TBool aBlocking) sl@0: { sl@0: iBlockingTransition = aBlocking; sl@0: } sl@0: sl@0: EXPORT_C TInt CTransition::GetErrorCode() const sl@0: { sl@0: return iLeaveError; sl@0: } sl@0: sl@0: EXPORT_C void CTransition::PostTransitionCleanup() sl@0: { sl@0: // Default behaviour is to do nothing sl@0: }