fep/frontendprocessor/test/src/DEFOCUSING_EDWIN.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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 #include <e32std.h>
       
    22 #include <e32base.h>
       
    23 #include <coemain.h>
       
    24 #include <coeaui.h>
       
    25 #include <gulbordr.h>
       
    26 #include <techview/eikedwin.h>
       
    27 #include <eikapp.h>
       
    28 #include <eikdoc.h>
       
    29 #include <eikenv.h>
       
    30 #include <ecom/ecom.h>
       
    31 
       
    32 #include "DEFOCUSING_EDWIN.h"
       
    33 
       
    34 _LIT(KLitInitialText, "Enter some inline text (with TFEP1) here and leave it uncommitted when the timer expires: ");
       
    35 
       
    36 const TInt	KNumberOfSeconds = 5;
       
    37 
       
    38 
       
    39 /*************************************************************
       
    40  **  
       
    41  **  CTestTimer
       
    42  **  
       
    43  *************************************************************/
       
    44 
       
    45 /**
       
    46   Application exists as long as the timer .\n 
       
    47 */
       
    48 
       
    49 CTestTimer* CTestTimer::NewL(TInt aDurationInSeconds)
       
    50 	{
       
    51 	CTestTimer* timer=new(ELeave) CTestTimer(aDurationInSeconds);
       
    52 	CleanupStack::PushL(timer);
       
    53 	timer->ConstructL();
       
    54 	timer->QueueAndInfoPrint();
       
    55 	
       
    56 	//CActiveScheduler::Start();
       
    57 	CleanupStack::Pop(timer);
       
    58 	return timer;
       
    59 	}
       
    60 
       
    61 
       
    62 CTestTimer::CTestTimer(TInt aDurationInSeconds)
       
    63 	:CTimer(EActivePriorityWsEvents+1),
       
    64 	 iSecondsRemaining(aDurationInSeconds)
       
    65 	{
       
    66 	CActiveScheduler::Add(this);
       
    67 	}
       
    68 
       
    69 /**  
       
    70    Format the timer message to be send to the appliation window.
       
    71 */
       
    72 
       
    73 void CTestTimer::QueueAndInfoPrint()
       
    74 	{
       
    75 	After(iSecondsRemaining*1000000);
       
    76 	TBuf<100> message;
       
    77 	message.Format(_L("%d seconds remaining"), iSecondsRemaining);
       
    78 	User::InfoPrint(message);
       
    79 	}
       
    80 
       
    81 /**
       
    82   Inform with a message ,the timer seconds remaining till its up.\n
       
    83   Send event to windows group when timer time is up .\n
       
    84 */
       
    85 void CTestTimer::RunL()
       
    86 	{
       
    87 	--iSecondsRemaining;
       
    88 	if (iSecondsRemaining>0)
       
    89 		{
       
    90 		QueueAndInfoPrint();
       
    91 		}
       
    92 	else
       
    93 		{
       
    94 		User::InfoPrint(_L("Time's up"));
       
    95 		iCompleted = ETrue;
       
    96 		
       
    97 		CCoeEnv* env = CCoeEnv::Static();
       
    98 		TWsEvent theEvent;
       
    99 		theEvent.SetType(EEventUser + 1);
       
   100 
       
   101 		RWsSession	ws;
       
   102 		TInt theRes = ws.Connect();
       
   103 
       
   104 		if(theRes == KErrNone)
       
   105 			{
       
   106 			RWindowGroup& winGroup = env->RootWin();
       
   107 			theEvent.SetType(EEventUser + 1);
       
   108 			theEvent.SetTimeNow();
       
   109 			TInt theId = winGroup.Identifier();
       
   110 			ws.SendEventToWindowGroup(theId, theEvent);
       
   111 			}
       
   112 		ws.Close();	
       
   113 		}
       
   114 	}
       
   115 
       
   116 
       
   117 
       
   118 /*************************************************************
       
   119  **  
       
   120  **  CDefocusingEdwinUi
       
   121  **  
       
   122  *************************************************************/
       
   123 
       
   124 CDefocusingEdwinUi::CDefocusingEdwinUi(CTmsTestStep* aStep) :
       
   125 	  CTestAppUi(aStep, KNullDesC)
       
   126 	  {
       
   127 	  }
       
   128 
       
   129 CDefocusingEdwinUi::~CDefocusingEdwinUi()
       
   130 	{
       
   131 	RemoveFromStack(iTextEditor);
       
   132 	delete iTextEditor;
       
   133 	delete iTestTimer;
       
   134 	}
       
   135 
       
   136 /**
       
   137   Construct a new Editor window and set the containing window \n
       
   138   Set cursor position in the document and the word wrap \n
       
   139   Set the pointer capture and make the control ready to draw\n
       
   140   Install the FEP and call the StartAutoTest()\n
       
   141 */
       
   142 void CDefocusingEdwinUi::ConstructL()
       
   143 	{
       
   144 	CTestAppUi::ConstructL();
       
   145 	iTestTimer = CTestTimer::NewL(5);
       
   146 
       
   147 	iTextEditor=new(ELeave) CEikEdwin(TGulBorder(TGulBorder::EDeepSunkenWithOutline));
       
   148 	iTextEditor->ConstructL(CEikEdwin::EOwnsWindow, 20, 0, 3);
       
   149 	iTextEditor->SetContainerWindowL();
       
   150 	iTextEditor->SetExtent(TPoint(20, 20), iTextEditor->Size());
       
   151 	iTextEditor->SetTextL(&KLitInitialText);
       
   152 	iTextEditor->SetCursorPosL(0, EFalse); // a necessary function call as it creates the CTextView in the CEikEdwin - also it needs to be passed zero to work around a bug where if it's passed textEditor->TextLength() (to put the cursor at the end of the text) then all the text gets scrolled to the left a bit (i.e. the left centimeter or so is off-screen)
       
   153 	iTextEditor->SetWordWrapL(ETrue);
       
   154 	iTextEditor->SetPointerCapture();
       
   155 	AddToStackL(iTextEditor, ECoeStackPriorityDialog, ECoeStackFlagSharable);
       
   156 	iTextEditor->ActivateL();
       
   157 	iTextEditor->SetCursorPosL(iTextEditor->TextLength(), EFalse); // the cursor can now be put at the end of the text as the text has been laid out
       
   158 	
       
   159 	iTmStart.HomeTime();
       
   160 	
       
   161 	const TUid KUidTFep1 = { 0x102024D0 };
       
   162 	iCoeEnv->InstallFepL(KUidTFep1);
       
   163 
       
   164 	AutoTestManager().StartAutoTest();
       
   165 	}
       
   166 
       
   167 /**
       
   168    @SYMTestCaseID 		UIF-FEPTEST-0001
       
   169    @SYMPREQ				0000
       
   170    @SYMTestCaseDesc  	Launch the application and offer events.
       
   171    @SYMTestPriority 	High 
       
   172    @SYMTestStatus 		Implemented
       
   173    @SYMTestActions 		Launch an application with the editor window. The application is made to exit, when a timer expires.   
       
   174    						Load the FEP (TFEP1). Create character codes for text events. Offer the texts to the applciation for 
       
   175    						the TFEP1 to intercept.  
       
   176    						A succesful implementation ensures that the application exits without a crash.
       
   177   						Here the layout of the FEP UI is such that the Composition Window is integrated into the Target Control.  
       
   178    @SYMTestExpectedResults The test case fails if the app crashed with an exception and passes if the app exits cleanly
       
   179  */
       
   180 void CDefocusingEdwinUi::RunTestStepL(TInt aStep)
       
   181 	{
       
   182 	User::After(TTimeIntervalMicroSeconds32(1));
       
   183 
       
   184 	TTimeIntervalSeconds theInterval;
       
   185 
       
   186 	TTime tm;
       
   187 	tm.HomeTime();
       
   188 	tm.SecondsFrom(iTmStart,theInterval);
       
   189 
       
   190 	TInt theInt = theInterval.Int();
       
   191 
       
   192 	if(iCurrentSecond < theInt)
       
   193 		{
       
   194 		if(KNumberOfSeconds-iCurrentSecond < 0)
       
   195 			{
       
   196 			iCoeEnv->InstallFepL(KNullUid);
       
   197 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   198 			return;
       
   199 			}
       
   200 		else
       
   201 			{
       
   202 			TBuf<100> message;
       
   203 			message.Format(_L("%d seconds remaining"), KNumberOfSeconds-iCurrentSecond);
       
   204 			User::InfoPrint(message);
       
   205 		
       
   206 			iCurrentSecond = theInt;
       
   207 			}
       
   208 		}
       
   209 	TWsEvent theEvent;
       
   210 	TKeyEvent *theKey = theEvent.Key();
       
   211 	theKey->iScanCode = 0;
       
   212 	theKey->iModifiers= 0;
       
   213 	theKey->iRepeats=0;
       
   214 	theKey->iCode = 'A';
       
   215 	
       
   216 	TInt nRes = aStep % 7;
       
   217 
       
   218 	if(nRes == 6)
       
   219 		{
       
   220 		theKey->iCode = EKeyEnter;
       
   221 		}
       
   222 	else
       
   223 		{
       
   224 		theKey->iCode += nRes;
       
   225 		}
       
   226 
       
   227 	INFO_PRINTF2(_L("Simulate Key Event with code %d"), theKey->iCode);
       
   228 	SendEventToWindowGroups(theEvent);
       
   229 	}
       
   230 
       
   231 /**
       
   232   Handle the user defined events.\n
       
   233   Handle the System events
       
   234   Call made to the static implementation CEikAppUi::HandleSystemEventL().\n
       
   235 */
       
   236 void CDefocusingEdwinUi::HandleApplicationSpecificEventL(TInt , const TWsEvent& aEvent)
       
   237 	{
       
   238 	if(aEvent.Type() == (EEventUser + 1))
       
   239 		{
       
   240 		Exit();
       
   241 		}
       
   242 	else
       
   243 		{
       
   244 		CEikAppUi::HandleSystemEventL(aEvent);
       
   245 		}
       
   246 	}
       
   247 	
       
   248 /**
       
   249   Handle the window events.\n
       
   250   Create a window server session and connect the client\n
       
   251   Set the event type and call the SendEventToWindowGroup().\n
       
   252   Close the session on completion \n
       
   253 */
       
   254 void CDefocusingEdwinUi::SendEventToWindowGroups(TWsEvent&	aEvent)
       
   255 	{
       
   256 	RWsSession	ws;
       
   257 	TInt theRes = ws.Connect();
       
   258 	TEST(theRes == KErrNone);
       
   259 
       
   260 	RWindowGroup& winGroup = iCoeEnv->RootWin();
       
   261 	TInt theId = winGroup.Identifier();
       
   262 	
       
   263 	aEvent.SetType(EEventKeyDown);
       
   264 	aEvent.SetTimeNow();
       
   265 	ws.SendEventToWindowGroup(theId, aEvent);
       
   266 		
       
   267 	aEvent.SetType(EEventKey);
       
   268 	aEvent.SetTimeNow();
       
   269 	ws.SendEventToWindowGroup(theId, aEvent);
       
   270 
       
   271 	aEvent.SetType(EEventKeyUp);
       
   272 	aEvent.SetTimeNow();
       
   273 	ws.SendEventToWindowGroup(theId, aEvent);
       
   274 	
       
   275 	ws.Close();
       
   276 	}
       
   277 
       
   278 
       
   279 
       
   280 /************************************************************* 
       
   281  **  
       
   282  **  CTestDefocusingEdwinStep
       
   283  **  
       
   284  *************************************************************/
       
   285 
       
   286 CTestDefocusingEdwinStep::CTestDefocusingEdwinStep()
       
   287 	{
       
   288 	SetTestStepName(KDefocusingEdwinStep);
       
   289 	}
       
   290 
       
   291 CTestDefocusingEdwinStep::~CTestDefocusingEdwinStep()
       
   292 	{
       
   293 	}
       
   294 
       
   295 /**
       
   296    Call ConstructL() of CEikonEnv and initialize a pointer to CDefocusingEdwinUi.
       
   297    Set the application's user interface object.
       
   298    Call ConstructL() of CDefocusingEdwinUi
       
   299  */
       
   300 void CTestDefocusingEdwinStep::ConstructAppL(CEikonEnv* aCoe)
       
   301     { // runs inside a TRAP harness
       
   302 	aCoe->ConstructL();
       
   303 	CTestAppUi* appUi= new (ELeave) CDefocusingEdwinUi(this);
       
   304     aCoe->SetAppUi(appUi);
       
   305     appUi->ConstructL();
       
   306 	}
       
   307 
       
   308 /**
       
   309    Launches the application using ExecuteD(). \n
       
   310  */
       
   311 TVerdict CTestDefocusingEdwinStep::doTestStepL()
       
   312 	{
       
   313 	PreallocateHALBuffer();
       
   314 
       
   315 	INFO_PRINTF1(_L("TestDefocusingEdwin started..."));
       
   316 
       
   317 	__UHEAP_MARK;
       
   318 
       
   319 	SetTestStepID(_L("UIF-FEPTEST-0001"));
       
   320 
       
   321 	CEikonEnv* coe=new(ELeave) CEikonEnv;
       
   322 	TRAPD(err,ConstructAppL(coe));
       
   323 
       
   324 	if (!err)
       
   325 		coe->ExecuteD();
       
   326 	else
       
   327 		{
       
   328 		delete coe;
       
   329 		SetTestStepResult(EFail);
       
   330 		}
       
   331 
       
   332 	RecordTestResultL();
       
   333 	CloseTMSGraphicsStep();
       
   334 
       
   335 	__UHEAP_MARKEND;
       
   336 
       
   337 	INFO_PRINTF1(_L("...TestDefocusingEdwin finished!"));
       
   338 
       
   339 	return TestStepResult();
       
   340 	}
       
   341