phoneapp/phoneuiqtviewadapter/tsrc/ut_phoneresourceadapter/unit_tests.cpp
changeset 37 ba76fc04e6c2
child 45 6b911d05207e
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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 PhoneResourceAdapter.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 #include <QtGui>
       
    20 #include <hbapplication.h>
       
    21 #include <QSignalSpy>
       
    22 #include <QVariant>
       
    23 #include <hbaction.h>
       
    24 //#include <hbglobal_p.h>
       
    25 #include <phoneappvoipcommands.hrh>
       
    26 #include "phoneresourceadapter.h"
       
    27 #include "phoneresourceids.h"
       
    28 #include "phoneui.hrh"
       
    29 
       
    30 #define PHONE_QT_RESOURCE_ADAPTER_TEST_MAIN(TestObject) \
       
    31 int main(int argc, char *argv[]) \
       
    32 { \
       
    33     HbApplication app(argc, argv); \
       
    34     TestObject tc; \
       
    35     QResource::registerResource("../hbcore.rcc"); \
       
    36     int ret = QTest::qExec(&tc, argc, argv); \
       
    37     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
       
    38     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
       
    39     /* app.exec() where the signal is normally emitted is not called here. */ \
       
    40     /* So, invoking the signal explicitly. */ \
       
    41     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
       
    42     return ret; \
       
    43 }
       
    44 
       
    45 class TestPhoneResourceAdapter : public QObject
       
    46 {
       
    47     Q_OBJECT
       
    48 public:
       
    49     TestPhoneResourceAdapter();
       
    50     virtual ~TestPhoneResourceAdapter();
       
    51 
       
    52 public slots:
       
    53     void initTestCase ();
       
    54     void cleanupTestCase ();
       
    55     void init ();
       
    56     void cleanup (); 
       
    57     
       
    58 private slots:
       
    59     void testConvert ();
       
    60     void testConvertToString ();
       
    61     void testConvertToString2 ();
       
    62     void testDefaultToolbarResourceId();
       
    63     void testConvertCommandToString();
       
    64     void testConvertToHbActions();
       
    65 
       
    66 private:
       
    67     void testIncallToolbar (int id); // helper function
       
    68     
       
    69 private:
       
    70     PhoneResourceAdapter *m_resourceAdapter; // class under test
       
    71 };
       
    72 
       
    73 TestPhoneResourceAdapter::TestPhoneResourceAdapter ()
       
    74 {
       
    75 }
       
    76 
       
    77 TestPhoneResourceAdapter::~TestPhoneResourceAdapter ()
       
    78 {
       
    79 }
       
    80 
       
    81 void TestPhoneResourceAdapter::initTestCase ()
       
    82 {
       
    83     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
    84 }
       
    85 
       
    86 void TestPhoneResourceAdapter::cleanupTestCase ()
       
    87 {
       
    88     delete m_resourceAdapter;
       
    89 }
       
    90 
       
    91 void TestPhoneResourceAdapter::init ()
       
    92 {
       
    93 }
       
    94 
       
    95 void TestPhoneResourceAdapter::cleanup ()
       
    96 {
       
    97 }
       
    98 
       
    99 void TestPhoneResourceAdapter::testConvert ()
       
   100 {
       
   101     // For coverage
       
   102     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
   103     PhoneUIQtButtonsController* buttonsController = 
       
   104         m_resourceAdapter->buttonsController ();
       
   105     
       
   106 
       
   107     QMap<PhoneAction::ActionType, PhoneAction *> map;
       
   108     PhoneAction *action = map [PhoneAction::LeftButton];
       
   109 
       
   110     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCOMINGCALL_CBA);
       
   111     QCOMPARE (map.size (), 2);
       
   112     action = map [PhoneAction::ToolbarButton1];
       
   113     QCOMPARE (action->icon (), HbIcon("qtg_mono_send"));    
       
   114     action = map [PhoneAction::ToolbarButton2];
       
   115     QCOMPARE (action->icon (), HbIcon("qtg_mono_speaker_off"));
       
   116     QCOMPARE (action->command (), (int)EPhoneCallComingCmdSilent);    
       
   117     
       
   118     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCOMINGCALL_REJECT_CBA);
       
   119     QCOMPARE (map.size (), 2);
       
   120     action = map [PhoneAction::ToolbarButton1];
       
   121     QCOMPARE (action->icon (), HbIcon("qtg_mono_send"));    
       
   122     action = map [PhoneAction::ToolbarButton2];
       
   123     QCOMPARE (action->icon (), HbIcon("qtg_mono_reject_call"));
       
   124     //Command is disabled
       
   125     //QCOMPARE (action->command (), (int)EPhoneCallComingCmdReject);    
       
   126      
       
   127     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCOMINGCALL_SOFT_REJECT_CBA);
       
   128     QCOMPARE (map.size (), 2);
       
   129     action = map [PhoneAction::ToolbarButton1];
       
   130     QCOMPARE (action->icon (), HbIcon("qtg_mono_send"));    
       
   131     action = map [PhoneAction::ToolbarButton2];
       
   132     QCOMPARE (action->icon (), HbIcon("qtg_mono_speaker_off"));
       
   133     //Command is disabled
       
   134     //QCOMPARE (action->command (), (int)EPhoneCallComingCmdReject); 
       
   135 
       
   136     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_CALLWAITING_CBA);
       
   137     QCOMPARE (map.size (), 2);
       
   138     action = map [PhoneAction::ToolbarButton1];
       
   139     QCOMPARE (action->icon (), HbIcon("qtg_mono_send"));    
       
   140     action = map [PhoneAction::ToolbarButton2];
       
   141     QCOMPARE (action->icon (), HbIcon("qtg_mono_join_call"));
       
   142     QCOMPARE (action->command (), (int)EPhoneInCallCmdJoin);    
       
   143     
       
   144     testIncallToolbar( R_PHONEUI_DIALER_CBA );
       
   145     testIncallToolbar( R_PHONEUI_INCALL_DIALER_CBA );
       
   146     testIncallToolbar( R_PHONEUI_CALLHANDLING_CALLSETUP_EMPTY_DTMFDIALER_CBA );
       
   147     testIncallToolbar( R_PHONEUI_CALLHANDLING_INCALL_UNHOLD_CBA );
       
   148     testIncallToolbar( R_PHONEUI_CALLHANDLING_INCALL_UNMUTE_CBA );
       
   149     
       
   150     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_INCOMING_CALL);
       
   151     QCOMPARE (map.size (), 1);
       
   152     action = map [PhoneAction::Text];
       
   153     QVERIFY( false == action->text().isEmpty() );
       
   154 
       
   155     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_DISCONNECTED);
       
   156     QCOMPARE (map.size (), 1);
       
   157     action = map [PhoneAction::Text];
       
   158     QVERIFY( false == action->text().isEmpty() );
       
   159     
       
   160     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_HELD);
       
   161     QCOMPARE (map.size (), 1);
       
   162     action = map [PhoneAction::Text];
       
   163     QVERIFY( false == action->text().isEmpty() );
       
   164 
       
   165     map = m_resourceAdapter->convert (R_PHONEUI_MULTC_WAITING);
       
   166     QCOMPARE (map.size (), 1);
       
   167     action = map [PhoneAction::Text];
       
   168     QVERIFY( false == action->text().isEmpty() );
       
   169 
       
   170     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_NUMBER, 3);
       
   171     QCOMPARE (map.size (), 1);
       
   172     action = map [PhoneAction::Text];
       
   173     QVERIFY( false == action->text().isEmpty() );
       
   174     
       
   175     map = m_resourceAdapter->convert (R_PHONEUI_TIME_DURAT_LONG_WITH_ZERO);
       
   176     QCOMPARE (map.size (), 1);
       
   177     action = map [PhoneAction::Text];
       
   178     QVERIFY( false == action->text().isEmpty() );
       
   179     
       
   180     map = m_resourceAdapter->convert (R_PHONEUI_OUT_GOING_CALL);
       
   181     QCOMPARE (map.size (), 1);
       
   182     action = map [PhoneAction::Text];
       
   183     QVERIFY( false == action->text().isEmpty() );
       
   184 
       
   185     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CLI_WITHHELD);
       
   186     QCOMPARE (map.size (), 1);
       
   187     action = map [PhoneAction::Text];
       
   188     QVERIFY( false == action->text().isEmpty() );
       
   189     
       
   190     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CALL);
       
   191     QCOMPARE (map.size (), 1);
       
   192     action = map [PhoneAction::Text];
       
   193     QVERIFY( false == action->text().isEmpty() );
       
   194     
       
   195     map = m_resourceAdapter->convert (R_PHONEUI_EMERGENCY_CALL_HEADER);
       
   196     QCOMPARE (map.size (), 1);
       
   197     action = map [PhoneAction::Text];
       
   198     QVERIFY( false == action->text().isEmpty() );
       
   199 
       
   200     map = m_resourceAdapter->convert (R_PHONEUI_ATTEMPTING_EMERGENCY_CALL_TEXT);
       
   201     QCOMPARE (map.size (), 1);
       
   202     action = map [PhoneAction::Text];
       
   203     QVERIFY( false == action->text().isEmpty() );
       
   204     
       
   205     map = m_resourceAdapter->convert (R_PHONEUI_EMERGENCY_CALL_BUTTONS);
       
   206     QCOMPARE (map.size (), 1);
       
   207     action = map [PhoneAction::LeftButton];
       
   208     QVERIFY( false == action->text().isEmpty() );
       
   209     QCOMPARE (action->icon (), HbIcon("qtg_mono_end_call"));
       
   210     QCOMPARE (action->command (), (int)EPhoneCmdEnd);
       
   211     
       
   212     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_EMERGENCY_CBA);
       
   213     QCOMPARE (map.size (), 2);
       
   214     action = map [PhoneAction::ToolbarButton1];
       
   215     QCOMPARE (action->icon (), HbIcon("qtg_mono_dialer"));
       
   216     action = map [PhoneAction::ToolbarButton2];
       
   217     QCOMPARE (action->icon (), HbIcon("qtg_mono_speaker"));
       
   218     QCOMPARE (action->command (), (int)EPhoneInCallCmdActivateIhf);        
       
   219     
       
   220     map = m_resourceAdapter->convert (R_PHONEUI_CONFERENCE_CALL);
       
   221     QCOMPARE (map.size (), 1);
       
   222     action = map [PhoneAction::Text];
       
   223     QVERIFY( false == action->text().isEmpty() );
       
   224     
       
   225     TBuf<10> buffer(_L("123"));
       
   226     map = m_resourceAdapter->convert (R_PHONEUI_SENDING_DTMF_WAIT_NOTE_TEXT, &buffer);
       
   227     QCOMPARE (map.size(), 1);
       
   228     action = map[PhoneAction::Text];
       
   229     QVERIFY( false == action->text().isEmpty() );
       
   230     
       
   231     map = m_resourceAdapter->convert(R_PHONEUI_DTMF_WAIT_CHARACTER_CONFIRMATION_QUERY_TEXT, &buffer);
       
   232     QCOMPARE(map.size(), 1);
       
   233     action = map[PhoneAction::Text];
       
   234     QVERIFY( false == action->text().isEmpty() );
       
   235     
       
   236     map = m_resourceAdapter->convert(R_PHONE_IMEI_STRING, &buffer);
       
   237     QCOMPARE(map.size(), 1);
       
   238     action = map[PhoneAction::Text];
       
   239     QVERIFY( false == action->text().isEmpty() );
       
   240 
       
   241     map = m_resourceAdapter->convert(R_PHONEUI_LIFE_TIMER_STRING, &buffer);
       
   242     QCOMPARE(map.size(), 1);
       
   243     action = map[PhoneAction::Text];
       
   244     QVERIFY( false == action->text().isEmpty() );
       
   245     
       
   246     // TODO
       
   247     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCALL_HANDSET_CBA);
       
   248     
       
   249     map = m_resourceAdapter->convert (0);
       
   250     QCOMPARE (map.size (), 0);
       
   251 }
       
   252 
       
   253 void TestPhoneResourceAdapter::testConvertToString ()
       
   254 {
       
   255     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
   256         
       
   257     QString testString = m_resourceAdapter->convertToString(R_PHONE_ERROR_CALL_NOT_ALLOWED); 
       
   258     QVERIFY( false == testString.isEmpty() );
       
   259     
       
   260     QString testString2 = m_resourceAdapter->convertToString(R_ERROR_NOTE_NOT_ALLOWED); 
       
   261     QVERIFY( false == testString2.isEmpty() );
       
   262     
       
   263     QString testString3 = m_resourceAdapter->convertToString(R_NOTETEXT_INVALID_PHONENUMBER); 
       
   264     QVERIFY( false == testString3.isEmpty() );
       
   265     
       
   266     QString testString4 = m_resourceAdapter->convertToString(R_NOTETEXT_NO_ANSWER); 
       
   267     QVERIFY( false == testString4.isEmpty() );
       
   268     
       
   269     QString testString5 = m_resourceAdapter->convertToString(R_PHONE_ERROR_NUMBER_BUSY); 
       
   270     QVERIFY( false == testString5.isEmpty() );
       
   271     
       
   272     QString testString6 = m_resourceAdapter->convertToString(R_PHONE_SS_NOTIFICATION_MOCAL_WAITING_TEXT); 
       
   273     QVERIFY( false == testString6.isEmpty() );
       
   274     
       
   275     QString testString7 = m_resourceAdapter->convertToString(R_PHONE_SS_NOTIFICATION_INCAL_INFO_HOLD_TEXT); 
       
   276     QVERIFY( false == testString7.isEmpty() );
       
   277     
       
   278     QString testString8 = m_resourceAdapter->convertToString(R_INCAL_INFO_HOLD_TEXT); 
       
   279     QVERIFY( false == testString8.isEmpty() );
       
   280     
       
   281     QString testString9 = m_resourceAdapter->convertToString(R_INCAL_REMOTE_ACTIVE_TEXT); 
       
   282     QVERIFY( false == testString9.isEmpty() );
       
   283     
       
   284     QString testString10 = m_resourceAdapter->convertToString(R_INCAL_INFO_CONF_HOLD_TEXT); 
       
   285     QVERIFY( false == testString10.isEmpty() );
       
   286     
       
   287     QString testString11 = m_resourceAdapter->convertToString(R_PHONE_INCALL_INFO_NO_NETWORK_SUPPORT); 
       
   288     QVERIFY( false == testString11.isEmpty() );
       
   289     
       
   290     QString testString12 = m_resourceAdapter->convertToString(R_PHONE_ERROR_EMERGENCY_CALLS_ONLY); 
       
   291     QVERIFY( false == testString12.isEmpty() );
       
   292     
       
   293     QString testString13 = m_resourceAdapter->convertToString(R_NOTETEXT_NUMBER_NOT_IN_USE); 
       
   294     QVERIFY( false == testString13.isEmpty() );
       
   295     
       
   296     QString testString14 = m_resourceAdapter->convertToString(R_NOTETEXT_NETWORK_BUSY); 
       
   297     QVERIFY( false == testString14.isEmpty() );
       
   298     
       
   299     QString testString15 = m_resourceAdapter->convertToString(R_NOTETEXT_ERROR_IN_CONNECTION); 
       
   300     QVERIFY( false == testString15.isEmpty() );
       
   301     
       
   302     QString testString16 = m_resourceAdapter->convertToString(R_PHONEUI_ERROR_EMERGENCY_ATTEMPT_FAILED); 
       
   303     QVERIFY( false == testString16.isEmpty() );   
       
   304     
       
   305     QString testString17 = m_resourceAdapter->convertToString(R_PHONE_SS_NOTIFICATION_INCAL_TRANSFERRED_TEXT); 
       
   306     QVERIFY( false == testString17.isEmpty() );    
       
   307  
       
   308     QString testString18 = m_resourceAdapter->convertToString(R_PHONE_ERROR_NO_SERVICE); 
       
   309     QVERIFY( false == testString18.isEmpty() ); 
       
   310     
       
   311     QString testString99 = m_resourceAdapter->convertToString(0); 
       
   312     QCOMPARE( testString99, QString ("") );
       
   313 }
       
   314 
       
   315 void TestPhoneResourceAdapter::testConvertToString2 ()
       
   316 {
       
   317     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
   318         
       
   319     QString testString = m_resourceAdapter->convertToString(
       
   320             R_PHONE_TEXT_COLP_CONNECTED, QString("123456"));
       
   321     
       
   322     QVERIFY( false == testString.isEmpty() );
       
   323        
       
   324     QString testString2 = m_resourceAdapter->convertToString(0, QString()); 
       
   325     QCOMPARE( testString2, QString ("") );
       
   326 }
       
   327 
       
   328 void TestPhoneResourceAdapter::testIncallToolbar (int id)
       
   329 {
       
   330     QMap<PhoneAction::ActionType, PhoneAction *> map;
       
   331     PhoneAction *action;
       
   332     map = m_resourceAdapter->convert (id);
       
   333     QCOMPARE (map.size (), 4);
       
   334     
       
   335     switch(id) {
       
   336     case R_PHONEUI_CALLHANDLING_INCALL_UNMUTE_CBA:
       
   337         action = map [PhoneAction::ToolbarButton1];
       
   338         QCOMPARE (action->icon (), HbIcon("qtg_mono_dialer"));
       
   339         action = map [PhoneAction::ToolbarButton2];
       
   340         QCOMPARE (action->icon (), HbIcon("qtg_mono_mic_unmute"));
       
   341         QCOMPARE (action->command (), (int)EPhoneInCallCmdUnmute);    
       
   342         action = map [PhoneAction::ToolbarButton3];
       
   343         QCOMPARE (action->icon (), HbIcon("qtg_mono_speaker"));
       
   344         QCOMPARE (action->command (), (int)EPhoneInCallCmdActivateIhf);        
       
   345         break;
       
   346     default:    
       
   347         action = map [PhoneAction::ToolbarButton1];
       
   348         QCOMPARE (action->icon (), HbIcon("qtg_mono_dialer"));
       
   349         action = map [PhoneAction::ToolbarButton2];
       
   350         QCOMPARE (action->icon (), HbIcon("qtg_mono_mic_mute"));
       
   351         QCOMPARE (action->command (), (int)EPhoneInCallCmdMute);    
       
   352         action = map [PhoneAction::ToolbarButton3];
       
   353         QCOMPARE (action->icon (), HbIcon("qtg_mono_speaker"));
       
   354         QCOMPARE (action->command (), (int)EPhoneInCallCmdActivateIhf);
       
   355         break;
       
   356     }
       
   357 }
       
   358 
       
   359 void TestPhoneResourceAdapter::testDefaultToolbarResourceId()
       
   360 {
       
   361     QVERIFY(m_resourceAdapter->defaultToolbarResourceId()==
       
   362             R_PHONEUI_CALLHANDLING_INCOMINGCALL_CBA);
       
   363 }
       
   364 
       
   365 void TestPhoneResourceAdapter::testConvertCommandToString ()
       
   366 {
       
   367     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
   368     
       
   369     QString testString = m_resourceAdapter->convertCommandToString(
       
   370             EPhoneInCallCmdEndAllCalls);    
       
   371     QVERIFY( false == testString.isEmpty() );
       
   372     
       
   373     testString = m_resourceAdapter->convertCommandToString(
       
   374             EPhoneInCallCmdTransfer);    
       
   375     QVERIFY( false == testString.isEmpty() );
       
   376     
       
   377     testString = m_resourceAdapter->convertCommandToString(
       
   378             EPhoneInCallCmdSwitchToVideo);    
       
   379     QVERIFY( false == testString.isEmpty() );
       
   380     
       
   381     testString = m_resourceAdapter->convertCommandToString(
       
   382             EPhoneCmdHandoverToWlan);    
       
   383     QVERIFY( false == testString.isEmpty() );
       
   384     
       
   385     testString = m_resourceAdapter->convertCommandToString(
       
   386             EPhoneCmdHandoverToGsm);    
       
   387     QVERIFY( false == testString.isEmpty() );
       
   388     
       
   389     testString = m_resourceAdapter->convertCommandToString(0); 
       
   390     QCOMPARE( testString, QString ("") );
       
   391 }
       
   392 
       
   393 void TestPhoneResourceAdapter::testConvertToHbActions()
       
   394 {
       
   395     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
       
   396     
       
   397     QList<HbAction*> testList = m_resourceAdapter->convertToHbActions(R_PHONEUI_DTMF_WAIT_CHARACTER_CONFIRMATION_QUERY);    
       
   398     QCOMPARE( testList.count(), 2 );
       
   399     QCOMPARE( (int)EPhoneInCallCmdContinueSendingDtmfString, 
       
   400               testList.at(0)->data().toInt());
       
   401     QCOMPARE( (int)EPhoneInCallCmdCancelSendingDtmfString, 
       
   402               testList.at(1)->data().toInt());
       
   403     qDeleteAll(testList);
       
   404     testList.clear();
       
   405     
       
   406     testList = m_resourceAdapter->convertToHbActions(R_PHONEUI_SENDING_DTMF_WAIT_NOTE);    
       
   407     QCOMPARE( testList.count(), 1 );
       
   408     QCOMPARE( (int)EPhoneInCallCmdCancelSendingDtmfString, 
       
   409               testList.at(0)->data().toInt());
       
   410     qDeleteAll(testList);
       
   411     testList.clear();
       
   412     
       
   413     testList = m_resourceAdapter->convertToHbActions(0);    
       
   414     QCOMPARE( testList.count(), 0 );
       
   415 }
       
   416 
       
   417 PHONE_QT_RESOURCE_ADAPTER_TEST_MAIN(TestPhoneResourceAdapter)
       
   418 #include "unit_tests.moc"