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