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