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>
28 void utc_dali_gesture_detector_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_gesture_detector_cleanup(void)
35 test_return_value = TET_PASS;
39 int UtcDaliGestureDetectorConstructorNegative(void)
41 TestApplication application;
43 GestureDetector detector;
45 Actor actor = Actor::New();
49 detector.Attach(actor);
52 catch (DaliException& exception)
54 if ( exception.mCondition.find("detector") != string::npos )
62 int UtcDaliGestureDetectorConstructorPositive(void)
64 TestApplication application;
66 // Use pan gesture as GestureDetector cannot be created.
67 GestureDetector detector = PanGestureDetector::New();
69 Actor actor = Actor::New();
73 detector.Attach(actor);
76 catch (DaliException& exception)
83 int UtcDaliGestureDetectorDownCast(void)
85 TestApplication application;
86 tet_infoline("Testing Dali::GestureDetector::DownCast()");
88 GestureDetector detector = PanGestureDetector::New();
90 BaseHandle object(detector);
92 GestureDetector detector2 = GestureDetector::DownCast(object);
93 DALI_TEST_CHECK(detector2);
95 GestureDetector detector3 = DownCast< GestureDetector >(object);
96 DALI_TEST_CHECK(detector3);
98 BaseHandle unInitializedObject;
99 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
100 DALI_TEST_CHECK(!detector4);
102 GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
103 DALI_TEST_CHECK(!detector5);
107 int UtcDaliGestureDetectorAttachPositive(void)
109 TestApplication application;
111 // Use pan gesture as GestureDetector cannot be created.
112 GestureDetector detector = PanGestureDetector::New();
114 Actor actor = Actor::New();
116 detector.Attach(actor);
118 vector<Actor> actors = detector.GetAttachedActors();
120 if (find(actors.begin(), actors.end(), actor) != actors.end())
122 tet_result(TET_PASS);
126 tet_result(TET_FAIL);
129 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
130 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
131 // this signal. If it does not, then when this function ends, there will be a segmentation fault
132 // thus, a TET case failure.
134 GestureDetector detector2 = PanGestureDetector::New();
135 detector2.Attach(actor);
140 int UtcDaliGestureDetectorAttachNegative(void)
142 TestApplication application;
144 // Use pan gesture as GestureDetector cannot be created.
145 GestureDetector detector = PanGestureDetector::New();
147 // Do not initialise actor
152 detector.Attach(actor);
153 tet_result(TET_FAIL);
155 catch (DaliException& exception)
157 if ( exception.mCondition.find("actor") != string::npos )
159 tet_result(TET_PASS);
165 int UtcDaliGestureDetectorDetachPositive(void)
167 TestApplication application;
169 // Use pan gesture as GestureDetector cannot be created.
170 GestureDetector detector = PanGestureDetector::New();
172 Actor actor = Actor::New();
173 detector.Attach(actor);
174 vector<Actor> actors = detector.GetAttachedActors();
176 if (find(actors.begin(), actors.end(), actor) != actors.end())
178 tet_result(TET_PASS);
182 tet_result(TET_FAIL);
185 // Detach and retrive attached actors again, the vector should be empty.
186 detector.Detach(actor);
188 actors = detector.GetAttachedActors();
191 tet_result(TET_PASS);
195 tet_result(TET_FAIL);
200 int UtcDaliGestureDetectorDetachNegative01(void)
202 TestApplication application;
204 // Use pan gesture as GestureDetector cannot be created.
205 GestureDetector detector = PanGestureDetector::New();
207 // Do not initialise actor
212 detector.Detach(actor);
213 tet_result(TET_FAIL);
215 catch (DaliException& exception)
217 if ( exception.mCondition.find("actor") != string::npos )
219 tet_result(TET_PASS);
225 int UtcDaliGestureDetectorDetachNegative02(void)
227 TestApplication application;
229 // Use pan gesture as GestureDetector cannot be created.
230 GestureDetector detector = PanGestureDetector::New();
232 Actor actor = Actor::New();
233 detector.Attach(actor);
235 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
238 Actor actor2 = Actor::New();
239 detector.Detach(actor2);
240 tet_result(TET_PASS);
242 catch (DaliException& exception)
244 tet_result(TET_FAIL);
249 int UtcDaliGestureDetectorDetachNegative03(void)
251 TestApplication application;
252 TestGestureManager& gestureManager = application.GetGestureManager();
254 // Use pan gesture as GestureDetector cannot be created.
255 GestureDetector detector = PanGestureDetector::New();
257 Actor actor = Actor::New();
258 detector.Attach(actor);
260 // Detach an actor twice - no exception should happen.
263 detector.Detach(actor);
264 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
266 gestureManager.Initialize(); // Reset values
267 detector.Detach(actor);
268 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
270 catch (DaliException& exception)
272 tet_result(TET_FAIL);
277 int UtcDaliGestureDetectorDetachAll(void)
279 TestApplication application;
281 // Use pan gesture as GestureDetector cannot be created.
282 GestureDetector detector = PanGestureDetector::New();
284 const unsigned int actorsToAdd = 5;
285 vector<Actor> myActors;
287 for (unsigned int i = 0; i < actorsToAdd; ++i)
289 Actor actor = Actor::New();
290 myActors.push_back(actor);
291 detector.Attach(actor);
294 vector<Actor> attachedActors = detector.GetAttachedActors();
295 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
297 // Detach and retrieve attached actors again, the vector should be empty.
298 detector.DetachAll();
300 attachedActors = detector.GetAttachedActors();
301 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
305 int UtcDaliGestureDetectorDetachAllNegative(void)
307 TestApplication application;
308 TestGestureManager& gestureManager = application.GetGestureManager();
310 // Use pan gesture as GestureDetector cannot be created.
311 GestureDetector detector = PanGestureDetector::New();
313 const unsigned int actorsToAdd = 5;
314 vector<Actor> myActors;
316 for (unsigned int i = 0; i < actorsToAdd; ++i)
318 Actor actor = Actor::New();
319 myActors.push_back(actor);
320 detector.Attach(actor);
323 vector<Actor> attachedActors = detector.GetAttachedActors();
324 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
326 // Detach and retrieve attached actors again, the vector should be empty.
327 detector.DetachAll();
329 attachedActors = detector.GetAttachedActors();
330 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
331 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
333 // Call DetachAll again, there should not be any exception
336 gestureManager.Initialize(); // Reset values
337 detector.DetachAll();
338 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
340 catch (DaliException& exception)
342 tet_result(TET_FAIL);
347 int UtcDaliGestureDetectorGetAttachedActors(void)
349 TestApplication application;
351 // Use pan gesture as GestureDetector cannot be created.
352 GestureDetector detector = PanGestureDetector::New();
354 // Initially there should not be any actors.
355 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
358 Actor actor1 = Actor::New();
359 detector.Attach(actor1);
360 DALI_TEST_EQUALS(1u, detector.GetAttachedActors().size(), TEST_LOCATION);
362 // Attach another actor
363 Actor actor2 = Actor::New();
364 detector.Attach(actor2);
365 DALI_TEST_EQUALS(2u, detector.GetAttachedActors().size(), TEST_LOCATION);
367 // Attach another five actors
368 vector<Actor> myActors;
369 for (unsigned int i = 0; i < 5; ++i)
371 Actor actor = Actor::New();
372 myActors.push_back(actor);
373 detector.Attach(actor);
375 DALI_TEST_EQUALS(7u, detector.GetAttachedActors().size(), TEST_LOCATION);
378 detector.Detach(actor2);
379 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
381 // Attach actor1 again, count should not increase.
382 detector.Attach(actor1);
383 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
385 // Detach actor2 again, count should not decrease.
386 detector.Detach(actor2);
387 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
390 detector.Detach(actor1);
391 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
393 // Create scoped actor, actor should be automatically removed from the detector when it goes out
396 Actor scopedActor = Actor::New();
397 detector.Attach(scopedActor);
398 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
400 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
402 // Detach all so nothing remains.
403 detector.DetachAll();
404 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);