common/tools/ats/smoketest/apploader/Src/TestAppLoaderKillProcess.cpp
changeset 117 483f966c6335
child 872 17498133d9ad
equal deleted inserted replaced
113:7f0174848f99 117:483f966c6335
       
     1 // Copyright (c) 2006-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 "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This contains CTestAppLoaderKillProcess
       
    15 // 
       
    16 //
       
    17 
       
    18 // USER includes
       
    19 #include "TestAppLoaderKillProcess.h"
       
    20 
       
    21 // EPOC includes
       
    22 #include <w32std.h>
       
    23 #include <coemain.h>
       
    24 #include <apgtask.h>
       
    25 #include <apgcli.h>
       
    26 #include <apgwgnam.H>
       
    27 
       
    28 /*@{*/
       
    29 /// Parameters
       
    30 _LIT(KProgram,					"program");
       
    31 
       
    32 /// Log messages
       
    33 _LIT(KLogProcess,				"Process '%S'.");
       
    34 
       
    35 /// Error messages
       
    36 _LIT(KErrMissingParameter,		"Misssing Parameter %S");
       
    37 _LIT(KErrProcessNotFound,		"Process '%S' not found");
       
    38 /*@}*/
       
    39 
       
    40 // constructor
       
    41 CTestAppLoaderKillProcess::CTestAppLoaderKillProcess()
       
    42 :	CTestAppLoaderBase()
       
    43 	{
       
    44 	SetTestStepName(_L("KillProcess"));
       
    45 	}
       
    46 
       
    47 // Each test step must supply a implementation for doTestStepL
       
    48 enum TVerdict CTestAppLoaderKillProcess::doTestStepL( void )
       
    49 	{
       
    50 	// Printing to the console and log file
       
    51 	INFO_PRINTF1(_L("TEST-> KILL PROCESS"));
       
    52 
       
    53 	TPtrC	program;
       
    54 	if ( !GetStringFromConfig(ConfigSection(), KProgram, program) )
       
    55 		{
       
    56 		ERR_PRINTF2(KErrMissingParameter, &KProgram());
       
    57 		SetTestStepResult(EFail);
       
    58 		}
       
    59 	else
       
    60 		{
       
    61 	    TFindProcess	findProcess;
       
    62 	    TFullName		currentProcessName;
       
    63 	    RProcess		process;
       
    64 	    TBool			searching=ETrue;
       
    65 	    while ( (findProcess.Next(currentProcessName)==KErrNone) && searching )
       
    66 	    	{
       
    67 	        User::LeaveIfError(process.Open(currentProcessName));
       
    68 	        CleanupClosePushL(process);
       
    69 
       
    70 	        HBufC*	fileName = process.FileName().AllocLC();
       
    71 
       
    72 	        TPtrC	name=*fileName;
       
    73 	        INFO_PRINTF2(KLogProcess, &name);
       
    74 	        if ( program.CompareC(name)==0 )
       
    75 	        	{
       
    76 	        	searching=EFalse;
       
    77 	        	process.Kill(0);
       
    78 	        	}
       
    79 	        CleanupStack::PopAndDestroy(2, &process);   // cmdLine, fileName, process
       
    80 			}
       
    81 	    if ( searching )
       
    82 	    	{
       
    83 	        ERR_PRINTF2(KErrProcessNotFound, &program);
       
    84 			SetTestStepResult(EFail);
       
    85 	    	}
       
    86 		}
       
    87 
       
    88 	// test steps return a result
       
    89 	return TestStepResult();
       
    90 	}