logsui/logsapp/tsrc/ut_logsapp/src/ut_logsrecentcallsview.cpp
changeset 10 b04270301d3b
parent 6 41c0a814d878
child 11 64a47b97e1e1
equal deleted inserted replaced
6:41c0a814d878 10:b04270301d3b
    30 #include "logscontact.h"
    30 #include "logscontact.h"
    31 #include "logsmatchesmodel.h"
    31 #include "logsmatchesmodel.h"
    32 
    32 
    33 //SYSTEM
    33 //SYSTEM
    34 #include <QtTest/QtTest>
    34 #include <QtTest/QtTest>
    35 #include <QGesture>
    35 #include <hbswipegesture.h>
    36 #include <hbmainwindow.h>
    36 #include <hbmainwindow.h>
    37 #include <hblistview.h>
    37 #include <hblistview.h>
    38 #include <hblabel.h>
    38 #include <hblabel.h>
    39 #include <hbaction.h>
    39 #include <hbaction.h>
    40 #include <hblistviewitem.h>
    40 #include <hblistviewitem.h>
   391 {
   391 {
   392     LogsRecentCallsView* view = mRepository->recentCallsView();
   392     LogsRecentCallsView* view = mRepository->recentCallsView();
   393     view->activated( false, QVariant(LogsServices::ViewCalled) );
   393     view->activated( false, QVariant(LogsServices::ViewCalled) );
   394     view->mCurrentView = LogsServices::ViewCalled;
   394     view->mCurrentView = LogsServices::ViewCalled;
   395     view->mAppearingView = LogsServices::ViewCalled;
   395     view->mAppearingView = LogsServices::ViewCalled;
   396     mRecentCallsView->mViewManager.mainWindow().setOrientation( Qt::Vertical );
   396 
   397 
   397     HbSwipeGesture* swipe = new HbSwipeGesture();
   398     QSwipeGesture* swipe = new QSwipeGesture();
       
   399     QList<QGesture*> list;
   398     QList<QGesture*> list;
   400     QGestureEvent event(list);
   399     QGestureEvent event(list);
   401     event.ignore(Qt::SwipeGesture);
   400     event.ignore(Qt::SwipeGesture);
   402 
   401 
   403     //no swipe gesture in event
   402     //no swipe gesture in event
   404     QVERIFY(!event.isAccepted(Qt::SwipeGesture));    
   403     QVERIFY(!event.isAccepted(Qt::SwipeGesture));    
   405     view->gestureEvent(&event);
   404     view->gestureEvent(&event);
   406     QVERIFY(!event.isAccepted(Qt::SwipeGesture));
   405     QVERIFY(!event.isAccepted(Qt::SwipeGesture));
   407     QVERIFY(view->mAppearingView == LogsServices::ViewCalled);
   406     QCOMPARE(view->mCurrentView, LogsServices::ViewCalled);
       
   407     QCOMPARE(view->mAppearingView, LogsServices::ViewCalled);
   408     
   408     
   409     //swipe gesture in event, but gesture isn't finished
   409     //swipe gesture in event, but gesture isn't finished
   410     list.append(swipe);
   410     list.append(swipe);
   411     QGestureEvent event2(list);
   411     QGestureEvent event2(list);
   412     event2.ignore(Qt::SwipeGesture);
   412     event2.ignore(Qt::SwipeGesture);
   413     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   413     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   414     QVERIFY(swipe->state() != Qt::GestureFinished);
   414     QVERIFY(swipe->state() != Qt::GestureFinished);
   415     view->gestureEvent(&event2);
   415     view->gestureEvent(&event2);
   416     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   416     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   417     QVERIFY(view->mAppearingView == LogsServices::ViewCalled);
   417     QCOMPARE(view->mCurrentView, LogsServices::ViewCalled);
   418     
   418     QCOMPARE(view->mAppearingView, LogsServices::ViewCalled);
   419     //vertical orientation swipe right up
   419     
       
   420     //swipe right
   420     HbStubHelper::setGestureState(Qt::GestureFinished);
   421     HbStubHelper::setGestureState(Qt::GestureFinished);
   421     event2.setAccepted(Qt::SwipeGesture, false);
   422     event2.setAccepted(Qt::SwipeGesture, false);
   422     swipe->setSwipeAngle(10);
   423     swipe->setSceneSwipeAngle(10);
   423     view->gestureEvent(&event2);
   424     view->gestureEvent(&event2);
   424     QVERIFY( view->mAppearingView == LogsServices::ViewAll );
   425     QCOMPARE(view->mCurrentView, LogsServices::ViewCalled);
       
   426     QCOMPARE(view->mAppearingView, LogsServices::ViewAll );
   425     QVERIFY( event2.isAccepted(Qt::SwipeGesture) );
   427     QVERIFY( event2.isAccepted(Qt::SwipeGesture) );
   426     
   428     
   427     //vertical orientation swipe left up
   429     //swipe left
   428     event2.setAccepted(Qt::SwipeGesture, false);
   430     event2.setAccepted(Qt::SwipeGesture, false);
   429     swipe->setSwipeAngle(170);
   431     swipe->setSceneSwipeAngle(170);
   430     view->gestureEvent(&event2);
   432     view->gestureEvent(&event2);
   431     QVERIFY(view->mAppearingView == LogsServices::ViewReceived);
   433     QCOMPARE(view->mCurrentView, LogsServices::ViewCalled);
       
   434     QCOMPARE(view->mAppearingView, LogsServices::ViewReceived);
   432     QVERIFY(event2.isAccepted(Qt::SwipeGesture));
   435     QVERIFY(event2.isAccepted(Qt::SwipeGesture));
   433 
   436     
   434     //vertical orientation swipe down, nothing happens
   437     //swipe down, nothing happens
   435     event2.setAccepted(Qt::SwipeGesture, false);
   438     event2.setAccepted(Qt::SwipeGesture, false);
   436     swipe->setSwipeAngle(70);
   439     swipe->setSceneSwipeAngle(70);
   437     view->mAppearingView = view->mCurrentView;
   440     view->mAppearingView = view->mCurrentView;
   438     view->gestureEvent(&event2);
   441     view->gestureEvent(&event2);
   439     QVERIFY(view->mAppearingView == LogsServices::ViewCalled);
   442     QCOMPARE(view->mCurrentView, LogsServices::ViewCalled);
       
   443     QCOMPARE(view->mAppearingView, LogsServices::ViewCalled);
   440     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   444     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
   441     
       
   442     //horizontal orientation swipe right up
       
   443     mRecentCallsView->mViewManager.mainWindow().setOrientation( Qt::Horizontal );
       
   444     event2.setAccepted(Qt::SwipeGesture, false);
       
   445     swipe->setSwipeAngle(80);
       
   446     view->gestureEvent(&event2);
       
   447     QVERIFY(view->mAppearingView == LogsServices::ViewReceived);
       
   448     QVERIFY(event2.isAccepted(Qt::SwipeGesture));
       
   449     
       
   450     //horizontal orientation swipe right down
       
   451     event2.setAccepted(Qt::SwipeGesture, false);
       
   452     swipe->setSwipeAngle(280);
       
   453     view->gestureEvent(&event2);
       
   454     QVERIFY(view->mAppearingView == LogsServices::ViewAll);
       
   455     QVERIFY(event2.isAccepted(Qt::SwipeGesture));
       
   456 
       
   457     //horizontal orientation swipe left, nothing happens
       
   458     event2.setAccepted(Qt::SwipeGesture, false);
       
   459     swipe->setSwipeAngle(200);
       
   460     view->mAppearingView = view->mCurrentView;
       
   461     view->gestureEvent(&event2);
       
   462     QVERIFY(view->mAppearingView == LogsServices::ViewCalled);
       
   463     QVERIFY(!event2.isAccepted(Qt::SwipeGesture));
       
   464 }
       
   465 
       
   466 void UT_LogsRecentCallsView::testSwipeAngleToDirection()
       
   467 {
       
   468     int delta = 30;
       
   469     QCOMPARE(mRecentCallsView->swipeAngleToDirection(61, delta), QSwipeGesture::Up);    
       
   470     QCOMPARE(mRecentCallsView->swipeAngleToDirection(119, delta), QSwipeGesture::Up);
       
   471     QCOMPARE(mRecentCallsView->swipeAngleToDirection(90, delta), QSwipeGesture::Up);
       
   472     QCOMPARE(mRecentCallsView->swipeAngleToDirection(60, delta), QSwipeGesture::NoDirection);
       
   473     QCOMPARE(mRecentCallsView->swipeAngleToDirection(120, delta), QSwipeGesture::NoDirection);
       
   474 
       
   475     QCOMPARE(mRecentCallsView->swipeAngleToDirection(241, delta), QSwipeGesture::Down);
       
   476     QCOMPARE(mRecentCallsView->swipeAngleToDirection(299, delta), QSwipeGesture::Down);
       
   477     QCOMPARE(mRecentCallsView->swipeAngleToDirection(270, delta), QSwipeGesture::Down);
       
   478     QCOMPARE(mRecentCallsView->swipeAngleToDirection(300, delta), QSwipeGesture::NoDirection);
       
   479     QCOMPARE(mRecentCallsView->swipeAngleToDirection(240, delta), QSwipeGesture::NoDirection);
       
   480     
       
   481     QCOMPARE(mRecentCallsView->swipeAngleToDirection(29, delta), QSwipeGesture::Right);
       
   482     QCOMPARE(mRecentCallsView->swipeAngleToDirection(331, delta), QSwipeGesture::Right);
       
   483     QCOMPARE(mRecentCallsView->swipeAngleToDirection(0, delta), QSwipeGesture::Right);
       
   484     QCOMPARE(mRecentCallsView->swipeAngleToDirection(360, delta), QSwipeGesture::Right);
       
   485     QCOMPARE(mRecentCallsView->swipeAngleToDirection(30, delta), QSwipeGesture::NoDirection);
       
   486     QCOMPARE(mRecentCallsView->swipeAngleToDirection(330, delta), QSwipeGesture::NoDirection);
       
   487     QCOMPARE(mRecentCallsView->swipeAngleToDirection(361, delta), QSwipeGesture::NoDirection);
       
   488     QCOMPARE(mRecentCallsView->swipeAngleToDirection(-1, delta), QSwipeGesture::NoDirection);
       
   489 
       
   490     QCOMPARE(mRecentCallsView->swipeAngleToDirection(151, delta), QSwipeGesture::Left);
       
   491     QCOMPARE(mRecentCallsView->swipeAngleToDirection(209, delta), QSwipeGesture::Left);
       
   492     QCOMPARE(mRecentCallsView->swipeAngleToDirection(180, delta), QSwipeGesture::Left);
       
   493     QCOMPARE(mRecentCallsView->swipeAngleToDirection(150, delta), QSwipeGesture::NoDirection);
       
   494     QCOMPARE(mRecentCallsView->swipeAngleToDirection(210, delta), QSwipeGesture::NoDirection);
       
   495 }
   445 }
   496 
   446 
   497 void UT_LogsRecentCallsView::testViewChangeByFlicking()
   447 void UT_LogsRecentCallsView::testViewChangeByFlicking()
   498 {
   448 {
   499     // At leftmost list, moving to left not possible
   449     // At leftmost list, moving to left not possible