Merge "Add new layouting support for TextLabel and ImageView." into devel/master
[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
73 int UtcDaliLayouting_AbsoluteLayout01(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline(" UtcDaliLayouting_AbsoluteLayout01 - Position an item with Actor::Property::POSITION");
77
78   Stage stage = Stage::GetCurrent();
79   auto absoluteLayout = Control::New();
80   auto layout = AbsoluteLayout::New();
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 }