X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ItemView.cpp;h=d5c6af5f7b1ab9488b097758f4676c5a99a35662;hp=b85524dd6904bb6777570acfc5f8a9b8e5dbc341;hb=b0afc347abc84d3ed5f02fc0f037ebf8dc223b6a;hpb=a7646628bf0d87a7f9e02d8f4db52dea881579c7 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp index b85524d..d5c6af5 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp @@ -22,8 +22,10 @@ // Need to override adaptor classes for toolkit test harness, so include // test harness headers before dali headers. #include - #include +#include +#include + using namespace Dali; using namespace Toolkit; @@ -59,6 +61,48 @@ static void OnLayoutActivated() gOnLayoutActivatedCalled = 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,9 +157,9 @@ 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 = ImageActor::New(image); + Actor actor = CreateRenderableActor(image); return actor; } @@ -301,6 +345,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 +376,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 +401,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 +433,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 +537,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 +628,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 +661,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 +718,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 +742,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()); @@ -704,11 +755,11 @@ int UtcDaliItemViewReplaceItemsP(void) for( unsigned int i = 0u; i < 10; ++i ) { - Actor child = view.GetChildAt( i ); + Actor child = view.GetItem( i ); Actor newActor = Actor::New(); newActor.SetName("Replaced"); - replaceList.push_back( Item( view.GetItemId(child), newActor ) ); + replaceList.push_back( Item( i, newActor ) ); } if( !replaceList.empty() ) @@ -729,9 +780,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 +805,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()); @@ -837,3 +890,215 @@ int UtcDaliItemViewLayoutActivatedSignalP(void) END_TEST; } + +int UtcDaliItemViewSetGetProperty(void) +{ + ToolkitTestApplication application; + + // Create the ItemView actor + TestItemFactory factory; + ItemView view = ItemView::New(factory); + DALI_TEST_CHECK(view); + + // Event side properties + + // Test "minimumSwipeSpeed" property + DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeSpeed") == ItemView::Property::MINIMUM_SWIPE_SPEED ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get(), view.GetMinimumSwipeSpeed(), TEST_LOCATION ); + view.SetProperty( ItemView::Property::MINIMUM_SWIPE_SPEED, 2.5f ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_SPEED).Get(), 2.5f, TEST_LOCATION ); + + // Test "minimumSwipeDistance" property + DALI_TEST_CHECK( view.GetPropertyIndex("minimumSwipeDistance") == ItemView::Property::MINIMUM_SWIPE_DISTANCE ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get(), view.GetMinimumSwipeDistance(), TEST_LOCATION ); + view.SetProperty( ItemView::Property::MINIMUM_SWIPE_DISTANCE, 8.725f ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::MINIMUM_SWIPE_DISTANCE).Get(), 8.725f, TEST_LOCATION ); + + // Test "wheelScrollDistanceStep" property + DALI_TEST_CHECK( view.GetPropertyIndex("wheelScrollDistanceStep") == ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get(), view.GetWheelScrollDistanceStep(), TEST_LOCATION ); + view.SetProperty( ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP, 5.0f ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP).Get(), 5.0f, TEST_LOCATION ); + + // Test "snapToItemEnabled" property + DALI_TEST_CHECK( view.GetPropertyIndex("snapToItemEnabled") == ItemView::Property::SNAP_TO_ITEM_ENABLED ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get(), view.GetAnchoring(), TEST_LOCATION ); + view.SetProperty( ItemView::Property::SNAP_TO_ITEM_ENABLED, true ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SNAP_TO_ITEM_ENABLED).Get(), true, TEST_LOCATION ); + + // Test "refreshInterval" property + DALI_TEST_CHECK( view.GetPropertyIndex("refreshInterval") == ItemView::Property::REFRESH_INTERVAL ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get(), view.GetRefreshInterval(), TEST_LOCATION ); + view.SetProperty( ItemView::Property::REFRESH_INTERVAL, 11.0f ); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::REFRESH_INTERVAL).Get(), 11.0f, TEST_LOCATION ); + + // Test "overshootEnabled" property + DALI_TEST_CHECK( view.GetPropertyIndex("overshootEnabled") == Scrollable::Property::OVERSHOOT_ENABLED ); + DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get(), view.IsOvershootEnabled(), TEST_LOCATION ); + view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false ); + DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get(), false, TEST_LOCATION ); + + // Animatable properties + + // Test "layoutPosition" property + DALI_TEST_CHECK( view.GetPropertyIndex("layoutPosition") == ItemView::Property::LAYOUT_POSITION ); + view.SetProperty( ItemView::Property::LAYOUT_POSITION, 20.5f ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_POSITION).Get(), 20.5f, TEST_LOCATION ); + + // Test "scrollSpeed" property + DALI_TEST_CHECK( view.GetPropertyIndex("scrollSpeed") == ItemView::Property::SCROLL_SPEED ); + view.SetProperty( ItemView::Property::SCROLL_SPEED, 3.35f ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_SPEED).Get(), 3.35f, TEST_LOCATION ); + + // Test "overshoot" property + DALI_TEST_CHECK( view.GetPropertyIndex("overshoot") == ItemView::Property::OVERSHOOT ); + view.SetProperty( ItemView::Property::OVERSHOOT, 0.15f ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::OVERSHOOT).Get(), 0.15f, TEST_LOCATION ); + + // Test "scrollDirection" property + DALI_TEST_CHECK( view.GetPropertyIndex("scrollDirection") == ItemView::Property::SCROLL_DIRECTION ); + view.SetProperty( ItemView::Property::SCROLL_DIRECTION, Vector2(0.85f, 0.5f) ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_DIRECTION).Get(), Vector2(0.85f, 0.5f), TEST_LOCATION ); + + // Test "layoutOrientation" property + DALI_TEST_CHECK( view.GetPropertyIndex("layoutOrientation") == ItemView::Property::LAYOUT_ORIENTATION ); + view.SetProperty( ItemView::Property::LAYOUT_ORIENTATION, 2 ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::LAYOUT_ORIENTATION).Get(), 2, TEST_LOCATION ); + + // Test "scrollContentSize" property + DALI_TEST_CHECK( view.GetPropertyIndex("scrollContentSize") == ItemView::Property::SCROLL_CONTENT_SIZE ); + view.SetProperty( ItemView::Property::SCROLL_CONTENT_SIZE, 250.0f ); + Wait(application); + DALI_TEST_EQUALS( view.GetProperty(ItemView::Property::SCROLL_CONTENT_SIZE).Get(), 250.0f, TEST_LOCATION ); + + 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(), 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(), 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; +}