calendarui/views/dayview/tsrc/unittests/unittest_calendaycontentscrollarea/unittest_calendaycontentscrollarea.cpp
changeset 81 ce92091cbd61
parent 70 a5ed90760192
equal deleted inserted replaced
75:7ac58b2aae6f 81:ce92091cbd61
    16  */
    16  */
    17 #include <QGraphicsItem>
    17 #include <QGraphicsItem>
    18 #include <QGraphicsScene>
    18 #include <QGraphicsScene>
    19 #include <QtTest/QtTest>
    19 #include <QtTest/QtTest>
    20 #include <QGesture>
    20 #include <QGesture>
    21 #include <QPanGesture>
       
    22 
    21 
    23 #include <HbStyleLoader>
    22 #include <HbStyleLoader>
    24 #include <HbWidget>
    23 #include <HbWidget>
    25 #include <HbSwipeGesture>
    24 #include <HbSwipeGesture>
    26 
    25 
    60     void testEvent();
    59     void testEvent();
    61     void testMoveTo();
    60     void testMoveTo();
    62     void testHorizontalSwipe();
    61     void testHorizontalSwipe();
    63     void testMoveFinished();
    62     void testMoveFinished();
    64     void testOrientationChanged();
    63     void testOrientationChanged();
       
    64     void testCheckPanDirection();
       
    65     void testSetGetDisallowedScrollDirection();
    65 
    66 
    66 private:
    67 private:
    67     CalenDayContentScrollArea *mContentScrollArea;
    68     CalenDayContentScrollArea *mContentScrollArea;
    68 };
    69 };
    69 
    70 
   365 /*!
   366 /*!
   366  Test function for moveTo
   367  Test function for moveTo
   367  1. Test moveTo, day not changed
   368  1. Test moveTo, day not changed
   368  2. Test moveTo, day changed to next
   369  2. Test moveTo, day changed to next
   369  3. Test moveTo, day changed to prev
   370  3. Test moveTo, day changed to prev
       
   371  4. Test moveTo, disallowed directon
   370  */
   372  */
   371 void TestCalenDayContentScrollArea::testMoveTo()
   373 void TestCalenDayContentScrollArea::testMoveTo()
   372 {
   374 {
   373 #ifndef __WINSCW__
   375 #ifndef __WINSCW__
   374     //1)
   376     //1)
   386     pos = mContentScrollArea->contentWidget()->pos();
   388     pos = mContentScrollArea->contentWidget()->pos();
   387     QCOMPARE(abs(pos.x()), abs(mContentScrollArea->contentWidget()->pos().x()));
   389     QCOMPARE(abs(pos.x()), abs(mContentScrollArea->contentWidget()->pos().x()));
   388     QCOMPARE(abs(pos.y()), abs(mContentScrollArea->contentWidget()->pos().y()));
   390     QCOMPARE(abs(pos.y()), abs(mContentScrollArea->contentWidget()->pos().y()));
   389     QCOMPARE(mContentScrollArea->mMoveDirection, ECalenScrollNoDayChange);
   391     QCOMPARE(mContentScrollArea->mMoveDirection, ECalenScrollNoDayChange);
   390     
   392     
   391     //2)
   393     //3)
   392     newPos = QPointF(-20,0);
   394     newPos = QPointF(-20,0);
   393     mContentScrollArea->mMoveDirection = ECalenScrollToNext;
   395     mContentScrollArea->mMoveDirection = ECalenScrollToNext;
   394     mContentScrollArea->moveTo(newPos);
   396     mContentScrollArea->moveTo(newPos);
   395     pos = mContentScrollArea->contentWidget()->pos();
   397     pos = mContentScrollArea->contentWidget()->pos();
   396     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().x()), abs(pos.x()));
   398     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().x()), abs(pos.x()));
   397     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().y()), abs(pos.y()));
   399     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().y()), abs(pos.y()));
   398     QCOMPARE(mContentScrollArea->mMoveDirection, ECalenScrollNoDayChange);
   400     QCOMPARE(mContentScrollArea->mMoveDirection, ECalenScrollNoDayChange);
       
   401     
       
   402     //4)
       
   403     newPos = QPointF(20,0);
       
   404     pos = mContentScrollArea->contentWidget()->pos();
       
   405     mContentScrollArea->mDisallowedDirection = ECalenScrollToNext;
       
   406     mContentScrollArea->mMoveDirection = ECalenScrollToNext;
       
   407     mContentScrollArea->moveTo(newPos);
       
   408     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().x()), abs(pos.x()));
       
   409     QCOMPARE(abs(mContentScrollArea->contentWidget()->pos().y()), abs(pos.y()));
   399 #endif /* __WINSCW__ */
   410 #endif /* __WINSCW__ */
   400 }
   411 }
   401 
   412 
   402 /*!
   413 /*!
   403  Test function for checking if swipe is horizontal or not
   414  Test function for checking if swipe is horizontal or not
   457     mContentScrollArea->orientationChanged(Qt::Vertical);
   468     mContentScrollArea->orientationChanged(Qt::Vertical);
   458     QCOMPARE(mContentScrollArea->mOrientation, Qt::Vertical);
   469     QCOMPARE(mContentScrollArea->mOrientation, Qt::Vertical);
   459 #endif /* __WINSCW__ */
   470 #endif /* __WINSCW__ */
   460 }
   471 }
   461 
   472 
       
   473 /*!
       
   474  Test checkPanDirection function
       
   475  1) test pan direction, gesture cancelled, vertical orientation
       
   476  2) test pan direction, gesture started, vertical orientation, vertical movement
       
   477  3) test pan direction, gesture started, vertical orientation, horizontal movement
       
   478  4) test pan direction, gesture started, horizontal orientation, vertical movement
       
   479  5) test pan direction, gesture started, horizontal orientation, horizontal movement
       
   480  */
       
   481 void TestCalenDayContentScrollArea::testCheckPanDirection()
       
   482 {
       
   483 #ifndef __WINSCW__
       
   484     QPanGesture *gesture = new QPanGesture();
       
   485     
       
   486     //1)
       
   487     gesture->setOffset(QPointF(10, 100));
       
   488     gTestGestureState = Qt::GestureCanceled;
       
   489     mContentScrollArea->mPanDayDirection = CalenDayContentScrollArea::ECalenPanNotSet;
       
   490     mContentScrollArea->mOrientation = Qt::Vertical;
       
   491     mContentScrollArea->checkPanDirection(gesture);
       
   492     QCOMPARE(mContentScrollArea->mPanDayDirection, CalenDayContentScrollArea::ECalenPanNotSet);
       
   493 
       
   494     // Cases 2-5 temporarily unavailable
       
   495 /*
       
   496     //2)
       
   497     gesture->setOffset(QPointF(10, 100));
       
   498     gTestGestureState = Qt::GestureStarted;
       
   499     mContentScrollArea->mPanDayDirection = CalenDayContentScrollArea::ECalenPanNotSet;
       
   500     mContentScrollArea->mOrientation = Qt::Vertical;
       
   501     mContentScrollArea->checkPanDirection(gesture);
       
   502     QCOMPARE(mContentScrollArea->mPanDayDirection, CalenDayContentScrollArea::ECalenPanVertical);
       
   503     
       
   504     //3)
       
   505     gesture->setOffset(QPointF(100, 10));
       
   506     gTestGestureState = Qt::GestureStarted;
       
   507     mContentScrollArea->mPanDayDirection = CalenDayContentScrollArea::ECalenPanNotSet;
       
   508     mContentScrollArea->mOrientation = Qt::Vertical;
       
   509     mContentScrollArea->checkPanDirection(gesture);
       
   510     QCOMPARE(mContentScrollArea->mPanDayDirection, CalenDayContentScrollArea::ECalenPanHorizontal);
       
   511     
       
   512     //4)
       
   513     gesture->setOffset(QPointF(10, 100));
       
   514     gTestGestureState = Qt::GestureStarted;
       
   515     mContentScrollArea->mPanDayDirection = CalenDayContentScrollArea::ECalenPanNotSet;
       
   516     mContentScrollArea->mOrientation = Qt::Horizontal;
       
   517     mContentScrollArea->checkPanDirection(gesture);
       
   518     QCOMPARE(mContentScrollArea->mPanDayDirection, CalenDayContentScrollArea::ECalenPanHorizontal);
       
   519     
       
   520     //5)
       
   521     gesture->setOffset(QPointF(100, 10));
       
   522     gTestGestureState = Qt::GestureStarted;
       
   523     mContentScrollArea->mPanDayDirection = CalenDayContentScrollArea::ECalenPanNotSet;
       
   524     mContentScrollArea->mOrientation = Qt::Horizontal;
       
   525     mContentScrollArea->checkPanDirection(gesture);
       
   526     QCOMPARE(mContentScrollArea->mPanDayDirection, CalenDayContentScrollArea::ECalenPanVertical);
       
   527 */
       
   528 #endif /* __WINSCW__ */
       
   529 }
       
   530 
       
   531 /*!
       
   532  Test setter and getter for disallowed direction
       
   533  1) test setter
       
   534  2) test getter
       
   535  */
       
   536 void TestCalenDayContentScrollArea::testSetGetDisallowedScrollDirection()
       
   537 {
       
   538     QCOMPARE(mContentScrollArea->mDisallowedDirection, ECalenScrollNoDayChange);
       
   539     
       
   540     //1)
       
   541     mContentScrollArea->setDisallowedScrollDirection(ECalenScrollToNext);
       
   542     QCOMPARE(mContentScrollArea->mDisallowedDirection, ECalenScrollToNext);
       
   543     
       
   544     //2)
       
   545     QCOMPARE(mContentScrollArea->disallowedScrollDirection(), ECalenScrollToNext);
       
   546 }
       
   547 
   462 QTEST_MAIN(TestCalenDayContentScrollArea);
   548 QTEST_MAIN(TestCalenDayContentScrollArea);
   463 #include "unittest_calendaycontentscrollarea.moc"
   549 #include "unittest_calendaycontentscrollarea.moc"