Support Right-To-Left of padding/margin in control
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Control.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/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 <toolkit-event-thread-callback.h>
31
32 #include "dummy-control.h"
33
34 using namespace Dali;
35 using namespace Dali::Toolkit;
36
37 void utc_dali_toolkit_control_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void utc_dali_toolkit_control_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47 ///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 namespace
50 {
51
52 bool gObjectCreatedCallBackCalled;
53
54 void TestCallback(BaseHandle handle)
55 {
56   gObjectCreatedCallBackCalled = true;
57 }
58
59 void TestVoidCallback()
60 {
61 }
62
63 static bool gKeyInputFocusCallBackCalled;
64
65 static void TestKeyInputFocusCallback( Control control )
66 {
67   tet_infoline(" TestKeyInputFocusCallback");
68
69   gKeyInputFocusCallBackCalled = true;
70 }
71
72 const char* TEST_LARGE_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/tbcol.png";
73 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/gallery-small-1.jpg";
74
75 } // namespace
76
77 ///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
80 int UtcDaliControlConstructor(void)
81 {
82   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
83
84   DummyControl dummy;
85
86   DALI_TEST_CHECK( !Control::DownCast(dummy) );
87
88   dummy = DummyControl::New();
89
90   DALI_TEST_CHECK( Control::DownCast(dummy) );
91   END_TEST;
92 }
93
94 int UtcDaliControlNew(void)
95 {
96   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
97
98   Control control;
99
100   DALI_TEST_CHECK( !Control::DownCast(control) );
101
102   control = Control::New();
103
104   DALI_TEST_CHECK( Control::DownCast(control) );
105   END_TEST;
106 }
107
108
109 int UtcDaliControlRegister(void)
110 {
111   ToolkitTestApplication application;
112
113   // Ensure the object is registered after creation
114   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
115   DALI_TEST_CHECK( registry );
116
117   gObjectCreatedCallBackCalled = false;
118   registry.ObjectCreatedSignal().Connect( &TestCallback );
119   {
120     Alignment alignment = Alignment::New();
121   }
122   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
123   END_TEST;
124 }
125
126 int UtcDaliControlCopyAndAssignment(void)
127 {
128   ToolkitTestApplication application;
129
130   DummyControl control = DummyControl::New();
131   Control emptyControl;
132
133   Control controlCopy( control );
134   DALI_TEST_CHECK( control == controlCopy );
135
136   Control emptyControlCopy( emptyControl );
137   DALI_TEST_CHECK( emptyControl == emptyControlCopy );
138
139   Control controlEquals;
140   controlEquals = control;
141   DALI_TEST_CHECK( control == controlEquals );
142
143   Control emptyControlEquals;
144   emptyControlEquals = emptyControl;
145   DALI_TEST_CHECK( emptyControl == emptyControlEquals );
146
147   // Self assignment
148   control = control;
149   DALI_TEST_CHECK( control == controlCopy );
150   END_TEST;
151 }
152
153 int UtcDaliControlDownCast(void)
154 {
155   ToolkitTestApplication application;
156
157   DummyControl control;
158
159   DALI_TEST_CHECK( !Control::DownCast( control ) );
160
161   control = DummyControl::New();
162
163   DALI_TEST_CHECK( Control::DownCast( control ) );
164
165   Actor actor;
166
167   DALI_TEST_CHECK( !Control::DownCast( actor ) );
168
169   actor = Actor::New();
170
171   DALI_TEST_CHECK( !Control::DownCast( actor ) );
172   END_TEST;
173 }
174
175 int UtcDaliControlDownCastTemplate(void)
176 {
177   ToolkitTestApplication application;
178
179   DummyControl control;
180
181   DALI_TEST_CHECK( !DummyControl::DownCast( control ));
182
183   control = DummyControl::New();
184
185   DALI_TEST_CHECK( DummyControl::DownCast( control ) );
186
187   Actor actor;
188
189   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
190
191   actor = Actor::New();
192
193   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
194   END_TEST;
195 }
196
197 int UtcDaliControlNavigationProperties(void)
198 {
199   ToolkitTestApplication application;
200
201   Control control = Control::New();
202   Stage::GetCurrent().Add( control );
203
204   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
205   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
206   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
207   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
208
209   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
210   DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
211   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
212   DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
213   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
214   DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
215   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
216   DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
217
218   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
219   DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
220   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
221   DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
222   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
223   DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
224   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
225   DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
226
227   END_TEST;
228 }
229
230 int UtcDaliControlKeyInputFocus(void)
231 {
232   ToolkitTestApplication application;
233   Stage stage = Stage::GetCurrent();
234
235   DummyControl control;
236
237   PushButton pushButton1 = PushButton::New();
238   stage.Add( pushButton1 );
239
240   pushButton1.SetKeyInputFocus();
241   DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
242
243   pushButton1.ClearKeyInputFocus();
244   DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
245   END_TEST;
246 }
247
248 int UtcDaliControlGetImplementationN(void)
249 {
250   ToolkitTestApplication application;
251   DummyControl control;
252
253   // Get Empty
254   {
255     try
256     {
257       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
258       (void)controlImpl; // Avoid unused warning
259       tet_result(TET_FAIL);
260     }
261     catch (DaliException &exception)
262     {
263       tet_result(TET_PASS);
264     }
265   }
266   END_TEST;
267 }
268
269 int UtcDaliControlGetImplementationConstN(void)
270 {
271   ToolkitTestApplication application;
272   DummyControl control;
273
274   // Get Const Empty
275   {
276     try
277     {
278       const DummyControl constControl(control);
279       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
280       (void)controlImpl; // Avoid unused warning
281       tet_result(TET_FAIL);
282     }
283     catch (DaliException &exception)
284     {
285       tet_result(TET_PASS);
286     }
287   }
288   END_TEST;
289 }
290
291 int UtcDaliControlGetImplementationP(void)
292 {
293   ToolkitTestApplication application;
294   DummyControl control = DummyControl::New();
295
296   // Get
297   {
298     try
299     {
300       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
301       (void)controlImpl; // Avoid unused warning
302       tet_result(TET_PASS);
303     }
304     catch (DaliException &exception)
305     {
306       tet_result(TET_FAIL);
307     }
308   }
309   END_TEST;
310 }
311
312 int UtcDaliControlGetImplementationConstP(void)
313 {
314   ToolkitTestApplication application;
315   DummyControl control = DummyControl::New();
316   // Get Const
317   {
318     try
319     {
320       const DummyControl constControl(control);
321       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
322       (void)controlImpl; // Avoid unused warning
323       tet_result(TET_PASS);
324     }
325     catch (DaliException &exception)
326     {
327       tet_result(TET_FAIL);
328     }
329   }
330   END_TEST;
331 }
332
333 int UtcDaliControlSignalConnectDisconnect(void)
334 {
335   ToolkitTestApplication application;
336
337   {
338     DummyControl dummy = DummyControlImpl::New();
339
340     Actor actor = Actor::New();
341     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
342     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
343     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
344
345     if( dummyImpl == NULL )
346     {
347       tet_result( TET_FAIL );
348       END_TEST;
349     }
350
351     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
352     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
353     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
354
355     Stage::GetCurrent().Add( actor );
356     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
357
358     dummyImpl->mCustomSlot1Called = false;
359     actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
360     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
361     Stage::GetCurrent().Remove( actor );
362     Stage::GetCurrent().Add( actor );
363     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
364   }
365   END_TEST;
366 }
367
368 int UtcDaliControlSignalAutomaticDisconnect(void)
369 {
370   ToolkitTestApplication application;
371
372   Actor actor = Actor::New();
373
374   {
375     DummyControl dummy = DummyControlImpl::New();
376     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
377     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
378
379     if( dummyImpl == NULL )
380     {
381       tet_result( TET_FAIL );
382       END_TEST;
383     }
384
385     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
386     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
387     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
388
389     Stage::GetCurrent().Add( actor );
390     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
391     Stage::GetCurrent().Remove( actor );
392   }
393   // dummyControl automatically disconnects
394
395   DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
396
397   const Vector3 ignoredSize( 20, 20, 0 );
398   actor.SetSize( ignoredSize );
399   END_TEST;
400 }
401
402 int UtcDaliControlTestParameters(void)
403 {
404   ToolkitTestApplication application;
405   DummyControl test = DummyControl::New();
406
407   test.SetSize( 0.7f, 0.7f, 0.7f );
408
409   Stage::GetCurrent().Add( test );
410
411   application.SendNotification();
412   application.Render();
413
414   float width = 640.0f;
415   float height = test.GetHeightForWidth( width );
416   DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
417   DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
418
419   test.KeyEventSignal();
420
421   // Provide coverage for pointer destructor
422   Control* testControlPtr = new Control;
423   DALI_TEST_CHECK( testControlPtr );
424   delete testControlPtr;
425   END_TEST;
426 }
427
428 int UtcDaliControlBackgroundColor(void)
429 {
430   ToolkitTestApplication application;
431   Control control = Control::New();
432
433   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
434
435   control.SetBackgroundColor( Color::RED );
436
437   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
438   Property::Map* resultMap = propValue.GetMap();
439   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
440   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
441   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
442   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
443
444   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
445
446   control.SetBackgroundColor( Color::YELLOW );
447
448   propValue = control.GetProperty( Control::Property::BACKGROUND );
449   resultMap = propValue.GetMap();
450   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
451   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
452
453   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
454
455   END_TEST;
456 }
457
458 int UtcDaliControlBackgroundImage(void)
459 {
460   ToolkitTestApplication application;
461   Control control = Control::New();
462
463   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
464
465   Image image = ResourceImage::New("TestImage");
466   control.SetBackgroundImage( image );
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::IMAGE );
472   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
473   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
474
475   image = ResourceImage::New("TestImage2");
476   control.SetBackgroundImage( image );
477
478   propValue = control.GetProperty( Control::Property::BACKGROUND );
479   resultMap = propValue.GetMap();
480   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
481   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
482
483   END_TEST;
484 }
485
486 int UtcDaliControlBackgroundProperties(void)
487 {
488   ToolkitTestApplication application;
489   Control control = Control::New();
490
491   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
492   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
493
494   Property::Map imageMap;
495   imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
496   imageMap[ ImageVisual::Property::URL ] = "TestImage";
497   control.SetProperty( Control::Property::BACKGROUND, imageMap );
498   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
499   Property::Map* resultMap = propValue.GetMap();
500   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
501   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
502   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
503   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
504
505   Property::Map rendererMap;
506   rendererMap[Visual::Property::TYPE] = Visual::COLOR;
507   rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
508   control.SetProperty( Control::Property::BACKGROUND, rendererMap );
509   propValue = control.GetProperty( Control::Property::BACKGROUND );
510   resultMap = propValue.GetMap();
511   DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
512   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
513   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
514   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
515
516   Property::Map emptyMap;
517   control.SetProperty( Control::Property::BACKGROUND, emptyMap );
518   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
519
520   // set as URL
521   control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
522   propValue = control.GetProperty( Control::Property::BACKGROUND );
523   resultMap = propValue.GetMap();
524   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
525   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
526
527   // set as Color
528   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
529   propValue = control.GetProperty( Control::Property::BACKGROUND );
530   resultMap = propValue.GetMap();
531   DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
532   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
533
534   // Deprecated Properties
535   control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
536   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
537   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
538
539   control.ClearBackground();
540
541   Property::Map deprecatedImageMap;
542   deprecatedImageMap[ "filename" ] = "TestImage";
543   control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
544   propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
545   resultMap = propValue.GetMap();
546   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
547
548   control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
549   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
550
551   END_TEST;
552 }
553
554 int UtcDaliControlKeyProperties(void)
555 {
556   ToolkitTestApplication application;
557
558   Control control = Control::New();
559   Stage::GetCurrent().Add( control );
560
561   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
562
563   control.SetKeyInputFocus();
564   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
565
566   control.ClearKeyInputFocus();
567   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
568
569   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
570   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
571
572   END_TEST;
573 }
574
575 int UtcDaliControlGestureSignals(void)
576 {
577   ToolkitTestApplication application;
578   ConnectionTracker connectionTracker;
579   Control control = Control::New();
580
581   // Each gesture detector gets created when connecting to the gesture signals
582   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
583   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
584   DALI_TEST_CHECK( control.GetTapGestureDetector() );
585
586   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
587   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
588   DALI_TEST_CHECK( control.GetPanGestureDetector() );
589
590   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
591   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
592   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
593
594   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
595   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
596   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
597
598   END_TEST;
599 }
600
601 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
602 {
603   ToolkitTestApplication application;
604
605   Control control = Control::New();
606   Stage::GetCurrent().Add( control );
607
608   gKeyInputFocusCallBackCalled = false;
609   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
610
611   application.SendNotification();
612   application.Render();
613
614   control.SetKeyInputFocus();
615
616   DALI_TEST_CHECK( control.HasKeyInputFocus() );
617
618   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
619
620   END_TEST;
621 }
622
623 int UtcDaliControlImplKeyInputFocusLostSignal(void)
624 {
625   ToolkitTestApplication application;
626
627   Control control = Control::New();
628   Stage::GetCurrent().Add( control );
629
630   gKeyInputFocusCallBackCalled = false;
631   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
632
633   application.SendNotification();
634   application.Render();
635
636   control.SetKeyInputFocus();
637
638   DALI_TEST_CHECK( control.HasKeyInputFocus() );
639
640   control.ClearKeyInputFocus();
641
642   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
643
644   END_TEST;
645 }
646
647 int UtcDaliControlImplGetControlExtensionP(void)
648 {
649   ToolkitTestApplication application;
650   Control control = Control::New();
651
652   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
653
654   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
655
656   END_TEST;
657 }
658
659 int UtcDaliControlAutoClipping(void)
660 {
661   ToolkitTestApplication application;
662   Control control = Control::New();
663
664   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
665
666   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
667
668   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
669
670   Stage::GetCurrent().Add( control );
671
672   application.SendNotification();
673   application.Render();
674
675   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
676
677   END_TEST;
678 }
679
680 int UtcDaliControlAutoClippingN(void)
681 {
682   ToolkitTestApplication application;
683   Control control = Control::New();
684   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
685                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
686
687   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
688
689   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
690
691   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
692
693   Stage::GetCurrent().Add( control );
694
695   application.SendNotification();
696   application.Render();
697
698   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
699
700   // Ensure the background color is still RED rather than what's set by the automatic clipping
701   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
702   Property::Map* map = value.GetMap();
703   DALI_TEST_CHECK( map );
704   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
705   DALI_TEST_CHECK( colorValue );
706   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
707
708   END_TEST;
709 }
710
711 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
712 {
713   ToolkitTestApplication application;
714   Control control = Control::New();
715
716   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
717
718   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
719
720   Stage::GetCurrent().Add( control );
721
722   application.SendNotification();
723   application.Render();
724
725   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
726
727   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
728
729   application.SendNotification();
730   application.Render();
731
732   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
733
734   END_TEST;
735 }
736
737 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
738 {
739   ToolkitTestApplication application;
740   Control control = Control::New();
741   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
742                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
743
744   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" );
745
746   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
747
748   Stage::GetCurrent().Add( control );
749
750   application.SendNotification();
751   application.Render();
752
753   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
754
755   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
756
757   application.SendNotification();
758   application.Render();
759
760   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
761
762   // Ensure the background color is still RED rather than what's set by the automatic clipping
763   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
764   Property::Map* map = value.GetMap();
765   DALI_TEST_CHECK( map );
766   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
767   DALI_TEST_CHECK( colorValue );
768   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
769
770   END_TEST;
771 }
772
773 int UtcDaliControlSetTransformSize(void)
774 {
775   ToolkitTestApplication application;
776   Control control = Control::New();
777
778   Property::Map transformMap;
779   transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
780               .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
781               .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
782               .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
783
784   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
785                                                                      .Add( Visual::Property::TRANSFORM, transformMap ) );
786
787   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
788
789   Stage::GetCurrent().Add( control );
790
791   application.SendNotification();
792   application.Render();
793
794   // Ensure the transform property still matches what we set
795   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
796   Property::Map* map = value.GetMap();
797   DALI_TEST_CHECK( map );
798   Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
799   DALI_TEST_CHECK( transformValue );
800
801   Property::Map* retMap = transformValue->GetMap();
802   DALI_TEST_CHECK( retMap );
803   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
804   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
805   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
806   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
807
808   END_TEST;
809 }
810
811
812 int UtcDaliControlResourcesReady(void)
813 {
814   ToolkitTestApplication application;
815   tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
816
817   VisualFactory factory = VisualFactory::Get();
818   DALI_TEST_CHECK( factory );
819
820   Property::Map propertyMapLarge;
821   propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
822   propertyMapLarge.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
823
824   Property::Map propertyMapSmall;
825   propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
826   propertyMapSmall.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
827
828   Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
829   smallVisual.SetName("smallVisual");
830   DALI_TEST_CHECK( smallVisual );
831
832   DummyControl actor = DummyControl::New();
833   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
834   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
835
836   actor.SetSize( 200.f, 200.f );
837
838   Toolkit::Visual::ResourceStatus resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL);
839   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
840   DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
841   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
842
843   Stage::GetCurrent().Add( actor );
844   application.SendNotification();
845   application.Render();
846
847   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
848
849   application.SendNotification();
850   application.Render();
851
852   resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL);
853   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
854   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
855   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
856
857   Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
858   largeVisual.SetName("largeVisual");
859   DALI_TEST_CHECK( largeVisual );
860
861   tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
862
863   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
864
865   resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
866   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
867
868   application.SendNotification();
869
870   resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
871   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
872   DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
873   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
874
875   dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
876
877   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
878
879   application.SendNotification();
880
881   resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
882   DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
883
884   END_TEST;
885 }
886
887 int UtcDaliControlMarginProperty(void)
888 {
889   ToolkitTestApplication application;
890
891   Control control = Control::New();
892   control.SetBackgroundColor( Color::BLUE );
893
894   control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
895
896   Stage::GetCurrent().Add( control );
897
898   application.SendNotification();
899   application.Render();
900
901   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
902
903   // Parent control has one ImageView as a Child.
904   ImageView image = ImageView::New();
905   image.SetBackgroundColor( Color::RED );
906   image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
907   image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
908   control.Add( image );
909
910   application.SendNotification();
911   application.Render();
912
913   DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
914
915   END_TEST;
916 }
917
918 int UtcDaliControlPaddingProperty(void)
919 {
920   ToolkitTestApplication application;
921
922   Control control = Control::New();
923   control.SetBackgroundColor( Color::BLUE );
924
925   control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
926
927   Stage::GetCurrent().Add( control );
928
929   application.SendNotification();
930   application.Render();
931
932   DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
933
934   Control child = Control::New();
935   control.Add(child);
936
937   application.SendNotification();
938   application.Render();
939
940   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
941
942   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT);
943   application.SendNotification();
944   application.Render();
945   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
946
947   control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::LEFT_TO_RIGHT);
948   application.SendNotification();
949   application.Render();
950
951   DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
952
953   END_TEST;
954 }