376ad0d4466af26d2a26e2decf63df1174781709
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Control.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
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/align-enums.h>
29
30 #include "dummy-control.h"
31
32 using namespace Dali;
33 using namespace Dali::Toolkit;
34
35 void utc_dali_toolkit_control_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void utc_dali_toolkit_control_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 ///////////////////////////////////////////////////////////////////////////////////////////////////
46
47 namespace
48 {
49
50 bool gObjectCreatedCallBackCalled;
51
52 void TestCallback(BaseHandle handle)
53 {
54   gObjectCreatedCallBackCalled = true;
55 }
56
57 void TestVoidCallback()
58 {
59 }
60
61 static bool gKeyInputFocusCallBackCalled;
62
63 static void TestKeyInputFocusCallback( Control control )
64 {
65   tet_infoline(" TestKeyInputFocusCallback");
66
67   gKeyInputFocusCallBackCalled = true;
68 }
69
70 } // namespace
71
72 ///////////////////////////////////////////////////////////////////////////////////////////////////
73
74
75 int UtcDaliControlConstructor(void)
76 {
77   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
78
79   DummyControl dummy;
80
81   DALI_TEST_CHECK( !Control::DownCast(dummy) );
82
83   dummy = DummyControl::New();
84
85   DALI_TEST_CHECK( Control::DownCast(dummy) );
86   END_TEST;
87 }
88
89 int UtcDaliControlNew(void)
90 {
91   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
92
93   Control control;
94
95   DALI_TEST_CHECK( !Control::DownCast(control) );
96
97   control = Control::New();
98
99   DALI_TEST_CHECK( Control::DownCast(control) );
100   END_TEST;
101 }
102
103
104 int UtcDaliControlRegister(void)
105 {
106   ToolkitTestApplication application;
107
108   // Ensure the object is registered after creation
109   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
110   DALI_TEST_CHECK( registry );
111
112   gObjectCreatedCallBackCalled = false;
113   registry.ObjectCreatedSignal().Connect( &TestCallback );
114   {
115     Alignment alignment = Alignment::New();
116   }
117   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
118   END_TEST;
119 }
120
121 int UtcDaliControlCopyAndAssignment(void)
122 {
123   ToolkitTestApplication application;
124
125   DummyControl control = DummyControl::New();
126   Control emptyControl;
127
128   Control controlCopy( control );
129   DALI_TEST_CHECK( control == controlCopy );
130
131   Control emptyControlCopy( emptyControl );
132   DALI_TEST_CHECK( emptyControl == emptyControlCopy );
133
134   Control controlEquals;
135   controlEquals = control;
136   DALI_TEST_CHECK( control == controlEquals );
137
138   Control emptyControlEquals;
139   emptyControlEquals = emptyControl;
140   DALI_TEST_CHECK( emptyControl == emptyControlEquals );
141
142   // Self assignment
143   control = control;
144   DALI_TEST_CHECK( control == controlCopy );
145   END_TEST;
146 }
147
148 int UtcDaliControlDownCast(void)
149 {
150   ToolkitTestApplication application;
151
152   DummyControl control;
153
154   DALI_TEST_CHECK( !Control::DownCast( control ) );
155
156   control = DummyControl::New();
157
158   DALI_TEST_CHECK( Control::DownCast( control ) );
159
160   Actor actor;
161
162   DALI_TEST_CHECK( !Control::DownCast( actor ) );
163
164   actor = Actor::New();
165
166   DALI_TEST_CHECK( !Control::DownCast( actor ) );
167   END_TEST;
168 }
169
170 int UtcDaliControlDownCastTemplate(void)
171 {
172   ToolkitTestApplication application;
173
174   DummyControl control;
175
176   DALI_TEST_CHECK( !DummyControl::DownCast( control ));
177
178   control = DummyControl::New();
179
180   DALI_TEST_CHECK( DummyControl::DownCast( control ) );
181
182   Actor actor;
183
184   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
185
186   actor = Actor::New();
187
188   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
189   END_TEST;
190 }
191
192 int UtcDaliControlKeyInputFocus(void)
193 {
194   ToolkitTestApplication application;
195   Stage stage = Stage::GetCurrent();
196
197   DummyControl control;
198
199   PushButton pushButton1 = PushButton::New();
200   stage.Add( pushButton1 );
201
202   pushButton1.SetKeyInputFocus();
203   DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
204
205   pushButton1.ClearKeyInputFocus();
206   DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
207   END_TEST;
208 }
209
210 int UtcDaliControlGetImplementationN(void)
211 {
212   ToolkitTestApplication application;
213   DummyControl control;
214
215   // Get Empty
216   {
217     try
218     {
219       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
220       (void)controlImpl; // Avoid unused warning
221       tet_result(TET_FAIL);
222     }
223     catch (DaliException &exception)
224     {
225       tet_result(TET_PASS);
226     }
227   }
228   END_TEST;
229 }
230
231 int UtcDaliControlGetImplementationConstN(void)
232 {
233   ToolkitTestApplication application;
234   DummyControl control;
235
236   // Get Const Empty
237   {
238     try
239     {
240       const DummyControl constControl(control);
241       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
242       (void)controlImpl; // Avoid unused warning
243       tet_result(TET_FAIL);
244     }
245     catch (DaliException &exception)
246     {
247       tet_result(TET_PASS);
248     }
249   }
250   END_TEST;
251 }
252
253 int UtcDaliControlGetImplementationP(void)
254 {
255   ToolkitTestApplication application;
256   DummyControl control = DummyControl::New();
257
258   // Get
259   {
260     try
261     {
262       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
263       (void)controlImpl; // Avoid unused warning
264       tet_result(TET_PASS);
265     }
266     catch (DaliException &exception)
267     {
268       tet_result(TET_FAIL);
269     }
270   }
271   END_TEST;
272 }
273
274 int UtcDaliControlGetImplementationConstP(void)
275 {
276   ToolkitTestApplication application;
277   DummyControl control = DummyControl::New();
278   // Get Const
279   {
280     try
281     {
282       const DummyControl constControl(control);
283       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
284       (void)controlImpl; // Avoid unused warning
285       tet_result(TET_PASS);
286     }
287     catch (DaliException &exception)
288     {
289       tet_result(TET_FAIL);
290     }
291   }
292   END_TEST;
293 }
294
295 int UtcDaliControlSignalConnectDisconnect(void)
296 {
297   ToolkitTestApplication application;
298
299   {
300     DummyControl dummy = DummyControlImpl::New();
301
302     Actor actor = Actor::New();
303     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
304     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
305     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
306
307     if( dummyImpl == NULL )
308     {
309       tet_result( TET_FAIL );
310       END_TEST;
311     }
312
313     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
314     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
315     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
316
317     Stage::GetCurrent().Add( actor );
318     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
319
320     dummyImpl->mCustomSlot1Called = false;
321     actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
322     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
323     Stage::GetCurrent().Remove( actor );
324     Stage::GetCurrent().Add( actor );
325     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
326   }
327   END_TEST;
328 }
329
330 int UtcDaliControlSignalAutomaticDisconnect(void)
331 {
332   ToolkitTestApplication application;
333
334   Actor actor = Actor::New();
335
336   {
337     DummyControl dummy = DummyControlImpl::New();
338     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
339     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
340
341     if( dummyImpl == NULL )
342     {
343       tet_result( TET_FAIL );
344       END_TEST;
345     }
346
347     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
348     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
349     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
350
351     Stage::GetCurrent().Add( actor );
352     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
353     Stage::GetCurrent().Remove( actor );
354   }
355   // dummyControl automatically disconnects
356
357   DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
358
359   const Vector3 ignoredSize( 20, 20, 0 );
360   actor.SetSize( ignoredSize );
361   END_TEST;
362 }
363
364 int UtcDaliControlTestParameters(void)
365 {
366   ToolkitTestApplication application;
367   DummyControl test = DummyControl::New();
368
369   test.SetSize( 0.7f, 0.7f, 0.7f );
370
371   Stage::GetCurrent().Add( test );
372
373   application.SendNotification();
374   application.Render();
375
376   float width = 640.0f;
377   float height = test.GetHeightForWidth( width );
378   DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
379   DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
380
381   test.KeyEventSignal();
382
383   // Provide coverage for pointer destructor
384   Control* testControlPtr = new Control;
385   DALI_TEST_CHECK( testControlPtr );
386   delete testControlPtr;
387   END_TEST;
388 }
389
390 int UtcDaliControlBackgroundColor(void)
391 {
392   ToolkitTestApplication application;
393   Control control = Control::New();
394
395   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
396
397   control.SetBackgroundColor( Color::RED );
398
399   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
400   Property::Map* resultMap = propValue.GetMap();
401   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
402   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
403   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
404   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
405
406   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
407
408   control.SetBackgroundColor( Color::YELLOW );
409
410   propValue = control.GetProperty( Control::Property::BACKGROUND );
411   resultMap = propValue.GetMap();
412   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
413   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
414
415   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
416
417   END_TEST;
418 }
419
420 int UtcDaliControlBackgroundImage(void)
421 {
422   ToolkitTestApplication application;
423   Control control = Control::New();
424
425   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
426
427   Image image = ResourceImage::New("TestImage");
428   control.SetBackgroundImage( image );
429
430   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
431   Property::Map* resultMap = propValue.GetMap();
432   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
433   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
434   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
435   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
436
437   image = ResourceImage::New("TestImage2");
438   control.SetBackgroundImage( image );
439
440   propValue = control.GetProperty( Control::Property::BACKGROUND );
441   resultMap = propValue.GetMap();
442   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
443   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
444
445   END_TEST;
446 }
447
448 int UtcDaliControlBackgroundProperties(void)
449 {
450   ToolkitTestApplication application;
451   Control control = Control::New();
452
453   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
454   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
455
456   Property::Map imageMap;
457   imageMap[ Visual::Property::TYPE ] = Visual::IMAGE;
458   imageMap[ ImageVisual::Property::URL ] = "TestImage";
459   control.SetProperty( Control::Property::BACKGROUND, imageMap );
460   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
461   Property::Map* resultMap = propValue.GetMap();
462   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
463   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
464   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
465   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
466
467   Property::Map rendererMap;
468   rendererMap[Visual::Property::TYPE] = Visual::COLOR;
469   rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
470   control.SetProperty( Control::Property::BACKGROUND, rendererMap );
471   propValue = control.GetProperty( Control::Property::BACKGROUND );
472   resultMap = propValue.GetMap();
473   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
474   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
475   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
476   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
477
478   Property::Map emptyMap;
479   control.SetProperty( Control::Property::BACKGROUND, emptyMap );
480   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
481
482   // set as URL
483   control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
484   propValue = control.GetProperty( Control::Property::BACKGROUND );
485   resultMap = propValue.GetMap();
486   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
487   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
488
489   // Deprecated Properties
490   control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
491   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
492   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
493
494   control.ClearBackground();
495
496   Property::Map deprecatedImageMap;
497   deprecatedImageMap[ "filename" ] = "TestImage";
498   control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
499   propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
500   resultMap = propValue.GetMap();
501   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
502
503   control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
504   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
505
506   END_TEST;
507 }
508
509 int UtcDaliControlKeyProperties(void)
510 {
511   ToolkitTestApplication application;
512
513   Control control = Control::New();
514   Stage::GetCurrent().Add( control );
515
516   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
517
518   control.SetKeyInputFocus();
519   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
520
521   control.ClearKeyInputFocus();
522   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
523
524   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
525   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
526
527   END_TEST;
528 }
529
530 int UtcDaliControlGestureSignals(void)
531 {
532   ToolkitTestApplication application;
533   ConnectionTracker connectionTracker;
534   Control control = Control::New();
535
536   // Each gesture detector gets created when connecting to the gesture signals
537   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
538   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
539   DALI_TEST_CHECK( control.GetTapGestureDetector() );
540
541   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
542   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
543   DALI_TEST_CHECK( control.GetPanGestureDetector() );
544
545   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
546   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
547   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
548
549   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
550   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
551   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
552
553   END_TEST;
554 }
555
556 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
557 {
558   ToolkitTestApplication application;
559
560   Control control = Control::New();
561   Stage::GetCurrent().Add( control );
562
563   gKeyInputFocusCallBackCalled = false;
564   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
565
566   application.SendNotification();
567   application.Render();
568
569   control.SetKeyInputFocus();
570
571   DALI_TEST_CHECK( control.HasKeyInputFocus() );
572
573   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
574
575   END_TEST;
576 }
577
578 int UtcDaliControlImplKeyInputFocusLostSignal(void)
579 {
580   ToolkitTestApplication application;
581
582   Control control = Control::New();
583   Stage::GetCurrent().Add( control );
584
585   gKeyInputFocusCallBackCalled = false;
586   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
587
588   application.SendNotification();
589   application.Render();
590
591   control.SetKeyInputFocus();
592
593   DALI_TEST_CHECK( control.HasKeyInputFocus() );
594
595   control.ClearKeyInputFocus();
596
597   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
598
599   END_TEST;
600 }
601
602 int UtcDaliControlImplGetControlExtensionP(void)
603 {
604   ToolkitTestApplication application;
605   Control control = Control::New();
606
607   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
608
609   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
610
611   END_TEST;
612 }
613
614 int UtcDaliControlAutoClipping(void)
615 {
616   ToolkitTestApplication application;
617   Control control = Control::New();
618
619   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
620
621   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
622
623   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
624
625   Stage::GetCurrent().Add( control );
626
627   application.SendNotification();
628   application.Render();
629
630   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
631
632   END_TEST;
633 }
634
635 int UtcDaliControlAutoClippingN(void)
636 {
637   ToolkitTestApplication application;
638   Control control = Control::New();
639   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
640                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
641
642   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
643
644   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
645
646   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
647
648   Stage::GetCurrent().Add( control );
649
650   application.SendNotification();
651   application.Render();
652
653   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
654
655   // Ensure the background color is still RED rather than what's set by the automatic clipping
656   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
657   Property::Map* map = value.GetMap();
658   DALI_TEST_CHECK( map );
659   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
660   DALI_TEST_CHECK( colorValue );
661   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
662
663   END_TEST;
664 }
665
666 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
667 {
668   ToolkitTestApplication application;
669   Control control = Control::New();
670
671   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
672
673   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
674
675   Stage::GetCurrent().Add( control );
676
677   application.SendNotification();
678   application.Render();
679
680   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
681
682   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
683
684   application.SendNotification();
685   application.Render();
686
687   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
688
689   END_TEST;
690 }
691
692 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
693 {
694   ToolkitTestApplication application;
695   Control control = Control::New();
696   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
697                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
698
699   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals and when already on stage" );
700
701   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
702
703   Stage::GetCurrent().Add( control );
704
705   application.SendNotification();
706   application.Render();
707
708   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
709
710   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
711
712   application.SendNotification();
713   application.Render();
714
715   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
716
717   // Ensure the background color is still RED rather than what's set by the automatic clipping
718   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
719   Property::Map* map = value.GetMap();
720   DALI_TEST_CHECK( map );
721   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
722   DALI_TEST_CHECK( colorValue );
723   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
724
725   END_TEST;
726 }
727
728 int UtcDaliControlSetTransformSize(void)
729 {
730   ToolkitTestApplication application;
731   Control control = Control::New();
732
733   Property::Map transformMap;
734   transformMap.Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
735               .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
736               .Add( DevelVisual::Transform::Property::ORIGIN, Align::BOTTOM_END )
737               .Add( DevelVisual::Transform::Property::SIZE, Vector2( 10, 20 ) );
738
739   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
740                                                                      .Add( DevelVisual::Property::TRANSFORM, transformMap ) );
741
742   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
743
744   Stage::GetCurrent().Add( control );
745
746   application.SendNotification();
747   application.Render();
748
749   // Ensure the transform property still matches what we set
750   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
751   Property::Map* map = value.GetMap();
752   DALI_TEST_CHECK( map );
753   Property::Value* transformValue = map->Find( DevelVisual::Property::TRANSFORM );
754   DALI_TEST_CHECK( transformValue );
755
756   Property::Map* retMap = transformValue->GetMap();
757   DALI_TEST_CHECK( retMap );
758   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
759   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
760   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
761   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
762
763   END_TEST;
764 }