2 * Copyright (c) 2020 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.
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"
30 using namespace Dali::Toolkit;
32 void dali_arc_visual_startup(void)
34 test_return_value = TET_UNDEF;
37 void dali_arc_visual_cleanup(void)
39 test_return_value = TET_PASS;
42 int UtcDaliVisualFactoryGetArcVisual01(void)
44 ToolkitTestApplication application;
45 tet_infoline( "UtcDaliVisualFactoryGetArcVisual01: Request arc visual with a Property::Map" );
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 );
52 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
53 DALI_TEST_CHECK( visual );
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 );
61 application.SendNotification();
64 // renderer is added to actor
65 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
66 Renderer renderer = actor.GetRendererAt( 0u );
67 DALI_TEST_CHECK( renderer );
70 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
75 int UtcDaliVisualFactoryGetArcVisual02(void)
77 ToolkitTestApplication application;
78 tet_infoline( "UtcDaliVisualFactoryGetArcVisual02: Request arc visual with a Property::Map" );
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 );
88 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
89 DALI_TEST_CHECK( visual );
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 );
97 application.SendNotification();
100 // renderer is added to actor
101 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
102 Renderer renderer = actor.GetRendererAt( 0u );
103 DALI_TEST_CHECK( renderer );
106 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
111 int UtcDaliArcVisualGetPropertyMap01(void)
113 ToolkitTestApplication application;
114 tet_infoline( "UtcDaliArcVisualGetPropertyMap01" );
116 float thickness = 20.0f;
117 float startAngle = 0.0f, sweepAngle = 90.0f;
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 );
127 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
128 DALI_TEST_CHECK( visual );
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 );
136 application.SendNotification();
137 application.Render();
139 // renderer is added to actor
140 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
141 Renderer renderer = actor.GetRendererAt( 0u );
142 DALI_TEST_CHECK( renderer );
144 Property::Map resultMap;
145 visual.CreatePropertyMap( resultMap );
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 );
152 value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
153 DALI_TEST_CHECK( value );
154 DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
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 );
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 );
164 value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
165 DALI_TEST_CHECK( value );
166 DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::ROUND );
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";
174 visual = VisualFactory::Get().CreateVisual( propertyMap );
175 DALI_TEST_CHECK( visual );
177 visual.CreatePropertyMap( resultMap );
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 );
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 );
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 );
191 value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
192 DALI_TEST_CHECK( value );
193 DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::BUTT );
196 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
201 int UtcDaliArcVisualUpdateProperty(void)
203 ToolkitTestApplication application;
204 tet_infoline( "UtcDaliArcVisualUpdateProperty" );
206 TestGlAbstraction& gl = application.GetGlAbstraction();
208 float thickness = 20.0f;
209 float startAngle = 0.0f;
210 float sweepAngle = 90.0f;
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 );
219 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
220 DALI_TEST_CHECK( visual );
222 DummyControl actor = DummyControl::New( true );
223 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
224 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
226 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
227 application.GetScene().Add( actor );
229 application.SendNotification();
230 application.Render();
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 );
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 );
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 );
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 );
254 DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelArcVisual::Action::UPDATE_PROPERTY, attributes );
256 application.SendNotification();
257 application.Render();
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 );
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 );
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 );