2 * Copyright (c) 2019 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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 void utc_dali_gesture_detector_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_gesture_detector_cleanup(void)
34 test_return_value = TET_PASS;
38 int UtcDaliGestureDetectorConstructorN(void)
40 TestApplication application;
42 GestureDetector detector;
44 Actor actor = Actor::New();
48 detector.Attach(actor);
51 catch (DaliException& e)
53 DALI_TEST_ASSERT( e, "detector", TEST_LOCATION );
58 int UtcDaliGestureDetectorConstructorP(void)
60 TestApplication application;
62 // Use pan gesture as GestureDetector cannot be created.
63 GestureDetector detector = PanGestureDetector::New();
65 Actor actor = Actor::New();
69 detector.Attach(actor);
72 catch (DaliException& e)
74 DALI_TEST_PRINT_ASSERT( e );
80 int UtcDaliGestureDetectorAssignP(void)
82 TestApplication application;
84 // Use pan gesture as GestureDetector cannot be created.
85 GestureDetector detector = PanGestureDetector::New();
86 GestureDetector detector2;
90 Actor actor = Actor::New();
94 detector2.Attach(actor);
97 catch (DaliException& e)
99 DALI_TEST_PRINT_ASSERT( e );
100 tet_result(TET_FAIL);
105 int UtcDaliGestureDetectorDownCastP(void)
107 TestApplication application;
108 tet_infoline("Testing Dali::GestureDetector::DownCast()");
110 GestureDetector detector = PanGestureDetector::New();
112 BaseHandle object(detector);
114 GestureDetector detector2 = GestureDetector::DownCast(object);
115 DALI_TEST_CHECK(detector2);
117 GestureDetector detector3 = DownCast< GestureDetector >(object);
118 DALI_TEST_CHECK(detector3);
120 BaseHandle unInitializedObject;
121 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
122 DALI_TEST_CHECK(!detector4);
124 GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
125 DALI_TEST_CHECK(!detector5);
129 int UtcDaliGestureDetectorAttachP(void)
131 TestApplication application;
133 // Use pan gesture as GestureDetector cannot be created.
134 GestureDetector detector = PanGestureDetector::New();
136 Actor actor = Actor::New();
138 detector.Attach(actor);
141 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
143 if( detector.GetAttachedActor(i) == actor )
145 tet_result(TET_PASS);
152 tet_result(TET_FAIL);
155 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
156 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
157 // this signal. If it does not, then when this function ends, there will be a segmentation fault
158 // thus, a TET case failure.
160 GestureDetector detector2 = PanGestureDetector::New();
161 detector2.Attach(actor);
166 int UtcDaliGestureDetectorAttachN(void)
168 TestApplication application;
170 // Use pan gesture as GestureDetector cannot be created.
171 GestureDetector detector = PanGestureDetector::New();
173 // Do not initialise actor
178 detector.Attach(actor);
179 tet_result(TET_FAIL);
181 catch (DaliException& e)
183 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
188 int UtcDaliGestureDetectorDetachP(void)
190 TestApplication application;
192 // Use pan gesture as GestureDetector cannot be created.
193 GestureDetector detector = PanGestureDetector::New();
195 Actor actor = Actor::New();
196 detector.Attach(actor);
199 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
201 if( detector.GetAttachedActor(i) == actor )
203 tet_result(TET_PASS);
210 tet_result(TET_FAIL);
213 // Detach and retrieve attached actors again, the vector should be empty.
214 detector.Detach(actor);
217 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
219 if( detector.GetAttachedActor(i) == actor )
227 tet_result(TET_FAIL);
231 tet_result(TET_PASS);
237 int UtcDaliGestureDetectorDetachN01(void)
239 TestApplication application;
241 // Use pan gesture as GestureDetector cannot be created.
242 GestureDetector detector = PanGestureDetector::New();
244 // Do not initialise actor
249 detector.Detach(actor);
250 tet_result(TET_FAIL);
252 catch (DaliException& e)
254 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
259 int UtcDaliGestureDetectorDetachN02(void)
261 TestApplication application;
263 // Use pan gesture as GestureDetector cannot be created.
264 GestureDetector detector = PanGestureDetector::New();
266 Actor actor = Actor::New();
267 detector.Attach(actor);
269 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
272 Actor actor2 = Actor::New();
273 detector.Detach(actor2);
274 tet_result(TET_PASS);
276 catch (DaliException& e)
278 DALI_TEST_PRINT_ASSERT( e );
279 tet_result(TET_FAIL);
284 int UtcDaliGestureDetectorDetachN03(void)
286 TestApplication application;
288 // Use pan gesture as GestureDetector cannot be created.
289 GestureDetector detector = PanGestureDetector::New();
291 Actor actor = Actor::New();
292 detector.Attach(actor);
294 DALI_TEST_EQUALS(1, detector.GetAttachedActorCount(), TEST_LOCATION);
296 // Detach an actor twice - no exception should happen.
299 detector.Detach(actor);
300 detector.Detach(actor);
302 catch (DaliException& e)
304 DALI_TEST_PRINT_ASSERT( e );
305 tet_result(TET_FAIL);
308 DALI_TEST_EQUALS(0, detector.GetAttachedActorCount(), TEST_LOCATION);
313 int UtcDaliGestureDetectorDetachAllP(void)
315 TestApplication application;
317 // Use pan gesture as GestureDetector cannot be created.
318 GestureDetector detector = PanGestureDetector::New();
320 const unsigned int actorsToAdd = 5;
321 std::vector<Actor> myActors;
323 for (unsigned int i = 0; i < actorsToAdd; ++i)
325 Actor actor = Actor::New();
326 myActors.push_back(actor);
327 detector.Attach(actor);
330 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
332 // Detach and retrieve attached actors again, the vector should be empty.
333 detector.DetachAll();
335 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
339 int UtcDaliGestureDetectorDetachAllN(void)
341 TestApplication application;
343 // Use pan gesture as GestureDetector cannot be created.
344 GestureDetector detector = PanGestureDetector::New();
346 const unsigned int actorsToAdd = 5;
347 std::vector<Actor> myActors;
349 for (unsigned int i = 0; i < actorsToAdd; ++i)
351 Actor actor = Actor::New();
352 myActors.push_back(actor);
353 detector.Attach(actor);
356 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
358 // Detach and retrieve attached actors again, the vector should be empty.
359 detector.DetachAll();
361 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
363 // Call DetachAll again, there should not be any exception
366 detector.DetachAll();
368 catch (DaliException& e)
370 DALI_TEST_PRINT_ASSERT( e );
371 tet_result(TET_FAIL);
376 int UtcDaliGestureDetectorGetAttachedActors(void)
378 TestApplication application;
380 // Use pan gesture as GestureDetector cannot be created.
381 GestureDetector detector = PanGestureDetector::New();
383 // Initially there should not be any actors.
384 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
387 Actor actor1 = Actor::New();
388 detector.Attach(actor1);
389 DALI_TEST_EQUALS(1u, detector.GetAttachedActorCount(), TEST_LOCATION);
391 // Attach another actor
392 Actor actor2 = Actor::New();
393 detector.Attach(actor2);
394 DALI_TEST_EQUALS(2u, detector.GetAttachedActorCount(), TEST_LOCATION);
396 // Attach another five actors
397 std::vector<Actor> myActors;
398 for (unsigned int i = 0; i < 5; ++i)
400 Actor actor = Actor::New();
401 myActors.push_back(actor);
402 detector.Attach(actor);
404 DALI_TEST_EQUALS(7u, detector.GetAttachedActorCount(), TEST_LOCATION);
407 detector.Detach(actor2);
408 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
410 // Attach actor1 again, count should not increase.
411 detector.Attach(actor1);
412 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
414 // Detach actor2 again, count should not decrease.
415 detector.Detach(actor2);
416 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
419 detector.Detach(actor1);
420 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
422 // Create scoped actor, actor should be automatically removed from the detector when it goes out
425 Actor scopedActor = Actor::New();
426 detector.Attach(scopedActor);
427 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
429 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
431 // Detach all so nothing remains.
432 detector.DetachAll();
433 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
437 int UtcDaliGestureDetectorProperties(void)
439 TestApplication application;
441 // Use pinch gesture as that doen't currently have any properties. Will need to change it if default properties are added.
442 GestureDetector detector = PinchGestureDetector::New();
444 DALI_TEST_EQUALS( detector.GetPropertyCount(), 0u, TEST_LOCATION );
446 Property::IndexContainer indices;
447 detector.GetPropertyIndices( indices );
448 DALI_TEST_EQUALS( indices.Size(), 0u, TEST_LOCATION );
450 DALI_TEST_EQUALS( detector.IsPropertyWritable( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
451 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
452 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
453 DALI_TEST_EQUALS( detector.GetPropertyType( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), Property::NONE, TEST_LOCATION );
454 DALI_TEST_EQUALS( detector.GetPropertyIndex( "InvalidIndex" ), Property::INVALID_INDEX, TEST_LOCATION );
456 Property::Value propValue = detector.GetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX );
457 DALI_TEST_EQUALS( propValue.GetType(), Property::NONE, TEST_LOCATION );
459 DALI_TEST_CHECK( detector.GetPropertyName( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ).empty() );
461 // For coverage only, not testable
462 detector.SetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true );
467 int UtcDaliGestureDetectorRegisterProperty(void)
469 TestApplication application;
471 GestureDetector detector = PinchGestureDetector::New();
473 Property::Index index = detector.RegisterProperty( "sceneProperty", 0 );
474 DALI_TEST_EQUALS( index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
475 DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), 0, TEST_LOCATION );
477 detector.SetProperty( index, -123 );
478 DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), -123, TEST_LOCATION );
480 using Dali::Animation;
481 Animation animation = Animation::New( 1.0f );
482 animation.AnimateTo( Property( detector, index ), 99 );
484 DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), -123, TEST_LOCATION );
485 // Start the animation
488 application.SendNotification();
489 application.Render( 1000 /* 100% progress */);
490 DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), 99, TEST_LOCATION );