Dali 3D User Interface Engine
utc-Dali-Control.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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.
24 
25 #include <dali.h>
27 #include "dummy-control.h"
28 
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31 
33 {
35 }
36 
38 {
40 }
41 
43 
44 namespace
45 {
46 
48 
50 {
51  gObjectCreatedCallBackCalled = true;
52 }
53 
55 {
56 }
57 
59 
60 static void TestKeyInputFocusCallback( Control control )
61 {
62  tet_infoline(" TestKeyInputFocusCallback");
63 
64  gKeyInputFocusCallBackCalled = true;
65 }
66 
67 } // namespace
68 
70 
71 
73 {
74  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
75 
76  DummyControl dummy;
77 
79 
80  dummy = DummyControl::New();
81 
83  END_TEST;
84 }
85 
87 {
88  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
89 
90  Control control;
91 
93 
94  control = Control::New();
95 
97  END_TEST;
98 }
99 
100 
102 {
103  ToolkitTestApplication application;
104 
105  // Ensure the object is registered after creation
107  DALI_TEST_CHECK( registry );
108 
110  registry.ObjectCreatedSignal().Connect( &TestCallback );
111  {
112  Alignment alignment = Alignment::New();
113  }
115  END_TEST;
116 }
117 
119 {
120  ToolkitTestApplication application;
121 
122  DummyControl control = DummyControl::New();
123  Control emptyControl;
124 
125  Control controlCopy( control );
126  DALI_TEST_CHECK( control == controlCopy );
127 
128  Control emptyControlCopy( emptyControl );
129  DALI_TEST_CHECK( emptyControl == emptyControlCopy );
130 
131  Control controlEquals;
132  controlEquals = control;
133  DALI_TEST_CHECK( control == controlEquals );
134 
135  Control emptyControlEquals;
136  emptyControlEquals = emptyControl;
137  DALI_TEST_CHECK( emptyControl == emptyControlEquals );
138 
139  // Self assignment
140  control = control;
141  DALI_TEST_CHECK( control == controlCopy );
142  END_TEST;
143 }
144 
146 {
147  ToolkitTestApplication application;
148 
149  DummyControl control;
150 
151  DALI_TEST_CHECK( !Control::DownCast( control ) );
152 
153  control = DummyControl::New();
154 
155  DALI_TEST_CHECK( Control::DownCast( control ) );
156 
157  Actor actor;
158 
159  DALI_TEST_CHECK( !Control::DownCast( actor ) );
160 
161  actor = Actor::New();
162 
163  DALI_TEST_CHECK( !Control::DownCast( actor ) );
164  END_TEST;
165 }
166 
168 {
169  ToolkitTestApplication application;
170 
171  DummyControl control;
172 
174 
175  control = DummyControl::New();
176 
178 
179  Actor actor;
180 
182 
183  actor = Actor::New();
184 
186  END_TEST;
187 }
188 
190 {
191  ToolkitTestApplication application;
192  Stage stage = Stage::GetCurrent();
193 
194  DummyControl control;
195 
196  PushButton pushButton1 = PushButton::New();
197  stage.Add( pushButton1 );
198 
199  pushButton1.SetKeyInputFocus();
200  DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
201 
202  pushButton1.ClearKeyInputFocus();
203  DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
204  END_TEST;
205 }
206 
208 {
209  ToolkitTestApplication application;
210  DummyControl control;
211 
212  // Get Empty
213  {
214  try
215  {
217  (void)controlImpl; // Avoid unused warning
219  }
220  catch (DaliException &exception)
221  {
223  }
224  }
225  END_TEST;
226 }
227 
229 {
230  ToolkitTestApplication application;
231  DummyControl control;
232 
233  // Get Const Empty
234  {
235  try
236  {
237  const DummyControl constControl(control);
238  const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
239  (void)controlImpl; // Avoid unused warning
241  }
242  catch (DaliException &exception)
243  {
245  }
246  }
247  END_TEST;
248 }
249 
251 {
252  ToolkitTestApplication application;
253  DummyControl control = DummyControl::New();
254 
255  // Get
256  {
257  try
258  {
260  (void)controlImpl; // Avoid unused warning
262  }
263  catch (DaliException &exception)
264  {
266  }
267  }
268  END_TEST;
269 }
270 
272 {
273  ToolkitTestApplication application;
274  DummyControl control = DummyControl::New();
275  // Get Const
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
283  }
284  catch (DaliException &exception)
285  {
287  }
288  }
289  END_TEST;
290 }
291 
293 {
294  ToolkitTestApplication application;
295 
296  {
298 
299  Actor actor = Actor::New();
300  DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
302  DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
303 
304  if( dummyImpl == NULL )
305  {
306  tet_result( TET_FAIL );
307  END_TEST;
308  }
309 
310  actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
311  DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
312  DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
313 
314  Stage::GetCurrent().Add( actor );
316 
317  dummyImpl->mCustomSlot1Called = false;
318  actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
319  DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
320  Stage::GetCurrent().Remove( actor );
321  Stage::GetCurrent().Add( actor );
322  DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
323  }
324  END_TEST;
325 }
326 
328 {
329  ToolkitTestApplication application;
330 
331  Actor actor = Actor::New();
332 
333  {
336  DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
337 
338  if( dummyImpl == NULL )
339  {
340  tet_result( TET_FAIL );
341  END_TEST;
342  }
343 
344  actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
345  DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
346  DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
347 
348  Stage::GetCurrent().Add( actor );
350  Stage::GetCurrent().Remove( actor );
351  }
352  // dummyControl automatically disconnects
353 
354  DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
355 
356  const Vector3 ignoredSize( 20, 20, 0 );
357  actor.SetSize( ignoredSize );
358  END_TEST;
359 }
360 
362 {
363  ToolkitTestApplication application;
365 
366  test.SetSize( 0.7f, 0.7f, 0.7f );
367 
368  Stage::GetCurrent().Add( test );
369 
370  application.SendNotification();
371  application.Render();
372 
373  float width = 640.0f;
374  float height = test.GetHeightForWidth( width );
375  DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
376  DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
377 
378  test.KeyEventSignal();
379 
380  // Provide coverage for pointer destructor
381  Control* testControlPtr = new Control;
382  DALI_TEST_CHECK( testControlPtr );
383  delete testControlPtr;
384  END_TEST;
385 }
386 
388 {
389  ToolkitTestApplication application;
390  Control control = Control::New();
391 
393 
394  control.SetBackgroundColor( Color::RED );
395 
397  Property::Map* resultMap = propValue.GetMap();
398  DALI_TEST_CHECK( resultMap->Find( "rendererType" ) );
399  DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get<std::string>() == "color" );
400  DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
401  DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::RED );
402 
404 
406 
407  propValue = control.GetProperty( Control::Property::BACKGROUND );
408  resultMap = propValue.GetMap();
409  DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
410  DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::YELLOW );
411 
413 
414  END_TEST;
415 }
416 
418 {
419  ToolkitTestApplication application;
420  Control control = Control::New();
421 
423 
424  Image image = ResourceImage::New("TestImage");
425  control.SetBackgroundImage( image );
426 
428  Property::Map* resultMap = propValue.GetMap();
429  DALI_TEST_CHECK( resultMap->Find( "rendererType" ) );
430  DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get<std::string>() == "image" );
431  DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) );
432  DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get<std::string>() == "TestImage" );
433 
434  image = ResourceImage::New("TestImage2");
435  control.SetBackgroundImage( image );
436 
437  propValue = control.GetProperty( Control::Property::BACKGROUND );
438  resultMap = propValue.GetMap();
439  DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) );
440  DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get<std::string>() == "TestImage2" );
441 
442  END_TEST;
443 }
444 
446 {
447  ToolkitTestApplication application;
448  Control control = Control::New();
449 
452 
453  Property::Map colorMap;
454  colorMap["color"] = Color::RED;
455  control.SetProperty( Control::Property::BACKGROUND, colorMap );
457  Property::Map* resultMap = propValue.GetMap();
458  DALI_TEST_CHECK( resultMap->Find( "rendererType" ) );
459  DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get<std::string>() == "color" );
460  DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
461  DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::RED );
462 
463  Property::Map imageMap;
464  imageMap[ "filename" ] = "TestImage";
465  control.SetProperty( Control::Property::BACKGROUND, imageMap );
466  propValue = control.GetProperty( Control::Property::BACKGROUND );
467  resultMap = propValue.GetMap();
468  DALI_TEST_CHECK( resultMap->Find( "rendererType" ) );
469  DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get<std::string>() == "image" );
470  DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) );
471  DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get<std::string>() == "TestImage" );
472 
473  Property::Map rendererMap;
474  rendererMap["rendererType"] = "color";
475  rendererMap["blendColor"] = Color::CYAN;
476  control.SetProperty( Control::Property::BACKGROUND, rendererMap );
477  propValue = control.GetProperty( Control::Property::BACKGROUND );
478  resultMap = propValue.GetMap();
479  DALI_TEST_CHECK( resultMap->Find( "rendererType" ) );
480  DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get<std::string>() == "color" );
481  DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
482  DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::CYAN );
483 
484  Property::Map emptyMap;
485  control.SetProperty( Control::Property::BACKGROUND, emptyMap );
487 
488  // Deprecated Properties
489  control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
490  DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >() == Color::YELLOW );
491  DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >() == control.GetBackgroundColor() );
492  control.ClearBackground();
493  control.SetProperty( Control::Property::BACKGROUND_IMAGE, imageMap );
494  propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
495  resultMap = propValue.GetMap();
496  DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get< std::string >() == "TestImage" );
497  control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
498  DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
499 
500  END_TEST;
501 }
502 
504 {
505  ToolkitTestApplication application;
506 
507  Control control = Control::New();
508  Stage::GetCurrent().Add( control );
509 
510  DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
511 
512  control.SetKeyInputFocus();
513  DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
514 
515  control.ClearKeyInputFocus();
516  DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
517 
518  control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
519  DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
520 
521  END_TEST;
522 }
523 
525 {
526  ToolkitTestApplication application;
527  ConnectionTracker connectionTracker;
528  Control control = Control::New();
529 
530  // Each gesture detector gets created when connecting to the gesture signals
532  control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
534 
536  control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
538 
540  control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
542 
544  control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
546 
547  END_TEST;
548 }
549 
551 {
552  ToolkitTestApplication application;
553 
554  Control control = Control::New();
555  Stage::GetCurrent().Add( control );
556 
559 
560  application.SendNotification();
561  application.Render();
562 
563  control.SetKeyInputFocus();
564 
565  DALI_TEST_CHECK( control.HasKeyInputFocus() );
566 
568 
569  END_TEST;
570 }
571 
573 {
574  ToolkitTestApplication application;
575 
576  Control control = Control::New();
577  Stage::GetCurrent().Add( control );
578 
581 
582  application.SendNotification();
583  application.Render();
584 
585  control.SetKeyInputFocus();
586 
587  DALI_TEST_CHECK( control.HasKeyInputFocus() );
588 
589  control.ClearKeyInputFocus();
590 
592 
593  END_TEST;
594 }
595 
597 {
598  ToolkitTestApplication application;
599  Control control = Control::New();
600 
602 
603  DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
604 
605  END_TEST;
606 }
Dali Docs Home
Read more about Dali