2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/dali.h>
22 #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& exception)
53 if ( exception.mCondition.find("detector") != string::npos )
61 int UtcDaliGestureDetectorConstructorPositive(void)
63 TestApplication application;
65 // Use pan gesture as GestureDetector cannot be created.
66 GestureDetector detector = PanGestureDetector::New();
68 Actor actor = Actor::New();
72 detector.Attach(actor);
75 catch (DaliException& exception)
82 int UtcDaliGestureDetectorDownCast(void)
84 TestApplication application;
85 tet_infoline("Testing Dali::GestureDetector::DownCast()");
87 GestureDetector detector = PanGestureDetector::New();
89 BaseHandle object(detector);
91 GestureDetector detector2 = GestureDetector::DownCast(object);
92 DALI_TEST_CHECK(detector2);
94 GestureDetector detector3 = DownCast< GestureDetector >(object);
95 DALI_TEST_CHECK(detector3);
97 BaseHandle unInitializedObject;
98 GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
99 DALI_TEST_CHECK(!detector4);
101 GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
102 DALI_TEST_CHECK(!detector5);
106 int UtcDaliGestureDetectorAttachPositive(void)
108 TestApplication application;
110 // Use pan gesture as GestureDetector cannot be created.
111 GestureDetector detector = PanGestureDetector::New();
113 Actor actor = Actor::New();
115 detector.Attach(actor);
117 vector<Actor> actors = detector.GetAttachedActors();
119 if (find(actors.begin(), actors.end(), actor) != actors.end())
121 tet_result(TET_PASS);
125 tet_result(TET_FAIL);
128 // Scoped gesture detector. GestureDetectors connect to a destroy signal of the actor. If the
129 // actor is still alive when the gesture detector is destroyed, then it should disconnect from
130 // this signal. If it does not, then when this function ends, there will be a segmentation fault
131 // thus, a TET case failure.
133 GestureDetector detector2 = PanGestureDetector::New();
134 detector2.Attach(actor);
139 int UtcDaliGestureDetectorAttachNegative(void)
141 TestApplication application;
143 // Use pan gesture as GestureDetector cannot be created.
144 GestureDetector detector = PanGestureDetector::New();
146 // Do not initialise actor
151 detector.Attach(actor);
152 tet_result(TET_FAIL);
154 catch (DaliException& exception)
156 if ( exception.mCondition.find("actor") != string::npos )
158 tet_result(TET_PASS);
164 int UtcDaliGestureDetectorDetachPositive(void)
166 TestApplication application;
168 // Use pan gesture as GestureDetector cannot be created.
169 GestureDetector detector = PanGestureDetector::New();
171 Actor actor = Actor::New();
172 detector.Attach(actor);
173 vector<Actor> actors = detector.GetAttachedActors();
175 if (find(actors.begin(), actors.end(), actor) != actors.end())
177 tet_result(TET_PASS);
181 tet_result(TET_FAIL);
184 // Detach and retrive attached actors again, the vector should be empty.
185 detector.Detach(actor);
187 actors = detector.GetAttachedActors();
190 tet_result(TET_PASS);
194 tet_result(TET_FAIL);
199 int UtcDaliGestureDetectorDetachNegative01(void)
201 TestApplication application;
203 // Use pan gesture as GestureDetector cannot be created.
204 GestureDetector detector = PanGestureDetector::New();
206 // Do not initialise actor
211 detector.Detach(actor);
212 tet_result(TET_FAIL);
214 catch (DaliException& exception)
216 if ( exception.mCondition.find("actor") != string::npos )
218 tet_result(TET_PASS);
224 int UtcDaliGestureDetectorDetachNegative02(void)
226 TestApplication application;
228 // Use pan gesture as GestureDetector cannot be created.
229 GestureDetector detector = PanGestureDetector::New();
231 Actor actor = Actor::New();
232 detector.Attach(actor);
234 // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
237 Actor actor2 = Actor::New();
238 detector.Detach(actor2);
239 tet_result(TET_PASS);
241 catch (DaliException& exception)
243 tet_result(TET_FAIL);
248 int UtcDaliGestureDetectorDetachNegative03(void)
250 TestApplication application;
251 TestGestureManager& gestureManager = application.GetGestureManager();
253 // Use pan gesture as GestureDetector cannot be created.
254 GestureDetector detector = PanGestureDetector::New();
256 Actor actor = Actor::New();
257 detector.Attach(actor);
259 // Detach an actor twice - no exception should happen.
262 detector.Detach(actor);
263 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
265 gestureManager.Initialize(); // Reset values
266 detector.Detach(actor);
267 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
269 catch (DaliException& exception)
271 tet_result(TET_FAIL);
276 int UtcDaliGestureDetectorDetachAll(void)
278 TestApplication application;
280 // Use pan gesture as GestureDetector cannot be created.
281 GestureDetector detector = PanGestureDetector::New();
283 const unsigned int actorsToAdd = 5;
284 vector<Actor> myActors;
286 for (unsigned int i = 0; i < actorsToAdd; ++i)
288 Actor actor = Actor::New();
289 myActors.push_back(actor);
290 detector.Attach(actor);
293 vector<Actor> attachedActors = detector.GetAttachedActors();
294 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
296 // Detach and retrieve attached actors again, the vector should be empty.
297 detector.DetachAll();
299 attachedActors = detector.GetAttachedActors();
300 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
304 int UtcDaliGestureDetectorDetachAllNegative(void)
306 TestApplication application;
307 TestGestureManager& gestureManager = application.GetGestureManager();
309 // Use pan gesture as GestureDetector cannot be created.
310 GestureDetector detector = PanGestureDetector::New();
312 const unsigned int actorsToAdd = 5;
313 vector<Actor> myActors;
315 for (unsigned int i = 0; i < actorsToAdd; ++i)
317 Actor actor = Actor::New();
318 myActors.push_back(actor);
319 detector.Attach(actor);
322 vector<Actor> attachedActors = detector.GetAttachedActors();
323 DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
325 // Detach and retrieve attached actors again, the vector should be empty.
326 detector.DetachAll();
328 attachedActors = detector.GetAttachedActors();
329 DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
330 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
332 // Call DetachAll again, there should not be any exception
335 gestureManager.Initialize(); // Reset values
336 detector.DetachAll();
337 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
339 catch (DaliException& exception)
341 tet_result(TET_FAIL);
346 int UtcDaliGestureDetectorGetAttachedActors(void)
348 TestApplication application;
350 // Use pan gesture as GestureDetector cannot be created.
351 GestureDetector detector = PanGestureDetector::New();
353 // Initially there should not be any actors.
354 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
357 Actor actor1 = Actor::New();
358 detector.Attach(actor1);
359 DALI_TEST_EQUALS(1u, detector.GetAttachedActors().size(), TEST_LOCATION);
361 // Attach another actor
362 Actor actor2 = Actor::New();
363 detector.Attach(actor2);
364 DALI_TEST_EQUALS(2u, detector.GetAttachedActors().size(), TEST_LOCATION);
366 // Attach another five actors
367 vector<Actor> myActors;
368 for (unsigned int i = 0; i < 5; ++i)
370 Actor actor = Actor::New();
371 myActors.push_back(actor);
372 detector.Attach(actor);
374 DALI_TEST_EQUALS(7u, detector.GetAttachedActors().size(), TEST_LOCATION);
377 detector.Detach(actor2);
378 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
380 // Attach actor1 again, count should not increase.
381 detector.Attach(actor1);
382 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
384 // Detach actor2 again, count should not decrease.
385 detector.Detach(actor2);
386 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
389 detector.Detach(actor1);
390 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
392 // Create scoped actor, actor should be automatically removed from the detector when it goes out
395 Actor scopedActor = Actor::New();
396 detector.Attach(scopedActor);
397 DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
399 DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
401 // Detach all so nothing remains.
402 detector.DetachAll();
403 DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);