2 * Copyright (c) 2020 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/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
25 using namespace Dali::Internal;
29 // Knots fed into Allegro, which generates control points
30 static void SetupPath( Dali::Path& path)
32 path.AddPoint(Vector3( 30.0, 80.0, 0.0));
33 path.AddPoint(Vector3( 70.0, 120.0, 0.0));
34 path.AddPoint(Vector3(100.0, 100.0, 0.0));
36 //Control points for first segment
37 path.AddControlPoint( Vector3( 39.0, 90.0, 0.0) );
38 path.AddControlPoint(Vector3( 56.0, 119.0, 0.0) );
40 //Control points for second segment
41 path.AddControlPoint(Vector3( 78.0, 120.0, 0.0) );
42 path.AddControlPoint(Vector3( 93.0, 104.0, 0.0) );
45 } // anonymous namespace
47 int utcDaliPathGetPoint(void)
49 TestApplication application;
51 Dali::Path path = Dali::Path::New();
52 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
53 path.AddPoint(Vector3(120.0, 70.0, 0.0));
54 path.AddPoint(Vector3(190.0, 250.0, 0.0));
55 path.AddPoint(Vector3(260.0, 260.0, 0.0));
56 path.AddPoint(Vector3(330.0, 220.0, 0.0));
57 path.AddPoint(Vector3(400.0, 50.0, 0.0));
59 DALI_TEST_EQUALS(path.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION);
60 DALI_TEST_EQUALS(path.GetPoint(1), Vector3(120.0, 70.0, 0.0), TEST_LOCATION);
61 DALI_TEST_EQUALS(path.GetPoint(2), Vector3(190.0, 250.0, 0.0), TEST_LOCATION);
62 DALI_TEST_EQUALS(path.GetPoint(3), Vector3(260.0, 260.0, 0.0), TEST_LOCATION);
63 DALI_TEST_EQUALS(path.GetPoint(4), Vector3(330.0, 220.0, 0.0), TEST_LOCATION);
64 DALI_TEST_EQUALS(path.GetPoint(5), Vector3(400.0, 50.0, 0.0), TEST_LOCATION);
68 int utcDaliPathGetPoint02(void)
70 TestApplication application;
72 Dali::Path path = Dali::Path::New();
73 path.AddPoint(Vector3( 50.0, 50.0, 0.0f));
80 catch (Dali::DaliException& e)
82 DALI_TEST_PRINT_ASSERT( e );
83 DALI_TEST_ASSERT(e, "index < mPoint.Size()", TEST_LOCATION);
88 int utcDaliPathGetPoint03(void)
90 TestApplication application;
92 Dali::Path path = Dali::Path::New();
99 catch (Dali::DaliException& e)
101 DALI_TEST_PRINT_ASSERT( e );
102 DALI_TEST_ASSERT(e, "index < mPoint.Size()", TEST_LOCATION);
107 int utcDaliPathGetControlPoints(void)
109 TestApplication application;
111 Dali::Path path = Dali::Path::New();
112 path.AddControlPoint( Vector3(0.0f, 0.0f, 0.0) );
113 path.AddControlPoint( Vector3(108.0f, 57.0f, 0.0) );
115 DALI_TEST_EQUALS(path.GetControlPoint(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION);
116 DALI_TEST_EQUALS(path.GetControlPoint(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION);
120 int utcDaliPathGetControlPoints01(void)
122 TestApplication application;
124 Dali::Path path = Dali::Path::New();
125 path.AddControlPoint(Vector3(0.0f, 0.0f, 0.0) );
126 path.AddControlPoint(Vector3(108.0f, 57.0f, 0.0) );
130 path.GetControlPoint(5);
131 tet_result(TET_FAIL);
133 catch (Dali::DaliException& e)
135 DALI_TEST_PRINT_ASSERT( e );
136 DALI_TEST_ASSERT(e, "index < mControlPoint.Size()", TEST_LOCATION);
141 int utcDaliPathGetControlPoints02(void)
143 TestApplication application;
145 Dali::Path path = Dali::Path::New();
148 path.GetControlPoint(0);
149 tet_result(TET_FAIL);
151 catch (Dali::DaliException& e)
153 DALI_TEST_PRINT_ASSERT( e );
154 DALI_TEST_ASSERT(e, "index < mControlPoint.Size()", TEST_LOCATION);
159 int utcDaliPathGenerateControlPoints01(void)
161 TestApplication application;
163 Dali::Path path = Dali::Path::New();
165 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
166 path.AddPoint(Vector3(120.0, 70.0, 0.0));
167 path.AddPoint(Vector3(190.0, 250.0, 0.0));
168 path.AddPoint(Vector3(260.0, 260.0, 0.0));
169 path.AddPoint(Vector3(330.0, 220.0, 0.0));
170 path.AddPoint(Vector3(400.0, 50.0, 0.0));
172 path.GenerateControlPoints(0.25);
174 DALI_TEST_EQUALS(path.GetControlPoint(0), Vector3( 68.0, 55.0, 0.0), 1.0, TEST_LOCATION);
175 DALI_TEST_EQUALS(path.GetControlPoint(1), Vector3(107.0, 58.0, 0.0), 1.0, TEST_LOCATION);
177 DALI_TEST_EQUALS(path.GetControlPoint(2), Vector3(156.0, 102.0, 0.0), 1.0, TEST_LOCATION);
178 DALI_TEST_EQUALS(path.GetControlPoint(3), Vector3(152.0, 220.0, 0.0), 1.0, TEST_LOCATION);
180 DALI_TEST_EQUALS(path.GetControlPoint(4), Vector3(204.0, 261.0, 0.0), 1.0, TEST_LOCATION);
181 DALI_TEST_EQUALS(path.GetControlPoint(5), Vector3(243.0, 263.0, 0.0), 1.0, TEST_LOCATION);
183 DALI_TEST_EQUALS(path.GetControlPoint(6), Vector3(280.0, 256.0, 0.0), 1.0, TEST_LOCATION);
184 DALI_TEST_EQUALS(path.GetControlPoint(7), Vector3(317.0, 235.0, 0.0), 1.0, TEST_LOCATION);
186 DALI_TEST_EQUALS(path.GetControlPoint(8), Vector3(360.0, 185.0, 0.0), 1.0, TEST_LOCATION);
187 DALI_TEST_EQUALS(path.GetControlPoint(9), Vector3(383.0, 93.0, 0.0), 1.0, TEST_LOCATION);
192 int utcDaliPathGetPointCount(void)
194 TestApplication application;
195 Dali::Path path = Dali::Path::New();
197 DALI_TEST_EQUALS(path.GetPointCount(), 0u, TEST_LOCATION);
199 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
200 path.AddPoint(Vector3(120.0, 70.0, 0.0));
201 path.AddPoint(Vector3(190.0, 250.0, 0.0));
202 path.AddPoint(Vector3(260.0, 260.0, 0.0));
204 DALI_TEST_EQUALS(path.GetPointCount(), 4u, TEST_LOCATION);
206 path.AddPoint(Vector3(330.0, 220.0, 0.0));
207 path.AddPoint(Vector3(400.0, 50.0, 0.0));
209 DALI_TEST_EQUALS(path.GetPointCount(), 6u, TEST_LOCATION);
213 int utcDaliPathGenerateControlPoints02(void)
215 TestApplication application;
217 Dali::Path path = Dali::Path::New();
220 path.GenerateControlPoints(0.25);
221 tet_result(TET_FAIL);
223 catch (Dali::DaliException& e)
225 DALI_TEST_PRINT_ASSERT( e );
226 DALI_TEST_ASSERT(e, "numSegments > 0", TEST_LOCATION);
231 int utcDaliPathGenerateControlPoints03(void)
233 TestApplication application;
235 Dali::Path path = Dali::Path::New();
236 path.AddPoint(Vector3(400.0, 50.0, 0.0f));
239 path.GenerateControlPoints(0.25);
240 tet_result(TET_FAIL);
242 catch (Dali::DaliException& e)
244 DALI_TEST_PRINT_ASSERT( e );
245 DALI_TEST_ASSERT(e, "numSegments > 0", TEST_LOCATION);
250 int UtcDaliPathSample01(void)
252 TestApplication application;
253 Dali::Path path = Dali::Path::New();
257 Vector3 position, tangent;
258 path.Sample(0.0f, position, tangent );
259 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
260 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
261 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
262 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
265 path.Sample(0.25f, position, tangent );
266 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
267 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
268 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
269 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
272 path.Sample(0.5f, position, tangent );
273 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
274 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
275 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
276 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
280 path.Sample(0.75f, position, tangent );
281 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
282 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
283 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
284 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
287 path.Sample(1.0f, position, tangent );
288 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
289 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
290 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
291 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
296 int UtcDaliPathDownCast(void)
298 TestApplication application;
300 Dali::Path path = Dali::Path::New();
301 Handle handle = path;
304 Dali::Path path2 = Dali::Path::DownCast(handle);
305 DALI_TEST_CHECK(path2);
308 Vector3 position, tangent;
309 path2.Sample(0.0f, position, tangent );
310 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
311 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
312 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
313 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
316 path2.Sample(0.25f, position, tangent );
317 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
318 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
319 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
320 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
323 path2.Sample(0.5f, position, tangent );
324 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
325 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
326 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
327 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
331 path2.Sample(0.75f, position, tangent );
332 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
333 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
334 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
335 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
338 path2.Sample(1.0f, position, tangent );
339 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
340 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
341 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
342 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
347 int UtcDaliPathAssignment(void)
349 TestApplication application;
351 Dali::Path path = Dali::Path::New();
356 DALI_TEST_CHECK(path2);
359 Vector3 position, tangent;
360 path2.Sample(0.0f, position, tangent );
361 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
362 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
363 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
364 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
367 path2.Sample(0.25f, position, tangent );
368 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
369 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
370 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
371 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
374 path2.Sample(0.5f, position, tangent );
375 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
376 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
377 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
378 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
382 path2.Sample(0.75f, position, tangent );
383 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
384 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
385 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
386 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
389 path2.Sample(1.0f, position, tangent );
390 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
391 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
392 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
393 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
398 int UtcDaliPathPropertyPoints(void)
400 TestApplication application;
402 Dali::Path path = Dali::Path::New();
404 Dali::Property::Array points;
405 points.Add( Vector3( 100.0f, 100.0f, 100.0f ) )
406 .Add( Vector3( 200.0f, 200.0f, 200.0f ) )
407 .Add( Vector3( 300.0f, 300.0f, 300.0f ) );
408 path.SetProperty( Dali::Path::Property::POINTS, points );
411 Property::Value value = path.GetProperty( Dali::Path::Property::POINTS );
412 Property::Array* array = value.GetArray();
413 DALI_TEST_CHECK( array );
415 const unsigned int noOfPoints = points.Size();
416 for( unsigned int i = 0; i < noOfPoints; ++i )
418 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
423 Property::Value value = path.GetCurrentProperty( Dali::Path::Property::POINTS );
424 Property::Array* array = value.GetArray();
425 DALI_TEST_CHECK( array );
427 const unsigned int noOfPoints = points.Size();
428 for( unsigned int i = 0; i < noOfPoints; ++i )
430 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
437 int UtcDaliPathPropertyControlPoints(void)
439 TestApplication application;
441 Dali::Path path = Dali::Path::New();
443 Dali::Property::Array points;
444 points.Add( Vector3( 0.1f, 0.1f, 0.1f ) )
445 .Add( Vector3( 0.2f, 0.2f, 0.2f ) )
446 .Add( Vector3( 0.3f, 0.3f, 0.3f ) );
447 path.SetProperty( Dali::Path::Property::CONTROL_POINTS, points );
450 Property::Value value = path.GetProperty( Dali::Path::Property::CONTROL_POINTS );
451 Property::Array* array = value.GetArray();
452 DALI_TEST_CHECK( array );
454 const unsigned int noOfPoints = points.Size();
455 for( unsigned int i = 0; i < noOfPoints; ++i )
457 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
462 Property::Value value = path.GetCurrentProperty( Dali::Path::Property::CONTROL_POINTS );
463 Property::Array* array = value.GetArray();
464 DALI_TEST_CHECK( array );
466 const unsigned int noOfPoints = points.Size();
467 for( unsigned int i = 0; i < noOfPoints; ++i )
469 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
476 int UtcDaliPathRegisterProperty(void)
478 TestApplication application;
480 Dali::Path path = Dali::Path::New();
482 Property::Index index = path.RegisterProperty( "sceneProperty", 0.f );
483 DALI_TEST_EQUALS( index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
484 DALI_TEST_EQUALS( path.GetProperty< float >( index ), 0.f, TEST_LOCATION );
486 path.SetProperty( index, -1 );
487 DALI_TEST_EQUALS( path.GetProperty< float >( index ), -1.f, TEST_LOCATION );
489 using Dali::Animation;
490 Animation animation = Animation::New( 1.0f );
491 animation.AnimateTo( Property( path, index ), 100.f );
493 DALI_TEST_EQUALS( path.GetProperty< float >( index ), -1.f, TEST_LOCATION );
494 // Start the animation
497 application.SendNotification();
498 application.Render( 1000 /* 100% progress */);
499 DALI_TEST_EQUALS( path.GetProperty< float >( index ), 100.0f, TEST_LOCATION );
504 int UtcDaliPathMoveConstrcutor(void)
506 TestApplication application;
508 Dali::Path path = Dali::Path::New();
509 DALI_TEST_CHECK( path );
510 DALI_TEST_EQUALS( 1, path.GetBaseObject().ReferenceCount(), TEST_LOCATION );
512 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
513 DALI_TEST_EQUALS( path.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION );
515 Dali::Path move = std::move( path );
516 DALI_TEST_CHECK( move );
517 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
518 DALI_TEST_EQUALS( move.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION );
519 DALI_TEST_CHECK( !path );
524 int UtcDaliPathMoveAssignment(void)
526 TestApplication application;
528 Dali::Path path = Dali::Path::New();
529 DALI_TEST_CHECK( path );
530 DALI_TEST_EQUALS( 1, path.GetBaseObject().ReferenceCount(), TEST_LOCATION );
532 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
533 DALI_TEST_EQUALS( path.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION );
536 move = std::move( path );
537 DALI_TEST_CHECK( move );
538 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
539 DALI_TEST_EQUALS( move.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION );
540 DALI_TEST_CHECK( !path );
545 int UtcDaliPathAddControlPointNegative(void)
547 TestApplication application;
552 instance.AddControlPoint(arg1);
553 DALI_TEST_CHECK(false); // Should not get here
557 DALI_TEST_CHECK(true); // We expect an assert
562 int UtcDaliPathGetControlPointNegative(void)
564 TestApplication application;
568 unsigned long arg1(0u);
569 instance.GetControlPoint(arg1);
570 DALI_TEST_CHECK(false); // Should not get here
574 DALI_TEST_CHECK(true); // We expect an assert
579 int UtcDaliPathGenerateControlPointsNegative(void)
581 TestApplication application;
586 instance.GenerateControlPoints(arg1);
587 DALI_TEST_CHECK(false); // Should not get here
591 DALI_TEST_CHECK(true); // We expect an assert
596 int UtcDaliPathAddPointNegative(void)
598 TestApplication application;
603 instance.AddPoint(arg1);
604 DALI_TEST_CHECK(false); // Should not get here
608 DALI_TEST_CHECK(true); // We expect an assert
613 int UtcDaliPathGetPointNegative(void)
615 TestApplication application;
619 unsigned long arg1(0u);
620 instance.GetPoint(arg1);
621 DALI_TEST_CHECK(false); // Should not get here
625 DALI_TEST_CHECK(true); // We expect an assert
630 int UtcDaliPathGetPointCountNegative(void)
632 TestApplication application;
636 instance.GetPointCount();
637 DALI_TEST_CHECK(false); // Should not get here
641 DALI_TEST_CHECK(true); // We expect an assert
646 int UtcDaliPathSampleNegative(void)
648 TestApplication application;
655 instance.Sample(arg1,arg2,arg3);
656 DALI_TEST_CHECK(false); // Should not get here
660 DALI_TEST_CHECK(true); // We expect an assert