First public contribution.
1 // Copyright (c) 2007-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 the License "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.
14 // @file testcaseroot.cpp
20 #include <e32std_private.h>
21 #include <u32std.h> // unicode builds
23 #include <e32base_private.h>
25 #include <e32Test.h> // RTest header
28 #include <e32def_private.h>
29 #include <d32otgdi.h> // OTGDI header
30 #include <d32usbc.h> // USBCC header
31 #include "testcaseroot.h"
33 /* Implemention of classes CTestCaseRoot, CTestCaseB2BRoot
37 /* ===============================================================
38 * The root test-case class, provides test-framework features
40 CTestCaseRoot::CTestCaseRoot(const TDesC& aTestCaseId, TBool aAutomation)
41 : CActive(EPriorityUserInput),
43 iAutomated(aAutomation)
45 iTestCaseId.Copy(aTestCaseId);
49 void CTestCaseRoot::BaseConstructL()
54 TInt err(iTimer.CreateLocal());
57 LOG_VERBOSE1(_L("Test case timer created"));
61 RDebug::Printf("<Error %d> Test case timer could not be created",err);
65 iConsole = test.Console();
66 iRequestedChar = EFalse;
70 CTestCaseRoot::~CTestCaseRoot()
76 // utility GUI methods
77 void CTestCaseRoot::DisplayTestCaseOptions()
81 // commonly overridden to display any options for that test
82 test.Printf(_L("Press <ESC> to end the test.\n"));
86 /***********************************************************************/
88 void CTestCaseRoot::SetTestPolicy(CBasicTestPolicy* aTestPolicy)
90 iTestPolicy = aTestPolicy;
91 iAutomated = gSemiAutomated; // read the global flag at this time
95 CBasicTestPolicy& CTestCaseRoot::TestPolicy()
101 void CTestCaseRoot::DoCancel()
108 override this method to perform other tasks, the base-class does nothing so that
109 child classes can use it as an any-key-to-continue helper
111 void CTestCaseRoot::ProcessKey(TKeyCode &aKey)
112 {// default implementation - reads the key.
113 iKeyCodeInput = aKey;
117 void CTestCaseRoot::ProcessEngineKey(TKeyCode &aKey)
121 if (EKeyEscape == aKey)
123 AssertionFailed( 1, _L("Test aborted by the user <ESC>\n"));
124 CActiveScheduler::Stop();
129 // call virtual method here to invoke the test's overridden method
131 // note, we do not go ask for another, that is done by the console handler
136 void CTestCaseRoot::RequestCharacter()
139 // A request is issued to the CConsoleBase to accept a
140 // character from the keyboard.
142 __ASSERT_ALWAYS(!IsActive(), User::Panic(KMsgAlreadyActive, EPanicAlreadyActive));
144 iConsole->Read(iStatus);
146 iRequestedChar = ETrue;
150 void CTestCaseRoot::RunL()
153 TInt complCode(iStatus.Int());
157 TKeyCode k(iConsole->KeyCode());
161 // When debugging if you have a breakpoint just before you read/process a key,
162 // the EMULATOR will read the key sent to the IDE and you get a (F5) key that
163 // you did not want from the IDE not the emulator.
166 iRequestedChar = EFalse;
168 // complete so that other tasks (there are none) can run
169 // we will then be scheduled by the ActiveScheduler again to run the next test step.
174 // run the next test step
175 TInt currentStep(GetStepIndex());
177 LOG_VERBOSE2(_L("\n<< RunStepL() step=%d\n"), currentStep);
179 LOG_VERBOSE3(_L(">> RunStepL() step=%d->%d\n"), currentStep, GetStepIndex());
185 void CTestCaseRoot::PostRunStep()
190 void CTestCaseRoot::PreRunStep()
195 TInt CTestCaseRoot::RunError(TInt aError)
198 test.Printf(_L("Test case C%lS::RunL left with %d"), &iTestCaseId, aError);
199 AssertionFailed(aError, _L("RunError"));
204 TDesC& CTestCaseRoot::TestCaseId()
210 TInt CTestCaseRoot::TestResult() const
216 void CTestCaseRoot::PerformTestL()
218 // tell user what they should have done before starting!
219 DescribePreconditions();
225 void CTestCaseRoot::TestFailed(TInt aFailResult, const TDesC &aErrorDescription)
228 iTestResult = aFailResult;
229 test.Printf(_L("Test %S\n"), &TestCaseId());
230 test.Printf(_L("Failed (%d)\n"), aFailResult);
231 test.Printf(_L("%S!\n"), &aErrorDescription);
234 test.Printf(_L("\n"));
235 test.Printf(KPressAnyKeyToContinue);
238 // the next call panics the framework!
239 TestPolicy().SignalTestComplete(iTestResult);
243 void CTestCaseRoot::TestFailed2(TInt aFailResult, const TDesC &aErrorDescription, TInt errorCode)
246 iTestResult = aFailResult;
247 test.Printf(_L("Test %S FAILED %d '%S %d'!\n"),
252 // the next call panics the framework!
253 TestPolicy().SignalTestComplete(iTestResult);
258 void CTestCaseRoot::TestPassed()
261 iTestResult = KErrNone;
262 TestPolicy().SignalTestComplete(iTestResult);
268 /** Complete the servicing of the Active object and signal it ready to run again
269 in next scheduler slot. This method works as drop-through when a test step has
272 void CTestCaseRoot::SelfComplete(TInt aCode)
274 TRequestStatus* s = &iStatus;
275 iStatus = KRequestPending;
276 User::RequestComplete(s, aCode);
280 /* Prints a little banner at the top of a test-step :
281 * B2B tests also display the duration of the last step, and the current OTG state
283 void CTestCaseRoot::PrintStepName(const TDesC &aStepName)
287 test.Printf(_L("--------------\n %S "), &aStepName);
288 // B2B class method dumps the engine state
290 test.Printf(_L("\n--------------\n"));
295 /* **************************************************************************************
298 CTestCaseB2BRoot::CTestCaseB2BRoot(const TDesC& aTestCaseId, TBool aHost, TRequestStatus &aStatus)
299 : CTestCaseRoot(aTestCaseId, aHost) , iCollector(aStatus)
306 CTestCaseB2BRoot::~CTestCaseB2BRoot()
312 /* Print step name : B2B override displays the OTG Engine state as well
314 void CTestCaseB2BRoot::PrintStepName(const TDesC &aStepName)
318 test.Printf(_L("--------------\n %S "), &aStepName);
320 CNotifyWatcherBase *pWatcher = iCollector.GetWatcher(EWatcherState);
323 TBuf<MAX_DSTRLEN> aDescription;
324 RUsbOtgDriver::TOtgState aState = static_cast<RUsbOtgDriver::TOtgState>(pWatcher->GetEventValue());
326 OtgStateString(aState, aDescription);
327 LOG_VERBOSE3(_L("OTGState %d '%S' \n"), aState, &aDescription);
329 test.Printf(_L(" : time = %dms\n--------------\n"), iCollector.DurationElapsed());
333 /* Default implementation which describes this as a B2B test-case
335 void CTestCaseB2BRoot::DescribePreconditions()
337 test.Printf(KTestTypeB2BMsg); // B2B
339 test.Printf(KRoleMasterMsg);
341 test.Printf(KRoleSlaveMsg);
345 void CTestCaseB2BRoot::StepB2BPreconditions()
347 // prompt to insert connector
350 test.Printf(KInsertBCablePrompt);
354 test.Printf(KInsertACablePrompt);
362 test.Printf(KPressAnyKeyToContinue);
367 /* Test for A or B plug as relevant for MASTER/SLAVE role, fail the test if wrong
369 void CTestCaseB2BRoot::CheckRoleConnections()
373 if (otgIdPinPresent())
375 test.Printf(KMsgErrorPreconditionFailed);
376 return TestFailed(KErrAbort, KMsgBPlugNotFound);
381 if (!otgIdPinPresent())
383 test.Printf(KMsgErrorPreconditionFailed);
384 return TestFailed(KErrAbort, KMsgAPlugNotFound);
390 /* Clears the expected event Q just before calling the step, but not the
391 * recieved Q since the step may still inspect it using the EventReceivedAlready() method.
393 void CTestCaseB2BRoot::PreRunStep()
397 iCollector.ClearAllEvents(EFalse, ETrue);
401 void CTestCaseB2BRoot::PostRunStep()
404 // clear the recieved event Q, but not the expected Q
405 iCollector.ClearAllEvents(ETrue, EFalse);