systemhealthmanagement/systemhealthmgr/test/tsysmon/src/tsysmon_stepselfmoncancel2.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 // tsysmon_stepselfmoncancel.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <sysmonclisess.h>
       
    25 #include <startupproperties.h>
       
    26 #include <ssm/ssmstartupproperties.h>
       
    27 #include "testprocgoodsession.h"
       
    28 #include "tsysmon_stepselfmoncancel2.h"
       
    29 
       
    30 CStepSelfMonCancel2::CStepSelfMonCancel2()
       
    31 	{
       
    32 	SetTestStepName(KCTestCaseSelfMonCancel2);
       
    33 	}
       
    34 /**
       
    35 Old Test CaseID 		APPFWK-SYSMON-0009
       
    36 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0009
       
    37  */
       
    38 
       
    39 TVerdict CStepSelfMonCancel2::doTestStepL()
       
    40 	{
       
    41 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0009"));
       
    42 	
       
    43 	INFO_PRINTF1(_L("Going to start a process"));
       
    44 	RSysMonSession sysmon;
       
    45 	CleanupClosePushL(sysmon);
       
    46 	sysmon.OpenL();
       
    47 
       
    48 	INFO_PRINTF1(_L("Going to request process monitoring using startupproperties"));
       
    49 	RProcess process;
       
    50 	CleanupClosePushL(process);
       
    51 	User::LeaveIfError(process.Create(KTestProcGood, KLaunchServerCommandLineOption));
       
    52 	ResumeL(process);
       
    53 
       
    54 	CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
    55 	prop->SetStartMethod(EWaitForStart);	
       
    56 	prop->SetMonitored(ETrue);
       
    57 	prop->SetNoOfRetries(1); 
       
    58 	
       
    59 	TRAPD(err, sysmon.MonitorL(*prop, process)); 
       
    60 	TESTEL(err == KErrNone, err);
       
    61 
       
    62 	DoTestMonitorL(process);
       
    63 	
       
    64 	CleanupStack::PopAndDestroy(prop);
       
    65 	CleanupStack::Pop(&process);
       
    66 
       
    67 	INFO_PRINTF1(_L("Going to request process monitoring using ssmstartupproperties"));
       
    68 	CleanupClosePushL(process);
       
    69 	User::LeaveIfError(process.Create(KTestProcGood, KLaunchServerCommandLineOption));
       
    70 	ResumeL(process);
       
    71 
       
    72 	CSsmStartupProperties* ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
    73 	ssmProp->SetExecutionBehaviour(ESsmWaitForSignal);
       
    74 	TSsmMonitorInfo monitorInfo;
       
    75 	monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure;
       
    76 	monitorInfo.iRestartMode = 0;
       
    77 	monitorInfo.iTimeout = 0;
       
    78 	monitorInfo.iRetries = 1;
       
    79 	ssmProp->SetMonitorInfoL(monitorInfo);
       
    80 	
       
    81 	TRAP(err, sysmon.MonitorL(*ssmProp, process)); 
       
    82 	TESTEL(err == KErrNone, err);
       
    83 
       
    84 	DoTestMonitorL(process);
       
    85 	
       
    86 	CleanupStack::PopAndDestroy(ssmProp);
       
    87 	CleanupStack::PopAndDestroy(&process);
       
    88 	CleanupStack::PopAndDestroy(&sysmon);
       
    89 
       
    90 	INFO_PRINTF1(_L("Test complete"));		
       
    91 	return TestStepResult();	
       
    92 	}
       
    93 
       
    94 void CStepSelfMonCancel2::DoTestMonitorL(RProcess& aProc)
       
    95 	{
       
    96 	INFO_PRINTF1(_L("Monitoring is now setup, we will now make a request to cancel monitoring."));
       
    97 	RTestProcGoodSession server;
       
    98 	User::LeaveIfError(server.Connect());
       
    99 	TEST(KErrNone == server.CancelMonitor());
       
   100 	server.Close();
       
   101 
       
   102 	INFO_PRINTF1(_L("A second cancel-request should make no difference."));
       
   103 	User::LeaveIfError(server.Connect());
       
   104 	TEST(KErrNone == server.CancelMonitor());
       
   105 	server.Close();
       
   106 
       
   107 	//Now, killing the process will not cause sysmon to restart after KWaitTime
       
   108 	TEST(Exists(KTestProcGood));
       
   109 	aProc.Kill(KErrNone);
       
   110 	TEST(EFalse == Exists(KTestProcGood));
       
   111 	INFO_PRINTF1(_L("Killed monitored process."));
       
   112 
       
   113 	INFO_PRINTF1(_L("Going to sleep for 16 seconds."));		
       
   114 	User::After(KThrottleTime + 1000000);
       
   115 
       
   116 	INFO_PRINTF1(_L("Check that the process wasn't restarted"));		
       
   117 	TEST(EFalse == Exists(KTestProcGood));
       
   118 	}