|
1 // Copyright (c) 1996-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 // GETPIXEL.CPP |
|
15 // Automatically test GetPixel |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include "TGETPIXEL.H" |
|
26 |
|
27 CTGetPixel::CTGetPixel(CTestStep* aStep): |
|
28 CTWsGraphicsBase(aStep) |
|
29 { |
|
30 } |
|
31 |
|
32 CTGetPixel::~CTGetPixel() |
|
33 { |
|
34 iWindow.Close(); |
|
35 User::Free(iRgbBuf); |
|
36 } |
|
37 |
|
38 LOCAL_C TInt DoPanicTest(TInt aFunc, TAny *aScreenNumber) |
|
39 { |
|
40 RWsSession ws; |
|
41 if (ws.Connect()==KErrNone) |
|
42 switch(aFunc) |
|
43 { |
|
44 case 1: // Get pixels into a TPtr 1 pixel too small |
|
45 { |
|
46 CWsScreenDevice *screen = new(ELeave) CWsScreenDevice(ws); |
|
47 User::LeaveIfError(screen->Construct((TInt)aScreenNumber)); |
|
48 CFbsBitmap *bitmap=new(ELeave) CFbsBitmap(); |
|
49 TInt bitWid=80; |
|
50 TRgb *buf=NULL; |
|
51 if (bitmap->Create(TSize(1,bitWid), EGray16)==KErrNone && (buf=(TRgb *)User::Alloc((bitWid-1)*sizeof(TRgb)))!=NULL) |
|
52 { |
|
53 TPtr8 desc((TUint8 *)buf,(bitWid-1)*sizeof(TRgb)); |
|
54 screen->GetScanLine(desc,TPoint(0,0),bitWid, ERgb); |
|
55 } |
|
56 } |
|
57 break; |
|
58 } |
|
59 return(EWsExitReasonBad); |
|
60 } |
|
61 |
|
62 void CTGetPixel::ClearOutRedraws() |
|
63 // This has been added because partial redraw store can be triggered to request a |
|
64 // low priority redraw from the window even though in normal circumstances the window |
|
65 // would not expect to receive any sort of redraw event. |
|
66 { |
|
67 iWindow.BeginRedraw(); |
|
68 iWindow.EndRedraw(); |
|
69 } |
|
70 |
|
71 void CTGetPixel::TestPanicsL() |
|
72 { |
|
73 if (!iTest->IsFullRomL()) |
|
74 { |
|
75 TEST(iTest->TestWsPanicL(DoPanicTest,EWservPanicInvalidParameter,1,(TAny*)iTest->iScreenNumber)); |
|
76 } |
|
77 } |
|
78 |
|
79 void CTGetPixel::DrawAndCheckLine(const TPoint &aPos,TInt aLen,TRgb aColor) |
|
80 { |
|
81 TheGc->Activate(iWindow); |
|
82 TheGc->SetPenColor(aColor); |
|
83 iWindow.BeginRedraw(TRect(aPos,TSize(aLen, 1))); |
|
84 TheGc->DrawLine(aPos,aPos+TSize(aLen,0)); |
|
85 iWindow.EndRedraw(); |
|
86 TheGc->Deactivate(); |
|
87 iRgbBuf=(TRgb *)User::ReAlloc(iRgbBuf,aLen*sizeof(TRgb)); |
|
88 TPtr8 ptr((TUint8 *)iRgbBuf,aLen*sizeof(TRgb)); |
|
89 TheClient->iScreen->GetScanLine(ptr, aPos+iWindow.InquireOffset(*TheClient->iGroup->WinTreeNode()), aLen, EColor16MA); |
|
90 TRgb result(TRgb::Gray16(aColor.Gray16())); |
|
91 if (TheClient->iScreen->DisplayMode()==EColor64K) |
|
92 result=TRgb::Color64K(result.Color64K()); |
|
93 for(TInt index=0;index<aLen;index++) |
|
94 { |
|
95 TEST(iRgbBuf[index]==result); |
|
96 } |
|
97 } |
|
98 |
|
99 void CTGetPixel::ConstructL() |
|
100 { |
|
101 iWindow = TheClient->iWs; |
|
102 TheGc->Activate(*BaseWin->Win()); |
|
103 TheGc->Clear(); |
|
104 TheGc->SetBrushColor(TRgb::Gray16(0)); |
|
105 TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
106 TheGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
107 TheGc->DrawRect(TRect(iWinSize)); |
|
108 TheGc->Deactivate(); |
|
109 |
|
110 iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle); |
|
111 iWinSize=TSize(TheClient->iScreen->SizeInPixels()); |
|
112 iWinSize.iWidth/=3; |
|
113 iWinSize.iHeight/=3; |
|
114 iWindow.SetRequiredDisplayMode(EGray16); |
|
115 TheClient->iWs.Flush(); |
|
116 iTest->DelayIfFullRomL(); // Need to wait for view server to mess around when display mode changed |
|
117 TheClient->WaitForRedrawsToFinish();// otherwise it will stomp on top of our window invalidating it. |
|
118 iWindow.SetExtent(TPoint(iWinSize.iWidth,iWinSize.iHeight),iWinSize); |
|
119 iWindow.EnableRedrawStore(EFalse); // Otherwise drawing might trigger a redraw when purging redraw store |
|
120 |
|
121 iWindow.Activate(); |
|
122 iWindow.BeginRedraw(); |
|
123 iWindow.EndRedraw(); |
|
124 |
|
125 } |
|
126 |
|
127 void CTGetPixel::TestCheckRect() |
|
128 { |
|
129 TSize size(TheClient->iScreen->SizeInPixels()); |
|
130 TEST(TheClient->iScreen->RectCompare(TRect(size),TRect(TPoint(iTest->StdTestWindowSize().iWidth>>1,0),iTest->StdTestWindowSize()))==EFalse); |
|
131 } |
|
132 |
|
133 void CTGetPixel::DrawColorsL() |
|
134 { |
|
135 TPoint point(0,0); |
|
136 TInt color=-1; |
|
137 iWindow.BeginRedraw(); |
|
138 FOREVER |
|
139 { |
|
140 TheGc->SetPenColor(TRgb::Color256(++color)); |
|
141 TheGc->Plot(point); |
|
142 if (color==255) |
|
143 break; |
|
144 if (++point.iX==iWinSize.iWidth) |
|
145 { |
|
146 point.iX=0; |
|
147 if (++point.iY==iWinSize.iHeight) |
|
148 break; |
|
149 } |
|
150 } |
|
151 iWindow.EndRedraw(); |
|
152 } |
|
153 |
|
154 void CTGetPixel::TestColors(CPalette* aPalette) |
|
155 { |
|
156 TInt numColors=iWinSize.iWidth; |
|
157 TPtr8 ptr(REINTERPRET_CAST(TUint8*,iRgbBuf),numColors*sizeof(TRgb)); |
|
158 TPtr8 paletteData(NULL,0); |
|
159 TInt color=0; |
|
160 TPoint point(iWinSize.AsPoint()); |
|
161 do { |
|
162 if (color+numColors>256) |
|
163 numColors=256-color; |
|
164 TheClient->iScreen->GetScanLine(ptr,point,numColors,EColor16MA); |
|
165 aPalette->GetDataPtr(color,numColors,paletteData); |
|
166 TEST(ptr==paletteData); |
|
167 color+=numColors; |
|
168 } while (color<256 && ++point.iY<2*iWinSize.iHeight); |
|
169 } |
|
170 |
|
171 void CTGetPixel::CheckPaletteL(CPalette*& aPalette) |
|
172 { |
|
173 User::LeaveIfError(TheClient->iScreen->SetCustomPalette(aPalette)); |
|
174 TestColors(aPalette); |
|
175 delete aPalette; |
|
176 User::LeaveIfError(TheClient->iScreen->GetPalette(aPalette)); |
|
177 TestColors(aPalette); |
|
178 } |
|
179 |
|
180 inline TInt Inc(TInt& aValue) |
|
181 { |
|
182 if (aValue>255-83) |
|
183 aValue-=256-83; |
|
184 else |
|
185 aValue+=83; |
|
186 return aValue; |
|
187 } |
|
188 |
|
189 inline TInt Inc2(TInt& aValue) |
|
190 { |
|
191 if (aValue>255-41) |
|
192 aValue-=256-41; |
|
193 else |
|
194 aValue+=41; |
|
195 return aValue; |
|
196 } |
|
197 |
|
198 void CTGetPixel::PaletteTestL() |
|
199 { |
|
200 //INFO_PRINTF1(_L("AUTO PaletteTest ")); |
|
201 TInt numEntries; |
|
202 TBool modifiable; |
|
203 TheClient->iScreen->PaletteAttributes(modifiable,numEntries); |
|
204 INFO_PRINTF2(_L("Number of entries in the palette %d"), numEntries); |
|
205 if(numEntries > 65536) |
|
206 { |
|
207 INFO_PRINTF1(_L("These test cases has been skipped, as the screen is set up in true colour display mode, where palette is not applicable")); |
|
208 return; |
|
209 } |
|
210 CPalette* palette=NULL; |
|
211 if (!modifiable) |
|
212 { |
|
213 if (numEntries==4) |
|
214 palette=CPalette::NewDefaultL(EGray4); |
|
215 else if (numEntries==16) |
|
216 palette=CPalette::NewDefaultL(EGray16); |
|
217 else |
|
218 palette=CPalette::NewL(numEntries); |
|
219 //INFO_PRINTF1(_L(" Creating Empty Palette, setting it as palette")); |
|
220 TInt err=TheClient->iScreen->SetCustomPalette(palette); |
|
221 TEST(err==KErrNoMemory || err==KErrNotSupported || (err==KErrNone && numEntries<=16)); //Series5MX palettes are changeable even though they say they aren't |
|
222 //INFO_PRINTF1(_L(" Palette setting test passed OK")); |
|
223 delete palette; |
|
224 } |
|
225 TInt err=iWindow.SetRequiredDisplayMode(EColor256); |
|
226 TheGc->Activate(iWindow); |
|
227 DrawColorsL(); |
|
228 //INFO_PRINTF1(_L(" Drawn Colors")); |
|
229 TheClient->iScreen->PaletteAttributes(modifiable,numEntries); |
|
230 iRgbBuf=STATIC_CAST(TRgb*,User::ReAllocL(iRgbBuf,Max(256,iWinSize.iWidth)*sizeof(TRgb))); |
|
231 if (err<KErrNone || modifiable==EFalse) |
|
232 { |
|
233 //INFO_PRINTF1(_L(" Palette Fixed")); |
|
234 TInt err=TheClient->iScreen->GetPalette(palette); |
|
235 if (err==KErrNotSupported) |
|
236 return; |
|
237 User::LeaveIfError(err); |
|
238 TestColors(palette); |
|
239 delete palette; |
|
240 //INFO_PRINTF1(_L(" Tested Palette OK")); |
|
241 return; |
|
242 } |
|
243 //INFO_PRINTF1(_L(" Palette Changeable")); |
|
244 TEST(numEntries==256); |
|
245 CPalette* defPalette=CPalette::NewDefaultL(EColor256); |
|
246 CleanupStack::PushL(defPalette); |
|
247 TestColors(defPalette); |
|
248 User::LeaveIfError(TheClient->iScreen->GetPalette(palette)); |
|
249 TestColors(palette); |
|
250 TInt color; |
|
251 TInt index=0; |
|
252 for (color=0;color<256;++color) |
|
253 palette->SetEntry(color,TRgb::Gray256(color)); |
|
254 CheckPaletteL(palette); |
|
255 for (color=0;color<256;++color) |
|
256 palette->SetEntry(color,TRgb(Inc(index),Inc(index),Inc(index))); |
|
257 CheckPaletteL(palette); |
|
258 for (color=0;color<256;++color) |
|
259 palette->SetEntry(color,TRgb(Inc2(index),Inc2(index),Inc2(index))); |
|
260 CheckPaletteL(palette); |
|
261 delete palette; |
|
262 User::LeaveIfError(TheClient->iScreen->SetCustomPalette(defPalette)); |
|
263 TestColors(defPalette); |
|
264 CleanupStack::PopAndDestroy(defPalette); |
|
265 ClearOutRedraws(); |
|
266 } |
|
267 |
|
268 void CTGetPixel::RunTestCaseL(TInt /*aCurTestCase*/) |
|
269 { |
|
270 ((CTGetPixelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
271 switch(++iTest->iState) |
|
272 { |
|
273 /** |
|
274 @SYMTestCaseID GRAPHICS-WSERV-0212 |
|
275 |
|
276 @SYMDEF DEF081259 |
|
277 |
|
278 @SYMTestCaseDesc Draw lines and check them by scanning the lines |
|
279 |
|
280 @SYMTestPriority High |
|
281 |
|
282 @SYMTestStatus Implemented |
|
283 |
|
284 @SYMTestActions Draw lines and then scan them to check that they have |
|
285 been drawn correctly |
|
286 |
|
287 @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly |
|
288 */ |
|
289 case 1: |
|
290 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0212")); |
|
291 TheClient->iWs.SetAutoFlush(ETrue); |
|
292 iTest->LogSubTest(_L("Basic")); |
|
293 DrawAndCheckLine(TPoint(0,2),iWinSize.iWidth-2,TRgb::Gray4(0)); |
|
294 DrawAndCheckLine(TPoint(0,iWinSize.iHeight-2),iWinSize.iWidth,TRgb::Gray4(1)); |
|
295 DrawAndCheckLine(TPoint(iWinSize.iWidth-1,iWinSize.iHeight-1),1,TRgb::Gray4(2)); |
|
296 ClearOutRedraws(); |
|
297 TheClient->iWs.SetAutoFlush(EFalse); |
|
298 break; |
|
299 /** |
|
300 @SYMTestCaseID GRAPHICS-WSERV-0213 |
|
301 |
|
302 @SYMDEF DEF081259 |
|
303 |
|
304 @SYMTestCaseDesc Draw line on every line of a window and |
|
305 check them by scanning the lines |
|
306 |
|
307 @SYMTestPriority High |
|
308 |
|
309 @SYMTestStatus Implemented |
|
310 |
|
311 @SYMTestActions Draw lines on every line of a window and |
|
312 check them by scanning the lines |
|
313 |
|
314 @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly |
|
315 */ |
|
316 |
|
317 case 2: |
|
318 { |
|
319 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0213")); |
|
320 iTest->LogSubTest(_L("Full window")); |
|
321 for(TInt ypos=0;ypos<iWinSize.iHeight;ypos++) |
|
322 DrawAndCheckLine(TPoint(0,ypos),iWinSize.iWidth,TRgb::Gray4(0)); |
|
323 ClearOutRedraws(); |
|
324 } |
|
325 break; |
|
326 /** |
|
327 @SYMTestCaseID GRAPHICS-WSERV-0214 |
|
328 |
|
329 @SYMDEF DEF081259 |
|
330 |
|
331 @SYMTestCaseDesc Test the check rect method |
|
332 |
|
333 @SYMTestPriority High |
|
334 |
|
335 @SYMTestStatus Implemented |
|
336 |
|
337 @SYMTestActions Use the check rect method to check the image in a window |
|
338 |
|
339 @SYMTestExpectedResults The check rect method functions correctly |
|
340 */ |
|
341 case 3: |
|
342 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0214")); |
|
343 iTest->LogSubTest(_L("Check Rect")); |
|
344 TestCheckRect(); |
|
345 break; |
|
346 /** |
|
347 @SYMTestCaseID GRAPHICS-WSERV-0215 |
|
348 |
|
349 @SYMDEF DEF081259 |
|
350 |
|
351 @SYMTestCaseDesc Test that the GetScanLine method panics correctly |
|
352 |
|
353 @SYMTestPriority High |
|
354 |
|
355 @SYMTestStatus Implemented |
|
356 |
|
357 @SYMTestActions Cause the GetScanLine method to panic and chekc the response |
|
358 |
|
359 @SYMTestExpectedResults The panic for the GetScanLine method is correct |
|
360 */ |
|
361 case 4: |
|
362 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0215")); |
|
363 iTest->LogSubTest(_L("Panic")); |
|
364 TestPanicsL(); |
|
365 break; |
|
366 /** |
|
367 @SYMTestCaseID GRAPHICS-WSERV-0216 |
|
368 |
|
369 @SYMDEF DEF081259 |
|
370 |
|
371 @SYMTestCaseDesc Test that CPalette class functions correctly |
|
372 |
|
373 @SYMTestPriority High |
|
374 |
|
375 @SYMTestStatus Implemented |
|
376 |
|
377 @SYMTestActions Create a CPalette object and exercise all its methods |
|
378 |
|
379 @SYMTestExpectedResults The palette functions as exepcted |
|
380 */ |
|
381 case 5: |
|
382 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0216")); |
|
383 iTest->LogSubTest(_L("Palette Test")); |
|
384 PaletteTestL(); |
|
385 break; |
|
386 case 6: |
|
387 ((CTGetPixelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
388 ((CTGetPixelStep*)iStep)->CloseTMSGraphicsStep(); |
|
389 TestComplete(); |
|
390 break; |
|
391 } |
|
392 ((CTGetPixelStep*)iStep)->RecordTestResultL(); |
|
393 } |
|
394 |
|
395 __WS_CONSTRUCT_STEP__(GetPixel) |