98ea9742b9ffd7cba7a573d659d3d052e0658b05
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AbsoluteLayout.cpp
1 /*
2  * Copyright (c) 2018 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 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
25
26 #include <layout-utils.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 void utc_dali_toolkit_absolute_layout_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_toolkit_absolute_layoutg_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41
42 int UtcDaliLayouting_AbsoluteLayoutDownCast(void)
43 {
44   TestApplication application;
45   tet_infoline(" UtcDaliLayouting_AbsoluteLayoutDownCast - Testing Downcast");
46
47   AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
48
49   LayoutGroup layoutGroup( absoluteLayout );
50
51   AbsoluteLayout absoluteLayoutCandidate = AbsoluteLayout::DownCast( layoutGroup );
52   DALI_TEST_CHECK( absoluteLayoutCandidate );
53
54   END_TEST;
55 }
56
57 int UtcDaliLayouting_AbsoluteLayoutAssignment(void)
58 {
59   TestApplication application;
60   tet_infoline(" UtcDaliLayouting_AbsoluteLayoutAssignment - Testing operator=");
61
62   AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
63   AbsoluteLayout absoluteLayout2;
64
65   absoluteLayout2 = absoluteLayout;
66
67   DALI_TEST_CHECK( absoluteLayout2 == absoluteLayout );
68
69   END_TEST;
70 }
71
72 int UtcDaliLayouting_AbsoluteLayout01(void)
73 {
74   ToolkitTestApplication application;
75   tet_infoline(" UtcDaliLayouting_AbsoluteLayout01 - Position an item with Actor::Property::POSITION");
76
77   Stage stage = Stage::GetCurrent();
78   auto absoluteLayout = Control::New();
79   auto layout = AbsoluteLayout::New();
80   layout.SetAnimateLayout( true );
81   DevelControl::SetLayout( absoluteLayout, layout );
82   absoluteLayout.SetName( "AsoluteLayout");
83
84   std::vector< Control > controls;
85   controls.push_back( CreateLeafControl( 100, 100 ) );
86   controls.push_back( CreateLeafControl( 100, 100 ) );
87   controls.push_back( CreateLeafControl( 100, 100 ) );
88   controls.push_back( CreateLeafControl( 100, 100 ) );
89
90   // Position one of the  controls using the actor property.
91   controls[1].SetProperty(Actor::Property::POSITION, Vector3( 100.0f, 0.0f, 0.0f) );
92
93   for( auto&& iter : controls )
94   {
95     absoluteLayout.Add( iter );
96   }
97   absoluteLayout.SetParentOrigin( ParentOrigin::CENTER );
98   absoluteLayout.SetAnchorPoint( AnchorPoint::CENTER );
99   stage.Add( absoluteLayout );
100
101   // Ensure layouting happens
102   application.SendNotification();
103   application.Render();
104
105   // AbsoluteLayout renders items at the positions given by their Actor::Property::POSITION relative to the top left of the container.
106   // Items can overlap or spill out of their parent container.
107   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
108
109   // The controls[1] was the only control to have a defiend position
110   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
111   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
112   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
113
114   // Items size should not change regardless of parent's size.
115   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
116   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
117   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
118   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
119
120   END_TEST;
121 }
122
123 int UtcDaliLayouting_AbsoluteLayout_SetPosition(void)
124 {
125   ToolkitTestApplication application;
126   tet_infoline(" UtcDaliLayouting_AbsoluteLayout_GetWorldPosition - Testing WorldPosition");
127
128   Stage stage = Stage::GetCurrent();
129
130   Dali::Toolkit::Control layoutControl = Dali::Toolkit::Control::New();
131   layoutControl.SetName("AsoluteLayout");
132   layoutControl.SetAnchorPoint( Dali::AnchorPoint::CENTER );
133   layoutControl.SetParentOrigin( Dali::ParentOrigin::CENTER );
134
135   Dali::Toolkit::AbsoluteLayout absoluteLayout = Dali::Toolkit::AbsoluteLayout::New();
136   Dali::Toolkit::DevelControl::SetLayout( layoutControl, absoluteLayout );
137
138   stage.GetRootLayer().Add( layoutControl );
139
140   // Ensure layouting happens
141   application.SendNotification();
142   application.Render(0);
143
144   Dali::Toolkit::Control control = Dali::Toolkit::Control::New();
145   control.SetSize( 100.0f, 100.0f );
146   control.SetParentOrigin( ParentOrigin::CENTER );
147   control.SetAnchorPoint( AnchorPoint::CENTER );
148   Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
149   control.SetPosition( parentPosition );
150
151   layoutControl.Add( control );
152
153   // Ensure layouting happens
154   application.SendNotification();
155   application.Render(0);
156
157   // The value of z should not be zero
158   DALI_TEST_EQUALS( control.GetCurrentPosition(), parentPosition, TEST_LOCATION );
159
160   END_TEST;
161 }