phoneapp/phoneuiqtviewadapter/tsrc/ut_phoneindicatorcontroller/unit_tests.cpp
changeset 74 d1c62c765e48
child 76 cfea66083b62
equal deleted inserted replaced
65:2a5d4ab426d3 74:d1c62c765e48
       
     1 /*!
       
     2 * Copyright (c) 2009-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 tests for PhoneIndicatorController.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 #include <QtGui>
       
    20 #include <HbGlobal>
       
    21 #include <HbMenu>
       
    22 #include <mockservice.h>
       
    23 
       
    24 #include <QByteArray>
       
    25 #include <QKeyEvent>
       
    26 #include <QSignalSpy>
       
    27 #include <HbApplication>
       
    28 #include <xqcallinfo.h>
       
    29 #include <callinformation.h>
       
    30 #include <MediatorDomainUIDs.h>
       
    31 #include <telinformationpskeys.h>
       
    32 #include <coreapplicationuisdomainpskeys.h>
       
    33 #include <ccallinfoiter.h>
       
    34 #include <keyguardaccessapi.h>
       
    35 
       
    36 #include <LogsDomainCRKeys.h>
       
    37 #include <ctsydomaincrkeys.h>
       
    38 
       
    39 #include "phonevisibilityhandler.h"
       
    40 #include "phoneuiqtviewif_stub.h"
       
    41 
       
    42 #include <logsmodel.h>
       
    43 #include "phoneindicatorcontroller.h"
       
    44 #include "phoneindicators.h"
       
    45 #include "hbindicatorstubhelper.h"
       
    46 
       
    47 
       
    48 extern bool m_logsModelCreated;
       
    49 extern bool m_serviceCreated;
       
    50 extern bool m_aiwRequestCreated;
       
    51 extern bool m_aiwRequestSended;
       
    52 extern int m_modelMaxSize;
       
    53 extern bool m_bringToForegroundCalled;
       
    54 
       
    55 #define PHONE_QT_INDICATOR_CONTROLLER_TEST_MAIN(TestObject) \
       
    56 int main(int argc, char *argv[]) \
       
    57 { \
       
    58     HbApplication app(argc, argv); \
       
    59     TestObject tc; \
       
    60     QResource::registerResource("../hbcore.rcc"); \
       
    61     int ret = QTest::qExec(&tc, argc, argv); \
       
    62     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
       
    63     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
       
    64     /* app.exec() where the signal is normally emitted is not called here. */ \
       
    65     /* So, invoking the signal explicitly. */ \
       
    66     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
       
    67     return ret; \
       
    68 }
       
    69 
       
    70 class UT_PhoneIndicatorController : public QObject, public MockService
       
    71 {
       
    72     Q_OBJECT
       
    73 public:
       
    74     UT_PhoneIndicatorController();
       
    75     virtual ~UT_PhoneIndicatorController();
       
    76     
       
    77 signals:
       
    78     void valueChanged(const XQSettingsKey &key ,const QVariant &value);
       
    79     void userActivated(QString,QVariantMap data);
       
    80     void rowsInserted(const QModelIndex &, int, int );
       
    81     
       
    82 public slots:
       
    83     void initTestCase();
       
    84     void cleanupTestCase();
       
    85     void init();
       
    86     void cleanup();
       
    87     
       
    88 private slots:
       
    89     void testIndicatorController();
       
    90     void t_setActiveCallData();
       
    91     void t_clearActiveCallData();
       
    92     void t_enableActiveCallIndicator();
       
    93     
       
    94     void t_updateMissedCallIndicator();
       
    95     void t_updateDivertIndicator();
       
    96     void t_setMissedallIndicatorData();
       
    97     void t_handleInteraction(); 
       
    98     void t_handleInteraction1(); 
       
    99     void t_handleInteraction2(); 
       
   100 
       
   101 private:
       
   102     PhoneUIQtViewIFStub *mPhoneUIQtViewIFStub;
       
   103     PhoneVisibilityHandler *m_handler;
       
   104     PhoneIndicatorController *m_phoneIndicatorController; // class under test
       
   105     HbMenu m_menu;  
       
   106 };
       
   107 
       
   108 UT_PhoneIndicatorController::UT_PhoneIndicatorController():
       
   109         m_phoneIndicatorController(NULL)
       
   110 {
       
   111 }
       
   112 
       
   113 UT_PhoneIndicatorController::~UT_PhoneIndicatorController()
       
   114 {
       
   115     delete m_phoneIndicatorController;
       
   116 }
       
   117 
       
   118 void UT_PhoneIndicatorController::initTestCase()
       
   119 {
       
   120     mPhoneUIQtViewIFStub = new PhoneUIQtViewIFStub();
       
   121     m_handler = new PhoneVisibilityHandler(*mPhoneUIQtViewIFStub, this);
       
   122     m_phoneIndicatorController = new PhoneIndicatorController(*m_handler, this);
       
   123 }
       
   124 
       
   125 void UT_PhoneIndicatorController::cleanupTestCase()
       
   126 {
       
   127     delete m_phoneIndicatorController;
       
   128     delete m_handler;
       
   129     delete mPhoneUIQtViewIFStub;
       
   130 }
       
   131 
       
   132 void UT_PhoneIndicatorController::init()
       
   133 {
       
   134 }
       
   135 
       
   136 void UT_PhoneIndicatorController::cleanup()
       
   137 {
       
   138     reset();
       
   139 }
       
   140 
       
   141 void UT_PhoneIndicatorController::testIndicatorController()
       
   142 {
       
   143     QVERIFY(m_phoneIndicatorController);
       
   144 }
       
   145 
       
   146 void UT_PhoneIndicatorController::t_setActiveCallData()
       
   147 {
       
   148     QVERIFY(m_phoneIndicatorController->m_cli.isEmpty());
       
   149     m_phoneIndicatorController->setActiveCallData();
       
   150     QVERIFY(!m_phoneIndicatorController->m_cli.isEmpty());
       
   151 }
       
   152 
       
   153 void UT_PhoneIndicatorController::t_clearActiveCallData()
       
   154 {
       
   155     m_phoneIndicatorController->clearActiveCallData();
       
   156     QVERIFY(m_phoneIndicatorController->m_cli.isEmpty());
       
   157 }
       
   158 
       
   159 void UT_PhoneIndicatorController::t_enableActiveCallIndicator()
       
   160 {   
       
   161     m_phoneIndicatorController->enableActiveCallIndicator();
       
   162     QVERIFY(!HbIndicatorStubHelper::indicatorActive());
       
   163     m_phoneIndicatorController->setActiveCallData();
       
   164     m_phoneIndicatorController->enableActiveCallIndicator();
       
   165     QVERIFY(HbIndicatorStubHelper::indicatorActive());
       
   166     m_phoneIndicatorController->disableActiveCallIndicator();
       
   167     QVERIFY(!HbIndicatorStubHelper::indicatorActive());    
       
   168 }
       
   169 
       
   170 void UT_PhoneIndicatorController::t_updateMissedCallIndicator()
       
   171 {
       
   172     QObject::connect( this, SIGNAL( valueChanged(const XQSettingsKey & ,const QVariant &)),
       
   173             m_phoneIndicatorController, SLOT(updateMissedCallIndicator(XQSettingsKey, 
       
   174                     QVariant)));
       
   175     const XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
       
   176             KCRUidLogs.iUid, 
       
   177             KLogsNewMissedCalls );
       
   178     emit valueChanged(key, QVariant(1));
       
   179     QVERIFY(m_logsModelCreated); 
       
   180     QVERIFY(m_modelMaxSize = 2);
       
   181 }
       
   182 
       
   183 void UT_PhoneIndicatorController::t_updateDivertIndicator()
       
   184 {
       
   185     QObject::connect( this, SIGNAL( valueChanged(const XQSettingsKey & ,const QVariant &)),
       
   186                 m_phoneIndicatorController, SLOT(updateDivertIndicator(XQSettingsKey, 
       
   187                         QVariant)));
       
   188     const XQSettingsKey key(XQSettingsKey::TargetCentralRepository, 
       
   189             KCRUidCtsyCallForwardingIndicator.iUid, 
       
   190             KCtsyUnconditionalCFStatus);
       
   191     int x(KCFVoiceForwarded);
       
   192     emit valueChanged( key, QVariant(x).toByteArray());
       
   193     QVERIFY(HbIndicatorStubHelper::indicatorActive());
       
   194     emit valueChanged( key, QVariant(0).toByteArray());
       
   195     QVERIFY(!HbIndicatorStubHelper::indicatorActive());
       
   196 }
       
   197 
       
   198 void UT_PhoneIndicatorController::t_setMissedallIndicatorData()
       
   199 {
       
   200     // TODO:
       
   201     QObject::connect( this, SIGNAL(rowsInserted(const QModelIndex &, int, int )),
       
   202                 this, SLOT(setMissedallIndicatorData()));  
       
   203     QModelIndex index; 
       
   204     emit(rowsInserted(index,0,0));
       
   205 }
       
   206 
       
   207 void UT_PhoneIndicatorController::t_handleInteraction()
       
   208 {
       
   209     QObject::connect(this,SIGNAL(userActivated(QString,QVariantMap)),
       
   210             m_phoneIndicatorController,SLOT(handleInteraction(QString,QVariantMap)));
       
   211     
       
   212     QVariantMap data;
       
   213     data.insert(QLatin1String("interaction"), OpenMissedCallView);
       
   214     emit userActivated(QString(),data);
       
   215     QVERIFY(m_serviceCreated);
       
   216     QVERIFY(m_aiwRequestCreated);
       
   217     QVERIFY(m_aiwRequestSended);
       
   218 }
       
   219 void UT_PhoneIndicatorController::t_handleInteraction1()
       
   220 {
       
   221     QObject::connect(this,SIGNAL(userActivated(QString,QVariantMap)),
       
   222                     m_phoneIndicatorController,SLOT(handleInteraction(QString,QVariantMap)));
       
   223     QVariantMap data;
       
   224     data.insert(QLatin1String("interaction"), OpenCallUi);
       
   225     emit userActivated(QString(),data);
       
   226     QVERIFY(m_bringToForegroundCalled);
       
   227     
       
   228 }
       
   229 void UT_PhoneIndicatorController::t_handleInteraction2()
       
   230 {
       
   231     QObject::connect(this,SIGNAL(userActivated(QString,QVariantMap)),
       
   232                 m_phoneIndicatorController,SLOT(handleInteraction(QString,QVariantMap)));
       
   233         
       
   234     QVariantMap data;
       
   235     data.insert(QLatin1String("interaction"), OpenDiverSettingsView);
       
   236     emit userActivated(QString(),data);
       
   237     QVERIFY(m_serviceCreated);
       
   238     QVERIFY(m_aiwRequestCreated);
       
   239     QVERIFY(m_aiwRequestSended);
       
   240 }
       
   241 
       
   242 PHONE_QT_INDICATOR_CONTROLLER_TEST_MAIN(UT_PhoneIndicatorController)
       
   243 #include "unit_tests.moc"
       
   244