2 * Copyright (c) 2015 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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
25 void geometry_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void geometry_test_cleanup(void)
32 test_return_value = TET_PASS;
38 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
46 int UtcDaliGeometryNew01(void)
48 TestApplication application;
50 Geometry geometry = Geometry::New();
52 DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
56 int UtcDaliGeometryNew02(void)
58 TestApplication application;
60 DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
64 int UtcDaliGeometryDownCast01(void)
66 TestApplication application;
68 Geometry geometry = Geometry::New();
70 BaseHandle handle(geometry);
71 Geometry geometry2 = Geometry::DownCast(handle);
72 DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
76 int UtcDaliGeometryDownCast02(void)
78 TestApplication application;
80 Handle handle = Handle::New(); // Create a custom object
81 Geometry geometry = Geometry::DownCast(handle);
82 DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
87 int UtcDaliGeometryConstraint01(void)
89 TestApplication application;
91 tet_infoline("Test that a non-uniform geometry property can be constrained");
93 Shader shader = Shader::New("VertexSource", "FragmentSource");
94 Material material = Material::New( shader );
95 material.SetProperty(Material::Property::COLOR, Color::WHITE);
97 Geometry geometry = CreateQuadGeometry();
98 Renderer renderer = Renderer::New( geometry, material );
100 Actor actor = Actor::New();
101 actor.AddRenderer(renderer);
102 actor.SetSize(400, 400);
103 Stage::GetCurrent().Add(actor);
105 Vector4 initialColor = Color::WHITE;
106 Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
108 application.SendNotification();
109 application.Render(0);
110 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
113 Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
115 application.SendNotification();
116 application.Render(0);
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 );
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 );
132 int UtcDaliGeometryConstraint02(void)
134 TestApplication application;
136 tet_infoline("Test that a uniform map geometry property can be constrained");
138 Shader shader = Shader::New("VertexSource", "FragmentSource");
139 Material material = Material::New( shader );
140 material.SetProperty(Material::Property::COLOR, Color::WHITE);
142 Geometry geometry = CreateQuadGeometry();
143 Renderer renderer = Renderer::New( geometry, material );
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);
152 Vector4 initialColor = Color::WHITE;
153 Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
155 TestGlAbstraction& gl = application.GetGlAbstraction();
157 application.SendNotification();
158 application.Render(0);
160 Vector4 actualValue(Vector4::ZERO);
161 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
162 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
165 Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
167 application.SendNotification();
168 application.Render(0);
170 // Expect no blue component in either buffer - yellow
171 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
172 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
174 application.Render(0);
175 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
176 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
178 geometry.RemoveConstraints();
179 geometry.SetProperty(colorIndex, Color::WHITE );
180 application.SendNotification();
181 application.Render(0);
183 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
184 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
191 int UtcDaliGeometryAnimatedProperty01(void)
193 TestApplication application;
195 tet_infoline("Test that a non-uniform geometry property can be animated");
197 Shader shader = Shader::New("VertexSource", "FragmentSource");
198 Material material = Material::New( shader );
199 material.SetProperty(Material::Property::COLOR, Color::WHITE);
201 Geometry geometry = CreateQuadGeometry();
202 Renderer renderer = Renderer::New( geometry, material );
204 Actor actor = Actor::New();
205 actor.AddRenderer(renderer);
206 actor.SetSize(400, 400);
207 Stage::GetCurrent().Add(actor);
209 Vector4 initialColor = Color::WHITE;
210 Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
212 application.SendNotification();
213 application.Render(0);
214 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
216 Animation animation = Animation::New(1.0f);
217 KeyFrames keyFrames = KeyFrames::New();
218 keyFrames.Add(0.0f, initialColor);
219 keyFrames.Add(1.0f, Color::TRANSPARENT);
220 animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
223 application.SendNotification();
224 application.Render(500);
226 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
228 application.Render(500);
230 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
235 int UtcDaliGeometryAnimatedProperty02(void)
237 TestApplication application;
239 tet_infoline("Test that a uniform map geometry property can be animated");
241 Shader shader = Shader::New("VertexSource", "FragmentSource");
242 Material material = Material::New( shader );
243 material.SetProperty(Material::Property::COLOR, Color::WHITE);
245 Geometry geometry = CreateQuadGeometry();
246 Renderer renderer = Renderer::New( geometry, material );
248 Actor actor = Actor::New();
249 actor.AddRenderer(renderer);
250 actor.SetSize(400, 400);
251 Stage::GetCurrent().Add(actor);
252 application.SendNotification();
253 application.Render(0);
255 Vector4 initialColor = Color::WHITE;
256 Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
258 TestGlAbstraction& gl = application.GetGlAbstraction();
260 application.SendNotification();
261 application.Render(0);
263 Vector4 actualValue(Vector4::ZERO);
264 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
265 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
267 Animation animation = Animation::New(1.0f);
268 KeyFrames keyFrames = KeyFrames::New();
269 keyFrames.Add(0.0f, initialColor);
270 keyFrames.Add(1.0f, Color::TRANSPARENT);
271 animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
274 application.SendNotification();
275 application.Render(500);
277 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
278 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
280 application.Render(500);
281 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
282 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );