2 * Copyright (c) 2017 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/devel-api/object/handle-devel.h>
23 #include <dali-test-suite-utils.h>
26 using namespace Dali::Internal;
30 // Knots fed into Allegro, which generates control points
31 static void SetupPath( Dali::Path& path)
33 path.AddPoint(Vector3( 30.0, 80.0, 0.0));
34 path.AddPoint(Vector3( 70.0, 120.0, 0.0));
35 path.AddPoint(Vector3(100.0, 100.0, 0.0));
37 //Control points for first segment
38 path.AddControlPoint( Vector3( 39.0, 90.0, 0.0) );
39 path.AddControlPoint(Vector3( 56.0, 119.0, 0.0) );
41 //Control points for second segment
42 path.AddControlPoint(Vector3( 78.0, 120.0, 0.0) );
43 path.AddControlPoint(Vector3( 93.0, 104.0, 0.0) );
46 } // anonymous namespace
48 int utcDaliPathGetPoint(void)
50 TestApplication application;
52 Dali::Path path = Dali::Path::New();
53 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
54 path.AddPoint(Vector3(120.0, 70.0, 0.0));
55 path.AddPoint(Vector3(190.0, 250.0, 0.0));
56 path.AddPoint(Vector3(260.0, 260.0, 0.0));
57 path.AddPoint(Vector3(330.0, 220.0, 0.0));
58 path.AddPoint(Vector3(400.0, 50.0, 0.0));
60 DALI_TEST_EQUALS(path.GetPoint(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION);
61 DALI_TEST_EQUALS(path.GetPoint(1), Vector3(120.0, 70.0, 0.0), TEST_LOCATION);
62 DALI_TEST_EQUALS(path.GetPoint(2), Vector3(190.0, 250.0, 0.0), TEST_LOCATION);
63 DALI_TEST_EQUALS(path.GetPoint(3), Vector3(260.0, 260.0, 0.0), TEST_LOCATION);
64 DALI_TEST_EQUALS(path.GetPoint(4), Vector3(330.0, 220.0, 0.0), TEST_LOCATION);
65 DALI_TEST_EQUALS(path.GetPoint(5), Vector3(400.0, 50.0, 0.0), TEST_LOCATION);
69 int utcDaliPathGetPoint02(void)
71 TestApplication application;
73 Dali::Path path = Dali::Path::New();
74 path.AddPoint(Vector3( 50.0, 50.0, 0.0f));
81 catch (Dali::DaliException& e)
83 DALI_TEST_PRINT_ASSERT( e );
84 DALI_TEST_ASSERT(e, "index < mPoint.Size()", TEST_LOCATION);
89 int utcDaliPathGetPoint03(void)
91 TestApplication application;
93 Dali::Path path = Dali::Path::New();
100 catch (Dali::DaliException& e)
102 DALI_TEST_PRINT_ASSERT( e );
103 DALI_TEST_ASSERT(e, "index < mPoint.Size()", TEST_LOCATION);
108 int utcDaliPathGetControlPoints(void)
110 TestApplication application;
112 Dali::Path path = Dali::Path::New();
113 path.AddControlPoint( Vector3(0.0f, 0.0f, 0.0) );
114 path.AddControlPoint( Vector3(108.0f, 57.0f, 0.0) );
116 DALI_TEST_EQUALS(path.GetControlPoint(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION);
117 DALI_TEST_EQUALS(path.GetControlPoint(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION);
121 int utcDaliPathGetControlPoints01(void)
123 TestApplication application;
125 Dali::Path path = Dali::Path::New();
126 path.AddControlPoint(Vector3(0.0f, 0.0f, 0.0) );
127 path.AddControlPoint(Vector3(108.0f, 57.0f, 0.0) );
131 path.GetControlPoint(5);
132 tet_result(TET_FAIL);
134 catch (Dali::DaliException& e)
136 DALI_TEST_PRINT_ASSERT( e );
137 DALI_TEST_ASSERT(e, "index < mControlPoint.Size()", TEST_LOCATION);
142 int utcDaliPathGetControlPoints02(void)
144 TestApplication application;
146 Dali::Path path = Dali::Path::New();
149 path.GetControlPoint(0);
150 tet_result(TET_FAIL);
152 catch (Dali::DaliException& e)
154 DALI_TEST_PRINT_ASSERT( e );
155 DALI_TEST_ASSERT(e, "index < mControlPoint.Size()", TEST_LOCATION);
160 int utcDaliPathGenerateControlPoints01(void)
162 TestApplication application;
164 Dali::Path path = Dali::Path::New();
166 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
167 path.AddPoint(Vector3(120.0, 70.0, 0.0));
168 path.AddPoint(Vector3(190.0, 250.0, 0.0));
169 path.AddPoint(Vector3(260.0, 260.0, 0.0));
170 path.AddPoint(Vector3(330.0, 220.0, 0.0));
171 path.AddPoint(Vector3(400.0, 50.0, 0.0));
173 path.GenerateControlPoints(0.25);
175 DALI_TEST_EQUALS(path.GetControlPoint(0), Vector3( 68.0, 55.0, 0.0), 1.0, TEST_LOCATION);
176 DALI_TEST_EQUALS(path.GetControlPoint(1), Vector3(107.0, 58.0, 0.0), 1.0, TEST_LOCATION);
178 DALI_TEST_EQUALS(path.GetControlPoint(2), Vector3(156.0, 102.0, 0.0), 1.0, TEST_LOCATION);
179 DALI_TEST_EQUALS(path.GetControlPoint(3), Vector3(152.0, 220.0, 0.0), 1.0, TEST_LOCATION);
181 DALI_TEST_EQUALS(path.GetControlPoint(4), Vector3(204.0, 261.0, 0.0), 1.0, TEST_LOCATION);
182 DALI_TEST_EQUALS(path.GetControlPoint(5), Vector3(243.0, 263.0, 0.0), 1.0, TEST_LOCATION);
184 DALI_TEST_EQUALS(path.GetControlPoint(6), Vector3(280.0, 256.0, 0.0), 1.0, TEST_LOCATION);
185 DALI_TEST_EQUALS(path.GetControlPoint(7), Vector3(317.0, 235.0, 0.0), 1.0, TEST_LOCATION);
187 DALI_TEST_EQUALS(path.GetControlPoint(8), Vector3(360.0, 185.0, 0.0), 1.0, TEST_LOCATION);
188 DALI_TEST_EQUALS(path.GetControlPoint(9), Vector3(383.0, 93.0, 0.0), 1.0, TEST_LOCATION);
193 int utcDaliPathGetPointCount(void)
195 TestApplication application;
196 Dali::Path path = Dali::Path::New();
198 DALI_TEST_EQUALS(path.GetPointCount(), 0u, TEST_LOCATION);
200 path.AddPoint(Vector3( 50.0, 50.0, 0.0));
201 path.AddPoint(Vector3(120.0, 70.0, 0.0));
202 path.AddPoint(Vector3(190.0, 250.0, 0.0));
203 path.AddPoint(Vector3(260.0, 260.0, 0.0));
205 DALI_TEST_EQUALS(path.GetPointCount(), 4u, TEST_LOCATION);
207 path.AddPoint(Vector3(330.0, 220.0, 0.0));
208 path.AddPoint(Vector3(400.0, 50.0, 0.0));
210 DALI_TEST_EQUALS(path.GetPointCount(), 6u, TEST_LOCATION);
214 int utcDaliPathGenerateControlPoints02(void)
216 TestApplication application;
218 Dali::Path path = Dali::Path::New();
221 path.GenerateControlPoints(0.25);
222 tet_result(TET_FAIL);
224 catch (Dali::DaliException& e)
226 DALI_TEST_PRINT_ASSERT( e );
227 DALI_TEST_ASSERT(e, "numSegments > 0", TEST_LOCATION);
232 int utcDaliPathGenerateControlPoints03(void)
234 TestApplication application;
236 Dali::Path path = Dali::Path::New();
237 path.AddPoint(Vector3(400.0, 50.0, 0.0f));
240 path.GenerateControlPoints(0.25);
241 tet_result(TET_FAIL);
243 catch (Dali::DaliException& e)
245 DALI_TEST_PRINT_ASSERT( e );
246 DALI_TEST_ASSERT(e, "numSegments > 0", TEST_LOCATION);
251 int UtcDaliPathSample01(void)
253 TestApplication application;
254 Dali::Path path = Dali::Path::New();
258 Vector3 position, tangent;
259 path.Sample(0.0f, position, tangent );
260 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
261 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
262 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
263 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
266 path.Sample(0.25f, position, tangent );
267 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
268 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
269 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
270 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
273 path.Sample(0.5f, position, tangent );
274 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
275 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
276 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
277 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
281 path.Sample(0.75f, position, tangent );
282 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
283 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
284 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
285 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
288 path.Sample(1.0f, position, tangent );
289 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
290 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
291 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
292 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
297 int UtcDaliPathDownCast(void)
299 TestApplication application;
301 Dali::Path path = Dali::Path::New();
302 Handle handle = path;
305 Dali::Path path2 = Dali::Path::DownCast(handle);
306 DALI_TEST_CHECK(path2);
309 Vector3 position, tangent;
310 path2.Sample(0.0f, position, tangent );
311 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
312 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
313 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
314 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
317 path2.Sample(0.25f, position, tangent );
318 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
319 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
320 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
321 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
324 path2.Sample(0.5f, position, tangent );
325 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
326 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
327 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
328 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
332 path2.Sample(0.75f, position, tangent );
333 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
334 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
335 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
336 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
339 path2.Sample(1.0f, position, tangent );
340 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
341 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
342 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
343 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
348 int UtcDaliPathAssignment(void)
350 TestApplication application;
352 Dali::Path path = Dali::Path::New();
357 DALI_TEST_CHECK(path2);
360 Vector3 position, tangent;
361 path2.Sample(0.0f, position, tangent );
362 DALI_TEST_EQUALS(position.x, 30.0f, TEST_LOCATION);
363 DALI_TEST_EQUALS(position.y, 80.0f, TEST_LOCATION);
364 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
365 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
368 path2.Sample(0.25f, position, tangent );
369 DALI_TEST_EQUALS(position.x, 48.0f, 2.0f, TEST_LOCATION);
370 DALI_TEST_EQUALS(position.y, 102.0f, 2.0f, TEST_LOCATION);
371 DALI_TEST_EQUALS(tangent.x, 0.6f, 0.1f, TEST_LOCATION);
372 DALI_TEST_EQUALS(tangent.y, 0.7f, 0.1f, TEST_LOCATION);
375 path2.Sample(0.5f, position, tangent );
376 DALI_TEST_EQUALS(position.x, 70.0f, TEST_LOCATION);
377 DALI_TEST_EQUALS(position.y, 120.0f, TEST_LOCATION);
378 DALI_TEST_EQUALS(tangent.x, 1.0f, 0.1f, TEST_LOCATION);
379 DALI_TEST_EQUALS(tangent.y, 0.0f, 0.1f, TEST_LOCATION);
383 path2.Sample(0.75f, position, tangent );
384 DALI_TEST_EQUALS(position.x, 85.0f, 2.0f, TEST_LOCATION);
385 DALI_TEST_EQUALS(position.y, 112.0f, 2.0f, TEST_LOCATION);
386 DALI_TEST_EQUALS(tangent.x, 0.7f, 0.1f, TEST_LOCATION);
387 DALI_TEST_EQUALS(tangent.y, -0.6f, 0.1f, TEST_LOCATION);
390 path2.Sample(1.0f, position, tangent );
391 DALI_TEST_EQUALS(position.x, 100.0f, TEST_LOCATION);
392 DALI_TEST_EQUALS(position.y, 100.0f, TEST_LOCATION);
393 DALI_TEST_EQUALS(tangent.x, 0.8f, 0.1f, TEST_LOCATION);
394 DALI_TEST_EQUALS(tangent.y, -0.4f, 0.1f, TEST_LOCATION);
399 int UtcDaliPathPropertyPoints(void)
401 TestApplication application;
403 Dali::Path path = Dali::Path::New();
405 Dali::Property::Array points;
406 points.Add( Vector3( 100.0f, 100.0f, 100.0f ) )
407 .Add( Vector3( 200.0f, 200.0f, 200.0f ) )
408 .Add( Vector3( 300.0f, 300.0f, 300.0f ) );
409 path.SetProperty( Dali::Path::Property::POINTS, points );
412 Property::Value value = path.GetProperty( Dali::Path::Property::POINTS );
413 Property::Array* array = value.GetArray();
414 DALI_TEST_CHECK( array );
416 const unsigned int noOfPoints = points.Size();
417 for( unsigned int i = 0; i < noOfPoints; ++i )
419 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
424 Property::Value value = DevelHandle::GetCurrentProperty( path, Dali::Path::Property::POINTS );
425 Property::Array* array = value.GetArray();
426 DALI_TEST_CHECK( array );
428 const unsigned int noOfPoints = points.Size();
429 for( unsigned int i = 0; i < noOfPoints; ++i )
431 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
438 int UtcDaliPathPropertyControlPoints(void)
440 TestApplication application;
442 Dali::Path path = Dali::Path::New();
444 Dali::Property::Array points;
445 points.Add( Vector3( 0.1f, 0.1f, 0.1f ) )
446 .Add( Vector3( 0.2f, 0.2f, 0.2f ) )
447 .Add( Vector3( 0.3f, 0.3f, 0.3f ) );
448 path.SetProperty( Dali::Path::Property::CONTROL_POINTS, points );
451 Property::Value value = path.GetProperty( Dali::Path::Property::CONTROL_POINTS );
452 Property::Array* array = value.GetArray();
453 DALI_TEST_CHECK( array );
455 const unsigned int noOfPoints = points.Size();
456 for( unsigned int i = 0; i < noOfPoints; ++i )
458 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
463 Property::Value value = DevelHandle::GetCurrentProperty( path, Dali::Path::Property::CONTROL_POINTS );
464 Property::Array* array = value.GetArray();
465 DALI_TEST_CHECK( array );
467 const unsigned int noOfPoints = points.Size();
468 for( unsigned int i = 0; i < noOfPoints; ++i )
470 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );