2 * Copyright (c) 2022 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>
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;
37 int UtcDaliGestureDetectorConstructorN(void)
39 TestApplication application;
41 GestureDetector detector;
43 Actor actor = Actor::New();
47 detector.Attach(actor);
50 catch(DaliException& e)
52 DALI_TEST_ASSERT(e, "detector", TEST_LOCATION);
57 int UtcDaliGestureDetectorConstructorP(void)
59 TestApplication application;
61 // Use pan gesture as GestureDetector cannot be created.
62 GestureDetector detector = PanGestureDetector::New();
64 Actor actor = Actor::New();
68 detector.Attach(actor);
71 catch(DaliException& e)
73 DALI_TEST_PRINT_ASSERT(e);
77 GestureDetector moved = std::move(detector);
78 DALI_TEST_CHECK(moved);
79 DALI_TEST_CHECK(!detector);
84 int UtcDaliGestureDetectorAssignP(void)
86 TestApplication application;
88 // Use pan gesture as GestureDetector cannot be created.
89 GestureDetector detector = PanGestureDetector::New();
90 GestureDetector detector2;
94 Actor actor = Actor::New();
98 detector2.Attach(actor);
101 catch(DaliException& e)
103 DALI_TEST_PRINT_ASSERT(e);
104 tet_result(TET_FAIL);
107 GestureDetector moved;
108 moved = std::move(detector2);
109 DALI_TEST_CHECK(moved);
110 DALI_TEST_CHECK(detector);
111 DALI_TEST_CHECK(!detector2);
115 int UtcDaliGestureDetectorDownCastP(void)
117 TestApplication application;
118 tet_infoline("Testing Dali::GestureDetector::DownCast()");
120 GestureDetector detector = PanGestureDetector::New();
122 BaseHandle object(detector);
124 GestureDetector detector2 = GestureDetector::DownCast(object);
125 DALI_TEST_CHECK(detector2);
127 GestureDetector detector3 = DownCast<GestureDetector>(object);
128 DALI_TEST_CHECK(detector3);
130 BaseHandle unInitializedObject;
131 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
132 DALI_TEST_CHECK(!detector4);
134 GestureDetector detector5 = DownCast<GestureDetector>(unInitializedObject);
135 DALI_TEST_CHECK(!detector5);
139 int UtcDaliGestureDetectorAttachP(void)
141 TestApplication application;
143 // Use pan gesture as GestureDetector cannot be created.
144 GestureDetector detector = PanGestureDetector::New();
146 Actor actor = Actor::New();
148 detector.Attach(actor);
151 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
153 if(detector.GetAttachedActor(i) == actor)
155 tet_result(TET_PASS);
162 tet_result(TET_FAIL);
165 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
166 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
167 // this signal. If it does not, then when this function ends, there will be a segmentation fault
168 // thus, a TET case failure.
170 GestureDetector detector2 = PanGestureDetector::New();
171 detector2.Attach(actor);
176 int UtcDaliGestureDetectorAttachN(void)
178 TestApplication application;
180 // Use pan gesture as GestureDetector cannot be created.
181 GestureDetector detector = PanGestureDetector::New();
183 // Do not initialise actor
188 detector.Attach(actor);
189 tet_result(TET_FAIL);
191 catch(DaliException& e)
193 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
198 int UtcDaliGestureDetectorDetachP(void)
200 TestApplication application;
202 // Use pan gesture as GestureDetector cannot be created.
203 GestureDetector detector = PanGestureDetector::New();
205 Actor actor = Actor::New();
206 detector.Attach(actor);
209 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
211 if(detector.GetAttachedActor(i) == actor)
213 tet_result(TET_PASS);
220 tet_result(TET_FAIL);
223 // Detach and retrieve attached actors again, the vector should be empty.
224 detector.Detach(actor);
227 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
229 if(detector.GetAttachedActor(i) == actor)
237 tet_result(TET_FAIL);
241 tet_result(TET_PASS);
247 int UtcDaliGestureDetectorDetachN01(void)
249 TestApplication application;
251 // Use pan gesture as GestureDetector cannot be created.
252 GestureDetector detector = PanGestureDetector::New();
254 // Do not initialise actor
259 detector.Detach(actor);
260 tet_result(TET_FAIL);
262 catch(DaliException& e)
264 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
269 int UtcDaliGestureDetectorDetachN02(void)
271 TestApplication application;
273 // Use pan gesture as GestureDetector cannot be created.
274 GestureDetector detector = PanGestureDetector::New();
276 Actor actor = Actor::New();
277 detector.Attach(actor);
279 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
282 Actor actor2 = Actor::New();
283 detector.Detach(actor2);
284 tet_result(TET_PASS);
286 catch(DaliException& e)
288 DALI_TEST_PRINT_ASSERT(e);
289 tet_result(TET_FAIL);
294 int UtcDaliGestureDetectorDetachN03(void)
296 TestApplication application;
298 // Use pan gesture as GestureDetector cannot be created.
299 GestureDetector detector = PanGestureDetector::New();
301 Actor actor = Actor::New();
302 detector.Attach(actor);
304 DALI_TEST_EQUALS(1, detector.GetAttachedActorCount(), TEST_LOCATION);
306 // Detach an actor twice - no exception should happen.
309 detector.Detach(actor);
310 detector.Detach(actor);
312 catch(DaliException& e)
314 DALI_TEST_PRINT_ASSERT(e);
315 tet_result(TET_FAIL);
318 DALI_TEST_EQUALS(0, detector.GetAttachedActorCount(), TEST_LOCATION);
323 int UtcDaliGestureDetectorDetachAllP(void)
325 TestApplication application;
327 // Use pan gesture as GestureDetector cannot be created.
328 GestureDetector detector = PanGestureDetector::New();
330 const unsigned int actorsToAdd = 5;
331 std::vector<Actor> myActors;
333 for(unsigned int i = 0; i < actorsToAdd; ++i)
335 Actor actor = Actor::New();
336 myActors.push_back(actor);
337 detector.Attach(actor);
340 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
342 // Detach and retrieve attached actors again, the vector should be empty.
343 detector.DetachAll();
345 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
349 int UtcDaliGestureDetectorDetachAllN(void)
351 TestApplication application;
353 // Use pan gesture as GestureDetector cannot be created.
354 GestureDetector detector = PanGestureDetector::New();
356 const unsigned int actorsToAdd = 5;
357 std::vector<Actor> myActors;
359 for(unsigned int i = 0; i < actorsToAdd; ++i)
361 Actor actor = Actor::New();
362 myActors.push_back(actor);
363 detector.Attach(actor);
366 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
368 // Detach and retrieve attached actors again, the vector should be empty.
369 detector.DetachAll();
371 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
373 // Call DetachAll again, there should not be any exception
376 detector.DetachAll();
378 catch(DaliException& e)
380 DALI_TEST_PRINT_ASSERT(e);
381 tet_result(TET_FAIL);
386 int UtcDaliGestureDetectorGetAttachedActors(void)
388 TestApplication application;
390 // Use pan gesture as GestureDetector cannot be created.
391 GestureDetector detector = PanGestureDetector::New();
393 // Initially there should not be any actors.
394 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
397 Actor actor1 = Actor::New();
398 detector.Attach(actor1);
399 DALI_TEST_EQUALS(1u, detector.GetAttachedActorCount(), TEST_LOCATION);
401 // Attach another actor
402 Actor actor2 = Actor::New();
403 detector.Attach(actor2);
404 DALI_TEST_EQUALS(2u, detector.GetAttachedActorCount(), TEST_LOCATION);
406 // Attach another five actors
407 std::vector<Actor> myActors;
408 for(unsigned int i = 0; i < 5; ++i)
410 Actor actor = Actor::New();
411 myActors.push_back(actor);
412 detector.Attach(actor);
414 DALI_TEST_EQUALS(7u, detector.GetAttachedActorCount(), TEST_LOCATION);
417 detector.Detach(actor2);
418 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
420 // Attach actor1 again, count should not increase.
421 detector.Attach(actor1);
422 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
424 // Detach actor2 again, count should not decrease.
425 detector.Detach(actor2);
426 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
429 detector.Detach(actor1);
430 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
432 // Create scoped actor, actor should be automatically removed from the detector when it goes out
435 Actor scopedActor = Actor::New();
436 detector.Attach(scopedActor);
437 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
439 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
441 // Detach all so nothing remains.
442 detector.DetachAll();
443 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
447 int UtcDaliGestureDetectorProperties(void)
449 TestApplication application;
451 // Use pinch gesture as that doen't currently have any properties. Will need to change it if default properties are added.
452 GestureDetector detector = PinchGestureDetector::New();
454 DALI_TEST_EQUALS(detector.GetPropertyCount(), 0u, TEST_LOCATION);
456 Property::IndexContainer indices;
457 detector.GetPropertyIndices(indices);
458 DALI_TEST_EQUALS(indices.Size(), 0u, TEST_LOCATION);
460 DALI_TEST_EQUALS(detector.IsPropertyWritable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
461 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
462 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
463 DALI_TEST_EQUALS(detector.GetPropertyType(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), Property::NONE, TEST_LOCATION);
464 DALI_TEST_EQUALS(detector.GetPropertyIndex("InvalidIndex"), Property::INVALID_INDEX, TEST_LOCATION);
466 Property::Value propValue = detector.GetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX);
467 DALI_TEST_EQUALS(propValue.GetType(), Property::NONE, TEST_LOCATION);
469 DALI_TEST_CHECK(detector.GetPropertyName(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX).empty());
471 // For coverage only, not testable
472 detector.SetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true);
477 int UtcDaliGestureDetectorRegisterProperty(void)
479 TestApplication application;
481 GestureDetector detector = PinchGestureDetector::New();
483 Property::Index index = detector.RegisterProperty("sceneProperty", 0);
484 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
485 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 0, TEST_LOCATION);
487 detector.SetProperty(index, -123);
488 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
490 using Dali::Animation;
491 Animation animation = Animation::New(1.0f);
492 animation.AnimateTo(Property(detector, index), 99);
494 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
495 // Start the animation
498 application.SendNotification();
499 application.Render(1000 /* 100% progress */);
500 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 99, TEST_LOCATION);