Dali 3D User Interface Engine
utc-Dali-GestureDetector.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
21 #include <algorithm>
23 #include <dali-test-suite-utils.h>
24 
25 using namespace Dali;
26 
28 {
30 }
31 
33 {
35 }
36 
37 
39 {
40  TestApplication application;
41 
42  GestureDetector detector;
43 
44  Actor actor = Actor::New();
45 
46  try
47  {
48  detector.Attach(actor);
50  }
51  catch (DaliException& e)
52  {
53  DALI_TEST_ASSERT( e, "detector", TEST_LOCATION );
54  }
55  END_TEST;
56 }
57 
59 {
60  TestApplication application;
61 
62  // Use pan gesture as GestureDetector cannot be created.
64 
65  Actor actor = Actor::New();
66 
67  try
68  {
69  detector.Attach(actor);
71  }
72  catch (DaliException& e)
73  {
76  }
77  END_TEST;
78 }
79 
81 {
82  TestApplication application;
83 
84  // Use pan gesture as GestureDetector cannot be created.
86  GestureDetector detector2;
87 
88  detector2 = detector;
89 
90  Actor actor = Actor::New();
91 
92  try
93  {
94  detector2.Attach(actor);
96  }
97  catch (DaliException& e)
98  {
101  }
102  END_TEST;
103 }
104 
106 {
107  TestApplication application;
108  tet_infoline("Testing Dali::GestureDetector::DownCast()");
109 
111 
112  BaseHandle object(detector);
113 
114  GestureDetector detector2 = GestureDetector::DownCast(object);
115  DALI_TEST_CHECK(detector2);
116 
117  GestureDetector detector3 = DownCast< GestureDetector >(object);
118  DALI_TEST_CHECK(detector3);
119 
120  BaseHandle unInitializedObject;
121  GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
122  DALI_TEST_CHECK(!detector4);
123 
124  GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
125  DALI_TEST_CHECK(!detector5);
126  END_TEST;
127 }
128 
130 {
131  TestApplication application;
132 
133  // Use pan gesture as GestureDetector cannot be created.
135 
136  Actor actor = Actor::New();
137 
138  detector.Attach(actor);
139 
140  bool found = false;
141  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
142  {
143  if( detector.GetAttachedActor(i) == actor )
144  {
146  found = true;
147  }
148  }
149 
150  if(!found)
151  {
153  }
154 
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.
159  {
161  detector2.Attach(actor);
162  }
163  END_TEST;
164 }
165 
167 {
168  TestApplication application;
169 
170  // Use pan gesture as GestureDetector cannot be created.
172 
173  // Do not initialise actor
174  Actor actor;
175 
176  try
177  {
178  detector.Attach(actor);
180  }
181  catch (DaliException& e)
182  {
183  DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
184  }
185  END_TEST;
186 }
187 
189 {
190  TestApplication application;
191 
192  // Use pan gesture as GestureDetector cannot be created.
194 
195  Actor actor = Actor::New();
196  detector.Attach(actor);
197 
198  bool found = false;
199  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
200  {
201  if( detector.GetAttachedActor(i) == actor )
202  {
204  found = true;
205  }
206  }
207 
208  if(!found)
209  {
211  }
212 
213  // Detach and retrieve attached actors again, the vector should be empty.
214  detector.Detach(actor);
215 
216  found = false;
217  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
218  {
219  if( detector.GetAttachedActor(i) == actor )
220  {
221  found = true;
222  }
223  }
224 
225  if(found)
226  {
228  }
229  else
230  {
232  }
233 
234  END_TEST;
235 }
236 
238 {
239  TestApplication application;
240 
241  // Use pan gesture as GestureDetector cannot be created.
243 
244  // Do not initialise actor
245  Actor actor;
246 
247  try
248  {
249  detector.Detach(actor);
251  }
252  catch (DaliException& e)
253  {
254  DALI_TEST_ASSERT( e, "actor", TEST_LOCATION );
255  }
256  END_TEST;
257 }
258 
260 {
261  TestApplication application;
262 
263  // Use pan gesture as GestureDetector cannot be created.
265 
266  Actor actor = Actor::New();
267  detector.Attach(actor);
268 
269  // Detach an actor that hasn't been attached. This should not cause an exception, it's a no-op.
270  try
271  {
272  Actor actor2 = Actor::New();
273  detector.Detach(actor2);
275  }
276  catch (DaliException& e)
277  {
280  }
281  END_TEST;
282 }
283 
285 {
286  TestApplication application;
287  TestGestureManager& gestureManager = application.GetGestureManager();
288 
289  // Use pan gesture as GestureDetector cannot be created.
291 
292  Actor actor = Actor::New();
293  detector.Attach(actor);
294 
295  // Detach an actor twice - no exception should happen.
296  try
297  {
298  detector.Detach(actor);
300 
301  gestureManager.Initialize(); // Reset values
302  detector.Detach(actor);
304  }
305  catch (DaliException& e)
306  {
309  }
310  END_TEST;
311 }
312 
314 {
315  TestApplication application;
316 
317  // Use pan gesture as GestureDetector cannot be created.
319 
320  const unsigned int actorsToAdd = 5;
321  std::vector<Actor> myActors;
322 
323  for (unsigned int i = 0; i < actorsToAdd; ++i)
324  {
325  Actor actor = Actor::New();
326  myActors.push_back(actor);
327  detector.Attach(actor);
328  }
329 
330  DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
331 
332  // Detach and retrieve attached actors again, the vector should be empty.
333  detector.DetachAll();
334 
336  END_TEST;
337 }
338 
340 {
341  TestApplication application;
342  TestGestureManager& gestureManager = application.GetGestureManager();
343 
344  // Use pan gesture as GestureDetector cannot be created.
346 
347  const unsigned int actorsToAdd = 5;
348  std::vector<Actor> myActors;
349 
350  for (unsigned int i = 0; i < actorsToAdd; ++i)
351  {
352  Actor actor = Actor::New();
353  myActors.push_back(actor);
354  detector.Attach(actor);
355  }
356 
357  DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
358 
359  // Detach and retrieve attached actors again, the vector should be empty.
360  detector.DetachAll();
361 
364 
365  // Call DetachAll again, there should not be any exception
366  try
367  {
368  gestureManager.Initialize(); // Reset values
369  detector.DetachAll();
371  }
372  catch (DaliException& e)
373  {
376  }
377  END_TEST;
378 }
379 
381 {
382  TestApplication application;
383 
384  // Use pan gesture as GestureDetector cannot be created.
386 
387  // Initially there should not be any actors.
389 
390  // Attach one actor
391  Actor actor1 = Actor::New();
392  detector.Attach(actor1);
394 
395  // Attach another actor
396  Actor actor2 = Actor::New();
397  detector.Attach(actor2);
399 
400  // Attach another five actors
401  std::vector<Actor> myActors;
402  for (unsigned int i = 0; i < 5; ++i)
403  {
404  Actor actor = Actor::New();
405  myActors.push_back(actor);
406  detector.Attach(actor);
407  }
409 
410  // Detach actor2
411  detector.Detach(actor2);
413 
414  // Attach actor1 again, count should not increase.
415  detector.Attach(actor1);
417 
418  // Detach actor2 again, count should not decrease.
419  detector.Detach(actor2);
421 
422  // Detach actor1.
423  detector.Detach(actor1);
425 
426  // Create scoped actor, actor should be automatically removed from the detector when it goes out
427  // of scope.
428  {
429  Actor scopedActor = Actor::New();
430  detector.Attach(scopedActor);
432  }
434 
435  // Detach all so nothing remains.
436  detector.DetachAll();
438  END_TEST;
439 }
Dali Docs Home
Read more about Dali