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/dali.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 #include "mesh-builder.h"
30 int UtcDaliLightActorConstructorVoid(void)
32 TestApplication application;
33 tet_infoline("Testing Dali::LightActor::LightActor() UtcDaliLightActorConstructorVoid");
37 DALI_TEST_CHECK(!actor);
42 int UtcDaliLightActorDestructor(void)
44 // This test is achieve 100% line and function coverage
45 TestApplication application;
46 tet_infoline("Testing Dali::LightActor::~LightActor() UtcDaliLightActorDestructor");
48 LightActor* actor = new LightActor;
50 DALI_TEST_CHECK( ! *actor );
54 DALI_TEST_CHECK( true );
58 int UtcDaliLightActorNew(void)
60 TestApplication application;
61 tet_infoline("Testing Dali::LightActor::New() UtcDaliLightActorNew");
63 LightActor actor = LightActor::New();
65 DALI_TEST_CHECK(actor);
69 int UtcDaliLightActorDownCast(void)
71 TestApplication application;
72 tet_infoline("Testing Dali::LightActor::DownCast() UtcDaliLightActorDownCast");
74 LightActor actor1 = LightActor::New();
75 Actor anActor = Actor::New();
78 Actor child = anActor.GetChildAt(0);
79 LightActor lightActor = LightActor::DownCast(child);
81 DALI_TEST_CHECK(lightActor);
84 light = Light::New( "TestLight" );
85 BaseHandle handle = light;
87 DALI_TEST_CHECK( Light::DownCast( handle ) );
91 int UtcDaliLightActorDownCast2(void)
93 TestApplication application;
94 tet_infoline("Testing Dali::LightActor::DownCast2() UtcDaliLightActorDownCast2");
96 Actor actor1 = Actor::New();
97 Actor anActor = Actor::New();
100 Actor child = anActor.GetChildAt(0);
101 LightActor lightActor = LightActor::DownCast(child);
102 DALI_TEST_CHECK(!lightActor);
104 Actor unInitialzedActor;
105 lightActor = DownCast< LightActor >( unInitialzedActor );
106 DALI_TEST_CHECK(!lightActor);
110 int UtcDaliLightActorSetGetLight(void)
112 TestApplication application;
113 tet_infoline( "Testing UtcDaliLightActorSetGetLight" );
117 LightActor lightActor = LightActor::New();
118 Light light1 = Light::New( "" );
119 light1.SetName( "TestLight" );
120 light1.SetDirection( Vector3::ZAXIS );
121 light1.SetSpotAngle( Vector2::YAXIS );
122 lightActor.SetLight( light1 );
124 Light light2 = lightActor.GetLight();
126 DALI_TEST_EQUALS( light1.GetName(), light2.GetName(), TEST_LOCATION );
127 DALI_TEST_EQUALS( light1.GetType(), light2.GetType(), TEST_LOCATION );
128 DALI_TEST_EQUALS( light1.GetFallOff(), light2.GetFallOff(), TEST_LOCATION );
129 DALI_TEST_EQUALS( light1.GetSpotAngle(), light2.GetSpotAngle(), TEST_LOCATION );
130 DALI_TEST_EQUALS( light1.GetAmbientColor(), light2.GetAmbientColor(), TEST_LOCATION );
131 DALI_TEST_EQUALS( light1.GetDiffuseColor(), light2.GetDiffuseColor(), TEST_LOCATION );
132 DALI_TEST_EQUALS( light1.GetSpecularColor(), light2.GetSpecularColor(), TEST_LOCATION );
133 DALI_TEST_EQUALS( light1.GetDirection(), light2.GetDirection(), TEST_LOCATION );
135 catch( Dali::DaliException& e )
137 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
138 tet_result(TET_FAIL);
142 tet_infoline( "Unknown exception." );
143 tet_result(TET_FAIL);
148 int UtcDaliLightActorSetGetActive(void)
150 TestApplication application;
151 tet_infoline( "Testing UtcDaliLightActorSetGetActive" );
155 LightActor lightActor = LightActor::New();
156 lightActor.SetActive( true );
158 DALI_TEST_CHECK( lightActor.GetActive() );
160 lightActor.SetActive( false );
162 DALI_TEST_CHECK( !lightActor.GetActive() );
164 lightActor.SetActive( true );
166 DALI_TEST_CHECK( lightActor.GetActive() );
168 lightActor.SetActive( false );
170 DALI_TEST_CHECK( !lightActor.GetActive() );
172 catch( Dali::DaliException& e )
174 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
175 tet_result(TET_FAIL);
179 tet_infoline( "Unknown exception." );
180 tet_result(TET_FAIL);
186 int UtcDaliLightActorMeshTest(void)
188 TestApplication application;
189 tet_infoline( "Testing UtcDaliLightActorMeshTest" );
193 Mesh mesh = ConstructMesh( 50 );
194 Actor actor = MeshActor::New( mesh );
195 Stage::GetCurrent().Add( actor );
197 actor.SetParentOrigin( ParentOrigin::CENTER );
198 actor.SetAnchorPoint( AnchorPoint::CENTER );
199 actor.SetPosition( 0.0f, 0.0f, 0.0f );
201 Light light = Light::New("Light");
202 light.SetType( POINT );
203 light.SetAmbientColor( Vector3( 0.22f, 0.33f, 0.44f ) );
204 light.SetDiffuseColor( Vector3( 0.55f, 0.66f, 0.77f) );
205 light.SetSpecularColor( Vector3( 0.88f, 0.99f, 0.11f) );
206 LightActor lightActor = LightActor::New();
207 lightActor.SetParentOrigin( ParentOrigin::CENTER );
208 lightActor.SetPosition( 0.f, 0.f, 100.0f );
209 lightActor.SetLight( light );
210 lightActor.SetName( light.GetName() );
212 Stage::GetCurrent().Add( lightActor );
213 lightActor.SetActive( true );
215 application.SendNotification();
216 application.Render();
218 // Test Ligh ambient.
219 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mAmbient", Vector3( 0.22f, 0.33f, 0.44f ) ) );
221 // Test Ligh diffuse.
222 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mDiffuse", Vector3( 0.55f, 0.66f, 0.77f ) ) );
224 // Test Ligh specular.
225 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mSpecular", Vector3( 0.88f, 0.99f, 0.11f ) ) );
228 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mOpacity", 0.76f ) );
230 // Test material Ambient color.
231 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mAmbient", Vector4(0.2f, 1.0f, 0.6f, 1.0f) ) );
233 // Test material Diffuse color.
234 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mDiffuse", Vector4(0.8f, 0.0f, 0.4f, 1.0f) ) );
236 // Test Specular color.
237 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mSpecular", Vector4(0.5f, 0.6f, 0.7f, 1.0f) ) );
239 catch( Dali::DaliException& e )
241 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
242 tet_result(TET_FAIL);
246 tet_infoline( "Unknown exception." );
247 tet_result(TET_FAIL);
250 DALI_TEST_CHECK( true );
254 int UtcDaliLightActorDefaultProperties(void)
256 TestApplication application;
257 tet_infoline("Testing Dali::LightActor DefaultProperties");
259 LightActor actor = LightActor::New();
261 std::vector<Property::Index> indices ;
262 indices.push_back(LightActor::LIGHT_TYPE );
263 indices.push_back(LightActor::ENABLE );
264 indices.push_back(LightActor::FALL_OFF );
265 indices.push_back(LightActor::SPOT_ANGLE );
266 indices.push_back(LightActor::AMBIENT_COLOR );
267 indices.push_back(LightActor::DIFFUSE_COLOR );
268 indices.push_back(LightActor::SPECULAR_COLOR );
269 indices.push_back(LightActor::DIRECTION );
271 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
273 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
275 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
276 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
277 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
278 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
281 // set/get one of them
282 actor.GetLight().SetAmbientColor( Vector3( 0.f, 0.f, 0.f ) );
283 Vector3 col( 0.22f, 0.33f, 0.44f ) ;
284 DALI_TEST_CHECK(actor.GetLight().GetAmbientColor() != col);
285 actor.SetProperty(LightActor::AMBIENT_COLOR, col);
286 Property::Value v = actor.GetProperty(LightActor::AMBIENT_COLOR);
287 DALI_TEST_CHECK(v.GetType() == Property::VECTOR3);
289 DALI_TEST_CHECK(v.Get<Vector3>() == col);
294 int UtcDaliLightActorPropertyIndices(void)
296 TestApplication application;
297 Actor basicActor = Actor::New();
298 LightActor light = LightActor::New();
300 Property::IndexContainer indices;
301 light.GetPropertyIndices( indices );
302 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
303 DALI_TEST_EQUALS( indices.size(), light.GetPropertyCount(), TEST_LOCATION );