1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/test_bed/Transition.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,175 @@
1.4 +// Copyright (c) 1997-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 +//
1.18 +
1.19 +#include <ecom/test_bed/transition.h>
1.20 +#include <ecom/test_bed/datalogger.h>
1.21 +#include <ecom/test_bed/testbeddefinitions.h>
1.22 +
1.23 +EXPORT_C CTransition::CTransition(const TDesC& aTransitionId,
1.24 + CUnitTestContext& aUTContext,
1.25 + TTransitionValidator& aValidator)
1.26 +: CActive(CActive::EPriorityStandard),
1.27 +iTransitionId(aTransitionId),
1.28 +iUTContext(aUTContext),
1.29 +iValidator(aValidator),
1.30 +iTransitionInfo(iTransitionId, iUTContext.DataLogger())
1.31 + {
1.32 + CActiveScheduler::Add(this);
1.33 + }
1.34 +
1.35 +
1.36 +EXPORT_C CTransition::~CTransition()
1.37 + {
1.38 + Cancel();
1.39 + }
1.40 +
1.41 +
1.42 +EXPORT_C void CTransition::SetStartStateL()
1.43 + {
1.44 + // Do nothing here
1.45 + }
1.46 +
1.47 +
1.48 +EXPORT_C const TDesC& CTransition::TransitionId() const
1.49 + {
1.50 + return iTransitionId;
1.51 + }
1.52 +
1.53 +EXPORT_C void CTransition::DoCancel()
1.54 + {
1.55 + // Complete the unit test so that this test will now finish
1.56 + // if the transition has not finished then we haven't even had to chance
1.57 + // to run yet so complete the UnitTest with a Cancel message
1.58 + // If the transition has finished then we must have an outstanding async
1.59 + // transition so Complete the observer to ensure it gets removed from the list
1.60 + // of outstanding transitions
1.61 + if(!iTransitionFinished)
1.62 + User::RequestComplete(iUnitTestStatus, KTestBedTestCancel);
1.63 + else
1.64 + iUTContext.TransitionObserver().Complete(*this, KTestBedTestCancel);
1.65 + }
1.66 +
1.67 +
1.68 +EXPORT_C void CTransition::RunTransition(TRequestStatus* aUnitTestStatus)
1.69 + {
1.70 + iUnitTestStatus = aUnitTestStatus;
1.71 + iTransitionFinished = EFalse;
1.72 +
1.73 + // Reset the iRepeat flag - if this transition should be repeated it will be
1.74 + // set during the execution of TransitMethodL().
1.75 + iRepeatThis = EFalse;
1.76 +
1.77 + if(!iValidator.ValidatePreConditions())
1.78 + {
1.79 + User::RequestComplete(iUnitTestStatus, KTestBedFailedPreConditions);
1.80 + }
1.81 + else
1.82 + {
1.83 + SetActive();
1.84 + TRequestStatus* status = &iStatus;
1.85 + User::RequestComplete(status, KErrNone);
1.86 + }
1.87 + }
1.88 +
1.89 +EXPORT_C void CTransition::RunL()
1.90 + {
1.91 + iUTContext.TransitionObserver().SetCurrentTransition(*this);
1.92 + if(!iTransitionFinished)
1.93 + {
1.94 + ++iTransitionInfo.iIteration;
1.95 + TransitMethodL();
1.96 + iTransitionFinished = ETrue;
1.97 + PostTransitionCleanup(); // Allow the derived transition class to do something before
1.98 + // PostCondition validation.
1.99 +
1.100 + // If the user called an asynchronous function then SetActive so that we run again
1.101 + // when the async function completes
1.102 + iAsyncTransition = iStatus == KRequestPending;
1.103 + if(iAsyncTransition)
1.104 + {
1.105 + SetActive();
1.106 + }
1.107 +
1.108 + TTestBedAsyncState asyncState = iAsyncTransition ? EAsyncCalled : EAsyncCompleted;
1.109 + if(!iValidator.ValidatePostConditions(asyncState))
1.110 + {
1.111 + if(iAsyncTransition)
1.112 + {
1.113 + //Cancel the request
1.114 + Cancel();
1.115 + }
1.116 + User::RequestComplete(iUnitTestStatus, KTestBedFailedPostConditions);
1.117 + }
1.118 + else if(iAsyncTransition)
1.119 + User::RequestComplete(iUnitTestStatus, KTestBedAsynchronousTransition);
1.120 + else if(iRepeatThis)
1.121 + User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
1.122 + else
1.123 + User::RequestComplete(iUnitTestStatus, KErrNone);
1.124 + }
1.125 + else
1.126 + {
1.127 + if(iAsyncTransition && !iValidator.ValidatePostConditions(EAsyncCompleted))
1.128 + iUTContext.TransitionObserver().Complete(*this, KTestBedFailedPostConditions);
1.129 + else
1.130 + iUTContext.TransitionObserver().Complete(*this, KErrNone);
1.131 + }
1.132 + }
1.133 +
1.134 +EXPORT_C const TTransitionInfo& CTransition::TransitionInfo() const
1.135 + {
1.136 + return iTransitionInfo;
1.137 + }
1.138 +
1.139 +EXPORT_C void CTransition::RepeatOnce()
1.140 + {
1.141 + iRepeatThis = ETrue;
1.142 + }
1.143 +
1.144 +EXPORT_C TInt CTransition::RunError(TInt aErrorCode)
1.145 + {
1.146 + // Record the leave and signal completed with a leave code
1.147 + _LIT(KTransitionRunError, "CTransition::TransitMethodL() leaving error %d.");
1.148 + iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, aErrorCode);
1.149 +
1.150 + iLeaveError = aErrorCode;
1.151 + // Check if the leave is associated with a repeat request
1.152 + // I.e. it was an execution path test from a stub.
1.153 + if(iLeaveError == KTestBedRepeatTest && iRepeatThis)
1.154 + User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
1.155 + else
1.156 + User::RequestComplete(iUnitTestStatus, KTestBedTestLeft);
1.157 + return KErrNone;
1.158 + }
1.159 +
1.160 +EXPORT_C TBool CTransition::IsBlockingTransition() const
1.161 + {
1.162 + return iBlockingTransition;
1.163 + }
1.164 +
1.165 +EXPORT_C void CTransition::SetBlockingTransition(TBool aBlocking)
1.166 + {
1.167 + iBlockingTransition = aBlocking;
1.168 + }
1.169 +
1.170 +EXPORT_C TInt CTransition::GetErrorCode() const
1.171 + {
1.172 + return iLeaveError;
1.173 + }
1.174 +
1.175 +EXPORT_C void CTransition::PostTransitionCleanup()
1.176 + {
1.177 + // Default behaviour is to do nothing
1.178 + }