phoneapp/phoneuiqtviewadapter/tsrc/ut_phonecommandextensionwrapper/unit_tests.cpp
changeset 36 2eacb6118286
parent 30 ebdbd102c78a
child 37 ba76fc04e6c2
equal deleted inserted replaced
30:ebdbd102c78a 36:2eacb6118286
     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 tests for PhoneCommandExtensionWrapper.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 #include <QtGui>
       
    20 #include <QList>
       
    21 #include <QMap>
       
    22 #include <hbapplication.h>
       
    23 #include <phoneappcommands.hrh>
       
    24 #include "phonecommandextensionwrapper.h"
       
    25 #include "pevirtualengine.h"
       
    26 #include "menuextension_stub.h"
       
    27 
       
    28 extern bool m_modifyMenuCommandListCalled;
       
    29 extern bool m_modifyPushButtonCommandListCalled;
       
    30 extern bool m_addMenuActionsCalled;
       
    31 extern bool m_releaseMenuCalled;
       
    32 extern bool m_releaseCalled;
       
    33 extern bool m_useExtensionStub;
       
    34 
       
    35 #define PHONE_QT_VIEW_ADAPTER_TEST_MAIN(TestObject) \
       
    36 int main(int argc, char *argv[]) \
       
    37     { \
       
    38         HbApplication app(argc, argv); \
       
    39         TestObject tc; \
       
    40         QResource::registerResource("../hbcore.rcc"); \
       
    41         int ret = QTest::qExec(&tc, argc, argv); \
       
    42         /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
       
    43         /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
       
    44         /* app.exec() where the signal is normally emitted is not called here. */ \
       
    45         /* So, invoking the signal explicitly. */ \
       
    46         QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
       
    47         return ret; \
       
    48     }
       
    49 
       
    50 
       
    51 class TestPhoneCommandExtensionWrapper : public QObject
       
    52 {
       
    53     Q_OBJECT
       
    54 public:
       
    55     TestPhoneCommandExtensionWrapper();
       
    56     virtual ~TestPhoneCommandExtensionWrapper();
       
    57 
       
    58 public slots:
       
    59     void initTestCase ();
       
    60     void cleanupTestCase ();
       
    61     void init ();
       
    62     void cleanup ();
       
    63     
       
    64 private slots:
       
    65     void testNullPlugin();
       
    66     void testPlugin();
       
    67     void testGetCallInfo();
       
    68 
       
    69 private:
       
    70     PhoneCommandExtensionWrapper *m_wrapper; // class under test
       
    71 
       
    72 };
       
    73 
       
    74 TestPhoneCommandExtensionWrapper::TestPhoneCommandExtensionWrapper()
       
    75 {
       
    76 }
       
    77 
       
    78 TestPhoneCommandExtensionWrapper::~TestPhoneCommandExtensionWrapper()
       
    79 {
       
    80 }
       
    81 
       
    82 void TestPhoneCommandExtensionWrapper::initTestCase()
       
    83 {
       
    84     
       
    85 }
       
    86 
       
    87 void TestPhoneCommandExtensionWrapper::cleanupTestCase()
       
    88 {
       
    89     
       
    90 }
       
    91 
       
    92 void TestPhoneCommandExtensionWrapper::init()
       
    93 {
       
    94 
       
    95 }
       
    96 
       
    97 void TestPhoneCommandExtensionWrapper::cleanup()
       
    98 {
       
    99 }
       
   100 
       
   101 
       
   102 
       
   103 void TestPhoneCommandExtensionWrapper::testNullPlugin()
       
   104 {
       
   105     QList<XQTelUiCommandExtension::CallInfo> callInfo; 
       
   106     QList<int> menuCmdList;
       
   107     QList<HbAction*> menuActions;
       
   108     m_useExtensionStub = false;
       
   109     m_wrapper = new PhoneCommandExtensionWrapper(123456);
       
   110     
       
   111     m_wrapper->modifyMenuCommandList(callInfo, menuCmdList);
       
   112     QVERIFY( false == m_modifyMenuCommandListCalled );
       
   113     
       
   114     m_wrapper->modifyPushButtonCommandList(callInfo, menuCmdList);
       
   115     QVERIFY( false == m_modifyPushButtonCommandListCalled );
       
   116     
       
   117     m_wrapper->addMenuActions(callInfo, menuActions);
       
   118     QVERIFY( false == m_addMenuActionsCalled );
       
   119     
       
   120     m_wrapper->releaseMenu();
       
   121     QVERIFY( false == m_releaseMenuCalled );
       
   122     
       
   123     delete m_wrapper;
       
   124     
       
   125     QVERIFY( false == m_releaseCalled );
       
   126 }
       
   127 
       
   128 void TestPhoneCommandExtensionWrapper::testPlugin()
       
   129 {
       
   130     QList<XQTelUiCommandExtension::CallInfo> callInfo; 
       
   131     QList<int> menuCmdList;
       
   132     QList<HbAction*> menuActions;
       
   133     m_useExtensionStub = true;
       
   134     m_wrapper = new PhoneCommandExtensionWrapper(123456);
       
   135     
       
   136     QVERIFY( 123456 == m_wrapper->pluginUid() );
       
   137     
       
   138     m_wrapper->modifyMenuCommandList(callInfo, menuCmdList);
       
   139     QVERIFY( m_modifyMenuCommandListCalled );
       
   140     
       
   141     m_wrapper->modifyPushButtonCommandList(callInfo, menuCmdList);
       
   142     QVERIFY( m_modifyPushButtonCommandListCalled );
       
   143     
       
   144     m_wrapper->addMenuActions(callInfo, menuActions);
       
   145     QVERIFY( m_addMenuActionsCalled );
       
   146     
       
   147     m_wrapper->releaseMenu();
       
   148     QVERIFY( m_releaseMenuCalled );
       
   149     
       
   150     delete m_wrapper;
       
   151 
       
   152     QVERIFY( m_releaseCalled );
       
   153 }
       
   154 
       
   155 void TestPhoneCommandExtensionWrapper::testGetCallInfo()
       
   156 {
       
   157     m_wrapper = new PhoneCommandExtensionWrapper(123456);
       
   158     QList<XQTelUiCommandExtension::CallInfo> callInfo; 
       
   159     QMap<int,int> callStates;
       
   160     QMap<int,int> serviceIds;
       
   161     int expandedCall(0);
       
   162     
       
   163     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   164     QCOMPARE(0, callInfo.count());
       
   165     
       
   166     callStates[0] = EPEStateDisconnecting; 
       
   167     serviceIds[0] = 3;   
       
   168     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   169     QCOMPARE(1, callInfo.count());
       
   170     QVERIFY(XQTelUiCommandExtension::Disconnecting == callInfo.at(0).mCallState);
       
   171     QVERIFY(true == callInfo.at(0).mIsExpanded);
       
   172     QVERIFY(3 == callInfo.at(0).mServiceId);
       
   173     
       
   174     callInfo.clear();
       
   175     callStates[0] = EPEStateRinging;    
       
   176     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   177     QCOMPARE(1, callInfo.count());
       
   178     QVERIFY(XQTelUiCommandExtension::Incoming == callInfo.at(0).mCallState);
       
   179     
       
   180     callInfo.clear();
       
   181     callStates[0] = EPEStateDialing;    
       
   182     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   183     QCOMPARE(1, callInfo.count());
       
   184     QVERIFY(XQTelUiCommandExtension::Outgoing == callInfo.at(0).mCallState);
       
   185     
       
   186     callInfo.clear();
       
   187     callStates[0] = EPEStateConnecting;    
       
   188     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   189     QCOMPARE(1, callInfo.count());
       
   190     QVERIFY(XQTelUiCommandExtension::Outgoing == callInfo.at(0).mCallState);
       
   191     
       
   192     callInfo.clear();
       
   193     callStates[0] = EPEStateConnected;    
       
   194     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   195     QCOMPARE(1, callInfo.count());
       
   196     QVERIFY(XQTelUiCommandExtension::Active == callInfo.at(0).mCallState);
       
   197     
       
   198     callInfo.clear();
       
   199     callStates[0] = EPEStateConnectedConference;    
       
   200     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   201     QCOMPARE(1, callInfo.count());
       
   202     QVERIFY(XQTelUiCommandExtension::Active == callInfo.at(0).mCallState);
       
   203     
       
   204     callInfo.clear();
       
   205     callStates[0] = EPEStateHeld;    
       
   206     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   207     QCOMPARE(1, callInfo.count());
       
   208     QVERIFY(XQTelUiCommandExtension::OnHold == callInfo.at(0).mCallState);
       
   209     
       
   210     callInfo.clear();
       
   211     callStates[0] = EPEStateHeldConference;    
       
   212     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   213     QCOMPARE(1, callInfo.count());
       
   214     QVERIFY(XQTelUiCommandExtension::OnHold == callInfo.at(0).mCallState);
       
   215     
       
   216     callInfo.clear();
       
   217     callStates[0] = EPEStateUnknown;    
       
   218     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   219     QCOMPARE(1, callInfo.count());
       
   220     QVERIFY(XQTelUiCommandExtension::None == callInfo.at(0).mCallState);
       
   221     
       
   222     callInfo.clear();
       
   223     callStates[0] = EPEStateIdle;    
       
   224     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   225     QCOMPARE(1, callInfo.count());
       
   226     QVERIFY(XQTelUiCommandExtension::None == callInfo.at(0).mCallState);
       
   227     
       
   228     callInfo.clear();
       
   229     callStates[0] = EPEStateConferenceIdle;    
       
   230     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   231     QCOMPARE(1, callInfo.count());
       
   232     QVERIFY(XQTelUiCommandExtension::None == callInfo.at(0).mCallState);
       
   233     
       
   234     callInfo.clear();
       
   235     callStates[0] = EPEStateMaximumState;    
       
   236     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   237     QCOMPARE(1, callInfo.count());
       
   238     QVERIFY(XQTelUiCommandExtension::None == callInfo.at(0).mCallState);
       
   239     
       
   240     //////////////////////////////////////////////////////////////////////////
       
   241     // Two calls
       
   242     //////////////////////////////////////////////////////////////////////////
       
   243     callInfo.clear();
       
   244     callStates[0] = EPEStateConnected;
       
   245     callStates[1] = EPEStateHeld;
       
   246     serviceIds[1] = 2;
       
   247     m_wrapper->getCallInfoList(callInfo, callStates, serviceIds, expandedCall);
       
   248     QCOMPARE(2, callInfo.count());
       
   249     QVERIFY(XQTelUiCommandExtension::Active == callInfo.at(0).mCallState);
       
   250     QVERIFY(true == callInfo.at(0).mIsExpanded);
       
   251     QVERIFY(3 == callInfo.at(0).mServiceId);
       
   252     QVERIFY(XQTelUiCommandExtension::OnHold == callInfo.at(1).mCallState);
       
   253     QVERIFY(false == callInfo.at(1).mIsExpanded);
       
   254     QVERIFY(2 == callInfo.at(1).mServiceId);
       
   255     
       
   256     delete m_wrapper;
       
   257 }
       
   258 
       
   259 
       
   260 PHONE_QT_VIEW_ADAPTER_TEST_MAIN(TestPhoneCommandExtensionWrapper)
       
   261 #include "unit_tests.moc"