fep/frontendprocessor/test/src/TAPPMORSE.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 "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 // @file
       
    15 // @test
       
    16 // @internalComponent - Internal Symbian test code
       
    17 // This is a FEP crash test.\n
       
    18 // Launch the application and load the Morse FEP (TAPPMORSE.FEP).\n
       
    19 // Create the stream code using character array.\n Offer these simulated events to the application.\n
       
    20 // FEP intercepts these events. On success the application exits without a crash.\n  
       
    21 // ___Install_Fep	// Define this if you want to use an extern fep
       
    22 // 
       
    23 //
       
    24 
       
    25       
       
    26 #include <eikdef.h>
       
    27 #include <eikenv.h>
       
    28 #include <eikapp.h>
       
    29 #include <eikdoc.h>
       
    30 #include <eikappui.h>
       
    31 #include <uikon.hrh>
       
    32 #include <w32std.h>
       
    33 #include <fepbase.h>
       
    34 
       
    35 #include "TAppMorse.h"
       
    36 
       
    37 //
       
    38 //	Forward class declarations
       
    39 //
       
    40 class CTAppMorseAppView;
       
    41 class CTAppMorseAppUi;
       
    42 class CTAppMorseDocument;
       
    43 class CTAppMorseApplication;
       
    44 
       
    45 //
       
    46 //	Constant definitions
       
    47 //
       
    48 
       
    49 //const TUid KUidTAppMorse				= { 0x01000001 };
       
    50 
       
    51 //Character codes to create the stream 
       
    52 const TUint KFirstTestStreamCode	= 'A';
       
    53 const TUint KListTestStreamCode		= 'Z';
       
    54 const TUint KSizeTestStream			= KListTestStreamCode - KFirstTestStreamCode;
       
    55 _LIT(KTAPPMORSEResourceFilePath,""/*"z:\\system\\data\\tappmorse.rsc"*/);
       
    56 
       
    57 #ifdef ___Install_Fep 	// Define this if you want to use an extern fep
       
    58 _LIT(KLitFepMorseDllName, "\\system\\fep\\TAPPMORSE.FEP");
       
    59 const TUid KUidTAppMorseFep = { 0x11111111 };
       
    60 #else					// Not defined, to use the internal fep
       
    61 	
       
    62 	
       
    63 //
       
    64 //	CStackFaultTestFep members definitions
       
    65 
       
    66 
       
    67 /**
       
    68 	Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
    69 	Return a fully constructed object of CCoeFep\n
       
    70 
       
    71 */
       
    72 CCoeFep* CStackFaultTestFep::NewFepL( CCoeEnv& aConeEnvironment, const CCoeFepParameters& aFepParameters )
       
    73 	{
       
    74 	CStackFaultTestFep* const fep=new(ELeave) CStackFaultTestFep(aConeEnvironment);
       
    75 	CleanupStack::PushL(fep);
       
    76 	fep->ConstructL(aFepParameters);
       
    77 	CleanupStack::Pop(); // fep
       
    78 	return fep;
       
    79 	}
       
    80 /**
       
    81   
       
    82   Constructor
       
    83   
       
    84 */
       
    85 CStackFaultTestFep::CStackFaultTestFep(CCoeEnv& aConeEnvironment)
       
    86 	:CCoeFep(aConeEnvironment)
       
    87 	{
       
    88 	}
       
    89 /**
       
    90   Auxiliary Function for  Test Case ID TAppMorse-doTestStepL.\n
       
    91   Initialise the FEP's generic settings\n
       
    92   Sets this FEP's attributes with values from the global settings\n
       
    93   Create a stream (character array)\n
       
    94   Simulates key event for each of the character codes in the array passed to it\n
       
    95   
       
    96 */
       
    97 void CStackFaultTestFep::ConstructL(const CCoeFepParameters& aFepParameters)
       
    98 	{
       
    99 	BaseConstructL(aFepParameters);
       
   100 	ReadAllAttributesL();
       
   101 	
       
   102 	//Set stream to owner.  Stream will be rubbish unless Morse test app had focus
       
   103 	RArray<TUint> aChars;
       
   104 	for( TUint i=0; i<=KSizeTestStream; i++ )
       
   105 		aChars.Insert( i+KFirstTestStreamCode, i );
       
   106 	SimulateKeyEventsL( aChars.Array() );
       
   107 	aChars.Close();
       
   108 	}
       
   109 #endif
       
   110 
       
   111 
       
   112 //
       
   113 //	CTAppMorseAppView members definition
       
   114 
       
   115 
       
   116 /**
       
   117  Auxiliary Function for  Test Case ID TAppMorse-doTestStepL.\n
       
   118  Initialise a pointer to CTAppMorseAppView and return it\n
       
   119 
       
   120 */
       
   121 CTAppMorseAppView* CTAppMorseAppView::NewL(const TRect& aRect, CTmsTestStep* aStep )
       
   122 	{
       
   123 
       
   124 	CTAppMorseAppView* self = new(ELeave) CTAppMorseAppView(aStep);
       
   125 	CleanupStack::PushL(self);
       
   126 	self->ConstructL(aRect);
       
   127 	CleanupStack::Pop();
       
   128 	return self;
       
   129 	};
       
   130 /**
       
   131    Constructor \n
       
   132   
       
   133  */	
       
   134 CTAppMorseAppView::CTAppMorseAppView(CTmsTestStep* aStep)
       
   135 	: iStop( NULL )
       
   136 	, iTestFep( NULL )
       
   137 	, iNextValidScanCode( KFirstTestStreamCode )
       
   138 	, iStep(aStep)
       
   139 	{INFO_PRINTF1(_L("AppMorse App View Default Constructor"));
       
   140 	}
       
   141 /**
       
   142   Auxiliary Function for  Test Case ID TAppMorse-doTestStepL.\n
       
   143   Creates a control's window \n
       
   144   Set the control's extent and as ready to be drawn \n
       
   145   Initialize the active object \n
       
   146   Install the FEP, if an external fep is to be used,else use internal FEP \n
       
   147   Create a fully constructed object of CStackFaultTestFep class \n
       
   148   
       
   149 */	
       
   150 void CTAppMorseAppView::ConstructL( const TRect& aRect )
       
   151 	{
       
   152 	INFO_PRINTF1(_L("App Mosre App View Construct L"));
       
   153 	CreateWindowL();
       
   154 	SetRect(aRect);
       
   155 	ActivateL();
       
   156 	iStop = new(ELeave) CTAppMorseAppView::CStop( iEikonEnv );
       
   157 #ifdef ___Install_Fep	// Define this if you what to use an extern fep
       
   158 	iCoeEnv->InstallFepL(KUidTAppMorseFep);
       
   159 #else					// Not defined to use the internal fep
       
   160 	CCoeFepParameters* pFepParams = NULL; // this is passed into a reference parameter - this pointer should never be dereferenced
       
   161 	iTestFep = CStackFaultTestFep::NewFepL(*ControlEnv(), *pFepParams );
       
   162 #endif	
       
   163 	};
       
   164 /**
       
   165   
       
   166    Destructor \n
       
   167    delete the FEP object and the active object\n
       
   168   
       
   169  */	
       
   170 CTAppMorseAppView::~CTAppMorseAppView()
       
   171 	{
       
   172 	delete iStop;
       
   173 	delete iTestFep;
       
   174 	}
       
   175 /**
       
   176    Auxiliary Function for  Test Case ID TAppMorse-doTestStepL.\n
       
   177    Send the key events to CCoeControl::OfferKeyEventL() to handle \n
       
   178   
       
   179  */	
       
   180 TKeyResponse CTAppMorseAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   181 	{
       
   182 	INFO_PRINTF3(_L("OfferKeyeventL, EventCode %d , EventCode %d"), aKeyEvent.iCode, aType);
       
   183 	if( aKeyEvent.iCode != iNextValidScanCode++ )
       
   184 		{
       
   185 		iNextValidScanCode = KFirstTestStreamCode;
       
   186 		}
       
   187 	else
       
   188 		{
       
   189 		if( iNextValidScanCode > KListTestStreamCode )
       
   190 			{
       
   191 			DoTestL();
       
   192 			};
       
   193 		};
       
   194 	return CCoeControl::OfferKeyEventL(aKeyEvent,aType);
       
   195 	};
       
   196 /**
       
   197   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   198   Install the external FEP, if to be used.\n
       
   199   Call DoStop() of CStop \n
       
   200    
       
   201 */
       
   202 void CTAppMorseAppView::DoTestL()
       
   203 	{
       
   204 	INFO_PRINTF1(_L("Executing Test"));
       
   205 #ifdef ___Install_Fep	// Define this if you what to use an extern fep
       
   206 	iCoeEnv->InstallFepL(KNullUid);
       
   207 	iStop->DoStop();
       
   208 	TRAPD(exitCondition,CActiveScheduler::Start());	
       
   209 	if (exitCondition!=KLeaveExit)
       
   210 		User::Leave(exitCondition);
       
   211 #else					// Not defined to use the internal fep
       
   212 	delete iTestFep;
       
   213 	iTestFep = NULL;
       
   214 #endif
       
   215 	iStop->DoStop();
       
   216 	}
       
   217 
       
   218 //	CTAppMorseAppView::CStop members definition
       
   219 
       
   220 
       
   221 /**
       
   222   
       
   223   Constructor \n
       
   224   Adds the active object to the current active scheduler \n
       
   225  
       
   226 */
       
   227 CTAppMorseAppView::CStop::CStop( CEikonEnv* env ) 
       
   228 	: CActive(EPriorityLow)
       
   229 	, iEikEnv( env )
       
   230 	{
       
   231 	CActiveScheduler::Add(this);
       
   232 	}
       
   233 /**
       
   234   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   235   Indicate the completion status of a request made to a service provider \n
       
   236  		
       
   237   Signal the current thread that the asynchronous request associated \n
       
   238   with the specified request status object is complete (RequestComplete) \n
       
   239  
       
   240   Indicates that the active object has issued a request \n
       
   241   and that it is now outstanding(Set Active) \n
       
   242   
       
   243 */			
       
   244 void CTAppMorseAppView::CStop::DoStop()
       
   245 	{
       
   246 	TRequestStatus* requestStatus=&iStatus;
       
   247 	User::RequestComplete(requestStatus, KErrNone);
       
   248 	SetActive();
       
   249 	}
       
   250 /**
       
   251  Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   252  Handles any leave occurring in the request completion event(RunL) \n
       
   253  
       
   254 */			
       
   255 TInt CTAppMorseAppView::CStop::RunError(TInt)
       
   256 	{
       
   257 	return KLeaveExit;
       
   258 	}
       
   259 /**
       
   260  Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   261  Do nothing \n
       
   262  
       
   263 */		
       
   264 void CTAppMorseAppView::CStop::DoCancel()
       
   265 	{
       
   266 	};
       
   267 /**
       
   268   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   269   Handle active object's request completion event \n
       
   270  
       
   271 */			
       
   272 void CTAppMorseAppView::CStop::RunL()
       
   273 	{
       
   274 	//Uncomment the following line if tester wants active confirmation success
       
   275 	//iEikEnv->AlertWin( _L( "No Defect. Press Continue to exit" ) );
       
   276 	static_cast< CTAppMorseAppUi* >( iEikEnv->AppUi() )->DoExit();
       
   277 	};
       
   278 
       
   279 //	CTAppMorseAppUi members definition
       
   280 
       
   281 /**
       
   282 
       
   283  Constructor \n
       
   284 
       
   285 */
       
   286 CTAppMorseAppUi::CTAppMorseAppUi(CTmsTestStep* aStep)
       
   287 	: CTestAppUi(aStep,KTAPPMORSEResourceFilePath), iAppView( NULL )
       
   288 	{INFO_PRINTF1(_L("App Morse default constructor"));
       
   289 	}
       
   290 /**
       
   291    Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   292    Inserts a control into the app UI's control stack (AddToStackL) \n
       
   293    Call StartAutoTest() of AutoTestManager() \n
       
   294     
       
   295  */	
       
   296 void CTAppMorseAppUi::ConstructL(CTmsTestStep* aStep)
       
   297 	{
       
   298 	INFO_PRINTF1(_L("AppMoresAppUI ContructL"));
       
   299 	CTestAppUi::ConstructL();
       
   300 	iAppView = CTAppMorseAppView::NewL(ClientRect(),aStep);
       
   301 	AddToStackL( iAppView );
       
   302 	AutoTestManager().StartAutoTest();
       
   303 	};
       
   304 /**
       
   305    
       
   306    Destructor \n
       
   307    Removes the control from the app UI's control stack \n
       
   308     
       
   309  */
       
   310 CTAppMorseAppUi::~CTAppMorseAppUi()
       
   311 	{
       
   312 	RemoveFromStack( iAppView );
       
   313 	delete iAppView;
       
   314 	};
       
   315 /**
       
   316   
       
   317   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   318   Do nothing for step number value 1\n
       
   319  
       
   320 */	
       
   321 void CTAppMorseAppUi::RunTestStepL(TInt aStepNum)
       
   322 	{
       
   323 	switch (aStepNum)
       
   324 		{
       
   325 		case 1:
       
   326 			{
       
   327 			}
       
   328 		}
       
   329 	}
       
   330 /**
       
   331   
       
   332   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   333   Handle the Application exit command by calling the DoExit() \n
       
   334  
       
   335 */
       
   336 void CTAppMorseAppUi::HandleCommandL(TInt aCommand)
       
   337 	{
       
   338 	switch(aCommand)
       
   339 		{
       
   340 		case EEikCmdExit:
       
   341 			DoExit();
       
   342 			break;
       
   343 		}
       
   344 	};
       
   345 /**
       
   346   
       
   347   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   348   Close the app UI \n
       
   349  
       
   350 */	
       
   351 void CTAppMorseAppUi::DoExit()
       
   352 	{
       
   353 	Exit();
       
   354 	};
       
   355 /**
       
   356   
       
   357   Auxiliary Function for Test Case ID TAppMorse-doTestStepL.\n
       
   358   Call ConstructL() of CEikonEnv and initialize a pointer to CTAppMorseAppUi \n
       
   359   Call ConstructL() of CTAppMorseAppUi and set the application's user interface object \n
       
   360  
       
   361 */
       
   362 void CTAppMorse::ConstructAppL(CEikonEnv* aEikEnv)
       
   363 	{
       
   364 	INFO_PRINTF1(_L("CTAppMorse::ConstructAppL"));
       
   365 	aEikEnv->ConstructL();
       
   366  	CTAppMorseAppUi* appUi=new(ELeave) CTAppMorseAppUi(this);
       
   367  	appUi->ConstructL(this);
       
   368 	CleanupStack::PushL(appUi);
       
   369  	aEikEnv->SetAppUi(appUi);
       
   370 	CleanupStack::Pop();
       
   371 	}
       
   372 	
       
   373 
       
   374 CTAppMorse::~CTAppMorse()
       
   375 /**
       
   376   Destructor
       
   377  */
       
   378 	{
       
   379 	}
       
   380 
       
   381 CTAppMorse::CTAppMorse()
       
   382 /**
       
   383   Constructor
       
   384  */
       
   385 	{
       
   386 	// Call base class method to set up the human readable name for logging
       
   387 	SetTestStepName(KTAppMorse);
       
   388 	}
       
   389 /**
       
   390    @SYMTestCaseID UIF-TAppMorse-doTestStepL
       
   391   
       
   392    @SYMPREQ
       
   393   
       
   394    @SYMTestCaseDesc  Simply launch the application and offer some key events.\n
       
   395    The test is dependend on the TFepMorse FEP being installed. \n
       
   396    
       
   397    @SYMTestPriority High 
       
   398   
       
   399    @SYMTestStatus Implemented
       
   400    
       
   401    @SYMTestActions Provide an active environment for creating controls and utility functions \n
       
   402    Launches the application using ExecuteD(). Simulate key events and offer them to the 
       
   403    application
       
   404   
       
   405    @SYMTestExpectedResults The test case fails if the application crashed with an exception, due to FEP not being able to intercept the event codes. \n 
       
   406    and the test passes if the application exits cleanly. 
       
   407     
       
   408  */
       
   409 TVerdict CTAppMorse::doTestStepL()
       
   410 	{
       
   411 	SetTestStepID(_L("UIF-TAppMorse-doTestStepL"));
       
   412 	INFO_PRINTF1(_L("Test Started"));
       
   413 	
       
   414 	CEikonEnv* EikEnv=new CEikonEnv;
       
   415 	if (EikEnv==NULL)
       
   416 		{	
       
   417 			SetTestStepResult(EFail);
       
   418 			return TestStepResult();
       
   419 		}
       
   420 	TRAPD(error, ConstructAppL(EikEnv));
       
   421 	if (error!=KErrNone)
       
   422 		{
       
   423 		delete EikEnv;
       
   424 		SetTestStepResult(EFail);
       
   425 		return TestStepResult();
       
   426 		}
       
   427 
       
   428 	EikEnv->ExecuteD();
       
   429 	
       
   430 	INFO_PRINTF1(_L("Test Finished"));
       
   431 	RecordTestResultL();
       
   432 	CloseTMSGraphicsStep();
       
   433 	return TestStepResult();
       
   434 	}
       
   435 	
       
   436 
       
   437 //	End of file TAppMorse.cpp
       
   438