|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements unit tests for CMusIndicatorApi class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "ut_cmusindicatordsa.h" |
|
21 #include "musindicatordsa.h" |
|
22 #include "mustesthelp.h" |
|
23 #include "e32property.h" |
|
24 |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include <AknGlobalMsgQuery.h> |
|
27 #include <AknsDrawUtils.h> |
|
28 |
|
29 |
|
30 // Next row is to disable warning emerging from EUnit code. |
|
31 #pragma warn_illtokenpasting off |
|
32 |
|
33 const TSize KOriginalSize = TSize( 176, 208 ); |
|
34 const TSize KDifferentSize = TSize( 208, 176 ); |
|
35 |
|
36 static CWindowGc* gc = NULL; |
|
37 static TAny* cc = NULL; |
|
38 static TTimeIntervalMicroSeconds32 delay = 0; |
|
39 static TSize sizeInPixels = KOriginalSize; |
|
40 |
|
41 |
|
42 // ======== stubs ======== |
|
43 |
|
44 |
|
45 void CCoeControl::CreateWindowL() |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 void CCoeControl::ActivateL() |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 void CCoeControl::DrawDeferred() const |
|
56 { |
|
57 } |
|
58 |
|
59 CWindowGc& CCoeControl::SystemGc() const |
|
60 { |
|
61 return *gc; |
|
62 } |
|
63 |
|
64 MWsClientClass::MWsClientClass() |
|
65 { |
|
66 } |
|
67 |
|
68 CWindowGc::CWindowGc(CWsScreenDevice* /*aDevice*/ ) |
|
69 { |
|
70 |
|
71 } |
|
72 |
|
73 CWindowGc::~CWindowGc() |
|
74 { |
|
75 |
|
76 } |
|
77 |
|
78 void CWindowGc::SetBrushStyle( TBrushStyle /*aBrushStyle*/ ) |
|
79 { |
|
80 } |
|
81 |
|
82 void CWindowGc::Clear( const TRect& /*aRect*/ ) |
|
83 { |
|
84 } |
|
85 |
|
86 void CWindowGc::UseFont( const CFont* /*aFont*/ ) |
|
87 { |
|
88 } |
|
89 |
|
90 void CWindowGc::SetPenStyle( TPenStyle /*aPenStyle*/ ) |
|
91 { |
|
92 } |
|
93 |
|
94 void CWindowGc::SetPenColor( const TRgb& /*aColor*/ ) |
|
95 { |
|
96 } |
|
97 |
|
98 void CWindowGc::SetPenSize( const TSize& /*aSize*/ ) |
|
99 { |
|
100 } |
|
101 |
|
102 void CWindowGc::DrawRoundRect( const TRect& /*aRect*/,const TSize& /*aEllipse*/ ) |
|
103 { |
|
104 } |
|
105 |
|
106 void CWindowGc::DrawText( const TDesC& /*aBuf*/,const TPoint& /*aPos*/ ) |
|
107 { |
|
108 } |
|
109 |
|
110 //Cannot stub due it is virtual method. This is not called |
|
111 TSize CWsScreenDevice::SizeInPixels() const |
|
112 { |
|
113 return sizeInPixels; |
|
114 } |
|
115 |
|
116 void CWindowGc::BitBltMasked(const TPoint& /*aPoint*/,const CFbsBitmap* /*aBitmap*/, |
|
117 const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/) |
|
118 { |
|
119 } |
|
120 |
|
121 MAknsControlContext* AknsDrawUtils::ControlContext( const MObjectProvider* /*aMop*/ ) |
|
122 { |
|
123 return static_cast<MAknsControlContext*>( cc ); |
|
124 } |
|
125 |
|
126 TBool AknsDrawUtils::Background( MAknsSkinInstance* /*aInstance*/, |
|
127 MAknsControlContext* /*aContext*/, const CCoeControl* /*aControl*/, |
|
128 CWindowGc& /*aGc*/, const TRect& /*aRect*/, const TInt /*aDrawParam*/ ) |
|
129 { |
|
130 return ETrue; |
|
131 } |
|
132 |
|
133 |
|
134 void CPeriodic::Start(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 /*anInterval*/,TCallBack /*aCallBack*/) |
|
135 { |
|
136 delay = aDelay; |
|
137 After(aDelay); |
|
138 |
|
139 } |
|
140 |
|
141 |
|
142 |
|
143 // ======== MEMBER FUNCTIONS ======== |
|
144 |
|
145 |
|
146 UT_CMusIndicatorDsa* UT_CMusIndicatorDsa::NewL() |
|
147 { |
|
148 UT_CMusIndicatorDsa* self = UT_CMusIndicatorDsa::NewLC(); |
|
149 CleanupStack::Pop( self ); |
|
150 return self; |
|
151 } |
|
152 |
|
153 |
|
154 UT_CMusIndicatorDsa* UT_CMusIndicatorDsa::NewLC() |
|
155 { |
|
156 UT_CMusIndicatorDsa* self = new( ELeave ) UT_CMusIndicatorDsa(); |
|
157 CleanupStack::PushL( self ); |
|
158 self->ConstructL(); |
|
159 return self; |
|
160 } |
|
161 |
|
162 |
|
163 UT_CMusIndicatorDsa::~UT_CMusIndicatorDsa() |
|
164 { |
|
165 } |
|
166 |
|
167 |
|
168 UT_CMusIndicatorDsa::UT_CMusIndicatorDsa() |
|
169 { |
|
170 delete iIndicatorDsa; |
|
171 iIndicatorDsa = NULL; |
|
172 } |
|
173 |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
177 // It generates the test case table. |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void UT_CMusIndicatorDsa::ConstructL() |
|
181 { |
|
182 CEUnitTestSuiteClass::ConstructL(); |
|
183 } |
|
184 |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // Prepares a test for execution. |
|
188 // ---------------------------------------------------------------------------- |
|
189 // |
|
190 void UT_CMusIndicatorDsa::SetupL() |
|
191 { |
|
192 /* NOTE: EUnit reports leak for any first test due AVKON resource reservation, |
|
193 * which is not released by AVKON at end of test. Resource reservation |
|
194 * happend in contruction of CMusIndicatorDsa |
|
195 */ |
|
196 |
|
197 cc = this; |
|
198 iIndicatorDsa = CMusIndicatorDsa::NewL(); |
|
199 if ( !gc ) |
|
200 { |
|
201 gc = new (ELeave) CWindowGc( NULL ); |
|
202 } |
|
203 delay = 0; |
|
204 sizeInPixels = KOriginalSize; |
|
205 |
|
206 } |
|
207 |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // Finalizes a test by releasing used resources. |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 void UT_CMusIndicatorDsa::Teardown() |
|
214 { |
|
215 delete iIndicatorDsa; |
|
216 iIndicatorDsa = NULL; |
|
217 delete gc; |
|
218 gc = NULL; |
|
219 cc = NULL; |
|
220 delay = 0; |
|
221 sizeInPixels = KOriginalSize; |
|
222 PropertyHelper::Close(); |
|
223 |
|
224 } |
|
225 |
|
226 |
|
227 // ======== UNIT TEST METHODS ======== |
|
228 |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // Asserts successful instantiation. |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 |
|
235 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_NewLL() |
|
236 { |
|
237 EUNIT_ASSERT( iIndicatorDsa ); |
|
238 } |
|
239 |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // |
|
243 // ---------------------------------------------------------------------------- |
|
244 // |
|
245 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_DrawL() |
|
246 { |
|
247 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
248 |
|
249 TRect rect; |
|
250 iIndicatorDsa->Draw( rect ); |
|
251 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
252 |
|
253 cc = NULL; |
|
254 iIndicatorDsa->Draw( rect ); |
|
255 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
256 |
|
257 /*size cannot be changed |
|
258 sizeInPixels = KDifferentSize; |
|
259 iIndicatorDsa->Draw( rect ); |
|
260 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
261 */ |
|
262 |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_InitializeL() |
|
270 { |
|
271 iIndicatorDsa->Initialize(); |
|
272 |
|
273 |
|
274 EUNIT_ASSERT( iIndicatorDsa->iTextpos.iX ); |
|
275 EUNIT_ASSERT( iIndicatorDsa->iTextpos.iY ); |
|
276 |
|
277 } |
|
278 |
|
279 |
|
280 // ---------------------------------------------------------------------------- |
|
281 // Asserts that load image is not doing anything if icon is already loaded |
|
282 // ---------------------------------------------------------------------------- |
|
283 // |
|
284 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_LoadImageLL() |
|
285 { |
|
286 CFbsBitmap* icon = iIndicatorDsa->iIcon; |
|
287 CFbsBitmap* iconMask = iIndicatorDsa->iIconMask; |
|
288 EUNIT_ASSERT( icon != NULL ); |
|
289 EUNIT_ASSERT( iconMask != NULL ); |
|
290 iIndicatorDsa->LoadImageL(); |
|
291 |
|
292 EUNIT_ASSERT( icon == iIndicatorDsa->iIcon ); |
|
293 EUNIT_ASSERT( iconMask == iIndicatorDsa->iIconMask ); |
|
294 } |
|
295 |
|
296 |
|
297 // ---------------------------------------------------------------------------- |
|
298 // Asserts successful loading of resource string. |
|
299 // ---------------------------------------------------------------------------- |
|
300 // |
|
301 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_LoadResourceStringLL() |
|
302 { |
|
303 iIndicatorDsa->LoadResourceStringL(); |
|
304 EUNIT_ASSERT( iIndicatorDsa->iText ); |
|
305 EUNIT_ASSERT( iIndicatorDsa->iText->Length() ); |
|
306 } |
|
307 |
|
308 |
|
309 |
|
310 // ---------------------------------------------------------------------------- |
|
311 // Asserts that periodic timer is started after method call. |
|
312 // ---------------------------------------------------------------------------- |
|
313 // |
|
314 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_StartPeriodicTimerL() |
|
315 { |
|
316 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
317 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
318 EUNIT_ASSERT( delay.Int() == 0 ); |
|
319 |
|
320 iIndicatorDsa->StartPeriodicTimer( iIndicatorDsa->iActivateCallBack ); |
|
321 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
322 EUNIT_ASSERT( delay.Int() == KMusIndicatorDelay ); |
|
323 |
|
324 delay = 0; |
|
325 iIndicatorDsa->StartPeriodicTimer( iIndicatorDsa->iActivateCallBack ); |
|
326 EUNIT_ASSERT( delay.Int() == 0 ); |
|
327 |
|
328 iIndicatorDsa->iPeriodic->Cancel(); |
|
329 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
330 EUNIT_ASSERT( delay.Int() == 0 ); |
|
331 |
|
332 iIndicatorDsa->StartPeriodicTimer( iIndicatorDsa->iRedrawCallBack ); |
|
333 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
334 EUNIT_ASSERT( delay.Int() == KMusRedrawDelay ); |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // Asserts that periodic timer is stopped after method call. |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_StopPeriodicTimerL() |
|
344 { |
|
345 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
346 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
347 iIndicatorDsa->StopPeriodicTimer(); |
|
348 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
349 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
350 |
|
351 iIndicatorDsa->StartPeriodicTimer( iIndicatorDsa->iActivateCallBack ); |
|
352 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
353 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
354 |
|
355 iIndicatorDsa->StopPeriodicTimer(); |
|
356 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
357 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
358 |
|
359 } |
|
360 |
|
361 // ---------------------------------------------------------------------------- |
|
362 // Asserts that periodic timer |
|
363 // ---------------------------------------------------------------------------- |
|
364 // |
|
365 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_TryActivateL() |
|
366 { |
|
367 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
368 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
369 |
|
370 EUNIT_ASSERT_EQUALS( iIndicatorDsa->TryActivate( iIndicatorDsa ), KErrNone ); |
|
371 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
372 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
373 |
|
374 cc = NULL; |
|
375 |
|
376 // Through async callback |
|
377 EUNIT_ASSERT_EQUALS( iIndicatorDsa->TryActivate( iIndicatorDsa ), KErrNone ); |
|
378 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
379 |
|
380 EUNIT_ASSERT_EQUALS( iIndicatorDsa->TryActivate( NULL ), KErrArgument ); |
|
381 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
382 |
|
383 } |
|
384 |
|
385 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_DoHandleResourceChangeL() |
|
386 { |
|
387 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
388 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
389 |
|
390 EUNIT_ASSERT_EQUALS( iIndicatorDsa->DoHandleResourceChange( iIndicatorDsa ), KErrNone ); |
|
391 EUNIT_ASSERT( iIndicatorDsa->iPeriodic ); |
|
392 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
393 |
|
394 EUNIT_ASSERT_EQUALS( iIndicatorDsa->DoHandleResourceChange( NULL ), KErrArgument ); |
|
395 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
396 |
|
397 } |
|
398 |
|
399 void UT_CMusIndicatorDsa::UT_CMusIndicatorDsa_HandleResourceChangeL() |
|
400 { |
|
401 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
402 iIndicatorDsa->StartPeriodicTimer( iIndicatorDsa->iRedrawCallBack ); |
|
403 EUNIT_ASSERT( iIndicatorDsa->iPeriodic->IsActive() ); |
|
404 |
|
405 iIndicatorDsa->iScreenSize = TSize(); |
|
406 iIndicatorDsa->HandleResourceChange( KEikDynamicLayoutVariantSwitch ); |
|
407 EUNIT_ASSERT( !iIndicatorDsa->iPeriodic->IsActive() ); |
|
408 |
|
409 EUNIT_ASSERT( iIndicatorDsa->iScreenSize != TSize() ); |
|
410 |
|
411 iIndicatorDsa->iScreenSize = TSize(); |
|
412 iIndicatorDsa->HandleResourceChange( 0 ); |
|
413 EUNIT_ASSERT( iIndicatorDsa->iScreenSize == TSize() ); |
|
414 |
|
415 } |
|
416 |
|
417 |
|
418 |
|
419 // ======== EUNIT TEST TABLE ======== |
|
420 |
|
421 |
|
422 EUNIT_BEGIN_TEST_TABLE( |
|
423 UT_CMusIndicatorDsa, |
|
424 "UT_CMusIndicatorDsa", |
|
425 "UNIT" ) |
|
426 |
|
427 EUNIT_TEST( |
|
428 "NewL - test", |
|
429 "CMusIndicatorDsa", |
|
430 "NewL", |
|
431 "FUNCTIONALITY", |
|
432 SetupL, UT_CMusIndicatorDsa_NewLL, Teardown ) |
|
433 |
|
434 |
|
435 EUNIT_TEST( |
|
436 "Draw - test", |
|
437 "CMusIndicatorDsa", |
|
438 "Draw", |
|
439 "FUNCTIONALITY", |
|
440 SetupL, UT_CMusIndicatorDsa_DrawL, Teardown ) |
|
441 |
|
442 |
|
443 EUNIT_TEST( |
|
444 "Initialize - test", |
|
445 "CMusIndicatorDsa", |
|
446 "Initialize", |
|
447 "FUNCTIONALITY", |
|
448 SetupL, UT_CMusIndicatorDsa_InitializeL, Teardown ) |
|
449 |
|
450 EUNIT_TEST( |
|
451 "LoadImageL - test", |
|
452 "CMusIndicatorDsa", |
|
453 "LoadImageL", |
|
454 "FUNCTIONALITY", |
|
455 SetupL, UT_CMusIndicatorDsa_LoadImageLL, Teardown ) |
|
456 |
|
457 EUNIT_TEST( |
|
458 "LoadResourceStringL - test", |
|
459 "CMusIndicatorDsa", |
|
460 "LoadResourceStringL", |
|
461 "FUNCTIONALITY", |
|
462 SetupL, UT_CMusIndicatorDsa_LoadResourceStringLL, Teardown ) |
|
463 |
|
464 |
|
465 EUNIT_TEST( |
|
466 "TryActivate - test", |
|
467 "CMusIndicatorDsa", |
|
468 "TryActivate", |
|
469 "FUNCTIONALITY", |
|
470 SetupL, UT_CMusIndicatorDsa_TryActivateL, Teardown ) |
|
471 |
|
472 EUNIT_TEST( |
|
473 "StartPeriodicTimer - test", |
|
474 "CMusIndicatorDsa", |
|
475 "StartPeriodicTimer", |
|
476 "FUNCTIONALITY", |
|
477 SetupL, UT_CMusIndicatorDsa_StartPeriodicTimerL, Teardown ) |
|
478 |
|
479 EUNIT_TEST( |
|
480 "StopPeriodicTimer - test", |
|
481 "CMusIndicatorDsa", |
|
482 "StopPeriodicTimer", |
|
483 "FUNCTIONALITY", |
|
484 SetupL, UT_CMusIndicatorDsa_StopPeriodicTimerL, Teardown ) |
|
485 |
|
486 EUNIT_TEST( |
|
487 "DoHandleResourceChange - test", |
|
488 "CMusIndicatorDsa", |
|
489 "DoHandleResourceChange", |
|
490 "FUNCTIONALITY", |
|
491 SetupL, UT_CMusIndicatorDsa_DoHandleResourceChangeL, Teardown ) |
|
492 |
|
493 EUNIT_TEST( |
|
494 "HandleResourceChange - test", |
|
495 "CMusIndicatorDsa", |
|
496 "HandleResourceChange", |
|
497 "FUNCTIONALITY", |
|
498 SetupL, UT_CMusIndicatorDsa_HandleResourceChangeL, Teardown ) |
|
499 |
|
500 |
|
501 EUNIT_END_TEST_TABLE |