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.
14 // Test the window server bitmap class
15 // Test the window server bitmap class
22 @internalComponent - Internal Symbian test code
29 CTBitmap::CTBitmap(CTestStep* aStep):
30 CTWsGraphicsBase(aStep)
40 void CTBitmap::ConstructL()
44 void CTBitmap::BasicTestsL()
46 iBitmap1=new(ELeave) CWsBitmap(TheClient->iWs);
47 iBitmap2=new(ELeave) CWsBitmap(TheClient->iWs);
48 User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
49 // Re-create should close previous Create
50 User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
51 User::LeaveIfError(iBitmap2->Duplicate(iBitmap1->Handle()));
52 TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
54 TInt err=iBitmap2->Load(_L("NOTEXIST.XXX"),0);
55 TEST(err==KErrNotFound || err==KErrPathNotFound);
56 if (err!=KErrNotFound && err!=KErrPathNotFound)
57 INFO_PRINTF4(_L("Bitmap2->Load(_L(NOTEXIST.XXX),0) return value - Expected: %d or %d , Actual: %d"), KErrNotFound, KErrPathNotFound, err);
59 TInt retVal = iBitmap2->Handle();
62 INFO_PRINTF3(_L("iBitmap2->Handle() return value - Expected: %d , Actual: %d"), 0, retVal);
65 User::LeaveIfError(fs.Connect());
66 fs.SetNotifyUser(EFalse);
67 TInt ret=fs.MkDir(SAVE_BITMAP_NAME);
68 if (ret!=KErrNone && ret!=KErrAlreadyExists && ret!=KErrPathNotFound)
72 retVal = iBitmap1->Save(SAVE_BITMAP_NAME);
73 TEST(retVal==KErrNone);
75 INFO_PRINTF3(_L("iBitmap1->Save(SAVE_BITMAP_NAME) return value - Expected: %d , Actual: %d"), KErrNone, retVal);
77 retVal = iBitmap2->Load(SAVE_BITMAP_NAME,0);
78 TEST(retVal==KErrNone);
80 INFO_PRINTF3(_L("iBitmap2->Load(SAVE_BITMAP_NAME,0) return value - Expected: %d , Actual: %d"), KErrNone, retVal);
82 TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
86 void CTBitmap::TestFixForPDEF098889L()
88 TRequestStatus status;
90 params.iScreenNr = TheClient->iWs.GetFocusScreen();
93 params.iFunction = Function1PDEF098889L;
94 TEST(thread1.Create(_L("PDEF098889_1"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone);
95 thread1.Logon(status);
97 User::WaitForRequest(status);
98 TEST(status==KErrNone);
99 TEST(thread1.ExitType()==EExitKill);
103 params.iFunction = Function2PDEF098889L;
104 TEST(thread2.Create(_L("PDEF098889_2"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone);
105 thread2.Logon(status);
107 User::WaitForRequest(status);
108 TEST(status==KErrNone);
109 TEST(thread2.ExitType()==EExitKill);
113 TInt CTBitmap::ThreadFunction(TAny* aParams)
115 CTrapCleanup *trap = CTrapCleanup::New();
116 __ASSERT_ALWAYS(trap, User::Invariant());
118 TInt err = session.Connect();
121 CWsScreenDevice *device = new CWsScreenDevice(session);
124 err = device->Construct(static_cast<TThreadParams*>(aParams)->iScreenNr);
127 TRAP(err, static_cast<TThreadParams*>(aParams)->iFunction(session, *device));
139 void CTBitmap::Function1PDEF098889L(RWsSession& aSession, CWsScreenDevice& aDevice)
142 User::LeaveIfError(aDevice.CreateContext(gc));
143 CleanupStack::PushL(gc);
144 RWindowGroup group(aSession);
145 User::LeaveIfError(group.Construct(1, EFalse));
146 CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
147 CleanupStack::PushL(bitmap);
148 User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
149 RWindow window(aSession);
150 User::LeaveIfError(window.Construct(group, 2));
151 window.SetExtent(TPoint(0,0), TSize(32, 32));
152 User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
154 window.BeginRedraw();
155 gc->Activate(window);
156 gc->BitBlt(TPoint(0, 0), bitmap);
159 CleanupStack::PopAndDestroy(bitmap);
161 CleanupStack::PopAndDestroy(gc);
164 void CTBitmap::Function2PDEF098889L(RWsSession& aSession, CWsScreenDevice& /*aDevice*/)
166 RWindowGroup group(aSession);
167 User::LeaveIfError(group.Construct(1, EFalse));
168 CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
169 CleanupStack::PushL(bitmap);
170 User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
171 RWindow window(aSession);
172 User::LeaveIfError(window.Construct(group, 2));
173 window.SetExtent(TPoint(0,0), TSize(32, 32));
174 User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
175 User::LeaveIfError(window.SetTransparencyWsBitmap(*bitmap));
177 CleanupStack::PopAndDestroy(bitmap);
181 void CTBitmap::RunTestCaseL(TInt /*aCurTestCase*/)
183 ((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
184 switch(++iTest->iState)
187 @SYMTestCaseID GRAPHICS-WSERV-0201
191 @SYMTestCaseDesc Test basic bitmap functionality
193 @SYMTestPriority High
195 @SYMTestStatus Implemented
197 @SYMTestActions Test that bitmaps can be loaded, copied and saved
200 @SYMTestExpectedResults The bitmaps are manipulated withotu error
203 ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0201"));
204 iTest->LogSubTest(_L("Bitmap1"));
209 @SYMTestCaseID GRAPHICS-WSERV-0532
211 ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0532"));
212 if (TransparencySupportedL()==KErrNotSupported)
214 iTest->LogSubTest(_L("Test fix for PDEF098889"));
215 TestFixForPDEF098889L();
218 ((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
219 ((CTBitmapStep*)iStep)->CloseTMSGraphicsStep();
223 ((CTBitmapStep*)iStep)->RecordTestResultL();
226 __WS_CONSTRUCT_STEP__(Bitmap)