videocollection/videocollectionview/tsrc/testcollectionview/src/testcollectionview.cpp
changeset 35 3738fe97f027
parent 34 bbb98528c666
child 36 8aed59de29f9
equal deleted inserted replaced
34:bbb98528c666 35:3738fe97f027
    17 #include <hbaction.h>
    17 #include <hbaction.h>
    18 #include <qpointer.h>
    18 #include <qpointer.h>
    19 #include <hbapplication.h>
    19 #include <hbapplication.h>
    20 #include <hbinstance.h>
    20 #include <hbinstance.h>
    21 #include <hblabel.h>
    21 #include <hblabel.h>
       
    22 
    22 #include "videocollectionuiloader.h"
    23 #include "videocollectionuiloader.h"
    23 #include "testcollectionview.h"
    24 #include "testcollectionview.h"
    24 #include "videocollectioncommon.h"
    25 #include "videocollectioncommon.h"
    25 #include "videolistview.h"
    26 #include "videolistview.h"
    26 
    27 
    37 //
    38 //
    38 int main(int argc, char *argv[])
    39 int main(int argc, char *argv[])
    39 {
    40 {
    40     HbApplication app(argc, argv);
    41     HbApplication app(argc, argv);
    41     HbMainWindow window;
    42     HbMainWindow window;
       
    43     hbInstance->mWindowses.append(&window);
    42 
    44 
    43     TestCollectionView tv;
    45     TestCollectionView tv;
    44 
    46 
    45     int res;
    47     int res;
    46     if(argc > 1)
    48     if(argc > 1)
    57     }
    59     }
    58 
    60 
    59     return res;
    61     return res;
    60 }
    62 }
    61 
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // TestCollectionView
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TestCollectionView::TestCollectionView()
       
    70  : mTestView(0)
       
    71 {
       
    72 }
       
    73 
    62 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    63 // initTestCase
    75 // initTestCase
    64 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    65 //
    77 //
    66 void TestCollectionView::initTestCase()
    78 void TestCollectionView::initTestCase()
    81 // init
    93 // init
    82 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
    83 //
    95 //
    84 void TestCollectionView::init()
    96 void TestCollectionView::init()
    85 {
    97 {
       
    98     cleanup();
    86     VideoCollectionUiLoaderData::reset();
    99     VideoCollectionUiLoaderData::reset();
    87     VideoListViewData::reset();
   100     VideoListViewData::reset();
    88         
   101         
    89     mTestView = new VideoCollectionViewPlugin();
   102     mTestView = new VideoCollectionViewPlugin();
    90     mTestView->createView();
   103     mTestView->createView();
   121 // Slot: test create view
   134 // Slot: test create view
   122 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   123 //
   136 //
   124 void TestCollectionView::testCreateView()
   137 void TestCollectionView::testCreateView()
   125 {
   138 {
       
   139     cleanup();
   126     VideoCollectionUiLoaderData::reset();
   140     VideoCollectionUiLoaderData::reset();
   127     VideoListViewData::reset();
   141     VideoListViewData::reset();
   128     
   142     
   129     VideoCollectionUiLoaderData::mFindFailure = true;
   143     VideoCollectionUiLoaderData::mFindFailure = true;
   130 	
   144 	
   131 	mTestView = new VideoCollectionViewPlugin();
   145 	mTestView = new VideoCollectionViewPlugin();
   132 
   146 
   133     QVERIFY( mTestView->mView == NULL );
   147     QVERIFY( mTestView->mView == 0 );
   134 
   148 
   135     mTestView->createView();
   149     mTestView->createView();
   136 
   150 
   137     QVERIFY( mTestView->mView == NULL );
   151     QVERIFY( mTestView->mView == 0 );
       
   152     QVERIFY( mTestView->mUiLoader != 0);
   138 
   153 
   139     delete mTestView;
   154     delete mTestView;
   140 
   155 
   141     VideoCollectionUiLoaderData::mFindFailure = false;
   156     VideoCollectionUiLoaderData::mFindFailure = false;
   142 	
   157 	
   143 	mTestView = new VideoCollectionViewPlugin();
   158 	mTestView = new VideoCollectionViewPlugin();
   144 
   159 
   145     QVERIFY( mTestView->mView == NULL );
   160     QVERIFY( mTestView->mView == 0 );
   146 
   161 
   147     mTestView->createView();
   162     mTestView->createView();
   148 
   163 
   149     QVERIFY( mTestView->mView != NULL );
   164     QVERIFY( mTestView->mView != 0 );
       
   165     QVERIFY( mTestView->mUiLoader != 0);
   150     QCOMPARE( VideoListViewData::mInitializeViewCount, 1 );
   166     QCOMPARE( VideoListViewData::mInitializeViewCount, 1 );
   151     QVERIFY( mTestView->mActivated == false );
   167     QVERIFY( mTestView->mActivated == false );
   152 
   168 
   153     connect( this, SIGNAL(commandSignal(int)), mTestView->mView, SIGNAL(command(int)));
   169     connect( this, SIGNAL(commandSignal(int)), mTestView->mView, SIGNAL(command(int)));
   154     QSignalSpy commandSpy(mTestView, SIGNAL(command(int)));
   170     QSignalSpy commandSpy(mTestView, SIGNAL(command(int)));
   184     mTestView->activateView();
   200     mTestView->activateView();
   185     QVERIFY( mTestView->mActivated == true );
   201     QVERIFY( mTestView->mActivated == true );
   186     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   202     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   187 
   203 
   188     mTestView->activateView();
   204     mTestView->activateView();
   189     HbAction *tmpAction = 0;
       
   190     HbMainWindow *window = hbInstance->allMainWindows().value(0);
       
   191     if (window)
       
   192     {
       
   193         tmpAction = window->softKeyAction(Hb::SecondarySoftKey);
       
   194     }
       
   195     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   205     QCOMPARE( VideoListViewData::mActivateViewCount, 1 );
   196     QVERIFY(tmpAction != 0);
       
   197 
   206 
   198     cleanup();
   207     cleanup();
   199 }
   208 }
   200 
   209 
   201 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   212 
   221 
   213     mTestView->activateView();
   222     mTestView->activateView();
   214 
   223 
   215     mTestView->deactivateView();
   224     mTestView->deactivateView();
   216     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   225     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   217 
       
   218     QVERIFY( mTestView->mActivated == false );
   226     QVERIFY( mTestView->mActivated == false );
   219 
   227 
   220     mTestView->deactivateView();
   228     mTestView->deactivateView();
   221     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   229     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   222     QVERIFY( mTestView->mActivated == false );
   230     QVERIFY( mTestView->mActivated == false );
   230 //
   238 //
   231 void TestCollectionView::testDestroyView()
   239 void TestCollectionView::testDestroyView()
   232 {
   240 {
   233     init();
   241     init();
   234 
   242 
   235     mTestView->activateView();
   243     // remove view from mainwindow so that we don't get hanging pointers there, as
   236 
   244     // the test is creating and destroying view several times.
       
   245     HbMainWindow *window = hbInstance->allMainWindows().value(0);
       
   246     QVERIFY(window);
       
   247     window->removeView(mTestView->mView);
       
   248     
       
   249     mTestView->activateView();
       
   250     
   237     mTestView->destroyView();
   251     mTestView->destroyView();
   238 
   252 
   239     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   253     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   240     QVERIFY( mTestView->mActivated == false );
   254     QVERIFY( mTestView->mActivated == false );
   241     QVERIFY( mTestView->mView == 0 );
   255     QVERIFY( mTestView->mView == 0 );
       
   256     QVERIFY( mTestView->mUiLoader == 0);
   242 
   257 
   243     mTestView->createView();
   258     mTestView->createView();
   244     QVERIFY( mTestView->mView != 0 );
   259     QVERIFY( mTestView->mView != 0 );
       
   260     QVERIFY( mTestView->mUiLoader != 0);
       
   261     
   245     mTestView->destroyView();
   262     mTestView->destroyView();
   246     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   263     QCOMPARE( VideoListViewData::mDeactivateViewCount, 1 );
   247     QVERIFY( mTestView->mActivated == false );
   264     QVERIFY( mTestView->mActivated == false );
   248     QVERIFY( mTestView->mView == 0 );
   265     QVERIFY( mTestView->mView == 0 );
       
   266     QVERIFY( mTestView->mUiLoader == 0);
   249 
   267 
   250     cleanup();
   268     cleanup();
   251 }
   269 }
   252 
   270 
   253 // ---------------------------------------------------------------------------
   271 // ---------------------------------------------------------------------------
   254 // Slot: test get view
   272 // Slot: test get view
   255 // ---------------------------------------------------------------------------
   273 // ---------------------------------------------------------------------------
   256 //
   274 //
   257 void TestCollectionView::testGetView()
   275 void TestCollectionView::testGetView()
   258 {
   276 {
       
   277     cleanup();
   259     mTestView = new VideoCollectionViewPlugin();
   278     mTestView = new VideoCollectionViewPlugin();
   260 
   279 
   261     QVERIFY( mTestView->getView() == 0 );
   280     QVERIFY( mTestView->getView() == 0 );
   262     mTestView->createView();
   281     mTestView->createView();
   263     QVERIFY( mTestView->getView() == mTestView->mView );
   282     QVERIFY( mTestView->getView() == mTestView->mView );
   292 // Slot: test orientation change
   311 // Slot: test orientation change
   293 // ---------------------------------------------------------------------------
   312 // ---------------------------------------------------------------------------
   294 //
   313 //
   295 void TestCollectionView::testOrientationChange()
   314 void TestCollectionView::testOrientationChange()
   296 {
   315 {
   297     // there's nothing to be tested yet for this.
   316     // there's nothing to be tested for this.
   298     // implementation is requires due inherited mpxviewplugin
   317     // slot is probably going to be removed. This is here just to have the
   299     init();
   318     // function decision coverage on correct level.
   300     QVERIFY(mTestView);
   319     init();
   301     mTestView->orientationChange(Qt::Horizontal);
   320     mTestView->orientationChange(Qt::Horizontal);
   302     mTestView->orientationChange(Qt::Vertical);
       
   303 
       
   304     cleanup();
   321     cleanup();
   305 }
   322 }
   306 
   323 
   307 
   324 
   308 
   325