Stop resetting transform values to default in OnRelayout & OnSizeSet
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ItemView.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 1f96f1b..040fb1c
 // Need to override adaptor classes for toolkit test harness, so include
 // test harness headers before dali headers.
 #include <dali-toolkit-test-suite-utils.h>
-
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/events/pan-gesture-event.h>
+#include <dali-toolkit/devel-api/controls/scrollable/item-view/default-item-layout-property.h>
+#include <dali-toolkit/devel-api/controls/scrollable/item-view/item-view-devel.h>
+
 
 using namespace Dali;
 using namespace Toolkit;
@@ -48,6 +52,7 @@ const int RENDER_FRAME_INTERVAL = 16;                     ///< Duration of each
 
 static bool gObjectCreatedCallBackCalled;
 static bool gOnLayoutActivatedCalled;                     ///< Whether the LayoutActivated signal was invoked.
+static bool gOnScrollUpdateCalled;
 
 static void TestCallback(BaseHandle handle)
 {
@@ -59,6 +64,53 @@ static void OnLayoutActivated()
   gOnLayoutActivatedCalled = true;
 }
 
+static void OnScrollUpdate( const Vector2& position )
+{
+  gOnScrollUpdateCalled = true;
+}
+
+// Generate a PanGestureEvent to send to Core
+Integration::PanGestureEvent GeneratePan(
+    Gesture::State state,
+    const Vector2& previousPosition,
+    const Vector2& currentPosition,
+    unsigned long timeDelta,
+    unsigned int numberOfTouches = 1)
+{
+  Integration::PanGestureEvent pan(state);
+
+  pan.previousPosition = previousPosition;
+  pan.currentPosition = currentPosition;
+  pan.timeDelta = timeDelta;
+  pan.numberOfTouches = numberOfTouches;
+
+  return pan;
+}
+
+/**
+ * Helper to generate PanGestureEvent
+ *
+ * @param[in] application Application instance
+ * @param[in] state The Gesture State
+ * @param[in] pos The current position of touch.
+ */
+static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
+{
+  static Vector2 last;
+
+  if( (state == Gesture::Started) ||
+      (state == Gesture::Possible) )
+  {
+    last.x = pos.x;
+    last.y = pos.y;
+  }
+
+  application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
+
+  last.x = pos.x;
+  last.y = pos.y;
+}
+
 /*
  * Simulate time passed by.
  *
@@ -113,7 +165,7 @@ public: // From ItemFactory
    */
   virtual Actor NewItem(unsigned int itemId)
   {
-    // Create an image actor for this item
+    // Create a renderable actor for this item
     Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
     Actor actor = CreateRenderableActor(image);
 
@@ -301,6 +353,7 @@ int UtcDaliItemViewDeactivateCurrentLayout(void)
 
   // Create a grid layout and add it to ItemView
   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  gridLayout->SetOrientation(ControlOrientation::Down);
   view.AddLayout(*gridLayout);
 
   // Check there is no active layout at the moment
@@ -331,6 +384,7 @@ int UtcDaliItemViewGetItemAndGetItemId(void)
 
   // Create a grid layout and add it to ItemView
   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  gridLayout->SetOrientation(ControlOrientation::Left);
   view.AddLayout(*gridLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
@@ -355,6 +409,7 @@ int UtcDaliItemViewRemoveItem(void)
 
   // Create a grid layout and add it to ItemView
   ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  gridLayout->SetOrientation(ControlOrientation::Right);
   view.AddLayout(*gridLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
@@ -386,9 +441,10 @@ int UtcDaliItemViewGetCurrentLayoutPosition(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a depth layout and add it to ItemView
+  ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
+  depthLayout->SetOrientation(ControlOrientation::Up);
+  view.AddLayout(*depthLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -489,14 +545,14 @@ int UtcDaliItemViewScrollToItem(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
   Vector3 vec(480.0f, 800.0f, 0.0f);
-  ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  ItemLayoutPtr layout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
 
   view.SetName("view actor");
   view.AddLayout(*layout);
   view.SetSize(vec);
 
   Stage::GetCurrent().Add(view);
-  layout->SetOrientation(ControlOrientation::Up);
+  layout->SetOrientation(ControlOrientation::Down);
   view.ActivateLayout(0, vec, 0.0f);
 
   application.SendNotification();
@@ -580,9 +636,10 @@ int UtcDaliItemViewInsertItemP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a depth layout and add it to ItemView
+  ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
+  depthLayout->SetOrientation(ControlOrientation::Left);
+  view.AddLayout(*depthLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -612,9 +669,10 @@ int UtcDaliItemViewInsertItemsP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a depth layout and add it to ItemView
+  ItemLayoutPtr depthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH);
+  depthLayout->SetOrientation(ControlOrientation::Right);
+  view.AddLayout(*depthLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -668,9 +726,9 @@ int UtcDaliItemViewReplaceItemP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a spiral layout and add it to ItemView
+  ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+  view.AddLayout(*spiralLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -692,9 +750,10 @@ int UtcDaliItemViewReplaceItemsP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a spiral layout and add it to ItemView
+  ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+  spiralLayout->SetOrientation( ControlOrientation::Down );
+  view.AddLayout(*spiralLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -729,9 +788,10 @@ int UtcDaliItemViewGetItemsRangeP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a spiral layout and add it to ItemView
+  ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+  spiralLayout->SetOrientation( ControlOrientation::Left );
+  view.AddLayout(*spiralLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -753,9 +813,10 @@ int UtcDaliItemViewSetItemsAnchorPointP(void)
   TestItemFactory factory;
   ItemView view = ItemView::New(factory);
 
-  // Create a grid layout and add it to ItemView
-  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
-  view.AddLayout(*gridLayout);
+  // Create a spiral layout and add it to ItemView
+  ItemLayoutPtr spiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+  spiralLayout->SetOrientation( ControlOrientation::Right );
+  view.AddLayout(*spiralLayout);
 
   // Activate the grid layout so that the items will be created and added to ItemView
   Vector3 stageSize(Dali::Stage::GetCurrent().GetSize());
@@ -879,12 +940,83 @@ int UtcDaliItemViewSetGetProperty(void)
   view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f );
   DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get<float>(), 11.0f, TEST_LOCATION );
 
+  // Test "layout" property
+  DALI_TEST_CHECK( view.GetPropertyIndex("layout") == DevelItemView::Property::LAYOUT  );
+  Property::Map gridLayoutProperty;
+  gridLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::GRID) );
+  gridLayoutProperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(200, 200,50)) );
+  gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_ROW_SPACING, Dali::Property::Value(50.0f) );
+  gridLayoutProperty.Insert( DefaultItemLayoutProperty::GRID_COLUMN_NUMBER, Dali::Property::Value(4) );
+
+  Property::Map depthLayoutProperty;
+  depthLayoutProperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::DEPTH) );
+  depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER, Dali::Property::Value(3) );
+  depthLayoutProperty.Insert( DefaultItemLayoutProperty::DEPTH_ROW_NUMBER, Dali::Property::Value(26.0f) );
+
+  Property::Map spiralLayoutPrperty;
+  spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::SPIRAL) );
+  spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_ITEM_SPACING, Dali::Property::Value((Math::PI*2.0f)/9.5f) );
+  spiralLayoutPrperty.Insert( DefaultItemLayoutProperty::SPIRAL_TOP_ITEM_ALIGNMENT, Dali::Property::Value(-0.125f) );
+
+  Property::Map listLayoutPrperty;
+  listLayoutPrperty.Insert( DefaultItemLayoutProperty::TYPE, Dali::Property::Value((int)DefaultItemLayout::LIST) );
+  listLayoutPrperty.Insert( DefaultItemLayoutProperty::ITEM_SIZE, Dali::Property::Value(Vector3(100, 100,50)) );
+
+
+  Property::Array layoutArray;
+  layoutArray.PushBack(gridLayoutProperty);
+  layoutArray.PushBack(depthLayoutProperty);
+  layoutArray.PushBack(spiralLayoutPrperty);
+  layoutArray.PushBack(listLayoutPrperty);
+
+  view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
+
+  Property::Array getLayoutArray;
+  DALI_TEST_CHECK( view.GetProperty(DevelItemView::Property::LAYOUT ).Get( getLayoutArray ) );
+
+  //Check that the result is the same as
+  DALI_TEST_EQUALS( layoutArray.Count(), getLayoutArray.Count(), TEST_LOCATION );
+  Property::Map firstLayout = *((getLayoutArray.GetElementAt( 0 )).GetMap());
+
+  for( unsigned int mapIdx = 0, mapCount = firstLayout.Count(); mapIdx < mapCount; ++mapIdx )
+  {
+    KeyValuePair propertyPair( firstLayout.GetKeyValue( mapIdx ) );
+    if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
+    {
+      int layoutType = propertyPair.second.Get<int>();
+      DALI_TEST_EQUALS( layoutType, (int)DefaultItemLayout::GRID, TEST_LOCATION );
+    }
+    else if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
+    {
+      Vector3 size = propertyPair.second.Get<Vector3>();
+      DALI_TEST_EQUALS( size, Vector3(200, 200,50), TEST_LOCATION );
+    }
+    else if(propertyPair.first == DefaultItemLayoutProperty::GRID_ROW_SPACING)
+    {
+      float spacing = propertyPair.second.Get<float>();
+      DALI_TEST_EQUALS( spacing, 50.0f, TEST_LOCATION );
+    }
+    else if(propertyPair.first == DefaultItemLayoutProperty::GRID_COLUMN_NUMBER)
+    {
+      int number = propertyPair.second.Get<int>();
+      DALI_TEST_EQUALS(number, 4, TEST_LOCATION );
+    }
+  }
+  view.SetProperty( DevelItemView::Property::LAYOUT, layoutArray);
+
+
   // Test "overshootEnabled" property
   DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED  );
   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), view.IsOvershootEnabled(), TEST_LOCATION );
   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
 
