2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
24 #include <dali-test-suite-utils.h>
28 #include <mesh-builder.h>
30 static void Startup();
31 static void Cleanup();
34 void (*tet_startup)() = Startup;
35 void (*tet_cleanup)() = Cleanup;
39 POSITIVE_TC_IDX = 0x01,
43 #define MAX_NUMBER_OF_TESTS 10000
45 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 TEST_FUNCTION( UtcDaliLightActorConstructorVoid, POSITIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliLightActorConstructorRefObject, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliLightActorDestructor, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliLightActorNew, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliLightActorDownCast, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliLightActorDownCast2, NEGATIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliLightActorSetGetLight, POSITIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliLightActorSetGetActive, POSITIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliLightActorMeshTest, POSITIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliLightActorDefaultProperties, POSITIVE_TC_IDX );
59 TEST_FUNCTION( UtcDaliLightActorPropertyIndices, POSITIVE_TC_IDX );
61 // Called only once before first test is run.
64 // THERE IS NO MAINLOOP IN THE TEST APPLICATION
67 // Called only once after last test is run
72 static void UtcDaliLightActorConstructorVoid()
74 TestApplication application;
75 tet_infoline("Testing Dali::LightActor::LightActor() UtcDaliLightActorConstructorVoid");
79 DALI_TEST_CHECK(!actor);
82 static void UtcDaliLightActorConstructorRefObject()
84 TestApplication application;
85 tet_infoline("Testing Dali::LightActor::LightActor(Internal::LightActor*) UtcDaliLightActorConstructorRefObject");
87 LightActor actor(NULL);
89 DALI_TEST_CHECK(!actor);
92 static void UtcDaliLightActorDestructor()
94 // This test is achieve 100% line and function coverage
95 TestApplication application;
96 tet_infoline("Testing Dali::LightActor::~LightActor() UtcDaliLightActorDestructor");
98 LightActor* actor = new LightActor;
100 DALI_TEST_CHECK( ! *actor );
104 DALI_TEST_CHECK( true );
107 static void UtcDaliLightActorNew()
109 TestApplication application;
110 tet_infoline("Testing Dali::LightActor::New() UtcDaliLightActorNew");
112 LightActor actor = LightActor::New();
114 DALI_TEST_CHECK(actor);
117 static void UtcDaliLightActorDownCast()
119 TestApplication application;
120 tet_infoline("Testing Dali::LightActor::DownCast() UtcDaliLightActorDownCast");
122 LightActor actor1 = LightActor::New();
123 Actor anActor = Actor::New();
126 Actor child = anActor.GetChildAt(0);
127 LightActor lightActor = LightActor::DownCast(child);
129 DALI_TEST_CHECK(lightActor);
132 light = Light::New( "TestLight" );
133 BaseHandle handle = light;
135 DALI_TEST_CHECK( Light::DownCast( handle ) );
138 static void UtcDaliLightActorDownCast2()
140 TestApplication application;
141 tet_infoline("Testing Dali::LightActor::DownCast2() UtcDaliLightActorDownCast2");
143 Actor actor1 = Actor::New();
144 Actor anActor = Actor::New();
147 Actor child = anActor.GetChildAt(0);
148 LightActor lightActor = LightActor::DownCast(child);
149 DALI_TEST_CHECK(!lightActor);
151 Actor unInitialzedActor;
152 lightActor = DownCast< LightActor >( unInitialzedActor );
153 DALI_TEST_CHECK(!lightActor);
156 static void UtcDaliLightActorSetGetLight()
158 TestApplication application;
159 tet_infoline( "Testing UtcDaliLightActorSetGetLight" );
163 LightActor lightActor = LightActor::New();
164 Light light1 = Light::New( "" );
165 light1.SetName( "TestLight" );
166 light1.SetDirection( Vector3::ZAXIS );
167 light1.SetSpotAngle( Vector2::YAXIS );
168 lightActor.SetLight( light1 );
170 Light light2 = lightActor.GetLight();
172 DALI_TEST_EQUALS( light1.GetName(), light2.GetName(), TEST_LOCATION );
173 DALI_TEST_EQUALS( light1.GetType(), light2.GetType(), TEST_LOCATION );
174 DALI_TEST_EQUALS( light1.GetFallOff(), light2.GetFallOff(), TEST_LOCATION );
175 DALI_TEST_EQUALS( light1.GetSpotAngle(), light2.GetSpotAngle(), TEST_LOCATION );
176 DALI_TEST_EQUALS( light1.GetAmbientColor(), light2.GetAmbientColor(), TEST_LOCATION );
177 DALI_TEST_EQUALS( light1.GetDiffuseColor(), light2.GetDiffuseColor(), TEST_LOCATION );
178 DALI_TEST_EQUALS( light1.GetSpecularColor(), light2.GetSpecularColor(), TEST_LOCATION );
179 DALI_TEST_EQUALS( light1.GetDirection(), light2.GetDirection(), TEST_LOCATION );
181 catch( Dali::DaliException& e )
183 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
184 tet_result(TET_FAIL);
188 tet_infoline( "Unknown exception." );
189 tet_result(TET_FAIL);
193 static void UtcDaliLightActorSetGetActive()
195 TestApplication application;
196 tet_infoline( "Testing UtcDaliLightActorSetGetActive" );
200 LightActor lightActor = LightActor::New();
201 lightActor.SetActive( true );
203 DALI_TEST_CHECK( lightActor.GetActive() );
205 lightActor.SetActive( false );
207 DALI_TEST_CHECK( !lightActor.GetActive() );
209 lightActor.SetActive( true );
211 DALI_TEST_CHECK( lightActor.GetActive() );
213 lightActor.SetActive( false );
215 DALI_TEST_CHECK( !lightActor.GetActive() );
217 catch( Dali::DaliException& e )
219 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
220 tet_result(TET_FAIL);
224 tet_infoline( "Unknown exception." );
225 tet_result(TET_FAIL);
230 static void UtcDaliLightActorMeshTest()
232 TestApplication application;
233 tet_infoline( "Testing UtcDaliLightActorMeshTest" );
237 Mesh mesh = ConstructMesh( 50 );
238 Actor actor = MeshActor::New( mesh );
239 Stage::GetCurrent().Add( actor );
241 actor.SetParentOrigin( ParentOrigin::CENTER );
242 actor.SetAnchorPoint( AnchorPoint::CENTER );
243 actor.SetPosition( 0.0f, 0.0f, 0.0f );
245 Light light = Light::New("Light");
246 light.SetType( POINT );
247 light.SetAmbientColor( Vector3( 0.22f, 0.33f, 0.44f ) );
248 light.SetDiffuseColor( Vector3( 0.55f, 0.66f, 0.77f) );
249 light.SetSpecularColor( Vector3( 0.88f, 0.99f, 0.11f) );
250 LightActor lightActor = LightActor::New();
251 lightActor.SetParentOrigin( ParentOrigin::CENTER );
252 lightActor.SetPosition( 0.f, 0.f, 100.0f );
253 lightActor.SetLight( light );
254 lightActor.SetName( light.GetName() );
256 Stage::GetCurrent().Add( lightActor );
257 lightActor.SetActive( true );
259 application.SendNotification();
260 application.Render();
262 // Test Ligh ambient.
263 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mAmbient", Vector3( 0.22f, 0.33f, 0.44f ) ) );
265 // Test Ligh diffuse.
266 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mDiffuse", Vector3( 0.55f, 0.66f, 0.77f ) ) );
268 // Test Ligh specular.
269 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uLight0.mSpecular", Vector3( 0.88f, 0.99f, 0.11f ) ) );
272 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mOpacity", 0.76f ) );
274 // Test material Ambient color.
275 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mAmbient", Vector4(0.2f, 1.0f, 0.6f, 1.0f) ) );
277 // Test material Diffuse color.
278 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mDiffuse", Vector4(0.8f, 0.0f, 0.4f, 1.0f) ) );
280 // Test Specular color.
281 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uMaterial.mSpecular", Vector4(0.5f, 0.6f, 0.7f, 1.0f) ) );
283 catch( Dali::DaliException& e )
285 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
286 tet_result(TET_FAIL);
290 tet_infoline( "Unknown exception." );
291 tet_result(TET_FAIL);
294 DALI_TEST_CHECK( true );
297 static void UtcDaliLightActorDefaultProperties()
299 TestApplication application;
300 tet_infoline("Testing Dali::LightActor DefaultProperties");
302 LightActor actor = LightActor::New();
304 std::vector<Property::Index> indices ;
305 indices.push_back(LightActor::LIGHT_TYPE );
306 indices.push_back(LightActor::ENABLE );
307 indices.push_back(LightActor::FALL_OFF );
308 indices.push_back(LightActor::SPOT_ANGLE );
309 indices.push_back(LightActor::AMBIENT_COLOR );
310 indices.push_back(LightActor::DIFFUSE_COLOR );
311 indices.push_back(LightActor::SPECULAR_COLOR );
312 indices.push_back(LightActor::DIRECTION );
314 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
316 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
318 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
319 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
320 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
321 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
324 // set/get one of them
325 actor.GetLight().SetAmbientColor( Vector3( 0.f, 0.f, 0.f ) );
326 Vector3 col( 0.22f, 0.33f, 0.44f ) ;
327 DALI_TEST_CHECK(actor.GetLight().GetAmbientColor() != col);
328 actor.SetProperty(LightActor::AMBIENT_COLOR, col);
329 Property::Value v = actor.GetProperty(LightActor::AMBIENT_COLOR);
330 DALI_TEST_CHECK(v.GetType() == Property::VECTOR3);
332 DALI_TEST_CHECK(v.Get<Vector3>() == col);
336 void UtcDaliLightActorPropertyIndices()
338 TestApplication application;
339 Actor basicActor = Actor::New();
340 LightActor light = LightActor::New();
342 Property::IndexContainer indices;
343 light.GetPropertyIndices( indices );
344 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
345 DALI_TEST_EQUALS( indices.size(), light.GetPropertyCount(), TEST_LOCATION );