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