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);
140 std::vector<Actor> actors = detector.GetAttachedActors();
142 if (find(actors.begin(), actors.end(), actor) != actors.end())
144 tet_result(TET_PASS);
148 tet_result(TET_FAIL);
151 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
152 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
153 // this signal. If it does not, then when this function ends, there will be a segmentation fault
154 // thus, a TET case failure.
156 GestureDetector detector2 = PanGestureDetector::New();
157 detector2.Attach(actor);
162 int UtcDaliGestureDetectorAttachN(void)
164 TestApplication application;
166 // Use pan gesture as GestureDetector cannot be created.
167 GestureDetector detector = PanGestureDetector::New();
169 // Do not initialise actor
174 detector.Attach(actor);
175 tet_result(TET_FAIL);
177 catch (DaliException& e)
179 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
184 int UtcDaliGestureDetectorDetachP(void)
186 TestApplication application;
188 // Use pan gesture as GestureDetector cannot be created.
189 GestureDetector detector = PanGestureDetector::New();
191 Actor actor = Actor::New();
192 detector.Attach(actor);
193 std::vector<Actor> actors = detector.GetAttachedActors();
195 if (find(actors.begin(), actors.end(), actor) != actors.end())
197 tet_result(TET_PASS);
201 tet_result(TET_FAIL);
204 // Detach and retrieve attached actors again, the vector should be empty.
205 detector.Detach(actor);
207 actors = detector.GetAttachedActors();
210 tet_result(TET_PASS);
214 tet_result(TET_FAIL);
219 int UtcDaliGestureDetectorDetachN01(void)
221 TestApplication application;
223 // Use pan gesture as GestureDetector cannot be created.
224 GestureDetector detector = PanGestureDetector::New();
226 // Do not initialise actor
231 detector.Detach(actor);
232 tet_result(TET_FAIL);
234 catch (DaliException& e)
236 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
241 int UtcDaliGestureDetectorDetachN02(void)
243 TestApplication application;
245 // Use pan gesture as GestureDetector cannot be created.
246 GestureDetector detector = PanGestureDetector::New();
248 Actor actor = Actor::New();
249 detector.Attach(actor);
251 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
254 Actor actor2 = Actor::New();
255 detector.Detach(actor2);
256 tet_result(TET_PASS);
258 catch (DaliException& e)
260 DALI_TEST_PRINT_ASSERT( e );
261 tet_result(TET_FAIL);
266 int UtcDaliGestureDetectorDetachN03(void)
268 TestApplication application;
269 TestGestureManager& gestureManager = application.GetGestureManager();
271 // Use pan gesture as GestureDetector cannot be created.
272 GestureDetector detector = PanGestureDetector::New();
274 Actor actor = Actor::New();
275 detector.Attach(actor);
277 // Detach an actor twice - no exception should happen.
280 detector.Detach(actor);
281 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
283 gestureManager.Initialize(); // Reset values
284 detector.Detach(actor);
285 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
287 catch (DaliException& e)
289 DALI_TEST_PRINT_ASSERT( e );
290 tet_result(TET_FAIL);
295 int UtcDaliGestureDetectorDetachAllP(void)
297 TestApplication application;
299 // Use pan gesture as GestureDetector cannot be created.
300 GestureDetector detector = PanGestureDetector::New();
302 const unsigned int actorsToAdd = 5;
303 std::vector<Actor> myActors;
305 for (unsigned int i = 0; i < actorsToAdd; ++i)
307 Actor actor = Actor::New();
308 myActors.push_back(actor);
309 detector.Attach(actor);
312 std::vector<Actor> attachedActors = detector.GetAttachedActors();
313 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
315 // Detach and retrieve attached actors again, the vector should be empty.
316 detector.DetachAll();
318 attachedActors = detector.GetAttachedActors();
319 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
323 int UtcDaliGestureDetectorDetachAllN(void)
325 TestApplication application;
326 TestGestureManager& gestureManager = application.GetGestureManager();
328 // Use pan gesture as GestureDetector cannot be created.
329 GestureDetector detector = PanGestureDetector::New();
331 const unsigned int actorsToAdd = 5;
332 std::vector<Actor> myActors;
334 for (unsigned int i = 0; i < actorsToAdd; ++i)
336 Actor actor = Actor::New();
337 myActors.push_back(actor);
338 detector.Attach(actor);
341 std::vector<Actor> attachedActors = detector.GetAttachedActors();
342 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
344 // Detach and retrieve attached actors again, the vector should be empty.
345 detector.DetachAll();
347 attachedActors = detector.GetAttachedActors();
348 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
349 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
351 // Call DetachAll again, there should not be any exception
354 gestureManager.Initialize(); // Reset values
355 detector.DetachAll();
356 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
358 catch (DaliException& e)
360 DALI_TEST_PRINT_ASSERT( e );
361 tet_result(TET_FAIL);
366 int UtcDaliGestureDetectorGetAttachedActors(void)
368 TestApplication application;
370 // Use pan gesture as GestureDetector cannot be created.
371 GestureDetector detector = PanGestureDetector::New();
373 // Initially there should not be any actors.
374 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
377 Actor actor1 = Actor::New();
378 detector.Attach(actor1);
379 DALI_TEST_EQUALS(1u, detector.GetAttachedActors().size(), TEST_LOCATION);
381 // Attach another actor
382 Actor actor2 = Actor::New();
383 detector.Attach(actor2);
384 DALI_TEST_EQUALS(2u, detector.GetAttachedActors().size(), TEST_LOCATION);
386 // Attach another five actors
387 std::vector<Actor> myActors;
388 for (unsigned int i = 0; i < 5; ++i)
390 Actor actor = Actor::New();
391 myActors.push_back(actor);
392 detector.Attach(actor);
394 DALI_TEST_EQUALS(7u, detector.GetAttachedActors().size(), TEST_LOCATION);
397 detector.Detach(actor2);
398 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
400 // Attach actor1 again, count should not increase.
401 detector.Attach(actor1);
402 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
404 // Detach actor2 again, count should not decrease.
405 detector.Detach(actor2);
406 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
409 detector.Detach(actor1);
410 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
412 // Create scoped actor, actor should be automatically removed from the detector when it goes out
415 Actor scopedActor = Actor::New();
416 detector.Attach(scopedActor);
417 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
419 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
421 // Detach all so nothing remains.
422 detector.DetachAll();
423 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);