1be8e8c670920e6ee2eaa5ba7ebd6b8fabfa5b08
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-DynamicsJoint.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
23
24 using namespace Dali;
25
26
27 int UtcDaliDynamicsJointConstructor(void)
28 {
29   tet_infoline("UtcDaliDynamicsJointConstructor - DynamicsJoint::DynamicsJoint");
30
31   TestApplication application;
32
33   // start up
34   application.SendNotification();
35   application.Render();
36   application.Render();
37
38   DynamicsJoint joint;
39
40   DALI_TEST_CHECK( !joint );
41   END_TEST;
42 }
43
44 int UtcDaliDynamicsJointLinearLimit(void)
45 {
46 #if !defined(DYNAMICS_SUPPORT)
47   tet_infoline("No dynamics support compiled\n");
48   return 0;
49 #endif
50   TestApplication application;
51
52   // start up
53   application.SendNotification();
54   application.Render();
55   application.Render();
56
57   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
58   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
59
60
61   if( !world )
62   {
63     // cannot create dynamics world, log failure and exit
64     DALI_TEST_CHECK( false );
65     END_TEST;
66   }
67
68   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
69   Actor actor1(Actor::New());
70   actor1.EnableDynamics(bodyConfig);
71   Actor actor2(Actor::New());
72   actor2.EnableDynamics(bodyConfig);
73
74   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
75
76   if( joint )
77   {
78     tet_infoline("UtcDaliDynamicsJointLinearLimit - DynamicsJoint::SetLinearLimit()");
79     joint.SetLinearLimit(DynamicsJoint::LINEAR_X, 0.0f, 1.0f);
80   }
81   DALI_TEST_CHECK( true );
82   END_TEST;
83 }
84
85 int UtcDaliDynamicsJointAngularLimit(void)
86 {
87 #if !defined(DYNAMICS_SUPPORT)
88   tet_infoline("No dynamics support compiled\n");
89   return 0;
90 #endif
91   TestApplication application;
92
93   // start up
94   application.SendNotification();
95   application.Render();
96   application.Render();
97
98   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
99   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
100
101   if( !world )
102   {
103     // cannot create dynamics world, log failure and exit
104     DALI_TEST_CHECK( false );
105     END_TEST;
106   }
107
108   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
109   Actor actor1(Actor::New());
110   actor1.EnableDynamics(bodyConfig);
111   Actor actor2(Actor::New());
112   actor2.EnableDynamics(bodyConfig);
113
114   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
115
116   tet_infoline("UtcDaliDynamicsJointAngularLimit - DynamicsJoint::SetAngularLimit()");
117   joint.SetAngularLimit(DynamicsJoint::ANGULAR_X, Degree(0.0f), Degree(1.0f) );
118   DALI_TEST_CHECK( true );
119   END_TEST;
120 }
121
122 int UtcDaliDynamicsJointEnableSpring(void)
123 {
124 #if !defined(DYNAMICS_SUPPORT)
125   tet_infoline("No dynamics support compiled\n");
126   return 0;
127 #endif
128   TestApplication application;
129
130   // start up
131   application.SendNotification();
132   application.Render();
133   application.Render();
134
135   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
136   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
137
138   if( !world )
139   {
140     // cannot create dynamics world, log failure and exit
141     DALI_TEST_CHECK( false );
142     END_TEST;
143   }
144
145   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
146   Actor actor1(Actor::New());
147   actor1.EnableDynamics(bodyConfig);
148   Actor actor2(Actor::New());
149   actor2.EnableDynamics(bodyConfig);
150
151   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
152
153   tet_infoline("UtcDaliDynamicsJointEnableSpring");
154   joint.EnableSpring(DynamicsJoint::LINEAR_X, true );
155   DALI_TEST_CHECK( true );
156   END_TEST;
157 }
158
159 int UtcDaliDynamicsJointSetSpringStiffness(void)
160 {
161 #if !defined(DYNAMICS_SUPPORT)
162   tet_infoline("No dynamics support compiled\n");
163   return 0;
164 #endif
165   TestApplication application;
166
167   // start up
168   application.SendNotification();
169   application.Render();
170   application.Render();
171
172   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
173   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
174
175   if( !world )
176   {
177     // cannot create dynamics world, log failure and exit
178     DALI_TEST_CHECK( false );
179     END_TEST;
180   }
181
182   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
183   Actor actor1(Actor::New());
184   actor1.EnableDynamics(bodyConfig);
185   Actor actor2(Actor::New());
186   actor2.EnableDynamics(bodyConfig);
187
188   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
189
190   tet_infoline("UtcDaliDynamicsJointSetSpringStiffness");
191   joint.SetSpringStiffness(DynamicsJoint::LINEAR_X, 1.0f );
192   DALI_TEST_CHECK( true );
193   END_TEST;
194 }
195
196 int UtcDaliDynamicsJointSetSpringCenterPoint(void)
197 {
198 #if !defined(DYNAMICS_SUPPORT)
199   tet_infoline("No dynamics support compiled\n");
200   return 0;
201 #endif
202   TestApplication application;
203
204   // start up
205   application.SendNotification();
206   application.Render();
207   application.Render();
208
209   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
210   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
211
212   if( !world )
213   {
214     // cannot create dynamics world, log failure and exit
215     DALI_TEST_CHECK( false );
216     END_TEST;
217   }
218
219   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
220   Actor actor1(Actor::New());
221   actor1.EnableDynamics(bodyConfig);
222   Actor actor2(Actor::New());
223   actor2.EnableDynamics(bodyConfig);
224
225   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
226
227   tet_infoline("UtcDaliDynamicsJointSetSpringCenterPoint");
228   joint.SetSpringCenterPoint(DynamicsJoint::LINEAR_X, 0.5f );
229   DALI_TEST_CHECK( true );
230   END_TEST;
231 }
232
233 int UtcDaliDynamicsJointEnableMotor(void)
234 {
235 #if !defined(DYNAMICS_SUPPORT)
236   tet_infoline("No dynamics support compiled\n");
237   return 0;
238 #endif
239   TestApplication application;
240
241   // start up
242   application.SendNotification();
243   application.Render();
244   application.Render();
245
246   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
247   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
248
249   if( !world )
250   {
251     // cannot create dynamics world, log failure and exit
252     DALI_TEST_CHECK( false );
253     END_TEST;
254   }
255
256   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
257   Actor actor1(Actor::New());
258   actor1.EnableDynamics(bodyConfig);
259   Actor actor2(Actor::New());
260   actor2.EnableDynamics(bodyConfig);
261
262   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
263
264   tet_infoline("UtcDaliDynamicsJointEnableMotor");
265   joint.EnableMotor(DynamicsJoint::LINEAR_X, true );
266   DALI_TEST_CHECK( true );
267   END_TEST;
268 }
269
270 int UtcDaliDynamicsJointSetMotorVelocity(void)
271 {
272 #if !defined(DYNAMICS_SUPPORT)
273   tet_infoline("No dynamics support compiled\n");
274   return 0;
275 #endif
276   TestApplication application;
277
278   // start up
279   application.SendNotification();
280   application.Render();
281   application.Render();
282
283   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
284   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
285
286   if( !world )
287   {
288     // cannot create dynamics world, log failure and exit
289     DALI_TEST_CHECK( false );
290     END_TEST;
291   }
292
293   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
294   Actor actor1(Actor::New());
295   actor1.EnableDynamics(bodyConfig);
296   Actor actor2(Actor::New());
297   actor2.EnableDynamics(bodyConfig);
298
299   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
300
301   tet_infoline("UtcDaliDynamicsJointSetMotorVelocity");
302   joint.SetMotorVelocity(DynamicsJoint::LINEAR_X, 1.0f );
303   DALI_TEST_CHECK( true );
304   END_TEST;
305 }
306
307 int UtcDaliDynamicsJointSetMotorForce(void)
308 {
309 #if !defined(DYNAMICS_SUPPORT)
310   tet_infoline("No dynamics support compiled\n");
311   return 0;
312 #endif
313   TestApplication application;
314
315   // start up
316   application.SendNotification();
317   application.Render();
318   application.Render();
319
320   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
321   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(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   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
331   Actor actor1(Actor::New());
332   actor1.EnableDynamics(bodyConfig);
333   Actor actor2(Actor::New());
334   actor2.EnableDynamics(bodyConfig);
335
336   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
337
338   tet_infoline("UtcDaliDynamicsJointSetMotorForce");
339   joint.SetMotorForce(DynamicsJoint::LINEAR_X, 0.5f );
340   DALI_TEST_CHECK( true );
341   END_TEST;
342 }
343
344 int UtcDaliDynamicsJointGetActor(void)
345 {
346 #if !defined(DYNAMICS_SUPPORT)
347   tet_infoline("No dynamics support compiled\n");
348   return 0;
349 #endif
350   TestApplication application;
351
352   // start up
353   application.SendNotification();
354   application.Render();
355   application.Render();
356
357   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
358   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
359
360   if( !world )
361   {
362     // cannot create dynamics world, log failure and exit
363     DALI_TEST_CHECK( false );
364     END_TEST;
365   }
366
367   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
368   Actor actor1(Actor::New());
369   actor1.EnableDynamics(bodyConfig);
370   Actor actor2(Actor::New());
371   actor2.EnableDynamics(bodyConfig);
372
373   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
374
375   tet_infoline("UtcDaliDynamicsJointGetActor");
376   DALI_TEST_CHECK( joint.GetActor(true) == actor1 && joint.GetActor(false) == actor2 );
377   END_TEST;
378 }