sysstatemgmt/systemstarter/test/tsysmon/src/tsysmon_stepnoprocmon.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 "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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include <sysmonclisess.h>
       
    23 #include <startupproperties.h>
       
    24 #include "testapps.h"
       
    25 #include "tsysmon_stepnoprocmon.h"
       
    26 
       
    27 
       
    28 CStepNoProcMon::CStepNoProcMon()
       
    29 	{
       
    30 	SetTestStepName(KCTestCaseNoProcMon);
       
    31 	}
       
    32 
       
    33 TVerdict CStepNoProcMon::doTestStepL()
       
    34 	{
       
    35 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0007"));
       
    36 	
       
    37 	DoTestNullHandleL();
       
    38 	DoTestKilledHandleL();
       
    39 	DoTestWrongHandleL();
       
    40 	
       
    41 	return TestStepResult();
       
    42 	}
       
    43 
       
    44 /**
       
    45 Old Test CaseID 		APPFWK-SYSMON-0007
       
    46 New Test CaseID 		DEVSRVS-SYSSTART-SYSMON-0007
       
    47  */
       
    48 
       
    49 void CStepNoProcMon::DoTestNullHandleL()
       
    50 	{
       
    51 	INFO_PRINTF1(_L("Requesting SysMon to monitor a process NULL handle"));
       
    52 	
       
    53 	RProcess process;
       
    54 	process.Close();
       
    55 
       
    56 	RSysMonSession sess;
       
    57 	sess.OpenL();
       
    58 	CleanupClosePushL(sess);
       
    59 	
       
    60 	CStartupProperties *prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC);
       
    61 	prop->SetMonitored(ETrue);
       
    62 	prop->SetStartMethod(EWaitForStart);	
       
    63 	prop->SetRecoveryParams(EIgnoreOnFailure, 0);
       
    64 	prop->SetNoOfRetries(1);
       
    65 	prop->SetTimeout(0);
       
    66 			
       
    67 	TRAPD(err, sess.MonitorL(*prop, process)); // check that passing in a null handle would return KErrArugment
       
    68 	
       
    69 	// check that the initiation of monitoring failed 
       
    70 	TESTE(KErrArgument == err, err);
       
    71 	if(KErrArgument == err)
       
    72 		{
       
    73 		INFO_PRINTF1(_L("Request refused with KErrArgument"));
       
    74 		}
       
    75 		
       
    76 	CleanupStack::PopAndDestroy(prop);;
       
    77 	CleanupStack::PopAndDestroy(&sess);
       
    78 	}
       
    79 
       
    80 /**
       
    81 Check that passing in a handle to a killed process will return KErrArugment
       
    82 */
       
    83 void CStepNoProcMon::DoTestKilledHandleL()
       
    84 	{
       
    85 	INFO_PRINTF1(_L("Requesting SysMon to monitor a handle to a killed process"));
       
    86 
       
    87 	RProcess process;
       
    88 	CleanupClosePushL(process);
       
    89 	User::LeaveIfError(process.Create(KTestProcGood, KNullDesC));
       
    90 	ResumeL(process);
       
    91 	
       
    92 	process.Kill(KErrNone);
       
    93 	INFO_PRINTF1(_L("Process killed."));
       
    94 	
       
    95 	RSysMonSession sess;
       
    96 	sess.OpenL();
       
    97 	CleanupClosePushL(sess);
       
    98 	
       
    99 	CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC);
       
   100 	prop->SetMonitored(ETrue);
       
   101 	prop->SetStartMethod(EWaitForStart);	
       
   102 	prop->SetRecoveryParams(EIgnoreOnFailure, 0);
       
   103 	prop->SetNoOfRetries(1);
       
   104 	prop->SetTimeout(0);
       
   105 				
       
   106 	TRAPD(err, sess.MonitorL(*prop, process));
       
   107 	
       
   108 	// check that the initiation of monitoring failed 
       
   109 	TESTE(KErrDied == err, err);
       
   110 	if(KErrDied == err)
       
   111 		{
       
   112 		INFO_PRINTF1(_L("Request refused with KErrDied"));
       
   113 		}
       
   114 		
       
   115 	CleanupStack::PopAndDestroy(prop);;
       
   116 	CleanupStack::PopAndDestroy(&sess);	
       
   117 	CleanupStack::PopAndDestroy(&process);
       
   118 	}
       
   119 
       
   120 void CStepNoProcMon::DoTestWrongHandleL()
       
   121 	{
       
   122 	INFO_PRINTF1(_L("Requesting SysMon to monitor wrong process handle"));
       
   123 	
       
   124 	RProcess process; // initiated with handle to current process
       
   125 
       
   126 	RSysMonSession sess;
       
   127 	sess.OpenL();
       
   128 	CleanupClosePushL(sess);
       
   129 	
       
   130 	CStartupProperties *prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC);
       
   131 	prop->SetMonitored(ETrue);
       
   132 	prop->SetStartMethod(EWaitForStart);	
       
   133 	prop->SetRecoveryParams(EIgnoreOnFailure, 0);
       
   134 	prop->SetNoOfRetries(1);
       
   135 	prop->SetTimeout(0);
       
   136 			
       
   137 	TRAPD(err, sess.MonitorL(*prop, process)); // check that passing in a null handle would return KErrArugment
       
   138 	
       
   139 	// check that the initiation of monitoring failed 
       
   140 	TESTE(KErrArgument == err, err);
       
   141 	if(KErrArgument == err)
       
   142 		{
       
   143 		INFO_PRINTF1(_L("Request refused with KErrArgument"));
       
   144 		}
       
   145 		
       
   146 	CleanupStack::PopAndDestroy(prop);;
       
   147 	CleanupStack::PopAndDestroy(&sess);
       
   148 	}
       
   149 
       
   150