sl@0: // Copyright (c) 1996-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: // GETPIXEL.CPP sl@0: // Automatically test GetPixel sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include "TGETPIXEL.H" sl@0: sl@0: CTGetPixel::CTGetPixel(CTestStep* aStep): sl@0: CTWsGraphicsBase(aStep) sl@0: { sl@0: } sl@0: sl@0: CTGetPixel::~CTGetPixel() sl@0: { sl@0: iWindow.Close(); sl@0: User::Free(iRgbBuf); sl@0: } sl@0: sl@0: LOCAL_C TInt DoPanicTest(TInt aFunc, TAny *aScreenNumber) sl@0: { sl@0: RWsSession ws; sl@0: if (ws.Connect()==KErrNone) sl@0: switch(aFunc) sl@0: { sl@0: case 1: // Get pixels into a TPtr 1 pixel too small sl@0: { sl@0: CWsScreenDevice *screen = new(ELeave) CWsScreenDevice(ws); sl@0: User::LeaveIfError(screen->Construct((TInt)aScreenNumber)); sl@0: CFbsBitmap *bitmap=new(ELeave) CFbsBitmap(); sl@0: TInt bitWid=80; sl@0: TRgb *buf=NULL; sl@0: if (bitmap->Create(TSize(1,bitWid), EGray16)==KErrNone && (buf=(TRgb *)User::Alloc((bitWid-1)*sizeof(TRgb)))!=NULL) sl@0: { sl@0: TPtr8 desc((TUint8 *)buf,(bitWid-1)*sizeof(TRgb)); sl@0: screen->GetScanLine(desc,TPoint(0,0),bitWid, ERgb); sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: return(EWsExitReasonBad); sl@0: } sl@0: sl@0: void CTGetPixel::ClearOutRedraws() sl@0: // This has been added because partial redraw store can be triggered to request a sl@0: // low priority redraw from the window even though in normal circumstances the window sl@0: // would not expect to receive any sort of redraw event. sl@0: { sl@0: iWindow.BeginRedraw(); sl@0: iWindow.EndRedraw(); sl@0: } sl@0: sl@0: void CTGetPixel::TestPanicsL() sl@0: { sl@0: if (!iTest->IsFullRomL()) sl@0: { sl@0: TEST(iTest->TestWsPanicL(DoPanicTest,EWservPanicInvalidParameter,1,(TAny*)iTest->iScreenNumber)); sl@0: } sl@0: } sl@0: sl@0: void CTGetPixel::DrawAndCheckLine(const TPoint &aPos,TInt aLen,TRgb aColor) sl@0: { sl@0: TheGc->Activate(iWindow); sl@0: TheGc->SetPenColor(aColor); sl@0: iWindow.BeginRedraw(TRect(aPos,TSize(aLen, 1))); sl@0: TheGc->DrawLine(aPos,aPos+TSize(aLen,0)); sl@0: iWindow.EndRedraw(); sl@0: TheGc->Deactivate(); sl@0: iRgbBuf=(TRgb *)User::ReAlloc(iRgbBuf,aLen*sizeof(TRgb)); sl@0: TPtr8 ptr((TUint8 *)iRgbBuf,aLen*sizeof(TRgb)); sl@0: TheClient->iScreen->GetScanLine(ptr, aPos+iWindow.InquireOffset(*TheClient->iGroup->WinTreeNode()), aLen, EColor16MA); sl@0: TRgb result(TRgb::Gray16(aColor.Gray16())); sl@0: if (TheClient->iScreen->DisplayMode()==EColor64K) sl@0: result=TRgb::Color64K(result.Color64K()); sl@0: for(TInt index=0;indexiWs; sl@0: TheGc->Activate(*BaseWin->Win()); sl@0: TheGc->Clear(); sl@0: TheGc->SetBrushColor(TRgb::Gray16(0)); sl@0: TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: TheGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: TheGc->DrawRect(TRect(iWinSize)); sl@0: TheGc->Deactivate(); sl@0: sl@0: iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle); sl@0: iWinSize=TSize(TheClient->iScreen->SizeInPixels()); sl@0: iWinSize.iWidth/=3; sl@0: iWinSize.iHeight/=3; sl@0: iWindow.SetRequiredDisplayMode(EGray16); sl@0: TheClient->iWs.Flush(); sl@0: iTest->DelayIfFullRomL(); // Need to wait for view server to mess around when display mode changed sl@0: TheClient->WaitForRedrawsToFinish();// otherwise it will stomp on top of our window invalidating it. sl@0: iWindow.SetExtent(TPoint(iWinSize.iWidth,iWinSize.iHeight),iWinSize); sl@0: iWindow.EnableRedrawStore(EFalse); // Otherwise drawing might trigger a redraw when purging redraw store sl@0: sl@0: iWindow.Activate(); sl@0: iWindow.BeginRedraw(); sl@0: iWindow.EndRedraw(); sl@0: sl@0: } sl@0: sl@0: void CTGetPixel::TestCheckRect() sl@0: { sl@0: TSize size(TheClient->iScreen->SizeInPixels()); sl@0: TEST(TheClient->iScreen->RectCompare(TRect(size),TRect(TPoint(iTest->StdTestWindowSize().iWidth>>1,0),iTest->StdTestWindowSize()))==EFalse); sl@0: } sl@0: sl@0: void CTGetPixel::DrawColorsL() sl@0: { sl@0: TPoint point(0,0); sl@0: TInt color=-1; sl@0: iWindow.BeginRedraw(); sl@0: FOREVER sl@0: { sl@0: TheGc->SetPenColor(TRgb::Color256(++color)); sl@0: TheGc->Plot(point); sl@0: if (color==255) sl@0: break; sl@0: if (++point.iX==iWinSize.iWidth) sl@0: { sl@0: point.iX=0; sl@0: if (++point.iY==iWinSize.iHeight) sl@0: break; sl@0: } sl@0: } sl@0: iWindow.EndRedraw(); sl@0: } sl@0: sl@0: void CTGetPixel::TestColors(CPalette* aPalette) sl@0: { sl@0: TInt numColors=iWinSize.iWidth; sl@0: TPtr8 ptr(REINTERPRET_CAST(TUint8*,iRgbBuf),numColors*sizeof(TRgb)); sl@0: TPtr8 paletteData(NULL,0); sl@0: TInt color=0; sl@0: TPoint point(iWinSize.AsPoint()); sl@0: do { sl@0: if (color+numColors>256) sl@0: numColors=256-color; sl@0: TheClient->iScreen->GetScanLine(ptr,point,numColors,EColor16MA); sl@0: aPalette->GetDataPtr(color,numColors,paletteData); sl@0: TEST(ptr==paletteData); sl@0: color+=numColors; sl@0: } while (color<256 && ++point.iY<2*iWinSize.iHeight); sl@0: } sl@0: sl@0: void CTGetPixel::CheckPaletteL(CPalette*& aPalette) sl@0: { sl@0: User::LeaveIfError(TheClient->iScreen->SetCustomPalette(aPalette)); sl@0: TestColors(aPalette); sl@0: delete aPalette; sl@0: User::LeaveIfError(TheClient->iScreen->GetPalette(aPalette)); sl@0: TestColors(aPalette); sl@0: } sl@0: sl@0: inline TInt Inc(TInt& aValue) sl@0: { sl@0: if (aValue>255-83) sl@0: aValue-=256-83; sl@0: else sl@0: aValue+=83; sl@0: return aValue; sl@0: } sl@0: sl@0: inline TInt Inc2(TInt& aValue) sl@0: { sl@0: if (aValue>255-41) sl@0: aValue-=256-41; sl@0: else sl@0: aValue+=41; sl@0: return aValue; sl@0: } sl@0: sl@0: void CTGetPixel::PaletteTestL() sl@0: { sl@0: //INFO_PRINTF1(_L("AUTO PaletteTest ")); sl@0: TInt numEntries; sl@0: TBool modifiable; sl@0: TheClient->iScreen->PaletteAttributes(modifiable,numEntries); sl@0: INFO_PRINTF2(_L("Number of entries in the palette %d"), numEntries); sl@0: if(numEntries > 65536) sl@0: { sl@0: 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")); sl@0: return; sl@0: } sl@0: CPalette* palette=NULL; sl@0: if (!modifiable) sl@0: { sl@0: if (numEntries==4) sl@0: palette=CPalette::NewDefaultL(EGray4); sl@0: else if (numEntries==16) sl@0: palette=CPalette::NewDefaultL(EGray16); sl@0: else sl@0: palette=CPalette::NewL(numEntries); sl@0: //INFO_PRINTF1(_L(" Creating Empty Palette, setting it as palette")); sl@0: TInt err=TheClient->iScreen->SetCustomPalette(palette); sl@0: TEST(err==KErrNoMemory || err==KErrNotSupported || (err==KErrNone && numEntries<=16)); //Series5MX palettes are changeable even though they say they aren't sl@0: //INFO_PRINTF1(_L(" Palette setting test passed OK")); sl@0: delete palette; sl@0: } sl@0: TInt err=iWindow.SetRequiredDisplayMode(EColor256); sl@0: TheGc->Activate(iWindow); sl@0: DrawColorsL(); sl@0: //INFO_PRINTF1(_L(" Drawn Colors")); sl@0: TheClient->iScreen->PaletteAttributes(modifiable,numEntries); sl@0: iRgbBuf=STATIC_CAST(TRgb*,User::ReAllocL(iRgbBuf,Max(256,iWinSize.iWidth)*sizeof(TRgb))); sl@0: if (erriScreen->GetPalette(palette); sl@0: if (err==KErrNotSupported) sl@0: return; sl@0: User::LeaveIfError(err); sl@0: TestColors(palette); sl@0: delete palette; sl@0: //INFO_PRINTF1(_L(" Tested Palette OK")); sl@0: return; sl@0: } sl@0: //INFO_PRINTF1(_L(" Palette Changeable")); sl@0: TEST(numEntries==256); sl@0: CPalette* defPalette=CPalette::NewDefaultL(EColor256); sl@0: CleanupStack::PushL(defPalette); sl@0: TestColors(defPalette); sl@0: User::LeaveIfError(TheClient->iScreen->GetPalette(palette)); sl@0: TestColors(palette); sl@0: TInt color; sl@0: TInt index=0; sl@0: for (color=0;color<256;++color) sl@0: palette->SetEntry(color,TRgb::Gray256(color)); sl@0: CheckPaletteL(palette); sl@0: for (color=0;color<256;++color) sl@0: palette->SetEntry(color,TRgb(Inc(index),Inc(index),Inc(index))); sl@0: CheckPaletteL(palette); sl@0: for (color=0;color<256;++color) sl@0: palette->SetEntry(color,TRgb(Inc2(index),Inc2(index),Inc2(index))); sl@0: CheckPaletteL(palette); sl@0: delete palette; sl@0: User::LeaveIfError(TheClient->iScreen->SetCustomPalette(defPalette)); sl@0: TestColors(defPalette); sl@0: CleanupStack::PopAndDestroy(defPalette); sl@0: ClearOutRedraws(); sl@0: } sl@0: sl@0: void CTGetPixel::RunTestCaseL(TInt /*aCurTestCase*/) sl@0: { sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(++iTest->iState) sl@0: { sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0212 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Draw lines and check them by scanning the lines sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Draw lines and then scan them to check that they have sl@0: been drawn correctly sl@0: sl@0: @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly sl@0: */ sl@0: case 1: sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0212")); sl@0: TheClient->iWs.SetAutoFlush(ETrue); sl@0: iTest->LogSubTest(_L("Basic")); sl@0: DrawAndCheckLine(TPoint(0,2),iWinSize.iWidth-2,TRgb::Gray4(0)); sl@0: DrawAndCheckLine(TPoint(0,iWinSize.iHeight-2),iWinSize.iWidth,TRgb::Gray4(1)); sl@0: DrawAndCheckLine(TPoint(iWinSize.iWidth-1,iWinSize.iHeight-1),1,TRgb::Gray4(2)); sl@0: ClearOutRedraws(); sl@0: TheClient->iWs.SetAutoFlush(EFalse); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0213 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Draw line on every line of a window and sl@0: check them by scanning the lines sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Draw lines on every line of a window and sl@0: check them by scanning the lines sl@0: sl@0: @SYMTestExpectedResults Scanning the lines reveals they have been drawn correctly sl@0: */ sl@0: sl@0: case 2: sl@0: { sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0213")); sl@0: iTest->LogSubTest(_L("Full window")); sl@0: for(TInt ypos=0;yposSetTestStepID(_L("GRAPHICS-WSERV-0214")); sl@0: iTest->LogSubTest(_L("Check Rect")); sl@0: TestCheckRect(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0215 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Test that the GetScanLine method panics correctly sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Cause the GetScanLine method to panic and chekc the response sl@0: sl@0: @SYMTestExpectedResults The panic for the GetScanLine method is correct sl@0: */ sl@0: case 4: sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0215")); sl@0: iTest->LogSubTest(_L("Panic")); sl@0: TestPanicsL(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0216 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Test that CPalette class functions correctly sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Create a CPalette object and exercise all its methods sl@0: sl@0: @SYMTestExpectedResults The palette functions as exepcted sl@0: */ sl@0: case 5: sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0216")); sl@0: iTest->LogSubTest(_L("Palette Test")); sl@0: PaletteTestL(); sl@0: break; sl@0: case 6: sl@0: ((CTGetPixelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTGetPixelStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTGetPixelStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: __WS_CONSTRUCT_STEP__(GetPixel)