[dali_2.0.15] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-PageTurnView.cpp
1 /*
2  * Copyright (c) 2020 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>
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
25 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h>
26 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h>
27 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-view.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 namespace
33 {
34 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
35 const unsigned int TOTAL_PAGE_NUMBER = 20;
36 const Vector2 VIEW_PAGE_SIZE( 300.f,400.f );
37 const Vector2 SPINE_SHADOW_PARAMETER( 60.0f, 30.0f );
38
39 static bool gObjectCreatedCallBackCalled;
40 static void TestCallback(BaseHandle handle)
41 {
42   gObjectCreatedCallBackCalled = true;
43 }
44
45 /*
46  * Simulate time passed by.
47  *
48  * @note this will always process at least 1 frame (1/60 sec)
49  *
50  * @param application Test application instance
51  * @param duration Time to pass in milliseconds.
52  */
53 int Wait(ToolkitTestApplication& application, int duration = 0)
54 {
55   int time = 0;
56
57   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
58   {
59     application.SendNotification();
60     application.Render(RENDER_FRAME_INTERVAL);
61     time += RENDER_FRAME_INTERVAL;
62   }
63
64   return time;
65 }
66
67
68 static Vector2 PerformGestureDiagonalSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames, uint32_t& time, bool toStart = true, bool toFinish = true)
69 {
70   Vector2 pos( start );
71
72   if( toStart )
73   {
74     // Now do a pan starting from (start + 20) and heading (direction)
75     Vector2 pos_start_jump( start + Vector2(15.0f, 0.0f) );
76     TestStartPan( application, start, pos_start_jump, time );
77     pos += direction;
78   }
79
80   time += Wait(application);
81
82   for(int i = 0;i<frames;i++)
83   {
84     pos += direction;
85     TestMovePan(application, pos, time );
86     time += Wait(application);
87   }
88
89   if(toFinish)
90   {
91     pos += direction;
92     TestEndPan(application, pos, time );
93     time += Wait(application);
94   }
95
96   return pos;
97 }
98
99
100 //Functor to test whether PageTurnSignal / PagePanSignal is emitted
101 class PageSignalCallback : public Dali::ConnectionTracker
102 {
103 public:
104
105   PageSignalCallback( bool& signalReceived, PageTurnView& view, unsigned int& pageIndex, bool& isForwards )
106   : mSignalVerified( signalReceived ),
107     mView( view ),
108     mPageIndex( pageIndex ),
109     mIsTurningForwards( isForwards )
110   {
111   }
112
113   // callback to be connected to PageTurnSignal
114   void PageTurnSignalCallback( PageTurnView view, unsigned int pageIndex, bool isTurningForward )
115   {
116     tet_infoline( "Verifying PageTurnedSignal" );
117
118     if( mView == view && mPageIndex == pageIndex && mIsTurningForwards == isTurningForward )
119     {
120       mSignalVerified = true;
121     }
122   }
123
124   // callback to be connected to PagePanSignal
125   void PagePanSignalCallback( PageTurnView view )
126   {
127     tet_infoline( "Verifying PagePannedSignal" );
128
129     if( mView == view )
130     {
131       mSignalVerified = true;
132     }
133   }
134
135   void Reset()
136   {
137     mSignalVerified = false;
138   }
139
140   bool&         mSignalVerified;
141   PageTurnView& mView;
142   unsigned int& mPageIndex;
143   bool&         mIsTurningForwards;
144
145 };
146
147
148 //Implementation of PageFactory for providing page actors to PageTurnView
149 class TestPageFactory : public PageFactory
150 {
151 public:
152
153   TestPageFactory( bool returnValidTexture = true )
154   : mValidTexture( returnValidTexture )
155   {
156     mTotalPageNumber = TOTAL_PAGE_NUMBER;
157   }
158
159   /**
160    * Query the number of pages available from the factory.
161    * The maximum available page has an ID of GetNumberOfPages()-1.
162    */
163   virtual unsigned int GetNumberOfPages()
164   {
165     return mTotalPageNumber;
166   }
167
168   /**
169    * Create an texture to represent a page content.
170    * @param[in] pageId The ID of the page to create.
171    * @return An image, or an empty handle if the ID is out of range.
172    */
173   virtual Texture NewPage( unsigned int pageId )
174   {
175     if( mValidTexture )
176     {
177       return Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, 100, 100 );
178     }
179     return Texture(); // empty handle
180   }
181
182 private:
183   unsigned int            mTotalPageNumber;
184   bool                    mValidTexture;
185 };
186
187 }// namespace
188
189 void dali_page_turn_view_startup(void)
190 {
191   test_return_value = TET_UNDEF;
192 }
193
194 void dali_page_turn_view_cleanup(void)
195 {
196   test_return_value = TET_PASS;
197 }
198
199 int UtcDaliPageTurnPortraitViewNew(void)
200 {
201   ToolkitTestApplication application;
202
203   tet_infoline(" UtcDaliPageTurnViewNew ");
204
205   // Test default constructor
206   PageTurnView portraitView;
207   DALI_TEST_CHECK( !portraitView );
208
209   // Test object creation
210   TestPageFactory factory;
211   portraitView = PageTurnPortraitView::New( factory, VIEW_PAGE_SIZE );
212   DALI_TEST_CHECK( portraitView );
213
214   //Additional check to ensure object is created by checking if it's registered
215   ObjectRegistry registry = application.GetCore().GetObjectRegistry();
216   DALI_TEST_CHECK( registry );
217
218   gObjectCreatedCallBackCalled = false;
219   registry.ObjectCreatedSignal().Connect( &TestCallback );
220   {
221     TestPageFactory factory;
222     PageTurnView portraitView = PageTurnPortraitView::New( factory, VIEW_PAGE_SIZE );
223   }
224   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
225
226   // Test copy constructor
227   PageTurnView viewCopy( portraitView );
228   DALI_TEST_CHECK( viewCopy );
229
230   // Test down cast
231   Handle handleView;
232   handleView = portraitView;
233   PageTurnView downCastView = PageTurnView::DownCast( handleView );
234   DALI_TEST_CHECK( downCastView );
235
236   END_TEST;
237 }
238
239 int UtcDaliPageTurnLandscapeViewNew(void)
240 {
241   ToolkitTestApplication application;
242
243   tet_infoline(" UtcDaliPageTurnViewNew ");
244
245   //Test default constructor
246   PageTurnView landscapeView;
247   DALI_TEST_CHECK( !landscapeView );
248
249   // Test object creation
250   TestPageFactory factory;
251   landscapeView = PageTurnLandscapeView::New( factory, VIEW_PAGE_SIZE );
252   DALI_TEST_CHECK( landscapeView );
253
254   //Additional check to ensure object is created by checking if it's registered
255   ObjectRegistry registry = application.GetCore().GetObjectRegistry();
256   DALI_TEST_CHECK( registry );
257
258   gObjectCreatedCallBackCalled = false;
259   registry.ObjectCreatedSignal().Connect( &TestCallback );
260   {
261     TestPageFactory factory;
262     PageTurnView landscapeView = PageTurnLandscapeView::New( factory, VIEW_PAGE_SIZE );
263   }
264   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
265
266   // Test copy constructor
267   PageTurnView viewCopy( landscapeView );
268   DALI_TEST_CHECK( viewCopy );
269
270   // Test down cast
271   Handle handleView;
272   handleView = landscapeView;
273   PageTurnView downCastView = PageTurnView::DownCast( handleView );
274   DALI_TEST_CHECK( downCastView );
275
276   END_TEST;
277 }
278
279 int UtcDaliPageTurnPortraitViewCopyConstructorAndAssignment(void)
280 {
281   ToolkitTestApplication application;
282
283   tet_infoline(" UtcDaliPageTurnPortraitViewCopyConstructorAndAssignment ");
284
285   // Test default constructor
286   PageTurnPortraitView portraitView;
287   DALI_TEST_CHECK( !portraitView );
288
289   // Test object creation
290   TestPageFactory factory;
291   portraitView = PageTurnPortraitView::New( factory, VIEW_PAGE_SIZE );
292   DALI_TEST_CHECK( portraitView );
293
294   // Test copy constructor
295   PageTurnPortraitView viewCopy( portraitView );
296   DALI_TEST_CHECK( viewCopy );
297
298   // Test assignment
299   PageTurnPortraitView portraitView2;
300   portraitView2 = portraitView;
301   DALI_TEST_CHECK( portraitView2 );
302   DALI_TEST_CHECK( portraitView == portraitView2);
303
304   // Test down cast
305   Handle handleView;
306   handleView = portraitView;
307   PageTurnPortraitView downCastView = PageTurnPortraitView::DownCast( handleView );
308   DALI_TEST_CHECK( downCastView );
309
310   END_TEST;
311 }
312
313 int UtcDaliPageTurnLandscapeViewCopyConstructorAndAssignment(void)
314 {
315   ToolkitTestApplication application;
316
317   tet_infoline(" UtcDaliPageTurnLandscapeViewCopyConstructorAndAssignment ");
318
319   // Test default constructor
320   PageTurnLandscapeView landscapeView;
321   DALI_TEST_CHECK( !landscapeView );
322
323   // Test object creation
324   TestPageFactory factory;
325   landscapeView = PageTurnLandscapeView::New( factory, VIEW_PAGE_SIZE );
326   DALI_TEST_CHECK( landscapeView );
327
328   // Test copy constructor
329   PageTurnLandscapeView viewCopy( landscapeView );
330   DALI_TEST_CHECK( viewCopy );
331
332   // Test assignment
333   PageTurnLandscapeView landscapeView2;
334   landscapeView2 = landscapeView;
335   DALI_TEST_CHECK( landscapeView2 );
336   DALI_TEST_CHECK( landscapeView == landscapeView2);
337
338   // Test down cast
339   Handle handleView;
340   handleView = landscapeView;
341   PageTurnLandscapeView downCastView = PageTurnLandscapeView::DownCast( handleView );
342   DALI_TEST_CHECK( downCastView );
343
344   END_TEST;
345 }
346
347 int UtcDaliPageTurnViewSetGetProperty(void)
348 {
349   ToolkitTestApplication application;
350
351   tet_infoline(" UtcDaliPageTurnViewSetGetProperty ");
352
353   TestPageFactory factory;
354   PageTurnView landscapeView = PageTurnLandscapeView::New( factory, VIEW_PAGE_SIZE );
355   DALI_TEST_CHECK( landscapeView );
356
357   application.GetScene().Add( landscapeView );
358
359   // Test "viewPageSize" property
360   DALI_TEST_CHECK( landscapeView.GetPropertyIndex("viewPageSize") == PageTurnView::Property::VIEW_PAGE_SIZE  );
361   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::VIEW_PAGE_SIZE).Get<Vector2>(), VIEW_PAGE_SIZE, TEST_LOCATION );
362
363   Vector2 newSize( VIEW_PAGE_SIZE.x*0.75, VIEW_PAGE_SIZE.y*0.5f );
364   landscapeView.SetProperty( PageTurnView::Property::VIEW_PAGE_SIZE, newSize );
365   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::VIEW_PAGE_SIZE).Get<Vector2>(), newSize, TEST_LOCATION );
366   Wait( application);
367   DALI_TEST_EQUALS( Vector2(landscapeView.GetTargetSize()), Vector2(newSize.x*2.f, newSize.y), TEST_LOCATION);
368
369   landscapeView.SetProperty( PageTurnView::Property::VIEW_PAGE_SIZE,newSize*1.5f);
370   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::VIEW_PAGE_SIZE).Get<Vector2>(), newSize*1.5f, TEST_LOCATION );
371   Wait( application);
372   DALI_TEST_EQUALS( Vector2(landscapeView.GetTargetSize()), Vector2(newSize.x*3.f, newSize.y*1.5f), TEST_LOCATION);
373
374   // Test "currentPageId" property
375   DALI_TEST_CHECK( landscapeView.GetPropertyIndex("currentPageId") == PageTurnView::Property::CURRENT_PAGE_ID );
376   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
377
378   int pageId = static_cast<int>(TOTAL_PAGE_NUMBER)/3;
379   landscapeView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, pageId );
380   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), pageId, TEST_LOCATION );
381
382   landscapeView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, pageId*2 );
383   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), pageId*2, TEST_LOCATION );
384
385   // Test "spinShadow" property
386   DALI_TEST_CHECK( landscapeView.GetPropertyIndex( "spineShadow" ) == PageTurnView::Property::SPINE_SHADOW );
387   landscapeView.SetProperty( PageTurnView::Property::SPINE_SHADOW, SPINE_SHADOW_PARAMETER );
388   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::SPINE_SHADOW).Get<Vector2>(), SPINE_SHADOW_PARAMETER, TEST_LOCATION );
389
390   landscapeView.SetProperty( PageTurnView::Property::SPINE_SHADOW,  SPINE_SHADOW_PARAMETER*0.75f );
391   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::SPINE_SHADOW).Get<Vector2>(), SPINE_SHADOW_PARAMETER*0.75f, TEST_LOCATION );
392
393   END_TEST;
394 }
395
396 int UtcDaliPageTurnPortraitViewSignals(void)
397 {
398   ToolkitTestApplication application;
399
400   tet_infoline(" UtcDaliPageTurnPortraitViewSignals ");
401
402   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
403
404   TestPageFactory factory;
405   Vector2 size = application.GetScene().GetSize();
406   PageTurnView portraitView = PageTurnPortraitView::New( factory, size );
407   portraitView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
408   application.GetScene().Add( portraitView );
409
410   // Render and notify
411   application.SendNotification();
412   application.Render(RENDER_FRAME_INTERVAL);
413
414   // [0]: testing PageTurnStartedSignal;  [1]: testing PageTurnFinishedSignal
415   // [2]: testing PagePanStartedSignal;   [3]: testing PagePanFinishedSignal
416   bool signalVerified[4] = {false, false, false, false};
417   PageTurnView currentView;
418   unsigned int pageIndex;
419   bool isTurningForwards;
420
421   PageSignalCallback callbackTurnStarted( signalVerified[0], currentView, pageIndex, isTurningForwards );
422   portraitView.PageTurnStartedSignal().Connect( &callbackTurnStarted, &PageSignalCallback::PageTurnSignalCallback );
423
424   PageSignalCallback callbackTurnFinished( signalVerified[1], currentView, pageIndex, isTurningForwards );
425   portraitView.PageTurnFinishedSignal().Connect( &callbackTurnFinished, &PageSignalCallback::PageTurnSignalCallback );
426
427   PageSignalCallback callbackPanStarted( signalVerified[2], currentView, pageIndex, isTurningForwards );
428   portraitView.PagePanStartedSignal().Connect( &callbackPanStarted, &PageSignalCallback::PagePanSignalCallback );
429
430   PageSignalCallback callbackPanFinished( signalVerified[3], currentView, pageIndex, isTurningForwards );
431   portraitView.PagePanFinishedSignal().Connect( &callbackPanFinished, &PageSignalCallback::PagePanSignalCallback );
432
433   DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
434   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
435   DALI_TEST_CHECK( !callbackPanStarted.mSignalVerified );
436   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
437
438   currentView = portraitView;
439
440   //-----Test 1: pan 10 frames from position(size * 0.75f) to position(size * 0.25f), page 0 will be turned forward----
441   pageIndex = 0;
442   isTurningForwards = true;
443   // Do a pan moving up diagonally
444   uint32_t time = 0;
445   Vector2 start = size * 0.75f;
446   Vector2 direction = -size*0.05f; //-size*0.5f/10.f;
447
448   DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
449   PerformGestureDiagonalSwipe( application, start, direction, 5, time, true, false);
450   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
451   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
452   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
453   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
454
455   PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, time, false, true);
456   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
457   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
458
459   time += Wait(application, 1000);
460   DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
461   // the page is turned over
462   DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)(pageIndex+1), TEST_LOCATION );
463
464   //---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---
465   callbackTurnStarted.Reset();
466   callbackTurnFinished.Reset();
467   callbackPanStarted.Reset();
468   callbackPanFinished.Reset();
469   portraitView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, 5 );
470   pageIndex = 5;
471   isTurningForwards = true;
472
473   //pan 10 frames from position( size.width, size.height*0.5f ) to position( size * 0.75f )
474   start = Vector2( size.width, size.height*0.5f );
475   direction = Vector2(-size.width*0.025f, size.height*0.025f);
476   PerformGestureDiagonalSwipe( application, start, direction, 5, time, true, false);
477   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
478   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
479   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
480   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
481
482   signalVerified[0] = false;
483   isTurningForwards = false;
484   PerformGestureDiagonalSwipe( application, start + direction*2 , direction, 5, time, false, true);
485   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
486   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
487   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified ); // start the sliding back
488
489   time += Wait(application, 1000);
490   DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
491   DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)pageIndex, TEST_LOCATION ); // the page is not turned over
492
493   // ----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---
494   callbackTurnStarted.Reset();
495   callbackTurnFinished.Reset();
496   callbackPanStarted.Reset();
497   callbackPanFinished.Reset();
498   portraitView.SetProperty( PageTurnView::Property::CURRENT_PAGE_ID, 10);
499   pageIndex = 9; // will turn the previous page back
500   isTurningForwards = false;
501   start = size*0.25f;
502   direction = Vector2(size.x*0.05f, 0.f);
503   PerformGestureDiagonalSwipe( application, start, direction, 4, time, true, false);
504   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
505   DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
506   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
507   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
508
509   PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, time, false, true);
510   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
511   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
512   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
513
514   Wait( application, 1000 );
515
516   DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
517   DALI_TEST_EQUALS( portraitView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 9, TEST_LOCATION );
518   END_TEST;
519 }
520
521 int UtcDaliPageTurnLanscapeViewSignals(void)
522 {
523   ToolkitTestApplication application;
524
525   tet_infoline(" UtcDaliPageTurnLanscapeViewSignals ");
526
527   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
528   /***
529    * -----------------
530    * |               |
531    * |---------------|
532    * |bookboo|bookboo|
533    * |kbookbo|kbookbo|
534    * |okbookb|okbookb|
535    * |ookbook|ookbook|
536    * |bookboo|bookboo|
537    * |---------------|
538    * |               |
539    * ----------------
540    */
541
542   TestPageFactory factory;
543   Vector2 stageSize = application.GetScene().GetSize();
544   PageTurnView landscapeView = PageTurnLandscapeView::New( factory, Vector2(stageSize.x*0.5f, stageSize.x*0.8f) );
545   landscapeView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
546   application.GetScene().Add( landscapeView );
547
548   // Render and notify
549   application.SendNotification();
550   application.Render(RENDER_FRAME_INTERVAL);
551
552   // [0]: testing PageTurnStartedSignal;  [1]: testing PageTurnFinishedSignal
553   // [2]: testing PagePanStartedSignal;   [3]: testing PagePanFinishedSignal
554   bool signalVerified[4] = {false, false, false, false};
555   PageTurnView currentView;
556   unsigned int pageIndex;
557   bool isTurningForwards;
558
559   PageSignalCallback callbackTurnStarted( signalVerified[0], currentView, pageIndex, isTurningForwards );
560   landscapeView.PageTurnStartedSignal().Connect( &callbackTurnStarted, &PageSignalCallback::PageTurnSignalCallback );
561
562   PageSignalCallback callbackTurnFinished( signalVerified[1], currentView, pageIndex, isTurningForwards );
563   landscapeView.PageTurnFinishedSignal().Connect( &callbackTurnFinished, &PageSignalCallback::PageTurnSignalCallback );
564
565   PageSignalCallback callbackPanStarted( signalVerified[2], currentView, pageIndex, isTurningForwards );
566   landscapeView.PagePanStartedSignal().Connect( &callbackPanStarted, &PageSignalCallback::PagePanSignalCallback );
567
568   PageSignalCallback callbackPanFinished( signalVerified[3], currentView, pageIndex, isTurningForwards );
569   landscapeView.PagePanFinishedSignal().Connect( &callbackPanFinished, &PageSignalCallback::PagePanSignalCallback );
570
571   DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
572   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
573   DALI_TEST_CHECK( !callbackPanStarted.mSignalVerified );
574   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
575
576   currentView = landscapeView;
577
578   //-----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----
579   pageIndex = 0;
580   isTurningForwards = true;
581   // Do a pan to the left.
582   uint32_t time = 0;
583   Vector2 start = Vector2(stageSize.x * 0.85f, stageSize.y*0.5);
584   Vector2 direction = Vector2(-stageSize.x*0.04f, -stageSize.x*0.03f);
585
586   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
587   PerformGestureDiagonalSwipe( application, start, direction, 5, time, true, false);
588   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
589   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
590   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
591   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
592
593   PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, time, false, true);
594   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
595   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
596
597   time += Wait(application, 1000);
598   DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
599   // the page is turned over
600   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), (int)(pageIndex+1), TEST_LOCATION );
601
602   //---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---
603   callbackTurnStarted.Reset();
604   callbackTurnFinished.Reset();
605   callbackPanStarted.Reset();
606   callbackPanFinished.Reset();
607   isTurningForwards = false;
608
609   //pan 10 frames from position( size.width, size.height*0.5f ) to position( size * 0.75f )
610   start = Vector2( stageSize.x * 0.15f, stageSize.y*0.5f );
611   direction = Vector2(stageSize.x * 0.03f, 0.f);
612   PerformGestureDiagonalSwipe( application, start, direction, 5, time, true, false);
613   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
614   DALI_TEST_CHECK( callbackTurnStarted.mSignalVerified );
615   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
616   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
617
618   PerformGestureDiagonalSwipe( application, start + direction*5.f , direction, 5, time, false, true);
619   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
620   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
621
622   time += Wait(application, 1000);
623   DALI_TEST_CHECK( callbackTurnFinished.mSignalVerified );
624   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION ); // the first page is turned back
625
626   // ----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---
627   callbackTurnStarted.Reset();
628   callbackTurnFinished.Reset();
629   callbackPanStarted.Reset();
630   callbackPanFinished.Reset();
631   isTurningForwards = false;
632   start = stageSize*0.55f;
633   direction = Vector2(stageSize.x*0.025f, 0.f);
634   PerformGestureDiagonalSwipe( application, start, direction, 5, time, true, false);
635   DALI_TEST_CHECK( callbackPanStarted.mSignalVerified );
636   DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
637   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
638   DALI_TEST_CHECK( !callbackPanFinished.mSignalVerified );
639
640   PerformGestureDiagonalSwipe( application, start+direction*5.f, direction, 5, time, false, true);
641   DALI_TEST_CHECK( !callbackTurnStarted.mSignalVerified );
642   DALI_TEST_CHECK( callbackPanFinished.mSignalVerified );
643   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
644
645   Wait( application, 1000 );
646
647   DALI_TEST_CHECK( !callbackTurnFinished.mSignalVerified );
648   DALI_TEST_EQUALS( landscapeView.GetProperty(PageTurnView::Property::CURRENT_PAGE_ID).Get<int>(), 0, TEST_LOCATION );
649   END_TEST;
650 }
651
652 int UtcDaliPageImageFactoryGetExtention(void)
653 {
654   ToolkitTestApplication application;
655   TestPageFactory factory;
656   DALI_TEST_CHECK( factory.GetExtension() == NULL );
657   END_TEST;
658 }
659
660 int UtcDaliPageTurnEmptyTextureHandle(void)
661 {
662   ToolkitTestApplication application;
663
664   tet_infoline(" UtcDaliPageTurnEmptyTextureHandle ");
665
666   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
667
668   TestPageFactory factory( false /* returns empty handles */ );
669   Vector2 size = application.GetScene().GetSize();
670   try
671   {
672     PageTurnView portraitView = PageTurnPortraitView::New( factory, size );
673     portraitView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
674     application.GetScene().Add( portraitView );
675
676     tet_result(TET_FAIL);
677   }
678   catch (DaliException& e)
679   {
680     DALI_TEST_ASSERT(e, "must pass in valid texture", TEST_LOCATION );
681   }
682   catch (...)
683   {
684     tet_result(TET_FAIL);
685   }
686
687   END_TEST;
688 }
689