|
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 // Test the window server bitmap class |
|
15 // Test the window server bitmap class |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include "TBITMAP.H" |
|
26 |
|
27 // |
|
28 |
|
29 CTBitmap::CTBitmap(CTestStep* aStep): |
|
30 CTWsGraphicsBase(aStep) |
|
31 { |
|
32 } |
|
33 |
|
34 CTBitmap::~CTBitmap() |
|
35 { |
|
36 delete iBitmap1; |
|
37 delete iBitmap2; |
|
38 } |
|
39 |
|
40 void CTBitmap::ConstructL() |
|
41 { |
|
42 } |
|
43 |
|
44 void CTBitmap::BasicTestsL() |
|
45 { |
|
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()); |
|
53 |
|
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); |
|
58 |
|
59 TInt retVal = iBitmap2->Handle(); |
|
60 TEST(retVal==0); |
|
61 if (retVal!=0) |
|
62 INFO_PRINTF3(_L("iBitmap2->Handle() return value - Expected: %d , Actual: %d"), 0, retVal); |
|
63 |
|
64 RFs fs; |
|
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) |
|
69 User::Leave(ret); |
|
70 fs.Close(); |
|
71 // |
|
72 retVal = iBitmap1->Save(SAVE_BITMAP_NAME); |
|
73 TEST(retVal==KErrNone); |
|
74 if (retVal!=KErrNone) |
|
75 INFO_PRINTF3(_L("iBitmap1->Save(SAVE_BITMAP_NAME) return value - Expected: %d , Actual: %d"), KErrNone, retVal); |
|
76 |
|
77 retVal = iBitmap2->Load(SAVE_BITMAP_NAME,0); |
|
78 TEST(retVal==KErrNone); |
|
79 if (retVal!=KErrNone) |
|
80 INFO_PRINTF3(_L("iBitmap2->Load(SAVE_BITMAP_NAME,0) return value - Expected: %d , Actual: %d"), KErrNone, retVal); |
|
81 |
|
82 TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels()); |
|
83 } |
|
84 |
|
85 |
|
86 void CTBitmap::TestFixForPDEF098889L() |
|
87 { |
|
88 TRequestStatus status; |
|
89 TThreadParams params; |
|
90 params.iScreenNr = TheClient->iWs.GetFocusScreen(); |
|
91 |
|
92 RThread thread1; |
|
93 params.iFunction = Function1PDEF098889L; |
|
94 TEST(thread1.Create(_L("PDEF098889_1"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone); |
|
95 thread1.Logon(status); |
|
96 thread1.Resume(); |
|
97 User::WaitForRequest(status); |
|
98 TEST(status==KErrNone); |
|
99 TEST(thread1.ExitType()==EExitKill); |
|
100 thread1.Close(); |
|
101 |
|
102 RThread thread2; |
|
103 params.iFunction = Function2PDEF098889L; |
|
104 TEST(thread2.Create(_L("PDEF098889_2"), ThreadFunction, 0x1000, NULL, ¶ms)==KErrNone); |
|
105 thread2.Logon(status); |
|
106 thread2.Resume(); |
|
107 User::WaitForRequest(status); |
|
108 TEST(status==KErrNone); |
|
109 TEST(thread2.ExitType()==EExitKill); |
|
110 thread2.Close(); |
|
111 } |
|
112 |
|
113 TInt CTBitmap::ThreadFunction(TAny* aParams) |
|
114 { |
|
115 CTrapCleanup *trap = CTrapCleanup::New(); |
|
116 __ASSERT_ALWAYS(trap, User::Invariant()); |
|
117 RWsSession session; |
|
118 TInt err = session.Connect(); |
|
119 if (err == KErrNone) |
|
120 { |
|
121 CWsScreenDevice *device = new CWsScreenDevice(session); |
|
122 if (device) |
|
123 { |
|
124 err = device->Construct(static_cast<TThreadParams*>(aParams)->iScreenNr); |
|
125 if (err == KErrNone) |
|
126 { |
|
127 TRAP(err, static_cast<TThreadParams*>(aParams)->iFunction(session, *device)); |
|
128 } |
|
129 delete device; |
|
130 } |
|
131 else |
|
132 err = KErrNoMemory; |
|
133 session.Close(); |
|
134 } |
|
135 delete trap; |
|
136 return err; |
|
137 } |
|
138 |
|
139 void CTBitmap::Function1PDEF098889L(RWsSession& aSession, CWsScreenDevice& aDevice) |
|
140 { |
|
141 CWindowGc *gc; |
|
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)); |
|
153 window.Activate(); |
|
154 window.BeginRedraw(); |
|
155 gc->Activate(window); |
|
156 gc->BitBlt(TPoint(0, 0), bitmap); |
|
157 gc->Deactivate(); |
|
158 window.EndRedraw(); |
|
159 CleanupStack::PopAndDestroy(bitmap); |
|
160 aSession.Flush(); |
|
161 CleanupStack::PopAndDestroy(gc); |
|
162 } |
|
163 |
|
164 void CTBitmap::Function2PDEF098889L(RWsSession& aSession, CWsScreenDevice& /*aDevice*/) |
|
165 { |
|
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)); |
|
176 window.Activate(); |
|
177 CleanupStack::PopAndDestroy(bitmap); |
|
178 aSession.Flush(); |
|
179 } |
|
180 |
|
181 void CTBitmap::RunTestCaseL(TInt /*aCurTestCase*/) |
|
182 { |
|
183 ((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
184 switch(++iTest->iState) |
|
185 { |
|
186 /** |
|
187 @SYMTestCaseID GRAPHICS-WSERV-0201 |
|
188 |
|
189 @SYMDEF DEF081259 |
|
190 |
|
191 @SYMTestCaseDesc Test basic bitmap functionality |
|
192 |
|
193 @SYMTestPriority High |
|
194 |
|
195 @SYMTestStatus Implemented |
|
196 |
|
197 @SYMTestActions Test that bitmaps can be loaded, copied and saved |
|
198 correctly |
|
199 |
|
200 @SYMTestExpectedResults The bitmaps are manipulated withotu error |
|
201 */ |
|
202 case 1: |
|
203 ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0201")); |
|
204 iTest->LogSubTest(_L("Bitmap1")); |
|
205 BasicTestsL(); |
|
206 break; |
|
207 case 2: |
|
208 /** |
|
209 @SYMTestCaseID GRAPHICS-WSERV-0532 |
|
210 */ |
|
211 ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0532")); |
|
212 if (TransparencySupportedL()==KErrNotSupported) |
|
213 return; |
|
214 iTest->LogSubTest(_L("Test fix for PDEF098889")); |
|
215 TestFixForPDEF098889L(); |
|
216 break; |
|
217 default: |
|
218 ((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
219 ((CTBitmapStep*)iStep)->CloseTMSGraphicsStep(); |
|
220 TestComplete(); |
|
221 break; |
|
222 } |
|
223 ((CTBitmapStep*)iStep)->RecordTestResultL(); |
|
224 } |
|
225 |
|
226 __WS_CONSTRUCT_STEP__(Bitmap) |