e7b096af0c4b6b58b67754a660fdbeffe4bfff5a
[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/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 = Stage::GetCurrent().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   Stage::GetCurrent().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   Stage stage = Stage::GetCurrent();
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     Stage::GetCurrent().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     Stage::GetCurrent().Remove( actor );
393     Stage::GetCurrent().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     Stage::GetCurrent().Add( actor );
421     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
422     Stage::GetCurrent().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   Stage::GetCurrent().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   Stage::GetCurrent().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   tet_infoline( "Set transparent, ensure no renderers are created" );
516   control.SetBackgroundColor( Color::TRANSPARENT );
517   application.SendNotification();
518   application.Render();
519   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
520   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
521
522   tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" );
523   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
524   application.SendNotification();
525   application.Render();
526   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
527   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
528
529   tet_infoline( "Set a color, only 1 renderer should exist" );
530   control.SetBackgroundColor( Color::RED );
531   application.SendNotification();
532   application.Render();
533   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
534   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::RED, TEST_LOCATION );
535
536   tet_infoline( "Clear the background, no renderers" );
537   control.ClearBackground();
538   application.SendNotification();
539   application.Render();
540   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
541
542   tet_infoline( "Set control to clip its children again, a renderer should be created which will be transparent" );
543   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
544   application.SendNotification();
545   application.Render();
546   DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
547   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
548
549   tet_infoline( "Disable clipping, no renderers" );
550   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
551   application.SendNotification();
552   application.Render();
553   DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
554   DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
555
556   END_TEST;
557 }
558
559 int UtcDaliControlBackgroundImage(void)
560 {
561   ToolkitTestApplication application;
562   Control control = Control::New();
563
564   tet_infoline( "Set first background image" );
565   control.SetProperty( Control::Property::BACKGROUND, "TestImage" );
566
567   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
568   Property::Map* resultMap = propValue.GetMap();
569   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
570   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
571   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
572   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
573
574   tet_infoline( "Set replacement background image" );
575   control.SetProperty( Control::Property::BACKGROUND, "TestImage2" );
576
577   propValue = control.GetProperty( Control::Property::BACKGROUND );
578   resultMap = propValue.GetMap();
579   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
580   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
581
582   END_TEST;
583 }
584
585 int UtcDaliControlBackgroundProperties(void)
586 {
587   ToolkitTestApplication application;
588   Control control = Control::New();
589
590   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
591
592   Property::Map imageMap;
593   imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
594   imageMap[ ImageVisual::Property::URL ] = "TestImage";
595   control.SetProperty( Control::Property::BACKGROUND, imageMap );
596   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
597   Property::Map* resultMap = propValue.GetMap();
598   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
599   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
600   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
601   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
602
603   Property::Map rendererMap;
604   rendererMap[Visual::Property::TYPE] = Visual::COLOR;
605   rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
606   control.SetProperty( Control::Property::BACKGROUND, rendererMap );
607   propValue = control.GetProperty( Control::Property::BACKGROUND );
608   resultMap = propValue.GetMap();
609   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
610   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
611   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
612   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
613
614   Property::Map emptyMap;
615   control.SetProperty( Control::Property::BACKGROUND, emptyMap );
616   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
617
618   // set as URL
619   control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
620   propValue = control.GetProperty( Control::Property::BACKGROUND );
621   resultMap = propValue.GetMap();
622   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
623   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
624
625   // set as Color
626   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
627   propValue = control.GetProperty( Control::Property::BACKGROUND );
628   resultMap = propValue.GetMap();
629   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
630   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
631
632   END_TEST;
633 }
634
635 int UtcDaliControlShadowProperties(void)
636 {
637   ToolkitTestApplication application;
638   Control control = Control::New();
639
640   DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
641
642   Property::Map imageMap;
643   imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
644   imageMap[ ImageVisual::Property::URL ] = "TestImage";
645   control.SetProperty( DevelControl::Property::SHADOW, imageMap );
646   Property::Value propValue = control.GetProperty( DevelControl::Property::SHADOW );
647   Property::Map* resultMap = propValue.GetMap();
648   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
649   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
650   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
651   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
652
653   Property::Map colorMap;
654   colorMap[Visual::Property::TYPE] = Visual::COLOR;
655   colorMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
656   control.SetProperty( DevelControl::Property::SHADOW, colorMap );
657   propValue = control.GetProperty( DevelControl::Property::SHADOW );
658   resultMap = propValue.GetMap();
659   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
660   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
661   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
662   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
663
664   Property::Map emptyMap;
665   control.SetProperty( DevelControl::Property::SHADOW, emptyMap );
666   DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
667
668   END_TEST;
669 }
670
671 int UtcDaliControlKeyProperties(void)
672 {
673   ToolkitTestApplication application;
674
675   Control control = Control::New();
676   Stage::GetCurrent().Add( control );
677
678   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
679
680   control.SetKeyInputFocus();
681   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
682
683   control.ClearKeyInputFocus();
684   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
685
686   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
687   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
688
689   END_TEST;
690 }
691
692 int UtcDaliControlGestureSignals(void)
693 {
694   ToolkitTestApplication application;
695   ConnectionTracker connectionTracker;
696   Control control = Control::New();
697
698   // Each gesture detector gets created when connecting to the gesture signals
699   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
700   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
701   DALI_TEST_CHECK( control.GetTapGestureDetector() );
702
703   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
704   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
705   DALI_TEST_CHECK( control.GetPanGestureDetector() );
706
707   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
708   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
709   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
710
711   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
712   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
713   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
714
715   END_TEST;
716 }
717
718 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
719 {
720   ToolkitTestApplication application;
721
722   Control control = Control::New();
723   Stage::GetCurrent().Add( control );
724
725   gKeyInputFocusCallBackCalled = false;
726   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
727
728   application.SendNotification();
729   application.Render();
730
731   control.SetKeyInputFocus();
732
733   DALI_TEST_CHECK( control.HasKeyInputFocus() );
734
735   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
736
737   END_TEST;
738 }
739
740 int UtcDaliControlImplKeyInputFocusLostSignal(void)
741 {
742   ToolkitTestApplication application;
743
744   Control control = Control::New();
745   Stage::GetCurrent().Add( control );
746
747   gKeyInputFocusCallBackCalled = false;
748   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
749
750   application.SendNotification();
751   application.Render();
752
753   control.SetKeyInputFocus();
754
755   DALI_TEST_CHECK( control.HasKeyInputFocus() );
756
757   control.ClearKeyInputFocus();
758
759   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
760
761   END_TEST;
762 }
763
764 int UtcDaliControlImplGetControlExtensionP(void)
765 {
766   ToolkitTestApplication application;
767   Control control = Control::New();
768
769   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
770
771   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
772
773   END_TEST;
774 }
775
776 int UtcDaliControlAutoClipping(void)
777 {
778   ToolkitTestApplication application;
779   Control control = Control::New();
780
781   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
782
783   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
784
785   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
786
787   Stage::GetCurrent().Add( control );
788
789   application.SendNotification();
790   application.Render();
791
792   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
793
794   END_TEST;
795 }
796
797 int UtcDaliControlAutoClippingN(void)
798 {
799   ToolkitTestApplication application;
800   Control control = Control::New();
801   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
802                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
803
804   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
805
806   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
807
808   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
809
810   Stage::GetCurrent().Add( control );
811
812   application.SendNotification();
813   application.Render();
814
815   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
816
817   // Ensure the background color is still RED rather than what's set by the automatic clipping
818   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
819   Property::Map* map = value.GetMap();
820   DALI_TEST_CHECK( map );
821   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
822   DALI_TEST_CHECK( colorValue );
823   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
824
825   END_TEST;
826 }
827
828 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
829 {
830   ToolkitTestApplication application;
831   Control control = Control::New();
832
833   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
834
835   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
836
837   Stage::GetCurrent().Add( control );
838
839   application.SendNotification();
840   application.Render();
841
842   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
843
844   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
845
846   application.SendNotification();
847   application.Render();
848
849   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
850
851   END_TEST;
852 }
853
854 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
855 {
856   ToolkitTestApplication application;
857   Control control = Control::New();
858   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
859                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
860
861   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" );
862
863   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
864
865   Stage::GetCurrent().Add( control );
866
867   application.SendNotification();
868   application.Render();
869
870   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
871
872   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
873
874   application.SendNotification();
875   application.Render();
876
877   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
878
879   // Ensure the background color is still RED rather than what's set by the automatic clipping
880   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
881   Property::Map* map = value.GetMap();
882   DALI_TEST_CHECK( map );
883   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
884   DALI_TEST_CHECK( colorValue );
885   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
886
887   END_TEST;
888 }
889
890 int UtcDaliControlSetTransformSize(void)
891 {
892   ToolkitTestApplication application;
893   Control control = Control::New();
894
895   Property::Map transformMap;
896   transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
897               .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
898               .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
899               .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
900
901   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
902                                                                      .Add( Visual::Property::TRANSFORM, transformMap ) );
903
904   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
905
906   Stage::GetCurrent().Add( control );
907
908   application.SendNotification();
909   application.Render();
910
911   // Ensure the transform property still matches what we set
912   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
913   Property::Map* map = value.GetMap();
914   DALI_TEST_CHECK( map );
915   Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
916   DALI_TEST_CHECK( transformValue );
917
918   Property::Map* retMap = transformValue->GetMap();
919   DALI_TEST_CHECK( retMap );
920   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
921   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
922   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
923   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
924
925   END_TEST;
926 }
927
928
929 int UtcDaliControlResourcesReady(void)
930 {
931   ToolkitTestApplication application;
932   tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
933
934   VisualFactory factory = VisualFactory::Get();
935   DALI_TEST_CHECK( factory );
936
937   Property::Map propertyMapLarge;
938   propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
939   propertyMapLarge.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
940
941   Property::Map propertyMapSmall;
942   propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
943   propertyMapSmall.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
944
945   Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
946   smallVisual.SetName("smallVisual");
947   DALI_TEST_CHECK( smallVisual );
948
949   DummyControl actor = DummyControl::New();
950   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
951
952   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
953
954   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
955
956   Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
957   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
958   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
959   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
960
961   Stage::GetCurrent().Add( actor );
962   application.SendNotification();
963   application.Render();
964
965   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
966
967   application.SendNotification();
968   application.Render();
969
970   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
971   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
972   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
973   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
974
975   Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
976   largeVisual.SetName("largeVisual");
977   DALI_TEST_CHECK( largeVisual );
978
979   tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
980
981   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
982
983   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
984   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
985
986   application.SendNotification();
987
988   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
989   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
990   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
991   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
992
993   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
994
995   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
996
997   application.SendNotification();
998
999   resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
1000   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
1001
1002   END_TEST;
1003 }
1004
1005 int UtcDaliControlResourcesReady02(void)
1006 {
1007   ToolkitTestApplication application;
1008   tet_infoline( "Change a resource during ResourceReady callback" );
1009
1010   gResourceReadySignalFired = false;
1011
1012   Control control = Control::New();
1013   control.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1014   control.ResourceReadySignal().Connect( &ResourceReadySignal );
1015
1016   Property::Map propertyMap;
1017   propertyMap.Insert( ImageVisual::Property::URL, "invalid.jpg" );
1018   control.SetProperty( Control::Property::BACKGROUND, propertyMap );
1019
1020   Stage::GetCurrent().Add( control );
1021
1022   application.SendNotification();
1023   application.Render();
1024
1025   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1026
1027   application.SendNotification();
1028   application.Render();
1029
1030   DALI_TEST_EQUALS( control.IsResourceReady(), true, TEST_LOCATION );
1031   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1032   gResourceReadySignalFired = false;
1033
1034   END_TEST;
1035 }
1036
1037 int UtcDaliControlMarginProperty(void)
1038 {
1039   ToolkitTestApplication application;
1040
1041   Control control = Control::New();
1042   control.SetBackgroundColor( Color::BLUE );
1043
1044   control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
1045
1046   Stage::GetCurrent().Add( control );
1047
1048   application.SendNotification();
1049   application.Render();
1050
1051   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
1052
1053   // Parent control has one ImageView as a Child.
1054   ImageView image = ImageView::New();
1055   image.SetBackgroundColor( Color::RED );
1056   image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1057   image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
1058   control.Add( image );
1059
1060   application.SendNotification();
1061   application.Render();
1062
1063   DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
1064
1065   END_TEST;
1066 }
1067
1068 int UtcDaliControlPaddingProperty(void)
1069 {
1070   ToolkitTestApplication application;
1071
1072   Control control = Control::New();
1073   control.SetBackgroundColor( Color::BLUE );
1074
1075   control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1076
1077   Stage::GetCurrent().Add( control );
1078
1079   application.SendNotification();
1080   application.Render();
1081
1082   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1083
1084   Control child = Control::New();
1085   control.Add(child);
1086
1087   application.SendNotification();
1088   application.Render();
1089
1090   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1091
1092   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT);
1093   application.SendNotification();
1094   application.Render();
1095   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
1096
1097   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::LEFT_TO_RIGHT);
1098   application.SendNotification();
1099   application.Render();
1100
1101   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1102
1103   END_TEST;
1104 }
1105
1106 int UtcDaliControlDoAction(void)
1107 {
1108   ToolkitTestApplication application;
1109   tet_infoline( "DoAction on a visual registered with a control" );
1110
1111   // Set up trace debug
1112   TestGlAbstraction& gl = application.GetGlAbstraction();
1113   TraceCallStack& textureTrace = gl.GetTextureTrace();
1114   textureTrace.Enable( true );
1115
1116   //Created AnimatedImageVisual
1117   VisualFactory factory = VisualFactory::Get();
1118   Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1119
1120   DummyControl dummyControl = DummyControl::New(true);
1121   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1122
1123   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1124   dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1125   Stage::GetCurrent().Add( dummyControl );
1126
1127   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1128
1129   application.SendNotification();
1130   application.Render();
1131   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1132   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1133   textureTrace.Reset();
1134
1135   Property::Map attributes;
1136   DevelControl::DoAction( dummyControl,  DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1137
1138   tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1139   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1140
1141   application.SendNotification();
1142   application.Render();
1143   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1144   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1145   END_TEST;
1146 }
1147
1148 int UtcDaliControlDoActionWhenNotStage(void)
1149 {
1150   ToolkitTestApplication application;
1151   tet_infoline( "DoAction on a visual registered with a control but not staged" );
1152
1153   // Set up trace debug
1154   TestGlAbstraction& gl = application.GetGlAbstraction();
1155   TraceCallStack& textureTrace = gl.GetTextureTrace();
1156   textureTrace.Enable( true );
1157
1158   //Created AnimatedImageVisual
1159   VisualFactory factory = VisualFactory::Get();
1160   Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1161
1162   DummyControl dummyControl = DummyControl::New(true);
1163   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1164
1165   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1166   dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1167
1168   application.SendNotification();
1169   application.Render();
1170   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1171   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1172   textureTrace.Reset();
1173
1174   Property::Map attributes;
1175   DevelControl::DoAction( dummyControl,  DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1176
1177   tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1178   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1179
1180   application.SendNotification();
1181   application.Render();
1182   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1183   textureTrace.Reset();
1184
1185   tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1186
1187   Stage::GetCurrent().Add( dummyControl );
1188   application.SendNotification();
1189   application.Render();
1190   tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1191
1192   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1193   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1194   textureTrace.Reset();
1195
1196   END_TEST;
1197 }