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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <ecom/test_bed/transition.h>
17 #include <ecom/test_bed/datalogger.h>
18 #include <ecom/test_bed/testbeddefinitions.h>
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())
29 CActiveScheduler::Add(this);
33 EXPORT_C CTransition::~CTransition()
39 EXPORT_C void CTransition::SetStartStateL()
45 EXPORT_C const TDesC& CTransition::TransitionId() const
50 EXPORT_C void CTransition::DoCancel()
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);
61 iUTContext.TransitionObserver().Complete(*this, KTestBedTestCancel);
65 EXPORT_C void CTransition::RunTransition(TRequestStatus* aUnitTestStatus)
67 iUnitTestStatus = aUnitTestStatus;
68 iTransitionFinished = EFalse;
70 // Reset the iRepeat flag - if this transition should be repeated it will be
71 // set during the execution of TransitMethodL().
74 if(!iValidator.ValidatePreConditions())
76 User::RequestComplete(iUnitTestStatus, KTestBedFailedPreConditions);
81 TRequestStatus* status = &iStatus;
82 User::RequestComplete(status, KErrNone);
86 EXPORT_C void CTransition::RunL()
88 iUTContext.TransitionObserver().SetCurrentTransition(*this);
89 if(!iTransitionFinished)
91 ++iTransitionInfo.iIteration;
93 iTransitionFinished = ETrue;
94 PostTransitionCleanup(); // Allow the derived transition class to do something before
95 // PostCondition validation.
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;
105 TTestBedAsyncState asyncState = iAsyncTransition ? EAsyncCalled : EAsyncCompleted;
106 if(!iValidator.ValidatePostConditions(asyncState))
113 User::RequestComplete(iUnitTestStatus, KTestBedFailedPostConditions);
115 else if(iAsyncTransition)
116 User::RequestComplete(iUnitTestStatus, KTestBedAsynchronousTransition);
118 User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
120 User::RequestComplete(iUnitTestStatus, KErrNone);
124 if(iAsyncTransition && !iValidator.ValidatePostConditions(EAsyncCompleted))
125 iUTContext.TransitionObserver().Complete(*this, KTestBedFailedPostConditions);
127 iUTContext.TransitionObserver().Complete(*this, KErrNone);
131 EXPORT_C const TTransitionInfo& CTransition::TransitionInfo() const
133 return iTransitionInfo;
136 EXPORT_C void CTransition::RepeatOnce()
141 EXPORT_C TInt CTransition::RunError(TInt aErrorCode)
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);
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);
153 User::RequestComplete(iUnitTestStatus, KTestBedTestLeft);
157 EXPORT_C TBool CTransition::IsBlockingTransition() const
159 return iBlockingTransition;
162 EXPORT_C void CTransition::SetBlockingTransition(TBool aBlocking)
164 iBlockingTransition = aBlocking;
167 EXPORT_C TInt CTransition::GetErrorCode() const
172 EXPORT_C void CTransition::PostTransitionCleanup()
174 // Default behaviour is to do nothing