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 UtcDaliGestureDetectorConstructorNegative(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 UtcDaliGestureDetectorConstructorPositive(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 UtcDaliGestureDetectorDownCast(void)
82 TestApplication application;
83 tet_infoline("Testing Dali::GestureDetector::DownCast()");
85 GestureDetector detector = PanGestureDetector::New();
87 BaseHandle object(detector);
89 GestureDetector detector2 = GestureDetector::DownCast(object);
90 DALI_TEST_CHECK(detector2);
92 GestureDetector detector3 = DownCast< GestureDetector >(object);
93 DALI_TEST_CHECK(detector3);
95 BaseHandle unInitializedObject;
96 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
97 DALI_TEST_CHECK(!detector4);
99 GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
100 DALI_TEST_CHECK(!detector5);
104 int UtcDaliGestureDetectorAttachPositive(void)
106 TestApplication application;
108 // Use pan gesture as GestureDetector cannot be created.
109 GestureDetector detector = PanGestureDetector::New();
111 Actor actor = Actor::New();
113 detector.Attach(actor);
115 std::vector<Actor> actors = detector.GetAttachedActors();
117 if (find(actors.begin(), actors.end(), actor) != actors.end())
119 tet_result(TET_PASS);
123 tet_result(TET_FAIL);
126 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
127 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
128 // this signal. If it does not, then when this function ends, there will be a segmentation fault
129 // thus, a TET case failure.
131 GestureDetector detector2 = PanGestureDetector::New();
132 detector2.Attach(actor);
137 int UtcDaliGestureDetectorAttachNegative(void)
139 TestApplication application;
141 // Use pan gesture as GestureDetector cannot be created.
142 GestureDetector detector = PanGestureDetector::New();
144 // Do not initialise actor
149 detector.Attach(actor);
150 tet_result(TET_FAIL);
152 catch (DaliException& e)
154 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
159 int UtcDaliGestureDetectorDetachPositive(void)
161 TestApplication application;
163 // Use pan gesture as GestureDetector cannot be created.
164 GestureDetector detector = PanGestureDetector::New();
166 Actor actor = Actor::New();
167 detector.Attach(actor);
168 std::vector<Actor> actors = detector.GetAttachedActors();
170 if (find(actors.begin(), actors.end(), actor) != actors.end())
172 tet_result(TET_PASS);
176 tet_result(TET_FAIL);
179 // Detach and retrieve attached actors again, the vector should be empty.
180 detector.Detach(actor);
182 actors = detector.GetAttachedActors();
185 tet_result(TET_PASS);
189 tet_result(TET_FAIL);
194 int UtcDaliGestureDetectorDetachNegative01(void)
196 TestApplication application;
198 // Use pan gesture as GestureDetector cannot be created.
199 GestureDetector detector = PanGestureDetector::New();
201 // Do not initialise actor
206 detector.Detach(actor);
207 tet_result(TET_FAIL);
209 catch (DaliException& e)
211 DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
216 int UtcDaliGestureDetectorDetachNegative02(void)
218 TestApplication application;
220 // Use pan gesture as GestureDetector cannot be created.
221 GestureDetector detector = PanGestureDetector::New();
223 Actor actor = Actor::New();
224 detector.Attach(actor);
226 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
229 Actor actor2 = Actor::New();
230 detector.Detach(actor2);
231 tet_result(TET_PASS);
233 catch (DaliException& e)
235 DALI_TEST_PRINT_ASSERT( e );
236 tet_result(TET_FAIL);
241 int UtcDaliGestureDetectorDetachNegative03(void)
243 TestApplication application;
244 TestGestureManager& gestureManager = application.GetGestureManager();
246 // Use pan gesture as GestureDetector cannot be created.
247 GestureDetector detector = PanGestureDetector::New();
249 Actor actor = Actor::New();
250 detector.Attach(actor);
252 // Detach an actor twice - no exception should happen.
255 detector.Detach(actor);
256 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
258 gestureManager.Initialize(); // Reset values
259 detector.Detach(actor);
260 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
262 catch (DaliException& e)
264 DALI_TEST_PRINT_ASSERT( e );
265 tet_result(TET_FAIL);
270 int UtcDaliGestureDetectorDetachAll(void)
272 TestApplication application;
274 // Use pan gesture as GestureDetector cannot be created.
275 GestureDetector detector = PanGestureDetector::New();
277 const unsigned int actorsToAdd = 5;
278 std::vector<Actor> myActors;
280 for (unsigned int i = 0; i < actorsToAdd; ++i)
282 Actor actor = Actor::New();
283 myActors.push_back(actor);
284 detector.Attach(actor);
287 std::vector<Actor> attachedActors = detector.GetAttachedActors();
288 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
290 // Detach and retrieve attached actors again, the vector should be empty.
291 detector.DetachAll();
293 attachedActors = detector.GetAttachedActors();
294 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
298 int UtcDaliGestureDetectorDetachAllNegative(void)
300 TestApplication application;
301 TestGestureManager& gestureManager = application.GetGestureManager();
303 // Use pan gesture as GestureDetector cannot be created.
304 GestureDetector detector = PanGestureDetector::New();
306 const unsigned int actorsToAdd = 5;
307 std::vector<Actor> myActors;
309 for (unsigned int i = 0; i < actorsToAdd; ++i)
311 Actor actor = Actor::New();
312 myActors.push_back(actor);
313 detector.Attach(actor);
316 std::vector<Actor> attachedActors = detector.GetAttachedActors();
317 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
319 // Detach and retrieve attached actors again, the vector should be empty.
320 detector.DetachAll();
322 attachedActors = detector.GetAttachedActors();
323 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
324 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
326 // Call DetachAll again, there should not be any exception
329 gestureManager.Initialize(); // Reset values
330 detector.DetachAll();
331 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
333 catch (DaliException& e)
335 DALI_TEST_PRINT_ASSERT( e );
336 tet_result(TET_FAIL);
341 int UtcDaliGestureDetectorGetAttachedActors(void)
343 TestApplication application;
345 // Use pan gesture as GestureDetector cannot be created.
346 GestureDetector detector = PanGestureDetector::New();
348 // Initially there should not be any actors.
349 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
352 Actor actor1 = Actor::New();
353 detector.Attach(actor1);
354 DALI_TEST_EQUALS(1u, detector.GetAttachedActors().size(), TEST_LOCATION);
356 // Attach another actor
357 Actor actor2 = Actor::New();
358 detector.Attach(actor2);
359 DALI_TEST_EQUALS(2u, detector.GetAttachedActors().size(), TEST_LOCATION);
361 // Attach another five actors
362 std::vector<Actor> myActors;
363 for (unsigned int i = 0; i < 5; ++i)
365 Actor actor = Actor::New();
366 myActors.push_back(actor);
367 detector.Attach(actor);
369 DALI_TEST_EQUALS(7u, detector.GetAttachedActors().size(), TEST_LOCATION);
372 detector.Detach(actor2);
373 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
375 // Attach actor1 again, count should not increase.
376 detector.Attach(actor1);
377 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
379 // Detach actor2 again, count should not decrease.
380 detector.Detach(actor2);
381 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
384 detector.Detach(actor1);
385 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
387 // Create scoped actor, actor should be automatically removed from the detector when it goes out
390 Actor scopedActor = Actor::New();
391 detector.Attach(scopedActor);
392 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
394 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
396 // Detach all so nothing remains.
397 detector.DetachAll();
398 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);