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.
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;
287 TestGestureManager& gestureManager = application.GetGestureManager();
289 // Use pan gesture as GestureDetector cannot be created.
290 GestureDetector detector = PanGestureDetector::New();
292 Actor actor = Actor::New();
293 detector.Attach(actor);
295 // Detach an actor twice - no exception should happen.
298 detector.Detach(actor);
299 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
301 gestureManager.Initialize(); // Reset values
302 detector.Detach(actor);
303 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
305 catch (DaliException& e)
307 DALI_TEST_PRINT_ASSERT( e );
308 tet_result(TET_FAIL);
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;
342 TestGestureManager& gestureManager = application.GetGestureManager();
344 // Use pan gesture as GestureDetector cannot be created.
345 GestureDetector detector = PanGestureDetector::New();
347 const unsigned int actorsToAdd = 5;
348 std::vector<Actor> myActors;
350 for (unsigned int i = 0; i < actorsToAdd; ++i)
352 Actor actor = Actor::New();
353 myActors.push_back(actor);
354 detector.Attach(actor);
357 DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
359 // Detach and retrieve attached actors again, the vector should be empty.
360 detector.DetachAll();
362 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
363 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
365 // Call DetachAll again, there should not be any exception
368 gestureManager.Initialize(); // Reset values
369 detector.DetachAll();
370 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
372 catch (DaliException& e)
374 DALI_TEST_PRINT_ASSERT( e );
375 tet_result(TET_FAIL);
380 int UtcDaliGestureDetectorGetAttachedActors(void)
382 TestApplication application;
384 // Use pan gesture as GestureDetector cannot be created.
385 GestureDetector detector = PanGestureDetector::New();
387 // Initially there should not be any actors.
388 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
391 Actor actor1 = Actor::New();
392 detector.Attach(actor1);
393 DALI_TEST_EQUALS(1u, detector.GetAttachedActorCount(), TEST_LOCATION);
395 // Attach another actor
396 Actor actor2 = Actor::New();
397 detector.Attach(actor2);
398 DALI_TEST_EQUALS(2u, detector.GetAttachedActorCount(), TEST_LOCATION);
400 // Attach another five actors
401 std::vector<Actor> myActors;
402 for (unsigned int i = 0; i < 5; ++i)
404 Actor actor = Actor::New();
405 myActors.push_back(actor);
406 detector.Attach(actor);
408 DALI_TEST_EQUALS(7u, detector.GetAttachedActorCount(), TEST_LOCATION);
411 detector.Detach(actor2);
412 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
414 // Attach actor1 again, count should not increase.
415 detector.Attach(actor1);
416 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
418 // Detach actor2 again, count should not decrease.
419 detector.Detach(actor2);
420 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
423 detector.Detach(actor1);
424 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
426 // Create scoped actor, actor should be automatically removed from the detector when it goes out
429 Actor scopedActor = Actor::New();
430 detector.Attach(scopedActor);
431 DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
433 DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
435 // Detach all so nothing remains.
436 detector.DetachAll();
437 DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
441 int UtcDaliGestureDetectorProperties(void)
443 TestApplication application;
445 // Use pinch gesture as that doen't currently have any properties. Will need to change it if default properties are added.
446 GestureDetector detector = PinchGestureDetector::New();
448 DALI_TEST_EQUALS( detector.GetPropertyCount(), 0u, TEST_LOCATION );
450 Property::IndexContainer indices;
451 detector.GetPropertyIndices( indices );
452 DALI_TEST_EQUALS( indices.Size(), 0u, TEST_LOCATION );
454 DALI_TEST_EQUALS( detector.IsPropertyWritable( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
455 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
456 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), false, TEST_LOCATION );
457 DALI_TEST_EQUALS( detector.GetPropertyType( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ), Property::NONE, TEST_LOCATION );
458 DALI_TEST_EQUALS( detector.GetPropertyIndex( "InvalidIndex" ), Property::INVALID_INDEX, TEST_LOCATION );
460 Property::Value propValue = detector.GetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX );
461 DALI_TEST_EQUALS( propValue.GetType(), Property::NONE, TEST_LOCATION );
463 DALI_TEST_CHECK( detector.GetPropertyName( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ).empty() );
465 // For coverage only, not testable
466 detector.SetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true );