SVACE error in size negotiation mapper
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-SizeNegotiationMapper.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
20 #include <stdlib.h>
21
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>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 int UtcDaliLayoutingSizeNegotiationMapper_01(void)
32 {
33   ToolkitTestApplication application;
34   tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_01 - Test mapping Dimension::ALL_DIMENSIONS");
35
36   auto control = Control::New();
37   control.SetName( "fitToChildrenControl" );
38   DevelControl::SetLayoutingRequired( control, true );
39   control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
40
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 );
47
48   // Set ALL_DIMENSIONS specifications using mapper
49   Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::ALL_DIMENSIONS );
50
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 );
54
55   END_TEST;
56 }
57
58 int UtcDaliLayoutingSizeNegotiationMapper_02(void)
59 {
60   ToolkitTestApplication application;
61   tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_02 - Test mapping for Dimension::WIDTH only");
62
63   auto control = Control::New();
64   control.SetName( "fitToChildrenControl" );
65   DevelControl::SetLayoutingRequired( control, true );
66   control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
67
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();
71
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 );
75
76   // Set WIDTH specifications using mapper
77   Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::WIDTH );
78
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 );
82
83   END_TEST;
84 }
85
86 int UtcDaliLayoutingSizeNegotiationMapper_03(void)
87 {
88   ToolkitTestApplication application;
89   tet_infoline("UtcDaliLayoutingSizeNegotiationMapper_03 - Test mapping for Dimension::HEIGHT only");
90
91   auto control = Control::New();
92   control.SetName( "fitToChildrenControl" );
93   DevelControl::SetLayoutingRequired( control, true );
94   control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
95
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();
99
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 );
103
104   // Set HEIGHT specifications using mapper
105   Toolkit::Internal::SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( control, layout, Dimension::HEIGHT );
106
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 );
110
111   END_TEST;
112 }