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: // testengine.cpp sl@0: // @internalComponent sl@0: // Test Case watchdog implementation 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: sl@0: sl@0: sl@0: sl@0: const TInt KMagicNumberWDogValid = 0xF143F00D; sl@0: _LIT(KMsgWatchdogPanicd, "Test Case watchdog error"); sl@0: sl@0: // sl@0: // CTestCaseWatchdog: Timer for any OTG event (async calls) time-outs sl@0: // sl@0: sl@0: CTestCaseWatchdog::CTestCaseWatchdog() sl@0: : CTimer(EPriorityUserInput) sl@0: { sl@0: } sl@0: sl@0: sl@0: CTestCaseWatchdog::~CTestCaseWatchdog() sl@0: { sl@0: Cancel(); sl@0: iValidConstr = 0; sl@0: } sl@0: sl@0: sl@0: CTestCaseWatchdog* CTestCaseWatchdog::NewL() sl@0: { sl@0: CTestCaseWatchdog *self = new (ELeave) CTestCaseWatchdog(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CTestCaseWatchdog::ConstructL() sl@0: { sl@0: iValidConstr = KMagicNumberWDogValid; sl@0: CTimer::ConstructL(); sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: void CTestCaseWatchdog::RunL() sl@0: // Timer request has completed, so notify the timer's owner that we timed out sl@0: { sl@0: LOG_FUNC sl@0: __ASSERT_ALWAYS(iCancelFriendFunc, User::Panic(KMsgWatchdogPanicd, EPanicWatchdogError)); sl@0: __ASSERT_ALWAYS(iThisPointer, User::Panic(KMsgWatchdogPanicd, EPanicWatchdogError)); sl@0: (*iCancelFriendFunc)(iThisPointer); sl@0: iCancelFriendFunc = NULL; sl@0: } sl@0: sl@0: sl@0: // call back setup sl@0: void CTestCaseWatchdog::IssueRequest(TInt aWatchdogIntervalMS, sl@0: CTestCaseRoot* pRoot, sl@0: WDCancellerMethod cancelMethod) sl@0: { sl@0: LOG_VERBOSE2(_L("Watchdogging this step for %d ms\n"), aWatchdogIntervalMS); sl@0: if (IsValid()) sl@0: { sl@0: Cancel(); sl@0: sl@0: iThisPointer = pRoot; // save caller instance data sl@0: iCancelFriendFunc = cancelMethod; // save cancel handler sl@0: iMSRequested = aWatchdogIntervalMS; sl@0: After(aWatchdogIntervalMS * 1000); // convert to uS sl@0: } sl@0: } sl@0: sl@0: sl@0: /** IsValid sl@0: A common mistake is to not new() this event source and start using it before instantiation sl@0: */ sl@0: TBool CTestCaseWatchdog::IsValid() sl@0: { sl@0: // return ETrue if the object is validly constructed sl@0: // This is test code, or else we would ifdef this out sl@0: if (KMagicNumberWDogValid!= iValidConstr) sl@0: { sl@0: sl@0: test.Printf(_L("CTestCaseWatchdog obj not properly constructed!\n")); sl@0: return(EFalse); sl@0: } sl@0: return(ETrue); sl@0: } sl@0: sl@0: sl@0: