videocollection/videocollectionwrapper/tsrc/testvideoproxymodelcontent/src/testvideoproxymodelcontent.cpp
changeset 62 0e1e938beb1a
equal deleted inserted replaced
59:a76e86df7ccd 62:0e1e938beb1a
       
     1 /**
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   tester for methods in VideoProxyModelContent
       
    15 * 
       
    16 */
       
    17 
       
    18 #include <QModelIndex>
       
    19 #include <QModelIndexList>
       
    20 #include <hbapplication.h>
       
    21 
       
    22 #include "videoproxymodelgeneric.h"
       
    23 
       
    24 #define private public
       
    25 #include "videoproxymodelcontent.h"
       
    26 #undef private
       
    27 
       
    28 #include "videolistdatamodel.h"
       
    29 #include "filterproxytester.h"
       
    30 #include "videocollectioncommon.h"
       
    31 #include "testvideoproxymodelcontent.h"
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // main
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 int main(int argc, char *argv[])
       
    38 {
       
    39     HbApplication app(argc, argv);
       
    40     
       
    41     TestVideoProxyModelContent tv;
       
    42 
       
    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\\testVideoProxyModelContent.txt";
       
    54         res = QTest::qExec(&tv, 3, pass);
       
    55     }    
       
    56     
       
    57     return res;
       
    58 }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // init
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void TestVideoProxyModelContent::init()
       
    65 {
       
    66     qRegisterMetaType<TMPXItemId>("TMPXItemId");
       
    67     
       
    68     mTestObject = new FilterProxyTester();
       
    69 }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // cleanup
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void TestVideoProxyModelContent::cleanup()
       
    76 {
       
    77     delete mTestObject;
       
    78     mTestObject = 0;
       
    79 }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // testConnectSignals
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void TestVideoProxyModelContent::testConnectSignals()
       
    86 {
       
    87     // Base class connect returns false.
       
    88     VideoProxyModelGeneric::mConnectSignalsCallCount = 0;
       
    89     VideoProxyModelGeneric::mConnectSignalsReturnValue = false;
       
    90     QVERIFY(mTestObject->callConnectSignals() == false);
       
    91     QCOMPARE(VideoProxyModelGeneric::mConnectSignalsCallCount, 1);
       
    92     
       
    93     // No model.
       
    94     VideoProxyModelGeneric::mConnectSignalsCallCount = 0;
       
    95     VideoProxyModelGeneric::mConnectSignalsReturnValue = true;
       
    96     QVERIFY(mTestObject->callConnectSignals() == false);
       
    97     QCOMPARE(VideoProxyModelGeneric::mConnectSignalsCallCount, 1);
       
    98 
       
    99     // Model exists.
       
   100     VideoProxyModelGeneric::mConnectSignalsCallCount = 0;
       
   101     VideoProxyModelGeneric::mConnectSignalsReturnValue = true;
       
   102     VideoListDataModel *model = new VideoListDataModel();
       
   103     mTestObject->mModel = model;
       
   104     QVERIFY(mTestObject->callConnectSignals() == true);
       
   105     QCOMPARE(VideoProxyModelGeneric::mConnectSignalsCallCount, 1);
       
   106 }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // testDisconnectSignals
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void TestVideoProxyModelContent::testDisconnectSignals()
       
   113 {
       
   114     // No model
       
   115     VideoProxyModelGeneric::mDisconnectSignalsCallCount = 0;
       
   116     mTestObject->callDisconnectSignals();
       
   117     QCOMPARE(VideoProxyModelGeneric::mDisconnectSignalsCallCount, 1);
       
   118     
       
   119     // Model exists.
       
   120     VideoProxyModelGeneric::mDisconnectSignalsCallCount = 0;
       
   121     VideoListDataModel *model = new VideoListDataModel();
       
   122     mTestObject->mModel = model;
       
   123     mTestObject->callDisconnectSignals();
       
   124     QCOMPARE(VideoProxyModelGeneric::mDisconnectSignalsCallCount, 1);
       
   125 }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // testFilterAcceptsRow
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void TestVideoProxyModelContent::testFilterAcceptsRow()
       
   132 {
       
   133     // No source model
       
   134     VideoListDataModel *model = 0;
       
   135     mTestObject->mModel = model;
       
   136     VideoListDataModel::mMediaIdAtIndexReturnValue = TMPXItemId::InvalidId();
       
   137     VideoListDataModel::mMediaIdAtIndexCallCount = 0;
       
   138     VideoListDataModel::mRowCountReturnValue = 0;
       
   139     QVERIFY(mTestObject->callFilterAcceptsRow(0, QModelIndex()) == false);
       
   140     QCOMPARE(VideoListDataModel::mMediaIdAtIndexCallCount, 0);
       
   141     
       
   142     // Source row < 0
       
   143     model = new VideoListDataModel();
       
   144     mTestObject->mModel = model;
       
   145     VideoListDataModel::mMediaIdAtIndexReturnValue = TMPXItemId::InvalidId();
       
   146     VideoListDataModel::mMediaIdAtIndexCallCount = 0;
       
   147     VideoListDataModel::mRowCountReturnValue = 0;
       
   148     QVERIFY(mTestObject->callFilterAcceptsRow(-1, QModelIndex()) == false);
       
   149     QCOMPARE(VideoListDataModel::mMediaIdAtIndexCallCount, 0);
       
   150 
       
   151     // Source row > model row count
       
   152     VideoListDataModel::mMediaIdAtIndexReturnValue = TMPXItemId::InvalidId();
       
   153     VideoListDataModel::mMediaIdAtIndexCallCount = 0;
       
   154     VideoListDataModel::mRowCountReturnValue = 0;
       
   155     QVERIFY(mTestObject->callFilterAcceptsRow(10, QModelIndex()) == false);
       
   156     QCOMPARE(VideoListDataModel::mMediaIdAtIndexCallCount, 0);
       
   157     
       
   158     // Doesn't belong to album
       
   159     VideoListDataModel::mBelongsToAlbumReturnValue = false;
       
   160     VideoListDataModel::mMediaIdAtIndexCallCount = 0;
       
   161     VideoListDataModel::mRowCountReturnValue = 1;
       
   162     QVERIFY(mTestObject->callFilterAcceptsRow(0, QModelIndex()) == false);
       
   163     QCOMPARE(VideoListDataModel::mMediaIdAtIndexCallCount, 1);
       
   164 
       
   165     // Good case
       
   166     VideoListDataModel::mBelongsToAlbumReturnValue = true;
       
   167     VideoListDataModel::mMediaIdAtIndexCallCount = 0;
       
   168     VideoListDataModel::mRowCountReturnValue = 1;
       
   169     QVERIFY(mTestObject->callFilterAcceptsRow(0, QModelIndex()) == true);
       
   170     QCOMPARE(VideoListDataModel::mMediaIdAtIndexCallCount, 1);
       
   171 }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // testGetOpenItem
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void TestVideoProxyModelContent::testGetOpenItem()
       
   178 {
       
   179     TMPXItemId returned = TMPXItemId(1, 1);
       
   180     
       
   181     // No model
       
   182     VideoListDataModel::mAlbumInUseReturnValue = TMPXItemId(2, 2);
       
   183     VideoListDataModel *model = 0;
       
   184     mTestObject->mModel = model;
       
   185     returned = mTestObject->getOpenItem();
       
   186     QVERIFY(returned == TMPXItemId::InvalidId());
       
   187     
       
   188     // No collection client
       
   189     returned = TMPXItemId(1, 1);
       
   190     VideoListDataModel::mAlbumInUseReturnValue = TMPXItemId(2, 2);
       
   191     model = new VideoListDataModel();
       
   192     mTestObject->mModel = model;
       
   193     mTestObject->mCollectionClient = 0;
       
   194     returned = mTestObject->getOpenItem();
       
   195     QVERIFY(returned == TMPXItemId::InvalidId());
       
   196 
       
   197     // Good case.
       
   198     returned = TMPXItemId(1, 1);
       
   199     VideoListDataModel::mAlbumInUseReturnValue = TMPXItemId(2, 2); 
       
   200     mTestObject->mModel = model;
       
   201     mTestObject->mCollectionClient = 1;
       
   202     returned = mTestObject->getOpenItem();
       
   203     QVERIFY(returned == TMPXItemId(2, 2));
       
   204 }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // testAlbumChangedSlot
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void TestVideoProxyModelContent::testAlbumChangedSlot()
       
   211 {
       
   212     VideoProxyModelGeneric::mLastSortRole = -1;
       
   213     mTestObject->mWantedSortRole = 5;
       
   214     mTestObject->mWantedSortOrder = Qt::DescendingOrder;
       
   215     VideoProxyModelGeneric::mLastSortedOrder = Qt::AscendingOrder;
       
   216             
       
   217     VideoListDataModel *model = new VideoListDataModel();
       
   218     mTestObject->mModel = model;
       
   219     mTestObject->callConnectSignals();
       
   220     emit model->emitAlbumChanged();
       
   221     mTestObject->callDisconnectSignals();
       
   222     QCOMPARE(VideoProxyModelGeneric::mInvalidateFilterCallCount, 1);
       
   223     QVERIFY(VideoProxyModelGeneric::mLastSortedOrder == Qt::DescendingOrder);
       
   224     QCOMPARE(VideoProxyModelGeneric::mLastSortRole, 5);
       
   225 }
       
   226 
       
   227 // End of file