phoneapp/phoneuiqtviewadapter/tsrc/ut_phonenotecontroller/unit_tests.cpp
changeset 21 92ab7f8d0eab
child 30 ebdbd102c78a
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     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 PhoneNoteController.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 #include <QtGui>
       
    20 #include <hbapplication.h>
       
    21 #include <QSignalSpy>
       
    22 //#include <hbglobal_p.h>
       
    23 #include "phonenotecontroller.h"
       
    24 #include "phoneresourceids.h"
       
    25 #include "phoneui.hrh"
       
    26 #include "tphonecmdparamglobalnote.h"
       
    27 #include "tphonecmdparamquery.h"
       
    28 #include "phoneresourceadapter.h"
       
    29 
       
    30 #define PHONE_QT_NOTE_CONTROLLER_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 TestPhoneNoteController : public QObject
       
    46 {
       
    47     Q_OBJECT
       
    48 public:
       
    49     TestPhoneNoteController();
       
    50     virtual ~TestPhoneNoteController();
       
    51 
       
    52 public slots:
       
    53     void initTestCase ();
       
    54     void cleanupTestCase ();
       
    55     void init ();
       
    56     void cleanup (); 
       
    57     
       
    58 private slots:
       
    59     void testShowGlobalNoteDefault ();
       
    60     void testShowGlobalInfoNoteWithResourceId ();
       
    61     void testShowGlobalWarningNoteWithText ();
       
    62     void testShowGlobalNoteWithTextAndResourceId ();
       
    63     void testShowGlobalNoteTwoTimes ();
       
    64     void testShowGlobalNoteThreeTimes ();
       
    65     void testShowNote();
       
    66     void testShowQuery();
       
    67     void testShowClobalWaitNote();
       
    68 
       
    69     
       
    70 private:
       
    71     PhoneNoteController *m_noteController; // class under test
       
    72 };
       
    73 
       
    74 TestPhoneNoteController::TestPhoneNoteController ()
       
    75 {
       
    76 }
       
    77 
       
    78 TestPhoneNoteController::~TestPhoneNoteController ()
       
    79 {
       
    80 }
       
    81 
       
    82 void TestPhoneNoteController::initTestCase ()
       
    83 {
       
    84     m_noteController = new PhoneNoteController();
       
    85 }
       
    86 
       
    87 void TestPhoneNoteController::cleanupTestCase ()
       
    88 {
       
    89     delete m_noteController;
       
    90 }
       
    91 
       
    92 void TestPhoneNoteController::init ()
       
    93 {
       
    94 }
       
    95 
       
    96 void TestPhoneNoteController::cleanup ()
       
    97 {
       
    98 }
       
    99 
       
   100 void TestPhoneNoteController::testShowGlobalNoteDefault ()
       
   101 {
       
   102     TPhoneCmdParamGlobalNote globalNoteParam;
       
   103     globalNoteParam.SetWaitForReady(ETrue);
       
   104     
       
   105     m_noteController->showGlobalNote(&globalNoteParam);
       
   106     
       
   107     QTest::qWait(5000);
       
   108 }
       
   109 
       
   110 void TestPhoneNoteController::testShowGlobalInfoNoteWithResourceId ()
       
   111 {
       
   112     TPhoneCmdParamGlobalNote globalNoteParam;
       
   113     globalNoteParam.SetTextResourceId(R_NOTETEXT_NO_ANSWER);
       
   114     globalNoteParam.SetWaitForReady(EFalse);
       
   115     globalNoteParam.SetType( EAknGlobalInformationNote );
       
   116     
       
   117     m_noteController->showGlobalNote(&globalNoteParam);
       
   118     
       
   119     QTest::qWait(5000);
       
   120 }
       
   121 
       
   122 void TestPhoneNoteController::testShowGlobalWarningNoteWithText ()
       
   123 {
       
   124     TPhoneCmdParamGlobalNote globalNoteParam;
       
   125     globalNoteParam.SetWaitForReady(ETrue);
       
   126     globalNoteParam.SetType( EAknGlobalWarningNote );
       
   127     globalNoteParam.SetText(_L("Test note 1"));
       
   128     
       
   129     m_noteController->showGlobalNote(&globalNoteParam);
       
   130 }
       
   131 
       
   132 void TestPhoneNoteController::testShowGlobalNoteWithTextAndResourceId ()
       
   133 {
       
   134     TPhoneCmdParamGlobalNote globalNoteParam;
       
   135     globalNoteParam.SetTextResourceId(R_PHONE_TEXT_COLP_CONNECTED);
       
   136     globalNoteParam.SetWaitForReady(EFalse);
       
   137     globalNoteParam.SetType( EAknGlobalInformationNote );
       
   138     globalNoteParam.SetText(_L("Test number"));
       
   139     
       
   140     m_noteController->showGlobalNote(&globalNoteParam);
       
   141     
       
   142     QTest::qWait(5000);
       
   143 }
       
   144 
       
   145 void TestPhoneNoteController::testShowGlobalNoteTwoTimes ()
       
   146 {
       
   147     TPhoneCmdParamGlobalNote globalNoteParam;
       
   148     //globalNoteParam.SetTextResourceId(R_NOTETEXT_NO_ANSWER);
       
   149     globalNoteParam.SetWaitForReady(EFalse);
       
   150     globalNoteParam.SetType( EAknGlobalInformationNote );
       
   151     globalNoteParam.SetText(_L("Test note 2"));
       
   152     
       
   153     m_noteController->showGlobalNote(&globalNoteParam);
       
   154     
       
   155     globalNoteParam.SetText(_L("Test note 3"));
       
   156     
       
   157     m_noteController->showGlobalNote(&globalNoteParam);
       
   158     
       
   159     QTest::qWait(10000);
       
   160 
       
   161 }
       
   162 
       
   163 void TestPhoneNoteController::testShowGlobalNoteThreeTimes ()
       
   164 {
       
   165     TPhoneCmdParamGlobalNote globalNoteParam;
       
   166     //globalNoteParam.SetTextResourceId(R_NOTETEXT_NO_ANSWER);
       
   167     globalNoteParam.SetWaitForReady(EFalse);
       
   168     globalNoteParam.SetType( EAknGlobalInformationNote );
       
   169     globalNoteParam.SetText(_L("Test note 4"));
       
   170     
       
   171     m_noteController->showGlobalNote(&globalNoteParam);
       
   172     
       
   173     globalNoteParam.SetText(_L("Test note 5"));
       
   174     
       
   175     m_noteController->showGlobalNote(&globalNoteParam);
       
   176     
       
   177     globalNoteParam.SetText(_L("Test note 6"));
       
   178     
       
   179     m_noteController->showGlobalNote(&globalNoteParam);
       
   180     
       
   181     QTest::qWait(20000);
       
   182 }
       
   183 
       
   184 void TestPhoneNoteController::testShowNote()
       
   185 {
       
   186     TPhoneCmdParamNote noteParam;
       
   187     
       
   188     m_noteController->showNote(&noteParam);
       
   189     m_noteController->removeDtmfNote();
       
   190     m_noteController->removeNote();
       
   191     
       
   192     noteParam.SetType(EPhoneNoteDtmfSending);
       
   193     m_noteController->showNote(&noteParam);
       
   194     
       
   195     noteParam.SetResourceId(R_PHONEUI_SENDING_DTMF_WAIT_NOTE);
       
   196     noteParam.SetText(_L("Sending:\n123p456"));
       
   197     
       
   198     m_noteController->showNote(&noteParam);
       
   199     QTest::qWait(20000);
       
   200     
       
   201     noteParam.SetText(_L("Sending:\n123p456"));
       
   202     m_noteController->showNote(&noteParam);
       
   203     
       
   204     QTest::qWait(20000);
       
   205     
       
   206     m_noteController->removeNote();
       
   207     
       
   208     QTest::qWait(20000);
       
   209 }
       
   210 
       
   211 void TestPhoneNoteController::testShowQuery()
       
   212 {
       
   213     TPhoneCmdParamQuery queryParam;    
       
   214     m_noteController->showQuery(&queryParam);
       
   215     
       
   216     queryParam.SetQueryType(EPhoneQueryDialog);
       
   217     m_noteController->showQuery(&queryParam);
       
   218     
       
   219     queryParam.SetQueryPrompt(_L("TestQuery"));
       
   220     m_noteController->showQuery(&queryParam);
       
   221     m_noteController->removeQuery();
       
   222 
       
   223     queryParam.SetQueryResourceId(R_PHONEUI_DTMF_WAIT_CHARACTER_CONFIRMATION_QUERY);
       
   224     m_noteController->showQuery(&queryParam);
       
   225     
       
   226     QTest::qWait(20000);
       
   227     m_noteController->showQuery(&queryParam);
       
   228     
       
   229     m_noteController->removeQuery();
       
   230     
       
   231     QTest::qWait(20000);
       
   232 }
       
   233 
       
   234 void TestPhoneNoteController::testShowClobalWaitNote()
       
   235 {
       
   236     TPhoneCmdParamQuery queryParam;    
       
   237     
       
   238     queryParam.SetQueryType(EPhoneGlobalWaitNote);
       
   239     m_noteController->showQuery(&queryParam);
       
   240     QTest::qWait(5000);
       
   241     m_noteController->removeGlobalWaitNote();
       
   242     QTest::qWait(5000);
       
   243     
       
   244     queryParam.SetQueryPrompt(_L("TestQuery"));
       
   245     m_noteController->showQuery(&queryParam);
       
   246     QTest::qWait(5000);
       
   247     m_noteController->removeGlobalWaitNote();
       
   248     QTest::qWait(5000);
       
   249     
       
   250     queryParam.SetQueryPrompt(KNullDesC);
       
   251     TBuf<4> buf(_L("test"));
       
   252     queryParam.SetDataText(&buf);
       
   253     queryParam.SetTimeOut(2000);
       
   254     m_noteController->showQuery(&queryParam);
       
   255     QTest::qWait(10000);
       
   256      
       
   257     queryParam.SetCustomCommandForTimeOut(10);
       
   258     m_noteController->showQuery(&queryParam);
       
   259     QTest::qWait(10000);
       
   260 }
       
   261 
       
   262 PHONE_QT_NOTE_CONTROLLER_TEST_MAIN(TestPhoneNoteController)
       
   263 #include "unit_tests.moc"