messagingfw/msgtestfw/TestActions/Sms/src/CMtfTestActionCheckIfSmsWatcherRunning.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2003-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // CheckIfSmsWatcherRunning
       
    17 // [Action Parameters]
       
    18 // TBool Started <output-completion>:   ETrue if the SMS watcher is running, EFalse otherwise.
       
    19 // [Action Description]
       
    20 // Checks if the SMS watcher is running.
       
    21 // The action waits for the SMS watcher to start before completing
       
    22 // [APIs Used]
       
    23 // None
       
    24 // __ACTION_INFO_END__
       
    25 // 
       
    26 //
       
    27 
       
    28 /**
       
    29  @file
       
    30 */
       
    31 
       
    32 #include "CMtfTestActionCheckIfSmsWatcherRunning.h"
       
    33 #include "CMtfTestCase.h"
       
    34 #include "CMtfTestActionParameters.h"
       
    35 #include "TestFrameworkActionsUtils.h"
       
    36 #include "CMtfTestActionUtilsTimer.h"
       
    37 
       
    38 #include <smsuaddr.h>
       
    39 
       
    40 const TInt KWaitForSmsWatcherToStart = 2;
       
    41 const TInt KWaitForSmsWatcherToStartCounter = 5;
       
    42 
       
    43 
       
    44 CMtfTestAction* CMtfTestActionCheckIfSmsWatcherRunning::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    45 	{
       
    46 	CMtfTestActionCheckIfSmsWatcherRunning* self = new (ELeave) CMtfTestActionCheckIfSmsWatcherRunning(aTestCase);
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL(aActionParameters);
       
    49 	CleanupStack::Pop();
       
    50 	return self;
       
    51 	}
       
    52 	
       
    53 
       
    54 CMtfTestActionCheckIfSmsWatcherRunning::CMtfTestActionCheckIfSmsWatcherRunning(CMtfTestCase& aTestCase)
       
    55 	:CMtfTestAction(aTestCase)
       
    56 	{
       
    57 	iCounter = KWaitForSmsWatcherToStartCounter;
       
    58 	}
       
    59 	
       
    60 
       
    61 CMtfTestActionCheckIfSmsWatcherRunning::~CMtfTestActionCheckIfSmsWatcherRunning()
       
    62 	{
       
    63 	Cancel();
       
    64 	delete iTimer;
       
    65 	}
       
    66 	
       
    67 	
       
    68 void CMtfTestActionCheckIfSmsWatcherRunning::DoCancel()
       
    69 	{
       
    70 	iTimer->Cancel();
       
    71 	}
       
    72 	
       
    73 
       
    74 void CMtfTestActionCheckIfSmsWatcherRunning::ExecuteActionL()
       
    75 	{
       
    76 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCheckIfSmsWatcherRunning);
       
    77 	CActiveScheduler::Add(this);
       
    78 	TBool smsWatcherStarted = EFalse;
       
    79 	
       
    80 	if(TestFrameworkActionsUtils::CheckIfSmsWatcherAlreadyRunningL())
       
    81 		{
       
    82 		smsWatcherStarted = ETrue;
       
    83 		StoreParameterL<TInt>(TestCase(),smsWatcherStarted,ActionParameters().Parameter(0));
       
    84 		TestCase().ActionCompletedL(*this);
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		//Wait for the SMS watcher to start
       
    89 		iTimer = CMtfTestActionUtilsTimer::NewL();
       
    90 		iTimer->After(KWaitForSmsWatcherToStart,iStatus);
       
    91 		SetActive();
       
    92 		}
       
    93 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCheckIfSmsWatcherRunning);
       
    94 	}
       
    95 		
       
    96 		
       
    97 void CMtfTestActionCheckIfSmsWatcherRunning::RunL()
       
    98 	{
       
    99 	User::LeaveIfError(iStatus.Int());
       
   100 	
       
   101 	TBool smsWatcherStarted = EFalse;
       
   102 	
       
   103 	if(TestFrameworkActionsUtils::CheckIfSmsWatcherAlreadyRunningL())
       
   104 		{
       
   105 		smsWatcherStarted = ETrue;
       
   106 		StoreParameterL<TInt>(TestCase(),smsWatcherStarted,ActionParameters().Parameter(0));
       
   107 		TestCase().ActionCompletedL(*this);
       
   108 		}
       
   109 	else
       
   110 		{	
       
   111 		// SMS Watcher is not running, restart the timer or decide to leave
       
   112 		if(iCounter--)
       
   113 			{
       
   114 			iTimer->After(KWaitForSmsWatcherToStartCounter,iStatus);
       
   115 			SetActive();
       
   116 			}
       
   117 		else
       
   118 			{
       
   119 			StoreParameterL<TInt>(TestCase(),smsWatcherStarted,ActionParameters().Parameter(0));
       
   120 			TestCase().ActionCompletedL(*this);
       
   121 			}
       
   122 		}
       
   123 	}