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