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>
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);
79 int UtcDaliGestureDetectorAssignP(void)
81 TestApplication application;
83 // Use pan gesture as GestureDetector cannot be created.
84 GestureDetector detector = PanGestureDetector::New();
85 GestureDetector detector2;
89 Actor actor = Actor::New();
93 detector2.Attach(actor);
96 catch(DaliException& e)
98 DALI_TEST_PRINT_ASSERT(e);
104 int UtcDaliGestureDetectorDownCastP(void)
106 TestApplication application;
107 tet_infoline("Testing Dali::GestureDetector::DownCast()");
109 GestureDetector detector = PanGestureDetector::New();
111 BaseHandle object(detector);
113 GestureDetector detector2 = GestureDetector::DownCast(object);
114 DALI_TEST_CHECK(detector2);
116 GestureDetector detector3 = DownCast<GestureDetector>(object);
117 DALI_TEST_CHECK(detector3);
119 BaseHandle unInitializedObject;
120 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
121 DALI_TEST_CHECK(!detector4);
123 GestureDetector detector5 = DownCast<GestureDetector>(unInitializedObject);
124 DALI_TEST_CHECK(!detector5);
128 int UtcDaliGestureDetectorAttachP(void)
130 TestApplication application;
132 // Use pan gesture as GestureDetector cannot be created.
133 GestureDetector detector = PanGestureDetector::New();
135 Actor actor = Actor::New();
137 detector.Attach(actor);
140 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
142 if(detector.GetAttachedActor(i) == actor)
144 tet_result(TET_PASS);
151 tet_result(TET_FAIL);
154 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
155 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
156 // this signal. If it does not, then when this function ends, there will be a segmentation fault
157 // thus, a TET case failure.
159 GestureDetector detector2 = PanGestureDetector::New();
160 detector2.Attach(actor);
165 int UtcDaliGestureDetectorAttachN(void)
167 TestApplication application;
169 // Use pan gesture as GestureDetector cannot be created.
170 GestureDetector detector = PanGestureDetector::New();
172 // Do not initialise actor
177 detector.Attach(actor);
178 tet_result(TET_FAIL);
180 catch(DaliException& e)
182 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
187 int UtcDaliGestureDetectorDetachP(void)
189 TestApplication application;
191 // Use pan gesture as GestureDetector cannot be created.
192 GestureDetector detector = PanGestureDetector::New();
194 Actor actor = Actor::New();
195 detector.Attach(actor);
198 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
200 if(detector.GetAttachedActor(i) == actor)
202 tet_result(TET_PASS);
209 tet_result(TET_FAIL);
212 // Detach and retrieve attached actors again, the vector should be empty.
213 detector.Detach(actor);
216 for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
218 if(detector.GetAttachedActor(i) == actor)
226 tet_result(TET_FAIL);
230 tet_result(TET_PASS);
236 int UtcDaliGestureDetectorDetachN01(void)
238 TestApplication application;
240 // Use pan gesture as GestureDetector cannot be created.
241 GestureDetector detector = PanGestureDetector::New();
243 // Do not initialise actor
248 detector.Detach(actor);
249 tet_result(TET_FAIL);
251 catch(DaliException& e)
253 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
258 int UtcDaliGestureDetectorDetachN02(void)
260 TestApplication application;
262 // Use pan gesture as GestureDetector cannot be created.
263 GestureDetector detector = PanGestureDetector::New();
265 Actor actor = Actor::New();
266 detector.Attach(actor);
268 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
271 Actor actor2 = Actor::New();
272 detector.Detach(actor2);
273 tet_result(TET_PASS);
275 catch(DaliException& e)
277 DALI_TEST_PRINT_ASSERT(e);
278 tet_result(TET_FAIL);
283 int UtcDaliGestureDetectorDetachN03(void)
285 TestApplication application;
287 // Use pan gesture as GestureDetector cannot be created.
288 GestureDetector detector = PanGestureDetector::New();
290 Actor actor = Actor::New();
291 detector.Attach(actor);
293 DALI_TEST_EQUALS(1, detector.GetAttachedActorCount(), TEST_LOCATION);
295 // Detach an actor twice - no exception should happen.
298 detector.Detach(actor);
299 detector.Detach(actor);
301 catch(DaliException& e)
303 DALI_TEST_PRINT_ASSERT(e);
304 tet_result(TET_FAIL);
307 DALI_TEST_EQUALS(0, detector.GetAttachedActorCount(), TEST_LOCATION);
312 int UtcDaliGestureDetectorDetachAllP(void)
314 TestApplication application;
316 // Use pan gesture as GestureDetector cannot be created.
317 GestureDetector detector = PanGestureDetector::New();
319 const unsigned int actorsToAdd = 5;
320 std::vector<Actor> myActors;
322 for(unsigned int i = 0; i < actorsToAdd; ++i)
324 Actor actor = Actor::New();
325 myActors.push_back(actor);
326 detector.Attach(actor);
329 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
331 // Detach and retrieve attached actors again, the vector should be empty.
332 detector.DetachAll();
334 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
338 int UtcDaliGestureDetectorDetachAllN(void)
340 TestApplication application;
342 // Use pan gesture as GestureDetector cannot be created.
343 GestureDetector detector = PanGestureDetector::New();
345 const unsigned int actorsToAdd = 5;
346 std::vector<Actor> myActors;
348 for(unsigned int i = 0; i < actorsToAdd; ++i)
350 Actor actor = Actor::New();
351 myActors.push_back(actor);
352 detector.Attach(actor);
355 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
357 // Detach and retrieve attached actors again, the vector should be empty.
358 detector.DetachAll();
360 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
362 // Call DetachAll again, there should not be any exception
365 detector.DetachAll();
367 catch(DaliException& e)
369 DALI_TEST_PRINT_ASSERT(e);
370 tet_result(TET_FAIL);
375 int UtcDaliGestureDetectorGetAttachedActors(void)
377 TestApplication application;
379 // Use pan gesture as GestureDetector cannot be created.
380 GestureDetector detector = PanGestureDetector::New();
382 // Initially there should not be any actors.
383 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
386 Actor actor1 = Actor::New();
387 detector.Attach(actor1);
388 DALI_TEST_EQUALS(1u, detector.GetAttachedActorCount(), TEST_LOCATION);
390 // Attach another actor
391 Actor actor2 = Actor::New();
392 detector.Attach(actor2);
393 DALI_TEST_EQUALS(2u, detector.GetAttachedActorCount(), TEST_LOCATION);
395 // Attach another five actors
396 std::vector<Actor> myActors;
397 for(unsigned int i = 0; i < 5; ++i)
399 Actor actor = Actor::New();
400 myActors.push_back(actor);
401 detector.Attach(actor);
403 DALI_TEST_EQUALS(7u, detector.GetAttachedActorCount(), TEST_LOCATION);
406 detector.Detach(actor2);
407 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
409 // Attach actor1 again, count should not increase.
410 detector.Attach(actor1);
411 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
413 // Detach actor2 again, count should not decrease.
414 detector.Detach(actor2);
415 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
418 detector.Detach(actor1);
419 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
421 // Create scoped actor, actor should be automatically removed from the detector when it goes out
424 Actor scopedActor = Actor::New();
425 detector.Attach(scopedActor);
426 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
428 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
430 // Detach all so nothing remains.
431 detector.DetachAll();
432 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
436 int UtcDaliGestureDetectorProperties(void)
438 TestApplication application;
440 // Use pinch gesture as that doen't currently have any properties. Will need to change it if default properties are added.
441 GestureDetector detector = PinchGestureDetector::New();
443 DALI_TEST_EQUALS(detector.GetPropertyCount(), 0u, TEST_LOCATION);
445 Property::IndexContainer indices;
446 detector.GetPropertyIndices(indices);
447 DALI_TEST_EQUALS(indices.Size(), 0u, TEST_LOCATION);
449 DALI_TEST_EQUALS(detector.IsPropertyWritable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
450 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
451 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
452 DALI_TEST_EQUALS(detector.GetPropertyType(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), Property::NONE, TEST_LOCATION);
453 DALI_TEST_EQUALS(detector.GetPropertyIndex("InvalidIndex"), Property::INVALID_INDEX, TEST_LOCATION);
455 Property::Value propValue = detector.GetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX);
456 DALI_TEST_EQUALS(propValue.GetType(), Property::NONE, TEST_LOCATION);
458 DALI_TEST_CHECK(detector.GetPropertyName(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX).empty());
460 // For coverage only, not testable
461 detector.SetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true);
466 int UtcDaliGestureDetectorRegisterProperty(void)
468 TestApplication application;
470 GestureDetector detector = PinchGestureDetector::New();
472 Property::Index index = detector.RegisterProperty("sceneProperty", 0);
473 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
474 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 0, TEST_LOCATION);
476 detector.SetProperty(index, -123);
477 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
479 using Dali::Animation;
480 Animation animation = Animation::New(1.0f);
481 animation.AnimateTo(Property(detector, index), 99);
483 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
484 // Start the animation
487 application.SendNotification();
488 application.Render(1000 /* 100% progress */);
489 DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 99, TEST_LOCATION);