32d16e4012aa3e81cb276eab6e00d83b6c26e116
[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/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/align-enums.h>
29 #include <dali-toolkit/devel-api/controls/control-devel.h>
30
31 #include "dummy-control.h"
32
33 using namespace Dali;
34 using namespace Dali::Toolkit;
35
36 void utc_dali_toolkit_control_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void utc_dali_toolkit_control_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 ///////////////////////////////////////////////////////////////////////////////////////////////////
47
48 namespace
49 {
50
51 bool gObjectCreatedCallBackCalled;
52
53 void TestCallback(BaseHandle handle)
54 {
55   gObjectCreatedCallBackCalled = true;
56 }
57
58 void TestVoidCallback()
59 {
60 }
61
62 static bool gKeyInputFocusCallBackCalled;
63
64 static void TestKeyInputFocusCallback( Control control )
65 {
66   tet_infoline(" TestKeyInputFocusCallback");
67
68   gKeyInputFocusCallBackCalled = true;
69 }
70
71 } // namespace
72
73 ///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
76 int UtcDaliControlConstructor(void)
77 {
78   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
79
80   DummyControl dummy;
81
82   DALI_TEST_CHECK( !Control::DownCast(dummy) );
83
84   dummy = DummyControl::New();
85
86   DALI_TEST_CHECK( Control::DownCast(dummy) );
87   END_TEST;
88 }
89
90 int UtcDaliControlNew(void)
91 {
92   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
93
94   Control control;
95
96   DALI_TEST_CHECK( !Control::DownCast(control) );
97
98   control = Control::New();
99
100   DALI_TEST_CHECK( Control::DownCast(control) );
101   END_TEST;
102 }
103
104
105 int UtcDaliControlRegister(void)
106 {
107   ToolkitTestApplication application;
108
109   // Ensure the object is registered after creation
110   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
111   DALI_TEST_CHECK( registry );
112
113   gObjectCreatedCallBackCalled = false;
114   registry.ObjectCreatedSignal().Connect( &TestCallback );
115   {
116     Alignment alignment = Alignment::New();
117   }
118   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
119   END_TEST;
120 }
121
122 int UtcDaliControlCopyAndAssignment(void)
123 {
124   ToolkitTestApplication application;
125
126   DummyControl control = DummyControl::New();
127   Control emptyControl;
128
129   Control controlCopy( control );
130   DALI_TEST_CHECK( control == controlCopy );
131
132   Control emptyControlCopy( emptyControl );
133   DALI_TEST_CHECK( emptyControl == emptyControlCopy );
134
135   Control controlEquals;
136   controlEquals = control;
137   DALI_TEST_CHECK( control == controlEquals );
138
139   Control emptyControlEquals;
140   emptyControlEquals = emptyControl;
141   DALI_TEST_CHECK( emptyControl == emptyControlEquals );
142
143   // Self assignment
144   control = control;
145   DALI_TEST_CHECK( control == controlCopy );
146   END_TEST;
147 }
148
149 int UtcDaliControlDownCast(void)
150 {
151   ToolkitTestApplication application;
152
153   DummyControl control;
154
155   DALI_TEST_CHECK( !Control::DownCast( control ) );
156
157   control = DummyControl::New();
158
159   DALI_TEST_CHECK( Control::DownCast( control ) );
160
161   Actor actor;
162
163   DALI_TEST_CHECK( !Control::DownCast( actor ) );
164
165   actor = Actor::New();
166
167   DALI_TEST_CHECK( !Control::DownCast( actor ) );
168   END_TEST;
169 }
170
171 int UtcDaliControlDownCastTemplate(void)
172 {
173   ToolkitTestApplication application;
174
175   DummyControl control;
176
177   DALI_TEST_CHECK( !DummyControl::DownCast( control ));
178
179   control = DummyControl::New();
180
181   DALI_TEST_CHECK( DummyControl::DownCast( control ) );
182
183   Actor actor;
184
185   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
186
187   actor = Actor::New();
188
189   DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
190   END_TEST;
191 }
192
193 int UtcDaliControlNavigationProperties(void)
194 {
195   ToolkitTestApplication application;
196
197   Control control = Control::New();
198   Stage::GetCurrent().Add( control );
199
200   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
201   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
202   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
203   DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
204
205   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
206   DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
207   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
208   DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
209   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
210   DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
211   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
212   DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
213
214   control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
215   DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
216   control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
217   DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
218   control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
219   DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
220   control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
221   DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
222
223   END_TEST;
224 }
225
226 int UtcDaliControlKeyInputFocus(void)
227 {
228   ToolkitTestApplication application;
229   Stage stage = Stage::GetCurrent();
230
231   DummyControl control;
232
233   PushButton pushButton1 = PushButton::New();
234   stage.Add( pushButton1 );
235
236   pushButton1.SetKeyInputFocus();
237   DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
238
239   pushButton1.ClearKeyInputFocus();
240   DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
241   END_TEST;
242 }
243
244 int UtcDaliControlGetImplementationN(void)
245 {
246   ToolkitTestApplication application;
247   DummyControl control;
248
249   // Get Empty
250   {
251     try
252     {
253       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
254       (void)controlImpl; // Avoid unused warning
255       tet_result(TET_FAIL);
256     }
257     catch (DaliException &exception)
258     {
259       tet_result(TET_PASS);
260     }
261   }
262   END_TEST;
263 }
264
265 int UtcDaliControlGetImplementationConstN(void)
266 {
267   ToolkitTestApplication application;
268   DummyControl control;
269
270   // Get Const Empty
271   {
272     try
273     {
274       const DummyControl constControl(control);
275       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
276       (void)controlImpl; // Avoid unused warning
277       tet_result(TET_FAIL);
278     }
279     catch (DaliException &exception)
280     {
281       tet_result(TET_PASS);
282     }
283   }
284   END_TEST;
285 }
286
287 int UtcDaliControlGetImplementationP(void)
288 {
289   ToolkitTestApplication application;
290   DummyControl control = DummyControl::New();
291
292   // Get
293   {
294     try
295     {
296       Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
297       (void)controlImpl; // Avoid unused warning
298       tet_result(TET_PASS);
299     }
300     catch (DaliException &exception)
301     {
302       tet_result(TET_FAIL);
303     }
304   }
305   END_TEST;
306 }
307
308 int UtcDaliControlGetImplementationConstP(void)
309 {
310   ToolkitTestApplication application;
311   DummyControl control = DummyControl::New();
312   // Get Const
313   {
314     try
315     {
316       const DummyControl constControl(control);
317       const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
318       (void)controlImpl; // Avoid unused warning
319       tet_result(TET_PASS);
320     }
321     catch (DaliException &exception)
322     {
323       tet_result(TET_FAIL);
324     }
325   }
326   END_TEST;
327 }
328
329 int UtcDaliControlSignalConnectDisconnect(void)
330 {
331   ToolkitTestApplication application;
332
333   {
334     DummyControl dummy = DummyControlImpl::New();
335
336     Actor actor = Actor::New();
337     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
338     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
339     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
340
341     if( dummyImpl == NULL )
342     {
343       tet_result( TET_FAIL );
344       END_TEST;
345     }
346
347     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
348     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
349     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
350
351     Stage::GetCurrent().Add( actor );
352     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
353
354     dummyImpl->mCustomSlot1Called = false;
355     actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
356     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
357     Stage::GetCurrent().Remove( actor );
358     Stage::GetCurrent().Add( actor );
359     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
360   }
361   END_TEST;
362 }
363
364 int UtcDaliControlSignalAutomaticDisconnect(void)
365 {
366   ToolkitTestApplication application;
367
368   Actor actor = Actor::New();
369
370   {
371     DummyControl dummy = DummyControlImpl::New();
372     Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
373     DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
374
375     if( dummyImpl == NULL )
376     {
377       tet_result( TET_FAIL );
378       END_TEST;
379     }
380
381     actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
382     DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
383     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
384
385     Stage::GetCurrent().Add( actor );
386     DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
387     Stage::GetCurrent().Remove( actor );
388   }
389   // dummyControl automatically disconnects
390
391   DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
392
393   const Vector3 ignoredSize( 20, 20, 0 );
394   actor.SetSize( ignoredSize );
395   END_TEST;
396 }
397
398 int UtcDaliControlTestParameters(void)
399 {
400   ToolkitTestApplication application;
401   DummyControl test = DummyControl::New();
402
403   test.SetSize( 0.7f, 0.7f, 0.7f );
404
405   Stage::GetCurrent().Add( test );
406
407   application.SendNotification();
408   application.Render();
409
410   float width = 640.0f;
411   float height = test.GetHeightForWidth( width );
412   DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
413   DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
414
415   test.KeyEventSignal();
416
417   // Provide coverage for pointer destructor
418   Control* testControlPtr = new Control;
419   DALI_TEST_CHECK( testControlPtr );
420   delete testControlPtr;
421   END_TEST;
422 }
423
424 int UtcDaliControlBackgroundColor(void)
425 {
426   ToolkitTestApplication application;
427   Control control = Control::New();
428
429   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
430
431   control.SetBackgroundColor( Color::RED );
432
433   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
434   Property::Map* resultMap = propValue.GetMap();
435   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
436   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
437   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
438   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
439
440   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
441
442   control.SetBackgroundColor( Color::YELLOW );
443
444   propValue = control.GetProperty( Control::Property::BACKGROUND );
445   resultMap = propValue.GetMap();
446   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
447   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
448
449   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
450
451   END_TEST;
452 }
453
454 int UtcDaliControlBackgroundImage(void)
455 {
456   ToolkitTestApplication application;
457   Control control = Control::New();
458
459   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
460
461   Image image = ResourceImage::New("TestImage");
462   control.SetBackgroundImage( image );
463
464   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
465   Property::Map* resultMap = propValue.GetMap();
466   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
467   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
468   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
469   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
470
471   image = ResourceImage::New("TestImage2");
472   control.SetBackgroundImage( image );
473
474   propValue = control.GetProperty( Control::Property::BACKGROUND );
475   resultMap = propValue.GetMap();
476   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
477   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
478
479   END_TEST;
480 }
481
482 int UtcDaliControlBackgroundProperties(void)
483 {
484   ToolkitTestApplication application;
485   Control control = Control::New();
486
487   DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
488   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
489
490   Property::Map imageMap;
491   imageMap[ Visual::Property::TYPE ] = Visual::IMAGE;
492   imageMap[ ImageVisual::Property::URL ] = "TestImage";
493   control.SetProperty( Control::Property::BACKGROUND, imageMap );
494   Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
495   Property::Map* resultMap = propValue.GetMap();
496   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
497   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
498   DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
499   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
500
501   Property::Map rendererMap;
502   rendererMap[Visual::Property::TYPE] = Visual::COLOR;
503   rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
504   control.SetProperty( Control::Property::BACKGROUND, rendererMap );
505   propValue = control.GetProperty( Control::Property::BACKGROUND );
506   resultMap = propValue.GetMap();
507   DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
508   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
509   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
510   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
511
512   Property::Map emptyMap;
513   control.SetProperty( Control::Property::BACKGROUND, emptyMap );
514   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
515
516   // set as URL
517   control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
518   propValue = control.GetProperty( Control::Property::BACKGROUND );
519   resultMap = propValue.GetMap();
520   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
521   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
522
523   // set as Color
524   control.SetProperty( Control::Property::BACKGROUND, Color::RED );
525   propValue = control.GetProperty( Control::Property::BACKGROUND );
526   resultMap = propValue.GetMap();
527   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
528   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
529
530   // Deprecated Properties
531   control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
532   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
533   DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
534
535   control.ClearBackground();
536
537   Property::Map deprecatedImageMap;
538   deprecatedImageMap[ "filename" ] = "TestImage";
539   control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
540   propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
541   resultMap = propValue.GetMap();
542   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
543
544   control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
545   DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
546
547   END_TEST;
548 }
549
550 int UtcDaliControlKeyProperties(void)
551 {
552   ToolkitTestApplication application;
553
554   Control control = Control::New();
555   Stage::GetCurrent().Add( control );
556
557   DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
558
559   control.SetKeyInputFocus();
560   DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
561
562   control.ClearKeyInputFocus();
563   DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
564
565   control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
566   DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
567
568   END_TEST;
569 }
570
571 int UtcDaliControlGestureSignals(void)
572 {
573   ToolkitTestApplication application;
574   ConnectionTracker connectionTracker;
575   Control control = Control::New();
576
577   // Each gesture detector gets created when connecting to the gesture signals
578   DALI_TEST_CHECK( !control.GetTapGestureDetector() );
579   control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
580   DALI_TEST_CHECK( control.GetTapGestureDetector() );
581
582   DALI_TEST_CHECK( !control.GetPanGestureDetector() );
583   control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
584   DALI_TEST_CHECK( control.GetPanGestureDetector() );
585
586   DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
587   control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
588   DALI_TEST_CHECK( control.GetPinchGestureDetector() );
589
590   DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
591   control.ConnectSignal( &connectionTracker, "longPressed",  &TestVoidCallback );
592   DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
593
594   END_TEST;
595 }
596
597 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
598 {
599   ToolkitTestApplication application;
600
601   Control control = Control::New();
602   Stage::GetCurrent().Add( control );
603
604   gKeyInputFocusCallBackCalled = false;
605   control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
606
607   application.SendNotification();
608   application.Render();
609
610   control.SetKeyInputFocus();
611
612   DALI_TEST_CHECK( control.HasKeyInputFocus() );
613
614   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
615
616   END_TEST;
617 }
618
619 int UtcDaliControlImplKeyInputFocusLostSignal(void)
620 {
621   ToolkitTestApplication application;
622
623   Control control = Control::New();
624   Stage::GetCurrent().Add( control );
625
626   gKeyInputFocusCallBackCalled = false;
627   control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
628
629   application.SendNotification();
630   application.Render();
631
632   control.SetKeyInputFocus();
633
634   DALI_TEST_CHECK( control.HasKeyInputFocus() );
635
636   control.ClearKeyInputFocus();
637
638   DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
639
640   END_TEST;
641 }
642
643 int UtcDaliControlImplGetControlExtensionP(void)
644 {
645   ToolkitTestApplication application;
646   Control control = Control::New();
647
648   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
649
650   DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
651
652   END_TEST;
653 }
654
655 int UtcDaliControlAutoClipping(void)
656 {
657   ToolkitTestApplication application;
658   Control control = Control::New();
659
660   tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
661
662   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
663
664   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
665
666   Stage::GetCurrent().Add( control );
667
668   application.SendNotification();
669   application.Render();
670
671   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
672
673   END_TEST;
674 }
675
676 int UtcDaliControlAutoClippingN(void)
677 {
678   ToolkitTestApplication application;
679   Control control = Control::New();
680   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
681                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
682
683   tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
684
685   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
686
687   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
688
689   Stage::GetCurrent().Add( control );
690
691   application.SendNotification();
692   application.Render();
693
694   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
695
696   // Ensure the background color is still RED rather than what's set by the automatic clipping
697   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
698   Property::Map* map = value.GetMap();
699   DALI_TEST_CHECK( map );
700   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
701   DALI_TEST_CHECK( colorValue );
702   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
703
704   END_TEST;
705 }
706
707 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
708 {
709   ToolkitTestApplication application;
710   Control control = Control::New();
711
712   tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
713
714   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
715
716   Stage::GetCurrent().Add( control );
717
718   application.SendNotification();
719   application.Render();
720
721   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
722
723   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
724
725   application.SendNotification();
726   application.Render();
727
728   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
729
730   END_TEST;
731 }
732
733 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
734 {
735   ToolkitTestApplication application;
736   Control control = Control::New();
737   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
738                                                                      .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
739
740   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" );
741
742   DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
743
744   Stage::GetCurrent().Add( control );
745
746   application.SendNotification();
747   application.Render();
748
749   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
750
751   control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
752
753   application.SendNotification();
754   application.Render();
755
756   DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
757
758   // Ensure the background color is still RED rather than what's set by the automatic clipping
759   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
760   Property::Map* map = value.GetMap();
761   DALI_TEST_CHECK( map );
762   Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
763   DALI_TEST_CHECK( colorValue );
764   DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
765
766   END_TEST;
767 }
768
769 int UtcDaliControlSetTransformSize(void)
770 {
771   ToolkitTestApplication application;
772   Control control = Control::New();
773
774   Property::Map transformMap;
775   transformMap.Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
776               .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
777               .Add( DevelVisual::Transform::Property::ORIGIN, Align::BOTTOM_END )
778               .Add( DevelVisual::Transform::Property::SIZE, Vector2( 10, 20 ) );
779
780   control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
781                                                                      .Add( DevelVisual::Property::TRANSFORM, transformMap ) );
782
783   tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
784
785   Stage::GetCurrent().Add( control );
786
787   application.SendNotification();
788   application.Render();
789
790   // Ensure the transform property still matches what we set
791   Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
792   Property::Map* map = value.GetMap();
793   DALI_TEST_CHECK( map );
794   Property::Value* transformValue = map->Find( DevelVisual::Property::TRANSFORM );
795   DALI_TEST_CHECK( transformValue );
796
797   Property::Map* retMap = transformValue->GetMap();
798   DALI_TEST_CHECK( retMap );
799   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
800   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
801   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
802   DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
803
804   END_TEST;
805 }