mpviewplugins/mpsettingsviewplugin/tsrc/unittest_mpsettingsaudioeffectswidget/src/unittest_mpsettingsaudioeffectswidget.cpp
changeset 45 612c4815aebe
child 47 4cc1412daed0
equal deleted inserted replaced
43:0f32e550d9d8 45:612c4815aebe
       
     1 /*
       
     2 * Copyright (c) 2010 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 mpsettingsaudioeffectswidget
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QMetaType>
       
    19 #include <QtGui>
       
    20 #include <QTranslator>
       
    21 #include <QLocale>
       
    22 
       
    23 #include "unittest_mpsettingsaudioeffectswidget.h"
       
    24 #include "mpenginefactory.h"
       
    25 #include "mpengine.h"
       
    26 
       
    27 // Do this so we can access all member variables.
       
    28 #define private public
       
    29 #include "MpSettingsAudioEffectsWidget.h"
       
    30 #undef private
       
    31 
       
    32 //This so we can test private functions
       
    33 //#include "../../src/mpsettingsaudioeffectswidget.cpp"
       
    34 
       
    35 
       
    36 
       
    37 /*!
       
    38  Make our test case a stand-alone executable that runs all the test functions.
       
    39  */
       
    40 int main(int argc, char *argv[])
       
    41 {
       
    42     QApplication app(argc, argv);
       
    43     TestMpSettingsAudioEffectsWidget tv;
       
    44 
       
    45     if ( argc > 1 ) {
       
    46         return QTest::qExec( &tv, argc, argv);
       
    47     }
       
    48     else {
       
    49         char *pass[3];
       
    50         pass[0] = argv[0];
       
    51         pass[1] = "-o";
       
    52         pass[2] = "c:\\data\\unittest_mpsettingsaudioeffectswidget.txt";
       
    53 
       
    54         return QTest::qExec(&tv, 3, pass);
       
    55     }
       
    56 }
       
    57 
       
    58 TestMpSettingsAudioEffectsWidget::TestMpSettingsAudioEffectsWidget()
       
    59     : mTest(0),
       
    60       mMpTranslator(0)
       
    61 {
       
    62 }
       
    63 
       
    64 TestMpSettingsAudioEffectsWidget::~TestMpSettingsAudioEffectsWidget()
       
    65 {
       
    66     delete mTest;
       
    67     delete mMpTranslator;
       
    68 }
       
    69 
       
    70 /*!
       
    71  Called before the first testfunction is executed.
       
    72  */
       
    73 void TestMpSettingsAudioEffectsWidget::initTestCase()
       
    74 {
       
    75     QString lang = QLocale::system().name();
       
    76     QString path = QString("z:/resource/qt/translations/");
       
    77     bool translatorLoaded = false;
       
    78 
       
    79     mMpTranslator = new QTranslator(this);
       
    80     translatorLoaded = mMpTranslator->load(path + "musicplayer_" + lang);
       
    81     if ( translatorLoaded ) {
       
    82         qApp->installTranslator(mMpTranslator);
       
    83     }
       
    84 }   
       
    85 
       
    86 /*!
       
    87  Called after the last testfunction was executed.
       
    88  */
       
    89 void TestMpSettingsAudioEffectsWidget::cleanupTestCase()
       
    90 {
       
    91 }
       
    92 
       
    93 /*!
       
    94  Called before each testfunction is executed.
       
    95  */
       
    96 void TestMpSettingsAudioEffectsWidget::init()
       
    97 {
       
    98     MpEngineFactory::createSharedEngine();
       
    99     mTest = new MpSettingsAudioEffectsWidget();
       
   100 }
       
   101 
       
   102 /*!
       
   103  Called after every testfunction.
       
   104  */
       
   105 void TestMpSettingsAudioEffectsWidget::cleanup()
       
   106 {
       
   107     delete mTest;
       
   108     mTest = 0;
       
   109     MpEngineFactory::close();
       
   110 }
       
   111 
       
   112 /*!
       
   113  Tests constructor.
       
   114  */
       
   115 void TestMpSettingsAudioEffectsWidget::testInitializeSlider()
       
   116 {
       
   117     mTest->initialize();
       
   118     QVERIFY(mTest->mMpEngine != 0 );
       
   119 
       
   120     MpEngineFactory::sharedEngine()->setLoudness( false );
       
   121 
       
   122     QCOMPARE(mTest->mModel->rowCount(),2 );
       
   123     QCOMPARE(mTest->mModel->columnCount(),1 );
       
   124 
       
   125 
       
   126     QCOMPARE(  mTest->mModel->item( 0 )->type(), HbDataFormModelItem::SliderItem );
       
   127     QCOMPARE(  mTest->mModel->item( 1 )->type(), HbDataFormModelItem::ToggleValueItem );
       
   128 
       
   129     //slider
       
   130     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("minimum"), QVariant(-100) );
       
   131     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("maximum"), QVariant(100) );
       
   132     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("majorTickInterval"), QVariant(100) );
       
   133     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("minorTickInterval"), QVariant(25) );
       
   134     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("singleStep"), QVariant(25) );
       
   135     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("toolTipVisible"), QVariant(false) );   
       
   136     int position = Hb::SliderTicksRight;
       
   137     QCOMPARE((mTest->mModel->item( 0 )->contentWidgetData("tickPosition")).toInt(), position);
       
   138     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("sliderPosition"), QVariant(mTest->mMpEngine->balance()) ); //this needs to be checked
       
   139     QCOMPARE(  mTest->mModel->item( 0 )->contentWidgetData("trackFilled"), QVariant(false) );
       
   140 
       
   141 }
       
   142 
       
   143 void TestMpSettingsAudioEffectsWidget::testInitializeLoudnessOff()
       
   144 {
       
   145     MpEngineFactory::sharedEngine()->setLoudness( false );
       
   146     mTest->initialize();
       
   147     QVERIFY(  mTest->mModel->item( 1 )->type() == HbDataFormModelItem::ToggleValueItem );
       
   148     QCOMPARE(  mTest->mModel->item( 1 )->contentWidgetData("text"), QVariant(hbTrId( "txt_mus_setlabel_loudness_val_off" )) );
       
   149     QCOMPARE(  mTest->mModel->item( 1 )->contentWidgetData("additionalText"), QVariant(hbTrId( "txt_mus_setlabel_loudness_val_on" )) );
       
   150 }
       
   151 
       
   152 void TestMpSettingsAudioEffectsWidget::testInitializeLoudnessOn()
       
   153 {
       
   154     MpEngineFactory::sharedEngine()->setLoudness( true );
       
   155     mTest->initialize();
       
   156     QVERIFY(  mTest->mModel->item( 1 )->type() == HbDataFormModelItem::ToggleValueItem );
       
   157     QCOMPARE(  mTest->mModel->item( 1 )->contentWidgetData("text"), QVariant(hbTrId( "txt_mus_setlabel_loudness_val_on" )) );
       
   158     QCOMPARE(  mTest->mModel->item( 1 )->contentWidgetData("additionalText"), QVariant(hbTrId( "txt_mus_setlabel_loudness_val_off" )) );
       
   159 
       
   160 }
       
   161 
       
   162 
       
   163 void TestMpSettingsAudioEffectsWidget::testFilterSignals()
       
   164 {
       
   165     MpEngineFactory::sharedEngine()->setLoudness( false );
       
   166     mTest->initialize();
       
   167     QCOMPARE(MpEngineFactory::sharedEngine()->loudness(), false);
       
   168     QModelIndex index1 = mTest->mModel->indexFromItem((mTest->mModel->item(1)));
       
   169     mTest->filterSignals(index1,index1);
       
   170     QCOMPARE(MpEngineFactory::sharedEngine()->loudness(), true);
       
   171 }
       
   172 
       
   173 
       
   174 
       
   175 // End of file