2476e0b4764445dc4294ad1c5cfa9ba3357ffa26
[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 <chrono>
20 //#include <thread>
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"
30
31 using namespace Dali;
32 using namespace Dali::Toolkit;
33
34 void dali_arc_visual_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void dali_arc_visual_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 int UtcDaliVisualFactoryGetArcVisual01(void)
45 {
46   ToolkitTestApplication application;
47   tet_infoline( "UtcDaliVisualFactoryGetArcVisual01: Request arc visual with a Property::Map" );
48
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 );
53
54   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
55   DALI_TEST_CHECK( visual );
56
57   DummyControl actor = DummyControl::New( true );
58   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
59   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
60   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
61   Stage::GetCurrent().Add( actor );
62
63   application.SendNotification();
64   application.Render();
65
66   // renderer is added to actor
67   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
68   Renderer renderer = actor.GetRendererAt( 0u );
69   DALI_TEST_CHECK( renderer );
70
71   actor.Unparent( );
72   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
73
74   END_TEST;
75 }
76
77 int UtcDaliVisualFactoryGetArcVisual02(void)
78 {
79   ToolkitTestApplication application;
80   tet_infoline( "UtcDaliVisualFactoryGetArcVisual02: Request arc visual with a Property::Map" );
81
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 );
89
90   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
91   DALI_TEST_CHECK( visual );
92
93   DummyControl actor = DummyControl::New( true );
94   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
95   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
96   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
97   Stage::GetCurrent().Add( actor );
98
99   application.SendNotification();
100   application.Render();
101
102   // renderer is added to actor
103   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
104   Renderer renderer = actor.GetRendererAt( 0u );
105   DALI_TEST_CHECK( renderer );
106
107   actor.Unparent( );
108   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
109
110   END_TEST;
111 }
112
113 int UtcDaliArcVisualGetPropertyMap01(void)
114 {
115   ToolkitTestApplication application;
116   tet_infoline( "UtcDaliArcVisualGetPropertyMap01" );
117
118   float thickness = 20.0f;
119   float startAngle = 0.0f, sweepAngle = 90.0f;
120
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 );
128
129   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
130   DALI_TEST_CHECK( visual );
131
132   DummyControl actor = DummyControl::New( true );
133   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
134   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
135   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
136   Stage::GetCurrent().Add( actor );
137
138   application.SendNotification();
139   application.Render();
140
141   // renderer is added to actor
142   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
143   Renderer renderer = actor.GetRendererAt( 0u );
144   DALI_TEST_CHECK( renderer );
145
146   Property::Map resultMap;
147   visual.CreatePropertyMap( resultMap );
148
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 );
153
154   value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
155   DALI_TEST_CHECK( value );
156   DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
157
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 );
161
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 );
165
166   value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
167   DALI_TEST_CHECK( value );
168   DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::ROUND );
169
170   // Test wrong values
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";
175
176   visual = VisualFactory::Get().CreateVisual( propertyMap );
177   DALI_TEST_CHECK( visual );
178
179   visual.CreatePropertyMap( resultMap );
180
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 );
184
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 );
188
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 );
192
193   value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
194   DALI_TEST_CHECK( value );
195   DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::BUTT );
196
197   actor.Unparent( );
198   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
199
200   END_TEST;
201 }