videocollection/videocollectionview/tsrc/testcollectionview/src/testcollectionview.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 41 229f037ce963
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:   tester for methods in VideoSortFilterProxyModel
    14 * Description:   tester for methods in VideoSortFilterProxyModel
    15 *
    15 *
    16 */
    16 */
       
    17 
       
    18 #include "xqserviceutilxtra.h"
       
    19 
    17 #include <hbaction.h>
    20 #include <hbaction.h>
    18 #include <qpointer.h>
    21 #include <qpointer.h>
    19 #include <hbapplication.h>
    22 #include <hbapplication.h>
    20 #include <hbinstance.h>
    23 #include <hbinstance.h>
    21 #include <hblabel.h>
    24 #include <hblabel.h>
       
    25 #include <vcxmyvideosdefs.h>
    22 
    26 
    23 #include "videocollectionuiloader.h"
    27 #include "videocollectionuiloader.h"
    24 #include "testcollectionview.h"
    28 #include "testcollectionview.h"
    25 #include "videocollectioncommon.h"
    29 #include "videocollectioncommon.h"
    26 #include "videolistview.h"
    30 #include "videolistview.h"
    27 
    31 
    28 #include "videolistviewdata.h"
    32 #include "videolistviewdata.h"
    29 #include "videocollectionuiloaderdata.h"
    33 #include "videocollectionuiloaderdata.h"
       
    34 #include "videoservicebrowsedata.h"
       
    35 #include "videolistviewdata.h"
    30 
    36 
    31 #define private public
    37 #define private public
    32 #include "videocollectionviewplugin.h"
    38 #include "videocollectionviewplugin.h"
       
    39 #include "videoservices.h"
    33 #undef private
    40 #undef private
    34 
    41 
    35 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    36 // main
    43 // main
    37 // ---------------------------------------------------------------------------
    44 // ---------------------------------------------------------------------------
    60 
    67 
    61     return res;
    68     return res;
    62 }
    69 }
    63 
    70 
    64 
    71 
    65 // ---------------------------------------------------------------------------
       
    66 // TestCollectionView
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TestCollectionView::TestCollectionView()
       
    70  : mTestView(0)
       
    71 {
       
    72 }
       
    73 
    72 
    74 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    75 // initTestCase
    74 // initTestCase
    76 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    77 //
    76 //
    93 // init
    92 // init
    94 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    95 //
    94 //
    96 void TestCollectionView::init()
    95 void TestCollectionView::init()
    97 {
    96 {
    98     cleanup();
    97 
    99     VideoCollectionUiLoaderData::reset();
    98     VideoCollectionUiLoaderData::reset();
   100     VideoListViewData::reset();
    99     VideoListViewData::reset();
   101         
   100     VideoServiceBrowseData::reset();
       
   101     VideoListViewData::reset();
       
   102     
       
   103     mTestView = 0;
   102     mTestView = new VideoCollectionViewPlugin();
   104     mTestView = new VideoCollectionViewPlugin();
   103     mTestView->createView();
   105     mTestView->createView();
   104     
   106     
   105     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   107     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   106     if (window)
   108     if (window)
   129     delete mTestView;
   131     delete mTestView;
   130     mTestView = 0;
   132     mTestView = 0;
   131 }
   133 }
   132 
   134 
   133 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   134 // Slot: test create view
   136 // testCreateView
   135 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   136 //
   138 //
   137 void TestCollectionView::testCreateView()
   139 void TestCollectionView::testCreateView()
   138 {
   140 {
   139     cleanup();
   141     cleanup();
   140     VideoCollectionUiLoaderData::reset();
   142     VideoCollectionUiLoaderData::reset();
   141     VideoListViewData::reset();
   143     VideoListViewData::reset();
   142     
   144     
       
   145     // finding view object from docml fails
   143     VideoCollectionUiLoaderData::mFindFailure = true;
   146     VideoCollectionUiLoaderData::mFindFailure = true;
   144 	
       
   145 	mTestView = new VideoCollectionViewPlugin();
   147 	mTestView = new VideoCollectionViewPlugin();
   146 
       
   147     QVERIFY( mTestView->mView == 0 );
       
   148 
       
   149     mTestView->createView();
   148     mTestView->createView();
   150 
   149 
   151     QVERIFY( mTestView->mView == 0 );
   150     QVERIFY( mTestView->mView == 0 );
   152     QVERIFY( mTestView->mUiLoader != 0);
   151     QVERIFY( mTestView->mUiLoader != 0);
   153 
   152 
   154     delete mTestView;
   153     delete mTestView;
   155 
   154 
   156     VideoCollectionUiLoaderData::mFindFailure = false;
   155     VideoCollectionUiLoaderData::mFindFailure = false;
   157 	
       
   158 	mTestView = new VideoCollectionViewPlugin();
   156 	mTestView = new VideoCollectionViewPlugin();
   159 
   157     mTestView->createView();
   160     QVERIFY( mTestView->mView == 0 );
       
   161 
       
   162     mTestView->createView();
       
   163 
       
   164     QVERIFY( mTestView->mView != 0 );
   158     QVERIFY( mTestView->mView != 0 );
   165     QVERIFY( mTestView->mUiLoader != 0);
   159     QVERIFY( mTestView->mUiLoader != 0);
   166     QCOMPARE( VideoListViewData::mInitializeViewCount, 1 );
   160     QCOMPARE( VideoListViewData::mInitializeViewCount, 1 );
   167     QVERIFY( mTestView->mActivated == false );
   161     QVERIFY( mTestView->mActivated == false );
   168 
   162     
       
   163     // second create without view object (for coverity)
       
   164     delete mTestView->mView;
       
   165     mTestView->mView = 0;
       
   166     mTestView->createView();
       
   167     QVERIFY( mTestView->mView != 0 );
       
   168     QVERIFY( mTestView->mUiLoader != 0);
       
   169     QCOMPARE( VideoListViewData::mInitializeViewCount, 2 );
       
   170     QVERIFY( mTestView->mActivated == false );
       
   171     
       
   172     // make sure command signaling works
   169     connect( this, SIGNAL(commandSignal(int)), mTestView->mView, SIGNAL(command(int)));
   173     connect( this, SIGNAL(commandSignal(int)), mTestView->mView, SIGNAL(command(int)));
   170     QSignalSpy commandSpy(mTestView, SIGNAL(command(int)));
   174     QSignalSpy commandSpy(mTestView, SIGNAL(command(int)));
   171     emit commandSignal(5);
   175     emit commandSignal(5);
   172     QCOMPARE( commandSpy.count(), 1 );
   176     QCOMPARE( commandSpy.count(), 1 );
   173     QList<QVariant> arguments = commandSpy.takeFirst();
   177     QList<QVariant> arguments = commandSpy.takeFirst();
   174     QCOMPARE( arguments.at(0).toInt(), 5 );
   178     QCOMPARE( arguments.at(0).toInt(), 5 );
   175     disconnect();
   179     disconnect();
   176 
   180 
       
   181     // view exists
   177     VideoListView* current = mTestView->mView;
   182     VideoListView* current = mTestView->mView;
   178 
   183     mTestView->createView();
   179     mTestView->createView();
   184     QCOMPARE( mTestView->mView, current );    
   180 
       
   181     QCOMPARE( mTestView->mView, current );
       
   182     
       
   183     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   185     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   184     if (window)
   186     if (window)
   185     {
   187     {
   186         window->addView(current);
   188         window->addView(current);
   187     }
   189     }
   188 
   190 }
   189     cleanup();
   191 
   190 }
   192 // ---------------------------------------------------------------------------
   191 
   193 // testActivateView
   192 // ---------------------------------------------------------------------------
       
   193 // Slot: test activate view
       
   194 // ---------------------------------------------------------------------------
   194 // ---------------------------------------------------------------------------
   195 //
   195 //
   196 void TestCollectionView::testActivateView()
   196 void TestCollectionView::testActivateView()
   197 {
   197 {
   198     init();
   198     XQServiceUtilXtra *serviceUtil = XQServiceUtilXtra::instance();
   199 
   199     VideoServices *videoServices = VideoServices::instance();
       
   200     
       
   201     // activate view two times
   200     mTestView->activateView();
   202     mTestView->activateView();
   201     QVERIFY( mTestView->mActivated == true );
   203     QVERIFY( mTestView->mActivated == true );
   202     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   204     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   203 
       
   204     mTestView->activateView();
   205     mTestView->activateView();
   205     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   206     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   206 
   207     cleanup();
   207     cleanup();
   208     
   208 }
   209     // activate view as service:
   209 
   210     // -browse service
   210 // ---------------------------------------------------------------------------
   211     // -captured category
   211 // Slot: test deactivate view
   212     init();
       
   213     serviceUtil->setCurrentService(true);
       
   214     videoServices->mCurrentService = VideoServices::EBrowse;
       
   215     VideoServiceBrowseData::mBrowseCategory = KVcxMvcCategoryIdCaptured;
       
   216     mTestView->activateView();
       
   217     QCOMPARE(VideoListViewData::mActivateViewCount, 1);
       
   218     QVERIFY(VideoListViewData::mActivatedItemId.iId1 == KVcxMvcCategoryIdCaptured);
       
   219     QVERIFY(VideoListViewData::mActivatedItemId.iId2 == KVcxMvcMediaTypeCategory);
       
   220     cleanup();
       
   221     
       
   222     // activate view as browse service:
       
   223     // -browse service
       
   224     // -downloads category
       
   225     init();
       
   226     serviceUtil->setCurrentService(true);
       
   227     videoServices->mCurrentService = VideoServices::EBrowse;
       
   228     VideoServiceBrowseData::mBrowseCategory = KVcxMvcCategoryIdDownloads;
       
   229     mTestView->activateView();
       
   230     QCOMPARE(VideoListViewData::mActivateViewCount, 1);
       
   231     QVERIFY(VideoListViewData::mActivatedItemId.iId1 == KVcxMvcCategoryIdDownloads);
       
   232     QVERIFY(VideoListViewData::mActivatedItemId.iId2 == KVcxMvcMediaTypeCategory);
       
   233     cleanup();
       
   234 
       
   235     // activate view as browse service:
       
   236     // -uri fetch service
       
   237     init();
       
   238     serviceUtil->setCurrentService(true);
       
   239     videoServices->mCurrentService = VideoServices::EUriFetcher;
       
   240     mTestView->activateView();
       
   241     QCOMPARE(VideoListViewData::mActivateViewCount, 1);
       
   242     QVERIFY(VideoListViewData::mActivatedItemId == TMPXItemId::InvalidId());
       
   243     cleanup();
       
   244     
       
   245     // final cleanup
       
   246     serviceUtil->decreaseReferenceCount();
       
   247     videoServices->decreaseReferenceCount();
       
   248 }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // testDeactivateView
   212 // ---------------------------------------------------------------------------
   252 // ---------------------------------------------------------------------------
   213 //
   253 //
   214 void TestCollectionView::testDeactivateView()
   254 void TestCollectionView::testDeactivateView()
   215 {
   255 {
   216     init();
       
   217 
       
   218     mTestView->deactivateView();
   256     mTestView->deactivateView();
   219     QCOMPARE( VideoListViewData::mDeactivateViewCount, 0 );
   257     QCOMPARE( VideoListViewData::mDeactivateViewCount, 0 );
   220     QVERIFY( mTestView->mActivated == false );
   258     QVERIFY( mTestView->mActivated == false );
   221 
   259 
   222     mTestView->activateView();
   260     mTestView->activateView();
   226     QVERIFY( mTestView->mActivated == false );
   264     QVERIFY( mTestView->mActivated == false );
   227 
   265 
   228     mTestView->deactivateView();
   266     mTestView->deactivateView();
   229     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   267     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   230     QVERIFY( mTestView->mActivated == false );
   268     QVERIFY( mTestView->mActivated == false );
   231 
   269 }
   232     cleanup();
   270 
   233 }
   271 // ---------------------------------------------------------------------------
   234 
   272 // testDestroyView
   235 // ---------------------------------------------------------------------------
       
   236 // Slot: test destroy view
       
   237 // ---------------------------------------------------------------------------
   273 // ---------------------------------------------------------------------------
   238 //
   274 //
   239 void TestCollectionView::testDestroyView()
   275 void TestCollectionView::testDestroyView()
   240 {
   276 {
   241     init();
       
   242 
       
   243     // remove view from mainwindow so that we don't get hanging pointers there, as
   277     // remove view from mainwindow so that we don't get hanging pointers there, as
   244     // the test is creating and destroying view several times.
   278     // the test is creating and destroying view several times.
   245     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   279     HbMainWindow *window = hbInstance->allMainWindows().value(0);
   246     QVERIFY(window);
   280     QVERIFY(window);
   247     window->removeView(mTestView->mView);
   281     window->removeView(mTestView->mView);
   262     mTestView->destroyView();
   296     mTestView->destroyView();
   263     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   297     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   264     QVERIFY( mTestView->mActivated == false );
   298     QVERIFY( mTestView->mActivated == false );
   265     QVERIFY( mTestView->mView == 0 );
   299     QVERIFY( mTestView->mView == 0 );
   266     QVERIFY( mTestView->mUiLoader == 0);
   300     QVERIFY( mTestView->mUiLoader == 0);
   267 
   301 }
   268     cleanup();
   302 
   269 }
   303 // ---------------------------------------------------------------------------
   270 
   304 // testGetView
   271 // ---------------------------------------------------------------------------
       
   272 // Slot: test get view
       
   273 // ---------------------------------------------------------------------------
   305 // ---------------------------------------------------------------------------
   274 //
   306 //
   275 void TestCollectionView::testGetView()
   307 void TestCollectionView::testGetView()
   276 {
   308 {
   277     cleanup();
   309     QVERIFY( mTestView->getView() == mTestView->mView );
   278     mTestView = new VideoCollectionViewPlugin();
       
   279 
       
   280     QVERIFY( mTestView->getView() == 0 );
       
   281     mTestView->createView();
   310     mTestView->createView();
   282     QVERIFY( mTestView->getView() == mTestView->mView );
   311     QVERIFY( mTestView->getView() == mTestView->mView );
   283     mTestView->activateView();
   312     mTestView->activateView();
   284     QVERIFY( mTestView->getView() == mTestView->mView );
   313     QVERIFY( mTestView->getView() == mTestView->mView );
   285     mTestView->deactivateView();
   314     mTestView->deactivateView();
   286     QVERIFY( mTestView->getView() == mTestView->mView );
   315     QVERIFY( mTestView->getView() == mTestView->mView );
   287     mTestView->destroyView();
   316     mTestView->destroyView();
   288     QVERIFY( mTestView->getView() == 0 );
   317     QVERIFY( mTestView->getView() == 0 );    
   289 
   318     // need to create view to handle cleaning up correctly
   290     cleanup();
   319     mTestView->createView();
   291 }
   320 }
   292 
   321 
   293 // ---------------------------------------------------------------------------
   322 // ---------------------------------------------------------------------------
   294 // Slot: test get view
   323 // testBack
   295 // ---------------------------------------------------------------------------
   324 // ---------------------------------------------------------------------------
   296 //
   325 //
   297 void TestCollectionView::testBack()
   326 void TestCollectionView::testBack()
   298 {
   327 {
   299     init();
       
   300 
       
   301     mTestView->back();
   328     mTestView->back();
   302     QCOMPARE( VideoListViewData::mBackCount, 0 );
   329     QCOMPARE( VideoListViewData::mBackCount, 0 );
   303     mTestView->activateView();
   330     mTestView->activateView();
   304     mTestView->back();
   331     mTestView->back();
   305     QCOMPARE( VideoListViewData::mBackCount, 1 );
   332     QCOMPARE( VideoListViewData::mBackCount, 1 );
   306 
   333 }
   307     cleanup();
   334 
   308 }
   335 // ---------------------------------------------------------------------------
   309 
   336 // testOrientationChange
   310 // ---------------------------------------------------------------------------
       
   311 // Slot: test orientation change
       
   312 // ---------------------------------------------------------------------------
   337 // ---------------------------------------------------------------------------
   313 //
   338 //
   314 void TestCollectionView::testOrientationChange()
   339 void TestCollectionView::testOrientationChange()
   315 {
   340 {
   316     // there's nothing to be tested for this.
   341     // there's nothing to be tested for this.
   317     // slot is probably going to be removed. This is here just to have the
   342     // slot is probably going to be removed. This is here just to have the
   318     // function decision coverage on correct level.
   343     // function decision coverage on correct level.
   319     init();
       
   320     mTestView->orientationChange(Qt::Horizontal);
   344     mTestView->orientationChange(Qt::Horizontal);
   321     cleanup();
   345 
       
   346 }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // testTimerEvent
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void TestCollectionView::testTimerEvent()
       
   353 {
       
   354     QSignalSpy commandSpy(mTestView, SIGNAL(command(int)));
       
   355     QSignalSpy delayedSpy(mTestView, SIGNAL(doDelayeds()));
       
   356     
       
   357     QEvent event(QEvent::Timer);
       
   358     QApplication::sendEvent(mTestView, &event);
       
   359     QVERIFY(commandSpy.count() == 0);
       
   360     QVERIFY(delayedSpy.count() == 0);
       
   361     
       
   362     QTimerEvent timerEvent(mTestView->mTimerId);
       
   363     QApplication::sendEvent(mTestView, &timerEvent);
       
   364     QVERIFY(commandSpy.count() == 1);
       
   365     QVERIFY(delayedSpy.count() == 1);
       
   366     
   322 }
   367 }
   323 
   368 
   324 
   369 
   325 
   370 
   326 // End of file
   371 // End of file