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