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