+  // Test "overshootSize" property
+  DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE  );
+  Vector2 overshootSize = Vector2(100.0f,100.0f);
+  view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
+  DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
+
   // Animatable properties
 
   // Test "layoutPosition" property
@@ -926,3 +1058,167 @@ int UtcDaliItemViewSetGetProperty(void)
   END_TEST;
 }
 
+
+int UtcDaliItemViewOvershootVertical(void)
+{
+  ToolkitTestApplication application;
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+
+  // Create the ItemView actor
+  TestItemFactory factory;
+  ItemView view = ItemView::New(factory);
+
+  // Create a grid layout and add it to ItemView
+  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  view.AddLayout(*gridLayout);
+  stage.Add(view);
+
+  // Activate the grid layout so that the items will be created and added to ItemView
+  Vector3 stageSize(stage.GetSize());
+  view.ActivateLayout(0, stageSize, 0.5f);
+
+  view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
+  DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
+
+  view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
+
+  Wait(application);
+
+  // Do a pan starting from 100,100 and moving down
+  Vector2 pos(100.0f, 100.0f);
+  SendPan(application, Gesture::Possible, pos);
+  SendPan(application, Gesture::Started, pos);
+  pos.y += 5.0f;
+  Wait(application, 100);
+
+  for(int i = 0;i<200;i++)
+  {
+    SendPan(application, Gesture::Continuing, pos);
+    pos.y += 5.0f;
+    Wait(application);
+  }
+
+  SendPan(application, Gesture::Finished, pos);
+  Wait(application, 100);
+
+  // Do a pan starting from 100,100 and moving up
+  pos = Vector2(100.0f, 300.0f);
+  SendPan(application, Gesture::Possible, pos);
+  SendPan(application, Gesture::Started, pos);
+  pos.y -= 5.0f;
+  Wait(application, 100);
+
+  for(int i = 0;i<200;i++)
+  {
+    SendPan(application, Gesture::Continuing, pos);
+    pos.y -= 5.0f;
+    Wait(application);
+  }
+
+  SendPan(application, Gesture::Finished, pos);
+  Wait(application, 100);
+  END_TEST;
+}
+
+int UtcDaliItemViewOvershootHorizontal(void)
+{
+  ToolkitTestApplication application;
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+
+  // Create the ItemView actor
+  TestItemFactory factory;
+  ItemView view = ItemView::New(factory);
+
+  // Create a grid layout and add it to ItemView
+  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+  view.AddLayout(*gridLayout);
+  stage.Add(view);
+
+  // Activate the grid layout so that the items will be created and added to ItemView
+  Vector3 stageSize(stage.GetSize());
+  view.ActivateLayout(0, stageSize, 0.5f);
+
+  view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, true );
+  DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), true, TEST_LOCATION );
+
+  view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, Vector2(30, 30) );
+
+  Wait(application);
+
+  // Do a pan starting from 100,100 and moving left
+  Vector2 pos(100.0f, 100.0f);
+  SendPan(application, Gesture::Possible, pos);
+  SendPan(application, Gesture::Started, pos);
+  pos.x -= 5.0f;
+  Wait(application, 100);
+
+  for(int i = 0;i<200;i++)
+  {
+    SendPan(application, Gesture::Continuing, pos);
+    pos.x -= 5.0f;
+    Wait(application);
+  }
+
+  SendPan(application, Gesture::Finished, pos);
+  Wait(application, 100);
+
+  // Do a pan starting from 100,100 and moving right
+  pos = Vector2(100.0f, 100.0f);
+  SendPan(application, Gesture::Possible, pos);
+  SendPan(application, Gesture::Started, pos);
+  pos.x += 5.0f;
+  Wait(application, 100);
+
+  for(int i = 0;i<200;i++)
+  {
+    SendPan(application, Gesture::Continuing, pos);
+    pos.x += 5.0f;
+    Wait(application);
+  }
+
+  SendPan(application, Gesture::Finished, pos);
+  Wait(application, 100);
+
+  END_TEST;
+}
+
+int UtcDaliItemEnableDisableRefresh(void)
+{
+  ToolkitTestApplication application;
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+
+  // Create the ItemView actor
+  TestItemFactory factory;
+  ItemView view = ItemView::New(factory);
+
+  // Create a grid layout and add it to ItemView
+  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  view.AddLayout(*gridLayout);
+  stage.Add(view);
+
+  // Activate the grid layout so that the items will be created and added to ItemView
+  Vector3 stageSize(stage.GetSize());
+  view.ActivateLayout(0, stageSize, 0.5f);
+
+  //Connect to signal scroll updated
+  view.ScrollUpdatedSignal().Connect( &OnScrollUpdate );
+
+  Property::Map attributes;
+  view.DoAction("enableRefresh", attributes );
+  gOnScrollUpdateCalled = true;
+  view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
+  application.SendNotification();
+  application.Render(1000);
+  DALI_TEST_EQUALS( gOnScrollUpdateCalled, true, TEST_LOCATION );
+
+
+  view.DoAction("disableRefresh", attributes );
+  gOnScrollUpdateCalled = false;
+  view.SetProperty( ItemView::Property::LAYOUT_POSITION, 100.0f );
+  application.SendNotification();
+  application.Render(1000);
+
+  DALI_TEST_EQUALS( gOnScrollUpdateCalled, false, TEST_LOCATION );
+
+  END_TEST;
+}