commonuisupport/uikon/test/tparent/T_ParentStep.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 // Tests border drawing using border colour & style.\n
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent - Internal Symbian test code
       
    21 */
       
    22 #include <e32keys.h>
       
    23 #include <basched.h>
       
    24 #include <gdi.h>
       
    25 #include <gulutil.h>
       
    26 #include <gulbordr.h>
       
    27 #include <coecntrl.h>
       
    28 #include <coeutils.h>
       
    29 #include <eikenv.h>
       
    30 #include <eikappui.h>
       
    31 #include <eikdef.h>
       
    32 #include <eikdoc.h>
       
    33 #include <eikapp.h>
       
    34 #include <ecom/ecom.h>
       
    35 
       
    36 
       
    37 #include "T_ParentStep.h"
       
    38 #include "appfwk_test_utils.h"
       
    39 
       
    40 //! Total Size of the Window in which controls are spaced.\n
       
    41 #define KViewRect TRect(TPoint(0,0), TPoint(400,200))
       
    42 
       
    43 /**
       
    44    Destructor
       
    45  */
       
    46 CSimpleParentControl::~CSimpleParentControl()
       
    47 	{
       
    48 	}
       
    49 
       
    50 /**
       
    51   Static function used for CSimpleParentControl class instantiation.\n
       
    52   The function instantiates an CSimpleParentControl object.\n
       
    53   Invokes second phase constructor of CSimpleParentControl class passing pointers to
       
    54   Layout manager, container object as arguments.\n
       
    55 */
       
    56 CSimpleParentControl* CSimpleParentControl::NewL(CCoeControl& aContainer, const TRect& /*aRect*/)
       
    57 	{
       
    58 	CSimpleParentControl* self = new(ELeave) CSimpleParentControl();
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL(aContainer);
       
    61 	CleanupStack::Pop();
       
    62 	return self;
       
    63 	}
       
    64 	
       
    65 /**
       
    66    Auxiliary function for all Test Cases
       
    67   
       
    68    This method creates the user interface control on which tests are carried
       
    69    out.
       
    70    
       
    71  */
       
    72 void CSimpleParentControl::ConstructL(CCoeControl& aContainer)
       
    73     {
       
    74     CreateWindowL();
       
    75     SetExtentToWholeScreen();
       
    76     SetContainerWindowL(aContainer);
       
    77     ActivateL();
       
    78 	}
       
    79 
       
    80 
       
    81 /**
       
    82    Auxilliary function for all Test Cases
       
    83   
       
    84    This method is an override from CCoeControl. It is used to handle key
       
    85    events for the control.
       
    86   
       
    87  */
       
    88 TKeyResponse CSimpleParentControl::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode aType)
       
    89     {
       
    90     if (aType!=EEventKey)
       
    91         return(EKeyWasNotConsumed);
       
    92         
       
    93     return(EKeyWasConsumed);
       
    94     }
       
    95 
       
    96 /**
       
    97    Auxiliary function for all Test Cases
       
    98   
       
    99    This method prepares the test step's user interface and prepares it
       
   100    to start the tests. As part of user interface it creates a control
       
   101    on which the tests are carried out.
       
   102    
       
   103  */
       
   104 void CSimpleParentAppUi::ConstructL()
       
   105     {
       
   106 	CTestCoeAppUi::ConstructL();
       
   107 
       
   108     iParentAppView = CParentTestAppView::NewL(KViewRect);
       
   109 	AutoTestManager().StartAutoTest();
       
   110    }
       
   111 
       
   112 CSimpleParentAppUi::~CSimpleParentAppUi()
       
   113 /**
       
   114    Destructor
       
   115  */
       
   116 	{
       
   117   	delete iParentAppView;
       
   118 	}
       
   119 
       
   120 /**
       
   121    Auxiliary function for all Test Cases
       
   122   
       
   123    The method is an override from CTestAppUi. The method initiates border
       
   124    drawing tests.
       
   125    
       
   126  */
       
   127 void CSimpleParentAppUi::RunTestStepL(TInt aNextStep)
       
   128 	{
       
   129 	switch(aNextStep)
       
   130 		{
       
   131 		case 1:	
       
   132 			{
       
   133 			INFO_PRINTF1(_L("Test Parent - does the control have the view as its parent?"));
       
   134 			
       
   135 			// Get the control on the appview
       
   136 			CCoeControl *control = iParentAppView->GetControl();
       
   137 			
       
   138 			if (control == NULL)
       
   139 				{
       
   140 				TEST(control != NULL); // generates a fail automatically
       
   141 				INFO_PRINTF1(_L("Could not get control from appview - test failed"));
       
   142 				break;
       
   143 				}
       
   144 				
       
   145 			// Get the parent of that control
       
   146 			CCoeControl *parent = control->Parent();
       
   147 			
       
   148 			// Check that there is a parent to begin with
       
   149 			if (parent==NULL)
       
   150 				{
       
   151 				TEST(parent != NULL); // generates a fail automatically
       
   152 				INFO_PRINTF1(_L("Control does not have a parent - test failed"));
       
   153 				break;
       
   154 				}
       
   155 				
       
   156 			// Check that the parent is the same as the view
       
   157 			TEST(parent == iParentAppView);
       
   158 				
       
   159 			if (parent != iParentAppView)
       
   160 				{
       
   161 				INFO_PRINTF1(_L("View is not parent of Control - test failed"));
       
   162 				}
       
   163 				else
       
   164 				{
       
   165 				INFO_PRINTF1(_L("View is parent of Control - test PASSED"));
       
   166 				}
       
   167 				
       
   168 			}
       
   169 			break;
       
   170 			
       
   171 		case 2:
       
   172 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
   173 			break;
       
   174 		default:
       
   175 			break;
       
   176 		}
       
   177 	}
       
   178 
       
   179 //----------
       
   180 
       
   181 CTestParentStep::CTestParentStep()
       
   182 /**
       
   183    Constructor
       
   184  */
       
   185 	{
       
   186 	SetTestStepName(KTestParentStep);
       
   187 	}
       
   188 	
       
   189 	
       
   190 
       
   191 CTestParentStep::~CTestParentStep()
       
   192 /**
       
   193    Destructor
       
   194  */
       
   195 	{
       
   196 	}
       
   197 
       
   198 /**
       
   199    Auxiliary function for all Test Cases
       
   200   
       
   201    The method creates & sets the application's user interface object.
       
   202    
       
   203  */
       
   204 void CTestParentStep::ConstructAppL(CEikonEnv* aCoe)
       
   205     { // runs inside a TRAP harness
       
   206 	aCoe->ConstructL();
       
   207 
       
   208 	CSimpleParentAppUi* appUi= new (ELeave) CSimpleParentAppUi(this);
       
   209     aCoe->SetAppUi(appUi);
       
   210     appUi->ConstructL();
       
   211     }
       
   212 
       
   213 /**
       
   214    Auxiliary function for all Test Cases
       
   215   
       
   216    The method creates & sets the test step's user interface object and
       
   217    launches the test step.
       
   218    
       
   219    @SYMTestCaseID UIF-TPARENT-doTestStepL
       
   220   
       
   221    @SYMDEF
       
   222   
       
   223    @SYMTestCaseDesc This test aims to test that the parent of a control created
       
   224                     in a container has the view as its parent.
       
   225   
       
   226    @SYMTestPriority High
       
   227   
       
   228    @SYMTestStatus Implemented
       
   229    
       
   230    @SYMTestActions The view creates a control, and sets the container window
       
   231                    for the control to be itself 
       
   232   
       
   233    @SYMTestExpectedResults The control is queried to confirm that its parent
       
   234                            is the view.
       
   235    
       
   236  
       
   237  */
       
   238 TVerdict CTestParentStep::doTestStepL() // main function called by E32
       
   239 	{
       
   240   	PreallocateHALBuffer();
       
   241 	__UHEAP_MARK;
       
   242 	SetTestStepID(_L("UIF-TPARENT-doTestStepL"));
       
   243 	// Before creating the CEikonEnv we must create C:\parent.txt.
       
   244 	// The presence of this file will modify the behaviour of 
       
   245 	// staticsettingsinit
       
   246 	RSmlTestUtils utils;
       
   247 	User::LeaveIfError(utils.Connect());
       
   248 	CleanupClosePushL(utils);
       
   249 	_LIT(KFile, "c:\\parent.txt");
       
   250 	utils.CreateFileL(KFile);
       
   251 	    
       
   252 	CEikonEnv* coe=new CEikonEnv;
       
   253 	TRAPD(err,ConstructAppL(coe));
       
   254 
       
   255 	if (!err)
       
   256 		coe->ExecuteD();
       
   257 	
       
   258 	utils.DeleteFileL(KFile);
       
   259 	CleanupStack::PopAndDestroy(&utils);
       
   260 
       
   261 	REComSession::FinalClose();
       
   262 	
       
   263 	RecordTestResultL();
       
   264 	CloseTMSGraphicsStep();
       
   265 	__UHEAP_MARKEND;
       
   266 	
       
   267 
       
   268 	return TestStepResult();
       
   269 	}
       
   270 
       
   271 //
       
   272 //
       
   273 // CParentTestAppView
       
   274 //
       
   275 //
       
   276 /**
       
   277   Constructor for CParentTestAppView Class.\n
       
   278 */
       
   279 CParentTestAppView::CParentTestAppView()
       
   280 	{
       
   281 	}
       
   282 /**
       
   283   Static entry function for CParentTestAppView class.\n
       
   284   Instantiates the CParentTestAppView object.\n
       
   285   Invokes the second phase constructor passing Layout manager as argument.\n
       
   286 */
       
   287 CParentTestAppView* CParentTestAppView::NewL( const TRect& aRect)
       
   288 	{
       
   289 	CParentTestAppView* self = new(ELeave) CParentTestAppView();
       
   290 	CleanupStack::PushL(self);
       
   291 	self->ConstructL(aRect);
       
   292 	CleanupStack::Pop();
       
   293 	return self;
       
   294 	}
       
   295 /**
       
   296   Destructor for CParentTestAppView class.\n
       
   297   Destroys the Control array.\n
       
   298 */
       
   299 CParentTestAppView::~CParentTestAppView()
       
   300 	{
       
   301 	delete iSimpleParentControl;
       
   302 	}
       
   303 /**
       
   304   Second phase constructor for CParentTestAppView class.\n
       
   305   Creates a control's window. The created window is the child of the application's window group.\n
       
   306   Sets the view's extent i.e dimensions.\n
       
   307   Instantiates a component control of CSimpleParentControl class.\n
       
   308   The AppView object is added as the container control for the component control.\n
       
   309 */
       
   310 void CParentTestAppView::ConstructL(const TRect& aRect)
       
   311     {
       
   312 	CreateWindowL();
       
   313 	SetRect(aRect);
       
   314 	TRect ctrlRect(10, 10, 20, 20);
       
   315 	
       
   316 	iSimpleParentControl = CSimpleParentControl::NewL(*this, ctrlRect);
       
   317 	iSimpleParentControl->SetContainerWindowL(*this);
       
   318 		
       
   319 	}
       
   320 /**
       
   321    Gets the component control's at the index (aIndex) in the Control array.\n
       
   322 */	
       
   323 CCoeControl* CParentTestAppView::ComponentControl(TInt /*aIndex*/) const
       
   324 	{
       
   325 	return iSimpleParentControl;
       
   326 	}
       
   327 /**
       
   328   Gets the number of component controls contained by the App View .\n
       
   329 */	
       
   330 TInt CParentTestAppView::CountComponentControls() const
       
   331 	{
       
   332 	return 1;
       
   333 	}
       
   334 
       
   335 /**
       
   336   Function to Draw the App View .\n
       
   337   Gets a pointer to the Windows Graphic context.
       
   338   Sets the pen colour,pen style and brush style settings.\n
       
   339   Draws the control using DrawRect function of the Graphics context.\n
       
   340 */
       
   341 void CParentTestAppView::Draw(const TRect& /*aRect*/) const
       
   342 	{
       
   343 	CWindowGc& gc = SystemGc();
       
   344 	gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   345  	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   346 	gc.DrawRect(Rect());
       
   347 	}
       
   348 
       
   349 
       
   350 
       
   351 
       
   352 
       
   353