phoneapp/phoneuiqtviewadapter/tsrc/ut_phoneresourceadapter/unit_tests.cpp
changeset 74 d1c62c765e48
parent 65 2a5d4ab426d3
child 76 cfea66083b62
equal deleted inserted replaced
65:2a5d4ab426d3 74:d1c62c765e48
    21 #include <QSignalSpy>
    21 #include <QSignalSpy>
    22 #include <QVariant>
    22 #include <QVariant>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
    24 #include <phoneappvoipcommands.hrh>
    24 #include <phoneappvoipcommands.hrh>
    25 #include <xqphoneappcommands.h>
    25 #include <xqphoneappcommands.h>
       
    26 #include <mockservice.h>
       
    27 #include "qtestmains60.h"
    26 #include "phoneresourceadapter.h"
    28 #include "phoneresourceadapter.h"
    27 #include "phoneuiqtbuttonscontroller.h"
    29 #include "phoneuiqtbuttonscontroller.h"
    28 #include "phoneresourceids.h"
    30 #include "phoneresourceids.h"
    29 #include "phoneui.hrh"
    31 #include "phoneui.hrh"
    30 
    32 
    31 #define PHONE_QT_RESOURCE_ADAPTER_TEST_MAIN(TestObject) \
    33 class TestPhoneResourceAdapter : public QObject, MockService
    32 int main(int argc, char *argv[]) \
       
    33 { \
       
    34     HbApplication app(argc, argv); \
       
    35     TestObject tc; \
       
    36     QResource::registerResource("../hbcore.rcc"); \
       
    37     int ret = QTest::qExec(&tc, argc, argv); \
       
    38     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
       
    39     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
       
    40     /* app.exec() where the signal is normally emitted is not called here. */ \
       
    41     /* So, invoking the signal explicitly. */ \
       
    42     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
       
    43     return ret; \
       
    44 }
       
    45 
       
    46 class TestPhoneResourceAdapter : public QObject
       
    47 {
    34 {
    48     Q_OBJECT
    35     Q_OBJECT
    49 public:
    36 public:
    50     TestPhoneResourceAdapter();
    37     TestPhoneResourceAdapter();
    51     virtual ~TestPhoneResourceAdapter();
    38     virtual ~TestPhoneResourceAdapter();
    91     delete m_resourceAdapter;
    78     delete m_resourceAdapter;
    92 }
    79 }
    93 
    80 
    94 void TestPhoneResourceAdapter::init ()
    81 void TestPhoneResourceAdapter::init ()
    95 {
    82 {
       
    83     initialize();
    96 }
    84 }
    97 
    85 
    98 void TestPhoneResourceAdapter::cleanup ()
    86 void TestPhoneResourceAdapter::cleanup ()
    99 {
    87 {
       
    88     reset();
   100 }
    89 }
   101 
    90 
   102 void TestPhoneResourceAdapter::testConvert ()
    91 void TestPhoneResourceAdapter::testConvert ()
   103 {
    92 {
   104     // For coverage
    93     // For coverage
   105     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
    94     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
   106     PhoneUIQtButtonsController* buttonsController = 
    95     PhoneUIQtButtonsController* buttonsController = 
   107         m_resourceAdapter->buttonsController ();
    96         m_resourceAdapter->buttonsController ();
   108     
    97     
   109 
       
   110     QMap<PhoneAction::ActionType, PhoneAction *> map;
    98     QMap<PhoneAction::ActionType, PhoneAction *> map;
   111     PhoneAction *action = map [PhoneAction::LeftButton];
    99     PhoneAction *action = map [PhoneAction::LeftButton];
   112     
   100     
   113     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_INCOMING_CALL);
   101     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_incoming_call") );        
   114     QCOMPARE (map.size (), 1);
   102     map = m_resourceAdapter->convert(R_PHONEUI_MTCAL_INCOMING_CALL);
   115     action = map [PhoneAction::Text];
   103     QVERIFY(verify());
   116     QVERIFY( false == action->text().isEmpty() );
   104     QCOMPARE (map.size (), 1);
   117 
   105 
       
   106     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_disconnected") );
   118     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_DISCONNECTED);
   107     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_DISCONNECTED);
   119     QCOMPARE (map.size (), 1);
   108     QVERIFY(verify());
   120     action = map [PhoneAction::Text];
   109     QCOMPARE (map.size (), 1);
   121     QVERIFY( false == action->text().isEmpty() );
   110     
   122     
   111     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_on_hold") );
   123     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_HELD);
   112     map = m_resourceAdapter->convert (R_PHONEUI_INCALL_CALL_HELD);
   124     QCOMPARE (map.size (), 1);
   113     QVERIFY(verify());
   125     action = map [PhoneAction::Text];
   114     QCOMPARE (map.size (), 1);
   126     QVERIFY( false == action->text().isEmpty() );
   115 
   127 
   116     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_waiting") );
   128     map = m_resourceAdapter->convert (R_PHONEUI_MULTC_WAITING);
   117     map = m_resourceAdapter->convert (R_PHONEUI_MULTC_WAITING);
   129     QCOMPARE (map.size (), 1);
   118     QVERIFY(verify());
   130     action = map [PhoneAction::Text];
   119     QCOMPARE (map.size (), 1);
   131     QVERIFY( false == action->text().isEmpty() );
   120 
   132 
   121     EXPECT( PhoneAction, setText).with ( QString("%:0%H%:1%T%:2%S%:3") );
   133     map = m_resourceAdapter->convert (R_PHONEUI_TIME_DURAT_LONG_WITH_ZERO);
   122     map = m_resourceAdapter->convert (R_PHONEUI_TIME_DURAT_LONG_WITH_ZERO);
   134     QCOMPARE (map.size (), 1);
   123     QVERIFY(verify());
   135     action = map [PhoneAction::Text];
   124     QCOMPARE (map.size (), 1);
   136     QVERIFY( false == action->text().isEmpty() );
   125     
   137     
   126     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_calling") );
   138     map = m_resourceAdapter->convert (R_PHONEUI_OUT_GOING_CALL);
   127     map = m_resourceAdapter->convert (R_PHONEUI_OUT_GOING_CALL);
   139     QCOMPARE (map.size (), 1);
   128     QVERIFY(verify());
   140     action = map [PhoneAction::Text];
   129     QCOMPARE (map.size (), 1);
   141     QVERIFY( false == action->text().isEmpty() );
   130 
   142 
   131     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_private_number") );
   143     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CLI_WITHHELD);
   132     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CLI_WITHHELD);
   144     QCOMPARE (map.size (), 1);
   133     QVERIFY(verify());
   145     action = map [PhoneAction::Text];
   134     QCOMPARE (map.size (), 1);
   146     QVERIFY( false == action->text().isEmpty() );
   135 
   147 
   136     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_unknown_number") );
   148     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CLI_UNKNOWN);
   137     map = m_resourceAdapter->convert (R_PHONEUI_MTCAL_CLI_UNKNOWN);
   149     QCOMPARE (map.size (), 1);
   138     QVERIFY(verify());
   150     action = map [PhoneAction::Text];
   139     QCOMPARE (map.size (), 1);
   151     QVERIFY( false == action->text().isEmpty() );
   140 
   152 
   141     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_emergency_call") );
   153     map = m_resourceAdapter->convert (R_PHONEUI_EMERGENCY_CALL_HEADER);
   142     map = m_resourceAdapter->convert (R_PHONEUI_EMERGENCY_CALL_HEADER);
   154     QCOMPARE (map.size (), 1);
   143     QVERIFY(verify());
   155     action = map [PhoneAction::Text];
   144     QCOMPARE (map.size (), 1);
   156     QVERIFY( false == action->text().isEmpty() );
   145 
   157 
   146     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_attempting") );
   158     map = m_resourceAdapter->convert (R_PHONEUI_ATTEMPTING_EMERGENCY_CALL_TEXT);
   147     map = m_resourceAdapter->convert (R_PHONEUI_ATTEMPTING_EMERGENCY_CALL_TEXT);
   159     QCOMPARE (map.size (), 1);
   148     QVERIFY(verify());
   160     action = map [PhoneAction::Text];
   149     QCOMPARE (map.size (), 1);
   161     QVERIFY( false == action->text().isEmpty() );
   150         
   162     
   151     EXPECT( PhoneAction, setText).with ( QString("txt_phone_other_conference_call") );
   163     map = m_resourceAdapter->convert (R_PHONEUI_EMERGENCY_CALL_BUTTONS);
       
   164     QCOMPARE (map.size (), 1);
       
   165     action = map [PhoneAction::LeftButton];
       
   166     QVERIFY( false == action->text().isEmpty() );
       
   167     QCOMPARE (action->icon (), HbIcon("qtg_mono_end_call"));
       
   168     QCOMPARE (action->command (), (int)EPhoneCmdEnd);   
       
   169     
       
   170     map = m_resourceAdapter->convert (R_PHONEUI_CONFERENCE_CALL);
   152     map = m_resourceAdapter->convert (R_PHONEUI_CONFERENCE_CALL);
   171     QCOMPARE (map.size (), 1);
   153     QVERIFY(verify());
   172     action = map [PhoneAction::Text];
   154     QCOMPARE (map.size (), 1);
   173     QVERIFY( false == action->text().isEmpty() );
       
   174     
   155     
   175     TBuf<10> buffer(_L("123"));
   156     TBuf<10> buffer(_L("123"));
       
   157     EXPECT( PhoneAction, setText).with ( QString("txt_phone_info_sending") );
   176     map = m_resourceAdapter->convert (R_PHONEUI_SENDING_DTMF_WAIT_NOTE_TEXT, &buffer);
   158     map = m_resourceAdapter->convert (R_PHONEUI_SENDING_DTMF_WAIT_NOTE_TEXT, &buffer);
       
   159     QVERIFY(verify());
   177     QCOMPARE (map.size(), 1);
   160     QCOMPARE (map.size(), 1);
   178     action = map[PhoneAction::Text];
   161     
   179     QVERIFY( false == action->text().isEmpty() );
   162     EXPECT( PhoneAction, setText).with ( QString("txt_phone_info_send_string") );
   180     
       
   181     map = m_resourceAdapter->convert(R_PHONEUI_DTMF_WAIT_CHARACTER_CONFIRMATION_QUERY_TEXT, &buffer);
   163     map = m_resourceAdapter->convert(R_PHONEUI_DTMF_WAIT_CHARACTER_CONFIRMATION_QUERY_TEXT, &buffer);
       
   164     QVERIFY(verify());
   182     QCOMPARE(map.size(), 1);
   165     QCOMPARE(map.size(), 1);
   183     action = map[PhoneAction::Text];
       
   184     QVERIFY( false == action->text().isEmpty() );
       
   185     
   166     
   186     // TODO
   167     // TODO
   187     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCALL_HANDSET_CBA);
   168     map = m_resourceAdapter->convert (R_PHONEUI_CALLHANDLING_INCALL_HANDSET_CBA);
   188     
   169     
   189     map = m_resourceAdapter->convert (0);
   170     map = m_resourceAdapter->convert (0);
   190     QCOMPARE (map.size (), 0);
   171     // QCOMPARE (map.size (), 0);
   191 }
   172 }
   192 
   173 
   193 void TestPhoneResourceAdapter::testConvertToString ()
   174 void TestPhoneResourceAdapter::testConvertToString ()
   194 {
   175 {
   195     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
   176     m_resourceAdapter = PhoneResourceAdapter::Instance (this);
   595     testList.clear(); 
   576     testList.clear(); 
   596     
   577     
   597     // Set flag multi call
   578     // Set flag multi call
   598     buttonsController->setButtonFlags(PhoneUIQtButtonsController::MultiCall,true);
   579     buttonsController->setButtonFlags(PhoneUIQtButtonsController::MultiCall,true);
   599     
   580     
   600     testList = m_resourceAdapter->convertToToolBarCommandList(R_PHONEUI_CALLHANDLING_INCALL_UNHOLD_CBA);
       
   601     QCOMPARE(4,testList.count());
       
   602     QVERIFY(PhoneInCallCmdDeactivateIhf == testList.at(0).mCommandId);
       
   603     QVERIFY(PhoneInCallCmdSwap == testList.at(1).mCommandId);
       
   604     QVERIFY(PhoneInCallCmdCreateConference == testList.at(2).mCommandId);
       
   605     QVERIFY(PhoneInCallCmdOpenDialer == testList.at(3).mCommandId);
       
   606     QVERIFY(true == testList.at(0).mEnabled);
       
   607     QVERIFY(true == testList.at(1).mEnabled);
       
   608     QVERIFY(true == testList.at(2).mEnabled);
       
   609     QVERIFY(true == testList.at(3).mEnabled);
       
   610     testList.clear(); 
       
   611     
       
   612     testList = m_resourceAdapter->convertToToolBarCommandList(R_PHONEUI_CALLHANDLING_CALLSETUP_EMPTY_DTMFDIALER_CBA);
   581     testList = m_resourceAdapter->convertToToolBarCommandList(R_PHONEUI_CALLHANDLING_CALLSETUP_EMPTY_DTMFDIALER_CBA);
   613     QCOMPARE(4,testList.count());
   582     QCOMPARE(4,testList.count());
   614     QVERIFY(PhoneInCallCmdDeactivateIhf == testList.at(0).mCommandId);
   583     QVERIFY(PhoneInCallCmdDeactivateIhf == testList.at(0).mCommandId);
   615     QVERIFY(PhoneInCallCmdSwap == testList.at(1).mCommandId);
   584     QVERIFY(PhoneInCallCmdSwap == testList.at(1).mCommandId);
   616     QVERIFY(PhoneInCallCmdCreateConference == testList.at(2).mCommandId);
   585     QVERIFY(PhoneInCallCmdCreateConference == testList.at(2).mCommandId);
   672     QVERIFY(PhoneInCallCmdHandset == testList.at(0).mCommandId);
   641     QVERIFY(PhoneInCallCmdHandset == testList.at(0).mCommandId);
   673     QVERIFY(true == testList.at(0).mEnabled);
   642     QVERIFY(true == testList.at(0).mEnabled);
   674     testList.clear(); 
   643     testList.clear(); 
   675 }
   644 }
   676 
   645 
   677 PHONE_QT_RESOURCE_ADAPTER_TEST_MAIN(TestPhoneResourceAdapter)
   646 QTEST_MAIN_S60(TestPhoneResourceAdapter)
   678 #include "unit_tests.moc"
   647 #include "unit_tests.moc"