2 * Copyright (c) 2014 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;
32 // Knots fed into Allegro, which generates control points
33 static Spline* SetupBezierSpline1()
35 Spline *bezierSpline = new Spline();
37 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
38 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
39 bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0));
40 bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0));
41 bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0));
42 bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0));
44 bezierSpline->SetInTangent (0, Vector3( 0.0, 0.0, 0.0));
45 bezierSpline->SetInTangent (1, Vector3(107.0, 58.0, 0.0));
46 bezierSpline->SetInTangent (2, Vector3(152.0, 220.0, 0.0));
47 bezierSpline->SetInTangent (3, Vector3(243.0, 263.0, 0.0));
48 bezierSpline->SetInTangent (4, Vector3(317.0, 235.0, 0.0));
49 bezierSpline->SetInTangent (5, Vector3(383.0, 93.0, 0.0));
51 bezierSpline->SetOutTangent(0, Vector3( 68.0, 55.0, 0.0));
52 bezierSpline->SetOutTangent(1, Vector3(156.0, 102.0, 0.0));
53 bezierSpline->SetOutTangent(2, Vector3(204.0, 261.0, 0.0));
54 bezierSpline->SetOutTangent(3, Vector3(280.0, 256.0, 0.0));
55 bezierSpline->SetOutTangent(4, Vector3(360.0, 185.0, 0.0));
56 bezierSpline->SetOutTangent(5, Vector3(410.0, 40.0, 0.0));
60 // Knots fed into Allegro, which generates control points
61 static Spline* SetupBezierSpline2()
63 Spline *spline = new Spline();
64 spline->AddKnot(Vector3( 30.0, 80.0, 0.0));
65 spline->AddKnot(Vector3( 70.0, 120.0, 0.0));
66 spline->AddKnot(Vector3(100.0, 100.0, 0.0));
67 spline->SetInTangent (0, Vector3( 0.0, 0.0, 0.0));
68 spline->SetInTangent (1, Vector3( 56.0, 119.0, 0.0));
69 spline->SetInTangent (2, Vector3( 93.0, 104.0, 0.0));
70 spline->SetOutTangent(0, Vector3( 39.0, 90.0, 0.0));
71 spline->SetOutTangent(1, Vector3( 78.0, 120.0, 0.0));
72 spline->SetOutTangent(2, Vector3(110.0, 90.0, 0.0));
101 } // anonymous namespace
105 // Positive test case for a method
106 int UtcDaliSplineGetYFromMonotonicX(void)
108 TestApplication application;
110 Spline *bezierSpline = SetupBezierSpline1();
113 for(unsigned int i=0; i<sizeof(test)/sizeof(tPoint); i++)
115 DALI_TEST_EQUALS(1, 1, (const char *)TEST_LOCATION);
117 DALI_TEST_EQUALS((float)bezierSpline->GetYFromMonotonicX(test[i].x),
118 (float)test[i].y, 0.1f,
126 int utcDaliSplineGetKnot01(void)
128 TestApplication application;
130 Spline *bezierSpline= new Spline();
131 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
132 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
133 bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0));
134 bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0));
135 bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0));
136 bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0));
138 DALI_TEST_EQUALS(bezierSpline->GetKnot(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION);
139 DALI_TEST_EQUALS(bezierSpline->GetKnot(1), Vector3(120.0, 70.0, 0.0), TEST_LOCATION);
140 DALI_TEST_EQUALS(bezierSpline->GetKnot(2), Vector3(190.0, 250.0, 0.0), TEST_LOCATION);
141 DALI_TEST_EQUALS(bezierSpline->GetKnot(3), Vector3(260.0, 260.0, 0.0), TEST_LOCATION);
142 DALI_TEST_EQUALS(bezierSpline->GetKnot(4), Vector3(330.0, 220.0, 0.0), TEST_LOCATION);
143 DALI_TEST_EQUALS(bezierSpline->GetKnot(5), Vector3(400.0, 50.0, 0.0), TEST_LOCATION);
147 int utcDaliSplineGetKnot02(void)
149 TestApplication application;
151 Spline *bezierSpline= new Spline();
152 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0f));
156 bezierSpline->GetKnot(1);
157 tet_result(TET_FAIL);
159 catch (Dali::DaliException& e)
161 DALI_TEST_PRINT_ASSERT( e );
162 DALI_TEST_ASSERT(e, "knotIndex < mKnots.size()", TEST_LOCATION);
167 int utcDaliSplineGetKnot03(void)
169 TestApplication application;
171 Spline *bezierSpline= new Spline();
175 bezierSpline->GetKnot(0);
176 tet_result(TET_FAIL);
178 catch (Dali::DaliException& e)
180 DALI_TEST_PRINT_ASSERT( e );
181 DALI_TEST_ASSERT(e, "knotIndex < mKnots.size()", TEST_LOCATION);
186 int utcDaliSplineGetInTangent01(void)
188 TestApplication application;
190 Spline *bezierSpline= new Spline();
191 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
192 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
193 bezierSpline->SetInTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused
194 bezierSpline->SetInTangent(1, Vector3(108.0f, 57.0f, 0.0));
196 DALI_TEST_EQUALS(bezierSpline->GetInTangent(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION);
197 DALI_TEST_EQUALS(bezierSpline->GetInTangent(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION);
203 int utcDaliSplineGetInTangent02(void)
205 TestApplication application;
207 Spline *bezierSpline= new Spline();
208 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
209 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
210 bezierSpline->SetInTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused
211 bezierSpline->SetInTangent(1, Vector3(108.0f, 57.0f, 0.0));
215 bezierSpline->GetInTangent(5);
216 tet_result(TET_FAIL);
218 catch (Dali::DaliException& e)
220 DALI_TEST_PRINT_ASSERT( e );
221 DALI_TEST_ASSERT(e, "knotIndex < mInTangents.size()", TEST_LOCATION);
227 int utcDaliSplineGetInTangent03(void)
229 TestApplication application;
231 Spline *bezierSpline= new Spline();
234 bezierSpline->GetInTangent(0);
235 tet_result(TET_FAIL);
237 catch (Dali::DaliException& e)
239 DALI_TEST_PRINT_ASSERT( e );
240 DALI_TEST_ASSERT(e, "knotIndex < mInTangents.size()", TEST_LOCATION);
246 int utcDaliSplineGetOutTangent01(void)
248 TestApplication application;
250 Spline *bezierSpline= new Spline();
251 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
252 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
253 bezierSpline->SetOutTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused
254 bezierSpline->SetOutTangent(1, Vector3(108.0f, 57.0f, 0.0));
256 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION);
257 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION);
263 int utcDaliSplineGetOutTangent02(void)
265 TestApplication application;
267 Spline *bezierSpline= new Spline();
268 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
269 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
270 bezierSpline->SetOutTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused
271 bezierSpline->SetOutTangent(1, Vector3(108.0f, 57.0f, 0.0));
275 bezierSpline->GetOutTangent(5);
276 tet_result(TET_FAIL);
278 catch (Dali::DaliException& e)
280 DALI_TEST_PRINT_ASSERT( e );
281 DALI_TEST_ASSERT(e, "knotIndex < mOutTangents.size()", TEST_LOCATION);
287 int utcDaliSplineGetOutTangent03(void)
289 TestApplication application;
291 Spline *bezierSpline= new Spline();
294 bezierSpline->GetOutTangent(0);
295 tet_result(TET_FAIL);
297 catch (Dali::DaliException& e)
299 DALI_TEST_PRINT_ASSERT( e );
300 DALI_TEST_ASSERT(e, "knotIndex < mOutTangents.size()", TEST_LOCATION);
306 int utcDaliSplineGenerateControlPoints01(void)
308 TestApplication application;
310 Spline *bezierSpline = new Spline();
312 bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0));
313 bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0));
314 bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0));
315 bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0));
316 bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0));
317 bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0));
319 bezierSpline->GenerateControlPoints(0.25);
321 // first in tangent is never used, ignore it.
322 DALI_TEST_EQUALS(bezierSpline->GetInTangent(1), Vector3(107.0, 58.0, 0.0), 1.0, TEST_LOCATION);
323 DALI_TEST_EQUALS(bezierSpline->GetInTangent(2), Vector3(152.0, 220.0, 0.0), 1.0, TEST_LOCATION);
324 DALI_TEST_EQUALS(bezierSpline->GetInTangent(3), Vector3(243.0, 263.0, 0.0), 1.0, TEST_LOCATION);
325 DALI_TEST_EQUALS(bezierSpline->GetInTangent(4), Vector3(317.0, 235.0, 0.0), 1.0, TEST_LOCATION);
326 DALI_TEST_EQUALS(bezierSpline->GetInTangent(5), Vector3(383.0, 93.0, 0.0), 1.0, TEST_LOCATION);
328 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(0), Vector3( 68.0, 55.0, 0.0), 1.0, TEST_LOCATION);
329 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(1), Vector3(156.0, 102.0, 0.0), 1.0, TEST_LOCATION);
330 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(2), Vector3(204.0, 261.0, 0.0), 1.0, TEST_LOCATION);
331 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(3), Vector3(280.0, 256.0, 0.0), 1.0, TEST_LOCATION);
332 DALI_TEST_EQUALS(bezierSpline->GetOutTangent(4), Vector3(360.0, 185.0, 0.0), 1.0, TEST_LOCATION);
333 // last out tangent is never used, ignore it.
337 int utcDaliSplineGenerateControlPoints02(void)
339 TestApplication application;
341 Spline *bezierSpline = new Spline();
344 bezierSpline->GenerateControlPoints(0.25);
345 tet_result(TET_FAIL);
347 catch (Dali::DaliException& e)
349 DALI_TEST_PRINT_ASSERT( e );
350 DALI_TEST_ASSERT(e, "numKnots > 1", TEST_LOCATION);
356 int utcDaliSplineGenerateControlPoints03(void)
358 TestApplication application;
360 Spline *bezierSpline = new Spline();
361 bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0f));
364 bezierSpline->GenerateControlPoints(0.25);
365 tet_result(TET_FAIL);
367 catch (Dali::DaliException& e)
369 DALI_TEST_PRINT_ASSERT( e );
370 DALI_TEST_ASSERT(e, "numKnots > 1", TEST_LOCATION);
376 int UtcDaliSplineGetY01(void)
378 TestApplication application;
379 Spline *spline = SetupBezierSpline2();
381 DALI_TEST_EQUALS(spline->GetY(0, 0.0f), 80.0f, TEST_LOCATION); // First control point
382 DALI_TEST_EQUALS(spline->GetY(0, 0.5f), 102.0f, 2.0f, TEST_LOCATION);
383 DALI_TEST_EQUALS(spline->GetY(0, 1.0f), 120.0f, TEST_LOCATION); // Second control point
384 DALI_TEST_EQUALS(spline->GetY(1, 0.0f), 120.0f, TEST_LOCATION); // Second control point
385 DALI_TEST_EQUALS(spline->GetY(1, 0.5f), 112.0f, 2.0f, TEST_LOCATION);
386 DALI_TEST_EQUALS(spline->GetY(1, 1.0f), 100.0f, TEST_LOCATION); // Third control point
391 // Test segments outside range (should assert and fail tetcase!)
392 int UtcDaliSplineGetY02(void)
394 TestApplication application;
398 Spline *spline = SetupBezierSpline2();
399 spline->GetY(3, 0.0f); // Segment outside range - expect assertion
401 // If we get here, assertion hasn't triggered.
402 tet_result(TET_FAIL);
405 catch (Dali::DaliException& e)
407 DALI_TEST_PRINT_ASSERT( e );
408 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
413 // Test segments outside range (should assert and fail tetcase!)
414 int UtcDaliSplineGetY02b(void)
416 TestApplication application;
419 Spline *spline = SetupBezierSpline2();
420 spline->GetY(-1, 0.0f); // Segment outside range - expect assertion
422 // If we get here, assertion hasn't triggered.
423 tet_result(TET_FAIL);
426 catch (Dali::DaliException& e)
428 DALI_TEST_PRINT_ASSERT( e );
429 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
435 // Test parameter ouside 0-1 - should return 0.
436 int UtcDaliSplineGetY03(void)
438 TestApplication application;
439 Spline *spline = SetupBezierSpline2();
440 DALI_TEST_EQUALS(spline->GetY(1, -1.0f), 0.0f, TEST_LOCATION);
441 DALI_TEST_EQUALS(spline->GetY(1, 2.0f), 0.0f, TEST_LOCATION);
446 // Test on empty spline - should assert
447 int UtcDaliSplineGetY04(void)
449 TestApplication application;
452 Spline *spline = new Spline();
453 spline->GetY(0, 0.0f); // Should assert
454 tet_result(TET_FAIL);
457 catch (Dali::DaliException& e)
459 DALI_TEST_PRINT_ASSERT( e );
460 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
466 // Test on empty spline - should assert
467 int UtcDaliSplineGetY04b(void)
469 TestApplication application;
472 Spline *spline = new Spline();
473 spline->GetY(0, 1.0f);
474 tet_result(TET_FAIL); // assertion didn't trigger
477 catch (Dali::DaliException& e)
479 DALI_TEST_PRINT_ASSERT( e );
480 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
487 int UtcDaliSplineGetPoint01(void)
489 TestApplication application;
490 Spline *spline = SetupBezierSpline2();
492 // Test control points
493 Vector3 pt = spline->GetPoint(0, 0.0f);
494 DALI_TEST_EQUALS(pt.x, 30.0f, TEST_LOCATION);
495 DALI_TEST_EQUALS(pt.y, 80.0f, TEST_LOCATION);
497 // Test control points
498 pt = spline->GetPoint(0, 1.0f);
499 DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION);
500 DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION);
502 // Halfway point computed using Allegro engine
503 pt = spline->GetPoint(0, 0.5f);
504 DALI_TEST_EQUALS(pt.x, 47.0f, 2.0f, TEST_LOCATION);
505 DALI_TEST_EQUALS(pt.y, 102.0f, 2.0f, TEST_LOCATION);
507 // Test control point
508 pt = spline->GetPoint(1, 0.0f);
509 DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION);
510 DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION);
512 // Halfway point computed using Allegro engine
513 pt = spline->GetPoint(1, 0.5f);
514 DALI_TEST_EQUALS(pt.x, 85.0f, 2.0f, TEST_LOCATION);
515 DALI_TEST_EQUALS(pt.y, 112.0f, 2.0f, TEST_LOCATION);
517 // Test control points
518 pt = spline->GetPoint(1, 1.0f);
519 DALI_TEST_EQUALS(pt.x, 100.0f, TEST_LOCATION);
520 DALI_TEST_EQUALS(pt.y, 100.0f, TEST_LOCATION);
526 int UtcDaliSplineGetPoint02(void)
528 TestApplication application;
529 Spline *spline = SetupBezierSpline2();
531 // Test control points
532 Vector3 pt = spline->GetPoint(0.0f);
533 DALI_TEST_EQUALS(pt.x, 30.0f, TEST_LOCATION);
534 DALI_TEST_EQUALS(pt.y, 80.0f, TEST_LOCATION);
536 // Halfway point computed using Allegro engine
537 pt = spline->GetPoint(0.25f);
538 DALI_TEST_EQUALS(pt.x, 47.0f, 2.0f, TEST_LOCATION);
539 DALI_TEST_EQUALS(pt.y, 102.0f, 2.0f, TEST_LOCATION);
541 // Test control points
542 pt = spline->GetPoint(0.5f);
543 DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION);
544 DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION);
546 // Halfway point computed using Allegro engine
547 pt = spline->GetPoint(0.75f);
548 DALI_TEST_EQUALS(pt.x, 85.0f, 2.0f, TEST_LOCATION);
549 DALI_TEST_EQUALS(pt.y, 112.0f, 2.0f, TEST_LOCATION);
551 // Test control points
552 pt = spline->GetPoint(1.0f);
553 DALI_TEST_EQUALS(pt.x, 100.0f, TEST_LOCATION);
554 DALI_TEST_EQUALS(pt.y, 100.0f, TEST_LOCATION);
560 // Test on segment index out of bounds - should assert and fail tet case
561 int UtcDaliSplineGetPoint03(void)
563 TestApplication application;
566 Spline *spline = SetupBezierSpline2();
568 spline->GetPoint(-1, 0.5f); // should assert
569 tet_result(TET_FAIL);
572 catch (Dali::DaliException& e)
574 DALI_TEST_PRINT_ASSERT( e );
575 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
580 // Test on segment index out of bounds - should assert and fail tet case
581 int UtcDaliSplineGetPoint04(void)
583 TestApplication application;
586 Spline *spline = SetupBezierSpline2();
588 spline->GetPoint(123, 0.5f); // should assert
589 tet_result(TET_FAIL);
592 catch (Dali::DaliException& e)
594 DALI_TEST_PRINT_ASSERT( e );
595 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
601 // Test on parameter out of bounds - should return 0,0
602 int UtcDaliSplineGetPoint05(void)
604 TestApplication application;
605 Spline *spline = SetupBezierSpline2();
607 Vector3 pt = spline->GetPoint(0, -32.0f);
608 DALI_TEST_EQUALS(pt.x, 0.0f, TEST_LOCATION);
609 DALI_TEST_EQUALS(pt.y, 0.0f, TEST_LOCATION);
611 pt = spline->GetPoint(0, 23444.0f);
612 DALI_TEST_EQUALS(pt.x, 0.0f, TEST_LOCATION);
613 DALI_TEST_EQUALS(pt.y, 0.0f, TEST_LOCATION);
617 // Test on empty spline - should assert and fail tet case
618 int UtcDaliSplineGetPoint06(void)
620 TestApplication application;
623 Spline *spline = new Spline();
624 spline->GetPoint(0, 23444.0f);
625 tet_result(TET_FAIL);
628 catch (Dali::DaliException& e)
630 DALI_TEST_PRINT_ASSERT( e );
631 DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);