sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "TTYPES.H" sl@0: sl@0: #define UNUSED_VAR(a) a = a sl@0: sl@0: TestPalette::TestPalette(CTTypes* aTest): sl@0: iPalette(NULL), iPalette2(NULL), sl@0: iTest(aTest) sl@0: {} sl@0: sl@0: TestPalette::~TestPalette() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: TestPalette::Test sl@0: sl@0: Method to test the functionality within the CPalette class sl@0: Called from the TTypes test script sl@0: */ sl@0: void TestPalette::Test() sl@0: { sl@0: _LIT(general,"General"); sl@0: iTest->INFO_PRINTF1(general); sl@0: TestGeneral(); sl@0: _LIT(defaults,"Defaults"); sl@0: iTest->INFO_PRINTF1(defaults); sl@0: //TestDefaults(); sl@0: _LIT(getData,"Get Data"); sl@0: iTest->INFO_PRINTF1(getData); sl@0: //TestGetPtr(); sl@0: } sl@0: sl@0: /** sl@0: TestPalette::TestGeneral sl@0: sl@0: Spawn a new CPalette object & test basic calls to retrieve number of entries, add colours, etc sl@0: */ sl@0: void TestPalette::TestGeneral() sl@0: { sl@0: const TInt numcolors=50; sl@0: TRAPD(ret,iPalette=CPalette::NewL(numcolors)); sl@0: UNUSED_VAR(ret); sl@0: iTest->TEST(iPalette->Entries()==numcolors); sl@0: for(TInt colcount=0;colcountSetEntry(colcount,color); sl@0: iTest->TEST(iPalette->GetEntry(colcount)==color); sl@0: } sl@0: for(TInt checkcount=0;checkcountTEST(iPalette->GetEntry(checkcount)==color); sl@0: } sl@0: iPalette->Clear(); sl@0: TRgb black(0,0,0); sl@0: for(TInt clearcount=0;clearcountTEST(iPalette->GetEntry(clearcount)==black); sl@0: for(TInt nearcount=0;nearcount<5;nearcount++) sl@0: { sl@0: TRgb color(nearcount*60,0,0); sl@0: iPalette->SetEntry(nearcount,color); sl@0: iTest->TEST(iPalette->GetEntry(nearcount)==color); sl@0: } sl@0: for(TInt approxcount=0;approxcount<5;approxcount++) sl@0: { sl@0: TRgb color(approxcount*60,0,0); sl@0: TRgb approxl(approxcount*59,0,0); sl@0: TRgb approxh(approxcount*61,0,0); sl@0: TRgb nearest=iPalette->NearestEntry(approxl); sl@0: iTest->TEST(nearest==color); sl@0: nearest=iPalette->NearestEntry(approxh); sl@0: iTest->TEST(nearest==color); sl@0: } sl@0: delete iPalette; sl@0: iPalette = NULL; sl@0: } sl@0: sl@0: /** sl@0: TestPalette::TestDefaults sl@0: sl@0: Test creation of default colour palettes for supported/un-supported display modes sl@0: Called from the TTypes test script sl@0: */ sl@0: void TestPalette::TestDefaults() sl@0: { sl@0: TRAPD(ret,iPalette=CPalette::NewDefaultL(ENone)); sl@0: iTest->TEST2(ret, KErrNotSupported); sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16M)); sl@0: iTest->TEST2(ret, KErrNotSupported); sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16MU)); sl@0: iTest->TEST2(ret, KErrNotSupported); sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(ERgb)); sl@0: iTest->TEST2(ret, KErrNotSupported); sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EGray2)); sl@0: iTest->TEST(iPalette->GetEntry(0)==TRgb::Gray2(0)); sl@0: iTest->TEST(iPalette->GetEntry(1)==TRgb::Gray2(1)); sl@0: iTest->TEST(iPalette->Entries()==2); sl@0: delete iPalette; sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EGray4)); sl@0: for(TInt g4=0;g4<4;g4++) sl@0: iTest->TEST(iPalette->GetEntry(g4)==TRgb::Gray4(g4)); sl@0: iTest->TEST(iPalette->Entries()==4); sl@0: delete iPalette; sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EGray16)); sl@0: for(TInt g16=0;g16<16;g16++) sl@0: iTest->TEST(iPalette->GetEntry(g16)==TRgb::Gray16(g16)); sl@0: iTest->TEST(iPalette->Entries()==16); sl@0: delete iPalette; sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EGray256)); sl@0: for(TInt g256=0;g256<256;g256++) sl@0: iTest->TEST(iPalette->GetEntry(g256)==TRgb::Gray256(g256)); sl@0: iTest->TEST(iPalette->Entries()==256); sl@0: delete iPalette; sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16)); sl@0: for (TInt c16 = 0; c16 < 16; c16++) sl@0: iTest->TEST(iPalette->GetEntry(c16)==TRgb::Color16(c16)); sl@0: iTest->TEST(iPalette->Entries()==16); sl@0: delete iPalette; sl@0: TRAP(ret,iPalette=CPalette::NewDefaultL(EColor256)); sl@0: for (TInt c256 = 0; c256 < 256; c256++) sl@0: iTest->TEST(iPalette->GetEntry(c256)==TRgb::Color256(c256)); sl@0: iTest->TEST(iPalette->Entries()==256); sl@0: delete iPalette; sl@0: iPalette = NULL; sl@0: } sl@0: sl@0: /** sl@0: TestPalette::TestGetPtr sl@0: sl@0: Test the GetDataPtr() method in CPalette, to retrieve palette entries for a specified colour sl@0: sl@0: Called from the TTypes test script sl@0: */ sl@0: void TestPalette::TestGetPtr() sl@0: { sl@0: TRAPD(ret,iPalette2=CTestPalette::NewL()); sl@0: UNUSED_VAR(ret); sl@0: iTest->TEST(iPalette2->TestGetPtr()); sl@0: TInt colorNum; sl@0: for(colorNum=0;colorNumSetEntry(colorNum,color); sl@0: } sl@0: TPtr8 ptr(NULL,0); sl@0: iPalette2->GetDataPtr(0,CTestPalette::eNumColors,ptr); sl@0: const TUint8 maxValue=CTestPalette::eNumColors-1; sl@0: TInt ii; sl@0: for(ii=0;ii<4*CTestPalette::eNumColors;++ii) sl@0: { sl@0: TUint8 value=ptr[ii]; sl@0: if (value!=0 && ((ii + 1) % 4)) //skip alpha channel sl@0: ptr[ii]=STATIC_CAST(TUint8,maxValue-value); sl@0: } sl@0: for(colorNum=1;colorNumTEST(iPalette2->GetEntry(colorNum)==TRgb::Gray256(maxValue-colorNum)); sl@0: delete iPalette2; sl@0: iPalette2 = NULL; sl@0: } sl@0: sl@0: /** sl@0: CTestPalette::TestGetPtr sl@0: sl@0: Part of TestPalette::TestGetPtr, retrieves a descriptor from CPalette containing entries for a given colour sl@0: & checks parameters are legal sl@0: Returns boolean indiciating whether the GetDataPtr was successful or not sl@0: */ sl@0: TBool CTestPalette::TestGetPtr() sl@0: { sl@0: TPtr8 ptr(NULL,0); sl@0: TUint32* data=REINTERPRET_CAST(TUint32*,iArray); sl@0: TInt start; sl@0: TInt length; sl@0: for(start=0;start