sysstatemgmt/systemstarter/test/tapstart/src/tapstart_step.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 <apgtask.h>
       
    23 
       
    24 #include <apastarter.h>
       
    25 #include "tapstart_step.h"
       
    26 #include "testapps.h"
       
    27 
       
    28 _LIT(KApStartDLL, "apstart.dll");
       
    29 typedef CApaStarter* (*TFuncNewL)();
       
    30 
       
    31 CApStartTestStep::CApStartTestStep()
       
    32 	{
       
    33 	SetTestStepName(KCTestCaseApStart);
       
    34 	}
       
    35 
       
    36 TVerdict CApStartTestStep::doTestStepPreambleL()
       
    37 	{
       
    38 	// Load the CApaStarter implementation
       
    39 	RLibrary lib;
       
    40 	User::LeaveIfError(lib.Load(KApStartDLL)); // load the library
       
    41 	CleanupClosePushL(lib);		
       
    42 	TLibraryFunction ord1 = lib.Lookup(1); // This is the NewL function
       
    43 	TFuncNewL funcL = reinterpret_cast<TFuncNewL>(ord1);
       
    44 	iAppStart = static_cast<CApaStarter*> (funcL());	
       
    45 	CleanupStack::PopAndDestroy(&lib);
       
    46 		
       
    47 	return CTestStep::doTestStepPreambleL();	
       
    48 	}
       
    49 
       
    50 TVerdict CApStartTestStep::doTestStepPostambleL()
       
    51 	{
       
    52 	delete iAppStart;
       
    53 	iAppStart = NULL;
       
    54 	
       
    55  	return CTestStep::doTestStepPostambleL();
       
    56 	}
       
    57 
       
    58 TVerdict CApStartTestStep::doTestStepL()
       
    59 	{
       
    60 	INFO_PRINTF1(_L("CApStartTestStep started....\n"));
       
    61 	__UHEAP_MARK;
       
    62 	
       
    63 	RWsSession wsSession;
       
    64 	User::LeaveIfError(wsSession.Connect());
       
    65 	CleanupClosePushL(wsSession);	
       
    66 	
       
    67 	TRAPD(err, TestStartAndForgetL(wsSession));
       
    68 	TESTE(KErrNone == err, err);
       
    69 
       
    70 	TRAP(err, TestStartAndFollowUpL(wsSession));
       
    71 	TESTE(KErrNone == err, err);
       
    72 	
       
    73 	CleanupStack::PopAndDestroy();	//wsSession.Close();
       
    74 	
       
    75 	TRAP(err, TestInitApparcL());
       
    76 	TESTE(KErrNone == err, err);
       
    77 
       
    78 	__UHEAP_MARKEND; 
       
    79 	INFO_PRINTF1(_L(".... CApStartTestStep finished!!"));
       
    80 	
       
    81 	return TestStepResult();
       
    82 	}
       
    83 
       
    84 /**
       
    85 Old Test CaseID 		APPFWK-APSTART-0001
       
    86 New Test CaseID 		DEVSRVS-SYSSTART-APSTART-0001
       
    87  */
       
    88 
       
    89 
       
    90 void CApStartTestStep::TestStartAndForgetL(RWsSession& aWsSession)
       
    91 	{
       
    92 	INFO_PRINTF1(_L("Entering test case: APPFWK-APSTART-0001"));
       
    93 	
       
    94 	TApaTask task = TestStartL(NULL, aWsSession);
       
    95 	
       
    96 	if(task.Exists())
       
    97 		{
       
    98 		task.KillTask();
       
    99 		INFO_PRINTF1(_L("Leaving test case: APPFWK-APSTART-0001\n"));
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		ERR_PRINTF1(_L("APPFWK-APSTART-0001 failed\n"));  
       
   104 		}
       
   105 	}
       
   106 
       
   107 /**
       
   108 Old Test CaseID 		APPFWK-APSTART-0002
       
   109 New Test CaseID 		DEVSRVS-SYSSTART-APSTART-0001
       
   110  */
       
   111 
       
   112 void CApStartTestStep::TestStartAndFollowUpL(RWsSession& aWsSession)
       
   113 	{
       
   114 	INFO_PRINTF1(_L("Entering test case: APPFWK-APSTART-0002"));	
       
   115 	
       
   116 	TRequestStatus status;
       
   117 	TApaTask task = TestStartL(&status, aWsSession);
       
   118 	TESTE(KErrNone == status.Int(), status.Int());
       
   119 	
       
   120 	if(task.Exists())
       
   121 		{
       
   122 		task.KillTask();
       
   123 		INFO_PRINTF1(_L("Leaving test case: APPFWK-APSTART-0002\n"));
       
   124 		}
       
   125 	else
       
   126 		{
       
   127 		ERR_PRINTF1(_L("APPFWK-APSTART-0002 failed\n"));  
       
   128 		}
       
   129 	}
       
   130 
       
   131 /**
       
   132 Old Test CaseID 		APPFWK-APSTART-0003
       
   133 New Test CaseID 		DEVSRVS-SYSSTART-APSTART-0001
       
   134  */
       
   135 
       
   136 void CApStartTestStep::TestInitApparcL()
       
   137 	{ // Leavescan, this implementation of this method does not leave but further derived implementations may if they choose
       
   138 	INFO_PRINTF1(_L("Entering test case: APPFWK-APSTART-0003"));
       
   139 	INFO_PRINTF1(_L("Going to sleep until Apparc finished initialisation."));
       
   140 	TRAPD(err, iAppStart->WaitForApparcToInitialiseL());
       
   141 	TEST(err == KErrNone);
       
   142 	if(err)
       
   143 		ERR_PRINTF2(_L("APPFWK-APSTART-0003 finished with errorcode = '%d'\n"), err);  
       
   144 	else
       
   145 		INFO_PRINTF1(_L("Leaving test case: APPFWK-APSTART-0003\n"));
       
   146 	}
       
   147 
       
   148 /**
       
   149  * Common implementation for test case 0001 and 0002. See INFO_PRINTs for further information.
       
   150  */
       
   151 TApaTask CApStartTestStep::TestStartL(TRequestStatus* aRequestStatus, RWsSession& aWsSession)
       
   152 	{
       
   153 	INFO_PRINTF1(_L("Requesting start of KTestAppGood in foreground."));
       
   154 	const TDesC& cmdLineParams = KNullDesC;
       
   155 	const TBool viewLess = EFalse;
       
   156 	const TBool startInBackground = EFalse;
       
   157 	TThreadId tId;
       
   158 	if(aRequestStatus)
       
   159 		{
       
   160 		iAppStart->StartAppL(KTestAppGood, cmdLineParams, viewLess, startInBackground, tId, *aRequestStatus);
       
   161 		}
       
   162 	else
       
   163 		{
       
   164 		iAppStart->StartAppL(KTestAppGood, cmdLineParams, viewLess, startInBackground, tId);
       
   165 		}
       
   166 		
       
   167 	RThread thread;
       
   168 	RProcess process;
       
   169 	INFO_PRINTF1(_L("Verifying that the process was created."));
       
   170 	TEST(KErrNone == thread.Open(tId));
       
   171 	TEST(KErrNone == thread.Process(process)); 
       
   172 	
       
   173 	INFO_PRINTF1(_L("Waiting for KTestAppGood to resume."));
       
   174 	if(aRequestStatus)
       
   175 		{
       
   176 		User::WaitForRequest(*aRequestStatus);
       
   177 		}
       
   178 	else
       
   179 		{
       
   180 		TRequestStatus status;
       
   181 		process.Rendezvous(status);
       
   182 		User::WaitForRequest(status);
       
   183 		}
       
   184 	process.Close();
       
   185 	thread.Close();
       
   186 	
       
   187 	INFO_PRINTF1(_L("Verifying that KTestAppGood is now up and running."));
       
   188 	TApaTaskList taskList(aWsSession); 
       
   189 	const TUid appUid = {KTestAppGoodUid};
       
   190 	TApaTask task = taskList.FindApp(appUid);
       
   191 	TEST(task.Exists());
       
   192 	
       
   193 	return task;
       
   194 	}