mediasettings/videosettingsplugin/tsrc/testgroup/src/testvideosettingsgroup.cpp
changeset 46 adbe7d5ba2f5
child 41 229f037ce963
equal deleted inserted replaced
28:c48470be1ba7 46:adbe7d5ba2f5
       
     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:   TestVideoSettingsGroup class implementation
       
    15 * 
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <QtTest/QtTest>
       
    20 #include <qdebug.h>
       
    21 #include <hbapplication.h>
       
    22 #include <hblineedit.h>
       
    23 #include <hbinputeditorinterface.h>
       
    24 #include <hbinputstandardfilters.h>
       
    25 #include <MPSettEngPluginImplementationUIDs.hrh>
       
    26 
       
    27 #include "testvideosettingsgroup.h"
       
    28 #include "videosettingsaccesspointentry.h"
       
    29 #include "mpsettingsmodel.h"
       
    30 #include "hbdataformmodel.h"
       
    31 #include "cpitemdatahelper.h"
       
    32 #include "hbvalidator.h"
       
    33 
       
    34 // trick to get access to protected/private members.
       
    35 #define private public
       
    36 #include "videosettingsgroup.h"
       
    37 #undef private
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // main
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 int main(int argc, char *argv[])
       
    44 {
       
    45     HbApplication app(argc, argv);
       
    46     
       
    47     TestVideoSettingsGroup tc;
       
    48     
       
    49     char *pass[3];
       
    50     pass[0] = argv[0];
       
    51     pass[1] = "-o";
       
    52     pass[2] = "c:\\data\\testvideosettingsgroup.txt";
       
    53 
       
    54     return QTest::qExec(&tc, 3, pass);
       
    55 }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // initTestCase
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void TestVideoSettingsGroup::initTestCase()
       
    62 {
       
    63     mItemHelper = new CpItemDataHelper;
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // cleanupTestCase
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void TestVideoSettingsGroup::cleanupTestCase()
       
    71 {
       
    72     delete mItemHelper;
       
    73     mItemHelper = 0;
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // init
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void TestVideoSettingsGroup::init()
       
    81 {
       
    82     CMPSettingsModel::mImplUid = TUid::Null();
       
    83     CMPSettingsModel::mConfigMode = -1;
       
    84     CMPSettingsModel::mProxyMode = 0;
       
    85     CMPSettingsModel::mHostName = QString("testhostname");
       
    86     CMPSettingsModel::mProxyPort = 4096;
       
    87     CMPSettingsModel::mMinUdpPort = 2048;
       
    88     CMPSettingsModel::mMaxUdpPort = 8080;
       
    89     CMPSettingsModel::mStoreSettingsCount = 0;
       
    90     CMPSettingsModel::mDestructorCount = 0;
       
    91     CMPSettingsModel::mApId = 5;
       
    92     HbEditorInterface::mFilter = 0;
       
    93     
       
    94     mTestObject = new VideoSettingsGroup(*mItemHelper);
       
    95 }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // cleanup
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void TestVideoSettingsGroup::cleanup()
       
   102 {
       
   103     disconnect();
       
   104     delete mTestObject;
       
   105     mTestObject = 0;
       
   106 }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // testSettingsConstruction
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void TestVideoSettingsGroup::testSettingsConstruction()
       
   113 {
       
   114     QVERIFY( mTestObject->mSettingsModel != 0 );
       
   115     QCOMPARE( mTestObject->mSettingsModel->mConfigMode, (int)EConfigUser);
       
   116     QVERIFY( CMPSettingsModel::mImplUid == TUid::Uid(KMPSettEngImplUidROP) );
       
   117     
       
   118     // verify also the itemShown connection to form here.
       
   119     QCOMPARE( mItemHelper->mFormConnection.signal, SIGNAL(itemShown(const QModelIndex)) );
       
   120     QVERIFY( mItemHelper->mFormConnection.receiver == mTestObject );
       
   121     QCOMPARE( mItemHelper->mFormConnection.method, SLOT(itemShown(const QModelIndex)) );
       
   122 }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // testAccessPointConstruction
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void TestVideoSettingsGroup::testAccessPointConstruction()
       
   129 {
       
   130     QVERIFY( mTestObject->mAccessPointItem != 0 );
       
   131     QVERIFY( mTestObject->indexOf(static_cast<HbDataFormModelItem*>(mTestObject->mAccessPointItem)) >= 0 );
       
   132     QCOMPARE( mTestObject->mAccessPointItem->mText, hbTrId("txt_videos_dblist_access_point") );
       
   133     QCOMPARE( mTestObject->mAccessPointItem->mApId, (uint)CMPSettingsModel::mApId );
       
   134 }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // testLowestUdpPortConstruction
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void TestVideoSettingsGroup::testLowestUdpPortConstruction()
       
   141 {
       
   142     QVERIFY( mTestObject->mLowestUDPPortItem != 0 );
       
   143     QVERIFY( mTestObject->indexOf(mTestObject->mLowestUDPPortItem) >= 0 );
       
   144     QCOMPARE( mTestObject->mLowestUDPPortItem->contentWidgetData(QString("maxRows")).toInt(), 1);
       
   145     QCOMPARE( mTestObject->mLowestUDPPortItem->contentWidgetData(QString("text")).toString(), 
       
   146         QString::number(CMPSettingsModel::mMinUdpPort) );
       
   147     
       
   148     ConnectionHolder connection = mItemHelper->mConnections[mTestObject->mLowestUDPPortItem];
       
   149     QCOMPARE( connection.signal, SIGNAL(editingFinished()) ); 
       
   150     QVERIFY( connection.receiver == mTestObject );
       
   151     QCOMPARE( connection.method, SLOT(lowestUdpPortEditingFinished()) );
       
   152 }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // testHighestUdpPortConstruction
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void TestVideoSettingsGroup::testHighestUdpPortConstruction()
       
   159 {
       
   160     QVERIFY( mTestObject->mHighestUDPPortItem != 0 );
       
   161     QVERIFY( mTestObject->indexOf(mTestObject->mHighestUDPPortItem) >= 0 );
       
   162     QCOMPARE( mTestObject->mHighestUDPPortItem->contentWidgetData(QString("maxRows")).toInt(), 1);
       
   163     QCOMPARE( mTestObject->mHighestUDPPortItem->contentWidgetData(QString("text")).toString(), 
       
   164         QString::number(CMPSettingsModel::mMaxUdpPort) );
       
   165     
       
   166     ConnectionHolder connection = mItemHelper->mConnections[mTestObject->mHighestUDPPortItem];
       
   167     QCOMPARE( connection.signal, SIGNAL(editingFinished()) ); 
       
   168     QVERIFY( connection.receiver == mTestObject );
       
   169     QCOMPARE( connection.method, SLOT(highestUdpPortEditingFinished()) );
       
   170 }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // testUseProxyConstruction
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void TestVideoSettingsGroup::testUseProxyConstruction()
       
   177 {
       
   178     QVERIFY( mTestObject->mUseProxyItem != 0 );
       
   179     QVERIFY( mTestObject->indexOf(mTestObject->mUseProxyItem) >= 0 );
       
   180     QCOMPARE( mTestObject->mUseProxyItem->contentWidgetData(QString("checked")).toBool(), 
       
   181         CMPSettingsModel::mProxyMode == 1 );
       
   182     
       
   183     // connection checking in the testItemShown.
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // testProxyServerConstruction
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void TestVideoSettingsGroup::testProxyServerConstruction()
       
   191 {
       
   192     QVERIFY( mTestObject->mProxyServerItem != 0 );
       
   193     QVERIFY( mTestObject->indexOf(mTestObject->mProxyServerItem) >= 0 );
       
   194     QCOMPARE( mTestObject->mProxyServerItem->contentWidgetData(QString("maxRows")).toInt(), 1);
       
   195     QCOMPARE( mTestObject->mProxyServerItem->contentWidgetData(QString("text")).toString(), 
       
   196         CMPSettingsModel::mHostName );
       
   197     QCOMPARE( mTestObject->mProxyServerItem->contentWidgetData(QString("placeholderText")).toString(),
       
   198         hbTrId("txt_videos_dblist_none") );
       
   199 
       
   200     ConnectionHolder connection = mItemHelper->mConnections[mTestObject->mProxyServerItem];
       
   201     QCOMPARE( connection.signal, SIGNAL(editingFinished()) ); 
       
   202     QVERIFY( connection.receiver == mTestObject );
       
   203     QCOMPARE( connection.method, SLOT(proxyServerEditingFinished()) );
       
   204 }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // testProxyPortConstruction
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void TestVideoSettingsGroup::testProxyPortConstruction()
       
   211 {
       
   212     QVERIFY( mTestObject->mProxyPortItem != 0 );
       
   213     QVERIFY( mTestObject->indexOf(mTestObject->mProxyPortItem) >= 0 );
       
   214     QCOMPARE( mTestObject->mProxyPortItem->contentWidgetData(QString("maxRows")).toInt(), 1);
       
   215     QCOMPARE( mTestObject->mProxyPortItem->contentWidgetData(QString("text")).toString(), 
       
   216         QString::number(CMPSettingsModel::mProxyPort) );
       
   217 
       
   218     ConnectionHolder connection = mItemHelper->mConnections[mTestObject->mProxyPortItem];
       
   219     QCOMPARE( connection.signal, SIGNAL(editingFinished()) ); 
       
   220     QVERIFY( connection.receiver == mTestObject );
       
   221     QCOMPARE( connection.method, SLOT(proxyPortEditingFinished()) );
       
   222 }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // testDestructor
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void TestVideoSettingsGroup::testDestructor()
       
   229 {
       
   230     delete mTestObject;
       
   231     mTestObject = 0;
       
   232     QCOMPARE( CMPSettingsModel::mStoreSettingsCount, 1 );
       
   233     QCOMPARE( CMPSettingsModel::mDestructorCount, 1 );
       
   234 }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // testDestructor
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void TestVideoSettingsGroup::testGetAccessPointId()
       
   241 {
       
   242     CMPSettingsModel::mApId = 4;
       
   243     
       
   244     QCOMPARE( mTestObject->getAccessPointId(), (uint)CMPSettingsModel::mApId );
       
   245 }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // testDestructor
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void TestVideoSettingsGroup::testSetAccessPointId()
       
   252 {
       
   253     CMPSettingsModel::mApId = -1;
       
   254     
       
   255     uint ap = 3;
       
   256     
       
   257     mTestObject->setAccessPointId(ap);
       
   258     
       
   259     QCOMPARE( CMPSettingsModel::mApId, (int)ap );
       
   260 }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // testLowestUdpPortEditingFinished
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void TestVideoSettingsGroup::testLowestUdpPortEditingFinished()
       
   267 {
       
   268     connect(this, SIGNAL(testTextSignal()),
       
   269         mTestObject, SLOT(lowestUdpPortEditingFinished()));
       
   270     
       
   271     QString highText("12345");
       
   272     mTestObject->mHighestUDPPortItem->setContentWidgetData(QString("text"), highText);
       
   273     
       
   274     QString testString("1234");
       
   275     mTestObject->mLowestUDPPortItem->setContentWidgetData(QString("text"), testString);
       
   276     
       
   277     emit testTextSignal();
       
   278     
       
   279     QCOMPARE( CMPSettingsModel::mMinUdpPort, testString.toInt() );
       
   280     
       
   281     CMPSettingsModel::mMinUdpPort = 0;
       
   282     mTestObject->mLowestUDPPortItem->setContentWidgetData(QString("text"), QString("12346"));
       
   283     
       
   284     emit testTextSignal();
       
   285     
       
   286     QCOMPARE( CMPSettingsModel::mMinUdpPort, highText.toInt() );
       
   287     
       
   288     CMPSettingsModel::mMinUdpPort = 0;
       
   289     testString = "12345";
       
   290     mTestObject->mLowestUDPPortItem->setContentWidgetData(QString("text"), testString);
       
   291     
       
   292     emit testTextSignal();
       
   293     
       
   294     QCOMPARE( CMPSettingsModel::mMinUdpPort, testString.toInt() );    
       
   295 }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // testHighestUdpPortEditingFinished
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void TestVideoSettingsGroup::testHighestUdpPortEditingFinished()
       
   302 {
       
   303     connect(this, SIGNAL(testTextSignal()),
       
   304         mTestObject, SLOT(highestUdpPortEditingFinished()));
       
   305     
       
   306     QString lowText("1234");
       
   307     mTestObject->mLowestUDPPortItem->setContentWidgetData(QString("text"), lowText);
       
   308     
       
   309     QString testString("12345");
       
   310     mTestObject->mHighestUDPPortItem->setContentWidgetData(QString("text"), testString);
       
   311     
       
   312     emit testTextSignal();
       
   313     
       
   314     QCOMPARE( CMPSettingsModel::mMaxUdpPort, testString.toInt() );
       
   315     
       
   316     CMPSettingsModel::mMaxUdpPort = 0;
       
   317     mTestObject->mHighestUDPPortItem->setContentWidgetData(QString("text"), QString("1233"));
       
   318     
       
   319     emit testTextSignal();
       
   320     
       
   321     QCOMPARE( CMPSettingsModel::mMaxUdpPort, lowText.toInt() );
       
   322     
       
   323     CMPSettingsModel::mMaxUdpPort = 0;
       
   324     testString = "1234";
       
   325     mTestObject->mHighestUDPPortItem->setContentWidgetData(QString("text"), testString);
       
   326     
       
   327     emit testTextSignal();
       
   328     
       
   329     QCOMPARE( CMPSettingsModel::mMaxUdpPort, testString.toInt() );
       
   330 }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // testUseProxyToggled
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void TestVideoSettingsGroup::testUseProxyToggled()
       
   337 {
       
   338     connect(this, SIGNAL(testIntSignal(int)),
       
   339         mTestObject, SLOT(useProxyToggled(int)));
       
   340     
       
   341     emit testIntSignal(Qt::Unchecked);
       
   342     
       
   343     QVERIFY( mTestObject->mProxyServerItem->isEnabled() == false );
       
   344     QVERIFY( mTestObject->mProxyPortItem->isEnabled() == false );
       
   345     QCOMPARE( CMPSettingsModel::mProxyMode, 0);
       
   346     
       
   347     emit testIntSignal(Qt::Checked);
       
   348     
       
   349     QVERIFY( mTestObject->mProxyServerItem->isEnabled() );
       
   350     QVERIFY( mTestObject->mProxyPortItem->isEnabled() );
       
   351     QCOMPARE( CMPSettingsModel::mProxyMode, 1);
       
   352 }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // testProxyServerEditingFinished
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 void TestVideoSettingsGroup::testProxyServerEditingFinished()
       
   359 {
       
   360     connect(this, SIGNAL(testTextSignal()),
       
   361         mTestObject, SLOT(proxyServerEditingFinished()));
       
   362     
       
   363     QString testString("testtesttest");
       
   364     mTestObject->mProxyServerItem->setContentWidgetData(QString("text"), testString);
       
   365     
       
   366     emit testTextSignal();
       
   367     QCOMPARE( CMPSettingsModel::mHostName, testString );
       
   368 }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // testProxyPortEditingFinished
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void TestVideoSettingsGroup::testProxyPortEditingFinished()
       
   375 {
       
   376     connect(this, SIGNAL(testTextSignal()),
       
   377         mTestObject, SLOT(proxyPortEditingFinished()));
       
   378     
       
   379     QString testString("1234");
       
   380     mTestObject->mProxyPortItem->setContentWidgetData(QString("text"), testString);
       
   381     
       
   382     emit testTextSignal();
       
   383     QCOMPARE( CMPSettingsModel::mProxyPort, testString.toInt() );
       
   384 }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // testItemShown
       
   388 // ---------------------------------------------------------------------------
       
   389 //
       
   390 void TestVideoSettingsGroup::testItemShown()
       
   391 {
       
   392     connect(this, SIGNAL(testShownSignal(const QModelIndex&)), 
       
   393         mTestObject, SLOT(itemShown(const QModelIndex&)));
       
   394     
       
   395     QModelIndex index;
       
   396     
       
   397     HbLineEdit* editor = new HbLineEdit();
       
   398     mItemHelper->mWidgetReturnValue = editor;
       
   399     
       
   400     QIntValidator* val;
       
   401     
       
   402     mItemHelper->mModelItemReturnValue = mTestObject->mLowestUDPPortItem;
       
   403     HbEditorInterface::mFilter = 0;
       
   404     emit testShownSignal(index);
       
   405     QVERIFY( HbEditorInterface::mFilter == HbDigitsOnlyFilter::instance() );
       
   406     QCOMPARE( editor->mValidator->mValidators.count(), 1 );
       
   407     val = static_cast<QIntValidator*>(editor->mValidator->mValidators.at(0));
       
   408     QCOMPARE( val->bottom(), 1024 );
       
   409     QCOMPARE( val->top(), 65535 );
       
   410 
       
   411     mItemHelper->mModelItemReturnValue = mTestObject->mProxyPortItem;
       
   412     HbEditorInterface::mFilter = 0;
       
   413     emit testShownSignal(index);
       
   414     QVERIFY( HbEditorInterface::mFilter == HbDigitsOnlyFilter::instance() );
       
   415     QCOMPARE( editor->mValidator->mValidators.count(), 1 );
       
   416     val = static_cast<QIntValidator*>(editor->mValidator->mValidators.at(0));
       
   417     QCOMPARE( val->bottom(), 1 );
       
   418     QCOMPARE( val->top(), 65535 );
       
   419     
       
   420     mItemHelper->mModelItemReturnValue = mTestObject->mHighestUDPPortItem;
       
   421     HbEditorInterface::mFilter = 0;
       
   422     emit testShownSignal(index);
       
   423     QVERIFY( HbEditorInterface::mFilter == HbDigitsOnlyFilter::instance() );
       
   424     QCOMPARE( editor->mValidator->mValidators.count(), 1 );
       
   425     val = static_cast<QIntValidator*>(editor->mValidator->mValidators.at(0));
       
   426     QCOMPARE( val->bottom(), 1024 );
       
   427     QCOMPARE( val->top(), 65535 );
       
   428     
       
   429     mItemHelper->mModelItemReturnValue = mTestObject->mProxyServerItem;
       
   430     HbEditorInterface::mFilter = 0;
       
   431     emit testShownSignal(index);
       
   432     QVERIFY( HbEditorInterface::mFilter == HbUrlFilter::instance() );
       
   433     
       
   434     // verify the use proxy connection:
       
   435     ConnectionHolder connection = mItemHelper->mConnections[mTestObject->mUseProxyItem];
       
   436     QCOMPARE( connection.signal, SIGNAL(stateChanged(int)) ); 
       
   437     QVERIFY( connection.receiver == mTestObject );
       
   438     QCOMPARE( connection.method, SLOT(useProxyToggled(int)) );
       
   439     
       
   440     delete editor;
       
   441 }
       
   442 
       
   443 // end of file