videocollection/videocollectionwrapper/tsrc/testvideocollectionwrapper_p/src/testvideocollectionwrapper_p.cpp
changeset 15 cf5481c2bc0b
child 17 69946d1824c4
equal deleted inserted replaced
2:dec420019252 15:cf5481c2bc0b
       
     1 
       
     2 /**
       
     3 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:   tester for methods in VideoCollectionWrapperPrivate
       
    16 * 
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <qabstractitemmodel.h>
       
    22 #include <hbapplication.h>
       
    23 #include "testvideocollectionwrapper_p.h"
       
    24 #include "videocollectionwrapper.h"
       
    25 #include "videocollectioncommon.h"
       
    26 #include "videolistdatamodel.h"
       
    27 #include "videosortfilterproxymodel.h"
       
    28 #include "videocollectionclient.h"
       
    29 #include "vcxmyvideosdefs.h"
       
    30 
       
    31 #define private public
       
    32 #include "videocollectionwrapper_p.h"
       
    33 #undef private
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // main
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 int main(int argc, char *argv[])
       
    40 {
       
    41     TestVideCollectionWrapper_p tv;
       
    42     HbApplication app(argc, argv);
       
    43     int res;
       
    44     if(argc > 1)
       
    45     {   
       
    46         res = QTest::qExec(&tv, argc, argv);
       
    47     }
       
    48     else
       
    49     {
       
    50         char *pass[3];
       
    51         pass[0] = argv[0];
       
    52         pass[1] = "-o";
       
    53         pass[2] = "c:\\data\\testvideocollectionwrapper_p.txt";
       
    54         res = QTest::qExec(&tv, 3, pass);
       
    55     }
       
    56     
       
    57     return res;
       
    58 }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // init
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void TestVideCollectionWrapper_p::init()
       
    66 {
       
    67     mTestObject = new VideoCollectionWrapperPrivate();
       
    68     QVERIFY(mTestObject);
       
    69 }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // cleanup
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void TestVideCollectionWrapper_p::cleanup()
       
    76 {
       
    77     delete mTestObject;  
       
    78     mTestObject = 0;
       
    79 }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // testGetModelInitFail
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void TestVideCollectionWrapper_p::testGetModelInitFail()
       
    86 {
       
    87     QVERIFY(mTestObject);        
       
    88     
       
    89     VideoSortFilterProxyModel *proxyGotten = 0;
       
    90     int type = -1;
       
    91            
       
    92     // source model init fails
       
    93     VideoListDataModel::mInitFails = true;
       
    94     type = VideoCollectionWrapper::EAllVideos;
       
    95     proxyGotten = mTestObject->getModel(type);
       
    96     QVERIFY(!proxyGotten);
       
    97     
       
    98     VideoListDataModel::mInitFails = false;
       
    99     VideoSortFilterProxyModel::setInitFailure(true);
       
   100     
       
   101     // VideoCollectionWrapper::EAllvideos -> init fails
       
   102     type = VideoCollectionWrapper::EAllVideos;
       
   103     proxyGotten = mTestObject->getModel(type);
       
   104     QVERIFY(!proxyGotten);
       
   105     
       
   106     // VideoCollectionWrapper::ECollections -> init fails
       
   107     type = VideoCollectionWrapper::ECollections;
       
   108     proxyGotten = mTestObject->getModel(type);
       
   109     QVERIFY(!proxyGotten);
       
   110     
       
   111     // VideoCollectionWrapper::EGeneric -> init fails
       
   112     type = VideoCollectionWrapper::EGeneric;
       
   113     proxyGotten = mTestObject->getModel(type);
       
   114     QVERIFY(!proxyGotten);
       
   115     
       
   116     type = VideoCollectionWrapper::ECollectionContent;
       
   117     proxyGotten = mTestObject->getModel(type);
       
   118     QVERIFY(!proxyGotten);
       
   119     
       
   120     // called with invalid type param
       
   121     type = -1;
       
   122     VideoListDataModel::mInitFails = false;
       
   123     proxyGotten = mTestObject->getModel(type);
       
   124     QVERIFY(!proxyGotten);
       
   125     
       
   126 }
       
   127 
       
   128  
       
   129 // -----------------------------------------------------------------------------
       
   130 // testGetModelSucceed
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void TestVideCollectionWrapper_p::testGetModelSucceed()
       
   134 {
       
   135     QVERIFY(mTestObject);        
       
   136        
       
   137     VideoSortFilterProxyModel *proxyGotten = 0;
       
   138     int type = -1;    
       
   139     VideoSortFilterProxyModel::setInitFailure(false);
       
   140     // VideoCollectionWrapper::EAllvideos
       
   141     type = VideoCollectionWrapper::EAllVideos;
       
   142     proxyGotten = mTestObject->getModel(type);
       
   143     QVERIFY(proxyGotten);
       
   144     QVERIFY(proxyGotten->mType == type);
       
   145     proxyGotten = mTestObject->getModel(type);
       
   146     QVERIFY(proxyGotten);
       
   147     QVERIFY(proxyGotten->mType == type);
       
   148     delete proxyGotten;
       
   149     proxyGotten = 0;
       
   150    
       
   151     // VideoCollectionWrapper::ECollections
       
   152     type = VideoCollectionWrapper::ECollections;
       
   153     proxyGotten = mTestObject->getModel(type);
       
   154     QVERIFY(proxyGotten);
       
   155     QVERIFY(proxyGotten->mType == type);
       
   156     proxyGotten = mTestObject->getModel(type);
       
   157     QVERIFY(proxyGotten);
       
   158     QVERIFY(proxyGotten->mType == type);
       
   159     delete proxyGotten;
       
   160     proxyGotten = 0;
       
   161    
       
   162    // VideoCollectionWrapper::EGeneric
       
   163     type = VideoCollectionWrapper::EGeneric;
       
   164     proxyGotten = mTestObject->getModel(type);
       
   165     QVERIFY(proxyGotten);
       
   166     QVERIFY(proxyGotten->mType == type);
       
   167     proxyGotten = mTestObject->getModel(type);
       
   168     QVERIFY(proxyGotten);
       
   169     QVERIFY(proxyGotten->mType == type);
       
   170     delete proxyGotten;
       
   171     proxyGotten = 0;
       
   172     
       
   173     // VideoCollectionWrapper::ECollectionContent
       
   174     type = VideoCollectionWrapper::ECollectionContent;
       
   175     proxyGotten = mTestObject->getModel(type);
       
   176     QVERIFY(proxyGotten);
       
   177     QVERIFY(proxyGotten->mType == type);
       
   178     proxyGotten = mTestObject->getModel(type);
       
   179     QVERIFY(proxyGotten);
       
   180     QVERIFY(proxyGotten->mType == type);
       
   181     delete proxyGotten;
       
   182     proxyGotten = 0;
       
   183    
       
   184     // called with invalid type param
       
   185     type = -1;
       
   186     VideoListDataModel::mInitFails = false;
       
   187     proxyGotten = mTestObject->getModel(type);
       
   188     QVERIFY(!proxyGotten);
       
   189     
       
   190 }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // testAboutToQuitSlot
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void TestVideCollectionWrapper_p::testAboutToQuitSlot()
       
   197 {
       
   198     QVERIFY(mTestObject);        
       
   199     connect(this, SIGNAL(testSignal()), mTestObject, SLOT(aboutToQuitSlot()));
       
   200     
       
   201     VideoSortFilterProxyModel *proxyGotten = 0;
       
   202     int type = -1;    
       
   203     
       
   204     VideoSortFilterProxyModel::setInitFailure(false);
       
   205     type = VideoCollectionWrapper::EAllVideos;
       
   206     proxyGotten = mTestObject->getModel(type);
       
   207     QVERIFY(proxyGotten);
       
   208     QVERIFY(!mTestObject->mSourceModel.isNull());
       
   209     emit testSignal();
       
   210     QVERIFY(mTestObject->mSourceModel.isNull());
       
   211     
       
   212     emit testSignal();
       
   213     QVERIFY(mTestObject->mSourceModel.isNull());
       
   214     
       
   215     
       
   216     disconnect(this, SIGNAL(testSignal()), mTestObject, SLOT(aboutToQuitSlot()));
       
   217 }
       
   218 
       
   219 
       
   220 // End of file
       
   221     
       
   222 
       
   223