mpviewplugins/mpsettingsviewplugin/tsrc/unittest_mpsettingsview/src/unittest_mpsettingsview.cpp
changeset 47 4cc1412daed0
equal deleted inserted replaced
45:612c4815aebe 47:4cc1412daed0
       
     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 mpsettingsview.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbmainwindow.h>
       
    19 #include <hbapplication.h>
       
    20 #include <QSignalSpy>
       
    21 
       
    22 #include "unittest_mpsettingsview.h"
       
    23 
       
    24 // Do this so we can access all member variables.
       
    25 #define private public
       
    26 #include "mpsettingsview.h"
       
    27 #undef private
       
    28 
       
    29 /*!
       
    30  Make our test case a stand-alone executable that runs all the test functions.
       
    31  */
       
    32 int main(int argc, char *argv[])
       
    33 {
       
    34     HbApplication app(argc, argv);
       
    35     HbMainWindow window;
       
    36 
       
    37     TestMpSettingsView tv;
       
    38 
       
    39 if ( argc > 1 ) {
       
    40         return QTest::qExec( &tv, argc, argv);
       
    41     }
       
    42     else {
       
    43         char *pass[3];
       
    44         pass[0] = argv[0];
       
    45         pass[1] = "-o";
       
    46         pass[2] = "c:\\data\\unittest_mpsettingsview.txt";
       
    47 
       
    48         return QTest::qExec(&tv, 3, pass);
       
    49     }
       
    50 }
       
    51 
       
    52 //Constructor
       
    53 TestMpSettingsView::TestMpSettingsView()
       
    54     : mTest(0)
       
    55 {
       
    56 
       
    57 }
       
    58 
       
    59 //Destructor
       
    60 TestMpSettingsView::~TestMpSettingsView()
       
    61 {
       
    62     delete mTest;
       
    63 }
       
    64 
       
    65 /*!
       
    66  Called before the first testfunction is executed.
       
    67  */
       
    68 void TestMpSettingsView::initTestCase()
       
    69 {
       
    70 
       
    71 }
       
    72 
       
    73 /*!
       
    74  Called after the last testfunction was executed.
       
    75  */
       
    76 void TestMpSettingsView::cleanupTestCase()
       
    77 {
       
    78 QCoreApplication::processEvents();
       
    79 }
       
    80 
       
    81 /*!
       
    82  Called before each testfunction is executed.
       
    83  */
       
    84 void TestMpSettingsView::init()
       
    85 {
       
    86     mTest = new MpSettingsView();
       
    87 }
       
    88 
       
    89 /*!
       
    90  Called after every testfunction.
       
    91  */
       
    92 void TestMpSettingsView::cleanup()
       
    93 {
       
    94     delete mTest;
       
    95     mTest = 0;
       
    96 }
       
    97 
       
    98 /*!
       
    99  Called before each testfunction is executed.
       
   100  */
       
   101 void TestMpSettingsView::testInitializeView()
       
   102 {
       
   103     //test widget initialization
       
   104     QVERIFY(mTest->mAudioEffectsWidget == 0);
       
   105     QVERIFY(mTest->mSoftKeyBack == 0);
       
   106     QVERIFY(mTest->mWindow == 0);
       
   107 
       
   108     mTest->initializeView();
       
   109     QVERIFY(mTest->mAudioEffectsWidget != 0);
       
   110     QVERIFY(mTest->mSoftKeyBack != 0);
       
   111 
       
   112 }
       
   113 
       
   114 /*!
       
   115  Test ActivateView
       
   116 */
       
   117 void TestMpSettingsView::testActivateView()
       
   118 {
       
   119     //test navigation action is set
       
   120     mTest->initializeView();    
       
   121     mTest->activateView();
       
   122     QCOMPARE(mTest->navigationAction(), mTest->mSoftKeyBack );
       
   123 
       
   124 }
       
   125 
       
   126 /*!
       
   127 test DecativateView
       
   128  */
       
   129 void TestMpSettingsView::testDeactivateView()
       
   130 {
       
   131     //test navigation action is set to 0
       
   132     mTest->initializeView();
       
   133     mTest->activateView();
       
   134     mTest->deactivateView();    
       
   135     QVERIFY(mTest->navigationAction()== 0 );
       
   136     mTest->deactivateView();
       
   137 
       
   138 
       
   139 }
       
   140 /*!
       
   141 test Back()
       
   142  */
       
   143 void TestMpSettingsView::testBack()
       
   144 {
       
   145     QSignalSpy spy(mTest, SIGNAL(command(int)));
       
   146     mTest->back();
       
   147     QCOMPARE(spy.count(), 1);
       
   148 
       
   149 }
       
   150