Merge "DALi Version 1.2.49" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ControlImpl.cpp
1 /*
2  * Copyright (c) 2017 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-toolkit/devel-api/visual-factory/visual-factory.h>
29 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/integration-api/events/wheel-event-integ.h>
31 #include <dali/integration-api/events/long-press-gesture-event.h>
32 #include <dali/integration-api/events/pinch-gesture-event.h>
33 #include <dali/integration-api/events/pan-gesture-event.h>
34 #include <dali/integration-api/events/tap-gesture-event.h>
35 #include <dali/integration-api/events/touch-event-integ.h>
36 #include <dali/integration-api/events/hover-event-integ.h>
37
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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(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     Integration::Point point;
567     point.SetDeviceId( 1 );
568     point.SetState( PointState::DOWN );
569     point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
570     touchEvent.AddPoint(point);
571     application.ProcessEvent(touchEvent);
572     DALI_TEST_EQUALS( dummyImpl.touchEventCalled, true, TEST_LOCATION );
573
574     Stage::GetCurrent().Remove(dummy);
575   }
576
577   // Ensure full code coverage
578   {
579     DummyControl dummy = DummyControl::New();
580
581     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
582     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
583     Stage::GetCurrent().Add(dummy);
584
585     application.Render();
586     application.SendNotification();
587     application.Render();
588     application.SendNotification();
589
590     Integration::TouchEvent touchEvent(1);
591     Integration::Point point;
592     point.SetDeviceId( 1 );
593     point.SetState( PointState::DOWN );
594     point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
595     touchEvent.AddPoint(point);
596     application.ProcessEvent(touchEvent);
597
598     Stage::GetCurrent().Remove(dummy);
599   }
600   END_TEST;
601 }
602
603 int UtcDaliControlImplHoverEvent(void)
604 {
605   ToolkitTestApplication application;
606
607   {
608     DummyControl dummy = DummyControl::New( true );
609     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
610
611     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
612     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
613     Stage::GetCurrent().Add(dummy);
614
615     application.Render();
616     application.SendNotification();
617     application.Render();
618     application.SendNotification();
619
620     DALI_TEST_EQUALS( dummyImpl.hoverEventCalled, false, TEST_LOCATION );
621     Integration::HoverEvent event(1);
622     Integration::Point point;
623     point.SetDeviceId( 1 );
624     point.SetState( PointState::MOTION );
625     point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
626     event.AddPoint(point);
627     application.ProcessEvent( event );
628     DALI_TEST_EQUALS( dummyImpl.hoverEventCalled, true, TEST_LOCATION );
629
630     Stage::GetCurrent().Remove(dummy);
631   }
632
633   // Ensure full code coverage
634   {
635     DummyControl dummy = DummyControl::New();
636
637     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
638     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
639     Stage::GetCurrent().Add(dummy);
640
641     application.Render();
642     application.SendNotification();
643     application.Render();
644     application.SendNotification();
645
646     Integration::HoverEvent event(1);
647     Integration::Point point;
648     point.SetDeviceId( 1 );
649     point.SetState( PointState::MOTION );
650     point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
651     event.AddPoint(point);
652     application.ProcessEvent( event );
653
654     Stage::GetCurrent().Remove(dummy);
655   }
656   END_TEST;
657 }
658
659 ///////////////////////////////////////////////////////////////////////////////////////////////////
660
661
662 int UtcDaliControlImplKeyEvent(void)
663 {
664   ToolkitTestApplication application;
665
666   {
667     DummyControl dummy = DummyControl::New( true );
668     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
669
670     Stage::GetCurrent().Add(dummy);
671     dummy.SetKeyInputFocus();
672
673     application.Render();
674     application.SendNotification();
675     application.Render();
676     application.SendNotification();
677
678     DALI_TEST_EQUALS( dummyImpl.keyEventCalled, false, TEST_LOCATION );
679     Integration::KeyEvent keyEvent;
680     application.ProcessEvent(keyEvent);
681     DALI_TEST_EQUALS( dummyImpl.keyEventCalled, true, TEST_LOCATION );
682
683     Stage::GetCurrent().Remove(dummy);
684   }
685
686   // Ensure full code coverage
687   {
688     DummyControl dummy = DummyControl::New();
689
690     Stage::GetCurrent().Add(dummy);
691     dummy.SetKeyInputFocus();
692
693     application.Render();
694     application.SendNotification();
695     application.Render();
696     application.SendNotification();
697
698     Integration::KeyEvent keyEvent;
699     application.ProcessEvent(keyEvent);
700
701     Stage::GetCurrent().Remove(dummy);
702   }
703   END_TEST;
704 }
705
706 int UtcDaliControlImplKeyInputFocusGained(void)
707 {
708   ToolkitTestApplication application;
709
710   {
711     DummyControl dummy = DummyControl::New( true );
712     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
713
714     Stage::GetCurrent().Add(dummy);
715
716     DALI_TEST_EQUALS( dummyImpl.keyInputFocusGained, false, TEST_LOCATION );
717
718     dummy.SetKeyInputFocus();
719
720     DALI_TEST_EQUALS( dummyImpl.keyInputFocusGained, true, TEST_LOCATION );
721
722     Stage::GetCurrent().Remove(dummy);
723   }
724
725   // Ensure full code coverage
726   {
727     DummyControl dummy = DummyControl::New();
728
729     Stage::GetCurrent().Add(dummy);
730     dummy.SetKeyInputFocus();
731     Stage::GetCurrent().Remove(dummy);
732   }
733   END_TEST;
734 }
735
736 int UtcDaliControlImplKeyInputFocusLost(void)
737 {
738   ToolkitTestApplication application;
739
740   {
741     DummyControl dummy = DummyControl::New( true );
742     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
743
744     Stage::GetCurrent().Add(dummy);
745
746     DALI_TEST_EQUALS( dummyImpl.keyInputFocusLost, false, TEST_LOCATION );
747
748     dummy.SetKeyInputFocus();
749     dummy.ClearKeyInputFocus();
750
751     DALI_TEST_EQUALS( dummyImpl.keyInputFocusLost, true, TEST_LOCATION );
752
753     Stage::GetCurrent().Remove(dummy);
754   }
755
756   // Ensure full code coverage
757   {
758     DummyControl dummy = DummyControl::New();
759
760     Stage::GetCurrent().Add(dummy);
761     dummy.SetKeyInputFocus();
762     dummy.ClearKeyInputFocus();
763
764     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
765
766     dummyImpl.IsKeyboardNavigationSupported();
767     dummyImpl.IsKeyboardFocusGroup();
768
769     Stage::GetCurrent().Remove(dummy);
770   }
771   END_TEST;
772 }
773
774 int UtcDaliControlImplTypeRegistry(void)
775 {
776   ToolkitTestApplication application;
777
778   // Register Type
779   TypeInfo type;
780   type = TypeRegistry::Get().GetTypeInfo( "Control" );
781   DALI_TEST_CHECK( type );
782   BaseHandle handle = type.CreateInstance();
783   DALI_TEST_CHECK( handle );
784
785   // Check if it's a control
786   DALI_TEST_CHECK( Control::DownCast(handle) );
787   END_TEST;
788 }
789
790
791 ///////////////////////////////////////////////////////////////////////////////////////////////////
792 namespace
793 {
794 static bool WheelEventCallback(Actor actor, const WheelEvent& event)
795 {
796   return false;
797 }
798 }
799
800 int UtcDaliControlImplWheelEvent(void)
801 {
802   ToolkitTestApplication application;
803
804   {
805     DummyControl dummy = DummyControl::New( true );
806     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
807
808     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
809     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
810     Stage::GetCurrent().Add(dummy);
811
812     dummy.WheelEventSignal().Connect(&WheelEventCallback);
813
814     application.Render();
815     application.SendNotification();
816     application.Render();
817     application.SendNotification();
818
819     DALI_TEST_EQUALS( dummyImpl.wheelEventCalled, false, TEST_LOCATION );
820
821     // simulate a wheel event
822     Vector2 screenCoordinates( 10.0f, 10.0f );
823     Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
824     application.ProcessEvent( event );
825     DALI_TEST_EQUALS( dummyImpl.wheelEventCalled, true, TEST_LOCATION );
826
827     Stage::GetCurrent().Remove(dummy);
828   }
829
830   // Ensure full code coverage
831   {
832     DummyControl dummy = DummyControl::New();
833
834     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
835     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
836     Stage::GetCurrent().Add(dummy);
837
838     dummy.WheelEventSignal().Connect(&WheelEventCallback);
839
840     application.Render();
841     application.SendNotification();
842     application.Render();
843     application.SendNotification();
844
845     // simulate a wheel event
846     Vector2 screenCoordinates( 20.0f, 20.0f );
847     Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
848     application.ProcessEvent( event );
849
850     Stage::GetCurrent().Remove(dummy);
851   }
852   END_TEST;
853 }
854
855 int UtcDaliControlImplSetStyleName(void)
856 {
857   ToolkitTestApplication application;
858
859   {
860     DummyControl dummy = DummyControl::New( true );
861
862     dummy.SetSize( Vector2( 100.0f, 100.0f ) );
863     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
864     Stage::GetCurrent().Add(dummy);
865
866     dummy.SetStyleName("TestStyle");
867
868     DALI_TEST_CHECK( dummy.GetStyleName() == "TestStyle" );
869
870     Stage::GetCurrent().Remove(dummy);
871   }
872   END_TEST;
873 }
874
875 int UtcDaliControlImplOnStyleChangeN(void)
876 {
877   ToolkitTestApplication application;
878   Control dummy = Control::New();
879   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( dummy );
880
881   // test that style manager is being used, passing an empty handle does nothing but does not crash either
882   Dali::Toolkit::StyleManager styleManager;
883   controlImpl.OnStyleChange( styleManager, StyleChange::THEME_CHANGE );
884   // no crash so test passes
885   tet_result(TET_PASS);
886
887   END_TEST;
888 }
889
890
891 int UtcDaliControlImplOnAccessibilityPanP(void)
892 {
893   ToolkitTestApplication application;
894   Control dummy = Control::New();
895   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( dummy );
896
897   PanGesture pan;
898   DALI_TEST_EQUALS( false, controlImpl.OnAccessibilityPan( pan ), TEST_LOCATION );
899
900   END_TEST;
901 }
902
903 int UtcDaliControlImplOnAccessibilityTouchP(void)
904 {
905   ToolkitTestApplication application;
906   Control dummy = Control::New();
907   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( dummy );
908   TouchEvent touch;
909   DALI_TEST_EQUALS( false, controlImpl.OnAccessibilityTouch( touch ), TEST_LOCATION );
910
911   END_TEST;
912 }
913
914 int UtcDaliControlImplOnAccessibilityActivatedP(void)
915 {
916   ToolkitTestApplication application;
917
918   Control dummy = Control::New();
919   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( dummy );
920   DALI_TEST_EQUALS( false, controlImpl.OnAccessibilityActivated(), TEST_LOCATION );
921
922   // Invoke the control's activate action
923   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "Control" );
924   DALI_TEST_CHECK( type );
925
926   BaseHandle handle = type.CreateInstance();
927   DALI_TEST_CHECK( handle );
928
929   Property::Map attributes;
930   DALI_TEST_EQUALS( false, handle.DoAction("accessibilityActivated",  attributes), TEST_LOCATION );
931
932   END_TEST;
933 }
934
935 int UtcDaliControlImplGetNextKeyboardFocusableActorP(void)
936 {
937   ToolkitTestApplication application;
938   Control dummy = Control::New();
939   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( dummy );
940
941   Actor currentFocusedActor;
942   Actor result = controlImpl.GetNextKeyboardFocusableActor( currentFocusedActor, Control::KeyboardFocus::LEFT, false );
943
944   DALI_TEST_EQUALS( result, currentFocusedActor, TEST_LOCATION );
945
946   END_TEST;
947 }
948
949 int UtcDaliControlImplRegisterThenReRegisterVisual(void)
950 {
951   ToolkitTestApplication application;
952
953   DummyControl dummy = DummyControl::New();
954   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
955
956   Property::Index index =1;
957
958   DALI_TEST_CHECK( !dummyImpl.GetVisual( index )  );
959
960   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
961   Toolkit::Visual::Base visual;
962
963   Property::Map map;
964   map[Visual::Property::TYPE] = Visual::COLOR;
965   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
966
967   visual = visualFactory.CreateVisual( map );
968   DALI_TEST_CHECK(visual);
969
970   // Register index with a color visual
971   dummyImpl.RegisterVisual( index, visual );
972
973   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
974
975   Property::Map newMap;
976   newMap[Visual::Property::TYPE] = Visual::COLOR;
977   newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE;
978
979   visual = visualFactory.CreateVisual( newMap );
980   DALI_TEST_CHECK(visual);
981
982   // ReRegister with altered color visual
983   dummyImpl.RegisterVisual( index, visual );
984
985   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
986
987   tet_result(TET_PASS);
988
989   END_TEST;
990 }
991
992 int UtcDaliControlImplRegisterVisaulThenReRegisterToSelf(void)
993 {
994   ToolkitTestApplication application;
995
996   DummyControl dummy = DummyControl::New();
997   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
998
999   Property::Index index =1;
1000
1001   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1002   Toolkit::Visual::Base visual;
1003
1004   Property::Map map;
1005   map[Visual::Property::TYPE] = Visual::COLOR;
1006   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1007
1008   visual = visualFactory.CreateVisual( map );
1009   DALI_TEST_CHECK(visual);
1010
1011   // Register index with a color visual
1012   dummyImpl.RegisterVisual( index, visual );
1013
1014   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
1015
1016   // ReRegister to self
1017   dummyImpl.RegisterVisual( index, visual );
1018
1019   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
1020
1021   END_TEST;
1022 }
1023
1024 int UtcDaliControlImplRegisterVisualToSelf(void)
1025 {
1026   ToolkitTestApplication application;
1027
1028   Test::ObjectDestructionTracker objectDestructionTracker;
1029
1030   {
1031     DummyControl dummy = DummyControl::New();
1032     DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1033     objectDestructionTracker.Start( dummy );
1034
1035     Property::Index index = 1;
1036
1037     Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1038     Toolkit::Visual::Base visual;
1039
1040     Property::Map map;
1041     map[Visual::Property::TYPE] = Visual::COLOR;
1042     map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1043
1044     visual = visualFactory.CreateVisual( map );
1045     DALI_TEST_CHECK(visual);
1046
1047     // Register to self
1048     dummyImpl.RegisterVisual( index, visual );
1049
1050     DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), false, TEST_LOCATION ); // Control not destroyed yet
1051     DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
1052   }
1053
1054   DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), true, TEST_LOCATION ); // Should be destroyed
1055
1056   END_TEST;
1057 }
1058
1059 int UtcDaliControlImplRegisterTwoVisuals(void)
1060 {
1061   ToolkitTestApplication application;
1062
1063   DummyControl dummy = DummyControl::New();
1064   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1065
1066   Property::Index index =1;
1067   Property::Index index2 =2;
1068
1069   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1070   Toolkit::Visual::Base visual;
1071   Toolkit::Visual::Base secondVisual;
1072
1073   Property::Map map;
1074   map[Visual::Property::TYPE] = Visual::COLOR;
1075   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1076
1077   visual = visualFactory.CreateVisual( map );
1078   DALI_TEST_CHECK(visual);
1079
1080   // Register index with a color visual
1081   dummyImpl.RegisterVisual( index, visual );
1082
1083   Property::Map newMap;
1084   newMap[Visual::Property::TYPE] = Visual::COLOR;
1085   newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE;
1086
1087   secondVisual = visualFactory.CreateVisual( newMap );
1088   DALI_TEST_CHECK( secondVisual );
1089
1090   // ReRegister with altered color visual
1091   dummyImpl.RegisterVisual( index2, secondVisual );
1092
1093   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
1094   DALI_TEST_CHECK( dummyImpl.GetVisual( index2 ) == secondVisual );
1095
1096   END_TEST;
1097 }
1098
1099 int UtcDaliControlImplRegisterUnregisterVisual(void)
1100 {
1101   ToolkitTestApplication application;
1102
1103   DummyControl dummy = DummyControl::New();
1104   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1105
1106   Property::Index index =1;
1107
1108   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1109   Toolkit::Visual::Base visual;
1110
1111   Property::Map map;
1112   map[Visual::Property::TYPE] = Visual::COLOR;
1113   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1114
1115   visual = visualFactory.CreateVisual( map );
1116   DALI_TEST_CHECK(visual);
1117
1118   // Register index with a color visual
1119   dummyImpl.RegisterVisual( index, visual );
1120
1121   tet_infoline( "Add control with visual to stage and check renderer count is 1" );
1122   Stage::GetCurrent().Add( dummy );
1123   application.SendNotification();
1124   application.Render();
1125
1126   DALI_TEST_CHECK( dummyImpl.GetVisual( index ) == visual );
1127   DALI_TEST_EQUALS( dummy.GetRendererCount(), 1, TEST_LOCATION );
1128
1129   // Unregister visual
1130   dummyImpl.UnregisterVisual( index );
1131
1132   tet_infoline( "Remove control with visual from stage and check renderer count is 0" );
1133   Stage::GetCurrent().Remove( dummy );
1134   application.SendNotification();
1135   application.Render();
1136
1137   DALI_TEST_EQUALS( dummy.GetRendererCount(), 0, TEST_LOCATION );
1138   DALI_TEST_CHECK( !dummyImpl.GetVisual( index ) );
1139
1140   END_TEST;
1141 }
1142
1143 int UtcDaliControlImplRegisterDisabledVisual(void)
1144 {
1145   ToolkitTestApplication application;
1146
1147   DummyControl dummy = DummyControl::New();
1148   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1149
1150   Property::Index TEST_PROPERTY =1;
1151
1152   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1153   Toolkit::Visual::Base visual;
1154
1155   Property::Map map;
1156   map[Visual::Property::TYPE] = Visual::COLOR;
1157   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1158
1159   visual = visualFactory.CreateVisual( map );
1160   DALI_TEST_CHECK(visual);
1161
1162   // Register index with a color visual
1163   dummyImpl.RegisterVisual( TEST_PROPERTY, visual, false );
1164
1165   DALI_TEST_CHECK( dummyImpl.GetVisual( TEST_PROPERTY ) == visual );
1166   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == false );
1167
1168   Stage::GetCurrent().Add(dummy);
1169
1170   // Render and notify
1171   application.SendNotification();
1172   application.Render();
1173
1174   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == false );
1175
1176   DALI_TEST_CHECK( dummy.OnStage() == true );
1177
1178   dummyImpl.EnableVisual( TEST_PROPERTY, true );
1179
1180   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == true );
1181
1182   END_TEST;
1183 }
1184
1185 int UtcDaliControlImplDisableRegisteredVisual(void)
1186 {
1187   ToolkitTestApplication application;
1188
1189   DummyControl dummy = DummyControl::New();
1190   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1191
1192   Property::Index TEST_PROPERTY =1;
1193
1194   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1195   Toolkit::Visual::Base visual;
1196
1197   Property::Map map;
1198   map[Visual::Property::TYPE] = Visual::COLOR;
1199   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1200
1201   visual = visualFactory.CreateVisual( map );
1202   DALI_TEST_CHECK(visual);
1203
1204   // Register index with a color visual
1205   dummyImpl.RegisterVisual( TEST_PROPERTY, visual );
1206
1207   Stage::GetCurrent().Add(dummy);
1208
1209   // Render and notify
1210   application.SendNotification();
1211   application.Render();
1212
1213   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == true);
1214
1215   DALI_TEST_CHECK( dummy.OnStage() == true );
1216
1217   dummyImpl.EnableVisual( TEST_PROPERTY, false );
1218
1219   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == false );
1220
1221   END_TEST;
1222 }
1223
1224 int UtcDaliControlImplEnabledVisualParentRemovedFromStage(void)
1225 {
1226   // Visual enabled but then parent removed from stage, test ensures visual/renderer are also removed from stage.
1227   // Then adding parent back to stage should automatically put visual/renderer back
1228
1229   ToolkitTestApplication application;
1230
1231   DummyControl dummy = DummyControl::New();
1232   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1233
1234   Property::Index TEST_PROPERTY =1;
1235
1236   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1237   Toolkit::Visual::Base visual;
1238
1239   Property::Map map;
1240   map[Visual::Property::TYPE] = Visual::COLOR;
1241   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1242
1243   visual = visualFactory.CreateVisual( map );
1244   DALI_TEST_CHECK(visual);
1245
1246   // Register index with a color visual
1247   dummyImpl.RegisterVisual( TEST_PROPERTY, visual, false );
1248
1249   Stage::GetCurrent().Add(dummy);
1250   // Render and notify
1251   application.SendNotification();
1252   application.Render();
1253
1254   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == false );
1255   DALI_TEST_CHECK( dummy.OnStage() == true );
1256   dummyImpl.EnableVisual( TEST_PROPERTY, true );
1257
1258   // Render and notify
1259   application.SendNotification();
1260   application.Render();
1261   DALI_TEST_CHECK( dummy.GetRendererCount() == 1u );
1262
1263   // Remove control from stage, visual should be removed from stage too
1264   Stage::GetCurrent().Remove(dummy);
1265   // Render and notify
1266   application.SendNotification();
1267   application.Render();
1268   DALI_TEST_CHECK( dummy.GetRendererCount() == 0u );
1269
1270   Stage::GetCurrent().Add(dummy);
1271   // Render and notify
1272   application.SendNotification();
1273   application.Render();
1274   DALI_TEST_CHECK( dummy.GetRendererCount() == 1u );
1275
1276   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY ) == true );
1277
1278   END_TEST;
1279 }
1280
1281 int UtcDaliControlImplRegisterTwoVisualsAndEnableOnlyOne(void)
1282 {
1283   // Register 2 visuals and enable by default
1284   // Disable 1 visual
1285   // Remove control from stage then put it back
1286   // Check that only 1 visual/renderer is staged.
1287
1288   ToolkitTestApplication application;
1289
1290   DummyControl dummy = DummyControl::New();
1291   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummy.GetImplementation());
1292
1293   Property::Index TEST_PROPERTY1 =1;
1294   Property::Index TEST_PROPERTY2 =2;
1295
1296   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1297   Toolkit::Visual::Base visual1;
1298   Toolkit::Visual::Base visual2;
1299
1300   Property::Map map;
1301   map[Visual::Property::TYPE] = Visual::COLOR;
1302   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1303
1304   Property::Map map2;
1305   map[Visual::Property::TYPE] = Visual::COLOR;
1306   map[ColorVisual::Property::MIX_COLOR] = Color::BLUE;
1307
1308   visual1 = visualFactory.CreateVisual( map );
1309   DALI_TEST_CHECK(visual1);
1310
1311   visual2 = visualFactory.CreateVisual( map );
1312   DALI_TEST_CHECK(visual2);
1313
1314   // Register index with a color visual
1315   dummyImpl.RegisterVisual( TEST_PROPERTY1, visual1 );
1316   // Register second index with a color visual
1317   dummyImpl.RegisterVisual( TEST_PROPERTY2, visual2 );
1318
1319   Stage::GetCurrent().Add(dummy);
1320   // Render and notify
1321   application.SendNotification();
1322   application.Render();
1323
1324   DALI_TEST_CHECK( dummy.GetRendererCount() == 2u );
1325   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY1 ) == true );
1326   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY1 ) == true);
1327   DALI_TEST_CHECK( dummy.OnStage() == true );
1328   dummyImpl.EnableVisual( TEST_PROPERTY2, false );
1329
1330   // Render and notify
1331   application.SendNotification();
1332   application.Render();
1333   DALI_TEST_CHECK( dummy.GetRendererCount() == 1u );
1334
1335   // Remove control from stage, visual should be removed from stage too
1336   Stage::GetCurrent().Remove(dummy);
1337   // Render and notify
1338   application.SendNotification();
1339   application.Render();
1340   DALI_TEST_CHECK( dummy.GetRendererCount() == 0u );
1341
1342   Stage::GetCurrent().Add(dummy);
1343   // Render and notify
1344   application.SendNotification();
1345   application.Render();
1346   DALI_TEST_CHECK( dummy.GetRendererCount() == 1u );
1347
1348   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY1 ) == true );
1349   DALI_TEST_CHECK( dummyImpl.IsVisualEnabled( TEST_PROPERTY2 ) == false );
1350
1351   END_TEST;
1352 }
1353 int UtcDaliControlImplAutoClippingWithVisuals(void)
1354 {
1355   ToolkitTestApplication application;
1356
1357   tet_infoline( "Test to ensure a renderer does NOT get added when we've already registered a visual which we haven't enabled" );
1358
1359   DummyControl control = DummyControl::New();
1360   DummyControlImpl& controlImpl = static_cast<DummyControlImpl&>( control.GetImplementation() );
1361
1362   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1363   Toolkit::Visual::Base visual;
1364   Property::Map map;
1365   map[Visual::Property::TYPE] = Visual::COLOR;
1366   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1367   visual = visualFactory.CreateVisual( map );
1368   DALI_TEST_CHECK(visual);
1369   controlImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual, false );
1370
1371   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
1372
1373   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1374
1375   Stage::GetCurrent().Add( control );
1376
1377   application.SendNotification();
1378   application.Render();
1379
1380   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
1381
1382   END_TEST;
1383 }
1384
1385 int UtcDaliControlImplAutoClippingWithVisualsAlreadyOnStage(void)
1386 {
1387   ToolkitTestApplication application;
1388
1389   tet_infoline( "Test to ensure a renderer does NOT get added when we've already registered a visual which we haven't enabled and we're already on the stage" );
1390
1391   DummyControl control = DummyControl::New();
1392   DummyControlImpl& controlImpl = static_cast<DummyControlImpl&>( control.GetImplementation() );
1393
1394   Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
1395   Toolkit::Visual::Base visual;
1396   Property::Map map;
1397   map[Visual::Property::TYPE] = Visual::COLOR;
1398   map[ColorVisual::Property::MIX_COLOR] = Color::RED;
1399   visual = visualFactory.CreateVisual( map );
1400   DALI_TEST_CHECK(visual);
1401   controlImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual, false );
1402
1403   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
1404
1405   Stage::GetCurrent().Add( control );
1406
1407   application.SendNotification();
1408   application.Render();
1409
1410   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1411
1412   application.SendNotification();
1413   application.Render();
1414
1415   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
1416
1417   END_TEST;
1418 }