|
1 // Copyright (c) 2008-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 // @file |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32math.h> |
|
20 #include <w32std.h> |
|
21 #include <w32debug.h> |
|
22 #include <e32base.h> |
|
23 #include "teflogextensions.h" |
|
24 #include "globalsettings.h" |
|
25 #include "CWsGceCscBase.h" |
|
26 #include <bitdraw.h> |
|
27 #include <bitdrawinterfaceid.h> |
|
28 #include <imageconversion.h> |
|
29 #include <test/tefunit.h> |
|
30 |
|
31 |
|
32 CWsGceCscBase::CWsGceCscBase(): |
|
33 iDoTearDown(EFalse), |
|
34 iUtility(this, NULL) |
|
35 { |
|
36 } |
|
37 |
|
38 CWsGceCscBase::~CWsGceCscBase() |
|
39 { |
|
40 if (iDoTearDown) |
|
41 TearDownFromDeleteL(); //This mechanism is not entirely clean to use. |
|
42 } |
|
43 |
|
44 void CWsGceCscBase::SetupL() |
|
45 { |
|
46 iDoTearDown=ETrue; |
|
47 iRed.SetInternal(0xFFFF0000); |
|
48 iGreen.SetInternal(0xFF00FF00); |
|
49 iBlue.SetInternal(0xFF0000FF); |
|
50 iCyan.SetInternal(0xFF00FFFF); |
|
51 iMagenta.SetInternal(0xFFFF00FF); |
|
52 iYellow.SetInternal(0xFFFFFF00); |
|
53 iWhite.SetInternal(0xFFFFFFFF); |
|
54 |
|
55 ASSERT_EQUALS_X(iSession.Connect(), KErrNone); |
|
56 |
|
57 {//Stolen from TAuto CloseAllPanicWindows() |
|
58 TInt idFocus = iSession.GetFocusWindowGroup(); |
|
59 TWsEvent event; |
|
60 event.SetType(EEventKey); //EEventKeyDown |
|
61 TKeyEvent *keyEvent = event.Key(); |
|
62 keyEvent->iCode = EKeyEscape; |
|
63 keyEvent->iScanCode = EStdKeyEscape; |
|
64 keyEvent->iModifiers = 0; |
|
65 TInt theLimit = 50; |
|
66 while(idFocus != NULL && (theLimit-- > 0)) |
|
67 { |
|
68 iSession.SendEventToAllWindowGroups(event); |
|
69 TInt idNewFocus = iSession.GetFocusWindowGroup(); |
|
70 if (idNewFocus!=idFocus) |
|
71 { |
|
72 INFO_PRINTF1(_L("A window was closed [probably a panic box from the previous test].")); |
|
73 } |
|
74 idFocus=idNewFocus; |
|
75 } |
|
76 } |
|
77 TInt err = KErrNone; |
|
78 |
|
79 TRAP(err, iScreenDevice = new (ELeave) CWsScreenDevice(iSession)); |
|
80 PRINT_ON_ERROR2_L(err, _L("Failed to create screen device: %d"), err); |
|
81 ASSERT_EQUALS_X(iScreenDevice->Construct(TGlobalSettings::Instance().iScreen), KErrNone); |
|
82 iDisplayMode = iScreenDevice->DisplayMode(); // Get default display mode |
|
83 |
|
84 TRAP(err, iGc = new (ELeave) CWindowGc(iScreenDevice)); |
|
85 PRINT_ON_ERROR2_L(err, _L("Failed to create graphics context: %d"), err); |
|
86 ASSERT_EQUALS_X(iGc->Construct(), KErrNone); |
|
87 |
|
88 iGroup = RWindowGroup(iSession); |
|
89 ASSERT_EQUALS_X(iGroup.Construct(++iWindowHandle,iScreenDevice), KErrNone); |
|
90 iSession.Flush(); |
|
91 |
|
92 RWindow testTrans(iSession); |
|
93 ASSERT_EQUALS_X(testTrans.Construct(iGroup, ++iWindowHandle), KErrNone); |
|
94 iTransparencyEnabled=(testTrans.SetTransparencyFactor(iWhite)==KErrNone); |
|
95 testTrans.Close(); |
|
96 |
|
97 //clean-up if previous test abended |
|
98 if (PostTestCleanupInstance().iSharedUtility) |
|
99 { |
|
100 //Temp removed - may be causing ONB fails! |
|
101 // if (PostTestCleanupInstance().iSharedUtility->DestroyAll()) |
|
102 // { |
|
103 // INFO_PRINTF1(_L("Destroyed some surfaces from previous test.")); |
|
104 // |
|
105 // } |
|
106 } |
|
107 if (!PostTestCleanupInstance().iCleanedUpOnExit) |
|
108 PostTestCleanupInstance().iCleanedUpOnExit=EFalse; |
|
109 |
|
110 if (!GCEIsSupported()) |
|
111 { |
|
112 INFO_PRINTF1(_L("Some Setup skipped: GCE support is not loaded")); |
|
113 return; |
|
114 } |
|
115 |
|
116 TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( PostTestCleanupInstance().iSharedUtility)); |
|
117 ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone); |
|
118 |
|
119 } |
|
120 |
|
121 void CWsGceCscBase::TearDownL() |
|
122 { |
|
123 iDoTearDown=EFalse; |
|
124 delete iGc; |
|
125 delete iScreenDevice; |
|
126 |
|
127 iGroup.Close(); |
|
128 iSession.Flush(); |
|
129 iSession.Close(); |
|
130 |
|
131 delete iUtility(); |
|
132 PostTestCleanupInstance().iCleanedUpOnExit=ETrue; |
|
133 Pause(1000); |
|
134 } |
|
135 |
|
136 void CWsGceCscBase::TearDownFromDeleteL() |
|
137 { |
|
138 CWsGceCscBase::TearDownL(); |
|
139 } |
|
140 |
|
141 void CWsGceCscBase::Pause(TInt aMilliseconds) |
|
142 { |
|
143 User::After(TTimeIntervalMicroSeconds32(aMilliseconds * 1000)); |
|
144 } |
|
145 |
|
146 /** Test using an indipendent method that GCE version of WServ is running |
|
147 * This method can only be called after the testcase is started |
|
148 * |
|
149 * @return true if WServ version is GCE technology, false if legacy technology |
|
150 **/ |
|
151 TBool CWsGceCscBase::GCEIsSupported() const |
|
152 { |
|
153 CFbsDrawDevice* screenDevice=NULL; |
|
154 TDisplayMode displayMode=iScreenDevice->DisplayMode(); |
|
155 TRAPD(err, screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode)); |
|
156 TBool rv=EFalse; |
|
157 if(err == KErrNone) |
|
158 { |
|
159 TAny* p=NULL; |
|
160 rv=(screenDevice->GetInterface(KSurfaceInterfaceID, p)==KErrNone); |
|
161 delete screenDevice; |
|
162 } |
|
163 return rv; |
|
164 } |
|
165 /** Test using an indipendent method that GCE version of WServ is running |
|
166 * This method can be called at any time, even by external code, but creates temporary window session objects |
|
167 * |
|
168 * @return true if WServ version is GCE technology, false if legacy technology |
|
169 **/ |
|
170 TBool CWsGceCscBase::GCEIsSupportedStatic() |
|
171 { |
|
172 CFbsDrawDevice* screenDevice=NULL; |
|
173 RWsSession session; |
|
174 if (session.Connect()!=KErrNone) |
|
175 { |
|
176 return EFalse; |
|
177 } |
|
178 CWsScreenDevice screen(session); |
|
179 if (screen.Construct(TGlobalSettings::Instance().iScreen)!=KErrNone) |
|
180 { |
|
181 return EFalse; |
|
182 } |
|
183 |
|
184 TDisplayMode displayMode=screen.DisplayMode(); |
|
185 TRAPD(err, screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode)); |
|
186 TBool rv=EFalse; |
|
187 if(err == KErrNone) |
|
188 { |
|
189 TAny* p=NULL; |
|
190 rv=(screenDevice->GetInterface(KSurfaceInterfaceID, p)==KErrNone); |
|
191 delete screenDevice; |
|
192 } |
|
193 return rv; |
|
194 } |
|
195 |
|
196 //Allocating an instance of surface utility here means all test code instances will share the same instance of the utility class. |
|
197 // Owns the singleton |
|
198 CWsGceCscBase::TPostTestCleanup& CWsGceCscBase::PostTestCleanupInstance() |
|
199 { |
|
200 static |
|
201 class RPostTestCleanup:public TPostTestCleanup |
|
202 { |
|
203 public: |
|
204 RPostTestCleanup() |
|
205 { |
|
206 iSharedUtility=NULL; |
|
207 iCleanedUpOnExit=ETrue; |
|
208 } |
|
209 ~RPostTestCleanup() |
|
210 { |
|
211 // I want to cleanly release the surface utility, but at this point the threads have already been pulled down! |
|
212 // if (iSharedUtility) |
|
213 // delete iSharedUtility; |
|
214 iSharedUtility=NULL; //avoid phoenix behaviour |
|
215 } |
|
216 } staticInstance; |
|
217 return staticInstance; |
|
218 } |
|
219 |
|
220 // This handles any non-member uses of the extended ASSERT_XXX macros |
|
221 extern void TefUnitFailLeaveL(); |
|
222 /** |
|
223 * side-effect: log the state info just before I leave! |
|
224 * Note that this only logs intentional assertion failures. |
|
225 * Fails due to panics or throws won't log this info. |
|
226 **/ |
|
227 void CWsGceCscBase::TefUnitFailLeaveL() |
|
228 { |
|
229 for (TInt line=0;line<KMaxInfoLines;line++) |
|
230 if (iTestInfo[line].Length()) |
|
231 Logger().LogExtra((TText8*)"Test state at fail - line",line, ESevrAll, iTestInfo[line]); |
|
232 TGlobalSettings::Instance().Report(Logger()); |
|
233 |
|
234 User::Leave(KErrTEFUnitFail); |
|
235 } |
|
236 |
|
237 TInt CWsGceCscBase::DebugInfo(TWsDebugInfoFunc aFunction, |
|
238 TInt aParam, |
|
239 TDes8& aHostBuffer, |
|
240 const void*&aReturnedObject, |
|
241 TInt aObjectSize)const |
|
242 { |
|
243 TInt reqSize=iSession.DebugInfo(aFunction,aHostBuffer,aParam); |
|
244 aReturnedObject=NULL; |
|
245 if (reqSize<0) |
|
246 { |
|
247 if ((reqSize%aObjectSize)!=0) |
|
248 { |
|
249 return KErrCorrupt; |
|
250 } |
|
251 else |
|
252 { |
|
253 return reqSize; |
|
254 } |
|
255 } |
|
256 if (reqSize>aHostBuffer.MaxLength()) |
|
257 { |
|
258 return reqSize/aObjectSize; |
|
259 } |
|
260 if (reqSize==0) |
|
261 { |
|
262 reqSize=aHostBuffer.MaxLength(); |
|
263 } |
|
264 if ((reqSize%aObjectSize)!=0) |
|
265 { |
|
266 return KErrCorrupt; |
|
267 } |
|
268 aReturnedObject=(const void*)aHostBuffer.Ptr(); |
|
269 reqSize/=aObjectSize; |
|
270 return reqSize; |
|
271 } |
|
272 |
|
273 void CWsGceCscBase::SetCompositionMode(RWindow& aWindow, TDisplayMode aMode) |
|
274 { |
|
275 iDisplayMode = (TDisplayMode)aWindow.SetRequiredDisplayMode(aMode); |
|
276 aWindow.Invalidate(); |
|
277 aWindow.BeginRedraw(); |
|
278 aWindow.EndRedraw(); |
|
279 } |
|
280 |
|
281 TBool CWsGceCscBase::Compare(CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2) |
|
282 { |
|
283 if ((aBitmap1.SizeInPixels() == aBitmap2.SizeInPixels()) && |
|
284 (aBitmap1.DisplayMode() == aBitmap2.DisplayMode())) |
|
285 { |
|
286 TSize size = aBitmap1.SizeInPixels(); |
|
287 TInt width = size.iWidth; |
|
288 TInt height = size.iHeight; |
|
289 TRgb color1, color2; |
|
290 |
|
291 for (TInt i = 0; i < width; i++) |
|
292 { |
|
293 for (TInt j = 0; j < height; j++) |
|
294 { |
|
295 aBitmap1.GetPixel(color1, TPoint(i, j)); |
|
296 aBitmap2.GetPixel(color2, TPoint(i, j)); |
|
297 if (color1 != color2) |
|
298 { |
|
299 return EFalse; |
|
300 } |
|
301 } |
|
302 } |
|
303 |
|
304 return ETrue; |
|
305 } |
|
306 return EFalse; |
|
307 } |
|
308 |
|
309 void CWsGceCscBase::ConstructOpaqueWindowL(RWindow& aWindow, |
|
310 const TRgb& aColor, |
|
311 TInt aPos, |
|
312 const TPoint &aPoint, |
|
313 const TSize &aSize) |
|
314 { |
|
315 ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone); |
|
316 aWindow.SetRequiredDisplayMode(iDisplayMode); |
|
317 aWindow.SetExtent(aPoint, aSize); |
|
318 aWindow.SetBackgroundColor(aColor); |
|
319 aWindow.SetOrdinalPosition(aPos); |
|
320 aWindow.Activate(); |
|
321 aWindow.BeginRedraw(); |
|
322 iGc->Activate(aWindow); |
|
323 iGc->Deactivate(); |
|
324 aWindow.EndRedraw(); |
|
325 } |
|
326 |
|
327 void CWsGceCscBase::ConstructOpaqueWindowLC(RWindow& aWindow, |
|
328 const TRgb& aColor, |
|
329 TInt aPos, |
|
330 const TPoint &aPoint, |
|
331 const TSize &aSize) |
|
332 { |
|
333 ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone); |
|
334 CleanupClosePushL(aWindow); |
|
335 aWindow.SetRequiredDisplayMode(iDisplayMode); |
|
336 aWindow.SetExtent(aPoint, aSize); |
|
337 aWindow.SetBackgroundColor(aColor); |
|
338 aWindow.SetOrdinalPosition(aPos); |
|
339 aWindow.SetVisible(ETrue); |
|
340 aWindow.Activate(); |
|
341 aWindow.BeginRedraw(); |
|
342 iGc->Activate(aWindow); |
|
343 iGc->Clear(); |
|
344 iGc->Deactivate(); |
|
345 aWindow.EndRedraw(); |
|
346 } |
|
347 |
|
348 |
|
349 void CWsGceCscBase::SetBackgroundColorWindow(RWindow& aWindow, const TRgb& aColor) |
|
350 { |
|
351 aWindow.Invalidate(); |
|
352 aWindow.SetBackgroundColor(aColor); |
|
353 aWindow.BeginRedraw(); |
|
354 iGc->Activate(aWindow); |
|
355 iGc->Deactivate(); |
|
356 aWindow.EndRedraw(); |
|
357 } |
|
358 |
|
359 void CWsGceCscBase::ConstructOpaqueSurfacedWindowLC(RWindow& aWindow, |
|
360 const TRgb& aColor, |
|
361 TInt aPos, |
|
362 const TPoint &aPoint, |
|
363 const TSize &aSize, |
|
364 TSurfaceId& aSurfaceID) |
|
365 { |
|
366 ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone); |
|
367 CleanupClosePushL(aWindow); |
|
368 aWindow.SetRequiredDisplayMode(iDisplayMode); |
|
369 aWindow.SetExtent(aPoint, aSize); |
|
370 aWindow.SetBackgroundColor(aColor); |
|
371 aWindow.SetOrdinalPosition(aPos); |
|
372 ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurfaceID), KErrNone); |
|
373 aWindow.Activate(); |
|
374 aWindow.BeginRedraw(); |
|
375 iGc->Activate(aWindow); |
|
376 iGc->Deactivate(); |
|
377 aWindow.EndRedraw(); |
|
378 } |
|
379 |
|
380 void CWsGceCscBase::ConstructOpaqueSurfacedWindowL(RWindow& aWindow, |
|
381 const TRgb& aColor, |
|
382 TInt aPos, |
|
383 const TPoint& aPoint, |
|
384 const TSize& aSize, |
|
385 const TSurfaceId& aSurfaceID) |
|
386 { |
|
387 ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone); |
|
388 aWindow.SetRequiredDisplayMode(iDisplayMode); |
|
389 aWindow.SetExtent(aPoint, aSize); |
|
390 aWindow.SetBackgroundColor(aColor); |
|
391 aWindow.SetOrdinalPosition(aPos); |
|
392 ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurfaceID), KErrNone); |
|
393 aWindow.Activate(); |
|
394 aWindow.BeginRedraw(); |
|
395 iGc->Activate(aWindow); |
|
396 iGc->Deactivate(); |
|
397 aWindow.EndRedraw(); |
|
398 } |
|
399 |
|
400 |