(AutomatedTests) Move devel-api dependent tests to internal tests
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-RelayoutController.cpp
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
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
26
27 using namespace Dali;
28
29 void utc_dali_internal_relayout_controller_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_internal_relayout_controller_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 namespace
40 {
41
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" );
47
48 /**
49  * Check to see that the desired test results were achieved
50  */
51 void CheckResults( Actor root )
52 {
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 >();
55
56   Internal::Actor& rootImpl = GetImplementation( root );
57
58   DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::WIDTH ) == expectedWidthDirty );
59   DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::HEIGHT ) == expectedHeightDirty );
60
61   for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i )
62   {
63     Actor child = root.GetChildAt( i );
64
65     CheckResults( child );
66   }
67 }
68
69 /**
70  * Create a new actor and enable relayout on it
71  *
72  * @return Return the new actor
73  */
74 Actor NewRelayoutActor( bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy )
75 {
76   Actor actor = Actor::New();
77
78   actor.SetResizePolicy( widthPolicy, Dimension::WIDTH );
79   actor.SetResizePolicy( heightPolicy, Dimension::HEIGHT );
80
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 );
84
85   return actor;
86 }
87
88 /**
89  * Create a new root actor and enable relayout on it
90  *
91  * @return Return the new actor
92  */
93 Actor NewRelayoutRootActor( bool requestWidth, bool requestHeight, bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy )
94 {
95   Actor actor = NewRelayoutActor( expectedWidthDirty, expectedHeightDirty, widthPolicy, heightPolicy );
96
97   // Add properties to configure testing
98   actor.RegisterProperty( REQUEST_WIDTH, requestWidth, Property::READ_WRITE );
99   actor.RegisterProperty( REQUEST_HEIGHT, requestHeight, Property::READ_WRITE );
100
101   return actor;
102 }
103
104 void TestTree( TestApplication& application, Actor root, Actor entryPoint = Actor() )
105 {
106   // Render and notify - clear the flags
107   application.SendNotification();
108   application.Render();
109
110   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
111   controller->SetEnabled( true );
112
113   const bool widthRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_WIDTH ) ).Get< bool >();
114   const bool heightRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_HEIGHT ) ).Get< bool >();
115
116   const Dimension::Type dimensions = Dimension::Type( ( ( widthRequest ) ? Dimension::WIDTH : 0 ) | ( ( heightRequest ) ? Dimension::HEIGHT : 0 ) );
117
118   controller->RequestRelayout( ( entryPoint ) ? entryPoint : root, dimensions );
119
120   CheckResults( root );
121 }
122
123 } // anonymous namespace
124
125 int UtcDaliRelayoutControllerGet(void)
126 {
127   TestApplication application;
128
129   Internal::RelayoutController* relayoutController = Internal::RelayoutController::Get();
130
131   DALI_TEST_CHECK( relayoutController );
132
133   END_TEST;
134 }
135
136 int UtcDaliRelayoutControllerRequestRelayout(void)
137 {
138   TestApplication application;
139
140   Actor actor = Actor::New();
141
142   Internal::Actor& actorImpl = GetImplementation( actor );
143
144   // Request default enable (false)
145   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
146   controller->RequestRelayout( actor );
147
148   DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
149
150   END_TEST;
151 }
152
153 int UtcDaliRelayoutController_Relayout_SingleActor(void)
154 {
155   TestApplication application;
156
157   // Construct scene
158   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
159
160   TestTree( application, parent );
161
162   END_TEST;
163 }
164
165 int UtcDaliRelayoutController_Relayout_FixedParent(void)
166 {
167   TestApplication application;
168
169   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
170   controller->SetEnabled( false );
171
172   // Construct scene
173   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
174
175   // Add a child
176   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
177   parent.Add( child );
178
179   TestTree( application, parent );
180
181   END_TEST;
182 }
183
184 int UtcDaliRelayoutController_Relayout_NaturalParent(void)
185 {
186   TestApplication application;
187
188   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
189   controller->SetEnabled( false );
190
191   // Construct scene
192   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::USE_NATURAL_SIZE );
193
194   // Add a child
195   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
196   parent.Add( child );
197
198   // Run the test
199   TestTree( application, parent );
200
201   END_TEST;
202 }
203
204 int UtcDaliRelayoutController_Relayout_FillParent(void)
205 {
206   TestApplication application;
207
208   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
209   controller->SetEnabled( false );
210
211   // Construct scene
212   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FILL_TO_PARENT );
213
214   // Add a child
215   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
216   parent.Add( child );
217
218   // Run the test
219   TestTree( application, parent );
220
221   END_TEST;
222 }
223
224 int UtcDaliRelayoutController_Relayout_FitParent(void)
225 {
226   TestApplication application;
227
228   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
229   controller->SetEnabled( false );
230
231   // Construct scene
232   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
233
234   // Add a child
235   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
236   parent.Add( child );
237
238   // Run the test
239   TestTree( application, parent );
240
241   END_TEST;
242 }
243
244 int UtcDaliRelayoutController_Relayout_DepParent1(void)
245 {
246   TestApplication application;
247
248   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
249   controller->SetEnabled( false );
250
251   // Construct scene
252   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::DIMENSION_DEPENDENCY, ResizePolicy::FIT_TO_CHILDREN );
253
254   // Add a child
255   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
256   parent.Add( child );
257
258   // Run the test
259   TestTree( application, parent );
260
261   END_TEST;
262 }
263
264 int UtcDaliRelayoutController_Relayout_DepParent2(void)
265 {
266   TestApplication application;
267
268   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
269   controller->SetEnabled( false );
270
271   // Construct scene
272   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::DIMENSION_DEPENDENCY );
273
274   Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
275   parent.Add( child );
276
277
278   // Run the test
279   TestTree( application, parent );
280
281   END_TEST;
282 }
283
284 int UtcDaliRelayoutController_Relayout_Child1(void)
285 {
286   TestApplication application;
287
288   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
289   controller->SetEnabled( false );
290
291   // Construct scene
292   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN );
293
294   // Add a child
295   Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
296   parent.Add( child );
297
298   // Run the test
299   TestTree( application, parent, child );
300
301   END_TEST;
302 }
303
304 int UtcDaliRelayoutController_Relayout_Child2(void)
305 {
306   TestApplication application;
307
308   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
309   controller->SetEnabled( false );
310
311   // Construct scene
312   Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
313
314   // Add a child
315   Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
316   parent.Add( child );
317
318   // Run the test
319   TestTree( application, parent, child );
320
321   END_TEST;
322 }
323
324 int UtcDaliRelayoutController_Relayout_Complex1(void)
325 {
326   TestApplication application;
327
328   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
329   controller->SetEnabled( false );
330
331   // Construct scene
332   Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
333
334   // Add children
335   Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
336   parent.Add( child1 );
337
338   Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
339   parent.Add( child2 );
340
341   Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
342   parent.Add( child3 );
343
344   // Grand children 1
345   Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
346   child1.Add( grandChild1_1 );
347
348   Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
349   child1.Add( grandChild1_2 );
350
351   // Grand children 2
352   Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
353   child2.Add( grandChild2_1 );
354
355   Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
356   child2.Add( grandChild2_2 );
357
358   // Run the test
359   TestTree( application, parent );
360
361   END_TEST;
362 }
363
364 int UtcDaliRelayoutController_Relayout_Complex2(void)
365 {
366   TestApplication application;
367
368   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
369   controller->SetEnabled( false );
370
371   // Construct scene
372   Actor parent = NewRelayoutRootActor( true, false, true, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
373
374   // Add children
375   Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
376   parent.Add( child1 );
377
378   Actor child2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
379   parent.Add( child2 );
380
381   Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
382   parent.Add( child3 );
383
384   // Grand children 1
385   Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
386   child1.Add( grandChild1_1 );
387
388   Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
389   child1.Add( grandChild1_2 );
390
391   // Grand children 2
392   Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
393   child2.Add( grandChild2_1 );
394
395   Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
396   child2.Add( grandChild2_2 );
397
398   // Run the test
399   TestTree( application, parent );
400
401   END_TEST;
402 }
403
404 int UtcDaliRelayoutController_Relayout_Complex3(void)
405 {
406   TestApplication application;
407
408   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
409   controller->SetEnabled( false );
410
411   // Construct scene
412   Actor parent = NewRelayoutRootActor( false, true, false, true, ResizePolicy::FIXED, ResizePolicy::FIXED );
413
414   // Add children
415   Actor child1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
416   parent.Add( child1 );
417
418   Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
419   parent.Add( child2 );
420
421   Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED );
422   parent.Add( child3 );
423
424   // Grand children 1
425   Actor grandChild1_1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
426   child1.Add( grandChild1_1 );
427
428   Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT );
429   child1.Add( grandChild1_2 );
430
431   // Grand children 2
432   Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
433   child2.Add( grandChild2_1 );
434
435   Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
436   child2.Add( grandChild2_2 );
437
438   // Run the test
439   TestTree( application, parent );
440
441   END_TEST;
442 }
443
444 int UtcDaliRelayoutController_Relayout_Dependency(void)
445 {
446   TestApplication application;
447
448   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
449   controller->SetEnabled( false );
450
451   // Construct scene
452   Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED );
453
454   // Add a child
455   Actor child = NewRelayoutActor( true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED );
456   child.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
457   parent.Add( child );
458
459   // Run the test
460   TestTree( application, parent, child );
461
462   END_TEST;
463 }
464
465 int UtcDaliRelayoutControllerRequestRelayoutTree(void)
466 {
467   TestApplication application;
468
469   Actor actor = Actor::New();
470
471   Internal::Actor& actorImpl = GetImplementation( actor );
472
473   // Check if flag is set
474   DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
475
476   Internal::RelayoutController* controller = Internal::RelayoutController::Get();
477   controller->SetEnabled( true );
478
479   // Request default enable (false)
480   controller->RequestRelayoutTree( actor );
481
482   DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() );
483
484   END_TEST;
485 }
486