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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.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);
279 path.Sample(0.75f, position, tangent);
280 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
281 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
282 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
283 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
286 path.Sample(1.0f, position, tangent);
287 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
288 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
289 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
290 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
295 int UtcDaliPathDownCast(void)
297 TestApplication application;
299 Dali::Path path = Dali::Path::New();
300 Handle handle = path;
303 Dali::Path path2 = Dali::Path::DownCast(handle);
304 DALI_TEST_CHECK(path2);
307 Vector3 position, tangent;
308 path2.Sample(0.0f, position, tangent);
309 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
310 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
311 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
312 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
315 path2.Sample(0.25f, position, tangent);
316 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
317 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
318 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
319 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
322 path2.Sample(0.5f, position, tangent);
323 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
324 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
325 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
326 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
329 path2.Sample(0.75f, position, tangent);
330 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
331 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
332 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
333 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
336 path2.Sample(1.0f, position, tangent);
337 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
338 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
339 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
340 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
345 int UtcDaliPathAssignment(void)
347 TestApplication application;
349 Dali::Path path = Dali::Path::New();
354 DALI_TEST_CHECK(path2);
357 Vector3 position, tangent;
358 path2.Sample(0.0f, position, tangent);
359 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
360 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
361 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
362 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
365 path2.Sample(0.25f, position, tangent);
366 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
367 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
368 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
369 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
372 path2.Sample(0.5f, position, tangent);
373 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
374 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
375 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
376 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
379 path2.Sample(0.75f, position, tangent);
380 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
381 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
382 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
383 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
386 path2.Sample(1.0f, position, tangent);
387 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
388 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
389 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
390 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
395 int UtcDaliPathPropertyPoints(void)
397 TestApplication application;
399 Dali::Path path = Dali::Path::New();
401 Dali::Property::Array points;
402 points.Add(Vector3(100.0f, 100.0f, 100.0f))
403 .Add(Vector3(200.0f, 200.0f, 200.0f))
404 .Add(Vector3(300.0f, 300.0f, 300.0f));
405 path.SetProperty(Dali::Path::Property::POINTS, points);
408 Property::Value value = path.GetProperty(Dali::Path::Property::POINTS);
409 Property::Array* array = value.GetArray();
410 DALI_TEST_CHECK(array);
412 const unsigned int noOfPoints = points.Size();
413 for(unsigned int i = 0; i < noOfPoints; ++i)
415 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
420 Property::Value value = path.GetCurrentProperty(Dali::Path::Property::POINTS);
421 Property::Array* array = value.GetArray();
422 DALI_TEST_CHECK(array);
424 const unsigned int noOfPoints = points.Size();
425 for(unsigned int i = 0; i < noOfPoints; ++i)
427 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
434 int UtcDaliPathPropertyControlPoints(void)
436 TestApplication application;
438 Dali::Path path = Dali::Path::New();
440 Dali::Property::Array points;
441 points.Add(Vector3(0.1f, 0.1f, 0.1f))
442 .Add(Vector3(0.2f, 0.2f, 0.2f))
443 .Add(Vector3(0.3f, 0.3f, 0.3f));
444 path.SetProperty(Dali::Path::Property::CONTROL_POINTS, points);
447 Property::Value value = path.GetProperty(Dali::Path::Property::CONTROL_POINTS);
448 Property::Array* array = value.GetArray();
449 DALI_TEST_CHECK(array);
451 const unsigned int noOfPoints = points.Size();
452 for(unsigned int i = 0; i < noOfPoints; ++i)
454 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
459 Property::Value value = path.GetCurrentProperty(Dali::Path::Property::CONTROL_POINTS);
460 Property::Array* array = value.GetArray();
461 DALI_TEST_CHECK(array);
463 const unsigned int noOfPoints = points.Size();
464 for(unsigned int i = 0; i < noOfPoints; ++i)
466 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
473 int UtcDaliPathRegisterProperty(void)
475 TestApplication application;
477 Dali::Path path = Dali::Path::New();
479 Property::Index index = path.RegisterProperty("sceneProperty", 0.f);
480 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
481 DALI_TEST_EQUALS(path.GetProperty<float>(index), 0.f, TEST_LOCATION);
483 path.SetProperty(index, -1);
484 DALI_TEST_EQUALS(path.GetProperty<float>(index), -1.f, TEST_LOCATION);
486 using Dali::Animation;
487 Animation animation = Animation::New(1.0f);
488 animation.AnimateTo(Property(path, index), 100.f);
490 DALI_TEST_EQUALS(path.GetProperty<float>(index), -1.f, TEST_LOCATION);
491 // Start the animation
494 application.SendNotification();
495 application.Render(1000 /* 100% progress */);
496 DALI_TEST_EQUALS(path.GetProperty<float>(index), 100.0f, TEST_LOCATION);
501 int UtcDaliPathMoveConstrcutor(void)
503 TestApplication application;
505 Dali::Path path = Dali::Path::New();
506 DALI_TEST_CHECK(path);
507 DALI_TEST_EQUALS(1, path.GetBaseObject().ReferenceCount(), TEST_LOCATION);
509 path.AddPoint(Vector3(50.0, 50.0, 0.0));
510 DALI_TEST_EQUALS(path.GetPoint(0), Vector3(50.0, 50.0, 0.0), TEST_LOCATION);
512 Dali::Path move = std::move(path);
513 DALI_TEST_CHECK(move);
514 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
515 DALI_TEST_EQUALS(move.GetPoint(0), Vector3(50.0, 50.0, 0.0), TEST_LOCATION);
516 DALI_TEST_CHECK(!path);
521 int UtcDaliPathMoveAssignment(void)
523 TestApplication application;
525 Dali::Path path = Dali::Path::New();
526 DALI_TEST_CHECK(path);
527 DALI_TEST_EQUALS(1, path.GetBaseObject().ReferenceCount(), TEST_LOCATION);
529 path.AddPoint(Vector3(50.0, 50.0, 0.0));
530 DALI_TEST_EQUALS(path.GetPoint(0), Vector3(50.0, 50.0, 0.0), TEST_LOCATION);
533 move = std::move(path);
534 DALI_TEST_CHECK(move);
535 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
536 DALI_TEST_EQUALS(move.GetPoint(0), Vector3(50.0, 50.0, 0.0), TEST_LOCATION);
537 DALI_TEST_CHECK(!path);
542 int UtcDaliPathAddControlPointNegative(void)
544 TestApplication application;
549 instance.AddControlPoint(arg1);
550 DALI_TEST_CHECK(false); // Should not get here
554 DALI_TEST_CHECK(true); // We expect an assert
559 int UtcDaliPathGetControlPointNegative(void)
561 TestApplication application;
565 unsigned long arg1(0u);
566 instance.GetControlPoint(arg1);
567 DALI_TEST_CHECK(false); // Should not get here
571 DALI_TEST_CHECK(true); // We expect an assert
576 int UtcDaliPathGenerateControlPointsNegative(void)
578 TestApplication application;
583 instance.GenerateControlPoints(arg1);
584 DALI_TEST_CHECK(false); // Should not get here
588 DALI_TEST_CHECK(true); // We expect an assert
593 int UtcDaliPathAddPointNegative(void)
595 TestApplication application;
600 instance.AddPoint(arg1);
601 DALI_TEST_CHECK(false); // Should not get here
605 DALI_TEST_CHECK(true); // We expect an assert
610 int UtcDaliPathGetPointNegative(void)
612 TestApplication application;
616 unsigned long arg1(0u);
617 instance.GetPoint(arg1);
618 DALI_TEST_CHECK(false); // Should not get here
622 DALI_TEST_CHECK(true); // We expect an assert
627 int UtcDaliPathGetPointCountNegative(void)
629 TestApplication application;
633 instance.GetPointCount();
634 DALI_TEST_CHECK(false); // Should not get here
638 DALI_TEST_CHECK(true); // We expect an assert
643 int UtcDaliPathSampleNegative(void)
645 TestApplication application;
652 instance.Sample(arg1, arg2, arg3);
653 DALI_TEST_CHECK(false); // Should not get here
657 DALI_TEST_CHECK(true); // We expect an assert