2 * Copyright (c) 2014 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/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 #include "mesh-builder.h"
29 int UtcDaliLightActorConstructorVoid(void)
31 TestApplication application;
32 tet_infoline("Testing Dali::LightActor::LightActor() UtcDaliLightActorConstructorVoid");
36 DALI_TEST_CHECK(!actor);
41 int UtcDaliLightActorDestructor(void)
43 // This test is achieve 100% line and function coverage
44 TestApplication application;
45 tet_infoline("Testing Dali::LightActor::~LightActor() UtcDaliLightActorDestructor");
47 LightActor* actor = new LightActor;
49 DALI_TEST_CHECK( ! *actor );
53 DALI_TEST_CHECK( true );
57 int UtcDaliLightActorNew(void)
59 TestApplication application;
60 tet_infoline("Testing Dali::LightActor::New() UtcDaliLightActorNew");
62 LightActor actor = LightActor::New();
64 DALI_TEST_CHECK(actor);
68 int UtcDaliLightActorDownCast(void)
70 TestApplication application;
71 tet_infoline("Testing Dali::LightActor::DownCast() UtcDaliLightActorDownCast");
73 LightActor actor1 = LightActor::New();
74 Actor anActor = Actor::New();
77 Actor child = anActor.GetChildAt(0);
78 LightActor lightActor = LightActor::DownCast(child);
80 DALI_TEST_CHECK(lightActor);
83 light = Light::New( "TestLight" );
84 BaseHandle handle = light;
86 DALI_TEST_CHECK( Light::DownCast( handle ) );
90 int UtcDaliLightActorDownCast2(void)
92 TestApplication application;
93 tet_infoline("Testing Dali::LightActor::DownCast2() UtcDaliLightActorDownCast2");
95 Actor actor1 = Actor::New();
96 Actor anActor = Actor::New();
99 Actor child = anActor.GetChildAt(0);
100 LightActor lightActor = LightActor::DownCast(child);
101 DALI_TEST_CHECK(!lightActor);
103 Actor unInitialzedActor;
104 lightActor = DownCast< LightActor >( unInitialzedActor );
105 DALI_TEST_CHECK(!lightActor);
109 int UtcDaliLightActorSetGetLight(void)
111 TestApplication application;
112 tet_infoline( "Testing UtcDaliLightActorSetGetLight" );
116 LightActor lightActor = LightActor::New();
117 Light light1 = Light::New( "" );
118 light1.SetName( "TestLight" );
119 light1.SetDirection( Vector3::ZAXIS );
120 light1.SetSpotAngle( Vector2::YAXIS );
121 lightActor.SetLight( light1 );
123 Light light2 = lightActor.GetLight();
125 DALI_TEST_EQUALS( light1.GetName(), light2.GetName(), TEST_LOCATION );
126 DALI_TEST_EQUALS( light1.GetType(), light2.GetType(), TEST_LOCATION );
127 DALI_TEST_EQUALS( light1.GetFallOff(), light2.GetFallOff(), TEST_LOCATION );
128 DALI_TEST_EQUALS( light1.GetSpotAngle(), light2.GetSpotAngle(), TEST_LOCATION );
129 DALI_TEST_EQUALS( light1.GetAmbientColor(), light2.GetAmbientColor(), TEST_LOCATION );
130 DALI_TEST_EQUALS( light1.GetDiffuseColor(), light2.GetDiffuseColor(), TEST_LOCATION );
131 DALI_TEST_EQUALS( light1.GetSpecularColor(), light2.GetSpecularColor(), TEST_LOCATION );
132 DALI_TEST_EQUALS( light1.GetDirection(), light2.GetDirection(), TEST_LOCATION );
134 catch( Dali::DaliException& e )
136 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
137 tet_result(TET_FAIL);
141 tet_infoline( "Unknown exception." );
142 tet_result(TET_FAIL);
147 int UtcDaliLightActorSetGetActive(void)
149 TestApplication application;
150 tet_infoline( "Testing UtcDaliLightActorSetGetActive" );
154 LightActor lightActor = LightActor::New();
155 lightActor.SetActive( true );
157 DALI_TEST_CHECK( lightActor.GetActive() );
159 lightActor.SetActive( false );
161 DALI_TEST_CHECK( !lightActor.GetActive() );
163 lightActor.SetActive( true );
165 DALI_TEST_CHECK( lightActor.GetActive() );
167 lightActor.SetActive( false );
169 DALI_TEST_CHECK( !lightActor.GetActive() );
171 catch( Dali::DaliException& e )
173 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
174 tet_result(TET_FAIL);
178 tet_infoline( "Unknown exception." );
179 tet_result(TET_FAIL);
185 int UtcDaliLightActorMeshTest(void)
187 TestApplication application;
188 tet_infoline( "Testing UtcDaliLightActorMeshTest" );
192 Mesh mesh = ConstructMesh( 50 );
193 Actor actor = MeshActor::New( mesh );
194 Stage::GetCurrent().Add( actor );
196 actor.SetParentOrigin( ParentOrigin::CENTER );
197 actor.SetAnchorPoint( AnchorPoint::CENTER );
198 actor.SetPosition( 0.0f, 0.0f, 0.0f );
200 Light light = Light::New("Light");
201 light.SetType( POINT );
202 light.SetAmbientColor( Vector3( 0.22f, 0.33f, 0.44f ) );
203 light.SetDiffuseColor( Vector3( 0.55f, 0.66f, 0.77f) );
204 light.SetSpecularColor( Vector3( 0.88f, 0.99f, 0.11f) );
205 LightActor lightActor = LightActor::New();
206 lightActor.SetParentOrigin( ParentOrigin::CENTER );
207 lightActor.SetPosition( 0.f, 0.f, 100.0f );
208 lightActor.SetLight( light );
209 lightActor.SetName( light.GetName() );
211 Stage::GetCurrent().Add( lightActor );
212 lightActor.SetActive( true );
214 application.SendNotification();
215 application.Render();
217 // Test Ligh ambient.
218 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mAmbient", Vector3( 0.22f, 0.33f, 0.44f ) ) );
220 // Test Ligh diffuse.
221 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mDiffuse", Vector3( 0.55f, 0.66f, 0.77f ) ) );
223 // Test Ligh specular.
224 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mSpecular", Vector3( 0.88f, 0.99f, 0.11f ) ) );
227 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mOpacity", 0.76f ) );
229 // Test material Ambient color.
230 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mAmbient", Vector4(0.2f, 1.0f, 0.6f, 1.0f) ) );
232 // Test material Diffuse color.
233 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mDiffuse", Vector4(0.8f, 0.0f, 0.4f, 1.0f) ) );
235 // Test Specular color.
236 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mSpecular", Vector4(0.5f, 0.6f, 0.7f, 1.0f) ) );
238 catch( Dali::DaliException& e )
240 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
241 tet_result(TET_FAIL);
245 tet_infoline( "Unknown exception." );
246 tet_result(TET_FAIL);
249 DALI_TEST_CHECK( true );
253 int UtcDaliLightActorDefaultProperties(void)
255 TestApplication application;
256 tet_infoline("Testing Dali::LightActor DefaultProperties");
258 LightActor actor = LightActor::New();
260 std::vector<Property::Index> indices ;
261 indices.push_back(LightActor::LIGHT_TYPE );
262 indices.push_back(LightActor::ENABLE );
263 indices.push_back(LightActor::FALL_OFF );
264 indices.push_back(LightActor::SPOT_ANGLE );
265 indices.push_back(LightActor::AMBIENT_COLOR );
266 indices.push_back(LightActor::DIFFUSE_COLOR );
267 indices.push_back(LightActor::SPECULAR_COLOR );
268 indices.push_back(LightActor::DIRECTION );
270 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
272 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
274 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
275 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
276 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
277 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
280 // set/get one of them
281 actor.GetLight().SetAmbientColor( Vector3( 0.f, 0.f, 0.f ) );
282 Vector3 col( 0.22f, 0.33f, 0.44f ) ;
283 DALI_TEST_CHECK(actor.GetLight().GetAmbientColor() != col);
284 actor.SetProperty(LightActor::AMBIENT_COLOR, col);
285 Property::Value v = actor.GetProperty(LightActor::AMBIENT_COLOR);
286 DALI_TEST_CHECK(v.GetType() == Property::VECTOR3);
288 DALI_TEST_CHECK(v.Get<Vector3>() == col);
293 int UtcDaliLightActorPropertyIndices(void)
295 TestApplication application;
296 Actor basicActor = Actor::New();
297 LightActor light = LightActor::New();
299 Property::IndexContainer indices;
300 light.GetPropertyIndices( indices );
301 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
302 DALI_TEST_EQUALS( indices.size(), light.GetPropertyCount(), TEST_LOCATION );
309 struct PropertyDetails
311 Property::Index index;
316 const PropertyDetails DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[] =
319 { LightActor::LIGHT_TYPE, "light-type", Property::STRING },
320 { LightActor::ENABLE, "enable", Property::BOOLEAN },
321 { LightActor::FALL_OFF, "fall-off", Property::VECTOR2 },
322 { LightActor::SPOT_ANGLE, "spot-angle", Property::VECTOR2 },
323 { LightActor::AMBIENT_COLOR, "ambient-color", Property::VECTOR3 },
324 { LightActor::DIFFUSE_COLOR, "diffuse-color", Property::VECTOR3 },
325 { LightActor::SPECULAR_COLOR, "specular-color", Property::VECTOR3 },
326 { LightActor::DIRECTION, "direction", Property::VECTOR3 },
328 const int DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT = sizeof( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS ) / sizeof( PropertyDetails );
329 } // unnamed namespace
331 int UtcDaliLightActorProperties(void)
333 TestApplication application;
334 Actor basicActor = Actor::New();
335 LightActor light = LightActor::New();
337 Property::IndexContainer indices;
338 light.GetPropertyIndices( indices );
339 DALI_TEST_EQUALS( DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT, indices.size() - basicActor.GetPropertyCount(), TEST_LOCATION );
341 for ( int i = 0; i < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT; ++i )
343 tet_printf( "Checking: %s\n", DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].name.c_str() );
344 DALI_TEST_EQUALS( light.GetPropertyIndex( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].name ), DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index, TEST_LOCATION );
345 DALI_TEST_EQUALS( light.GetPropertyName( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index ), DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].name, TEST_LOCATION );
346 DALI_TEST_EQUALS( light.GetPropertyType( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index ), DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].type, TEST_LOCATION );
347 DALI_TEST_EQUALS( light.IsPropertyWritable( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index ), true, TEST_LOCATION );
348 DALI_TEST_EQUALS( light.IsPropertyAnimatable( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index ), false, TEST_LOCATION );
349 DALI_TEST_EQUALS( light.IsPropertyAConstraintInput( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[i].index ), true, TEST_LOCATION );