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