Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Geometry.cpp
1 /*
2  * Copyright (c) 2015 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 <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 void geometry_test_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void geometry_test_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 namespace
36 {
37
38 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
39 {
40   current.b = 0.0f;
41 }
42
43 }
44
45
46 int UtcDaliGeometryNew01(void)
47 {
48   TestApplication application;
49
50   Geometry geometry = Geometry::New();
51
52   DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
53   END_TEST;
54 }
55
56 int UtcDaliGeometryNew02(void)
57 {
58   TestApplication application;
59   Geometry geometry;
60   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
61   END_TEST;
62 }
63
64 int UtcDaliGeometryDownCast01(void)
65 {
66   TestApplication application;
67
68   Geometry geometry = Geometry::New();
69
70   BaseHandle handle(geometry);
71   Geometry geometry2 = Geometry::DownCast(handle);
72   DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
73   END_TEST;
74 }
75
76 int UtcDaliGeometryDownCast02(void)
77 {
78   TestApplication application;
79
80   Handle handle = Handle::New(); // Create a custom object
81   Geometry geometry = Geometry::DownCast(handle);
82   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
83   END_TEST;
84 }
85
86
87 int UtcDaliGeometryConstraint01(void)
88 {
89   TestApplication application;
90
91   tet_infoline("Test that a non-uniform geometry property can be constrained");
92
93   Shader shader = Shader::New("VertexSource", "FragmentSource");
94   Material material = Material::New( shader );
95   material.SetProperty(Material::Property::COLOR, Color::WHITE);
96
97   Geometry geometry = CreateQuadGeometry();
98   Renderer renderer = Renderer::New( geometry, material );
99
100   Actor actor = Actor::New();
101   actor.AddRenderer(renderer);
102   actor.SetSize(400, 400);
103   Stage::GetCurrent().Add(actor);
104
105   Vector4 initialColor = Color::WHITE;
106   Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
107
108   application.SendNotification();
109   application.Render(0);
110   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
111
112   // Apply constraint
113   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
114   constraint.Apply();
115   application.SendNotification();
116   application.Render(0);
117
118   // Expect no blue component in either buffer - yellow
119   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
120   application.Render(0);
121   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
122
123   geometry.RemoveConstraints();
124   geometry.SetProperty(colorIndex, Color::WHITE );
125   application.SendNotification();
126   application.Render(0);
127   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
128
129   END_TEST;
130 }
131
132 int UtcDaliGeometryConstraint02(void)
133 {
134   TestApplication application;
135
136   tet_infoline("Test that a uniform map geometry property can be constrained");
137
138   Shader shader = Shader::New("VertexSource", "FragmentSource");
139   Material material = Material::New( shader );
140   material.SetProperty(Material::Property::COLOR, Color::WHITE);
141
142   Geometry geometry = CreateQuadGeometry();
143   Renderer renderer = Renderer::New( geometry, material );
144
145   Actor actor = Actor::New();
146   actor.AddRenderer(renderer);
147   actor.SetSize(400, 400);
148   Stage::GetCurrent().Add(actor);
149   application.SendNotification();
150   application.Render(0);
151
152   Vector4 initialColor = Color::WHITE;
153   Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
154   geometry.AddUniformMapping( colorIndex, std::string("uFadeColor") );
155
156   TestGlAbstraction& gl = application.GetGlAbstraction();
157
158   application.SendNotification();
159   application.Render(0);
160
161   Vector4 actualValue(Vector4::ZERO);
162   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
163   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
164
165   // Apply constraint
166   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
167   constraint.Apply();
168   application.SendNotification();
169   application.Render(0);
170
171    // Expect no blue component in either buffer - yellow
172   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
173   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
174
175   application.Render(0);
176   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
177   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
178
179   geometry.RemoveConstraints();
180   geometry.SetProperty(colorIndex, Color::WHITE );
181   application.SendNotification();
182   application.Render(0);
183
184   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
185   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
186
187   END_TEST;
188 }
189
190
191
192 int UtcDaliGeometryAnimatedProperty01(void)
193 {
194   TestApplication application;
195
196   tet_infoline("Test that a non-uniform geometry property can be animated");
197
198   Shader shader = Shader::New("VertexSource", "FragmentSource");
199   Material material = Material::New( shader );
200   material.SetProperty(Material::Property::COLOR, Color::WHITE);
201
202   Geometry geometry = CreateQuadGeometry();
203   Renderer renderer = Renderer::New( geometry, material );
204
205   Actor actor = Actor::New();
206   actor.AddRenderer(renderer);
207   actor.SetSize(400, 400);
208   Stage::GetCurrent().Add(actor);
209
210   Vector4 initialColor = Color::WHITE;
211   Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
212
213   application.SendNotification();
214   application.Render(0);
215   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
216
217   Animation  animation = Animation::New(1.0f);
218   KeyFrames keyFrames = KeyFrames::New();
219   keyFrames.Add(0.0f, initialColor);
220   keyFrames.Add(1.0f, Color::TRANSPARENT);
221   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
222   animation.Play();
223
224   application.SendNotification();
225   application.Render(500);
226
227   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
228
229   application.Render(500);
230
231   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
232
233   END_TEST;
234 }
235
236 int UtcDaliGeometryAnimatedProperty02(void)
237 {
238   TestApplication application;
239
240   tet_infoline("Test that a uniform map geometry property can be animated");
241
242   Shader shader = Shader::New("VertexSource", "FragmentSource");
243   Material material = Material::New( shader );
244   material.SetProperty(Material::Property::COLOR, Color::WHITE);
245
246   Geometry geometry = CreateQuadGeometry();
247   Renderer renderer = Renderer::New( geometry, material );
248
249   Actor actor = Actor::New();
250   actor.AddRenderer(renderer);
251   actor.SetSize(400, 400);
252   Stage::GetCurrent().Add(actor);
253   application.SendNotification();
254   application.Render(0);
255
256   Vector4 initialColor = Color::WHITE;
257   Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
258   geometry.AddUniformMapping( colorIndex, std::string("uFadeColor") );
259
260   TestGlAbstraction& gl = application.GetGlAbstraction();
261
262   application.SendNotification();
263   application.Render(0);
264
265   Vector4 actualValue(Vector4::ZERO);
266   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
267   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
268
269   Animation  animation = Animation::New(1.0f);
270   KeyFrames keyFrames = KeyFrames::New();
271   keyFrames.Add(0.0f, initialColor);
272   keyFrames.Add(1.0f, Color::TRANSPARENT);
273   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
274   animation.Play();
275
276   application.SendNotification();
277   application.Render(500);
278
279   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
280   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
281
282   application.Render(500);
283   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
284   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
285
286   END_TEST;
287 }