1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TBITMAP.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,226 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Test the window server bitmap class
1.18 +// Test the window server bitmap class
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file
1.24 + @test
1.25 + @internalComponent - Internal Symbian test code
1.26 +*/
1.27 +
1.28 +#include "TBITMAP.H"
1.29 +
1.30 +//
1.31 +
1.32 +CTBitmap::CTBitmap(CTestStep* aStep):
1.33 + CTWsGraphicsBase(aStep)
1.34 + {
1.35 + }
1.36 +
1.37 +CTBitmap::~CTBitmap()
1.38 + {
1.39 + delete iBitmap1;
1.40 + delete iBitmap2;
1.41 + }
1.42 +
1.43 +void CTBitmap::ConstructL()
1.44 + {
1.45 + }
1.46 +
1.47 +void CTBitmap::BasicTestsL()
1.48 + {
1.49 + iBitmap1=new(ELeave) CWsBitmap(TheClient->iWs);
1.50 + iBitmap2=new(ELeave) CWsBitmap(TheClient->iWs);
1.51 + User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
1.52 +// Re-create should close previous Create
1.53 + User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
1.54 + User::LeaveIfError(iBitmap2->Duplicate(iBitmap1->Handle()));
1.55 + TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
1.56 +
1.57 + TInt err=iBitmap2->Load(_L("NOTEXIST.XXX"),0);
1.58 + TEST(err==KErrNotFound || err==KErrPathNotFound);
1.59 + if (err!=KErrNotFound && err!=KErrPathNotFound)
1.60 + INFO_PRINTF4(_L("Bitmap2->Load(_L(NOTEXIST.XXX),0) return value - Expected: %d or %d , Actual: %d"), KErrNotFound, KErrPathNotFound, err);
1.61 +
1.62 + TInt retVal = iBitmap2->Handle();
1.63 + TEST(retVal==0);
1.64 + if (retVal!=0)
1.65 + INFO_PRINTF3(_L("iBitmap2->Handle() return value - Expected: %d , Actual: %d"), 0, retVal);
1.66 +
1.67 + RFs fs;
1.68 + User::LeaveIfError(fs.Connect());
1.69 + fs.SetNotifyUser(EFalse);
1.70 + TInt ret=fs.MkDir(SAVE_BITMAP_NAME);
1.71 + if (ret!=KErrNone && ret!=KErrAlreadyExists && ret!=KErrPathNotFound)
1.72 + User::Leave(ret);
1.73 + fs.Close();
1.74 +//
1.75 + retVal = iBitmap1->Save(SAVE_BITMAP_NAME);
1.76 + TEST(retVal==KErrNone);
1.77 + if (retVal!=KErrNone)
1.78 + INFO_PRINTF3(_L("iBitmap1->Save(SAVE_BITMAP_NAME) return value - Expected: %d , Actual: %d"), KErrNone, retVal);
1.79 +
1.80 + retVal = iBitmap2->Load(SAVE_BITMAP_NAME,0);
1.81 + TEST(retVal==KErrNone);
1.82 + if (retVal!=KErrNone)
1.83 + INFO_PRINTF3(_L("iBitmap2->Load(SAVE_BITMAP_NAME,0) return value - Expected: %d , Actual: %d"), KErrNone, retVal);
1.84 +
1.85 + TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
1.86 + }
1.87 +
1.88 +
1.89 +void CTBitmap::TestFixForPDEF098889L()
1.90 + {
1.91 + TRequestStatus status;
1.92 + TThreadParams params;
1.93 + params.iScreenNr = TheClient->iWs.GetFocusScreen();
1.94 +
1.95 + RThread thread1;
1.96 + params.iFunction = Function1PDEF098889L;
1.97 + TEST(thread1.Create(_L("PDEF098889_1"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone);
1.98 + thread1.Logon(status);
1.99 + thread1.Resume();
1.100 + User::WaitForRequest(status);
1.101 + TEST(status==KErrNone);
1.102 + TEST(thread1.ExitType()==EExitKill);
1.103 + thread1.Close();
1.104 +
1.105 + RThread thread2;
1.106 + params.iFunction = Function2PDEF098889L;
1.107 + TEST(thread2.Create(_L("PDEF098889_2"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone);
1.108 + thread2.Logon(status);
1.109 + thread2.Resume();
1.110 + User::WaitForRequest(status);
1.111 + TEST(status==KErrNone);
1.112 + TEST(thread2.ExitType()==EExitKill);
1.113 + thread2.Close();
1.114 + }
1.115 +
1.116 +TInt CTBitmap::ThreadFunction(TAny* aParams)
1.117 + {
1.118 + CTrapCleanup *trap = CTrapCleanup::New();
1.119 + __ASSERT_ALWAYS(trap, User::Invariant());
1.120 + RWsSession session;
1.121 + TInt err = session.Connect();
1.122 + if (err == KErrNone)
1.123 + {
1.124 + CWsScreenDevice *device = new CWsScreenDevice(session);
1.125 + if (device)
1.126 + {
1.127 + err = device->Construct(static_cast<TThreadParams*>(aParams)->iScreenNr);
1.128 + if (err == KErrNone)
1.129 + {
1.130 + TRAP(err, static_cast<TThreadParams*>(aParams)->iFunction(session, *device));
1.131 + }
1.132 + delete device;
1.133 + }
1.134 + else
1.135 + err = KErrNoMemory;
1.136 + session.Close();
1.137 + }
1.138 + delete trap;
1.139 + return err;
1.140 + }
1.141 +
1.142 +void CTBitmap::Function1PDEF098889L(RWsSession& aSession, CWsScreenDevice& aDevice)
1.143 + {
1.144 + CWindowGc *gc;
1.145 + User::LeaveIfError(aDevice.CreateContext(gc));
1.146 + CleanupStack::PushL(gc);
1.147 + RWindowGroup group(aSession);
1.148 + User::LeaveIfError(group.Construct(1, EFalse));
1.149 + CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
1.150 + CleanupStack::PushL(bitmap);
1.151 + User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
1.152 + RWindow window(aSession);
1.153 + User::LeaveIfError(window.Construct(group, 2));
1.154 + window.SetExtent(TPoint(0,0), TSize(32, 32));
1.155 + User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
1.156 + window.Activate();
1.157 + window.BeginRedraw();
1.158 + gc->Activate(window);
1.159 + gc->BitBlt(TPoint(0, 0), bitmap);
1.160 + gc->Deactivate();
1.161 + window.EndRedraw();
1.162 + CleanupStack::PopAndDestroy(bitmap);
1.163 + aSession.Flush();
1.164 + CleanupStack::PopAndDestroy(gc);
1.165 + }
1.166 +
1.167 +void CTBitmap::Function2PDEF098889L(RWsSession& aSession, CWsScreenDevice& /*aDevice*/)
1.168 + {
1.169 + RWindowGroup group(aSession);
1.170 + User::LeaveIfError(group.Construct(1, EFalse));
1.171 + CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
1.172 + CleanupStack::PushL(bitmap);
1.173 + User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
1.174 + RWindow window(aSession);
1.175 + User::LeaveIfError(window.Construct(group, 2));
1.176 + window.SetExtent(TPoint(0,0), TSize(32, 32));
1.177 + User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
1.178 + User::LeaveIfError(window.SetTransparencyWsBitmap(*bitmap));
1.179 + window.Activate();
1.180 + CleanupStack::PopAndDestroy(bitmap);
1.181 + aSession.Flush();
1.182 + }
1.183 +
1.184 +void CTBitmap::RunTestCaseL(TInt /*aCurTestCase*/)
1.185 + {
1.186 + ((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.187 + switch(++iTest->iState)
1.188 + {
1.189 +/**
1.190 +@SYMTestCaseID GRAPHICS-WSERV-0201
1.191 +
1.192 +@SYMDEF DEF081259
1.193 +
1.194 +@SYMTestCaseDesc Test basic bitmap functionality
1.195 +
1.196 +@SYMTestPriority High
1.197 +
1.198 +@SYMTestStatus Implemented
1.199 +
1.200 +@SYMTestActions Test that bitmaps can be loaded, copied and saved
1.201 + correctly
1.202 +
1.203 +@SYMTestExpectedResults The bitmaps are manipulated withotu error
1.204 +*/
1.205 + case 1:
1.206 + ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0201"));
1.207 + iTest->LogSubTest(_L("Bitmap1"));
1.208 + BasicTestsL();
1.209 + break;
1.210 + case 2:
1.211 +/**
1.212 +@SYMTestCaseID GRAPHICS-WSERV-0532
1.213 +*/
1.214 + ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0532"));
1.215 + if (TransparencySupportedL()==KErrNotSupported)
1.216 + return;
1.217 + iTest->LogSubTest(_L("Test fix for PDEF098889"));
1.218 + TestFixForPDEF098889L();
1.219 + break;
1.220 + default:
1.221 + ((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.222 + ((CTBitmapStep*)iStep)->CloseTMSGraphicsStep();
1.223 + TestComplete();
1.224 + break;
1.225 + }
1.226 + ((CTBitmapStep*)iStep)->RecordTestResultL();
1.227 + }
1.228 +
1.229 +__WS_CONSTRUCT_STEP__(Bitmap)