2 * Copyright (c) 2018 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.
20 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
27 #include <layout-utils.h>
30 using namespace Toolkit;
32 void utc_dali_toolkit_absolute_layout_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_absolute_layoutg_cleanup(void)
39 test_return_value = TET_PASS;
43 int UtcDaliLayouting_AbsoluteLayoutDownCast(void)
45 TestApplication application;
46 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutDownCast - Testing Downcast");
48 AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
50 LayoutGroup layoutGroup( absoluteLayout );
52 AbsoluteLayout absoluteLayoutCandidate = AbsoluteLayout::DownCast( layoutGroup );
53 DALI_TEST_CHECK( absoluteLayoutCandidate );
58 int UtcDaliLayouting_AbsoluteLayoutAssignment(void)
60 TestApplication application;
61 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutAssignment - Testing operator=");
63 AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
64 AbsoluteLayout absoluteLayout2;
66 absoluteLayout2 = absoluteLayout;
68 DALI_TEST_CHECK( absoluteLayout2 == absoluteLayout );
74 int UtcDaliLayouting_AbsoluteLayout01(void)
76 ToolkitTestApplication application;
77 tet_infoline(" UtcDaliLayouting_AbsoluteLayout01 - Position an item with Actor::Property::POSITION");
79 Stage stage = Stage::GetCurrent();
80 auto absoluteLayout = Control::New();
81 auto layout = AbsoluteLayout::New();
82 layout.SetAnimateLayout( true );
83 DevelControl::SetLayout( absoluteLayout, layout );
84 absoluteLayout.SetName( "AsoluteLayout");
86 std::vector< Control > controls;
87 controls.push_back( CreateLeafControl( 100, 100 ) );
88 controls.push_back( CreateLeafControl( 100, 100 ) );
89 controls.push_back( CreateLeafControl( 100, 100 ) );
90 controls.push_back( CreateLeafControl( 100, 100 ) );
92 // Position one of the controls using the actor property.
93 controls[1].SetProperty(Actor::Property::POSITION, Vector3( 100.0f, 0.0f, 0.0f) );
95 for( auto&& iter : controls )
97 absoluteLayout.Add( iter );
99 absoluteLayout.SetParentOrigin( ParentOrigin::CENTER );
100 absoluteLayout.SetAnchorPoint( AnchorPoint::CENTER );
101 stage.Add( absoluteLayout );
103 // Ensure layouting happens
104 application.SendNotification();
105 application.Render();
107 // AbsoluteLayout renders items at the positions given by their Actor::Property::POSITION relative to the top left of the container.
108 // Items can overlap or spill out of their parent container.
109 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
111 // The controls[1] was the only control to have a defiend position
112 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
113 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
114 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
116 // Items size should not change regardless of parent's size.
117 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
118 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
119 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
120 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
128 // Functor to test whether a Finish signal is emitted
129 struct AnimationFinishCheck
131 AnimationFinishCheck(bool& signalReceived)
132 : mSignalReceived(signalReceived)
136 void operator()(Animation& animation)
138 mSignalReceived = true;
143 mSignalReceived = false;
146 void CheckSignalReceived()
148 if (!mSignalReceived)
150 tet_printf("Expected Finish signal was not received\n");
151 tet_result(TET_FAIL);
155 tet_result(TET_PASS);
159 void CheckSignalNotReceived()
163 tet_printf("Unexpected Finish signal was received\n");
164 tet_result(TET_FAIL);
168 tet_result(TET_PASS);
172 bool& mSignalReceived; // owned by individual tests
177 int UtcDaliLayouting_AbsoluteLayoutWithStandaloneAnimation(void)
179 ToolkitTestApplication application;
180 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutWithStandaloneAnimation ");
182 Stage stage = Stage::GetCurrent();
183 auto root = Control::New();
184 auto layout = AbsoluteLayout::New();
185 layout.SetAnimateLayout( false );
186 DevelControl::SetLayout( root, layout );
187 root.SetName( "AsoluteLayout");
189 std::vector< Control > controls;
190 controls.push_back( CreateLeafControl( 100, 100 ) );
192 controls[0].SetProperty( Actor::Property::POSITION, Vector3( 100.0f, 100.0f, 0.0f ) );
194 for( auto&& iter : controls )
199 root.SetParentOrigin( ParentOrigin::CENTER );
200 root.SetAnchorPoint( AnchorPoint::CENTER );
203 float durationSeconds = 1.0f;
204 Animation animation = Animation::New( durationSeconds );
205 Vector3 targetPosition( 200.0f, 200.0f, 0.0f );
206 animation.AnimateTo(Property( controls[0], Actor::Property::POSITION ), targetPosition, AlphaFunction::LINEAR );
209 DALI_TEST_EQUALS( true, DevelActor::IsPositionOrSizeCurrentlyAnimating( controls[0] ), TEST_LOCATION );
211 bool signalReceived( false );
212 AnimationFinishCheck finishCheck( signalReceived );
213 animation.FinishedSignal().Connect( &application, finishCheck );
215 application.SendNotification();
216 // 0.1 of a second, 10 pixel delta
217 application.Render( 100u );
219 DALI_TEST_EQUALS( controls[0].GetCurrentPosition(), Vector3( 110.0f, 110.0f, 0.0f ), 0.0001f, TEST_LOCATION );
221 application.SendNotification();
222 application.Render(static_cast<unsigned int>( durationSeconds * 1000.0f ) - 100u + 1u );
224 // We did expect the animation to finish
225 application.SendNotification();
226 finishCheck.CheckSignalReceived();
228 DALI_TEST_EQUALS( false, DevelActor::IsPositionOrSizeCurrentlyAnimating( controls[0] ), TEST_LOCATION);
229 DALI_TEST_EQUALS( targetPosition, controls[0].GetCurrentPosition(), TEST_LOCATION );
234 int UtcDaliLayouting_AbsoluteLayoutAndLayoutGroupWithStandaloneAnimation(void)
236 ToolkitTestApplication application;
237 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutAndLayoutGroupWithStandaloneAnimation ");
239 Stage stage = Stage::GetCurrent();
240 auto root = Control::New();
241 auto layout = AbsoluteLayout::New();
242 layout.SetAnimateLayout( false );
243 DevelControl::SetLayout( root, layout );
244 root.SetName( "AsoluteLayout" );
246 Control container = CreateLeafControl( 200, 200 );
247 DevelControl::SetLayoutingRequired( container, true );
248 container.SetName( "Container" );
249 root.Add( container );
251 std::vector< Control > controls;
252 controls.push_back( CreateLeafControl( 100, 100 ) );
253 controls[0].SetProperty( Actor::Property::POSITION, Vector3( 100.0f, 100.0f, 0.0f ) );
255 for( auto&& iter : controls )
257 container.Add( iter );
260 root.SetParentOrigin( ParentOrigin::CENTER );
261 root.SetAnchorPoint( AnchorPoint::CENTER );
264 float durationSeconds = 1.0f;
265 Animation animation = Animation::New( durationSeconds );
266 Vector3 targetPosition( 200.0f, 200.0f, 0.0f );
267 animation.AnimateTo(Property( controls[0], Actor::Property::POSITION ), targetPosition, AlphaFunction::LINEAR );
270 DALI_TEST_EQUALS( true, DevelActor::IsPositionOrSizeCurrentlyAnimating( controls[0] ), TEST_LOCATION );
272 bool signalReceived( false );
273 AnimationFinishCheck finishCheck( signalReceived );
274 animation.FinishedSignal().Connect( &application, finishCheck );
276 application.SendNotification();
277 // 0.1 of a second, 10 pixel delta
278 application.Render( 100u );
280 DALI_TEST_EQUALS( controls[0].GetCurrentPosition(), Vector3( 110.0f, 110.0f, 0.0f ), 0.0001f, TEST_LOCATION );
282 application.SendNotification();
283 application.Render(static_cast<unsigned int>( durationSeconds * 1000.0f ) - 100u + 1u );
285 // We did expect the animation to finish
286 application.SendNotification();
287 finishCheck.CheckSignalReceived();
289 DALI_TEST_EQUALS( false, DevelActor::IsPositionOrSizeCurrentlyAnimating( controls[0] ), TEST_LOCATION);
290 DALI_TEST_EQUALS( targetPosition, controls[0].GetCurrentPosition(), TEST_LOCATION );