os/graphics/graphicsdeviceinterface/gdi/tgdi/TPALETTE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TPALETTE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,201 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "TTYPES.H"
    1.20 +
    1.21 +#define UNUSED_VAR(a) a = a
    1.22 +
    1.23 +TestPalette::TestPalette(CTTypes* aTest):
    1.24 +	iPalette(NULL), iPalette2(NULL),
    1.25 +	iTest(aTest)
    1.26 +	{}
    1.27 +
    1.28 +TestPalette::~TestPalette()
    1.29 +	{
    1.30 +	}
    1.31 +
    1.32 +/** 
    1.33 +	TestPalette::Test
    1.34 +	
    1.35 +	Method to test the functionality within the CPalette class
    1.36 +	Called from the TTypes test script
    1.37 +*/
    1.38 +void TestPalette::Test()
    1.39 +	{
    1.40 +	_LIT(general,"General");
    1.41 +	iTest->INFO_PRINTF1(general);
    1.42 +	TestGeneral();
    1.43 +	_LIT(defaults,"Defaults");
    1.44 +	iTest->INFO_PRINTF1(defaults);
    1.45 +	//TestDefaults();
    1.46 +	_LIT(getData,"Get Data");
    1.47 +	iTest->INFO_PRINTF1(getData);
    1.48 +	//TestGetPtr();
    1.49 +	}
    1.50 +
    1.51 +/** 
    1.52 +	TestPalette::TestGeneral
    1.53 +	
    1.54 +	Spawn a new CPalette object & test basic calls to retrieve number of entries, add colours, etc
    1.55 +*/
    1.56 +void TestPalette::TestGeneral()
    1.57 +	{
    1.58 +	const TInt numcolors=50;
    1.59 +	TRAPD(ret,iPalette=CPalette::NewL(numcolors));
    1.60 +    UNUSED_VAR(ret);
    1.61 +	iTest->TEST(iPalette->Entries()==numcolors);
    1.62 +	for(TInt colcount=0;colcount<numcolors;colcount++)
    1.63 +		{
    1.64 +		TRgb color(colcount,0,0);
    1.65 +		iPalette->SetEntry(colcount,color);
    1.66 +		iTest->TEST(iPalette->GetEntry(colcount)==color);
    1.67 +		}
    1.68 +	for(TInt checkcount=0;checkcount<numcolors;checkcount++)
    1.69 +		{
    1.70 +		TRgb color(checkcount,0,0);
    1.71 +		iTest->TEST(iPalette->GetEntry(checkcount)==color);
    1.72 +		}
    1.73 +	iPalette->Clear();
    1.74 +	TRgb black(0,0,0);
    1.75 +	for(TInt clearcount=0;clearcount<numcolors;clearcount++)
    1.76 +		iTest->TEST(iPalette->GetEntry(clearcount)==black);
    1.77 +	for(TInt nearcount=0;nearcount<5;nearcount++)
    1.78 +		{
    1.79 +		TRgb color(nearcount*60,0,0);
    1.80 +		iPalette->SetEntry(nearcount,color);
    1.81 +		iTest->TEST(iPalette->GetEntry(nearcount)==color);
    1.82 +		}
    1.83 +	for(TInt approxcount=0;approxcount<5;approxcount++)
    1.84 +		{
    1.85 +		TRgb color(approxcount*60,0,0);
    1.86 +		TRgb approxl(approxcount*59,0,0);
    1.87 +		TRgb approxh(approxcount*61,0,0);
    1.88 +		TRgb nearest=iPalette->NearestEntry(approxl);
    1.89 +		iTest->TEST(nearest==color);
    1.90 +		nearest=iPalette->NearestEntry(approxh);
    1.91 +		iTest->TEST(nearest==color);
    1.92 +		}
    1.93 +	delete iPalette;
    1.94 +	iPalette = NULL;
    1.95 +	}
    1.96 +
    1.97 +/** 
    1.98 +	TestPalette::TestDefaults
    1.99 +	
   1.100 +	Test creation of default colour palettes for supported/un-supported display modes
   1.101 +	Called from the TTypes test script
   1.102 +*/
   1.103 +void TestPalette::TestDefaults()
   1.104 +	{
   1.105 +	TRAPD(ret,iPalette=CPalette::NewDefaultL(ENone));
   1.106 +	iTest->TEST2(ret, KErrNotSupported);
   1.107 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16M));
   1.108 +	iTest->TEST2(ret, KErrNotSupported);
   1.109 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16MU));
   1.110 +	iTest->TEST2(ret, KErrNotSupported);
   1.111 +	TRAP(ret,iPalette=CPalette::NewDefaultL(ERgb));
   1.112 +	iTest->TEST2(ret, KErrNotSupported);
   1.113 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EGray2));
   1.114 +	iTest->TEST(iPalette->GetEntry(0)==TRgb::Gray2(0));
   1.115 +	iTest->TEST(iPalette->GetEntry(1)==TRgb::Gray2(1));
   1.116 +	iTest->TEST(iPalette->Entries()==2);
   1.117 +	delete iPalette;
   1.118 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EGray4));
   1.119 +	for(TInt g4=0;g4<4;g4++)
   1.120 +		iTest->TEST(iPalette->GetEntry(g4)==TRgb::Gray4(g4));
   1.121 +	iTest->TEST(iPalette->Entries()==4);
   1.122 +	delete iPalette;
   1.123 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EGray16));
   1.124 +	for(TInt g16=0;g16<16;g16++)
   1.125 +		iTest->TEST(iPalette->GetEntry(g16)==TRgb::Gray16(g16));
   1.126 +	iTest->TEST(iPalette->Entries()==16);
   1.127 +	delete iPalette;
   1.128 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EGray256));
   1.129 +	for(TInt g256=0;g256<256;g256++)
   1.130 +		iTest->TEST(iPalette->GetEntry(g256)==TRgb::Gray256(g256));
   1.131 +	iTest->TEST(iPalette->Entries()==256);
   1.132 +	delete iPalette;
   1.133 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16));
   1.134 +	for (TInt c16 = 0; c16 < 16; c16++)
   1.135 +		iTest->TEST(iPalette->GetEntry(c16)==TRgb::Color16(c16));
   1.136 +	iTest->TEST(iPalette->Entries()==16);
   1.137 +	delete iPalette;
   1.138 +	TRAP(ret,iPalette=CPalette::NewDefaultL(EColor256));
   1.139 +	for (TInt c256 = 0; c256 < 256; c256++)
   1.140 +		iTest->TEST(iPalette->GetEntry(c256)==TRgb::Color256(c256));
   1.141 +	iTest->TEST(iPalette->Entries()==256);
   1.142 +	delete iPalette;
   1.143 +	iPalette = NULL;
   1.144 +	}
   1.145 +
   1.146 +/** 
   1.147 +	TestPalette::TestGetPtr
   1.148 +	
   1.149 +	Test the GetDataPtr() method in CPalette, to retrieve palette entries for a specified colour
   1.150 +	
   1.151 +	Called from the TTypes test script
   1.152 +*/
   1.153 +void TestPalette::TestGetPtr()
   1.154 +	{
   1.155 +	TRAPD(ret,iPalette2=CTestPalette::NewL());
   1.156 +    UNUSED_VAR(ret);
   1.157 +	iTest->TEST(iPalette2->TestGetPtr());
   1.158 +	TInt colorNum;
   1.159 +	for(colorNum=0;colorNum<CTestPalette::eNumColors;++colorNum)
   1.160 +		{
   1.161 +		TRgb color(colorNum,colorNum,colorNum);
   1.162 +		iPalette2->SetEntry(colorNum,color);
   1.163 +		}
   1.164 +	TPtr8 ptr(NULL,0);
   1.165 +	iPalette2->GetDataPtr(0,CTestPalette::eNumColors,ptr);
   1.166 +	const TUint8 maxValue=CTestPalette::eNumColors-1;
   1.167 +	TInt ii;
   1.168 +	for(ii=0;ii<4*CTestPalette::eNumColors;++ii)
   1.169 +		{
   1.170 +		TUint8 value=ptr[ii];
   1.171 +		if (value!=0 && ((ii + 1) % 4)) //skip alpha channel
   1.172 +			ptr[ii]=STATIC_CAST(TUint8,maxValue-value);
   1.173 +		}	
   1.174 +	for(colorNum=1;colorNum<maxValue;++colorNum)
   1.175 +		iTest->TEST(iPalette2->GetEntry(colorNum)==TRgb::Gray256(maxValue-colorNum));
   1.176 +	delete iPalette2;
   1.177 +	iPalette2 = NULL;
   1.178 +	}
   1.179 +
   1.180 +/** 
   1.181 +	CTestPalette::TestGetPtr
   1.182 +	
   1.183 +	Part of TestPalette::TestGetPtr, retrieves a descriptor from CPalette containing entries for a given colour 
   1.184 +	& checks parameters are legal
   1.185 +	Returns boolean indiciating whether the GetDataPtr was successful or not
   1.186 +*/
   1.187 +TBool CTestPalette::TestGetPtr()
   1.188 +	{
   1.189 +	TPtr8 ptr(NULL,0);
   1.190 +	TUint32* data=REINTERPRET_CAST(TUint32*,iArray);
   1.191 +	TInt start;
   1.192 +	TInt length;
   1.193 +	for(start=0;start<eNumColors;++start)
   1.194 +		{
   1.195 +		for(length=1;length<eNumColors-start;++length)
   1.196 +			{
   1.197 +			TInt len=sizeof(TRgb)*length;
   1.198 +			GetDataPtr(start,length,ptr);
   1.199 +			if (&ptr[0]!=REINTERPRET_CAST(TUint8*,data+start) || ptr.Length()!=len || ptr.MaxLength()!=len)
   1.200 +				return EFalse;
   1.201 +			}
   1.202 +		}
   1.203 +	return ETrue;
   1.204 +	}