9de71010201ab18e11be5b69a593580a5c475d63
[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   // set as Color
490   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
491   propValue = control.GetProperty( Control::Property::BACKGROUND );
492   resultMap = propValue.GetMap();
493   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
494   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
495
496   // Deprecated Properties
497   control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
498   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
499   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
500
501   control.ClearBackground();
502
503   Property::Map deprecatedImageMap;
504   deprecatedImageMap[ "filename" ] = "TestImage";
505   control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
506   propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
507   resultMap = propValue.GetMap();
508   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
509
510   control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
511   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
512
513   END_TEST;
514 }
515
516 int UtcDaliControlKeyProperties(void)
517 {
518   ToolkitTestApplication application;
519
520   Control control = Control::New();
521   Stage::GetCurrent().Add( control );
522
523   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
524
525   control.SetKeyInputFocus();
526   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
527
528   control.ClearKeyInputFocus();
529   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
530
531   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
532   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
533
534   END_TEST;
535 }
536
537 int UtcDaliControlGestureSignals(void)
538 {
539   ToolkitTestApplication application;
540   ConnectionTracker connectionTracker;
541   Control control = Control::New();
542
543   // Each gesture detector gets created when connecting to the gesture signals
544   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
545   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
546   DALI_TEST_CHECK( control.GetTapGestureDetector() );
547
548   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
549   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
550   DALI_TEST_CHECK( control.GetPanGestureDetector() );
551
552   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
553   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
554   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
555
556   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
557   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
558   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
559
560   END_TEST;
561 }
562
563 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
564 {
565   ToolkitTestApplication application;
566
567   Control control = Control::New();
568   Stage::GetCurrent().Add( control );
569
570   gKeyInputFocusCallBackCalled = false;
571   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
572
573   application.SendNotification();
574   application.Render();
575
576   control.SetKeyInputFocus();
577
578   DALI_TEST_CHECK( control.HasKeyInputFocus() );
579
580   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
581
582   END_TEST;
583 }
584
585 int UtcDaliControlImplKeyInputFocusLostSignal(void)
586 {
587   ToolkitTestApplication application;
588
589   Control control = Control::New();
590   Stage::GetCurrent().Add( control );
591
592   gKeyInputFocusCallBackCalled = false;
593   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
594
595   application.SendNotification();
596   application.Render();
597
598   control.SetKeyInputFocus();
599
600   DALI_TEST_CHECK( control.HasKeyInputFocus() );
601
602   control.ClearKeyInputFocus();
603
604   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
605
606   END_TEST;
607 }
608
609 int UtcDaliControlImplGetControlExtensionP(void)
610 {
611   ToolkitTestApplication application;
612   Control control = Control::New();
613
614   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
615
616   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
617
618   END_TEST;
619 }
620
621 int UtcDaliControlAutoClipping(void)
622 {
623   ToolkitTestApplication application;
624   Control control = Control::New();
625
626   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
627
628   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
629
630   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
631
632   Stage::GetCurrent().Add( control );
633
634   application.SendNotification();
635   application.Render();
636
637   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
638
639   END_TEST;
640 }
641
642 int UtcDaliControlAutoClippingN(void)
643 {
644   ToolkitTestApplication application;
645   Control control = Control::New();
646   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
647                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
648
649   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
650
651   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
652
653   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
654
655   Stage::GetCurrent().Add( control );
656
657   application.SendNotification();
658   application.Render();
659
660   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
661
662   // Ensure the background color is still RED rather than what's set by the automatic clipping
663   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
664   Property::Map* map = value.GetMap();
665   DALI_TEST_CHECK( map );
666   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
667   DALI_TEST_CHECK( colorValue );
668   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
669
670   END_TEST;
671 }
672
673 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
674 {
675   ToolkitTestApplication application;
676   Control control = Control::New();
677
678   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
679
680   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
681
682   Stage::GetCurrent().Add( control );
683
684   application.SendNotification();
685   application.Render();
686
687   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
688
689   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
690
691   application.SendNotification();
692   application.Render();
693
694   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
695
696   END_TEST;
697 }
698
699 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
700 {
701   ToolkitTestApplication application;
702   Control control = Control::New();
703   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
704                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
705
706   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" );
707
708   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
709
710   Stage::GetCurrent().Add( control );
711
712   application.SendNotification();
713   application.Render();
714
715   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
716
717   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
718
719   application.SendNotification();
720   application.Render();
721
722   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
723
724   // Ensure the background color is still RED rather than what's set by the automatic clipping
725   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
726   Property::Map* map = value.GetMap();
727   DALI_TEST_CHECK( map );
728   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
729   DALI_TEST_CHECK( colorValue );
730   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
731
732   END_TEST;
733 }
734
735 int UtcDaliControlSetTransformSize(void)
736 {
737   ToolkitTestApplication application;
738   Control control = Control::New();
739
740   Property::Map transformMap;
741   transformMap.Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
742               .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
743               .Add( DevelVisual::Transform::Property::ORIGIN, Align::BOTTOM_END )
744               .Add( DevelVisual::Transform::Property::SIZE, Vector2( 10, 20 ) );
745
746   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
747                                                                      .Add( DevelVisual::Property::TRANSFORM, transformMap ) );
748
749   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
750
751   Stage::GetCurrent().Add( control );
752
753   application.SendNotification();
754   application.Render();
755
756   // Ensure the transform property still matches what we set
757   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
758   Property::Map* map = value.GetMap();
759   DALI_TEST_CHECK( map );
760   Property::Value* transformValue = map->Find( DevelVisual::Property::TRANSFORM );
761   DALI_TEST_CHECK( transformValue );
762
763   Property::Map* retMap = transformValue->GetMap();
764   DALI_TEST_CHECK( retMap );
765   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
766   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
767   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
768   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
769
770   END_TEST;
771 }