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.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/internal/layouting/size-negotiation-mapper.h>
24 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
25 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 using namespace Toolkit;
31 int UtcDaliLayoutingSizeNegotiationMapper_01(void)
33 ToolkitTestApplication application;
34 tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_01 - Test mapping Dimension::ALL_DIMENSIONS");
36 auto control = Control::New();
37 control.SetName( "fitToChildrenControl" );
38 DevelControl::SetLayoutingRequired( control, true );
39 control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
41 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
42 Toolkit::Internal::Control::Impl& controlDataImpl = Toolkit::Internal::Control::Impl::Get( controlImpl );
43 Toolkit::Internal::LayoutItemPtr layout = controlDataImpl.GetLayout();
44 // Set defaults which should be overriden by mapper
45 control.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
46 control.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
48 // Set ALL_DIMENSIONS specifications using mapper
49 Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::ALL_DIMENSIONS );
51 // Test WIDTH and HEIGHT updated
52 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::WRAP_CONTENT ), TEST_LOCATION );
53 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ), Property::Value( ChildLayoutData::WRAP_CONTENT ), TEST_LOCATION );
58 int UtcDaliLayoutingSizeNegotiationMapper_02(void)
60 ToolkitTestApplication application;
61 tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_02 - Test mapping for Dimension::WIDTH only");
63 auto control = Control::New();
64 control.SetName( "fitToChildrenControl" );
65 DevelControl::SetLayoutingRequired( control, true );
66 control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
68 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
69 Toolkit::Internal::Control::Impl& controlDataImpl = Toolkit::Internal::Control::Impl::Get( controlImpl );
70 Toolkit::Internal::LayoutItemPtr layout = controlDataImpl.GetLayout();
72 // Set defaults which should be overriden by mapper
73 control.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
74 control.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
76 // Set WIDTH specifications using mapper
77 Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::WIDTH );
79 // Test WIDTH only updated.
80 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::WRAP_CONTENT ), TEST_LOCATION );
81 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
86 int UtcDaliLayoutingSizeNegotiationMapper_03(void)
88 ToolkitTestApplication application;
89 tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_03 - Test mapping for Dimension::HEIGHT only");
91 auto control = Control::New();
92 control.SetName( "fitToChildrenControl" );
93 DevelControl::SetLayoutingRequired( control, true );
94 control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
96 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
97 Toolkit::Internal::Control::Impl& controlDataImpl = Toolkit::Internal::Control::Impl::Get( controlImpl );
98 Toolkit::Internal::LayoutItemPtr layout = controlDataImpl.GetLayout();
100 // Set defaults which should be overriden by mapper
101 control.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
102 control.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
104 // Set HEIGHT specifications using mapper
105 Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::HEIGHT );
107 // Test HEIGHT only updated.
108 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
109 DALI_TEST_EQUALS( control.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ), Property::Value( ChildLayoutData::WRAP_CONTENT), TEST_LOCATION );