Add animated vector image visual
[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   layout.SetAnimateLayout( true );
82   DevelControl::SetLayout( absoluteLayout, layout );
83   absoluteLayout.SetName( "AsoluteLayout");
84
85   std::vector< Control > controls;
86   controls.push_back( CreateLeafControl( 100, 100 ) );
87   controls.push_back( CreateLeafControl( 100, 100 ) );
88   controls.push_back( CreateLeafControl( 100, 100 ) );
89   controls.push_back( CreateLeafControl( 100, 100 ) );
90
91   // Position one of the  controls using the actor property.
92   controls[1].SetProperty(Actor::Property::POSITION, Vector3( 100.0f, 0.0f, 0.0f) );
93
94   for( auto&& iter : controls )
95   {
96     absoluteLayout.Add( iter );
97   }
98   absoluteLayout.SetParentOrigin( ParentOrigin::CENTER );
99   absoluteLayout.SetAnchorPoint( AnchorPoint::CENTER );
100   stage.Add( absoluteLayout );
101
102   // Ensure layouting happens
103   application.SendNotification();
104   application.Render();
105
106   // AbsoluteLayout renders items at the positions given by their Actor::Property::POSITION relative to the top left of the container.
107   // Items can overlap or spill out of their parent container.
108   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
109
110   // The controls[1] was the only control to have a defiend position
111   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
112   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
113   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
114
115   // Items size should not change regardless of parent's size.
116   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
117   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
118   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
119   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
120
121   END_TEST;
122 }