sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "TTYPES.H"
|
sl@0
|
17 |
|
sl@0
|
18 |
#define UNUSED_VAR(a) a = a
|
sl@0
|
19 |
|
sl@0
|
20 |
TestPalette::TestPalette(CTTypes* aTest):
|
sl@0
|
21 |
iPalette(NULL), iPalette2(NULL),
|
sl@0
|
22 |
iTest(aTest)
|
sl@0
|
23 |
{}
|
sl@0
|
24 |
|
sl@0
|
25 |
TestPalette::~TestPalette()
|
sl@0
|
26 |
{
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
TestPalette::Test
|
sl@0
|
31 |
|
sl@0
|
32 |
Method to test the functionality within the CPalette class
|
sl@0
|
33 |
Called from the TTypes test script
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
void TestPalette::Test()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
_LIT(general,"General");
|
sl@0
|
38 |
iTest->INFO_PRINTF1(general);
|
sl@0
|
39 |
TestGeneral();
|
sl@0
|
40 |
_LIT(defaults,"Defaults");
|
sl@0
|
41 |
iTest->INFO_PRINTF1(defaults);
|
sl@0
|
42 |
//TestDefaults();
|
sl@0
|
43 |
_LIT(getData,"Get Data");
|
sl@0
|
44 |
iTest->INFO_PRINTF1(getData);
|
sl@0
|
45 |
//TestGetPtr();
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
/**
|
sl@0
|
49 |
TestPalette::TestGeneral
|
sl@0
|
50 |
|
sl@0
|
51 |
Spawn a new CPalette object & test basic calls to retrieve number of entries, add colours, etc
|
sl@0
|
52 |
*/
|
sl@0
|
53 |
void TestPalette::TestGeneral()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
const TInt numcolors=50;
|
sl@0
|
56 |
TRAPD(ret,iPalette=CPalette::NewL(numcolors));
|
sl@0
|
57 |
UNUSED_VAR(ret);
|
sl@0
|
58 |
iTest->TEST(iPalette->Entries()==numcolors);
|
sl@0
|
59 |
for(TInt colcount=0;colcount<numcolors;colcount++)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
TRgb color(colcount,0,0);
|
sl@0
|
62 |
iPalette->SetEntry(colcount,color);
|
sl@0
|
63 |
iTest->TEST(iPalette->GetEntry(colcount)==color);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
for(TInt checkcount=0;checkcount<numcolors;checkcount++)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
TRgb color(checkcount,0,0);
|
sl@0
|
68 |
iTest->TEST(iPalette->GetEntry(checkcount)==color);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
iPalette->Clear();
|
sl@0
|
71 |
TRgb black(0,0,0);
|
sl@0
|
72 |
for(TInt clearcount=0;clearcount<numcolors;clearcount++)
|
sl@0
|
73 |
iTest->TEST(iPalette->GetEntry(clearcount)==black);
|
sl@0
|
74 |
for(TInt nearcount=0;nearcount<5;nearcount++)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
TRgb color(nearcount*60,0,0);
|
sl@0
|
77 |
iPalette->SetEntry(nearcount,color);
|
sl@0
|
78 |
iTest->TEST(iPalette->GetEntry(nearcount)==color);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
for(TInt approxcount=0;approxcount<5;approxcount++)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TRgb color(approxcount*60,0,0);
|
sl@0
|
83 |
TRgb approxl(approxcount*59,0,0);
|
sl@0
|
84 |
TRgb approxh(approxcount*61,0,0);
|
sl@0
|
85 |
TRgb nearest=iPalette->NearestEntry(approxl);
|
sl@0
|
86 |
iTest->TEST(nearest==color);
|
sl@0
|
87 |
nearest=iPalette->NearestEntry(approxh);
|
sl@0
|
88 |
iTest->TEST(nearest==color);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
delete iPalette;
|
sl@0
|
91 |
iPalette = NULL;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
/**
|
sl@0
|
95 |
TestPalette::TestDefaults
|
sl@0
|
96 |
|
sl@0
|
97 |
Test creation of default colour palettes for supported/un-supported display modes
|
sl@0
|
98 |
Called from the TTypes test script
|
sl@0
|
99 |
*/
|
sl@0
|
100 |
void TestPalette::TestDefaults()
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TRAPD(ret,iPalette=CPalette::NewDefaultL(ENone));
|
sl@0
|
103 |
iTest->TEST2(ret, KErrNotSupported);
|
sl@0
|
104 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16M));
|
sl@0
|
105 |
iTest->TEST2(ret, KErrNotSupported);
|
sl@0
|
106 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16MU));
|
sl@0
|
107 |
iTest->TEST2(ret, KErrNotSupported);
|
sl@0
|
108 |
TRAP(ret,iPalette=CPalette::NewDefaultL(ERgb));
|
sl@0
|
109 |
iTest->TEST2(ret, KErrNotSupported);
|
sl@0
|
110 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EGray2));
|
sl@0
|
111 |
iTest->TEST(iPalette->GetEntry(0)==TRgb::Gray2(0));
|
sl@0
|
112 |
iTest->TEST(iPalette->GetEntry(1)==TRgb::Gray2(1));
|
sl@0
|
113 |
iTest->TEST(iPalette->Entries()==2);
|
sl@0
|
114 |
delete iPalette;
|
sl@0
|
115 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EGray4));
|
sl@0
|
116 |
for(TInt g4=0;g4<4;g4++)
|
sl@0
|
117 |
iTest->TEST(iPalette->GetEntry(g4)==TRgb::Gray4(g4));
|
sl@0
|
118 |
iTest->TEST(iPalette->Entries()==4);
|
sl@0
|
119 |
delete iPalette;
|
sl@0
|
120 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EGray16));
|
sl@0
|
121 |
for(TInt g16=0;g16<16;g16++)
|
sl@0
|
122 |
iTest->TEST(iPalette->GetEntry(g16)==TRgb::Gray16(g16));
|
sl@0
|
123 |
iTest->TEST(iPalette->Entries()==16);
|
sl@0
|
124 |
delete iPalette;
|
sl@0
|
125 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EGray256));
|
sl@0
|
126 |
for(TInt g256=0;g256<256;g256++)
|
sl@0
|
127 |
iTest->TEST(iPalette->GetEntry(g256)==TRgb::Gray256(g256));
|
sl@0
|
128 |
iTest->TEST(iPalette->Entries()==256);
|
sl@0
|
129 |
delete iPalette;
|
sl@0
|
130 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EColor16));
|
sl@0
|
131 |
for (TInt c16 = 0; c16 < 16; c16++)
|
sl@0
|
132 |
iTest->TEST(iPalette->GetEntry(c16)==TRgb::Color16(c16));
|
sl@0
|
133 |
iTest->TEST(iPalette->Entries()==16);
|
sl@0
|
134 |
delete iPalette;
|
sl@0
|
135 |
TRAP(ret,iPalette=CPalette::NewDefaultL(EColor256));
|
sl@0
|
136 |
for (TInt c256 = 0; c256 < 256; c256++)
|
sl@0
|
137 |
iTest->TEST(iPalette->GetEntry(c256)==TRgb::Color256(c256));
|
sl@0
|
138 |
iTest->TEST(iPalette->Entries()==256);
|
sl@0
|
139 |
delete iPalette;
|
sl@0
|
140 |
iPalette = NULL;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
TestPalette::TestGetPtr
|
sl@0
|
145 |
|
sl@0
|
146 |
Test the GetDataPtr() method in CPalette, to retrieve palette entries for a specified colour
|
sl@0
|
147 |
|
sl@0
|
148 |
Called from the TTypes test script
|
sl@0
|
149 |
*/
|
sl@0
|
150 |
void TestPalette::TestGetPtr()
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TRAPD(ret,iPalette2=CTestPalette::NewL());
|
sl@0
|
153 |
UNUSED_VAR(ret);
|
sl@0
|
154 |
iTest->TEST(iPalette2->TestGetPtr());
|
sl@0
|
155 |
TInt colorNum;
|
sl@0
|
156 |
for(colorNum=0;colorNum<CTestPalette::eNumColors;++colorNum)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
TRgb color(colorNum,colorNum,colorNum);
|
sl@0
|
159 |
iPalette2->SetEntry(colorNum,color);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
TPtr8 ptr(NULL,0);
|
sl@0
|
162 |
iPalette2->GetDataPtr(0,CTestPalette::eNumColors,ptr);
|
sl@0
|
163 |
const TUint8 maxValue=CTestPalette::eNumColors-1;
|
sl@0
|
164 |
TInt ii;
|
sl@0
|
165 |
for(ii=0;ii<4*CTestPalette::eNumColors;++ii)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TUint8 value=ptr[ii];
|
sl@0
|
168 |
if (value!=0 && ((ii + 1) % 4)) //skip alpha channel
|
sl@0
|
169 |
ptr[ii]=STATIC_CAST(TUint8,maxValue-value);
|
sl@0
|
170 |
}
|
sl@0
|
171 |
for(colorNum=1;colorNum<maxValue;++colorNum)
|
sl@0
|
172 |
iTest->TEST(iPalette2->GetEntry(colorNum)==TRgb::Gray256(maxValue-colorNum));
|
sl@0
|
173 |
delete iPalette2;
|
sl@0
|
174 |
iPalette2 = NULL;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
CTestPalette::TestGetPtr
|
sl@0
|
179 |
|
sl@0
|
180 |
Part of TestPalette::TestGetPtr, retrieves a descriptor from CPalette containing entries for a given colour
|
sl@0
|
181 |
& checks parameters are legal
|
sl@0
|
182 |
Returns boolean indiciating whether the GetDataPtr was successful or not
|
sl@0
|
183 |
*/
|
sl@0
|
184 |
TBool CTestPalette::TestGetPtr()
|
sl@0
|
185 |
{
|
sl@0
|
186 |
TPtr8 ptr(NULL,0);
|
sl@0
|
187 |
TUint32* data=REINTERPRET_CAST(TUint32*,iArray);
|
sl@0
|
188 |
TInt start;
|
sl@0
|
189 |
TInt length;
|
sl@0
|
190 |
for(start=0;start<eNumColors;++start)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
for(length=1;length<eNumColors-start;++length)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
TInt len=sizeof(TRgb)*length;
|
sl@0
|
195 |
GetDataPtr(start,length,ptr);
|
sl@0
|
196 |
if (&ptr[0]!=REINTERPRET_CAST(TUint8*,data+start) || ptr.Length()!=len || ptr.MaxLength()!=len)
|
sl@0
|
197 |
return EFalse;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
}
|
sl@0
|
200 |
return ETrue;
|
sl@0
|
201 |
}
|