[dali_2.0.5] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Control.cpp
1 /*
2  * Copyright (c) 2020 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/public-api/align-enumerations.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/controls/alignment/alignment.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
32
33
34 #include <toolkit-event-thread-callback.h>
35
36 #include "dummy-control.h"
37
38 using namespace Dali;
39 using namespace Dali::Toolkit;
40
41 void utc_dali_toolkit_control_startup(void)
42 {
43   test_return_value = TET_UNDEF;
44 }
45
46 void utc_dali_toolkit_control_cleanup(void)
47 {
48   test_return_value = TET_PASS;
49 }
50
51 ///////////////////////////////////////////////////////////////////////////////////////////////////
52
53 namespace
54 {
55
56 bool gObjectCreatedCallBackCalled;
57
58 void TestCallback(BaseHandle handle)
59 {
60   gObjectCreatedCallBackCalled = true;
61 }
62
63 void TestVoidCallback()
64 {
65 }
66
67 static bool gKeyInputFocusCallBackCalled;
68
69 static void TestKeyInputFocusCallback( Control control )
70 {
71   tet_infoline(" TestKeyInputFocusCallback");
72
73   gKeyInputFocusCallBackCalled = true;
74 }
75
76 const char* TEST_LARGE_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/tbcol.png";
77 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/gallery-small-1.jpg";
78 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/Kid1.svg";
79
80 Vector4 GetControlBackgroundColor( Control& control )
81 {
82   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
83   Property::Map* resultMap = propValue.GetMap();
84   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
85
86   Vector4 color;
87   resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get( color );
88
89   return color;
90 }
91
92 bool gResourceReadySignalFired = false;
93
94 void ResourceReadySignal( Control control )
95 {
96   if( control.GetVisualResourceStatus( Control::Property::BACKGROUND ) == Visual::ResourceStatus::FAILED )
97   {
98     Property::Map propertyMap;
99     propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
100     control.SetProperty( Control::Property::BACKGROUND, propertyMap );
101   }
102
103   gResourceReadySignalFired = true;
104 }
105
106 } // namespace
107
108 ///////////////////////////////////////////////////////////////////////////////////////////////////
109
110
111 int UtcDaliControlConstructor(void)
112 {
113   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
114
115   DummyControl dummy;
116
117   DALI_TEST_CHECK( !Control::DownCast(dummy) );
118
119   dummy = DummyControl::New();
120
121   DALI_TEST_CHECK( Control::DownCast(dummy) );
122   END_TEST;
123 }
124
125 int UtcDaliControlNew(void)
126 {
127   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
128
129   Control control;
130
131   DALI_TEST_CHECK( !Control::DownCast(control) );
132
133   control = Control::New();
134
135   DALI_TEST_CHECK( Control::DownCast(control) );
136   END_TEST;
137 }
138
139
140 int UtcDaliControlRegister(void)
141 {
142   ToolkitTestApplication application;
143
144   // Ensure the object is registered after creation
145   ObjectRegistry registry = application.GetCore().GetObjectRegistry();
146   DALI_TEST_CHECK( registry );
147
148   gObjectCreatedCallBackCalled = false;
149   registry.ObjectCreatedSignal().Connect( &TestCallback );
150   {
151     Alignment alignment = Alignment::New();
152   }
153   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
154   END_TEST;
155 }
156
157 int UtcDaliControlCopyAndAssignment(void)
158 {
159   ToolkitTestApplication application;
160
161   DummyControl control = DummyControl::New();
162   Control emptyControl;
163
164   Control controlCopy( control );
165   DALI_TEST_CHECK( control == controlCopy );
166
167   Control emptyControlCopy( emptyControl );
168   DALI_TEST_CHECK( emptyControl == emptyControlCopy );
169
170   Control controlEquals;
171   controlEquals = control;
172   DALI_TEST_CHECK( control == controlEquals );
173
174   Control emptyControlEquals;
175   emptyControlEquals = emptyControl;
176   DALI_TEST_CHECK( emptyControl == emptyControlEquals );
177
178   // Self assignment
179   control = control;
180   DALI_TEST_CHECK( control == controlCopy );
181   END_TEST;
182 }
183
184 int UtcDaliControlMoveConstructor(void)
185 {
186   ToolkitTestApplication application;
187
188   Control control = Control::New();
189   DALI_TEST_EQUALS( 1, control.GetBaseObject().ReferenceCount(), TEST_LOCATION );
190   control.SetProperty( Actor::Property::SENSITIVE, false );
191   DALI_TEST_CHECK( false == control.GetProperty< bool >( Actor::Property::SENSITIVE ) );
192
193   Control moved = std::move( control );
194   DALI_TEST_CHECK( moved );
195   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
196   DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
197   DALI_TEST_CHECK( !control );
198
199   END_TEST;
200 }
201
202 int UtcDaliControlMoveAssignment(void)
203 {
204   ToolkitTestApplication application;
205
206   Control control = Control::New();
207   DALI_TEST_EQUALS( 1, control.GetBaseObject().ReferenceCount(), TEST_LOCATION );
208   control.SetProperty( Actor::Property::SENSITIVE, false );
209   DALI_TEST_CHECK( false == control.GetProperty< bool >( Actor::Property::SENSITIVE ) );
210
211   Control moved;
212   moved = std::move( control );
213   DALI_TEST_CHECK( moved );
214   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
215   DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
216   DALI_TEST_CHECK( !control );
217
218   END_TEST;
219 }
220
221 int UtcDaliControlDownCast(void)
222 {
223   ToolkitTestApplication application;
224
225   DummyControl control;
226
227   DALI_TEST_CHECK( !Control::DownCast( control ) );
228
229   control = DummyControl::New();
230
231   DALI_TEST_CHECK( Control::DownCast( control ) );
232
233   Actor actor;
234
235   DALI_TEST_CHECK( !Control::DownCast( actor ) );
236
237   actor = Actor::New();
238
239   DALI_TEST_CHECK( !Control::DownCast( actor ) );
240   END_TEST;
241 }
242
243 int UtcDaliControlDownCastTemplate(void)
244 {
245   ToolkitTestApplication application;
246
247   DummyControl control;
248
249   DALI_TEST_CHECK( !DummyControl::DownCast( control ));
250
251   control = DummyControl::New();
252
253   DALI_TEST_CHECK( DummyControl::DownCast( control ) );
254
255   Actor actor;
256
257   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
258
259   actor = Actor::New();
260
261   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
262   END_TEST;
263 }
264
265 int UtcDaliControlNavigationProperties(void)
266 {
267   ToolkitTestApplication application;
268
269   Control control = Control::New();
270   application.GetScene().Add( control );
271
272   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
273   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
274   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
275   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
276
277   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
278   DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
279   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
280   DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
281   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
282   DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
283   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
284   DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
285
286   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
287   DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
288   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
289   DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
290   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
291   DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
292   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
293   DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
294
295   END_TEST;
296 }
297
298 int UtcDaliControlKeyInputFocus(void)
299 {
300   ToolkitTestApplication application;
301   Integration::Scene stage = application.GetScene();
302
303   DummyControl control;
304
305   PushButton pushButton1 = PushButton::New();
306   stage.Add( pushButton1 );
307
308   pushButton1.SetKeyInputFocus();
309   DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
310
311   pushButton1.ClearKeyInputFocus();
312   DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
313   END_TEST;
314 }
315
316 int UtcDaliControlGetImplementationN(void)
317 {
318   ToolkitTestApplication application;
319   DummyControl control;
320
321   // Get Empty
322   {
323     try
324     {
325       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
326       (void)controlImpl; // Avoid unused warning
327       tet_result(TET_FAIL);
328     }
329     catch (DaliException &exception)
330     {
331       tet_result(TET_PASS);
332     }
333   }
334   END_TEST;
335 }
336
337 int UtcDaliControlGetImplementationConstN(void)
338 {
339   ToolkitTestApplication application;
340   DummyControl control;
341
342   // Get Const Empty
343   {
344     try
345     {
346       const DummyControl constControl(control);
347       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
348       (void)controlImpl; // Avoid unused warning
349       tet_result(TET_FAIL);
350     }
351     catch (DaliException &exception)
352     {
353       tet_result(TET_PASS);
354     }
355   }
356   END_TEST;
357 }
358
359 int UtcDaliControlGetImplementationP(void)
360 {
361   ToolkitTestApplication application;
362   DummyControl control = DummyControl::New();
363
364   // Get
365   {
366     try
367     {
368       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
369       (void)controlImpl; // Avoid unused warning
370       tet_result(TET_PASS);
371     }
372     catch (DaliException &exception)
373     {
374       tet_result(TET_FAIL);
375     }
376   }
377   END_TEST;
378 }
379
380 int UtcDaliControlGetImplementationConstP(void)
381 {
382   ToolkitTestApplication application;
383   DummyControl control = DummyControl::New();
384   // Get Const
385   {
386     try
387     {
388       const DummyControl constControl(control);
389       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
390       (void)controlImpl; // Avoid unused warning
391       tet_result(TET_PASS);
392     }
393     catch (DaliException &exception)
394     {
395       tet_result(TET_FAIL);
396     }
397   }
398   END_TEST;
399 }
400
401 int UtcDaliControlSignalConnectDisconnect(void)
402 {
403   ToolkitTestApplication application;
404
405   {
406     DummyControl dummy = DummyControlImpl::New();
407
408     Actor actor = Actor::New();
409     DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION );
410     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
411     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
412
413     if( dummyImpl == NULL )
414     {
415       tet_result( TET_FAIL );
416       END_TEST;
417     }
418
419     actor.OnSceneSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
420     DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 1u, TEST_LOCATION );
421     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
422
423     application.GetScene().Add( actor );
424     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
425
426     dummyImpl->mCustomSlot1Called = false;
427     actor.OnSceneSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
428     DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION );
429     application.GetScene().Remove( actor );
430     application.GetScene().Add( actor );
431     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
432   }
433   END_TEST;
434 }
435
436 int UtcDaliControlSignalAutomaticDisconnect(void)
437 {
438   ToolkitTestApplication application;
439
440   Actor actor = Actor::New();
441
442   {
443     DummyControl dummy = DummyControlImpl::New();
444     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
445     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
446
447     if( dummyImpl == NULL )
448     {
449       tet_result( TET_FAIL );
450       END_TEST;
451     }
452
453     actor.OnSceneSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
454     DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 1u, TEST_LOCATION );
455     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
456
457     application.GetScene().Add( actor );
458     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
459     application.GetScene().Remove( actor );
460   }
461   // dummyControl automatically disconnects
462
463   DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION );
464
465   const Vector3 ignoredSize( 20, 20, 0 );
466   actor.SetProperty( Actor::Property::SIZE, ignoredSize );
467   END_TEST;
468 }
469
470 int UtcDaliControlTestParameters(void)
471 {
472   ToolkitTestApplication application;
473   DummyControl test = DummyControl::New();
474
475   test.SetProperty( Actor::Property::SIZE, Vector3( 0.7f, 0.7f, 0.7f ) );
476
477   application.GetScene().Add( test );
478
479   application.SendNotification();
480   application.Render();
481
482   float width = 640.0f;
483   float height = test.GetHeightForWidth( width );
484   DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
485   DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
486
487   test.KeyEventSignal();
488
489   // Provide coverage for pointer destructor
490   Control* testControlPtr = new Control;
491   DALI_TEST_CHECK( testControlPtr );
492   delete testControlPtr;
493   END_TEST;
494 }
495
496 int UtcDaliControlBackgroundColor(void)
497 {
498   ToolkitTestApplication application;
499   Control control = Control::New();
500
501   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
502
503   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
504
505   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
506   Property::Map* resultMap = propValue.GetMap();
507   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
508   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
509   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
510   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
511
512   control.SetProperty( Control::Property::BACKGROUND, Color::YELLOW );
513
514   propValue = control.GetProperty( Control::Property::BACKGROUND );
515   resultMap = propValue.GetMap();
516   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
517   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
518
519   END_TEST;
520 }
521
522 int UtcDaliControlBackgroundColorRendererCount(void)
523 {
524   tet_infoline( "Test ensures we only create renderers when non-transparent color is requested or if we our clipping-mode is set to CLIP_CHILDREN" );
525
526   ToolkitTestApplication application;
527   Control control = Control::New();
528   application.GetScene().Add( control );
529
530   tet_infoline( "Set transparent, no renderers should be created" );
531   control.SetBackgroundColor( Color::TRANSPARENT );
532   application.SendNotification();
533   application.Render();
534   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
535
536   tet_infoline( "Set transparent alpha with positive RGB values, no renderers should be created, but returned color should reflect what we set" );
537   const Vector4 alphaZero( 1.0f, 0.5f, 0.25f, 0.0f );
538   control.SetBackgroundColor( alphaZero );
539   application.SendNotification();
540   application.Render();
541   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
542   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), alphaZero, TEST_LOCATION );
543
544   tet_infoline( "Set semi transparent alpha with positive RGB values, 1 renderer should be created, but returned color should reflect what we set" );
545   const Vector4 semiTransparent( 1.0f, 0.75f, 0.5f, 0.5f );
546   control.SetBackgroundColor( semiTransparent );
547   application.SendNotification();
548   application.Render();
549   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
550   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), semiTransparent, TEST_LOCATION );
551
552   Renderer renderer = control.GetRendererAt( 0 );
553   DALI_TEST_CHECK( renderer );
554
555   tet_infoline( "Set semi transparent alpha with positive RGB values, renderer should not be changed" );
556   const Vector4 newColor( 1.0f, 1.0f, 0.5f, 0.5f );
557   control.SetBackgroundColor( newColor );
558   application.SendNotification();
559   application.Render();
560   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
561   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), newColor, TEST_LOCATION );
562   DALI_TEST_EQUALS( renderer, control.GetRendererAt( 0 ), TEST_LOCATION );
563
564   tet_infoline( "Set transparent, ensure no renderers are created" );
565   control.SetBackgroundColor( Color::TRANSPARENT );
566   application.SendNotification();
567   application.Render();
568   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
569   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
570
571   tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" );
572   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
573   application.SendNotification();
574   application.Render();
575   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
576   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
577
578   tet_infoline( "Set a color, only 1 renderer should exist" );
579   control.SetBackgroundColor( Color::RED );
580   application.SendNotification();
581   application.Render();
582   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
583   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::RED, TEST_LOCATION );
584
585   tet_infoline( "Clear the background, no renderers" );
586   control.ClearBackground();
587   application.SendNotification();
588   application.Render();
589   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
590
591   tet_infoline( "Set control to clip its children again, a renderer should be created which will be transparent" );
592   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
593   application.SendNotification();
594   application.Render();
595   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
596   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
597
598   tet_infoline( "Disable clipping, no renderers" );
599   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
600   application.SendNotification();
601   application.Render();
602   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
603   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
604
605   END_TEST;
606 }
607
608 int UtcDaliControlBackgroundImage(void)
609 {
610   ToolkitTestApplication application;
611   Control control = Control::New();
612
613   tet_infoline( "Set first background image" );
614   control.SetProperty( Control::Property::BACKGROUND, "TestImage" );
615
616   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
617   Property::Map* resultMap = propValue.GetMap();
618   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
619   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
620   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
621   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
622
623   tet_infoline( "Set replacement background image" );
624   control.SetProperty( Control::Property::BACKGROUND, "TestImage2" );
625
626   propValue = control.GetProperty( Control::Property::BACKGROUND );
627   resultMap = propValue.GetMap();
628   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
629   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
630
631   END_TEST;
632 }
633
634 int UtcDaliControlBackgroundProperties(void)
635 {
636   ToolkitTestApplication application;
637   Control control = Control::New();
638
639   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
640
641   Property::Map imageMap;
642   imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
643   imageMap[ ImageVisual::Property::URL ] = "TestImage";
644   control.SetProperty( Control::Property::BACKGROUND, imageMap );
645   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
646   Property::Map* resultMap = propValue.GetMap();
647   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
648   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
649   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
650   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
651
652   Property::Map rendererMap;
653   rendererMap[Visual::Property::TYPE] = Visual::COLOR;
654   rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
655   control.SetProperty( Control::Property::BACKGROUND, rendererMap );
656   propValue = control.GetProperty( Control::Property::BACKGROUND );
657   resultMap = propValue.GetMap();
658   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
659   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
660   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
661   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
662
663   Property::Map emptyMap;
664   control.SetProperty( Control::Property::BACKGROUND, emptyMap );
665   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
666
667   // set as URL
668   control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
669   propValue = control.GetProperty( Control::Property::BACKGROUND );
670   resultMap = propValue.GetMap();
671   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
672   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
673
674   // set as Color
675   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
676   propValue = control.GetProperty( Control::Property::BACKGROUND );
677   resultMap = propValue.GetMap();
678   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
679   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
680
681   END_TEST;
682 }
683
684 int UtcDaliControlShadowProperties(void)
685 {
686   ToolkitTestApplication application;
687   Control control = Control::New();
688
689   DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
690
691   Property::Map imageMap;
692   imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
693   imageMap[ ImageVisual::Property::URL ] = "TestImage";
694   control.SetProperty( DevelControl::Property::SHADOW, imageMap );
695   Property::Value propValue = control.GetProperty( DevelControl::Property::SHADOW );
696   Property::Map* resultMap = propValue.GetMap();
697   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
698   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
699   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
700   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
701
702   Property::Map colorMap;
703   colorMap[Visual::Property::TYPE] = Visual::COLOR;
704   colorMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
705   control.SetProperty( DevelControl::Property::SHADOW, colorMap );
706   propValue = control.GetProperty( DevelControl::Property::SHADOW );
707   resultMap = propValue.GetMap();
708   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
709   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
710   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
711   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
712
713   Property::Map emptyMap;
714   control.SetProperty( DevelControl::Property::SHADOW, emptyMap );
715   DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
716
717   END_TEST;
718 }
719
720 int UtcDaliControlKeyProperties(void)
721 {
722   ToolkitTestApplication application;
723
724   Control control = Control::New();
725   application.GetScene().Add( control );
726
727   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
728
729   control.SetKeyInputFocus();
730   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
731
732   control.ClearKeyInputFocus();
733   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
734
735   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
736   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
737
738   END_TEST;
739 }
740
741 int UtcDaliControlGestureSignals(void)
742 {
743   ToolkitTestApplication application;
744   ConnectionTracker connectionTracker;
745   Control control = Control::New();
746
747   // Each gesture detector gets created when connecting to the gesture signals
748   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
749   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
750   DALI_TEST_CHECK( control.GetTapGestureDetector() );
751
752   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
753   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
754   DALI_TEST_CHECK( control.GetPanGestureDetector() );
755
756   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
757   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
758   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
759
760   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
761   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
762   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
763
764   END_TEST;
765 }
766
767 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
768 {
769   ToolkitTestApplication application;
770
771   Control control = Control::New();
772   application.GetScene().Add( control );
773
774   gKeyInputFocusCallBackCalled = false;
775   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
776
777   application.SendNotification();
778   application.Render();
779
780   control.SetKeyInputFocus();
781
782   DALI_TEST_CHECK( control.HasKeyInputFocus() );
783
784   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
785
786   END_TEST;
787 }
788
789 int UtcDaliControlImplKeyInputFocusLostSignal(void)
790 {
791   ToolkitTestApplication application;
792
793   Control control = Control::New();
794   application.GetScene().Add( control );
795
796   gKeyInputFocusCallBackCalled = false;
797   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
798
799   application.SendNotification();
800   application.Render();
801
802   control.SetKeyInputFocus();
803
804   DALI_TEST_CHECK( control.HasKeyInputFocus() );
805
806   control.ClearKeyInputFocus();
807
808   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
809
810   END_TEST;
811 }
812
813 int UtcDaliControlImplGetControlExtensionP(void)
814 {
815   ToolkitTestApplication application;
816   Control control = Control::New();
817
818   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
819
820   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
821
822   END_TEST;
823 }
824
825 int UtcDaliControlAutoClipping(void)
826 {
827   ToolkitTestApplication application;
828   Control control = Control::New();
829
830   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
831
832   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
833
834   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
835
836   application.GetScene().Add( control );
837
838   application.SendNotification();
839   application.Render();
840
841   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
842
843   END_TEST;
844 }
845
846 int UtcDaliControlAutoClippingN(void)
847 {
848   ToolkitTestApplication application;
849   Control control = Control::New();
850   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
851                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
852
853   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
854
855   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
856
857   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
858
859   application.GetScene().Add( control );
860
861   application.SendNotification();
862   application.Render();
863
864   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
865
866   // Ensure the background color is still RED rather than what's set by the automatic clipping
867   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
868   Property::Map* map = value.GetMap();
869   DALI_TEST_CHECK( map );
870   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
871   DALI_TEST_CHECK( colorValue );
872   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
873
874   END_TEST;
875 }
876
877 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
878 {
879   ToolkitTestApplication application;
880   Control control = Control::New();
881
882   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
883
884   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
885
886   application.GetScene().Add( control );
887
888   application.SendNotification();
889   application.Render();
890
891   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
892
893   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
894
895   application.SendNotification();
896   application.Render();
897
898   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
899
900   END_TEST;
901 }
902
903 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
904 {
905   ToolkitTestApplication application;
906   Control control = Control::New();
907   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
908                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
909
910   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" );
911
912   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
913
914   application.GetScene().Add( control );
915
916   application.SendNotification();
917   application.Render();
918
919   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
920
921   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
922
923   application.SendNotification();
924   application.Render();
925
926   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
927
928   // Ensure the background color is still RED rather than what's set by the automatic clipping
929   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
930   Property::Map* map = value.GetMap();
931   DALI_TEST_CHECK( map );
932   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
933   DALI_TEST_CHECK( colorValue );
934   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
935
936   END_TEST;
937 }
938
939 int UtcDaliControlSetTransformSize(void)
940 {
941   ToolkitTestApplication application;
942   Control control = Control::New();
943
944   Property::Map transformMap;
945   transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
946               .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
947               .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
948               .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
949
950   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
951                                                                      .Add( Visual::Property::TRANSFORM, transformMap ) );
952
953   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
954
955   application.GetScene().Add( control );
956
957   application.SendNotification();
958   application.Render();
959
960   // Ensure the transform property still matches what we set
961   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
962   Property::Map* map = value.GetMap();
963   DALI_TEST_CHECK( map );
964   Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
965   DALI_TEST_CHECK( transformValue );
966
967   Property::Map* retMap = transformValue->GetMap();
968   DALI_TEST_CHECK( retMap );
969   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
970   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
971   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
972   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
973
974   END_TEST;
975 }
976
977
978 int UtcDaliControlResourcesReady(void)
979 {
980   ToolkitTestApplication application;
981   tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
982
983   VisualFactory factory = VisualFactory::Get();
984   DALI_TEST_CHECK( factory );
985
986   Property::Map propertyMapLarge;
987   propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
988   propertyMapLarge.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
989
990   Property::Map propertyMapSmall;
991   propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
992   propertyMapSmall.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
993
994   Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
995   smallVisual.SetName("smallVisual");
996   DALI_TEST_CHECK( smallVisual );
997
998   DummyControl actor = DummyControl::New();
999   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1000
1001   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
1002
1003   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1004
1005   Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1006   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1007   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1008   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
1009
1010   application.GetScene().Add( actor );
1011   application.SendNotification();
1012   application.Render();
1013
1014   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1015
1016   application.SendNotification();
1017   application.Render();
1018
1019   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1020   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1021   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1022   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
1023
1024   Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
1025   largeVisual.SetName("largeVisual");
1026   DALI_TEST_CHECK( largeVisual );
1027
1028   tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
1029
1030   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
1031
1032   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
1033   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
1034
1035   application.SendNotification();
1036
1037   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
1038   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1039   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1040   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
1041
1042   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
1043
1044   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1045
1046   application.SendNotification();
1047
1048   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
1049   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
1050
1051   END_TEST;
1052 }
1053
1054 int UtcDaliControlResourcesReady02(void)
1055 {
1056   ToolkitTestApplication application;
1057   tet_infoline( "Change a resource during ResourceReady callback" );
1058
1059   gResourceReadySignalFired = false;
1060
1061   Control control = Control::New();
1062   control.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1063   control.ResourceReadySignal().Connect( &ResourceReadySignal );
1064
1065   Property::Map propertyMap;
1066   propertyMap.Insert( ImageVisual::Property::URL, "invalid.jpg" );
1067   control.SetProperty( Control::Property::BACKGROUND, propertyMap );
1068
1069   application.GetScene().Add( control );
1070
1071   application.SendNotification();
1072   application.Render();
1073
1074   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1075
1076   application.SendNotification();
1077   application.Render();
1078
1079   DALI_TEST_EQUALS( control.IsResourceReady(), true, TEST_LOCATION );
1080   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1081   gResourceReadySignalFired = false;
1082
1083   END_TEST;
1084 }
1085
1086 int UtcDaliControlMarginProperty(void)
1087 {
1088   ToolkitTestApplication application;
1089
1090   Control control = Control::New();
1091   control.SetBackgroundColor( Color::BLUE );
1092
1093   control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
1094
1095   application.GetScene().Add( control );
1096
1097   application.SendNotification();
1098   application.Render();
1099
1100   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
1101
1102   // Parent control has one ImageView as a Child.
1103   ImageView image = ImageView::New();
1104   image.SetBackgroundColor( Color::RED );
1105   image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1106   image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
1107   control.Add( image );
1108
1109   application.SendNotification();
1110   application.Render();
1111
1112   DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
1113
1114   END_TEST;
1115 }
1116
1117 int UtcDaliControlPaddingProperty(void)
1118 {
1119   ToolkitTestApplication application;
1120
1121   Control control = Control::New();
1122   control.SetBackgroundColor( Color::BLUE );
1123
1124   control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1125
1126   application.GetScene().Add( control );
1127
1128   application.SendNotification();
1129   application.Render();
1130
1131   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1132
1133   Control child = Control::New();
1134   control.Add(child);
1135
1136   application.SendNotification();
1137   application.Render();
1138
1139   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1140
1141   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT);
1142   application.SendNotification();
1143   application.Render();
1144   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
1145
1146   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::LEFT_TO_RIGHT);
1147   application.SendNotification();
1148   application.Render();
1149
1150   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1151
1152   END_TEST;
1153 }
1154
1155 int UtcDaliControlDoAction(void)
1156 {
1157   ToolkitTestApplication application;
1158   tet_infoline( "DoAction on a visual registered with a control" );
1159
1160   // Set up trace debug
1161   TestGlAbstraction& gl = application.GetGlAbstraction();
1162   TraceCallStack& textureTrace = gl.GetTextureTrace();
1163   textureTrace.Enable( true );
1164
1165   //Created AnimatedImageVisual
1166   VisualFactory factory = VisualFactory::Get();
1167   Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1168
1169   DummyControl dummyControl = DummyControl::New(true);
1170   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1171
1172   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1173   dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1174   application.GetScene().Add( dummyControl );
1175
1176   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1177
1178   application.SendNotification();
1179   application.Render();
1180   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1181   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1182   textureTrace.Reset();
1183
1184   Property::Map attributes;
1185   DevelControl::DoAction( dummyControl,  DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1186
1187   tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1188   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1189
1190   application.SendNotification();
1191   application.Render();
1192   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1193   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1194   END_TEST;
1195 }
1196
1197 int UtcDaliControlDoActionWhenNotStage(void)
1198 {
1199   ToolkitTestApplication application;
1200   tet_infoline( "DoAction on a visual registered with a control but not staged" );
1201
1202   // Set up trace debug
1203   TestGlAbstraction& gl = application.GetGlAbstraction();
1204   TraceCallStack& textureTrace = gl.GetTextureTrace();
1205   textureTrace.Enable( true );
1206
1207   //Created AnimatedImageVisual
1208   VisualFactory factory = VisualFactory::Get();
1209   Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1210
1211   DummyControl dummyControl = DummyControl::New(true);
1212   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1213
1214   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1215   dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1216
1217   application.SendNotification();
1218   application.Render();
1219   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1220   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1221   textureTrace.Reset();
1222
1223   Property::Map attributes;
1224   DevelControl::DoAction( dummyControl,  DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1225
1226   tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1227   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1228
1229   application.SendNotification();
1230   application.Render();
1231   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1232   textureTrace.Reset();
1233
1234   tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1235
1236   application.GetScene().Add( dummyControl );
1237   application.SendNotification();
1238   application.Render();
1239   tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1240
1241   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1242   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1243   textureTrace.Reset();
1244
1245   END_TEST;
1246 }