phonesettings/cpphonesettingsplugins/cptelephonyutils/tsrc/ut_cpphonenotes/ut_cpphonenotes.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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ut_cpphonenotes.h"
       
    19 #include "qtestmains60ui.h"
       
    20 #include <hbmainwindow.h>
       
    21 #include <HbDeviceMessageBox.h>
       
    22 #include <HbMessageBox.h>
       
    23 #define private public
       
    24 #include "cpphonenotes.h"
       
    25 
       
    26 /*!
       
    27   UT_CpPhoneNotes::UT_CpPhoneNotes
       
    28  */
       
    29 UT_CpPhoneNotes::UT_CpPhoneNotes() 
       
    30 {
       
    31     CpPhoneNotes::instance();
       
    32 }
       
    33 
       
    34 /*!
       
    35   UT_CpPhoneNotes::~UT_CpPhoneNotes
       
    36  */
       
    37 UT_CpPhoneNotes::~UT_CpPhoneNotes()
       
    38 {
       
    39     //delete m_psui;
       
    40 }
       
    41 
       
    42 /*!
       
    43   UT_CpPhoneNotes::timerEvent
       
    44  */
       
    45 void UT_CpPhoneNotes::timerEvent( QTimerEvent* event )
       
    46 {
       
    47     QString currentTest(QTest::currentTestFunction());
       
    48     qDebug() << "timerEvent:" << currentTest;
       
    49     
       
    50     if (currentTest == "t_showGlobalErrorNote") {
       
    51         verifyGlobalNote(wantedNoteText);
       
    52     }
       
    53     
       
    54     if (m_noteid1) {
       
    55         CpPhoneNotes::instance()->cancelNote(m_noteid1);
       
    56         m_noteid1 = 0;
       
    57     }
       
    58     if (m_noteid2) {
       
    59         CpPhoneNotes::instance()->cancelNote(m_noteid2);
       
    60         m_noteid2 = 0;
       
    61     }
       
    62     if (m_noteid3) {
       
    63         CpPhoneNotes::instance()->cancelNote(m_noteid3);
       
    64         m_noteid3 = 0;
       
    65     }
       
    66     
       
    67     if (visibleDialog()) {
       
    68         visibleDialog()->close();
       
    69         QTest::qWait(1);
       
    70     }
       
    71 	
       
    72 }
       
    73 
       
    74 /*!
       
    75   UT_CpPhoneNotes::visibleDialog
       
    76  */
       
    77 HbDialog *UT_CpPhoneNotes::visibleDialog()
       
    78 {
       
    79     QList<QGraphicsItem*> items = mainWindow->scene()->items();
       
    80     foreach (QGraphicsItem* item, items) {
       
    81         HbDialog *w = qobject_cast<HbDialog*>(item->parentWidget());
       
    82         if (w && w->isVisible()) {
       
    83             qDebug() << "visibleDialog: " << w->getStaticMetaObject().className() <<
       
    84                     "contentWidget: " << w->contentWidget()->getStaticMetaObject().className();
       
    85             return w;
       
    86         }
       
    87     }
       
    88     
       
    89     return 0;
       
    90 }
       
    91 
       
    92 /*!
       
    93   UT_CpPhoneNotes::verifyGlobalNote
       
    94  */
       
    95 void UT_CpPhoneNotes::verifyGlobalNote( const QString& noteText )
       
    96 {
       
    97     qDebug() << "verifyGlobalNote:" << noteText;
       
    98     HbDeviceMessageBox *note=0;
       
    99     QObject* o=0;
       
   100     QVERIFY(CpPhoneNotes::instance()->m_notesQueue->count());
       
   101     QVERIFY(o = CpPhoneNotes::instance()->m_notesQueue->at(0));
       
   102     QVERIFY(note = qobject_cast<HbDeviceMessageBox *>(o));
       
   103     QCOMPARE(note->text(), noteText);
       
   104     note->close();
       
   105     QTest::qWait(1);
       
   106 }
       
   107 
       
   108 /*!
       
   109   UT_CpPhoneNotes::init
       
   110  */
       
   111 void UT_CpPhoneNotes::init()
       
   112 {
       
   113     initialize();
       
   114     timerid = startTimer(3000);
       
   115     m_noteid1 = 0;
       
   116     m_noteid2 = 0;
       
   117     m_noteid3 = 0;
       
   118 }
       
   119 
       
   120 /*!
       
   121   UT_CpPhoneNotes::cleanup
       
   122  */
       
   123 void UT_CpPhoneNotes::cleanup()
       
   124 {
       
   125     reset();
       
   126     if (timerid) {
       
   127         killTimer(timerid);
       
   128         timerid = 0;
       
   129     }
       
   130 }
       
   131 
       
   132 /*!
       
   133   UT_CpPhoneNotes::t_memleak
       
   134  */
       
   135 void UT_CpPhoneNotes::t_memleak()
       
   136 {
       
   137     
       
   138 }
       
   139 
       
   140 /*!
       
   141   UT_CpPhoneNotes::t_showProgressNote
       
   142  */
       
   143 void UT_CpPhoneNotes::t_showProgressNote()
       
   144 {
       
   145     CpPhoneNotes::instance()->showGlobalProgressNote(m_noteid1, "test");
       
   146     CpPhoneNotes::instance()->showGlobalProgressNote(m_noteid2, "test");
       
   147     QTest::qWait(5000);
       
   148 }
       
   149 
       
   150 /*!
       
   151   UT_CpPhoneNotes::t_showGlobalProgressNote
       
   152  */
       
   153 void UT_CpPhoneNotes::t_showGlobalProgressNote()
       
   154 {
       
   155     CpPhoneNotes::instance()->showGlobalProgressNote(m_noteid1, "test");
       
   156     QTest::qWait(5000);
       
   157 }
       
   158 
       
   159 /*!
       
   160   UT_CpPhoneNotes::t_showGlobalNote
       
   161  */
       
   162 void UT_CpPhoneNotes::t_showGlobalNote()
       
   163 {
       
   164     CpPhoneNotes::instance()->showGlobalNote(m_noteid1, "MessageTypeQuestion",HbMessageBox::MessageTypeQuestion );
       
   165     CpPhoneNotes::instance()->showGlobalNote(m_noteid2, "MessageTypeInformation",HbMessageBox::MessageTypeInformation);
       
   166     CpPhoneNotes::instance()->showGlobalNote(m_noteid3, "MessageTypeWarning",HbMessageBox::MessageTypeWarning );
       
   167     
       
   168 }
       
   169 
       
   170 /*!
       
   171   UT_CpPhoneNotes::t_showGlobalErrorNote
       
   172  */
       
   173 void UT_CpPhoneNotes::t_showGlobalErrorNote()
       
   174 {
       
   175     int errorcode = -1;
       
   176     wantedNoteText = "";
       
   177     expect("Tools::errorCodeTextMapping").with(errorcode,wantedNoteText).returns(true);
       
   178     CpPhoneNotes::instance()->showGlobalErrorNote(m_noteid1, errorcode );
       
   179     QVERIFY( verify() );
       
   180 
       
   181 }
       
   182 
       
   183 /*!
       
   184   UT_CpPhoneNotes::t_showBasicServiceList
       
   185  */
       
   186 void UT_CpPhoneNotes::t_showBasicServiceList()
       
   187 {
       
   188     QList<unsigned char> basicServiceGroupIds;
       
   189     basicServiceGroupIds << Telephony;
       
   190     basicServiceGroupIds << AllDataTele;
       
   191     CpPhoneNotes::instance()->
       
   192         showBasicServiceList("Basic Service List", basicServiceGroupIds );
       
   193 }
       
   194 
       
   195 /*!
       
   196   UT_CpPhoneNotes::t_showCallDivertDetails
       
   197  */
       
   198 void UT_CpPhoneNotes::t_showCallDivertDetails()
       
   199 {
       
   200     expect("CpSettingsWrapper::numberGroupingSupported").returns(QVariant(true));
       
   201     PSCallDivertingStatus status;
       
   202     CpPhoneNotes::instance()->showCallDivertDetails(status);
       
   203     QVERIFY( verify() );
       
   204 
       
   205     expect("CpSettingsWrapper::numberGroupingSupported").returns(QVariant(false));
       
   206     status.iTimeout = 30;
       
   207     CpPhoneNotes::instance()->showCallDivertDetails(status);
       
   208     QVERIFY( verify() );
       
   209 }
       
   210 
       
   211 /*!
       
   212   UT_CpPhoneNotes::t_showPasswordQueryDialog
       
   213  */
       
   214 void UT_CpPhoneNotes::t_showPasswordQueryDialog()
       
   215 {
       
   216     QString queryTitle("Password query title");
       
   217     QString password = "";
       
   218     bool okPressed = false;
       
   219     QRegExp regExpression("\\d{4}");
       
   220     QRegExpValidator validator(regExpression, this);
       
   221     CpPhoneNotes::instance()->showPasswordQueryDialog(
       
   222         queryTitle, validator, 5);
       
   223 
       
   224 }
       
   225 
       
   226 
       
   227 /*!
       
   228   UT_CpPhoneNotes::t_cancelNote
       
   229  */
       
   230 void UT_CpPhoneNotes::t_cancelNote()
       
   231 {
       
   232     CpPhoneNotes::instance()->cancelNote(m_noteid1);
       
   233     CpPhoneNotes::instance()->showGlobalProgressNote(m_noteid1, "test");
       
   234     CpPhoneNotes::instance()->noteShowing();
       
   235     CpPhoneNotes::instance()->cancelNote(m_noteid1);
       
   236         
       
   237     QTest::qWait(5000);
       
   238 }
       
   239 
       
   240 QTEST_MAIN_S60UI(UT_CpPhoneNotes)