removed reliance on dali-adaptor
[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   TestApplication application;
47
48   // start up
49   application.SendNotification();
50   application.Render();
51   application.Render();
52
53   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
54   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
55
56
57   if( !world )
58   {
59     // cannot create dynamics world, log failure and exit
60     DALI_TEST_CHECK( false );
61     END_TEST;
62   }
63
64   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
65   Actor actor1(Actor::New());
66   actor1.EnableDynamics(bodyConfig);
67   Actor actor2(Actor::New());
68   actor2.EnableDynamics(bodyConfig);
69
70   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
71
72   if( joint )
73   {
74     tet_infoline("UtcDaliDynamicsJointLinearLimit - DynamicsJoint::SetLinearLimit()");
75     joint.SetLinearLimit(DynamicsJoint::LINEAR_X, 0.0f, 1.0f);
76   }
77   DALI_TEST_CHECK( true );
78   END_TEST;
79 }
80
81 int UtcDaliDynamicsJointAngularLimit(void)
82 {
83   TestApplication application;
84
85   // start up
86   application.SendNotification();
87   application.Render();
88   application.Render();
89
90   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
91   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
92
93   if( !world )
94   {
95     // cannot create dynamics world, log failure and exit
96     DALI_TEST_CHECK( false );
97     END_TEST;
98   }
99
100   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
101   Actor actor1(Actor::New());
102   actor1.EnableDynamics(bodyConfig);
103   Actor actor2(Actor::New());
104   actor2.EnableDynamics(bodyConfig);
105
106   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
107
108   tet_infoline("UtcDaliDynamicsJointAngularLimit - DynamicsJoint::SetAngularLimit()");
109   joint.SetAngularLimit(DynamicsJoint::ANGULAR_X, Degree(0.0f), Degree(1.0f) );
110   DALI_TEST_CHECK( true );
111   END_TEST;
112 }
113
114 int UtcDaliDynamicsJointEnableSpring(void)
115 {
116   TestApplication application;
117
118   // start up
119   application.SendNotification();
120   application.Render();
121   application.Render();
122
123   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
124   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
125
126   if( !world )
127   {
128     // cannot create dynamics world, log failure and exit
129     DALI_TEST_CHECK( false );
130     END_TEST;
131   }
132
133   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
134   Actor actor1(Actor::New());
135   actor1.EnableDynamics(bodyConfig);
136   Actor actor2(Actor::New());
137   actor2.EnableDynamics(bodyConfig);
138
139   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
140
141   tet_infoline("UtcDaliDynamicsJointEnableSpring");
142   joint.EnableSpring(DynamicsJoint::LINEAR_X, true );
143   DALI_TEST_CHECK( true );
144   END_TEST;
145 }
146
147 int UtcDaliDynamicsJointSetSpringStiffness(void)
148 {
149   TestApplication application;
150
151   // start up
152   application.SendNotification();
153   application.Render();
154   application.Render();
155
156   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
157   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
158
159   if( !world )
160   {
161     // cannot create dynamics world, log failure and exit
162     DALI_TEST_CHECK( false );
163     END_TEST;
164   }
165
166   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
167   Actor actor1(Actor::New());
168   actor1.EnableDynamics(bodyConfig);
169   Actor actor2(Actor::New());
170   actor2.EnableDynamics(bodyConfig);
171
172   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
173
174   tet_infoline("UtcDaliDynamicsJointSetSpringStiffness");
175   joint.SetSpringStiffness(DynamicsJoint::LINEAR_X, 1.0f );
176   DALI_TEST_CHECK( true );
177   END_TEST;
178 }
179
180 int UtcDaliDynamicsJointSetSpringCenterPoint(void)
181 {
182   TestApplication application;
183
184   // start up
185   application.SendNotification();
186   application.Render();
187   application.Render();
188
189   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
190   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
191
192   if( !world )
193   {
194     // cannot create dynamics world, log failure and exit
195     DALI_TEST_CHECK( false );
196     END_TEST;
197   }
198
199   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
200   Actor actor1(Actor::New());
201   actor1.EnableDynamics(bodyConfig);
202   Actor actor2(Actor::New());
203   actor2.EnableDynamics(bodyConfig);
204
205   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
206
207   tet_infoline("UtcDaliDynamicsJointSetSpringCenterPoint");
208   joint.SetSpringCenterPoint(DynamicsJoint::LINEAR_X, 0.5f );
209   DALI_TEST_CHECK( true );
210   END_TEST;
211 }
212
213 int UtcDaliDynamicsJointEnableMotor(void)
214 {
215   TestApplication application;
216
217   // start up
218   application.SendNotification();
219   application.Render();
220   application.Render();
221
222   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
223   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
224
225   if( !world )
226   {
227     // cannot create dynamics world, log failure and exit
228     DALI_TEST_CHECK( false );
229     END_TEST;
230   }
231
232   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
233   Actor actor1(Actor::New());
234   actor1.EnableDynamics(bodyConfig);
235   Actor actor2(Actor::New());
236   actor2.EnableDynamics(bodyConfig);
237
238   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
239
240   tet_infoline("UtcDaliDynamicsJointEnableMotor");
241   joint.EnableMotor(DynamicsJoint::LINEAR_X, true );
242   DALI_TEST_CHECK( true );
243   END_TEST;
244 }
245
246 int UtcDaliDynamicsJointSetMotorVelocity(void)
247 {
248   TestApplication application;
249
250   // start up
251   application.SendNotification();
252   application.Render();
253   application.Render();
254
255   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
256   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
257
258   if( !world )
259   {
260     // cannot create dynamics world, log failure and exit
261     DALI_TEST_CHECK( false );
262     END_TEST;
263   }
264
265   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
266   Actor actor1(Actor::New());
267   actor1.EnableDynamics(bodyConfig);
268   Actor actor2(Actor::New());
269   actor2.EnableDynamics(bodyConfig);
270
271   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
272
273   tet_infoline("UtcDaliDynamicsJointSetMotorVelocity");
274   joint.SetMotorVelocity(DynamicsJoint::LINEAR_X, 1.0f );
275   DALI_TEST_CHECK( true );
276   END_TEST;
277 }
278
279 int UtcDaliDynamicsJointSetMotorForce(void)
280 {
281   TestApplication application;
282
283   // start up
284   application.SendNotification();
285   application.Render();
286   application.Render();
287
288   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
289   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
290
291   if( !world )
292   {
293     // cannot create dynamics world, log failure and exit
294     DALI_TEST_CHECK( false );
295     END_TEST;
296   }
297
298   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
299   Actor actor1(Actor::New());
300   actor1.EnableDynamics(bodyConfig);
301   Actor actor2(Actor::New());
302   actor2.EnableDynamics(bodyConfig);
303
304   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
305
306   tet_infoline("UtcDaliDynamicsJointSetMotorForce");
307   joint.SetMotorForce(DynamicsJoint::LINEAR_X, 0.5f );
308   DALI_TEST_CHECK( true );
309   END_TEST;
310 }
311
312 int UtcDaliDynamicsJointGetActor(void)
313 {
314   TestApplication application;
315
316   // start up
317   application.SendNotification();
318   application.Render();
319   application.Render();
320
321   DynamicsWorldConfig worldConfig(DynamicsWorldConfig::New());
322   DynamicsWorld world( Stage::GetCurrent().InitializeDynamics(worldConfig) );
323
324   if( !world )
325   {
326     // cannot create dynamics world, log failure and exit
327     DALI_TEST_CHECK( false );
328     END_TEST;
329   }
330
331   DynamicsBodyConfig bodyConfig(DynamicsBodyConfig::New());
332   Actor actor1(Actor::New());
333   actor1.EnableDynamics(bodyConfig);
334   Actor actor2(Actor::New());
335   actor2.EnableDynamics(bodyConfig);
336
337   DynamicsJoint joint( actor1.AddDynamicsJoint(actor2, Vector3() ) );
338
339   tet_infoline("UtcDaliDynamicsJointGetActor");
340   DALI_TEST_CHECK( joint.GetActor(true) == actor1 && joint.GetActor(false) == actor2 );
341   END_TEST;
342 }