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