windowing/windowserver/tauto/TMDISPLAY.CPP
changeset 116 171fae344dd4
parent 103 2717213c588a
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 1996-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 // Multiple display test
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 
       
    25 
       
    26 #include "TMDISPLAY.H"
       
    27 #include <hal.h>
       
    28 //
       
    29 //
       
    30 CTClient* CreateClientL()
       
    31 	{
       
    32 	return (TheClient=new(ELeave) TestClient());
       
    33 	}
       
    34 	
       
    35 TInt ProcMultiDisplay(TAny* aScreenNo)
       
    36 	{
       
    37 	return TestLibStartUp(CreateClientL,(TInt)aScreenNo);
       
    38 	}
       
    39 
       
    40 
       
    41 //
       
    42 //
       
    43 
       
    44 CTMultiDisplay::CTMultiDisplay(CTestStep* aStep) : CTWsGraphicsBase(aStep)
       
    45 	{
       
    46 	INFO_PRINTF1(_L("Testing Mutli display functions"));
       
    47 	}
       
    48 
       
    49 void CTMultiDisplay::ConstructL()
       
    50 	{
       
    51 	}
       
    52 	
       
    53 CTMultiDisplay::~CTMultiDisplay()
       
    54 	{
       
    55 	}
       
    56 
       
    57 TInt DoSetFocusScreenL(TInt aFocusScreen,TAny* /*aArg*/)
       
    58 	{
       
    59 	RWsSession ws;
       
    60 	User::LeaveIfError(ws.Connect());
       
    61 	ws.SetFocusScreen(aFocusScreen);
       
    62 	ws.Close();
       
    63 	return EWsExitReasonBad;
       
    64 	}
       
    65 
       
    66 /**
       
    67 @SYMTestCaseID		GRAPHICS-WSERV-0051
       
    68 
       
    69 @SYMDEF             DEF081259
       
    70 
       
    71 @SYMTestCaseDesc    Test focusing on the two different screens
       
    72 					available
       
    73 
       
    74 @SYMTestPriority    High
       
    75 
       
    76 @SYMTestStatus      Implemented
       
    77 
       
    78 @SYMTestActions     Test the response to different calls to focus
       
    79 					on the two screens available
       
    80 
       
    81 @SYMTestExpectedResults Foucisng on the different screens is correct
       
    82 */	
       
    83 void CTMultiDisplay::DoFocusScreenTestL()
       
    84 	{
       
    85 	_LIT(KSubTitle,"FocusScreen API");
       
    86 	INFO_PRINTF1(KSubTitle);
       
    87 	
       
    88 	TInt numberOfScreens;
       
    89 	HAL::Get(HALData::EDisplayNumberOfScreens, numberOfScreens);
       
    90 	TInt oldFocus=TheClient->iWs.GetFocusScreen();
       
    91 		
       
    92 	// test case #1: out of bounds screen number
       
    93 	// expected result: client panic and focus stays on current screen
       
    94 	TEST(iTest->TestWsPanicL(&DoSetFocusScreenL,EWservPanicScreenNumber,-1,NULL));
       
    95 	TEST(TheClient->iWs.GetFocusScreen()==oldFocus);
       
    96 	if (TheClient->iWs.GetFocusScreen()!=oldFocus)
       
    97 		INFO_PRINTF3(_L("TheClient->iWs.GetFocusScreen() return value - Expected: %d, Actual: %d"), oldFocus, TheClient->iWs.GetFocusScreen());		
       
    98 
       
    99 	TEST(iTest->TestWsPanicL(&DoSetFocusScreenL,EWservPanicScreenNumber,numberOfScreens,NULL));
       
   100 	TEST(TheClient->iWs.GetFocusScreen()==oldFocus);
       
   101 	if (TheClient->iWs.GetFocusScreen()!=oldFocus)
       
   102 		INFO_PRINTF3(_L("TheClient->iWs.GetFocusScreen() return value - Expected: %d, Actual: %d"), oldFocus, TheClient->iWs.GetFocusScreen());		
       
   103 
       
   104 	
       
   105 	// test case #2: new focus equals to current focus
       
   106 	// expected result: KErrNone and focus stays on current screen
       
   107 	TInt ret = TheClient->iWs.SetFocusScreen(oldFocus);
       
   108 	TEST(ret==KErrNone && TheClient->iWs.GetFocusScreen()==oldFocus);
       
   109 	if (ret!=KErrNone || TheClient->iWs.GetFocusScreen()!=oldFocus)
       
   110 		INFO_PRINTF5(_L("TheClient->iWs.SetFocusScreen(oldFocus)==KErrNone && TheClient->iWs.GetFocusScreen()==oldFocus - Expected: %d and %d, Actual: %d and %d"),KErrNone,  oldFocus, ret, TheClient->iWs.GetFocusScreen());		
       
   111 
       
   112 	
       
   113 	// test case #3: set focus to screen N where screen N is empty (doesn't have any windows)
       
   114 	// expected result: KErrNotFound and focus stays on current screen
       
   115 	TInt i;
       
   116 	for(i=1;i<numberOfScreens;++i)
       
   117 		{
       
   118 		ret = TheClient->iWs.SetFocusScreen(i);
       
   119 		TEST(ret==KErrNotReady && TheClient->iWs.GetFocusScreen()==oldFocus);
       
   120 		if (ret!=KErrNotReady || TheClient->iWs.GetFocusScreen()!=oldFocus)
       
   121 			INFO_PRINTF5(_L("TheClient->iWs.SetFocusScreen(i)==KErrNotReady && TheClient->iWs.GetFocusScreen()==oldFocus - Expected: %d and %d, Actual: %d and %d"),KErrNotReady,  oldFocus, ret, TheClient->iWs.GetFocusScreen());
       
   122 		}
       
   123 				
       
   124 	// test case #4: set focus to screen N where screen N has focus-able window
       
   125 	// expected result: KErrNone and focus is set to screen N
       
   126 	CArrayPtrFlat<CMinWin>* wins;
       
   127 	wins=new(ELeave) CArrayPtrFlat<CMinWin>(numberOfScreens);
       
   128 	CleanupStack::PushL(wins);
       
   129 	for(i=0;i<numberOfScreens;++i)
       
   130 		{
       
   131 		CMinWin* win=new(ELeave) CMinWin(i);
       
   132 		CleanupStack::PushL(win);
       
   133 		win->ConstructL();
       
   134 		wins->AppendL(win);
       
   135 		}
       
   136 		
       
   137 	for(i=1;i<numberOfScreens;++i)
       
   138 		{
       
   139 		ret = TheClient->iWs.SetFocusScreen(i);
       
   140 		TEST(ret==KErrNone && TheClient->iWs.GetFocusScreen()==i);
       
   141 		if (ret!=KErrNone || TheClient->iWs.GetFocusScreen()!=i)
       
   142 			INFO_PRINTF5(_L("TheClient->iWs.SetFocusScreen(i)==KErrNone && TheClient->iWs.GetFocusScreen()==i - Expected: %d and %d, Actual: %d and %d"),KErrNone,  i, ret, TheClient->iWs.GetFocusScreen());
       
   143 
       
   144 		}		
       
   145 	
       
   146 	// test case #5: set focus back from screen N to main screen (screen 0)
       
   147 	// expected result: KErrNone and focus is set to screen 0
       
   148 	ret = TheClient->iWs.SetFocusScreen(0);
       
   149 	TEST(ret==KErrNone && TheClient->iWs.GetFocusScreen()==0);
       
   150 	if (ret!=KErrNone || TheClient->iWs.GetFocusScreen()!=0)
       
   151 		INFO_PRINTF5(_L("TheClient->iWs.SetFocusScreen(0)==KErrNone && TheClient->iWs.GetFocusScreen()==0 - Expected: %d and %d, Actual: %d and %d"),KErrNone,  0, ret, TheClient->iWs.GetFocusScreen());
       
   152 	
       
   153 	CleanupStack::PopAndDestroy(numberOfScreens+1,wins);
       
   154 	}
       
   155 
       
   156 /**
       
   157 @SYMTestCaseID		GRAPHICS-WSERV-0052
       
   158 
       
   159 @SYMDEF             DEF081259
       
   160 
       
   161 @SYMTestCaseDesc    Launch a test from a new process and check
       
   162 					that it passes indepenedent of screen focus
       
   163 
       
   164 @SYMTestPriority    High
       
   165 
       
   166 @SYMTestStatus      Implemented
       
   167 
       
   168 @SYMTestActions     Focus on a screen, launch a test process,
       
   169 					switch to focus on the other screen, then
       
   170 					then check the test process passed
       
   171 
       
   172 @SYMTestExpectedResults The test in the process passed
       
   173 */		
       
   174 void CTMultiDisplay::DoScreenTestL(TInt aScreenNo)
       
   175 	{
       
   176 	_LIT(KSubTest,"Screen %d");
       
   177 	TBuf<16> subMsg;
       
   178 
       
   179 	const TInt numScreens=TheClient->iWs.NumberOfScreens();
       
   180 	if (numScreens<=aScreenNo)
       
   181 		{
       
   182 		_LIT(KLog,"WARNING!! Cannot run test for screen %d as the device only has %d screens.");
       
   183 		LOG_MESSAGE3(KLog,aScreenNo,numScreens);
       
   184 		aScreenNo=numScreens-1;
       
   185 		}
       
   186 
       
   187 	subMsg.AppendFormat(KSubTest,aScreenNo);
       
   188 	LOG_MESSAGE(subMsg);
       
   189 
       
   190 	// Must switch focus screen to relevant screen manually 
       
   191 	CMinWin* win=new(ELeave) CMinWin(aScreenNo);
       
   192 	CleanupStack::PushL(win);
       
   193 	win->ConstructL();
       
   194 	TheClient->iWs.SetFocusScreen(aScreenNo);
       
   195 
       
   196 	CleanupStack::PopAndDestroy(win);
       
   197 	TheClient->iWs.SetFocusScreen(0);
       
   198 	CTestBase::iScreenNo=aScreenNo;
       
   199 
       
   200 	//Set CTestBase::iNumberOfGrpWndsOnPrimaryScreenWithZeroPriority with the number of window groups
       
   201 	//in default screen with priority zero. This will be used in TGwHandle test case.
       
   202 	CTestBase::iNumberOfGrpWndsOnPrimaryScreenWithZeroPriority = TheClient->iWs.NumWindowGroups(0) - 1;
       
   203 	}
       
   204 
       
   205 void CTMultiDisplay::RunTestCaseL(TInt /*aCurTestCase*/)
       
   206 	{
       
   207 	_LIT(KTest1,"Focus Screen");
       
   208 	_LIT(KTest2,"Screen");
       
   209 	((CTMultiDisplayStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
   210 
       
   211 	switch (++iTest->iState)
       
   212 		{
       
   213 		case 1:
       
   214 			((CTMultiDisplayStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0051"));
       
   215 			iTest->LogSubTest(KTest1);
       
   216 			DoFocusScreenTestL();
       
   217 			break;
       
   218 		case 2:
       
   219 			((CTMultiDisplayStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0052"));
       
   220 			iTest->LogSubTest(KTest2);
       
   221 			DoScreenTestL(1);
       
   222 			break;
       
   223 		default:
       
   224 			((CTMultiDisplayStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
   225 			((CTMultiDisplayStep*)iStep)->CloseTMSGraphicsStep();
       
   226 			TestComplete();
       
   227 			break;	
       
   228 		}
       
   229 	((CTMultiDisplayStep*)iStep)->RecordTestResultL();
       
   230 	}
       
   231 
       
   232 __WS_CONSTRUCT_STEP__(MultiDisplay)