windowing/windowserver/twsgraphic/TWsGraphicShareTest.CPP
changeset 110 7f25ef56562d
parent 98 bf7481649c98
child 111 29ddb8a72f0e
equal deleted inserted replaced
98:bf7481649c98 110:7f25ef56562d
     1 // Copyright (c) 1995-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 #include <w32stdgraphic.h>
       
    23 
       
    24 // bitmap to load for comparison
       
    25 #define MY_TEST_BITMAP _L("Z:\\WSTEST\\MYTEST.MBM")
       
    26 
       
    27 const TUint32 ENullWsHandle=0xFFFFFFFF;
       
    28 const TInt KErrTestExeFailure = -666;
       
    29 
       
    30 // class to check if a shared CWsGraphic can be drawn correctly
       
    31 class CWsGraphicShareBase : public CBase
       
    32 	{
       
    33 public:
       
    34 	CWsGraphicShareBase();
       
    35 	~CWsGraphicShareBase();
       
    36 	void ConstructL();
       
    37 	void DoTestDrawGraphicCompareL(TPtrC aShare);
       
    38 private :
       
    39 	void Test(TInt aCondition);
       
    40 	
       
    41 	
       
    42 private :
       
    43 	TInt iScreenNumber;
       
    44 	CWindowGc *iGc;
       
    45 	RWsSession iWs;
       
    46 	RWindowGroup *iGroupWin;
       
    47 	CWsScreenDevice *iScreen;
       
    48 	RWindow *iWin;	
       
    49 	};
       
    50 
       
    51 CWsGraphicShareBase::CWsGraphicShareBase() 
       
    52 	{
       
    53 		iScreenNumber = 0;
       
    54 	}
       
    55 	
       
    56 CWsGraphicShareBase::~CWsGraphicShareBase() 
       
    57 	{
       
    58 		iWin->Close();
       
    59 		delete iWin;
       
    60 		delete iScreen;
       
    61 		delete iGc;
       
    62 		delete iGroupWin;
       
    63 		iWs.Close();
       
    64 	}
       
    65 	
       
    66 void CWsGraphicShareBase::ConstructL()
       
    67 	{
       
    68 	User::LeaveIfError(iWs.Connect());
       
    69 	iScreen=new(ELeave) CWsScreenDevice(iWs);
       
    70 	User::LeaveIfError(iScreen->Construct(iScreenNumber));
       
    71 	iGc=new(ELeave) CWindowGc(iScreen);
       
    72 	User::LeaveIfError(iGc->Construct());
       
    73 	iGroupWin=new(ELeave) RWindowGroup(iWs);
       
    74 	iGroupWin->Construct(1);
       
    75 		
       
    76 	iWin=new(ELeave) RWindow(iWs);
       
    77 	iWin->Construct(*iGroupWin,ENullWsHandle);
       
    78 	iWin->SetRequiredDisplayMode(EColor256);
       
    79 	iWin->SetExtent(TPoint(0,0),iScreen->SizeInPixels());
       
    80 	iWin->Activate();
       
    81 	iWin->BeginRedraw();
       
    82 	iWin->EndRedraw();
       
    83 	iWs.Flush();
       
    84 	}	
       
    85 
       
    86 // Checks that the shared graphic is drawn or not. This is done by creating a new graphic in this process
       
    87 // which looks the same as the shared graphic. The new graphic is then drawn to the screen followed by an 
       
    88 // attempt to draw the shared graphic. The two graphics are then compared. In cases where the shared graphic
       
    89 // should be drawn the two graphics should compare exactly. In cases where the shared graphic should not be 
       
    90 // drawn the comparison will fail.
       
    91    
       
    92 void CWsGraphicShareBase::DoTestDrawGraphicCompareL(TPtrC aShare)
       
    93 	{
       
    94 	// UID of the shared graphic
       
    95 	TUid uid1 = {0x12000021};
       
    96 	TWsGraphicId twsGraphicId1(uid1);
       
    97 
       
    98 	_LIT8(KTestData,"HelloWorld");
       
    99 	
       
   100 	CFbsBitmap bitmap1;
       
   101 	CFbsBitmap mask1;
       
   102 	
       
   103 	TSize screenSize = iScreen->SizeInPixels();
       
   104 	User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
       
   105 	mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
       
   106 	
       
   107 		CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
       
   108 	
       
   109 	// divide the screen into two equal rectangles
       
   110 	TRect position1(0,0,screenSize.iWidth/2,screenSize.iHeight);
       
   111 	TRect position2(screenSize.iWidth/2,0,screenSize.iWidth,screenSize.iHeight);
       
   112 	
       
   113 	// draw the new graphic and attempt to draw the shared graphic
       
   114 	iGc->Activate(*iWin);
       
   115 	iWin->Invalidate();
       
   116 	iWin->BeginRedraw();
       
   117 	iGc->Clear(position1);
       
   118 	iGc->Clear(position2);
       
   119 
       
   120 	iGc->DrawWsGraphic(bTest->Id(),position1,KTestData);
       
   121 	iGc->DrawWsGraphic(twsGraphicId1.Uid(),position2,KTestData);
       
   122 
       
   123 	iGc->Deactivate();	
       
   124 	iWin->EndRedraw();
       
   125 	
       
   126 	iWs.Flush();
       
   127 	iWs.Finish();
       
   128 	// compare the graphic in both positions
       
   129 	if (aShare==_L("false"))
       
   130 		Test(!iScreen->RectCompare(position1,position2));
       
   131 	else
       
   132 		Test(iScreen->RectCompare(position1,position2));	
       
   133 		
       
   134 	delete bTest;
       
   135 	}
       
   136 
       
   137 // Failures are written to WSERV.log
       
   138 void CWsGraphicShareBase::Test(TInt aCondition)
       
   139 	{
       
   140 	if(!aCondition)
       
   141 		{
       
   142 		TLogMessageText buf;
       
   143 		_LIT(Fail,"AUTO Failed in WsGraphics Test : DrawSharedGraphic");
       
   144 		buf.Format(Fail);
       
   145 		iWs.LogMessage(buf);
       
   146 		iWs.Flush();
       
   147 		RProcess().Terminate(KErrTestExeFailure); // terminate this process immediately. Expect TWsGraph test step (TAutoServer.exe) to capture this
       
   148 		}
       
   149 	}
       
   150 	
       
   151 void MainL()
       
   152 	{
       
   153 	// read the argument from the command line of whether the graphic should be shared or not
       
   154 	TBuf<256> commandLine;
       
   155     User::CommandLine(commandLine);
       
   156     TLex lex(commandLine);
       
   157     TPtrC toShare = lex.NextToken();    
       
   158     
       
   159     CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler;
       
   160 	CActiveScheduler::Install(activeScheduler);
       
   161 	CleanupStack::PushL(activeScheduler);
       
   162 
       
   163     CWsGraphicShareBase testBase;
       
   164     testBase.ConstructL();
       
   165        
       
   166     testBase.DoTestDrawGraphicCompareL(toShare);
       
   167     
       
   168 	CleanupStack::PopAndDestroy(activeScheduler);
       
   169 	}
       
   170 
       
   171 GLDEF_C TInt E32Main()
       
   172 	{
       
   173 	CTrapCleanup* cleanUpStack=CTrapCleanup::New();
       
   174 	if(cleanUpStack==NULL)
       
   175 		{
       
   176 		return KErrNoMemory;
       
   177 		}
       
   178 	TRAP_IGNORE(MainL())
       
   179 	delete cleanUpStack;
       
   180 	
       
   181 	return(KErrNone);
       
   182 	}