First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // Automatically test GetPixel
22 @internalComponent - Internal Symbian test code
25 #include "TGETPIXEL.H"
27 CTGetPixel::CTGetPixel(CTestStep* aStep):
28 CTWsGraphicsBase(aStep)
32 CTGetPixel::~CTGetPixel()
38 LOCAL_C TInt DoPanicTest(TInt aFunc, TAny *aScreenNumber)
41 if (ws.Connect()==KErrNone)
44 case 1: // Get pixels into a TPtr 1 pixel too small
46 CWsScreenDevice *screen = new(ELeave) CWsScreenDevice(ws);
47 User::LeaveIfError(screen->Construct((TInt)aScreenNumber));
48 CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
51 if (bitmap->Create(TSize(1,bitWid), EGray16)==KErrNone && (buf=(TRgb *)User::Alloc((bitWid-1)*sizeof(TRgb)))!=NULL)
53 TPtr8 desc((TUint8 *)buf,(bitWid-1)*sizeof(TRgb));
54 screen->GetScanLine(desc,TPoint(0,0),bitWid, ERgb);
59 return(EWsExitReasonBad);
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.
67 iWindow.BeginRedraw();
71 void CTGetPixel::TestPanicsL()
73 if (!iTest->IsFullRomL())
75 TEST(iTest->TestWsPanicL(DoPanicTest,EWservPanicInvalidParameter,1,(TAny*)iTest->iScreenNumber));
79 void CTGetPixel::DrawAndCheckLine(const TPoint &aPos,TInt aLen,TRgb aColor)
81 TheGc->Activate(iWindow);
82 TheGc->SetPenColor(aColor);
83 iWindow.BeginRedraw(TRect(aPos,TSize(aLen, 1)));
84 TheGc->DrawLine(aPos,aPos+TSize(aLen,0));
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++)
95 TEST(iRgbBuf[index]==result);
99 void CTGetPixel::ConstructL()
101 iWindow = TheClient->iWs;
102 TheGc->Activate(*BaseWin->Win());
104 TheGc->SetBrushColor(TRgb::Gray16(0));
105 TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
106 TheGc->SetPenStyle(CGraphicsContext::ENullPen);
107 TheGc->DrawRect(TRect(iWinSize));
110 iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle);
111 iWinSize=TSize(TheClient->iScreen->SizeInPixels());
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
122 iWindow.BeginRedraw();
127 void CTGetPixel::TestCheckRect()
129 TSize size(TheClient->iScreen->SizeInPixels());
130 TEST(TheClient->iScreen->RectCompare(TRect(size),TRect(TPoint(iTest->StdTestWindowSize().iWidth>>1,0),iTest->StdTestWindowSize()))==EFalse);
133 void CTGetPixel::DrawColorsL()
137 iWindow.BeginRedraw();
140 TheGc->SetPenColor(TRgb::Color256(++color));
144 if (++point.iX==iWinSize.iWidth)
147 if (++point.iY==iWinSize.iHeight)
154 void CTGetPixel::TestColors(CPalette* aPalette)
156 TInt numColors=iWinSize.iWidth;
157 TPtr8 ptr(REINTERPRET_CAST(TUint8*,iRgbBuf),numColors*sizeof(TRgb));
158 TPtr8 paletteData(NULL,0);
160 TPoint point(iWinSize.AsPoint());
162 if (color+numColors>256)
164 TheClient->iScreen->GetScanLine(ptr,point,numColors,EColor16MA);
165 aPalette->GetDataPtr(color,numColors,paletteData);
166 TEST(ptr==paletteData);
168 } while (color<256 && ++point.iY<2*iWinSize.iHeight);
171 void CTGetPixel::CheckPaletteL(CPalette*& aPalette)
173 User::LeaveIfError(TheClient->iScreen->SetCustomPalette(aPalette));
174 TestColors(aPalette);
176 User::LeaveIfError(TheClient->iScreen->GetPalette(aPalette));
177 TestColors(aPalette);
180 inline TInt Inc(TInt& aValue)
189 inline TInt Inc2(TInt& aValue)
198 void CTGetPixel::PaletteTestL()
200 //INFO_PRINTF1(_L("AUTO PaletteTest "));
203 TheClient->iScreen->PaletteAttributes(modifiable,numEntries);
204 INFO_PRINTF2(_L("Number of entries in the palette %d"), numEntries);
205 if(numEntries > 65536)
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"));
210 CPalette* palette=NULL;
214 palette=CPalette::NewDefaultL(EGray4);
215 else if (numEntries==16)
216 palette=CPalette::NewDefaultL(EGray16);
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"));
225 TInt err=iWindow.SetRequiredDisplayMode(EColor256);
226 TheGc->Activate(iWindow);
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)
233 //INFO_PRINTF1(_L(" Palette Fixed"));
234 TInt err=TheClient->iScreen->GetPalette(palette);
235 if (err==KErrNotSupported)
237 User::LeaveIfError(err);
240 //INFO_PRINTF1(_L(" Tested Palette OK"));
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));
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);
262 User::LeaveIfError(TheClient->iScreen->SetCustomPalette(defPalette));
263 TestColors(defPalette);
264 CleanupStack::PopAndDestroy(defPalette);
268 void CTGetPixel::RunTestCaseL(TInt /*aCurTestCase*/)
270 ((CTGetPixelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
271 switch(++iTest->iState)
274 @SYMTestCaseID GRAPHICS-WSERV-0212
278 @SYMTestCaseDesc Draw lines and check them by scanning the lines
280 @SYMTestPriority High
282 @SYMTestStatus Implemented
284 @SYMTestActions Draw lines and then scan them to check that they have
287 @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
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));
297 TheClient->iWs.SetAutoFlush(EFalse);
300 @SYMTestCaseID GRAPHICS-WSERV-0213
304 @SYMTestCaseDesc Draw line on every line of a window and
305 check them by scanning the lines
307 @SYMTestPriority High
309 @SYMTestStatus Implemented
311 @SYMTestActions Draw lines on every line of a window and
312 check them by scanning the lines
314 @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly
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));
327 @SYMTestCaseID GRAPHICS-WSERV-0214
331 @SYMTestCaseDesc Test the check rect method
333 @SYMTestPriority High
335 @SYMTestStatus Implemented
337 @SYMTestActions Use the check rect method to check the image in a window
339 @SYMTestExpectedResults The check rect method functions correctly
342 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0214"));
343 iTest->LogSubTest(_L("Check Rect"));
347 @SYMTestCaseID GRAPHICS-WSERV-0215
351 @SYMTestCaseDesc Test that the GetScanLine method panics correctly
353 @SYMTestPriority High
355 @SYMTestStatus Implemented
357 @SYMTestActions Cause the GetScanLine method to panic and chekc the response
359 @SYMTestExpectedResults The panic for the GetScanLine method is correct
362 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0215"));
363 iTest->LogSubTest(_L("Panic"));
367 @SYMTestCaseID GRAPHICS-WSERV-0216
371 @SYMTestCaseDesc Test that CPalette class functions correctly
373 @SYMTestPriority High
375 @SYMTestStatus Implemented
377 @SYMTestActions Create a CPalette object and exercise all its methods
379 @SYMTestExpectedResults The palette functions as exepcted
382 ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0216"));
383 iTest->LogSubTest(_L("Palette Test"));
387 ((CTGetPixelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
388 ((CTGetPixelStep*)iStep)->CloseTMSGraphicsStep();
392 ((CTGetPixelStep*)iStep)->RecordTestResultL();
395 __WS_CONSTRUCT_STEP__(GetPixel)