tsrc/unittest/unittest_statehandler/unittest_statehandler.cpp
changeset 23 74c9f037fd5d
child 26 c499df2dbb33
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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: 
       
    15 *
       
    16 */
       
    17 #include "hbmainwindow.h"
       
    18 #include "hbapplication.h"
       
    19 
       
    20 #include "unittest_statehandler.h"
       
    21 #include "glxstatemanager.h"
       
    22 #include "glxbasestate.h"
       
    23 #include "glxgridstate.h"
       
    24 #include "glxfullscreenstate.h"
       
    25 #include <glxcollectionpluginall.hrh>
       
    26 #include "glxmediaid.h"
       
    27 
       
    28 int main(int argc, char *argv[])
       
    29 {
       
    30     Q_UNUSED(argc);
       
    31     HbApplication app(argc, argv);	    
       
    32 
       
    33     HbMainWindow *mMainWindow = new HbMainWindow();
       
    34     TestGlxStateManager tv;
       
    35 
       
    36     char *pass[3];
       
    37     pass[0] = argv[0];
       
    38     pass[1] = "-o";
       
    39     pass[2] = "c:\\data\\teststatehandler.txt";
       
    40 
       
    41     int res = QTest::qExec(&tv, 3, pass);
       
    42 
       
    43     return res;
       
    44 }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // initTestCase
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void TestGlxStateManager::initTestCase()
       
    51 {
       
    52     mStateManager = 0;
       
    53 }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // init
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void TestGlxStateManager::init()
       
    60 {
       
    61     mStateManager = new GlxStateManager();
       
    62     QVERIFY(mStateManager);
       
    63     QVERIFY(mStateManager->mViewManager);
       
    64     QVERIFY(mStateManager->mActionHandler);
       
    65 }
       
    66 
       
    67 void TestGlxStateManager::removeModelTestCase1()
       
    68 {
       
    69     mStateManager->createGridModel(ALBUM_ITEM_S, FORWARD_DIR);
       
    70     mStateManager->removeCurrentModel();
       
    71     QVERIFY(mStateManager->mAlbumGridMediaModel == 0 );   
       
    72 }
       
    73 
       
    74 void TestGlxStateManager::removeModelTestCase2()
       
    75 {
       
    76     mStateManager->createModel(GLX_LISTVIEW_ID);
       
    77     mStateManager->removeCurrentModel();
       
    78     QVERIFY(mStateManager->mAlbumMediaModel == 0 );    
       
    79 }
       
    80 
       
    81 
       
    82 void TestGlxStateManager::createStateTestCase()
       
    83 {
       
    84     GlxState * state = mStateManager->createState(GLX_GRIDVIEW_ID);
       
    85     QVERIFY(state);
       
    86     QCOMPARE(state->id(), GLX_GRIDVIEW_ID);
       
    87     delete state;
       
    88     state = NULL;
       
    89     
       
    90     state = mStateManager->createState(GLX_LISTVIEW_ID);
       
    91     QVERIFY(state);
       
    92     QCOMPARE(state->id(), GLX_LISTVIEW_ID);
       
    93     delete state;
       
    94     state = NULL;
       
    95     
       
    96     state = mStateManager->createState(1000);
       
    97     QVERIFY(state == 0);
       
    98 }
       
    99 
       
   100 void TestGlxStateManager::createModelTestCase1()
       
   101 {
       
   102     mStateManager->createModel(GLX_LISTVIEW_ID);
       
   103     QVERIFY(mStateManager->mAlbumMediaModel);
       
   104     mStateManager->removeCurrentModel();
       
   105 }
       
   106 
       
   107 void TestGlxStateManager::createModelTestCase2()
       
   108 {
       
   109     mStateManager->mCurrentState = mStateManager->createState(GLX_FULLSCREENVIEW_ID);
       
   110     mStateManager->mCurrentState->setState(EXTERNAL_S);
       
   111     mStateManager->createModel(GLX_FULLSCREENVIEW_ID);    
       
   112     QVERIFY(mStateManager->mAllMediaModel);
       
   113     
       
   114     mStateManager->removeCurrentModel();
       
   115     delete mStateManager->mCurrentState;
       
   116     mStateManager->mCurrentState = NULL;
       
   117 }
       
   118 
       
   119 void TestGlxStateManager::createGridModelTestCase1()
       
   120 {
       
   121     mStateManager->createGridModel(ALL_ITEM_S, NO_DIR);
       
   122     QCOMPARE(mStateManager->mCollectionId, KGlxCollectionPluginAllImplementationUid);
       
   123     QVERIFY(mStateManager->mAllMediaModel);
       
   124     mStateManager->removeCurrentModel();
       
   125 }
       
   126 
       
   127 void TestGlxStateManager::createGridModelTestCase2()
       
   128 {
       
   129     mStateManager->createGridModel(ALBUM_ITEM_S, FORWARD_DIR);
       
   130     QCOMPARE(mStateManager->mCollectionId, (int )KGlxAlbumsMediaId);
       
   131     QVERIFY(mStateManager->mAlbumGridMediaModel); 
       
   132     mStateManager->removeCurrentModel();
       
   133 }
       
   134 
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // cleanup
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void TestGlxStateManager::cleanup()
       
   141 {
       
   142     if(mStateManager)
       
   143     {
       
   144         delete mStateManager;
       
   145         mStateManager = 0;
       
   146     }  
       
   147 }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // cleanupTestCase
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void TestGlxStateManager::cleanupTestCase()
       
   154 {
       
   155 
       
   156 }