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.
21 #include <dali-toolkit-test-suite-utils.h>
22 //#include <toolkit-timer.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
27 #include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
28 #include <dali/devel-api/rendering/renderer-devel.h>
29 #include "dummy-control.h"
32 using namespace Dali::Toolkit;
34 void dali_arc_visual_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_arc_visual_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliVisualFactoryGetArcVisual01(void)
46 ToolkitTestApplication application;
47 tet_infoline( "UtcDaliVisualFactoryGetArcVisual01: Request arc visual with a Property::Map" );
49 Property::Map propertyMap;
50 propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
51 .Add( Visual::Property::MIX_COLOR, Color::RED )
52 .Add( DevelArcVisual::Property::THICKNESS, 20.0f );
54 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
55 DALI_TEST_CHECK( visual );
57 DummyControl actor = DummyControl::New( true );
58 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
59 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
60 actor.SetSize( 200.0f, 200.0f );
61 Stage::GetCurrent().Add( actor );
63 application.SendNotification();
66 // renderer is added to actor
67 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
68 Renderer renderer = actor.GetRendererAt( 0u );
69 DALI_TEST_CHECK( renderer );
72 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
77 int UtcDaliVisualFactoryGetArcVisual02(void)
79 ToolkitTestApplication application;
80 tet_infoline( "UtcDaliVisualFactoryGetArcVisual02: Request arc visual with a Property::Map" );
82 Property::Map propertyMap;
83 propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
84 .Add( Visual::Property::MIX_COLOR, Color::RED )
85 .Add( DevelArcVisual::Property::THICKNESS, 20.0f )
86 .Add( DevelArcVisual::Property::START_ANGLE, 0.0f )
87 .Add( DevelArcVisual::Property::SWEEP_ANGLE, 90.0f )
88 .Add( DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND );
90 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
91 DALI_TEST_CHECK( visual );
93 DummyControl actor = DummyControl::New( true );
94 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
95 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
96 actor.SetSize( 200.0f, 200.0f );
97 Stage::GetCurrent().Add( actor );
99 application.SendNotification();
100 application.Render();
102 // renderer is added to actor
103 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
104 Renderer renderer = actor.GetRendererAt( 0u );
105 DALI_TEST_CHECK( renderer );
108 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
113 int UtcDaliArcVisualGetPropertyMap01(void)
115 ToolkitTestApplication application;
116 tet_infoline( "UtcDaliArcVisualGetPropertyMap01" );
118 float thickness = 20.0f;
119 float startAngle = 0.0f, sweepAngle = 90.0f;
121 Property::Map propertyMap;
122 propertyMap.Add( "visualType", DevelVisual::ARC )
123 .Add( "mixColor", Color::RED )
124 .Add( "thickness", thickness )
125 .Add( "startAngle", startAngle )
126 .Add( "sweepAngle", sweepAngle )
127 .Add( "cap", DevelArcVisual::Cap::ROUND );
129 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
130 DALI_TEST_CHECK( visual );
132 DummyControl actor = DummyControl::New( true );
133 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
134 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
135 actor.SetSize( 200.0f, 200.0f );
136 Stage::GetCurrent().Add( actor );
138 application.SendNotification();
139 application.Render();
141 // renderer is added to actor
142 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
143 Renderer renderer = actor.GetRendererAt( 0u );
144 DALI_TEST_CHECK( renderer );
146 Property::Map resultMap;
147 visual.CreatePropertyMap( resultMap );
149 // check the property values from the returned map from a visual
150 Property::Value* value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 );
151 DALI_TEST_CHECK( value );
152 DALI_TEST_EQUALS( value->Get< Vector4 >(), Color::RED, TEST_LOCATION );
154 value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
155 DALI_TEST_CHECK( value );
156 DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
158 value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
159 DALI_TEST_CHECK( value );
160 DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION );
162 value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
163 DALI_TEST_CHECK( value );
164 DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION );
166 value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
167 DALI_TEST_CHECK( value );
168 DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::ROUND );
171 propertyMap[DevelArcVisual::Property::THICKNESS] = "3.0f";
172 propertyMap[DevelArcVisual::Property::START_ANGLE] = "0.0f";
173 propertyMap[DevelArcVisual::Property::SWEEP_ANGLE] = "90.0f";
174 propertyMap[DevelArcVisual::Property::CAP] = "1";
176 visual = VisualFactory::Get().CreateVisual( propertyMap );
177 DALI_TEST_CHECK( visual );
179 visual.CreatePropertyMap( resultMap );
181 value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
182 DALI_TEST_CHECK( value );
183 DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
185 value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
186 DALI_TEST_CHECK( value );
187 DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
189 value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
190 DALI_TEST_CHECK( value );
191 DALI_TEST_EQUALS( value->Get< float >(), 360.0f, TEST_LOCATION );
193 value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
194 DALI_TEST_CHECK( value );
195 DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::BUTT );
198 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );