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-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
26 #include <layout-utils.h>
29 using namespace Toolkit;
31 void utc_dali_toolkit_absolute_layout_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_absolute_layoutg_cleanup(void)
38 test_return_value = TET_PASS;
42 int UtcDaliLayouting_AbsoluteLayoutDownCast(void)
44 TestApplication application;
45 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutDownCast - Testing Downcast");
47 AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
49 LayoutGroup layoutGroup( absoluteLayout );
51 AbsoluteLayout absoluteLayoutCandidate = AbsoluteLayout::DownCast( layoutGroup );
52 DALI_TEST_CHECK( absoluteLayoutCandidate );
57 int UtcDaliLayouting_AbsoluteLayoutAssignment(void)
59 TestApplication application;
60 tet_infoline(" UtcDaliLayouting_AbsoluteLayoutAssignment - Testing operator=");
62 AbsoluteLayout absoluteLayout = AbsoluteLayout::New();
63 AbsoluteLayout absoluteLayout2;
65 absoluteLayout2 = absoluteLayout;
67 DALI_TEST_CHECK( absoluteLayout2 == absoluteLayout );
73 int UtcDaliLayouting_AbsoluteLayout01(void)
75 ToolkitTestApplication application;
76 tet_infoline(" UtcDaliLayouting_AbsoluteLayout01 - Position an item with Actor::Property::POSITION");
78 Stage stage = Stage::GetCurrent();
79 auto absoluteLayout = Control::New();
80 auto layout = AbsoluteLayout::New();
81 DevelControl::SetLayout( absoluteLayout, layout );
82 absoluteLayout.SetName( "AsoluteLayout");
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 ) );
90 // Position one of the controls using the actor property.
91 controls[1].SetProperty(Actor::Property::POSITION, Vector3( 100.0f, 0.0f, 0.0f) );
93 for( auto&& iter : controls )
95 absoluteLayout.Add( iter );
97 absoluteLayout.SetParentOrigin( ParentOrigin::CENTER );
98 absoluteLayout.SetAnchorPoint( AnchorPoint::CENTER );
99 stage.Add( absoluteLayout );
101 // Ensure layouting happens
102 application.SendNotification();
103 application.Render();
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 );
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 );
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 );