Merge "Add utc test cases" into tizen
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ControlImpl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include "toolkit-style-monitor.h"
25
26 #include <dali.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/integration-api/events/key-event-integ.h>
29 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
30 #include <dali/integration-api/events/long-press-gesture-event.h>
31 #include <dali/integration-api/events/pinch-gesture-event.h>
32 #include <dali/integration-api/events/pan-gesture-event.h>
33 #include <dali/integration-api/events/tap-gesture-event.h>
34 #include <dali/integration-api/events/touch-event-integ.h>
35 #include <dali/integration-api/events/hover-event-integ.h>
36
37 #include "dummy-control.h"
38
39 using namespace Dali;
40 using namespace Dali::Toolkit;
41
42 void utc_dali_toolkit_control_impl_startup(void)
43 {
44   test_return_value = TET_UNDEF;
45 }
46
47 void utc_dali_toolkit_control_impl_cleanup(void)
48 {
49   test_return_value = TET_PASS;
50 }
51
52 int UtcDaliControlImplNew(void)
53 {
54   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
55
56   Control control;
57
58   DALI_TEST_CHECK( !Control::DownCast(control) );
59
60   control = Toolkit::Internal::Control::New();
61
62   DALI_TEST_CHECK( Control::DownCast(control) );
63   END_TEST;
64 }
65
66
67 int UtcDaliControlImplEnableGestureDetector(void)
68 {
69   ToolkitTestApplication application;
70
71   // Enable individually
72   {
73     DummyControl dummy = DummyControl::New();
74     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
75
76     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
77     dummyImpl.EnableGestureDetection(Gesture::Pinch);
78     DALI_TEST_CHECK( dummyImpl.GetPinchGestureDetector() );
79
80     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
81     dummyImpl.EnableGestureDetection(Gesture::Pan);
82     DALI_TEST_CHECK( dummyImpl.GetPanGestureDetector() );
83
84     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
85     dummyImpl.EnableGestureDetection(Gesture::Tap);
86     DALI_TEST_CHECK( dummyImpl.GetTapGestureDetector() );
87
88     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
89     dummyImpl.EnableGestureDetection(Gesture::LongPress);
90     DALI_TEST_CHECK( dummyImpl.GetLongPressGestureDetector() );
91   }
92
93   // Enable All
94   {
95     DummyControl dummy = DummyControl::New();
96     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
97
98     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
99     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
100     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
101     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
102
103     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
104
105     DALI_TEST_CHECK( dummyImpl.GetPinchGestureDetector() );
106     DALI_TEST_CHECK( dummyImpl.GetPanGestureDetector() );
107     DALI_TEST_CHECK( dummyImpl.GetTapGestureDetector() );
108     DALI_TEST_CHECK( dummyImpl.GetLongPressGestureDetector() );
109
110     // Enable when already enabled
111
112     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
113
114     DALI_TEST_CHECK( dummyImpl.GetPinchGestureDetector() );
115     DALI_TEST_CHECK( dummyImpl.GetPanGestureDetector() );
116     DALI_TEST_CHECK( dummyImpl.GetTapGestureDetector() );
117     DALI_TEST_CHECK( dummyImpl.GetLongPressGestureDetector() );
118   }
119   END_TEST;
120 }
121
122 int UtcDaliControlImplDisableGestureDetector(void)
123 {
124   ToolkitTestApplication application;
125
126   // Disable individually
127   {
128     DummyControl dummy = DummyControl::New();
129     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
130
131     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
132
133     DALI_TEST_CHECK( dummyImpl.GetPinchGestureDetector() );
134     dummyImpl.DisableGestureDetection(Gesture::Pinch);
135     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
136
137     DALI_TEST_CHECK( dummyImpl.GetPanGestureDetector() );
138     dummyImpl.DisableGestureDetection(Gesture::Pan);
139     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
140
141     DALI_TEST_CHECK( dummyImpl.GetTapGestureDetector() );
142     dummyImpl.DisableGestureDetection(Gesture::Tap);
143     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
144
145     DALI_TEST_CHECK( dummyImpl.GetLongPressGestureDetector() );
146     dummyImpl.DisableGestureDetection(Gesture::LongPress);
147     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
148   }
149
150   // Disable All
151   {
152     DummyControl dummy = DummyControl::New();
153     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
154
155     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
156
157     DALI_TEST_CHECK( dummyImpl.GetPinchGestureDetector() );
158     DALI_TEST_CHECK( dummyImpl.GetPanGestureDetector() );
159     DALI_TEST_CHECK( dummyImpl.GetTapGestureDetector() );
160     DALI_TEST_CHECK( dummyImpl.GetLongPressGestureDetector() );
161
162     dummyImpl.DisableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
163
164     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
165     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
166     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
167     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
168   }
169
170   // Disable When not enabled
171   {
172     DummyControl dummy = DummyControl::New();
173     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
174
175     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
176     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
177     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
178     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
179
180     dummyImpl.DisableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
181
182     DALI_TEST_CHECK( !dummyImpl.GetPinchGestureDetector() );
183     DALI_TEST_CHECK( !dummyImpl.GetPanGestureDetector() );
184     DALI_TEST_CHECK( !dummyImpl.GetTapGestureDetector() );
185     DALI_TEST_CHECK( !dummyImpl.GetLongPressGestureDetector() );
186   }
187
188   // Ensure control is detached if gesture detector is not deleted
189   {
190     DummyControl dummy = DummyControl::New();
191     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
192
193     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
194
195     PinchGestureDetector pinch = dummyImpl.GetPinchGestureDetector();
196     PanGestureDetector pan   = dummyImpl.GetPanGestureDetector();
197     TapGestureDetector tap = dummyImpl.GetTapGestureDetector();
198     LongPressGestureDetector longPress = dummyImpl.GetLongPressGestureDetector();
199
200     DALI_TEST_EQUALS( pinch.GetAttachedActors().empty(), false, TEST_LOCATION );
201     DALI_TEST_EQUALS( pan.GetAttachedActors().empty(), false, TEST_LOCATION );
202     DALI_TEST_EQUALS( tap.GetAttachedActors().empty(), false, TEST_LOCATION );
203     DALI_TEST_EQUALS( longPress.GetAttachedActors().empty(), false, TEST_LOCATION );
204
205     dummyImpl.DisableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
206
207     DALI_TEST_EQUALS( pinch.GetAttachedActors().empty(), true, TEST_LOCATION );
208     DALI_TEST_EQUALS( pan.GetAttachedActors().empty(), true, TEST_LOCATION );
209     DALI_TEST_EQUALS( tap.GetAttachedActors().empty(), true, TEST_LOCATION );
210     DALI_TEST_EQUALS( longPress.GetAttachedActors().empty(), true, TEST_LOCATION );
211   }
212   END_TEST;
213 }
214
215 int UtcDaliControlImplOnGestureMethods(void)
216 {
217   ToolkitTestApplication application;
218
219   // Check gesture actually happens
220   {
221     DummyControl dummy = DummyControl::New(true);
222     dummy.SetSize( Vector2(100.0f, 100.0f ) );
223
224     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
225     Stage::GetCurrent().Add(dummy);
226
227     // Render and notify a couple of times
228     application.SendNotification();
229     application.Render();
230     application.SendNotification();
231     application.Render();
232
233     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
234     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
235
236     DALI_TEST_CHECK( dummyImpl.pinchCalled == false );
237     Integration::PinchGestureEvent pinch(Gesture::Started);
238     pinch.scale = 10.0f;
239     pinch.speed = 50.0f;
240     pinch.centerPoint = Vector2(20.0f, 20.0f);
241     application.ProcessEvent(pinch);
242     DALI_TEST_CHECK( dummyImpl.pinchCalled == true );
243
244     DALI_TEST_CHECK( dummyImpl.panCalled == false );
245     Integration::PanGestureEvent pan(Gesture::Possible);
246     pan.previousPosition = Vector2(10.0f, 20.0f);
247     pan.currentPosition = Vector2(20.0f, 20.0f);
248     pan.timeDelta = 10;
249     pan.numberOfTouches = 1u;
250     application.ProcessEvent(pan);
251     pan.state = Gesture::Started;
252     application.ProcessEvent(pan);
253     DALI_TEST_CHECK( dummyImpl.panCalled == true );
254
255     DALI_TEST_CHECK( dummyImpl.tapCalled == false );
256     Integration::TapGestureEvent tap(Gesture::Possible);
257     tap.numberOfTaps = 1u;
258     tap.numberOfTouches = 1u;
259     tap.point = Vector2(50.0f, 50.0f);
260     application.ProcessEvent(tap);
261     tap.state = Gesture::Started;
262     application.ProcessEvent(tap);
263     DALI_TEST_CHECK( dummyImpl.tapCalled == true );
264
265     DALI_TEST_CHECK( dummyImpl.longPressCalled == false );
266     Integration::LongPressGestureEvent longPress(Gesture::Possible);
267     longPress.numberOfTouches = 1u;
268     longPress.point = Vector2(50.0f, 50.0f);
269     application.ProcessEvent(longPress);
270     longPress.state = Gesture::Started;
271     application.ProcessEvent(longPress);
272     DALI_TEST_CHECK( dummyImpl.longPressCalled == true );
273     longPress.state = Gesture::Finished;
274     application.ProcessEvent(longPress);
275
276     Stage::GetCurrent().Remove(dummy);
277   }
278
279   // Ensure full code coverage
280   {
281     DummyControl dummy = DummyControl::New();
282     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
283
284     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
285     Stage::GetCurrent().Add(dummy);
286
287     // Render and notify a couple of times
288     application.SendNotification();
289     application.Render();
290     application.SendNotification();
291     application.Render();
292
293     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
294     dummyImpl.EnableGestureDetection( Gesture::Type(Gesture::Pinch | Gesture::Pan | Gesture::Tap | Gesture::LongPress) );
295
296     DALI_TEST_CHECK( dummy.GetCurrentScale().x != 10.0f );
297     Integration::PinchGestureEvent pinch(Gesture::Started);
298     pinch.scale = 10.0f;
299     pinch.speed = 50.0f;
300     pinch.centerPoint = Vector2(20.0f, 20.0f);
301     application.ProcessEvent(pinch);
302
303     // Render and notify a couple of times
304     application.SendNotification();
305     application.Render();
306     application.SendNotification();
307     application.Render();
308     DALI_TEST_CHECK( dummy.GetCurrentScale().x == 10.0f );
309
310     Integration::PanGestureEvent pan(Gesture::Possible);
311     pan.previousPosition = Vector2(10.0f, 20.0f);
312     pan.currentPosition = Vector2(20.0f, 20.0f);
313     pan.timeDelta = 10;
314     pan.numberOfTouches = 1u;
315     application.ProcessEvent(pan);
316     pan.state = Gesture::Started;
317     application.ProcessEvent(pan);
318
319     Integration::TapGestureEvent tap(Gesture::Possible);
320     tap.numberOfTaps = 1u;
321     tap.numberOfTouches = 1u;
322     tap.point = Vector2(50.0f, 50.0f);
323     application.ProcessEvent(tap);
324     tap.state = Gesture::Started;
325     application.ProcessEvent(tap);
326
327     Integration::LongPressGestureEvent longPress(Gesture::Possible);
328     longPress.numberOfTouches = 1u;
329     longPress.point = Vector2(50.0f, 50.0f);
330     application.ProcessEvent(longPress);
331     longPress.state = Gesture::Started;
332     application.ProcessEvent(longPress);
333     longPress.state = Gesture::Finished;
334     application.ProcessEvent(longPress);
335
336     Stage::GetCurrent().Remove(dummy);
337   }
338   END_TEST;
339 }
340
341 int UtcDaliControlImplChildAddAndRemove(void)
342 {
343   ToolkitTestApplication application;
344
345   {
346     DummyControl dummy = DummyControl::New( true );
347     Stage::GetCurrent().Add(dummy);
348     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
349
350     application.Render();
351     application.SendNotification();
352
353     DALI_TEST_EQUALS( dummyImpl.childAddCalled, false, TEST_LOCATION );
354     DALI_TEST_EQUALS( dummy.GetChildCount(), 0u, TEST_LOCATION );
355     Actor actor = RenderableActor::New();
356     dummy.Add(actor);
357     DALI_TEST_EQUALS( dummyImpl.childAddCalled, true, TEST_LOCATION );
358     DALI_TEST_EQUALS( dummy.GetChildCount(), 1u, TEST_LOCATION );
359
360     application.Render();
361     application.SendNotification();
362
363     DALI_TEST_EQUALS( dummyImpl.childRemoveCalled, false, TEST_LOCATION );
364     dummy.Remove( actor );
365     DALI_TEST_EQUALS( dummyImpl.childRemoveCalled, true, TEST_LOCATION );
366     DALI_TEST_EQUALS( dummy.GetChildCount(), 0u, TEST_LOCATION );
367
368     application.Render();
369     application.SendNotification();
370
371     Stage::GetCurrent().Remove(dummy);
372   }
373
374   // Ensure full code coverage
375   {
376     DummyControl dummy = DummyControl::New();
377     Stage::GetCurrent().Add(dummy);
378
379     application.Render();
380     application.SendNotification();
381
382     DALI_TEST_EQUALS( dummy.GetChildCount(), 0u, TEST_LOCATION );
383     Actor actor = RenderableActor::New();
384     dummy.Add(actor);
385     DALI_TEST_EQUALS( dummy.GetChildCount(), 1u, TEST_LOCATION );
386
387     application.Render();
388     application.SendNotification();
389
390     dummy.Remove( actor );
391     DALI_TEST_EQUALS( dummy.GetChildCount(), 0u, TEST_LOCATION );
392
393     application.Render();
394     application.SendNotification();
395
396     Stage::GetCurrent().Remove(dummy);
397   }
398   END_TEST;
399 }
400
401 int UtcDaliControlImplStageConnection(void)
402 {
403   ToolkitTestApplication application;
404
405   {
406     DummyControl dummy = DummyControl::New( true );
407     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
408
409     DALI_TEST_EQUALS( dummyImpl.stageConnectionCalled, false, TEST_LOCATION );
410     Stage::GetCurrent().Add(dummy);
411     application.Render();
412     application.SendNotification();
413     DALI_TEST_EQUALS( dummyImpl.stageConnectionCalled, true, TEST_LOCATION );
414
415     DALI_TEST_EQUALS( dummyImpl.stageDisconnectionCalled, false, TEST_LOCATION );
416     Stage::GetCurrent().Remove(dummy);
417     application.Render();
418     application.SendNotification();
419     DALI_TEST_EQUALS( dummyImpl.stageDisconnectionCalled, true, TEST_LOCATION );
420   }
421
422   // Ensure full code coverage
423   {
424     unsigned int stageChildren = Stage::GetCurrent().GetLayer(0).GetChildCount();
425     DummyControl dummy = DummyControl::New();
426
427     DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer(0).GetChildCount(), stageChildren, TEST_LOCATION );
428     Stage::GetCurrent().Add(dummy);
429     application.Render();
430     application.SendNotification();
431     DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer(0).GetChildCount(), stageChildren + 1, TEST_LOCATION );
432
433     Stage::GetCurrent().Remove(dummy);
434     application.Render();
435     application.SendNotification();
436     DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer(0).GetChildCount(), stageChildren, TEST_LOCATION );
437   }
438   END_TEST;
439 }
440
441 int UtcDaliControlImplSizeSetP(void)
442 {
443   ToolkitTestApplication application;
444
445   {
446     DummyControl dummy = DummyControl::New( true );
447     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
448
449     Stage::GetCurrent().Add(dummy);
450     application.Render();
451     application.SendNotification();
452
453     DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, false, TEST_LOCATION ); // Size not set, no onSizeSet called
454     Vector2 size(100.0f, 200.0f);
455     dummy.SetSize( size );
456
457     DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, false, TEST_LOCATION ); // Size is going to get negotiated, no onSizeSet called
458
459     application.SendNotification();
460     application.Render();
461
462     DALI_TEST_EQUALS( size, dummy.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
463     DALI_TEST_EQUALS( dummyImpl.sizeSetCalled, true, TEST_LOCATION );
464
465     Stage::GetCurrent().Remove(dummy);
466   }
467
468   END_TEST;
469 }
470
471 int UtcDaliControlImplSizeSet2P(void)
472 {
473   ToolkitTestApplication application;
474
475   {
476     DummyControl dummy = DummyControl::New();
477     Stage::GetCurrent().Add(dummy);
478
479     Vector2 size(100.0f, 200.0f);
480     DALI_TEST_CHECK( size != dummy.GetCurrentSize().GetVectorXY() );
481
482     application.SendNotification();
483     application.Render();
484
485     dummy.SetSize(size);
486
487     application.SendNotification();
488     application.Render();
489
490     DALI_TEST_EQUALS(size, dummy.GetCurrentSize().GetVectorXY(), TEST_LOCATION);
491
492     Stage::GetCurrent().Remove(dummy);
493   }
494   END_TEST;
495 }
496
497
498 int UtcDaliControlImplSizeAnimation(void)
499 {
500   ToolkitTestApplication application;
501
502   {
503     DummyControl dummy = DummyControl::New( true );
504     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
505
506     Stage::GetCurrent().Add(dummy);
507
508     DALI_TEST_EQUALS( dummyImpl.sizeAnimationCalled, false, TEST_LOCATION );
509     Animation animation = Animation::New(1.0f);
510     animation.AnimateTo( Property( dummy, Actor::Property::SIZE ), Vector3( 100.0f, 150.0f, 200.0f ) );
511     animation.Play();
512
513     application.Render();
514     application.SendNotification();
515     application.Render();
516     application.SendNotification();
517
518     DALI_TEST_EQUALS( dummyImpl.sizeAnimationCalled, true, TEST_LOCATION );
519
520     Stage::GetCurrent().Remove(dummy);
521   }
522
523   // Ensure full code coverage
524   {
525     DummyControl dummy = DummyControl::New();
526
527     Stage::GetCurrent().Add(dummy);
528
529     Animation animation = Animation::New(1.0f);
530     animation.AnimateTo( Property( dummy, Actor::Property::SIZE ), Vector3( 100.0f, 150.0f, 200.0f ) );
531     animation.Play();
532
533     application.Render();
534     application.SendNotification();
535     application.Render();
536     application.SendNotification();
537
538     Stage::GetCurrent().Remove(dummy);
539   }
540   END_TEST;
541 }
542
543 ///////////////////////////////////////////////////////////////////////////////////////////////////
544
545 int UtcDaliControlImplTouchEvent(void)
546 {
547   ToolkitTestApplication application;
548
549   {
550     DummyControl dummy = DummyControl::New( true );
551     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
552
553     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
554     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
555     Stage::GetCurrent().Add(dummy);
556
557     application.Render();
558     application.SendNotification();
559     application.Render();
560     application.SendNotification();
561
562     DALI_TEST_EQUALS( dummyImpl.touchEventCalled, false, TEST_LOCATION );
563     Integration::TouchEvent touchEvent(1);
564     TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
565     touchEvent.AddPoint(point);
566     application.ProcessEvent(touchEvent);
567     DALI_TEST_EQUALS( dummyImpl.touchEventCalled, true, TEST_LOCATION );
568
569     Stage::GetCurrent().Remove(dummy);
570   }
571
572   // Ensure full code coverage
573   {
574     DummyControl dummy = DummyControl::New();
575
576     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
577     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
578     Stage::GetCurrent().Add(dummy);
579
580     application.Render();
581     application.SendNotification();
582     application.Render();
583     application.SendNotification();
584
585     Integration::TouchEvent touchEvent(1);
586     TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
587     touchEvent.AddPoint(point);
588     application.ProcessEvent(touchEvent);
589
590     Stage::GetCurrent().Remove(dummy);
591   }
592   END_TEST;
593 }
594
595 int UtcDaliControlImplHoverEvent(void)
596 {
597   ToolkitTestApplication application;
598
599   {
600     DummyControl dummy = DummyControl::New( true );
601     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
602
603     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
604     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
605     Stage::GetCurrent().Add(dummy);
606
607     application.Render();
608     application.SendNotification();
609     application.Render();
610     application.SendNotification();
611
612     DALI_TEST_EQUALS( dummyImpl.hoverEventCalled, false, TEST_LOCATION );
613     Integration::HoverEvent event(1);
614     TouchPoint point( 1, TouchPoint::Motion, 20.0f, 20.0f );
615     event.AddPoint( point );
616     application.ProcessEvent( event );
617     DALI_TEST_EQUALS( dummyImpl.hoverEventCalled, true, TEST_LOCATION );
618
619     Stage::GetCurrent().Remove(dummy);
620   }
621
622   // Ensure full code coverage
623   {
624     DummyControl dummy = DummyControl::New();
625
626     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
627     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
628     Stage::GetCurrent().Add(dummy);
629
630     application.Render();
631     application.SendNotification();
632     application.Render();
633     application.SendNotification();
634
635     Integration::HoverEvent event(1);
636     TouchPoint point( 1, TouchPoint::Motion, 20.0f, 20.0f );
637     event.AddPoint( point );
638     application.ProcessEvent( event );
639
640     Stage::GetCurrent().Remove(dummy);
641   }
642   END_TEST;
643 }
644
645 ///////////////////////////////////////////////////////////////////////////////////////////////////
646
647
648 int UtcDaliControlImplKeyEvent(void)
649 {
650   ToolkitTestApplication application;
651
652   {
653     DummyControl dummy = DummyControl::New( true );
654     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
655
656     Stage::GetCurrent().Add(dummy);
657     dummy.SetKeyInputFocus();
658
659     application.Render();
660     application.SendNotification();
661     application.Render();
662     application.SendNotification();
663
664     DALI_TEST_EQUALS( dummyImpl.keyEventCalled, false, TEST_LOCATION );
665     Integration::KeyEvent keyEvent;
666     application.ProcessEvent(keyEvent);
667     DALI_TEST_EQUALS( dummyImpl.keyEventCalled, true, TEST_LOCATION );
668
669     Stage::GetCurrent().Remove(dummy);
670   }
671
672   // Ensure full code coverage
673   {
674     DummyControl dummy = DummyControl::New();
675
676     Stage::GetCurrent().Add(dummy);
677     dummy.SetKeyInputFocus();
678
679     application.Render();
680     application.SendNotification();
681     application.Render();
682     application.SendNotification();
683
684     Integration::KeyEvent keyEvent;
685     application.ProcessEvent(keyEvent);
686
687     Stage::GetCurrent().Remove(dummy);
688   }
689   END_TEST;
690 }
691
692 int UtcDaliControlImplKeyInputFocusGained(void)
693 {
694   ToolkitTestApplication application;
695
696   {
697     DummyControl dummy = DummyControl::New( true );
698     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
699
700     Stage::GetCurrent().Add(dummy);
701
702     DALI_TEST_EQUALS( dummyImpl.keyInputFocusGained, false, TEST_LOCATION );
703
704     dummy.SetKeyInputFocus();
705
706     DALI_TEST_EQUALS( dummyImpl.keyInputFocusGained, true, TEST_LOCATION );
707
708     Stage::GetCurrent().Remove(dummy);
709   }
710
711   // Ensure full code coverage
712   {
713     DummyControl dummy = DummyControl::New();
714
715     Stage::GetCurrent().Add(dummy);
716     dummy.SetKeyInputFocus();
717     Stage::GetCurrent().Remove(dummy);
718   }
719   END_TEST;
720 }
721
722 int UtcDaliControlImplKeyInputFocusLost(void)
723 {
724   ToolkitTestApplication application;
725
726   {
727     DummyControl dummy = DummyControl::New( true );
728     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
729
730     Stage::GetCurrent().Add(dummy);
731
732     DALI_TEST_EQUALS( dummyImpl.keyInputFocusLost, false, TEST_LOCATION );
733
734     dummy.SetKeyInputFocus();
735     dummy.ClearKeyInputFocus();
736
737     DALI_TEST_EQUALS( dummyImpl.keyInputFocusLost, true, TEST_LOCATION );
738
739     Stage::GetCurrent().Remove(dummy);
740   }
741
742   // Ensure full code coverage
743   {
744     DummyControl dummy = DummyControl::New();
745
746     Stage::GetCurrent().Add(dummy);
747     dummy.SetKeyInputFocus();
748     dummy.ClearKeyInputFocus();
749
750     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
751
752     dummyImpl.OnAccessibilityValueChange( true );
753     dummyImpl.IsKeyboardNavigationSupported();
754     dummyImpl.IsKeyboardFocusGroup();
755
756     Stage::GetCurrent().Remove(dummy);
757   }
758   END_TEST;
759 }
760
761 int UtcDaliControlImplTypeRegistry(void)
762 {
763   ToolkitTestApplication application;
764
765   // Register Type
766   TypeInfo type;
767   type = TypeRegistry::Get().GetTypeInfo( "Control" );
768   DALI_TEST_CHECK( type );
769   BaseHandle handle = type.CreateInstance();
770   DALI_TEST_CHECK( handle );
771
772   // Check if it's a control
773   DALI_TEST_CHECK( Control::DownCast(handle) );
774   END_TEST;
775 }
776
777
778 ///////////////////////////////////////////////////////////////////////////////////////////////////
779 namespace
780 {
781 static bool MouseWheelEventCallback(Actor actor, const MouseWheelEvent& event)
782 {
783   return false;
784 }
785 }
786
787 int UtcDaliControlImplMouseWheelEvent(void)
788 {
789   ToolkitTestApplication application;
790
791   {
792     DummyControl dummy = DummyControl::New( true );
793     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
794
795     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
796     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
797     Stage::GetCurrent().Add(dummy);
798
799     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
800
801     application.Render();
802     application.SendNotification();
803     application.Render();
804     application.SendNotification();
805
806     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, false, TEST_LOCATION );
807
808     // simulate a mouse wheel event
809     Vector2 screenCoordinates( 10.0f, 10.0f );
810     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
811     application.ProcessEvent(event);
812     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, true, TEST_LOCATION );
813
814     Stage::GetCurrent().Remove(dummy);
815   }
816
817   // Ensure full code coverage
818   {
819     DummyControl dummy = DummyControl::New();
820
821     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
822     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
823     Stage::GetCurrent().Add(dummy);
824
825     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
826
827     application.Render();
828     application.SendNotification();
829     application.Render();
830     application.SendNotification();
831
832     // simulate a mouse wheel event
833     Vector2 screenCoordinates( 20.0f, 20.0f );
834     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
835     application.ProcessEvent(event);
836
837     Stage::GetCurrent().Remove(dummy);
838   }
839   END_TEST;
840 }
841
842 int UtcDaliControlImplSetStyleName(void)
843 {
844   ToolkitTestApplication application;
845
846   {
847     DummyControl dummy = DummyControl::New( true );
848     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
849
850     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
851     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
852     Stage::GetCurrent().Add(dummy);
853
854     dummy.SetStyleName("TestStyle");
855
856     DALI_TEST_CHECK( dummy.GetStyleName() == "TestStyle" );
857
858     Stage::GetCurrent().Remove(dummy);
859   }
860   END_TEST;
861 }