sl@0: // Copyright (c) 2007-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 the License "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: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include // unicode builds sl@0: #include sl@0: #include sl@0: #include sl@0: #include // RTest headder sl@0: #include "testcaseroot.h" sl@0: #include "testcasewd.h" sl@0: #include "testcasefactory.h" sl@0: #include "exampletestcase.h" sl@0: sl@0: sl@0: sl@0: // the name below is used to add a pointer to our construction method to a pointer MAP in sl@0: // the class factory sl@0: _LIT(KTestCaseId,"EXAMPLETESTCASE"); sl@0: sl@0: // UNcomment the next line to add the test to the catalog(factory) sl@0: const TTestCaseFactoryReceipt CExampleTestCase::iFactoryReceipt(KTestCaseId); sl@0: sl@0: CExampleTestCase* CExampleTestCase::NewL(TBool aHost) sl@0: { sl@0: LOG_FUNC sl@0: CExampleTestCase* self = new (ELeave) CExampleTestCase(aHost); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CExampleTestCase::CExampleTestCase(TBool aHost) sl@0: : CTestCaseRoot(KTestCaseId, aHost) sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: sl@0: void CExampleTestCase::ConstructL() sl@0: { sl@0: LOG_FUNC sl@0: BaseConstructL(); sl@0: iWDTimer = CTestCaseWatchdog::NewL(); sl@0: } sl@0: sl@0: sl@0: CExampleTestCase::~CExampleTestCase() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: delete iWDTimer; sl@0: Cancel(); sl@0: } sl@0: sl@0: sl@0: void CExampleTestCase::ExecuteTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: iCaseStep = EFirstStep; sl@0: sl@0: // sl@0: CActiveScheduler::Add(this); sl@0: // run our root RunL() sl@0: SelfComplete(); sl@0: sl@0: } sl@0: sl@0: void CExampleTestCase::DescribePreconditions() sl@0: { sl@0: test.Printf(_L("This is an example test, there is nothing to do beforehand.\n")); sl@0: } sl@0: sl@0: void CExampleTestCase::DoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: } sl@0: sl@0: sl@0: void CExampleTestCase::ProcessKey(TKeyCode &aKey) sl@0: { // the default implementation does this already, but we will store the key here again anyway sl@0: iKeyCodeInput = aKey; sl@0: sl@0: } sl@0: sl@0: void CExampleTestCase::FuncA(CTestCaseRoot *pThis) sl@0: { sl@0: CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis); sl@0: // cancel any pending call, and then complete our active obj with a timeout value sl@0: test.Printf(_L("@@@ FuncA cancel a keyboard Read() @@@\n")); sl@0: sl@0: p->iConsole->ReadCancel(); sl@0: sl@0: } sl@0: sl@0: void CExampleTestCase::FuncB(CTestCaseRoot *pThis) sl@0: { sl@0: CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis); sl@0: // cancel any pending call, and then complete our active obj with a timeout value sl@0: test.Printf(_L("@@@ FuncB cancel a 'B' keyboard Read() @@@\n")); sl@0: sl@0: p->Cancel(); sl@0: p->iConsole->ReadCancel(); sl@0: sl@0: TRequestStatus* s = &p->iStatus; sl@0: p->iStatus = KRequestPending; sl@0: sl@0: p->SetActive(); sl@0: User::RequestComplete(s, KTestCaseWatchdogTO); sl@0: sl@0: } sl@0: sl@0: sl@0: // handle event completion sl@0: void CExampleTestCase::RunStepL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Obtain the completion code for this CActive obj. sl@0: TInt completionCode(iStatus.Int()); sl@0: RDebug::Printf("Example test iStatus compl.=%d\n", completionCode); sl@0: //test.Printf(_L("Example test iStatus compl.=%d\n"), completionCode); sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case EFirstStep: sl@0: iCaseStep=ESecondStep; sl@0: test.Printf(_L("Test step 1\n")); sl@0: sl@0: SelfComplete(); sl@0: break; sl@0: case ESecondStep: sl@0: iCaseStep=EThirdStep; sl@0: test.Printf(_L("Test step 2\n")); sl@0: test.Printf(_L("(this test step uses Keyboard)\n")); sl@0: test.Printf(_L("Press ANY key once you have removed the 'A' connector...\n")); sl@0: RequestCharacter(); sl@0: iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncA); sl@0: break; sl@0: case EThirdStep: sl@0: test.Printf(_L("key was a '%c'\n"), iKeyCodeInput); sl@0: iWDTimer->Cancel(); sl@0: iCaseStep=EFourthStep; sl@0: test.Printf(_L("Test step 3\n")); sl@0: test.Printf(_L("(this test step uses Keyboard)\n")); sl@0: test.Printf(_L("Press key once you have removed the 'A' connector...\n")); sl@0: RequestCharacter(); sl@0: iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncB); sl@0: sl@0: break; sl@0: case EFourthStep: sl@0: test.Printf(_L("key was a '%c'\n"), iKeyCodeInput); sl@0: test.Printf(_L("Test step 4\n")); sl@0: iWDTimer->Cancel(); sl@0: sl@0: iCaseStep=EFifthStep; sl@0: if (' ' != iKeyCodeInput) sl@0: { sl@0: sl@0: iCaseStep=EThirdStep; sl@0: } sl@0: SelfComplete(); sl@0: break; sl@0: case EFifthStep: sl@0: iCaseStep=ESixthStep; sl@0: test.Printf(_L("Test step 5\n")); sl@0: test.Printf(_L("(this test uses a delay)\n")); sl@0: iTimer.After(iStatus, 500000); sl@0: SetActive(); sl@0: break; sl@0: case ESixthStep: sl@0: iCaseStep=ELastStep; sl@0: test.Printf(_L("Test step 6(%d)\n"), completionCode); sl@0: RequestCharacter(); sl@0: iConsole->ReadCancel(); sl@0: Cancel(); sl@0: RequestCharacter(); sl@0: sl@0: //SelfComplete(); sl@0: break; sl@0: case ELastStep: sl@0: iCaseStep=ESecondStep; sl@0: test.Printf(_L("LAST step7 code (%d)\n"), completionCode); sl@0: TestPolicy().SignalTestComplete(KErrNone); sl@0: return TestPassed(); sl@0: //break; sl@0: sl@0: default: sl@0: //test.Printf(_L(" unknown test step")); sl@0: Cancel(); sl@0: TestFailed(KErrCorrupt, _L("unknown test step")); sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: