mpengine/tsrc/unittest_mpmpxisolatedcollectionhelper/src/unittest_mpmpxisolatedcollectionhelper.cpp
changeset 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
       
     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: Unit test for CMpMpxIsolatedCollectionHelper
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbapplication.h>
       
    19 #include <hbmainwindow.h>
       
    20 
       
    21 #include <mpxmedia.h>
       
    22 #include <mpxcollectionplaylist.h>
       
    23 #include <mpxcollectionpath.h>
       
    24 
       
    25 #include "unittest_mpmpxisolatedcollectionhelper.h"
       
    26 
       
    27 
       
    28 //This so we can test private functions
       
    29 #include "../../src/mpmpxisolatedcollectionhelper.cpp"
       
    30 
       
    31 
       
    32 /*!
       
    33  Make our test case a stand-alone executable that runs all the test functions.
       
    34  */
       
    35 int main(int argc, char *argv[])
       
    36 {
       
    37     HbApplication app(argc, argv);
       
    38     HbMainWindow window;
       
    39 
       
    40     TestCMpMpxIsolatedCollectionHelper tv;
       
    41 
       
    42     char *pass[3];
       
    43     pass[0] = argv[0];
       
    44     pass[1] = "-o";
       
    45     pass[2] = "c:\\data\\unittest_mpmpxisolatedcollectionhelper.txt";
       
    46 
       
    47     int res = QTest::qExec(&tv, 3, pass);
       
    48 
       
    49     return res;
       
    50 }
       
    51 
       
    52 TestCMpMpxIsolatedCollectionHelper::TestCMpMpxIsolatedCollectionHelper()
       
    53     : mTest( 0 ),
       
    54       iEntriesFromoOpenCallback ( 0 ),
       
    55       iErrorFromoOpenCallback( KErrNone ),
       
    56       iOpenCallbackCounter( 0 )
       
    57 {
       
    58 }
       
    59 
       
    60 TestCMpMpxIsolatedCollectionHelper::~TestCMpMpxIsolatedCollectionHelper()
       
    61 {
       
    62     delete mTest;
       
    63 }
       
    64 
       
    65 /*!
       
    66  Called before the first testfunction is executed.
       
    67  */
       
    68 void TestCMpMpxIsolatedCollectionHelper::initTestCase()
       
    69 {
       
    70 }
       
    71 
       
    72 /*!
       
    73  Called after the last testfunction was executed.
       
    74  */
       
    75 void TestCMpMpxIsolatedCollectionHelper::cleanupTestCase()
       
    76 {
       
    77 }
       
    78 
       
    79 /*!
       
    80  Called before each testfunction is executed.
       
    81  */
       
    82 void TestCMpMpxIsolatedCollectionHelper::init()
       
    83 {
       
    84     mTest = CMpMpxIsolatedCollectionHelper::NewL( this );
       
    85 }
       
    86 
       
    87 /*!
       
    88  Called after every testfunction.
       
    89  */
       
    90 void TestCMpMpxIsolatedCollectionHelper::cleanup()
       
    91 {
       
    92     delete mTest;
       
    93     mTest = 0;
       
    94 }
       
    95 
       
    96 /*!
       
    97  Tests constructor.
       
    98 */
       
    99 void TestCMpMpxIsolatedCollectionHelper::testConstructor()
       
   100 {
       
   101     QVERIFY(mTest->iIncrementalOpenUtil != 0);
       
   102     QCOMPARE(mTest->iIncrementalOpenUtil->iMode , KMcModeIsolated);
       
   103     QCOMPARE(mTest->iObserver , dynamic_cast<MMpMpxIsolatedCollectionHelperObserver*>(this));
       
   104 }
       
   105 
       
   106 /*!
       
   107  Tests OpenCollection.
       
   108  */
       
   109 void TestCMpMpxIsolatedCollectionHelper::testOpenCollection()
       
   110 {
       
   111     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   112     mTest->OpenCollectionL(*path);
       
   113     QCOMPARE(mTest->iIncrementalOpenUtil->iDelay, KIncrementalDelayHalfSecond);
       
   114     QCOMPARE(mTest->iIncrementalOpenUtil->iStop,TBool(ETrue));
       
   115     QCOMPARE(mTest->iIncrementalOpenUtil->iStart,TBool(ETrue));
       
   116     QCOMPARE(mTest->iFirstIncrementalOpen,TBool(ETrue));
       
   117     QCOMPARE(mTest->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchNormal);
       
   118     QCOMPARE(mTest->iIncrementalOpenUtil->iChunkSize, KIncrementalFetchBlockSize);
       
   119     QCOMPARE((int)mTest->iIncrementalOpenUtil->iPath, (int)path);
       
   120     delete path;
       
   121 }
       
   122 
       
   123 /*!
       
   124  Tests HandleOpen.
       
   125  */
       
   126 void TestCMpMpxIsolatedCollectionHelper::testHandleOpen()
       
   127 {
       
   128      iEntriesFromoOpenCallback = 0;
       
   129      iErrorFromoOpenCallback = KErrArgument;
       
   130      iOpenCallbackCounter = 0;
       
   131      CMPXMedia *media = CMPXMedia::NewL();
       
   132      mTest->iFirstIncrementalOpen = ETrue;
       
   133      mTest->HandleOpenL(*media, 0, false, KErrNone);
       
   134      QCOMPARE((int)iEntriesFromoOpenCallback,(int)media);
       
   135      QCOMPARE(iErrorFromoOpenCallback,KErrNone);
       
   136      QCOMPARE(iOpenCallbackCounter,1);
       
   137 }
       
   138  
       
   139 /*!
       
   140  Used to keep track of the callback from teh isolated collection helper.
       
   141  */
       
   142 void TestCMpMpxIsolatedCollectionHelper::HandleIsolatedOpenL( const CMPXMedia& aEntries, TInt aError )
       
   143 {
       
   144      iEntriesFromoOpenCallback = &aEntries;
       
   145      iErrorFromoOpenCallback = aError;
       
   146      iOpenCallbackCounter++;
       
   147 }
       
   148 
       
   149 //end of file