Dali 3D User Interface Engine
utc-Dali-PageTurnView.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 #include <stdlib.h>
20 #include <string.h>
21 #include <sstream>
28 
29 
30 
31 using namespace Dali;
32 using namespace Dali::Toolkit;
33 
34 namespace
35 {
36 const int RENDER_FRAME_INTERVAL = 16;
37 const unsigned int TOTAL_PAGE_NUMBER = 20;
38 const Vector2 PAGE_SIZE( 300.f,400.f );
39 const unsigned int IMAGE_WIDTH = 30;
40 const unsigned int IMAGE_HEIGHT = 30;
41 const Vector2 IMAGE_SIZE( static_cast<float>( IMAGE_WIDTH ), static_cast<float>(IMAGE_HEIGHT) );
42 const Vector2 SPINE_SHADOW_PARAMETER( 60.0f, 30.0f );
43 
45 static void TestCallback(BaseHandle handle)
46 {
47  gObjectCreatedCallBackCalled = true;
48 }
49 
50 /*
51  * Simulate time passed by.
52  *
53  * @note this will always process at least 1 frame (1/60 sec)
54  *
55  * @param application Test application instance
56  * @param duration Time to pass in milliseconds.
57  */
58 void Wait(ToolkitTestApplication& application, int duration = 0)
59 {
60  for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
61  {
62  application.SendNotification();
63  application.Render(RENDER_FRAME_INTERVAL);
64  }
65 }
66 
67 // Generate a PanGestureEvent to send to Core
68 Integration::PanGestureEvent GeneratePan(
69  Gesture::State state,
70  const Vector2& previousPosition,
71  const Vector2& currentPosition,
72  unsigned long timeDelta,
73  unsigned int numberOfTouches = 1)
74 {
75  Integration::PanGestureEvent pan(state);
76 
77  pan.previousPosition = previousPosition;
78  pan.currentPosition = currentPosition;
79  pan.timeDelta = timeDelta;
80  pan.numberOfTouches = numberOfTouches;
81 
82  return pan;
83 }
84 
92 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
93 {
94  static Vector2 last;
95 
96  if( (state == Gesture::Started) ||
97  (state == Gesture::Possible) )
98  {
99  last.x = pos.x;
100  last.y = pos.y;
101  }
102 
103  application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
104 
105  last.x = pos.x;
106  last.y = pos.y;
107 }
108 
109 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, bool toStart = true, bool toFinish = true)
110 {
111  // Now do a pan starting from (start) and heading (direction)
112  Vector2 pos(start);
113 
114  if( toStart )
115  {
116  SendPan(application, Gesture::Possible, pos);
117  Wait(application);
118  SendPan(application, Gesture::Started, pos);
119  Wait(application);
120  }
121 
122  for(int i = 0;i<frames;i++)
123  {
124  pos += direction; // Move in this direction
125  SendPan(application, Gesture::Continuing, pos);
126  Wait(application);
127  }
128 
129  if(toFinish)
130  {
131  pos += direction; // Move in this direction
132  SendPan(application, Gesture::Finished, pos);
133  Wait(application);
134  }
135 
136  return pos;
137 }
138 
139 
140 //Functor to test whether PageTurnSignal / PagePanSignal is emitted
142 {
143 public:
144 
145  PageSignalCallback( bool& signalReceived, PageTurnView& view, unsigned int& pageIndex, bool& isForwards )
146  : mSignalVerified( signalReceived ),
147  mView( view ),
148  mPageIndex( pageIndex ),
149  mIsTurningForwards( isForwards )
150  {
151  }
152 
153  // callback to be connected to PageTurnSignal
154  void PageTurnSignalCallback( PageTurnView view, unsigned int pageIndex, bool isTurningForward )
155  {
156  tet_infoline( "Verifying PageTurnedSignal" );
157 
158  if( mView == view && mPageIndex == pageIndex && mIsTurningForwards == isTurningForward )
159  {
160  mSignalVerified = true;
161  }
162  }
163 
164  // callback to be connected to PagePanSignal
165  void PagePanSignalCallback( PageTurnView view )
166  {
167  tet_infoline( "Verifying PagePannedSignal" );
168 
169  if( mView == view )
170  {
171  mSignalVerified = true;
172  }
173  }
174 
175  void Reset()
176  {
177  mSignalVerified = false;
178  }
179 
182  unsigned int& mPageIndex;
184 
185 };
186 
187 
188 //Implementation of PageFactory for providing page actors to PageTurnView
190 {
191 public:
192 
194  : mApplication( application )
195  {
196  mSourceActors.resize(TOTAL_PAGE_NUMBER);
197  mTotalPageNumber = TOTAL_PAGE_NUMBER;
198  }
199 
204  virtual unsigned int GetNumberOfPages()
205  {
206  return mTotalPageNumber;
207  }
208 
214  virtual Actor NewPage( unsigned int pageId )
215  {
216  if(!mSourceActors[pageId])
217  {
218  Actor actor = CreateSolidColorImageActor(mApplication, Color::BLUE,IMAGE_WIDTH,IMAGE_HEIGHT);
219  actor.SetName( static_cast<std::ostringstream*>( &(std::ostringstream() << pageId) )->str() );
220 
223 
224  ImageActor backPageActor = CreateSolidColorImageActor(mApplication, Color::BLUE,IMAGE_WIDTH,IMAGE_HEIGHT);
225  backPageActor.SetParentOrigin( ParentOrigin::CENTER );
226  backPageActor.SetAnchorPoint( AnchorPoint::CENTER );
227  actor.Add( backPageActor );
228 
229  mSourceActors[pageId] = actor;
230  }
231 
232  return mSourceActors[pageId];
233  }
234 
235  void DeletePage( unsigned int pageId )
236  {
237  mSourceActors.erase( mSourceActors.begin() + pageId );
238  mTotalPageNumber--;
239  }
240 
241 private:
243  std::vector<Actor> mSourceActors;
244  unsigned int mTotalPageNumber;
245 };
246 
247 }// namespace
248 
250 {
252 }
253 
255 {
257 }
258 
260 {
261  ToolkitTestApplication application;
262 
263  tet_infoline(" UtcDaliPageTurnViewNew ");
264 
265  // Test default constructor
266  PageTurnView portraitView;
267  DALI_TEST_CHECK( !portraitView );
268 
269  // Test object creation
270  TestPageFactory factory(application);
271  portraitView = PageTurnPortraitView::New( factory, PAGE_SIZE );
272  DALI_TEST_CHECK( portraitView );
273 
274  //Additional check to ensure object is created by checking if it's registered
276  DALI_TEST_CHECK( registry );
277 
279  registry.ObjectCreatedSignal().Connect( &TestCallback );
280  {
281  TestPageFactory factory(application);
282  PageTurnView portraitView = PageTurnPortraitView::New( factory, PAGE_SIZE );
283  }
285 
286  // Test copy constructor
287  PageTurnView viewCopy( portraitView );
288  DALI_TEST_CHECK( viewCopy );
289 
290  // Test down cast
291  Handle handleView;
292  handleView = portraitView;
293  PageTurnView downCastView = PageTurnView::DownCast( handleView );
294  DALI_TEST_CHECK( downCastView );
295 
296  END_TEST;
297 }
298 
300 {
301  ToolkitTestApplication application;
302 
303  tet_infoline(" UtcDaliPageTurnViewNew ");
304 
305  //Test default constructor
306  PageTurnView landscapeView;
307  DALI_TEST_CHECK( !landscapeView );
308 
309  // Test object creation
310  TestPageFactory factory(application);
311  landscapeView = PageTurnLandscapeView::New( factory, PAGE_SIZE );
312  DALI_TEST_CHECK( landscapeView );
313 
314  //Additional check to ensure object is created by checking if it's registered
316  DALI_TEST_CHECK( registry );
317 
319  registry.ObjectCreatedSignal().Connect( &TestCallback );
320  {
321  TestPageFactory factory(application);
322  PageTurnView landscapeView = PageTurnLandscapeView::New( factory, PAGE_SIZE );
323  }
325 
326  // Test copy constructor
327  PageTurnView viewCopy( landscapeView );
328  DALI_TEST_CHECK( viewCopy );
329 
330  // Test down cast
331  Handle handleView;
332  handleView = landscapeView;
333  PageTurnView downCastView = PageTurnView::DownCast( handleView );
334  DALI_TEST_CHECK( downCastView );
335 
336  END_TEST;
337 }
338 
340 {
341  ToolkitTestApplication application;
342 
343  tet_infoline(" UtcDaliPageTurnPortraitViewCopyConstructorAndAssignment ");
344 
345  // Test default constructor
346  PageTurnPortraitView portraitView;
347  DALI_TEST_CHECK( !portraitView );
348 
349  // Test object creation
350  TestPageFactory factory(application);
351  portraitView = PageTurnPortraitView::New( factory, PAGE_SIZE );
352  DALI_TEST_CHECK( portraitView );
353 
354  // Test copy constructor
355  PageTurnPortraitView viewCopy( portraitView );
356  DALI_TEST_CHECK( viewCopy );
357 
358  // Test assignment
359  PageTurnPortraitView portraitView2;
360  portraitView2 = portraitView;
361  DALI_TEST_CHECK( portraitView2 );
362  DALI_TEST_CHECK( portraitView == portraitView2);
363 
364  // Test down cast
365  Handle handleView;
366  handleView = portraitView;
367  PageTurnPortraitView downCastView = PageTurnPortraitView::DownCast( handleView );
368  DALI_TEST_CHECK( downCastView );
369 
370  END_TEST;
371 }
372 
374 {
375  ToolkitTestApplication application;
376 
377  tet_infoline(" UtcDaliPageTurnLandscapeViewCopyConstructorAndAssignment ");
378 
379  // Test default constructor
380  PageTurnLandscapeView landscapeView;
381  DALI_TEST_CHECK( !landscapeView );
382 
383  // Test object creation
384  TestPageFactory factory(application);
385  landscapeView = PageTurnLandscapeView::New( factory, PAGE_SIZE );
386  DALI_TEST_CHECK( landscapeView );
387 
388  // Test copy constructor
389  PageTurnLandscapeView viewCopy( landscapeView );
390  DALI_TEST_CHECK( viewCopy );
391 
392  // Test assignment
393  PageTurnLandscapeView landscapeView2;
394  landscapeView2 = landscapeView;
395  DALI_TEST_CHECK( landscapeView2 );
396  DALI_TEST_CHECK( landscapeView == landscapeView2);
397 
398  // Test down cast
399  Handle handleView;
400  handleView = landscapeView;
401  PageTurnLandscapeView downCastView = PageTurnLandscapeView::DownCast( handleView );
402  DALI_TEST_CHECK( downCastView );
403 
404  END_TEST;
405 }
406 
408 {
409  ToolkitTestApplication application;
410 
411  tet_infoline(" UtcDaliPageTurnViewSetGetProperty ");
412 
413  TestPageFactory factory(application);
414  PageTurnView landscapeView = PageTurnLandscapeView::New( factory, PAGE_SIZE );
415  DALI_TEST_CHECK( landscapeView );
416 
417  Stage::GetCurrent().Add( landscapeView );
418 
419  // Test "pageSize" property
422 
423  Vector2 newSize( PAGE_SIZE.x*0.75, PAGE_SIZE.y*0.5f );
424  landscapeView.SetProperty( PageTurnView::Property::PAGE_SIZE, newSize );
426  Wait( application);
427  DALI_TEST_EQUALS( Vector2(landscapeView.GetTargetSize()), Vector2(newSize.x*2.f, newSize.y), TEST_LOCATION);
428 
429  landscapeView.SetProperty( PageTurnView::Property::PAGE_SIZE,newSize*1.5f);
431  Wait( application);
432  DALI_TEST_EQUALS( Vector2(landscapeView.GetTargetSize()), Vector2(newSize.x*3.f, newSize.y*1.5f), TEST_LOCATION);
433 
434  // Test "currentPageId" property
435  DALI_TEST_CHECK( landscapeView.GetPropertyIndex("currentPageId") == PageTurnView::Property::CURRENT_PAGE_ID );
436  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
437 
438  int pageId = static_cast<int>(TOTAL_PAGE_NUMBER)/3;
439  landscapeView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, pageId );
440  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), pageId, TEST_LOCATION );
441 
442  landscapeView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, pageId*2 );
443  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), pageId*2, TEST_LOCATION );
444 
445  // Test "spinShadow" property
446  DALI_TEST_CHECK( landscapeView.GetPropertyIndex( "spineShadow" ) == PageTurnView::Property::SPINE_SHADOW );
447  landscapeView.SetProperty( PageTurnView::Property::SPINE_SHADOW, SPINE_SHADOW_PARAMETER );
448  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::SPINE_SHADOW).Get<Vector2>(), SPINE_SHADOW_PARAMETER, TEST_LOCATION );
449 
450  landscapeView.SetProperty( PageTurnView::Property::SPINE_SHADOW, SPINE_SHADOW_PARAMETER*0.75f );
451  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::SPINE_SHADOW).Get<Vector2>(), SPINE_SHADOW_PARAMETER*0.75f, TEST_LOCATION );
452 
453  END_TEST;
454 }
455 
457 {
458  ToolkitTestApplication application;
459 
460  tet_infoline(" UtcDaliPageTurnPortraitViewSignals ");
461 
463 
464  TestPageFactory factory(application);
465  Vector2 size = Stage::GetCurrent().GetSize();
466  PageTurnView portraitView = PageTurnPortraitView::New( factory, size );
468  Stage::GetCurrent().Add( portraitView );
469 
470  // Render and notify
471  application.SendNotification();
472  application.Render(RENDER_FRAME_INTERVAL);
473 
474  // [0]: testing PageTurnStartedSignal; [1]: testing PageTurnFinishedSignal
475  // [2]: testing PagePanStartedSignal; [3]: testing PagePanFinishedSignal
476  bool signalVerified[4] = {false, false, false, false};
477  PageTurnView currentView;
478  unsigned int pageIndex;
479  bool isTurningForwards;
480 
481  PageSignalCallback callbackTurnStarted( signalVerified[0], currentView, pageIndex, isTurningForwards );
482  portraitView.PageTurnStartedSignal().Connect( &callbackTurnStarted, &PageSignalCallback::PageTurnSignalCallback );
483 
484  PageSignalCallback callbackTurnFinished( signalVerified[1], currentView, pageIndex, isTurningForwards );
485  portraitView.PageTurnFinishedSignal().Connect( &callbackTurnFinished, &PageSignalCallback::PageTurnSignalCallback );
486 
487  PageSignalCallback callbackPanStarted( signalVerified[2], currentView, pageIndex, isTurningForwards );
488  portraitView.PagePanStartedSignal().Connect( &callbackPanStarted, &PageSignalCallback::PagePanSignalCallback );
489 
490  PageSignalCallback callbackPanFinished( signalVerified[3], currentView, pageIndex, isTurningForwards );
491  portraitView.PagePanFinishedSignal().Connect( &callbackPanFinished, &PageSignalCallback::PagePanSignalCallback );
492 
493  DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
494  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
495  DALI_TEST_CHECK( !callbackPanStarted.mSignalVerified );
496  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
497 
498  currentView = portraitView;
499 
500  //-----Test 1: pan 10 frames from position(size * 0.75f) to position(size * 0.25f), page 0 will be turned forward----
501  pageIndex = 0;
502  isTurningForwards = true;
503  // Do a pan moving up diagonally.
504  Vector2 start = size * 0.75f;
505  Vector2 direction = -size*0.05f; //-size*0.5f/10.f;
506 
507  DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
508  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
509  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
510  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
511  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
512  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
513 
514  PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, false, true);
515  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
516  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
517 
518  Wait(application, 1000);
519  DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
520  // the page is turned over
521  DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)(pageIndex+1), TEST_LOCATION );
522 
523  //---Test 2: pan from position( size*0.5f ) to position( size.width, size.height*0.5f ) to position( size * 0.75f ), page 1 will bent then slid back---
524  callbackTurnStarted.Reset();
525  callbackTurnFinished.Reset();
526  callbackPanStarted.Reset();
527  callbackPanFinished.Reset();
528  portraitView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, 5 );
529  pageIndex = 5;
530  isTurningForwards = true;
531 
532  //pan 10 frames from position( size.width, size.height*0.5f ) to position( size * 0.75f )
533  start = Vector2( size.width, size.height*0.5f );
534  direction = Vector2(-size.width*0.025f, size.height*0.025f);
535  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
536  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
537  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
538  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
539  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
540 
541  signalVerified[0] = false;
542  isTurningForwards = false;
543  PerformGestureDiagonalSwipe( application, start + direction*2 , direction, 5, false, true);
544  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
545  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
546  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified ); // start the sliding back
547 
548  Wait(application, 1000);
549  DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
550  DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)pageIndex, TEST_LOCATION ); // the page is not turned over
551 
552  // ----Test 3: pan 10 frames from position( size*0.25f ) to position( size.width*0.75f, size.height*0.25f ), the previous page will be turned backwards---
553  callbackTurnStarted.Reset();
554  callbackTurnFinished.Reset();
555  callbackPanStarted.Reset();
556  callbackPanFinished.Reset();
557  portraitView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, 10);
558  pageIndex = 9; // will turn the previous page back
559  isTurningForwards = false;
560  start = size*0.25f;
561  direction = Vector2(size.x*0.05f, 0.f);
562  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
563  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
564  DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
565  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
566  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
567 
568  PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, false, true);
569  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
570  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
571  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
572 
573  Wait( application, 1000 );
574 
575  DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
576  DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 9, TEST_LOCATION );
577  END_TEST;
578 }
579 
581 {
582  ToolkitTestApplication application;
583 
584  tet_infoline(" UtcDaliPageTurnLanscapeViewSignals ");
585 
587 
588  /***
589  * -----------------
590  * | |
591  * |---------------|
592  * |bookboo|bookboo|
593  * |kbookbo|kbookbo|
594  * |okbookb|okbookb|
595  * |ookbook|ookbook|
596  * |bookboo|bookboo|
597  * |---------------|
598  * | |
599  * ----------------
600  */
601 
602  TestPageFactory factory(application);
603  Vector2 stageSize = Stage::GetCurrent().GetSize();
604  PageTurnView landscapeView = PageTurnLandscapeView::New( factory, Vector2(stageSize.x*0.5f, stageSize.x*0.8f) );
606  Stage::GetCurrent().Add( landscapeView );
607 
608  // Render and notify
609  application.SendNotification();
610  application.Render(RENDER_FRAME_INTERVAL);
611 
612  // [0]: testing PageTurnStartedSignal; [1]: testing PageTurnFinishedSignal
613  // [2]: testing PagePanStartedSignal; [3]: testing PagePanFinishedSignal
614  bool signalVerified[4] = {false, false, false, false};
615  PageTurnView currentView;
616  unsigned int pageIndex;
617  bool isTurningForwards;
618 
619  PageSignalCallback callbackTurnStarted( signalVerified[0], currentView, pageIndex, isTurningForwards );
620  landscapeView.PageTurnStartedSignal().Connect( &callbackTurnStarted, &PageSignalCallback::PageTurnSignalCallback );
621 
622  PageSignalCallback callbackTurnFinished( signalVerified[1], currentView, pageIndex, isTurningForwards );
623  landscapeView.PageTurnFinishedSignal().Connect( &callbackTurnFinished, &PageSignalCallback::PageTurnSignalCallback );
624 
625  PageSignalCallback callbackPanStarted( signalVerified[2], currentView, pageIndex, isTurningForwards );
626  landscapeView.PagePanStartedSignal().Connect( &callbackPanStarted, &PageSignalCallback::PagePanSignalCallback );
627 
628  PageSignalCallback callbackPanFinished( signalVerified[3], currentView, pageIndex, isTurningForwards );
629  landscapeView.PagePanFinishedSignal().Connect( &callbackPanFinished, &PageSignalCallback::PagePanSignalCallback );
630 
631  DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
632  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
633  DALI_TEST_CHECK( !callbackPanStarted.mSignalVerified );
634  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
635 
636  currentView = landscapeView;
637 
638  //-----Test 1: pan 10 frames from position(stageSize.x * 0.85f, stageSize.y*0.5) to position(stageSize.x * 0.45f, stageSize.y*0.5-stageSize.x * 0.3f), page 0 will be turned forward----
639  pageIndex = 0;
640  isTurningForwards = true;
641  // Do a pan to the left.
642  Vector2 start = Vector2(stageSize.x * 0.85f, stageSize.y*0.5);
643  Vector2 direction = Vector2(-stageSize.x*0.04f, -stageSize.x*0.03f);
644 
645  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
646  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
647  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
648  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
649  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
650  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
651 
652  PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, false, true);
653  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
654  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
655 
656  Wait(application, 1000);
657  DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
658  // the page is turned over
659  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)(pageIndex+1), TEST_LOCATION );
660 
661  //---Test 2: pan from position(stageSize.x * 0.15f, stageSize.y*0.5) to position(stageSize.x * 0.45f, stageSize.y*0.5) page 4 will be turned back---
662  callbackTurnStarted.Reset();
663  callbackTurnFinished.Reset();
664  callbackPanStarted.Reset();
665  callbackPanFinished.Reset();
666  isTurningForwards = false;
667 
668  //pan 10 frames from position( size.width, size.height*0.5f ) to position( size * 0.75f )
669  start = Vector2( stageSize.x * 0.15f, stageSize.y*0.5f );
670  direction = Vector2(stageSize.x * 0.03f, 0.f);
671  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
672  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
673  DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
674  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
675  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
676 
677  PerformGestureDiagonalSwipe( application, start + direction*5.f , direction, 5, false, true);
678  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
679  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
680 
681  Wait(application, 1000);
682  DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
683  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION ); // the first page is turned back
684 
685  // ----Test 3: pan 10 frames from position( size*0.55f ) to position( size.width*0.8f, size.height*0.5f ), no page turn will be started---
686  callbackTurnStarted.Reset();
687  callbackTurnFinished.Reset();
688  callbackPanStarted.Reset();
689  callbackPanFinished.Reset();
690  isTurningForwards = false;
691  start = stageSize*0.55f;
692  direction = Vector2(stageSize.x*0.025f, 0.f);
693  PerformGestureDiagonalSwipe( application, start, direction, 5, true, false);
694  DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
695  DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
696  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
697  DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
698 
699  PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, false, true);
700  DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
701  DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
702  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
703 
704  Wait( application, 1000 );
705 
706  DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
707  DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
708  END_TEST;
709 }
Dali Docs Home
Read more about Dali