windowing/windowserver/test/tauto/TDERIVED.CPP
branchRCL_3
changeset 163 bbf46f59e123
equal deleted inserted replaced
150:57c618273d5c 163:bbf46f59e123
       
     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 // Test classes derived from Wserv client side classes
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include "TDERIVED.H"
       
    25 
       
    26 CTDerived::CTDerived(CTestStep* aStep) : CTWsGraphicsBase(aStep)
       
    27 	{
       
    28 	}
       
    29 
       
    30 CTDerived::~CTDerived()
       
    31 	{
       
    32 	}
       
    33 
       
    34 //
       
    35 // CDerivedWindowGc //
       
    36 //
       
    37 
       
    38 CDerivedWindowGc::CDerivedWindowGc(CWsScreenDevice *aDevice) : CWindowGc(aDevice)
       
    39 	{
       
    40 	}
       
    41 
       
    42 CDerivedWindowGc::~CDerivedWindowGc()
       
    43 	{
       
    44 	}
       
    45 
       
    46 void CDerivedWindowGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
       
    47 	{
       
    48 	CWindowGc::DrawLine(aPoint1+TPoint(10,10), aPoint2-TPoint(10,10));
       
    49 	}
       
    50 
       
    51 //
       
    52 // RDerivedSession //
       
    53 //
       
    54 
       
    55 TInt RDerivedSession::ResourceCount()
       
    56 	{
       
    57 	return(RWsSession::ResourceCount()+1);
       
    58 	}
       
    59 
       
    60 void RDerivedSession::EnableAutoFlush()
       
    61 	{
       
    62 	SetAutoFlush(ETrue);
       
    63 	}
       
    64 
       
    65 //
       
    66 // Derived windows //
       
    67 //
       
    68 
       
    69 RDerivedBlankWindow::RDerivedBlankWindow()
       
    70 	{}
       
    71 RDerivedBlankWindow::RDerivedBlankWindow(RWsSession &aWs) : RBlankWindow(aWs)
       
    72 	{
       
    73 	}
       
    74 
       
    75 void RDerivedBlankWindow::SetColor(TRgb aColor)
       
    76 	{
       
    77 	RBlankWindow::SetColor(~aColor);
       
    78 	}
       
    79 
       
    80 void RDerivedBlankWindow::SetColorGray()
       
    81 	{
       
    82 	RBlankWindow::SetColor(TRgb::Gray16(8));
       
    83 	}
       
    84 
       
    85 RDerivedWindow::RDerivedWindow()
       
    86 	{}
       
    87 RDerivedWindow::RDerivedWindow(RWsSession &aWs) : RWindow(aWs)
       
    88 	{
       
    89 	}
       
    90 
       
    91 void RDerivedWindow::SetBackgroundColor(TRgb aColor)
       
    92 	{
       
    93 	RWindow::SetBackgroundColor(~aColor);
       
    94 	}
       
    95 
       
    96 void RDerivedWindow::SetBackgroundColorGray()
       
    97 	{
       
    98 	RWindow::SetBackgroundColor(TRgb::Gray16(8));
       
    99 	}
       
   100 
       
   101 RDerivedBackedUpWindow::RDerivedBackedUpWindow()
       
   102 	{}
       
   103 RDerivedBackedUpWindow::RDerivedBackedUpWindow(RWsSession &aWs) : RBackedUpWindow(aWs)
       
   104 	{
       
   105 	}
       
   106 
       
   107 TInt RDerivedBackedUpWindow::BitmapHandle()
       
   108 	{
       
   109 	MaintainBackup();
       
   110 	return(RBackedUpWindow::BitmapHandle()+1);
       
   111 	};
       
   112 
       
   113 RDerivedWindowGroup::RDerivedWindowGroup()
       
   114 	{}
       
   115 
       
   116 RDerivedWindowGroup::RDerivedWindowGroup(RWsSession &aWs) : RWindowGroup(aWs)
       
   117 	{
       
   118 	}
       
   119 
       
   120 TName RDerivedWindowGroup::Name() const
       
   121 	{
       
   122 	return(_L("Fred"));
       
   123 	}
       
   124 
       
   125 //
       
   126 // CDerivedScreenDevice //
       
   127 //
       
   128 
       
   129 CDerivedScreenDevice::CDerivedScreenDevice()
       
   130 	{}
       
   131 
       
   132 CDerivedScreenDevice::CDerivedScreenDevice(RWsSession &aWs) : CWsScreenDevice(aWs)
       
   133 	{}
       
   134 
       
   135 TSize CDerivedScreenDevice::SizeInPixels() const
       
   136 	{
       
   137 	TSize size=CWsScreenDevice::SizeInPixels();
       
   138 	return(TSize(size.iWidth*2,size.iHeight*2));
       
   139 	}
       
   140 
       
   141 //
       
   142 // Derived Sprite/Pointer cursor //
       
   143 //
       
   144 
       
   145 RDerivedSprite::RDerivedSprite()
       
   146 	{
       
   147 	}
       
   148 
       
   149 RDerivedSprite::RDerivedSprite(RWsSession &aWs) : RWsSprite(aWs)
       
   150 	{
       
   151 	}
       
   152 
       
   153 RDerivedPointerCursor::RDerivedPointerCursor()
       
   154 	{
       
   155 	}
       
   156 
       
   157 RDerivedPointerCursor::RDerivedPointerCursor(RWsSession &aWs) : RWsPointerCursor(aWs)
       
   158 	{
       
   159 	}
       
   160 
       
   161 //
       
   162 
       
   163 void CTDerived::ConstructL()
       
   164 	{
       
   165 	TheGc->Activate(*BaseWin->Win());
       
   166 	TheGc->Clear();
       
   167 	TheGc->SetBrushColor(TRgb::Gray16(12));
       
   168 	TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   169 	TheGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   170 	TheGc->DrawRect(TRect(BaseWin->Win()->Size()));
       
   171 	TheGc->Deactivate();
       
   172 	TheGc->Activate(*TestWin->Win());
       
   173 	TheGc->Clear();
       
   174 	TheGc->SetBrushColor(TRgb::Gray16(4));
       
   175 	TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   176 	TheGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   177 	TheGc->DrawRect(TRect(TestWin->Win()->Size()));
       
   178 	TheGc->Deactivate();
       
   179 	}
       
   180 
       
   181 void CTDerived::DerivedWindowGcL()
       
   182 	{
       
   183 	CDerivedWindowGc *dgc=new(ELeave) CDerivedWindowGc(TheClient->iScreen);
       
   184 	dgc->Construct();
       
   185 	dgc->Activate(*TestWin->Win());
       
   186 	dgc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   187 	TestWin->Win()->BeginRedraw();
       
   188 	dgc->DrawRect(TRect(TestWin->Win()->Size()));
       
   189 	dgc->DrawLine(TPoint(0,0),TestWin->Win()->Size().AsPoint());
       
   190 	TestWin->Win()->EndRedraw();
       
   191 	dgc->Deactivate();
       
   192 	delete dgc;
       
   193 	dgc = NULL;
       
   194 	CWindowGc *wgc=new(ELeave) CWindowGc(TheClient->iScreen);
       
   195 	wgc->Construct();
       
   196 	wgc->Activate(*BaseWin->Win());
       
   197 	wgc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   198 	BaseWin->Win()->BeginRedraw();
       
   199 	wgc->DrawRect(TRect(TestWin->Win()->Size()));
       
   200 	wgc->DrawLine(TPoint(10,10),TestWin->Win()->Size().AsPoint()-TPoint(10,10));
       
   201 	BaseWin->Win()->EndRedraw();
       
   202 	wgc->Deactivate();
       
   203 	delete wgc;
       
   204 	wgc = NULL;
       
   205 	CompareWindows(_L("CTDerived::DerivedWindowGcL()"));
       
   206 	}
       
   207 
       
   208 void CTDerived::DerivedSession()
       
   209 	{
       
   210 	TInt err;
       
   211 	err = iDSession.Connect();
       
   212 	if (err!=KErrNone)
       
   213 		return;
       
   214 	
       
   215 	// use the correct screen
       
   216 	CWsScreenDevice* screen = NULL;
       
   217 	TRAP(err, screen = new (ELeave) CWsScreenDevice(iDSession));
       
   218 	if (err!=KErrNone)
       
   219 		{
       
   220 		iDSession.Close();
       
   221 		return;
       
   222 		}
       
   223 	
       
   224 	if ((err=screen->Construct(iTest->iScreenNumber))!=KErrNone)
       
   225 		{
       
   226 		delete screen;
       
   227 		iDSession.Close();
       
   228 		return;
       
   229 		}
       
   230 
       
   231 	delete screen;
       
   232 	
       
   233 	TInt retVal = iDSession.ResourceCount();	
       
   234 	TEST(retVal==1);
       
   235 	if (retVal!=1)
       
   236 		INFO_PRINTF3(_L("iDSession.ResourceCount() return value - Expected: %d, Actual: %d"), 1, retVal);		
       
   237 	
       
   238 	iDSession.SetAutoFlush(EFalse);
       
   239 	iDSession.EnableAutoFlush();
       
   240 	
       
   241 	TBool retBool = iDSession.SetAutoFlush(EFalse);	
       
   242 	TEST(retBool);
       
   243 	if (!retBool)
       
   244 		INFO_PRINTF3(_L("iDSession.SetAutoFlush(EFalse) return value - Expected: %d, Actual: %d"), ETrue, retBool);		
       
   245 	
       
   246 	iDSession.Close();
       
   247 	}
       
   248 
       
   249 void CTDerived::DerivedWindows()
       
   250 	{
       
   251 //
       
   252 // Window group
       
   253 //
       
   254 	iDGroup=RDerivedWindowGroup(TheClient->iWs);
       
   255 	iDGroup.Construct(222);
       
   256 	iDGroup.Name();
       
   257 //
       
   258 // Redraw up window
       
   259 //
       
   260 	iDRedraw=RDerivedWindow(TheClient->iWs);
       
   261 	iDRedraw.Construct(iDGroup,12);
       
   262 	iDRedraw.SetBackgroundColor(TRgb(1,2,3));
       
   263 	iDRedraw.SetBackgroundColorGray();
       
   264 	iDRedraw.Close();
       
   265 //
       
   266 // Blank up window
       
   267 //
       
   268 	iDBlank=RDerivedBlankWindow(TheClient->iWs);
       
   269 	iDBlank.Construct(iDGroup,123);
       
   270 	iDBlank.SetColor(TRgb(1,20,50));
       
   271 	iDBlank.SetColorGray();
       
   272 	iDBlank.Close();
       
   273 //
       
   274 // Backed up window
       
   275 //
       
   276 	iDBackedUp=RDerivedBackedUpWindow(TheClient->iWs);
       
   277 	iDBackedUp.Construct(iDGroup,EGray4,1234);
       
   278 	iDBackedUp.BitmapHandle();
       
   279 	iDBackedUp.Close();
       
   280 //
       
   281 	iDGroup.Close();
       
   282 	}
       
   283 
       
   284 void CTDerived::DerivedScreenDeviceL()
       
   285 	{
       
   286 	CWsScreenDevice *wsd=new(ELeave) CWsScreenDevice(TheClient->iWs);
       
   287 	User::LeaveIfError(wsd->Construct(iTest->iScreenNumber));
       
   288 	TSize size1(wsd->SizeInPixels());
       
   289 	delete wsd;
       
   290 	CDerivedScreenDevice *dsd=new(ELeave) CDerivedScreenDevice(TheClient->iWs);
       
   291 	User::LeaveIfError(dsd->Construct(iTest->iScreenNumber));
       
   292 	TSize size2(dsd->SizeInPixels());
       
   293 	delete dsd;
       
   294 	TEST(size2.iWidth==size1.iWidth*2 && size2.iHeight==size1.iHeight*2);
       
   295 	}
       
   296 
       
   297 void CTDerived::DerivedSprite()
       
   298 	{
       
   299 	iDSprite=RDerivedSprite(TheClient->iWs);
       
   300 	TSpriteMember spm;
       
   301 	spm.iBitmap=NULL;
       
   302 	spm.iMaskBitmap=NULL;
       
   303 	spm.iInvertMask=EFalse;
       
   304 	spm.iOffset=TPoint(0,0);				// Offset from sprites central position
       
   305 	spm.iInterval=TTimeIntervalMicroSeconds32(1000000);
       
   306 	iDSprite.Construct(*TestWin->Win(), TPoint(10,10), 0);
       
   307 	iDSprite.Close();
       
   308 //
       
   309 	iDPCursor=RDerivedPointerCursor(TheClient->iWs);
       
   310 	iDPCursor.Construct(0);
       
   311 	iDPCursor.Close();
       
   312 	};
       
   313 
       
   314 void CTDerived::RunTestCaseL(TInt /*aCurTestCase*/)
       
   315 	{
       
   316 	((CTDerivedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
   317 	switch(++iTest->iState)
       
   318 		{
       
   319 /**
       
   320 @SYMTestCaseID		GRAPHICS-WSERV-0075
       
   321 
       
   322 @SYMDEF             DEF081259
       
   323 
       
   324 @SYMTestCaseDesc    Test derived window graphics context
       
   325 
       
   326 @SYMTestPriority    High
       
   327 
       
   328 @SYMTestStatus      Implemented
       
   329 
       
   330 @SYMTestActions     Draw using a derived window gc and a normal
       
   331 					window gc and check the dawing is the same
       
   332 
       
   333 @SYMTestExpectedResults Drawing is the same with a derived window gc
       
   334 */
       
   335 		case 1:
       
   336 			((CTDerivedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0075"));
       
   337 			iTest->LogSubTest(_L("Derived Gc"));
       
   338 			DerivedWindowGcL();
       
   339 			break;
       
   340 /**
       
   341 @SYMTestCaseID		GRAPHICS-WSERV-0076
       
   342 
       
   343 @SYMDEF             DEF081259
       
   344 
       
   345 @SYMTestCaseDesc    Test derived window server session
       
   346 
       
   347 @SYMTestPriority    High
       
   348 
       
   349 @SYMTestStatus      Implemented
       
   350 
       
   351 @SYMTestActions     Test that a derived window server session functions
       
   352 					the same as a normal window server session
       
   353 
       
   354 @SYMTestExpectedResults The derived window server session functions correctly
       
   355 */
       
   356 		case 2:
       
   357 			((CTDerivedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0076"));
       
   358 			iTest->LogSubTest(_L("Derived Session"));
       
   359 			DerivedSession();
       
   360 			break;
       
   361 /**
       
   362 @SYMTestCaseID		GRAPHICS-WSERV-0077
       
   363 
       
   364 @SYMDEF             DEF081259
       
   365 
       
   366 @SYMTestCaseDesc    Test derived windows and window groups function correctly
       
   367 
       
   368 @SYMTestPriority    High
       
   369 
       
   370 @SYMTestStatus      Implemented
       
   371 
       
   372 @SYMTestActions     Test that a derived windows and window groups function
       
   373 					the same as the classes they are derived from
       
   374 
       
   375 @SYMTestExpectedResults The derived windows and window group functions correctly
       
   376 */
       
   377 		case 3:
       
   378 			((CTDerivedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0077"));
       
   379 			iTest->LogSubTest(_L("Derived Blank Window"));
       
   380 			DerivedWindows();
       
   381 			break;
       
   382 /**
       
   383 @SYMTestCaseID		GRAPHICS-WSERV-0078
       
   384 
       
   385 @SYMDEF             DEF081259
       
   386 
       
   387 @SYMTestCaseDesc    Test derived screen devices function correctly
       
   388 
       
   389 @SYMTestPriority    High
       
   390 
       
   391 @SYMTestStatus      Implemented
       
   392 
       
   393 @SYMTestActions     Test that a derived screen device function
       
   394 					the same as the class it is derived from
       
   395 
       
   396 @SYMTestExpectedResults The derived screen device functions correctly
       
   397 */
       
   398 		case 4:
       
   399 			((CTDerivedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0078"));
       
   400 			iTest->LogSubTest(_L("Derived Screed Device"));
       
   401 			DerivedScreenDeviceL();
       
   402 			break;
       
   403 /**
       
   404 @SYMTestCaseID		GRAPHICS-WSERV-0079
       
   405 
       
   406 @SYMDEF             DEF081259
       
   407 
       
   408 @SYMTestCaseDesc    Test derived sprites and pointer cursors function
       
   409 					correctly
       
   410 
       
   411 @SYMTestPriority    High
       
   412 
       
   413 @SYMTestStatus      Implemented
       
   414 
       
   415 @SYMTestActions     Test that a derived sprite and pointer cursor
       
   416 					function correctly
       
   417 
       
   418 @SYMTestExpectedResults The derived sprite and pointer cursor function 
       
   419 					correctly
       
   420 */
       
   421 		case 5:
       
   422 			((CTDerivedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0079"));
       
   423 			iTest->LogSubTest(_L("Derived Sprites"));
       
   424 			DerivedSprite();
       
   425 			break;
       
   426 		case 6:
       
   427 			((CTDerivedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
   428 			((CTDerivedStep*)iStep)->CloseTMSGraphicsStep();
       
   429 			TestComplete();	
       
   430 			break;
       
   431 		}
       
   432 	((CTDerivedStep*)iStep)->RecordTestResultL();
       
   433 	}
       
   434 	
       
   435 __WS_CONSTRUCT_STEP__(Derived)