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.SetResizePolicy( widthPolicy, Dimension::WIDTH );
79 actor.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
81 // Expected results for this actor
82 actor.RegisterProperty( EXPECTED_WIDTH_DIRTY, expectedWidthDirty, Property::READ_WRITE );
83 actor.RegisterProperty( EXPECTED_HEIGHT_DIRTY, expectedHeightDirty, Property::READ_WRITE );
89 * Create a new root actor and enable relayout on it
91 * @return Return the new actor
93 Actor NewRelayoutRootActor( bool requestWidth, bool requestHeight, bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy )
95 Actor actor = NewRelayoutActor( expectedWidthDirty, expectedHeightDirty, widthPolicy, heightPolicy );
97 // Add properties to configure testing
98 actor.RegisterProperty( REQUEST_WIDTH, requestWidth, Property::READ_WRITE );
99 actor.RegisterProperty( REQUEST_HEIGHT, requestHeight, Property::READ_WRITE );
104 void TestTree( TestApplication& application, Actor root, Actor entryPoint = Actor() )
106 // Render and notify - clear the flags
107 application.SendNotification();
108 application.Render();
110 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
111 controller->SetEnabled( true );
113 const bool widthRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_WIDTH ) ).Get< bool >();
114 const bool heightRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_HEIGHT ) ).Get< bool >();
116 const Dimension::Type dimensions = Dimension::Type( ( ( widthRequest ) ? Dimension::WIDTH : 0 ) | ( ( heightRequest ) ? Dimension::HEIGHT : 0 ) );
118 controller->RequestRelayout( ( entryPoint ) ? entryPoint : root, dimensions );
120 CheckResults( root );
123 } // anonymous namespace
125 int UtcDaliRelayoutControllerGet(void)
127 TestApplication application;
129 Internal::RelayoutController* relayoutController = Internal::RelayoutController::Get();
131 DALI_TEST_CHECK( relayoutController );
136 int UtcDaliRelayoutControllerRequestRelayout(void)
138 TestApplication application;
140 Actor actor = Actor::New();
142 Internal::Actor& actorImpl = GetImplementation( actor );
144 // Request default enable (false)
145 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
146 controller->RequestRelayout( actor );
148 DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
153 int UtcDaliRelayoutController_Relayout_SingleActor(void)
155 TestApplication application;
158 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
160 TestTree( application, parent );
165 int UtcDaliRelayoutController_Relayout_FixedParent(void)
167 TestApplication application;
169 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
170 controller->SetEnabled( false );
173 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
176 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
179 TestTree( application, parent );
184 int UtcDaliRelayoutController_Relayout_NaturalParent(void)
186 TestApplication application;
188 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
189 controller->SetEnabled( false );
192 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::USE_NATURAL_SIZE );
195 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
199 TestTree( application, parent );
204 int UtcDaliRelayoutController_Relayout_FillParent(void)
206 TestApplication application;
208 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
209 controller->SetEnabled( false );
212 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FILL_TO_PARENT );
215 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
219 TestTree( application, parent );
224 int UtcDaliRelayoutController_Relayout_FitParent(void)
226 TestApplication application;
228 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
229 controller->SetEnabled( false );
232 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
235 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
239 TestTree( application, parent );
244 int UtcDaliRelayoutController_Relayout_DepParent1(void)
246 TestApplication application;
248 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
249 controller->SetEnabled( false );
252 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::DIMENSION_DEPENDENCY, ResizePolicy::FIT_TO_CHILDREN );
255 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
259 TestTree( application, parent );
264 int UtcDaliRelayoutController_Relayout_DepParent2(void)
266 TestApplication application;
268 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
269 controller->SetEnabled( false );
272 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::DIMENSION_DEPENDENCY );
274 Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
279 TestTree( application, parent );
284 int UtcDaliRelayoutController_Relayout_Child1(void)
286 TestApplication application;
288 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
289 controller->SetEnabled( false );
292 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
295 Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
299 TestTree( application, parent, child );
304 int UtcDaliRelayoutController_Relayout_Child2(void)
306 TestApplication application;
308 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
309 controller->SetEnabled( false );
312 Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
315 Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
319 TestTree( application, parent, child );
324 int UtcDaliRelayoutController_Relayout_Complex1(void)
326 TestApplication application;
328 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
329 controller->SetEnabled( false );
332 Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
335 Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
336 parent.Add( child1 );
338 Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
339 parent.Add( child2 );
341 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
342 parent.Add( child3 );
345 Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
346 child1.Add( grandChild1_1 );
348 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
349 child1.Add( grandChild1_2 );
352 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
353 child2.Add( grandChild2_1 );
355 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
356 child2.Add( grandChild2_2 );
359 TestTree( application, parent );
364 int UtcDaliRelayoutController_Relayout_Complex2(void)
366 TestApplication application;
368 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
369 controller->SetEnabled( false );
372 Actor parent = NewRelayoutRootActor( true, false, true, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
375 Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
376 parent.Add( child1 );
378 Actor child2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
379 parent.Add( child2 );
381 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
382 parent.Add( child3 );
385 Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
386 child1.Add( grandChild1_1 );
388 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
389 child1.Add( grandChild1_2 );
392 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
393 child2.Add( grandChild2_1 );
395 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
396 child2.Add( grandChild2_2 );
399 TestTree( application, parent );
404 int UtcDaliRelayoutController_Relayout_Complex3(void)
406 TestApplication application;
408 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
409 controller->SetEnabled( false );
412 Actor parent = NewRelayoutRootActor( false, true, false, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
415 Actor child1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
416 parent.Add( child1 );
418 Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
419 parent.Add( child2 );
421 Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
422 parent.Add( child3 );
425 Actor grandChild1_1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
426 child1.Add( grandChild1_1 );
428 Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
429 child1.Add( grandChild1_2 );
432 Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
433 child2.Add( grandChild2_1 );
435 Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
436 child2.Add( grandChild2_2 );
439 TestTree( application, parent );
444 int UtcDaliRelayoutController_Relayout_Dependency(void)
446 TestApplication application;
448 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
449 controller->SetEnabled( false );
452 Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
455 Actor child = NewRelayoutActor( true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
456 child.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
460 TestTree( application, parent, child );
465 int UtcDaliRelayoutControllerRequestRelayoutTree(void)
467 TestApplication application;
469 Actor actor = Actor::New();
471 Internal::Actor& actorImpl = GetImplementation( actor );
473 // Check if flag is set
474 DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
476 Internal::RelayoutController* controller = Internal::RelayoutController::Get();
477 controller->SetEnabled( true );
479 // Request default enable (false)
480 controller->RequestRelayoutTree( actor );
482 DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );