UTC public API updates: stage.h
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-DynamicsWorld.cpp
1 /*
2  * Copyright (c) 2014 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 <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <test-dynamics.h>
23 #include <dali/devel-api/dynamics/dynamics.h>
24
25 using namespace Dali;
26
27 // Note: dali-core needs to be configured and built with --enable-dynamics for these tests to run.
28
29 int UtcDaliDynamicsWorldConstructor(void)
30 {
31 #if !defined(DYNAMICS_SUPPORT)
32   tet_infoline("No dynamics support compiled\n");
33   return 0;
34 #endif
35   tet_infoline("UtcDaliDynamicsWorldConstructor - DynamicsWorld::DynamicsWorld");
36
37   TestApplication application;
38
39   // start up
40   application.SendNotification();
41   application.Render();
42   application.Render();
43
44   // Default constructor - create an uninitialized handle
45   DynamicsWorld world;
46   DALI_TEST_CHECK( !world );
47
48   // initialize handle
49   DynamicsWorldConfig worldConfig( DynamicsWorldConfig::New() );
50   world =  DynamicsWorld::GetInstance( worldConfig );
51
52   DALI_TEST_CHECK( world );
53   END_TEST;
54 }
55
56 int UtcDaliDynamicsWorldGetInstanceP(void)
57 {
58 #if !defined(DYNAMICS_SUPPORT)
59   tet_infoline( "No dynamics support compiled\n" );
60   return 0;
61 #endif
62   TestApplication app;
63   Stage stage = Stage::GetCurrent();
64   TraceCallStack& trace = app.GetPlatform().GetTrace();
65   trace.Enable(true);
66
67   DynamicsWorldConfig config = DynamicsWorldConfig::New();
68
69   bool asserted = false;
70   try
71   {
72     DALI_TEST_CHECK( DynamicsWorld::GetInstance( config ) );
73   }
74   catch( Dali::DaliException& e )
75   {
76     DALI_TEST_PRINT_ASSERT( e );
77     asserted = true;
78   }
79   DALI_TEST_CHECK( !asserted );
80
81   DALI_TEST_CHECK( trace.FindMethod( "GetDynamicsFactory" ) );
82   DALI_TEST_CHECK( trace.FindMethod( "DynamicsFactory::InitializeDynamics" ) );
83
84   END_TEST;
85 }
86
87 int UtcDaliDynamicsWorldGetInstanceN(void)
88 {
89 #if !defined(DYNAMICS_SUPPORT)
90   tet_infoline( "No dynamics support compiled\n" );
91   return 0;
92 #endif
93   TestApplication app;
94
95   DynamicsWorldConfig config;
96
97   // Check that creating a DynamicsWorld instance without a valid config causes an assert.
98   bool asserted = false;
99   try
100   {
101     DynamicsWorld::GetInstance( config );
102   }
103   catch( Dali::DaliException& e )
104   {
105     DALI_TEST_PRINT_ASSERT( e );
106     DALI_TEST_ASSERT( e, "object && \"DynamicsWorldConfig object is uninitialized!\"", TEST_LOCATION );
107     asserted = true;
108   }
109   DALI_TEST_CHECK( asserted );
110
111   END_TEST;
112 }
113
114 int UtcDaliDynamicsWorldGetP(void)
115 {
116 #if !defined(DYNAMICS_SUPPORT)
117   tet_infoline( "No dynamics support compiled\n" );
118   return 0;
119 #endif
120   TestApplication app;
121
122   DynamicsWorldConfig config = DynamicsWorldConfig::New();
123
124   bool asserted = false;
125   try
126   {
127     DynamicsWorld::GetInstance( config );
128     DynamicsWorld world = DynamicsWorld::Get();
129     DALI_TEST_CHECK( world );
130   }
131   catch( Dali::DaliException& e )
132   {
133     DALI_TEST_PRINT_ASSERT( e );
134     asserted = true;
135   }
136   DALI_TEST_CHECK( !asserted );
137
138   END_TEST;
139 }
140
141 int UtcDaliDynamicsWorldGetN(void)
142 {
143 #if !defined(DYNAMICS_SUPPORT)
144   tet_infoline( "No dynamics support compiled\n" );
145   return 0;
146 #endif
147   TestApplication app;
148
149   bool asserted = false;
150   try
151   {
152     DynamicsWorld::Get();
153   }
154   catch( Dali::DaliException& e )
155   {
156     DALI_TEST_PRINT_ASSERT( e );
157     DALI_TEST_ASSERT( e, "dynamicsWorld && \"DynamicsWorld doesn't exist\"", TEST_LOCATION );
158     asserted = true;
159   }
160   DALI_TEST_CHECK( asserted );
161
162   END_TEST;
163 }
164
165 int UtcDaliDynamicsWorldDestroyInstanceP(void)
166 {
167 #if !defined(DYNAMICS_SUPPORT)
168   tet_infoline( "No dynamics support compiled\n" );
169   return 0;
170 #endif
171   TestApplication app;
172
173   DynamicsWorldConfig config = DynamicsWorldConfig::New();
174   DynamicsWorld world = DynamicsWorld::GetInstance( config );
175   DALI_TEST_CHECK( world );
176   DynamicsWorld::DestroyInstance();
177
178   // After destroying the instance, check we assert when trying to get the instance,
179   // to prove that it's been removed correctly.
180   bool asserted = false;
181   try
182   {
183     DynamicsWorld::Get();
184   }
185   catch( Dali::DaliException& e )
186   {
187     DALI_TEST_PRINT_ASSERT( e );
188     DALI_TEST_ASSERT( e, "dynamicsWorld && \"DynamicsWorld doesn't exist\"", TEST_LOCATION );
189     asserted = true;
190   }
191   DALI_TEST_CHECK( asserted );
192
193   END_TEST;
194 }
195
196 int UtcDaliDynamicsWorldDestroyInstanceN(void)
197 {
198 #if !defined(DYNAMICS_SUPPORT)
199   tet_infoline( "No dynamics support compiled\n" );
200   return 0;
201 #endif
202   TestApplication app;
203
204   // Check that calling DestroyInstance() when there is no instance is safe.
205   bool asserted = false;
206   try
207   {
208     DynamicsWorld::DestroyInstance();
209   }
210   catch( Dali::DaliException& e )
211   {
212     DALI_TEST_PRINT_ASSERT( e );
213     asserted = true;
214   }
215   DALI_TEST_CHECK( !asserted );
216
217   END_TEST;
218 }
219
220 int UtcDaliDynamicsWorldGravity(void)
221 {
222 #if !defined(DYNAMICS_SUPPORT)
223   tet_infoline("No dynamics support compiled\n");
224   return 0;
225 #endif
226   TestApplication application;
227   TraceCallStack& trace( application.GetPlatform().GetTrace() );
228   trace.Enable( true );
229
230   // start up
231   application.SendNotification();
232   application.Render();
233   application.Render();
234
235   const Vector3 gravity(1.0f, 2.0f, 3.0f);
236
237   DynamicsWorldConfig worldConfig( DynamicsWorldConfig::New() );
238   DynamicsWorld world( DynamicsWorld::GetInstance( worldConfig ) );
239
240   if( !world )
241   {
242     // cannot create dynamics world, log failure and exit
243     DALI_TEST_CHECK( false );
244     END_TEST;
245   }
246
247   tet_infoline("UtcDaliDynamicsWorldGravity - DynamicsWorld::SetGravity");
248   world.SetGravity(gravity);
249
250   // update
251   application.SendNotification();
252   application.Render();
253   application.Render();
254
255   DALI_TEST_CHECK( trace.FindMethod( "DynamicsWorld::SetGravity" ) );
256
257   tet_infoline("UtcDaliDynamicsWorldGravity - DynamicsWorld::GetGravity");
258   DALI_TEST_EQUALS(gravity, world.GetGravity(), TEST_LOCATION);
259   END_TEST;
260 }
261
262 int UtcDaliDynamicsWorldDebugDrawMode(void)
263 {
264 #if !defined(DYNAMICS_SUPPORT)
265   tet_infoline("No dynamics support compiled\n");
266   return 0;
267 #endif
268   TestApplication application;
269   TraceCallStack& trace( application.GetPlatform().GetTrace() );
270   trace.Enable( true );
271
272   // start up
273   application.SendNotification();
274   application.Render();
275   application.Render();
276
277   const Vector3 gravity(1.0f, 2.0f, 3.0f);
278   DynamicsWorldConfig worldConfig( DynamicsWorldConfig::New() );
279   DynamicsWorld world( DynamicsWorld::GetInstance( worldConfig ) );
280
281   if( !world )
282   {
283     // cannot create dynamics world, log failure and exit
284     DALI_TEST_CHECK( false );
285     END_TEST;
286   }
287
288   const int mode(DynamicsWorld::DEBUG_MODE_WIREFRAME | DynamicsWorld::DEBUG_MODE_AABB);
289
290   tet_infoline("UtcDaliDynamicsWorldDebugDrawMode - DynamicsWorld::SetDebugDrawMode");
291   world.SetDebugDrawMode(mode);
292
293   // update
294   application.SendNotification();
295   application.Render();
296   application.Render();
297
298   DALI_TEST_CHECK( trace.FindMethod( "DynamicsWorld::SetDebugDrawMode" ) );
299   DALI_TEST_CHECK( trace.FindMethod( "DynamicsWorld::SetGravity" ) );
300
301   tet_infoline("UtcDaliDynamicsWorldDebugDrawMode - DynamicsWorld::GetDebugDrawMode");
302   DALI_TEST_CHECK(mode == world.GetDebugDrawMode());
303   END_TEST;
304 }
305
306 int UtcDaliDynamicsWorldRootActor(void)
307 {
308 #if !defined(DYNAMICS_SUPPORT)
309   tet_infoline("No dynamics support compiled\n");
310   return 0;
311 #endif
312   TestApplication application;
313
314   // start up
315   application.SendNotification();
316   application.Render();
317   application.Render();
318
319   const Vector3 gravity(1.0f, 2.0f, 3.0f);
320   DynamicsWorldConfig worldConfig( DynamicsWorldConfig::New() );
321   DynamicsWorld world( DynamicsWorld::GetInstance( worldConfig ) );
322
323   if( !world )
324   {
325     // cannot create dynamics world, log failure and exit
326     DALI_TEST_CHECK( false );
327     END_TEST;
328   }
329
330   Actor rootActor(Actor::New());
331
332   tet_infoline("UtcDaliDynamicsWorldDebugDrawMode - DynamicsWorld::GetRootActor");
333   Actor actor(world.GetRootActor());
334   DALI_TEST_CHECK( !actor );
335
336   tet_infoline("UtcDaliDynamicsWorldSetRootActor - DynamicsWorld::SetRootActor");
337   world.SetRootActor(rootActor);
338   DALI_TEST_CHECK(rootActor == world.GetRootActor());
339   END_TEST;
340 }