Updated test cases for increased coverage
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-accessibility-adaptor.cpp
1 /*
2  * Copyright (c) 2015 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 <dali/public-api/object/base-object.h>
19 #include <dali/integration-api/events/pan-gesture-event.h>
20 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
21 #include <dali/devel-api/adaptor-framework/accessibility-action-handler.h>
22 #include <dali/devel-api/adaptor-framework/accessibility-gesture-handler.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 /**
34  * Stub for the AccessibilityAdaptor
35  */
36 class AccessibilityAdaptor : public BaseObject
37 {
38 public: // Creation & Destruction
39
40   static Dali::AccessibilityAdaptor Get();
41
42   AccessibilityAdaptor();
43   ~AccessibilityAdaptor();
44
45 public:
46
47   // Functions to modify mock returns:
48
49   void MockSetReadPosition( Vector2& position );
50
51   void SetEnabled(bool enabled)
52   {
53     mIsEnabled = enabled;
54   }
55
56   void SendPanGesture( const Dali::Integration::PanGestureEvent& panEvent );
57
58 public:
59
60   bool IsEnabled() const;
61   void SetActionHandler(Dali::AccessibilityActionHandler& handler);
62   void SetGestureHandler(Dali::AccessibilityGestureHandler& handler);
63
64   Vector2 GetReadPosition() const;
65
66   bool HandleActionNextEvent(bool);
67   bool HandleActionPreviousEvent(bool);
68   bool HandleActionActivateEvent();
69   bool HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain);
70   bool HandleActionReadNextEvent(bool);
71   bool HandleActionReadPreviousEvent(bool);
72   bool HandleActionUpEvent();
73   bool HandleActionDownEvent();
74   bool HandleActionClearFocusEvent();
75   bool HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp);
76   bool HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp);
77   bool HandleActionBackEvent();
78   bool HandleActionEnableEvent();
79   bool HandleActionDisableEvent();
80   bool HandleActionScrollUpEvent();
81   bool HandleActionScrollDownEvent();
82   bool HandleActionPageLeftEvent();
83   bool HandleActionPageRightEvent();
84   bool HandleActionPageUpEvent();
85   bool HandleActionPageDownEvent();
86   bool HandleActionMoveToFirstEvent();
87   bool HandleActionMoveToLastEvent();
88   bool HandleActionReadFromTopEvent();
89   bool HandleActionReadFromNextEvent();
90   bool HandleActionZoomEvent();
91   bool HandleActionReadIndicatorInformationEvent();
92   bool HandleActionReadPauseResumeEvent();
93   bool HandleActionStartStopEvent();
94
95 private:
96
97   bool mIsEnabled;
98   Dali::AccessibilityActionHandler* mActionHandler;
99   Dali::AccessibilityGestureHandler* mGestureHandler;
100   Vector2 mReadPosition;
101
102   static Dali::AccessibilityAdaptor mToolkitAccessibilityAdaptor;
103 };
104
105 Dali::AccessibilityAdaptor AccessibilityAdaptor::mToolkitAccessibilityAdaptor;
106
107
108 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
109 {
110   if( !mToolkitAccessibilityAdaptor )
111   {
112     mToolkitAccessibilityAdaptor = Dali::AccessibilityAdaptor( new Dali::Internal::Adaptor::AccessibilityAdaptor() );
113   }
114   return mToolkitAccessibilityAdaptor;
115 }
116
117 AccessibilityAdaptor::AccessibilityAdaptor()
118 : mIsEnabled(false),
119   mReadPosition( 0.0f, 0.0f )
120 {
121 }
122
123 AccessibilityAdaptor::~AccessibilityAdaptor()
124 {
125 }
126
127 Vector2 AccessibilityAdaptor::GetReadPosition() const
128 {
129   return mReadPosition;
130 }
131
132 void AccessibilityAdaptor::MockSetReadPosition( Vector2& position )
133 {
134   mReadPosition = position;
135 }
136
137 bool AccessibilityAdaptor::IsEnabled() const
138 {
139   return mIsEnabled;
140 }
141
142 void AccessibilityAdaptor::SendPanGesture( const Integration::PanGestureEvent& panEvent )
143 {
144   mGestureHandler->HandlePanGesture( panEvent );
145 }
146
147 void AccessibilityAdaptor::SetActionHandler(Dali::AccessibilityActionHandler& handler)
148 {
149   mActionHandler = &handler;
150 }
151
152 void AccessibilityAdaptor::SetGestureHandler(Dali::AccessibilityGestureHandler& handler)
153 {
154   mGestureHandler = &handler;
155 }
156
157 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
158 {
159   if( mActionHandler )
160   {
161     return mActionHandler->AccessibilityActionNext( true );
162   }
163   return false;
164 }
165
166 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
167 {
168   if( mActionHandler )
169   {
170     return mActionHandler->AccessibilityActionPrevious( true );
171   }
172   return false;
173 }
174
175 bool AccessibilityAdaptor::HandleActionActivateEvent()
176 {
177   if( mActionHandler )
178   {
179     return mActionHandler->AccessibilityActionActivate();
180   }
181   return false;
182 }
183
184 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
185 {
186   if( mActionHandler )
187   {
188     return mActionHandler->AccessibilityActionRead( allowReadAgain );
189   }
190   return false;
191 }
192
193 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
194 {
195   if( mActionHandler )
196   {
197     return mActionHandler->AccessibilityActionReadNext( true );
198   }
199   return false;
200 }
201
202 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
203 {
204   if( mActionHandler )
205   {
206     return mActionHandler->AccessibilityActionReadPrevious( true );
207   }
208   return false;
209 }
210
211 bool AccessibilityAdaptor::HandleActionUpEvent()
212 {
213   if( mActionHandler )
214   {
215     return mActionHandler->AccessibilityActionUp();
216   }
217   return false;
218 }
219
220 bool AccessibilityAdaptor::HandleActionDownEvent()
221 {
222   if( mActionHandler )
223   {
224     return mActionHandler->AccessibilityActionDown();
225   }
226   return false;
227 }
228
229 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
230 {
231   if( mActionHandler )
232   {
233     return mActionHandler->ClearAccessibilityFocus();
234   }
235   return false;
236 }
237
238 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
239 {
240   if( mActionHandler )
241   {
242     Dali::TouchEvent touchEvent;
243     touchEvent.points.push_back( point );
244     return mActionHandler->AccessibilityActionScroll( touchEvent );
245   }
246   return false;
247 }
248
249 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
250 {
251   if( mActionHandler )
252   {
253     Dali::TouchEvent touchEvent;
254     touchEvent.points.push_back( point );
255     return mActionHandler->AccessibilityActionTouch( touchEvent );
256   }
257   return false;
258 }
259
260 bool AccessibilityAdaptor::HandleActionBackEvent()
261 {
262   if( mActionHandler )
263   {
264     return mActionHandler->AccessibilityActionBack();
265   }
266   return false;
267 }
268
269 bool AccessibilityAdaptor::HandleActionEnableEvent()
270 {
271   if( mActionHandler )
272   {
273     return mActionHandler->ChangeAccessibilityStatus();
274   }
275   return false;
276 }
277
278 bool AccessibilityAdaptor::HandleActionDisableEvent()
279 {
280   if( mActionHandler )
281   {
282     return mActionHandler->ChangeAccessibilityStatus();
283   }
284   return false;
285 }
286
287 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
288 {
289   if( mActionHandler )
290   {
291     return mActionHandler->AccessibilityActionScrollUp();
292   }
293   return false;
294 }
295
296 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
297 {
298   if( mActionHandler )
299   {
300     return mActionHandler->AccessibilityActionScrollDown();
301   }
302   return false;
303 }
304
305 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
306 {
307   if( mActionHandler )
308   {
309     return mActionHandler->AccessibilityActionPageLeft();
310   }
311   return false;
312 }
313
314 bool AccessibilityAdaptor::HandleActionPageRightEvent()
315 {
316   if( mActionHandler )
317   {
318     return mActionHandler->AccessibilityActionPageRight();
319   }
320   return false;
321 }
322
323 bool AccessibilityAdaptor::HandleActionPageUpEvent()
324 {
325   if( mActionHandler )
326   {
327     return mActionHandler->AccessibilityActionPageUp();
328   }
329   return false;
330 }
331
332 bool AccessibilityAdaptor::HandleActionPageDownEvent()
333 {
334   if( mActionHandler )
335   {
336     return mActionHandler->AccessibilityActionPageDown();
337   }
338   return false;
339 }
340
341 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
342 {
343   if( mActionHandler )
344   {
345     return mActionHandler->AccessibilityActionMoveToFirst();
346   }
347   return false;
348 }
349
350 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
351 {
352   if( mActionHandler )
353   {
354     return mActionHandler->AccessibilityActionMoveToLast();
355   }
356   return false;
357 }
358
359 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
360 {
361   if( mActionHandler )
362   {
363     return mActionHandler->AccessibilityActionReadFromTop();
364   }
365   return false;
366 }
367
368 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
369 {
370   if( mActionHandler )
371   {
372     return mActionHandler->AccessibilityActionReadFromNext();
373   }
374   return false;
375 }
376
377 bool AccessibilityAdaptor::HandleActionZoomEvent()
378 {
379   if( mActionHandler )
380   {
381     return mActionHandler->AccessibilityActionZoom();
382   }
383   return false;
384 }
385
386 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
387 {
388   if( mActionHandler )
389   {
390     return mActionHandler->AccessibilityActionReadIndicatorInformation();
391   }
392   return false;
393 }
394
395 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
396 {
397   if( mActionHandler )
398   {
399     return mActionHandler->AccessibilityActionReadPauseResume();
400   }
401   return false;
402 }
403
404 bool AccessibilityAdaptor::HandleActionStartStopEvent()
405 {
406   if( mActionHandler )
407   {
408     return mActionHandler->AccessibilityActionStartStop();
409   }
410   return false;
411 }
412
413 static Internal::Adaptor::AccessibilityAdaptor& GetImplementation(Dali::AccessibilityAdaptor& adaptor)
414 {
415   BaseObject& handle = adaptor.GetBaseObject();
416   return static_cast<Internal::Adaptor::AccessibilityAdaptor&>(handle);
417 }
418
419 static const Internal::Adaptor::AccessibilityAdaptor& GetImplementation(const Dali::AccessibilityAdaptor& adaptor)
420 {
421   const BaseObject& handle = adaptor.GetBaseObject();
422   return static_cast<const Internal::Adaptor::AccessibilityAdaptor&>(handle);
423 }
424
425
426 } // namespace Adaptor
427 } // namespace Internal
428
429 ////////////////////////////////////////////////////////////////////////////////////////////////////
430
431 AccessibilityAdaptor::AccessibilityAdaptor()
432 {
433 }
434
435 AccessibilityAdaptor AccessibilityAdaptor::Get()
436 {
437   return Internal::Adaptor::AccessibilityAdaptor::Get();
438 }
439
440 AccessibilityAdaptor::~AccessibilityAdaptor()
441 {
442 }
443
444 // Methods:
445
446 Vector2 AccessibilityAdaptor::GetReadPosition() const
447 {
448   return Internal::Adaptor::GetImplementation(*this).GetReadPosition();
449 }
450
451 bool AccessibilityAdaptor::IsEnabled() const
452 {
453   return Internal::Adaptor::GetImplementation(*this).IsEnabled();
454 }
455
456 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
457 {
458   Internal::Adaptor::GetImplementation(*this).SetActionHandler(handler);
459 }
460
461 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
462 {
463   Internal::Adaptor::GetImplementation(*this).SetGestureHandler(handler);
464 }
465
466 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
467 {
468   return Internal::Adaptor::GetImplementation(*this).HandleActionNextEvent(allowEndFeedback);
469 }
470
471 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
472 {
473   return Internal::Adaptor::GetImplementation(*this).HandleActionPreviousEvent(allowEndFeedback);
474 }
475
476 bool AccessibilityAdaptor::HandleActionActivateEvent()
477 {
478   return Internal::Adaptor::GetImplementation(*this).HandleActionActivateEvent();
479 }
480
481 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
482 {
483   return Internal::Adaptor::GetImplementation(*this).HandleActionReadEvent( x, y, allowReadAgain );
484 }
485
486 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
487 {
488   return Internal::Adaptor::GetImplementation(*this).HandleActionReadNextEvent(allowEndFeedback);
489 }
490
491 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
492 {
493   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPreviousEvent(allowEndFeedback);
494 }
495
496 bool AccessibilityAdaptor::HandleActionUpEvent()
497 {
498   return Internal::Adaptor::GetImplementation(*this).HandleActionUpEvent();
499 }
500
501 bool AccessibilityAdaptor::HandleActionDownEvent()
502 {
503   return Internal::Adaptor::GetImplementation(*this).HandleActionDownEvent();
504 }
505
506 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
507 {
508   return Internal::Adaptor::GetImplementation(*this).HandleActionClearFocusEvent();
509 }
510
511 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
512 {
513   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollEvent(point, timeStamp);
514 }
515
516 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
517 {
518   return Internal::Adaptor::GetImplementation(*this).HandleActionTouchEvent(point, timeStamp);
519 }
520
521 bool AccessibilityAdaptor::HandleActionBackEvent()
522 {
523   return Internal::Adaptor::GetImplementation(*this).HandleActionBackEvent();
524 }
525
526 void AccessibilityAdaptor::HandleActionEnableEvent()
527 {
528   Internal::Adaptor::GetImplementation(*this).HandleActionEnableEvent();
529 }
530
531 void AccessibilityAdaptor::HandleActionDisableEvent()
532 {
533   Internal::Adaptor::GetImplementation(*this).HandleActionDisableEvent();
534 }
535
536 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
537 {
538   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollUpEvent();
539 }
540
541 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
542 {
543   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollDownEvent();
544 }
545
546 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
547 {
548   return Internal::Adaptor::GetImplementation(*this).HandleActionPageLeftEvent();
549 }
550
551 bool AccessibilityAdaptor::HandleActionPageRightEvent()
552 {
553   return Internal::Adaptor::GetImplementation(*this).HandleActionPageRightEvent();
554 }
555
556 bool AccessibilityAdaptor::HandleActionPageUpEvent()
557 {
558   return Internal::Adaptor::GetImplementation(*this).HandleActionPageUpEvent();
559 }
560
561 bool AccessibilityAdaptor::HandleActionPageDownEvent()
562 {
563   return Internal::Adaptor::GetImplementation(*this).HandleActionPageDownEvent();
564 }
565
566 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
567 {
568   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToFirstEvent();
569 }
570
571 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
572 {
573   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToLastEvent();
574 }
575
576 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
577 {
578   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromTopEvent();
579 }
580
581 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
582 {
583   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromNextEvent();
584 }
585
586 bool AccessibilityAdaptor::HandleActionZoomEvent()
587 {
588   return Internal::Adaptor::GetImplementation(*this).HandleActionZoomEvent();
589 }
590
591 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
592 {
593   return Internal::Adaptor::GetImplementation(*this).HandleActionReadIndicatorInformationEvent();
594 }
595
596 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
597 {
598   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPauseResumeEvent();
599 }
600
601 bool AccessibilityAdaptor::HandleActionStartStopEvent()
602 {
603   return Internal::Adaptor::GetImplementation(*this).HandleActionStartStopEvent();
604 }
605
606 AccessibilityAdaptor::AccessibilityAdaptor( Internal::Adaptor::AccessibilityAdaptor* adaptor )
607 : BaseHandle( adaptor )
608 {
609 }
610
611 } // namespace Dali
612
613
614 namespace Test
615 {
616 namespace AccessibilityAdaptor
617 {
618
619 // Mock setup:
620
621 void MockSetReadPosition( Dali::AccessibilityAdaptor adaptor, Dali::Vector2& position )
622 {
623   Dali::Internal::Adaptor::GetImplementation(adaptor).MockSetReadPosition( position );
624 }
625
626 void SetEnabled( Dali::AccessibilityAdaptor adaptor, bool enabled )
627 {
628   Dali::Internal::Adaptor::GetImplementation(adaptor).SetEnabled(enabled);
629 }
630
631 void SendPanGesture( Dali::AccessibilityAdaptor adaptor, const Dali::Integration::PanGestureEvent& panEvent )
632 {
633   Dali::Internal::Adaptor::GetImplementation(adaptor).SendPanGesture( panEvent );
634 }
635
636 } // namespace AccessibilityAdaptor
637 } // namespace Test