appfw/uiftestfw/src/appfwk_test_AppUi.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-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 
       
    23 #include <techview/eikmenub.h>
       
    24 #include <techview/eikbtgpc.h>
       
    25 #include <eikenv.h>
       
    26 #include <hal.h>
       
    27 
       
    28 #include "appfwk_test_AppUi.h"
       
    29 
       
    30 
       
    31 EXPORT_C void PreallocateHALBuffer()
       
    32 	{
       
    33 	HAL::SEntry* pE=NULL;
       
    34 	TInt entries=0;
       
    35 	HAL::GetAll(entries, pE);
       
    36 	User::Free(pE);
       
    37 	}
       
    38 
       
    39 EXPORT_C void CloseAllPanicWindowsL()
       
    40 	{
       
    41 	RWsSession	ws;
       
    42 	User::LeaveIfError(ws.Connect());
       
    43 
       
    44 	TInt wgFocus = ws.GetFocusWindowGroup();
       
    45 
       
    46 	const TUint32 ENullWsHandle = 0xFFFFFFFF;	// Events delivered to this handle are thrown away
       
    47 	RWindowGroup wg = RWindowGroup(ws);
       
    48 
       
    49 	wg.Construct(ENullWsHandle);
       
    50 	TInt wgId = wg.Identifier();
       
    51 
       
    52 	TWsEvent event;
       
    53 	event.SetType(EEventKey);
       
    54 	TKeyEvent *keyEvent = event.Key();
       
    55 	keyEvent->iCode = EKeyEscape;
       
    56 	keyEvent->iScanCode = EStdKeyEscape;
       
    57 	keyEvent->iModifiers = 0;
       
    58 
       
    59 	TInt limit = 0;
       
    60 	for(limit = 0; wgFocus != wgId && (limit < 50); limit++)
       
    61 	{
       
    62 		ws.SendEventToAllWindowGroups(event);
       
    63 		wgFocus = ws.GetFocusWindowGroup();
       
    64 		RDebug::Print(_L("CloseAllPanicWindowsL() - EKeyEscape sent to Windows Group"));
       
    65 	}
       
    66 
       
    67 	// close everything
       
    68 	wg.Close();
       
    69 	ws.Close();
       
    70 	}
       
    71 
       
    72 
       
    73 EXPORT_C CAutoTestManager::CAutoTestManager(MAutoTestApp* aAutoTestApp) :
       
    74 	CActive(EPriorityIdle), iAutoTestApp(aAutoTestApp)
       
    75 	{
       
    76 	}
       
    77 
       
    78 
       
    79 EXPORT_C CAutoTestManager::~CAutoTestManager()
       
    80 	{
       
    81 	Cancel();
       
    82 	}
       
    83 	
       
    84 
       
    85 EXPORT_C CAutoTestManager* CAutoTestManager::NewL(MAutoTestApp* aAutoTestApp)
       
    86 	{
       
    87      CAutoTestManager *theTestManager=new (ELeave) CAutoTestManager(aAutoTestApp);
       
    88      CActiveScheduler::Add(theTestManager);
       
    89 	 return theTestManager;
       
    90 	}
       
    91 
       
    92 
       
    93 void CAutoTestManager::RunL()
       
    94 	{
       
    95 	__ASSERT_DEBUG(iAutoTestApp, User::Panic(KPanicNullPointer, KNullPointer));
       
    96 	iAutoTestApp->RunTestStepL(++iNumStep);
       
    97 	StartAutoTest();
       
    98 	}
       
    99 	
       
   100 
       
   101 void CAutoTestManager::DoCancel()
       
   102 	{
       
   103 	}
       
   104 
       
   105 
       
   106 /**
       
   107   Init active object and set it active
       
   108  */
       
   109 EXPORT_C void CAutoTestManager::StartAutoTest()
       
   110 	{
       
   111 	TRequestStatus *pS=(&iStatus);
       
   112 	User::RequestComplete(pS,0);
       
   113 	SetActive();
       
   114 	}
       
   115 
       
   116 
       
   117 /**
       
   118   This function must be called after all test cases will be completed 	
       
   119  */
       
   120 EXPORT_C void CAutoTestManager::FinishAllTestCases(TTestResult aResult)
       
   121 	{
       
   122 	iResult = aResult;
       
   123 	if(aResult != EPass)
       
   124 		{
       
   125 		RDebug::Print(_L("\nTest completed with error %d"), aResult);
       
   126 		}
       
   127 	CCoeEnv::Static()->Flush();
       
   128 	CBaActiveScheduler::Exit();
       
   129 	}
       
   130 	
       
   131 	
       
   132 /**
       
   133   This function will set the internal test state variable to the user defined state.
       
   134  */
       
   135 EXPORT_C void CAutoTestManager::SetTestCaseNumber(TInt aNumber)
       
   136 	{
       
   137 	iNumStep = aNumber;
       
   138 	}
       
   139 
       
   140 
       
   141 EXPORT_C CTestCoeAppUi::CTestCoeAppUi(CTmsTestStep* aStep) :
       
   142 		iStep(aStep) 
       
   143 	{
       
   144 	}
       
   145 
       
   146 
       
   147 EXPORT_C CTestCoeAppUi::~CTestCoeAppUi()
       
   148 	{
       
   149 	if(iAutoTestManager)
       
   150 		{
       
   151 		iAutoTestManager->Cancel();
       
   152 		}
       
   153 	delete iAutoTestManager;
       
   154 	}
       
   155 	
       
   156 
       
   157 /**
       
   158   Read thread local storage read and free thread local storage STL is used for storage  Auto attribute,  
       
   159   it sets in an export function void ProcessParam(TAny* aParam)	
       
   160  */
       
   161 EXPORT_C void CTestCoeAppUi::ConstructL()
       
   162 	{
       
   163 	iAutoTestManager = CAutoTestManager::NewL(this);
       
   164 	
       
   165 	CCoeAppUi::ConstructL();
       
   166 	}
       
   167 
       
   168 
       
   169 EXPORT_C CTestAppUi::CTestAppUi(CTmsTestStep* aStep, const	TDesC& aRes, TInt aResourceHotKeysId,  TInt aResourceMenuBarId, TInt aResourceToolBarId) :
       
   170 		CEikAppUi(),
       
   171 		iResourceHotKeysId(aResourceHotKeysId), 
       
   172 		iResourceMenuBarId(aResourceMenuBarId),
       
   173 		iResourceToolBarId(aResourceToolBarId),
       
   174 		iStep(aStep)
       
   175 	{
       
   176 	iRes.Copy(aRes);
       
   177 	}
       
   178 
       
   179 
       
   180 EXPORT_C CTestAppUi::~CTestAppUi()
       
   181 	{
       
   182 	if(iResourceFileFlag)
       
   183 		{
       
   184 		CCoeEnv::Static()->DeleteResourceFile(iResourceFileFlag); 
       
   185 		}
       
   186 	
       
   187 	if(iAutoTestManager)
       
   188 		{
       
   189 		iAutoTestManager->Cancel();
       
   190 		}
       
   191 	delete iAutoTestManager;
       
   192 	
       
   193 	if(iMenuBar)
       
   194 		{
       
   195 		RemoveFromStack(iMenuBar);
       
   196 		}
       
   197 	delete iMenuBar;
       
   198 	
       
   199 	if(iToolBar)
       
   200 		{
       
   201 		RemoveFromStack(iToolBar);
       
   202 		}
       
   203 	delete iToolBar;
       
   204 	}
       
   205 
       
   206 
       
   207 /**
       
   208    Load resource, create toolbar & menubar, read and free thread local storage	
       
   209  */
       
   210 EXPORT_C void CTestAppUi::ConstructL()
       
   211 	{
       
   212 	iAutoTestManager = CAutoTestManager::NewL(this);
       
   213 	
       
   214 	if(iStep == 0)
       
   215 		{
       
   216 		BaseConstructL(ENoAppResourceFile);
       
   217 		}
       
   218 	else
       
   219 		{
       
   220 		CCoeAppUi::ConstructL();
       
   221 		}
       
   222 
       
   223 	if(iRes.Length() > 0)
       
   224 		{
       
   225 		CCoeEnv* coeEnv = CCoeEnv::Static();
       
   226 		TBuf8<256>	buf;
       
   227 		buf.Copy(iRes);
       
   228 		iResourceFileFlag=coeEnv->AddResourceFileL(iRes);
       
   229 		}
       
   230 
       
   231 	if(iResourceMenuBarId)
       
   232 		{
       
   233 		iMenuBar = new (ELeave) CEikMenuBar;
       
   234 		iMenuBar->ConstructL(this,iResourceHotKeysId,iResourceMenuBarId);
       
   235 		iMenuBar->MakeVisible(ETrue);
       
   236 		AddToStackL(iMenuBar);
       
   237 		}
       
   238 
       
   239 	if(iResourceToolBarId)
       
   240 		{
       
   241 		iToolBar=CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::EToolbar, CEikButtonGroupContainer::EVertical, this, iResourceToolBarId);
       
   242 		const TRect boundingRect = ClientRect(); // make toolband stretch to the screen width by default
       
   243 		iToolBar->SetBoundingRect(boundingRect);
       
   244 		iToolBar->MakeVisible(ETrue);
       
   245 		AddToStackL(iToolBar);
       
   246 		}
       
   247 	}
       
   248 
       
   249 
       
   250 /**
       
   251    Reduce client rectangle	
       
   252  */
       
   253 EXPORT_C void CTestAppUi::ReduceRect(TRect& aRect) const
       
   254 	{
       
   255 	if(iMenuBar)
       
   256 		{
       
   257 		iMenuBar->ReduceRect(aRect);
       
   258 		}
       
   259 
       
   260 	if(iToolBar)
       
   261 		{
       
   262 		iToolBar->ReduceRect(aRect);
       
   263 		}
       
   264 	}
       
   265 
       
   266 
       
   267 /**
       
   268   Hide menu from screen and pass on to the parent method
       
   269  */
       
   270 EXPORT_C void CTestAppUi::ProcessCommandL(TInt aCommand)
       
   271 	{
       
   272  	if (iMenuBar && iMenuBar->IsVisible())
       
   273 		{
       
   274 		iMenuBar->StopDisplayingMenuBar();
       
   275 		}
       
   276 	if(aCommand != EEikCmdCanceled)
       
   277 		{
       
   278 		CEikAppUi::ProcessCommandL(aCommand);
       
   279 		}
       
   280 	}
       
   281 
       
   282 
       
   283 TInt  E32Dll()
       
   284 	{
       
   285 	return 0;
       
   286 	}
       
   287 
       
   288