2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
29 void utc_dali_internal_relayout_controller_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_internal_relayout_controller_cleanup(void)
36 test_return_value = TET_PASS;
42 // Properties to attach to actors for testing
43 const std::string REQUEST_WIDTH( "REQUEST_WIDTH" );
44 const std::string REQUEST_HEIGHT( "REQUEST_HEIGHT" );
45 const std::string EXPECTED_WIDTH_DIRTY( "EXPECTED_WIDTH_DIRTY" );
46 const std::string EXPECTED_HEIGHT_DIRTY( "EXPECTED_HEIGHT_DIRTY" );
49 * Check to see that the desired test results were achieved
51 void CheckResults( Actor root )
53 const bool expectedWidthDirty = root.GetProperty( root.GetPropertyIndex( EXPECTED_WIDTH_DIRTY ) ).Get< bool >();
54 const bool expectedHeightDirty = root.GetProperty( root.GetPropertyIndex( EXPECTED_HEIGHT_DIRTY ) ).Get< bool >();
56 Internal::Actor& rootImpl = GetImplementation( root );
58 DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::WIDTH ) == expectedWidthDirty );
59 DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::HEIGHT ) == expectedHeightDirty );
61 for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i )
63 Actor child = root.GetChildAt( i );
65 CheckResults( child );
70 * Create a new actor and enable relayout on it
72 * @return Return the new actor
74 Actor NewRelayoutActor( bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy )
76 Actor actor = Actor::New();
78 actor.SetRelayoutEnabled( true );
80 actor.SetResizePolicy( widthPolicy, Dimension::WIDTH );
81 actor.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
83 // Expected results for this actor
84 actor.RegisterProperty( EXPECTED_WIDTH_DIRTY, expectedWidthDirty, Property::READ_WRITE );
85 actor.RegisterProperty( EXPECTED_HEIGHT_DIRTY, expectedHeightDirty, Property::READ_WRITE );
91 * Create a new root actor and enable relayout on it
93 * @return Return the new actor
95 Actor NewRelayoutRootActor( bool requestWidth, bool requestHeight, bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy )
97 Actor actor = NewRelayoutActor( expectedWidthDirty, expectedHeightDirty, widthPolicy, heightPolicy );
99 // Add properties to configure testing
100 actor.RegisterProperty( REQUEST_WIDTH, requestWidth, Property::READ_WRITE );
101 actor.RegisterProperty( REQUEST_HEIGHT, requestHeight, Property::READ_WRITE );
106 void TestTree( TestApplication& application, Actor root, Actor entryPoint = Actor() )
108 // Render and notify - clear the flags
109 application.SendNotification();
110 application.Render();
112 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
113 controller->SetEnabled( true );
115 const bool widthRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_WIDTH ) ).Get< bool >();
116 const bool heightRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_HEIGHT ) ).Get< bool >();
118 const Dimension::Type dimensions = Dimension::Type( ( ( widthRequest ) ? Dimension::WIDTH : 0 ) | ( ( heightRequest ) ? Dimension::HEIGHT : 0 ) );
120 controller->RequestRelayout( ( entryPoint ) ? entryPoint : root, dimensions );
122 CheckResults( root );
125 } // anonymous namespace
127 int UtcDaliRelayoutControllerGet(void)
129 TestApplication application;
131 Internal::RelayoutController* relayoutController = Internal::RelayoutController::Get();
133 DALI_TEST_CHECK( relayoutController );
138 int UtcDaliRelayoutControllerRequestRelayout(void)
140 TestApplication application;
142 Actor actor = Actor::New();
143 actor.SetRelayoutEnabled( true );
145 Internal::Actor& actorImpl = GetImplementation( actor );
147 // Request default enable (false)
148 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
149 controller->RequestRelayout( actor );
151 DALI_TEST_CHECK( actorImpl.IsLayoutDirty() );
156 int UtcDaliRelayoutController_Relayout_SingleActor(void)
158 TestApplication application;
161 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
163 TestTree( application, parent );
168 int UtcDaliRelayoutController_Relayout_FixedParent(void)
170 TestApplication application;
172 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
173 controller->SetEnabled( false );
176 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
179 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
182 TestTree( application, parent );
187 int UtcDaliRelayoutController_Relayout_NaturalParent(void)
189 TestApplication application;
191 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
192 controller->SetEnabled( false );
195 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::USE_NATURAL_SIZE );
198 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
202 TestTree( application, parent );
207 int UtcDaliRelayoutController_Relayout_FillParent(void)
209 TestApplication application;
211 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
212 controller->SetEnabled( false );
215 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FILL_TO_PARENT );
218 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
222 TestTree( application, parent );
227 int UtcDaliRelayoutController_Relayout_FitParent(void)
229 TestApplication application;
231 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
232 controller->SetEnabled( false );
235 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
238 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
242 TestTree( application, parent );
247 int UtcDaliRelayoutController_Relayout_DepParent1(void)
249 TestApplication application;
251 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
252 controller->SetEnabled( false );
255 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::DIMENSION_DEPENDENCY, ResizePolicy::FIT_TO_CHILDREN );
258 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
262 TestTree( application, parent );
267 int UtcDaliRelayoutController_Relayout_DepParent2(void)
269 TestApplication application;
271 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
272 controller->SetEnabled( false );
275 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::DIMENSION_DEPENDENCY );
277 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
282 TestTree( application, parent );
287 int UtcDaliRelayoutController_Relayout_Child1(void)
289 TestApplication application;
291 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
292 controller->SetEnabled( false );
295 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
298 Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
302 TestTree( application, parent, child );
307 int UtcDaliRelayoutController_Relayout_Child2(void)
309 TestApplication application;
311 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
312 controller->SetEnabled( false );
315 Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
318 Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
322 TestTree( application, parent, child );
327 int UtcDaliRelayoutController_Relayout_Complex1(void)
329 TestApplication application;
331 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
332 controller->SetEnabled( false );
335 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
338 Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
339 parent.Add( child1 );
341 Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
342 parent.Add( child2 );
344 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
345 parent.Add( child3 );
348 Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
349 child1.Add( grandChild1_1 );
351 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
352 child1.Add( grandChild1_2 );
355 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
356 child2.Add( grandChild2_1 );
358 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
359 child2.Add( grandChild2_2 );
362 TestTree( application, parent );
367 int UtcDaliRelayoutController_Relayout_Complex2(void)
369 TestApplication application;
371 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
372 controller->SetEnabled( false );
375 Actor parent = NewRelayoutRootActor( true, false, true, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
378 Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
379 parent.Add( child1 );
381 Actor child2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
382 parent.Add( child2 );
384 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
385 parent.Add( child3 );
388 Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
389 child1.Add( grandChild1_1 );
391 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
392 child1.Add( grandChild1_2 );
395 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
396 child2.Add( grandChild2_1 );
398 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
399 child2.Add( grandChild2_2 );
402 TestTree( application, parent );
407 int UtcDaliRelayoutController_Relayout_Complex3(void)
409 TestApplication application;
411 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
412 controller->SetEnabled( false );
415 Actor parent = NewRelayoutRootActor( false, true, false, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
418 Actor child1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
419 parent.Add( child1 );
421 Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
422 parent.Add( child2 );
424 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
425 parent.Add( child3 );
428 Actor grandChild1_1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
429 child1.Add( grandChild1_1 );
431 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
432 child1.Add( grandChild1_2 );
435 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
436 child2.Add( grandChild2_1 );
438 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
439 child2.Add( grandChild2_2 );
442 TestTree( application, parent );
447 int UtcDaliRelayoutController_Relayout_Dependency(void)
449 TestApplication application;
451 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
452 controller->SetEnabled( false );
455 Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
458 Actor child = NewRelayoutActor( true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
459 child.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
463 TestTree( application, parent, child );
468 int UtcDaliRelayoutControllerRequestRelayoutTree(void)
470 TestApplication application;
472 Actor actor = Actor::New();
473 actor.SetRelayoutEnabled( true );
475 Internal::Actor& actorImpl = GetImplementation( actor );
477 // Check if flag is set
478 DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
480 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
481 controller->SetEnabled( true );
483 // Request default enable (false)
484 controller->RequestRelayoutTree( actor );
486 DALI_TEST_CHECK( actorImpl.IsLayoutDirty() );