satui/satapp/tsrc/ut_satapp/src/ut_satapppopupprovider.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 /*
       
     2 * Copyright (c) 2010 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 test for satappmainhandler
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QTimer>
       
    19 #include <QAction>
       
    20 
       
    21 #include <hbmessagebox.h>
       
    22 #include <hbprogressdialog.h>
       
    23 #include <hbdevicemessagebox.h>
       
    24 
       
    25 #include "ut_satapppopupprovider.h"
       
    26 #include "satapppopupprovider.h"
       
    27 #include "satappaction.h"
       
    28 
       
    29 
       
    30 
       
    31 // --------------------------------------------------------
       
    32 // The unit tests begin here
       
    33 // --------------------------------------------------------
       
    34 
       
    35 Ut_SatAppPopupProvider::Ut_SatAppPopupProvider(
       
    36         QObject *parent)
       
    37     :QObject(parent)
       
    38 {
       
    39 }
       
    40 
       
    41 
       
    42 void Ut_SatAppPopupProvider::testDisplayTextAndOk_data()
       
    43 {
       
    44     QTest::addColumn<QString>("text");
       
    45     QTest::addColumn<QString>("appName");
       
    46     QTest::addColumn<bool>("sustainedText");
       
    47     QTest::addColumn<int>("duration");
       
    48 
       
    49     QTest::newRow("t01") << "title" << "sat" << true << 1000;
       
    50     QTest::newRow("t02") << "" << "sat" << false << 100;
       
    51     QTest::newRow("t03") << "" << "sat" << true << 500;
       
    52     QTest::newRow("t04") << "title" << "sat" << true << 0;
       
    53     QTest::newRow("t05") << "a bit longer title that does not fit" << "" << false << 900;
       
    54     QTest::newRow("t06") << "title" << "" << false << 400;
       
    55     QTest::newRow("t07") << "" << "" << true << 150;
       
    56     QTest::newRow("t08") << "a bit longer title that does not fit" << "sat" << true << 2000;
       
    57     QTest::newRow("t09") << "title" << "sat" << false << 600;
       
    58     QTest::newRow("t10") << "" << "somewhat longer application name" << false << 200;
       
    59     QTest::newRow("t11") << "" << "" << false << 0;
       
    60     QTest::newRow("t12") << "title" << "" << true << 500;
       
    61     QTest::newRow("t13") << "title" << "somewhat longer application name" << false << 0;
       
    62     QTest::newRow("t14") << "" << "sat" << true << 700;
       
    63     QTest::newRow("t15") << "title" << "sat" << false << 3000;
       
    64     
       
    65 }
       
    66 
       
    67 void Ut_SatAppPopupProvider::testDisplayTextAndOk()
       
    68 {
       
    69     QFETCH(QString, text);
       
    70     QFETCH(QString, appName);
       
    71     QFETCH(bool, sustainedText);
       
    72     QFETCH(int, duration);
       
    73 
       
    74     SatAppAction a(ESatDisplayTextAction);
       
    75     a.set(KeyText,text);
       
    76     a.set(KeyApplicationName,appName);
       
    77     a.set(KeySustainedText,sustainedText);
       
    78     a.set(KeyDuration,duration);
       
    79     a.set(KeyWaitUserToClear,false);
       
    80     a.setResponse(ESatFailure);
       
    81 
       
    82     PopupProviderTest test;
       
    83     test.mPopup->displayText(a);
       
    84     test.simulateOkClicked();
       
    85     
       
    86     QCOMPARE(a.response(),ESatSuccess);
       
    87 }
       
    88 
       
    89 
       
    90 void Ut_SatAppPopupProvider::testDisplayTextAndCancel_data()
       
    91 {
       
    92     testDisplayTextAndOk_data(); // same test material
       
    93 }
       
    94 
       
    95 void Ut_SatAppPopupProvider::testDisplayTextAndCancel()
       
    96 {
       
    97     QFETCH(QString, text);
       
    98     QFETCH(QString, appName);
       
    99     QFETCH(bool, sustainedText);
       
   100     QFETCH(int, duration);
       
   101 
       
   102     SatAppAction a(ESatDisplayTextAction);
       
   103     a.set(KeyText,text);
       
   104     a.set(KeyApplicationName,appName);
       
   105     a.set(KeySustainedText,sustainedText);
       
   106     a.set(KeyDuration,duration);
       
   107     a.set(KeyWaitUserToClear,false);
       
   108     a.setResponse(ESatFailure);
       
   109 
       
   110     PopupProviderTest test;
       
   111     test.mPopup->displayText(a);
       
   112     test.simulateCancelClicked();
       
   113     
       
   114     QCOMPARE(a.response(),ESatBackwardModeRequestedByUser);
       
   115 }
       
   116 
       
   117 
       
   118 void Ut_SatAppPopupProvider::testDisplayTextAndTimeout()
       
   119 {
       
   120     SatAppAction a(ESatDisplayTextAction);
       
   121     a.set(KeyText,"hello world");
       
   122     a.set(KeyApplicationName,"sat");
       
   123     a.set(KeySustainedText,false);
       
   124     a.set(KeyDuration,1000);
       
   125     a.set(KeyWaitUserToClear,true);
       
   126     a.setResponse(ESatFailure);
       
   127 
       
   128     PopupProviderTest test;
       
   129     test.mPopup->displayText(a);
       
   130     a.waitUntilCompleted();
       
   131     QCOMPARE(a.response(),ESatNoResponseFromUser);
       
   132 }
       
   133 
       
   134 void Ut_SatAppPopupProvider::testNotificationWithCancel_data()
       
   135 {
       
   136     QTest::addColumn<int>("commandId");
       
   137     QTest::addColumn<int>("alphaIdStatus");
       
   138     QTest::addColumn<QString>("text");
       
   139     QTest::addColumn<int>("controlResult");
       
   140     QTest::addColumn<int>("clickState"); // clikcked->state
       
   141 
       
   142     QTest::newRow("t01") << (int)ESatSSendDataNotify << (int)ESatAlphaIdNotNull << "notify"
       
   143         << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   144     QTest::newRow("t02") << (int)ESatSSendDataNotify << (int)ESatAlphaIdNull << ""
       
   145         << (int)ESatNotAllowed << (int)ESatSuccess;
       
   146     
       
   147     QTest::newRow("t03") << (int)ESatSReceiveDataNotify << (int)ESatAlphaIdNotNull
       
   148         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   149     QTest::newRow("t04") << (int)ESatSReceiveDataNotify << (int)ESatAlphaIdNull
       
   150         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   151 
       
   152     QTest::newRow("t05") << (int)ESatSSendDtmfNotify << (int)ESatAlphaIdNotNull
       
   153         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   154     QTest::newRow("t06") << (int)ESatSSendDtmfNotify << (int)ESatAlphaIdNull
       
   155         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   156 }
       
   157 
       
   158 void Ut_SatAppPopupProvider::testNotificationWithCancel()
       
   159 {
       
   160     QFETCH(int, commandId);
       
   161     QFETCH(int, alphaIdStatus);
       
   162     QFETCH(QString, text);
       
   163     QFETCH(int, controlResult);
       
   164     QFETCH(int, clickState);
       
   165 
       
   166     SatAppAction *a = new SatAppAction(ESatNotifyAction);
       
   167     a->set(KeyCommandId,commandId);
       
   168     a->set(KeyAlphaIdStatus,alphaIdStatus);
       
   169     a->set(KeyText,text);
       
   170     a->set(KeyControlResult,controlResult);
       
   171     a->setResponse(ESatSuccess);
       
   172 
       
   173     PopupProviderTest test;
       
   174     test.mPopup->notification(*a);
       
   175     qDebug() << "action response" << a->response() << "/" << clickState;
       
   176     QVERIFY(a->response()==(TSatUiResponse)clickState);
       
   177 }
       
   178 
       
   179 void Ut_SatAppPopupProvider::testNotification_data()
       
   180 {
       
   181     QTest::addColumn<int>("commandId");
       
   182     QTest::addColumn<int>("alphaIdStatus");
       
   183     QTest::addColumn<QString>("text");
       
   184     QTest::addColumn<int>("controlResult");
       
   185     QTest::addColumn<int>("clickState"); // clikcked->state    
       
   186 
       
   187     QTest::newRow("t01") << (int)ESatSCloseChannelNotify << (int)ESatAlphaIdNotNull
       
   188         << "notify" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   189     QTest::newRow("t02") << (int)ESatSCloseChannelNotify << (int)ESatAlphaIdNull
       
   190         << "" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   191 
       
   192     QTest::newRow("t03") << (int)ESatSMoSmControlNotify << (int)ESatAlphaIdNotNull
       
   193         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   194     QTest::newRow("t04") << (int)ESatSMoSmControlNotify << (int)ESatAlphaIdNull
       
   195         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   196     QTest::newRow("t05") << (int)ESatSMoSmControlNotify << (int)ESatAlphaIdNotProvided
       
   197         << "" << (int)ESatAllowedWithModifications << (int)ESatSuccess;
       
   198 
       
   199     QTest::newRow("t06") << (int)ESatSCallControlNotify << (int)ESatAlphaIdNotNull
       
   200         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   201     QTest::newRow("t07") << (int)ESatSCallControlNotify << (int)ESatAlphaIdNull
       
   202         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   203     QTest::newRow("t08") << (int)ESatSCallControlNotify << (int)ESatAlphaIdNotProvided
       
   204         << "" << (int)ESatAllowedWithModifications << (int)ESatSuccess;
       
   205 
       
   206     QTest::newRow("t09") << (int)ESatSSendUssdNotify << (int)ESatAlphaIdNotNull
       
   207         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   208     QTest::newRow("t10") << (int)ESatSSendUssdNotify << (int)ESatAlphaIdNull
       
   209         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   210 
       
   211     QTest::newRow("t11") << (int)ESatSSendUssdNotify << (int)ESatAlphaIdNotNull
       
   212         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   213     QTest::newRow("t12") << (int)ESatSSendUssdNotify << (int)ESatAlphaIdNull
       
   214         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   215 
       
   216     QTest::newRow("t13") << (int)ESatSSendSsNotify << (int)ESatAlphaIdNotNull
       
   217         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   218     QTest::newRow("t14") << (int)ESatSSendSsNotify << (int)ESatAlphaIdNull
       
   219         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   220     
       
   221     QTest::newRow("t15") << (int)ESatSSendSmsNotify << (int)ESatAlphaIdNotNull
       
   222         << "notify" << (int)ESatAllowedNoModification << (int)ESatSuccess;
       
   223     QTest::newRow("t16") << (int)ESatSSendSmsNotify << (int)ESatAlphaIdNull
       
   224         << "" << (int)ESatNotAllowed << (int)ESatSuccess;
       
   225 }
       
   226 
       
   227 void Ut_SatAppPopupProvider::testNotification()
       
   228 {
       
   229     QFETCH(int, commandId);
       
   230     QFETCH(int, alphaIdStatus);
       
   231     QFETCH(QString, text);
       
   232     QFETCH(int, controlResult);
       
   233     QFETCH(int, clickState);
       
   234 
       
   235     SatAppAction a(ESatNotifyAction);
       
   236     a.set(KeyCommandId,commandId);
       
   237     a.set(KeyAlphaIdStatus,alphaIdStatus);
       
   238     a.set(KeyText,text);
       
   239     a.set(KeyControlResult,controlResult);
       
   240     a.setResponse(ESatSuccess);
       
   241     
       
   242     PopupProviderTest test;
       
   243     test.mPopup->notification(a);
       
   244 
       
   245     qDebug() << "action response:" << a.response() << "/" << clickState;
       
   246     QCOMPARE(a.response(),(TSatUiResponse)clickState);
       
   247 }
       
   248 
       
   249 // ---------------------------------------------------------------
       
   250 // internal helper class
       
   251 // ---------------------------------------------------------------
       
   252 
       
   253 PopupProviderTest::PopupProviderTest()
       
   254 {
       
   255     mPopup = new SatAppPopupProvider(this);
       
   256 }
       
   257 
       
   258 PopupProviderTest::~PopupProviderTest()
       
   259 {
       
   260     cleanup();
       
   261 }
       
   262 
       
   263 bool PopupProviderTest::simulateOkClicked()
       
   264 {
       
   265     if (mPopup->mDisplayText->actions().size()<=0) return false;
       
   266     mPopup->mDisplayText->actions().at(0)->trigger();
       
   267     return true;
       
   268 }
       
   269 
       
   270 bool PopupProviderTest::simulateCancelClicked()
       
   271 {
       
   272     if (mPopup->mDisplayText->actions().size()<=1) return false;
       
   273     mPopup->mDisplayText->actions().at(1)->trigger();
       
   274     return true;
       
   275 }
       
   276 
       
   277 void PopupProviderTest::cleanup()
       
   278 {
       
   279     delete mPopup;
       
   280     mPopup = 0;
       
   281 }
       
   282 
       
   283 
       
   284 // End of file