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