Merge "Dali-Text: Keyboard Shortcuts" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ArcVisual.cpp
1 /*
2  * Copyright (c) 2020 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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 #include <dali-toolkit/devel-api/controls/control-devel.h>
23 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
24 #include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
25 #include <dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h>
26 #include <dali/devel-api/rendering/renderer-devel.h>
27 #include "dummy-control.h"
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void dali_arc_visual_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void dali_arc_visual_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int UtcDaliVisualFactoryGetArcVisual01(void)
43 {
44   ToolkitTestApplication application;
45   tet_infoline( "UtcDaliVisualFactoryGetArcVisual01: Request arc visual with a Property::Map" );
46
47   Property::Map propertyMap;
48   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
49              .Add( Visual::Property::MIX_COLOR, Color::RED )
50              .Add( DevelArcVisual::Property::THICKNESS, 20.0f );
51
52   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
53   DALI_TEST_CHECK( visual );
54
55   DummyControl actor = DummyControl::New( true );
56   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
57   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
58   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
59   application.GetScene().Add( actor );
60
61   application.SendNotification();
62   application.Render();
63
64   // renderer is added to actor
65   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
66   Renderer renderer = actor.GetRendererAt( 0u );
67   DALI_TEST_CHECK( renderer );
68
69   actor.Unparent( );
70   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
71
72   END_TEST;
73 }
74
75 int UtcDaliVisualFactoryGetArcVisual02(void)
76 {
77   ToolkitTestApplication application;
78   tet_infoline( "UtcDaliVisualFactoryGetArcVisual02: Request arc visual with a Property::Map" );
79
80   Property::Map propertyMap;
81   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
82              .Add( Visual::Property::MIX_COLOR, Color::RED )
83              .Add( DevelArcVisual::Property::THICKNESS, 20.0f )
84              .Add( DevelArcVisual::Property::START_ANGLE, 0.0f )
85              .Add( DevelArcVisual::Property::SWEEP_ANGLE, 90.0f )
86              .Add( DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND );
87
88   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
89   DALI_TEST_CHECK( visual );
90
91   DummyControl actor = DummyControl::New( true );
92   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
93   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
94   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
95   application.GetScene().Add( actor );
96
97   application.SendNotification();
98   application.Render();
99
100   // renderer is added to actor
101   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
102   Renderer renderer = actor.GetRendererAt( 0u );
103   DALI_TEST_CHECK( renderer );
104
105   actor.Unparent( );
106   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
107
108   END_TEST;
109 }
110
111 int UtcDaliArcVisualGetPropertyMap01(void)
112 {
113   ToolkitTestApplication application;
114   tet_infoline( "UtcDaliArcVisualGetPropertyMap01" );
115
116   float thickness = 20.0f;
117   float startAngle = 0.0f, sweepAngle = 90.0f;
118
119   Property::Map propertyMap;
120   propertyMap.Add( "visualType", DevelVisual::ARC )
121              .Add( "mixColor", Color::RED )
122              .Add( "thickness", thickness )
123              .Add( "startAngle", startAngle )
124              .Add( "sweepAngle", sweepAngle )
125              .Add( "cap", DevelArcVisual::Cap::ROUND );
126
127   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
128   DALI_TEST_CHECK( visual );
129
130   DummyControl actor = DummyControl::New( true );
131   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
132   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
133   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
134   application.GetScene().Add( actor );
135
136   application.SendNotification();
137   application.Render();
138
139   // renderer is added to actor
140   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
141   Renderer renderer = actor.GetRendererAt( 0u );
142   DALI_TEST_CHECK( renderer );
143
144   Property::Map resultMap;
145   visual.CreatePropertyMap( resultMap );
146
147   // check the property values from the returned map from a visual
148   Property::Value* value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 );
149   DALI_TEST_CHECK( value );
150   DALI_TEST_EQUALS( value->Get< Vector4 >(), Color::RED, TEST_LOCATION );
151
152   value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
153   DALI_TEST_CHECK( value );
154   DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
155
156   value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
157   DALI_TEST_CHECK( value );
158   DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION );
159
160   value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
161   DALI_TEST_CHECK( value );
162   DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION );
163
164   value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
165   DALI_TEST_CHECK( value );
166   DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::ROUND );
167
168   // Test wrong values
169   propertyMap[DevelArcVisual::Property::THICKNESS] = "3.0f";
170   propertyMap[DevelArcVisual::Property::START_ANGLE] = "0.0f";
171   propertyMap[DevelArcVisual::Property::SWEEP_ANGLE] = "90.0f";
172   propertyMap[DevelArcVisual::Property::CAP] = "1";
173
174   visual = VisualFactory::Get().CreateVisual( propertyMap );
175   DALI_TEST_CHECK( visual );
176
177   visual.CreatePropertyMap( resultMap );
178
179   value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
180   DALI_TEST_CHECK( value );
181   DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
182
183   value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
184   DALI_TEST_CHECK( value );
185   DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
186
187   value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
188   DALI_TEST_CHECK( value );
189   DALI_TEST_EQUALS( value->Get< float >(), 360.0f, TEST_LOCATION );
190
191   value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
192   DALI_TEST_CHECK( value );
193   DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::BUTT );
194
195   actor.Unparent( );
196   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
197
198   END_TEST;
199 }
200
201 int UtcDaliArcVisualUpdateProperty(void)
202 {
203   ToolkitTestApplication application;
204   tet_infoline( "UtcDaliArcVisualUpdateProperty" );
205
206   TestGlAbstraction& gl = application.GetGlAbstraction();
207
208   float thickness = 20.0f;
209   float startAngle = 0.0f;
210   float sweepAngle = 90.0f;
211
212   Property::Map propertyMap;
213   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
214              .Add( Visual::Property::MIX_COLOR, Color::RED )
215              .Add( DevelArcVisual::Property::THICKNESS, thickness )
216              .Add( DevelArcVisual::Property::START_ANGLE, startAngle )
217              .Add( DevelArcVisual::Property::SWEEP_ANGLE, sweepAngle );
218
219   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
220   DALI_TEST_CHECK( visual );
221
222   DummyControl actor = DummyControl::New( true );
223   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
224   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
225
226   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
227   application.GetScene().Add( actor );
228
229   application.SendNotification();
230   application.Render();
231
232   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
233   Property::Value* value = map.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
234   DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
235   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "thickness", thickness ), true, TEST_LOCATION );
236
237   value = map.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
238   DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION );
239   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "startAngle", startAngle ), true, TEST_LOCATION );
240
241   value = map.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
242   DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION );
243   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "sweepAngle", sweepAngle ), true, TEST_LOCATION );
244
245   thickness = 10.0f;
246   startAngle = 90.0f;
247   sweepAngle = 180.0f;
248
249   Property::Map attributes;
250   attributes.Add( DevelArcVisual::Property::THICKNESS, thickness )
251             .Add( DevelArcVisual::Property::START_ANGLE, startAngle )
252             .Add( DevelArcVisual::Property::SWEEP_ANGLE, sweepAngle );
253
254   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelArcVisual::Action::UPDATE_PROPERTY, attributes );
255
256   application.SendNotification();
257   application.Render();
258
259   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
260   value = map.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
261   DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
262   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "thickness", thickness ), true, TEST_LOCATION );
263
264   value = map.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
265   DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION );
266   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "startAngle", startAngle ), true, TEST_LOCATION );
267
268   value = map.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
269   DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION );
270   DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "sweepAngle", sweepAngle ), true, TEST_LOCATION );
271
272   END_TEST;
273 }