phoneapp/phoneuiqtviewadapter/tsrc/ut_phonemessagecontroller/unit_tests.cpp
changeset 56 5bcb308bd24d
parent 46 bc5a64e5bc3c
child 60 1eef62f5c541
equal deleted inserted replaced
46:bc5a64e5bc3c 56:5bcb308bd24d
     1 /*!
     1 /*!
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Unit tests for PhoneNoteController.
    14 * Description:  Unit tests for PhoneMessageController.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 #include <QtGui>
    19 #include <QtGui>
    20 #include <hbapplication.h>
    20 #include <HbGlobal>
    21 #include <QSignalSpy>
    21 #include <mockservice.h>
    22 #include "phoneconstants.h"
       
    23 #include "cphonecenrepproxy.h"
       
    24 #include "cphonepubsubproxy.h"
       
    25 #include <settingsinternalcrkeys.h>
    22 #include <settingsinternalcrkeys.h>
    26 #include "phoneapplauncher.h"
    23 #include "phoneapplauncher.h"
    27 #include "phonemessagecontroller.h"
    24 #include "phonemessagecontroller.h"
    28 #include "tphonecmdparamsfidata.h"
    25 #include "tphonecmdparamsfidata.h"
       
    26 #include "phoneconstants.h"
       
    27 #include "cphonecenrepproxy.h"
    29 
    28 
    30 extern QList<QVariant> gList;
    29 const QString KNumber = "1234567";
       
    30 const QString KName = "Tester";
       
    31 const QString KUserDefinedSoftRejectText = "user defined text";
       
    32 
       
    33 void enableUserDefinedSoftRejectText(
       
    34     const TUid & aUid,
       
    35     const TUint aId,
       
    36     TInt & aValue)
       
    37 {
       
    38     Q_UNUSED(aUid)
       
    39     Q_UNUSED(aId)
       
    40     
       
    41     aValue = 1;
       
    42 }
    31 
    43 
    32 
    44 
    33 #define PHONE_QT_MESSAGE_CONTROLLER_TEST_MAIN(TestObject) \
    45 void setUserDefinedSoftRejectText(
    34 int main(int argc, char *argv[]) \
    46     const TUid & aUid,
    35 { \
    47     const TUint aId,
    36     HbApplication app(argc, argv); \
    48     TDes & aValue)
    37     TestObject tc; \
    49 {
    38     QResource::registerResource("../hbcore.rcc"); \
    50     Q_UNUSED(aUid)
    39     int ret = QTest::qExec(&tc, argc, argv); \
    51     Q_UNUSED(aId)
    40     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
    52     
    41     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
    53     aValue.Copy(KUserDefinedSoftRejectText.utf16());
    42     /* app.exec() where the signal is normally emitted is not called here. */ \
       
    43     /* So, invoking the signal explicitly. */ \
       
    44     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
       
    45     return ret; \
       
    46 }
    54 }
    47 
    55 
    48 class TestPhoneMessageController : public QObject
    56 
       
    57 class UT_PhoneMessageController : public QObject, public MockService
    49 {
    58 {
    50     Q_OBJECT
    59     Q_OBJECT
    51 public:
    60 public:
    52     TestPhoneMessageController();
    61     UT_PhoneMessageController();
    53     virtual ~TestPhoneMessageController();
    62     virtual ~UT_PhoneMessageController();
    54 
    63 
    55 public slots:
    64 public slots:
    56     void initTestCase();
    65     void initTestCase();
    57     void cleanupTestCase();
    66     void cleanupTestCase();
    58     void init();
    67     void init();
    59     void cleanup(); 
    68     void cleanup(); 
    60     
    69     
    61 private slots:
    70 private slots:
    62     void testOpenSoftRejectEditor();
    71     void t_openSoftRejectEditorDefaultText();
       
    72     void t_openSoftRejectEditorUserDefinedText();
    63 
    73 
    64 
       
    65 private:
       
    66     QString softRejectText();
       
    67     
       
    68 private:
    74 private:
    69     PhoneAppLauncher *m_launcher;
    75     PhoneAppLauncher *m_launcher;
    70     PhoneMessageController *m_messageController; // class under test
    76     PhoneMessageController *m_messageController; // class under test
    71 };
    77 };
    72 
    78 
    73 TestPhoneMessageController::TestPhoneMessageController()
    79 
       
    80 UT_PhoneMessageController::UT_PhoneMessageController()
       
    81     :
       
    82     m_launcher(NULL),
       
    83     m_messageController(NULL)
    74 {
    84 {
    75 }
    85 }
    76 
    86 
    77 TestPhoneMessageController::~TestPhoneMessageController()
    87 
       
    88 UT_PhoneMessageController::~UT_PhoneMessageController()
    78 {
    89 {
       
    90     delete m_messageController;
       
    91     delete m_launcher;
    79 }
    92 }
    80 
    93 
    81 void TestPhoneMessageController::initTestCase()
    94 
       
    95 void UT_PhoneMessageController::initTestCase()
    82 {
    96 {
    83     m_launcher = new PhoneAppLauncher(this);
    97     m_launcher = new PhoneAppLauncher(this);
    84     m_messageController = new PhoneMessageController(*m_launcher, this);
    98     m_messageController = new PhoneMessageController(*m_launcher, this);
    85 }
    99 }
    86 
   100 
    87 void TestPhoneMessageController::cleanupTestCase()
   101 
       
   102 void UT_PhoneMessageController::cleanupTestCase()
    88 {
   103 {
    89     delete m_messageController;
   104     delete m_messageController;
       
   105     m_messageController = NULL;
    90     delete m_launcher;
   106     delete m_launcher;
       
   107     m_launcher = NULL;
    91 }
   108 }
    92 
   109 
    93 void TestPhoneMessageController::init()
   110 
       
   111 void UT_PhoneMessageController::init()
    94 {
   112 {
       
   113     initialize();
    95 }
   114 }
    96 
   115 
    97 void TestPhoneMessageController::cleanup()
   116 
       
   117 void UT_PhoneMessageController::cleanup()
    98 {
   118 {
       
   119     reset();
    99 }
   120 }
   100 
   121 
   101 void TestPhoneMessageController::testOpenSoftRejectEditor()
   122 
       
   123 void UT_PhoneMessageController::t_openSoftRejectEditorDefaultText()
   102 {
   124 {
   103     QString text = softRejectText();
   125     const QString KDefaultSoftRejectText = 
       
   126         hbTrId("txt_phone_setlabel_soft_reject_val_default_text");
       
   127     EXPECT(PhoneAppLauncher::launchMessaging)
       
   128         .with(KNumber, KName, KDefaultSoftRejectText);
       
   129     
   104     TPhoneCmdParamSfiData sfiParam;
   130     TPhoneCmdParamSfiData sfiParam;
   105     sfiParam.SetNumber(_L("1234567"));
   131     sfiParam.SetNumber(TBuf16<20>(KNumber.utf16()));
   106     sfiParam.SetName(_L("Tester"));
   132     sfiParam.SetName(TBuf16<20>(KName.utf16()));
   107     
       
   108     m_messageController->openSoftRejectMessageEditor(&sfiParam);
   133     m_messageController->openSoftRejectMessageEditor(&sfiParam);
   109     
   134     
   110     QVERIFY( gList.contains("1234567") );
   135     QVERIFY(verify());
   111     QVERIFY( gList.contains("Tester") );
       
   112     QVERIFY( gList.contains(text) );
       
   113 }
   136 }
   114 
   137 
   115 QString TestPhoneMessageController::softRejectText()
   138 
       
   139 void UT_PhoneMessageController::t_openSoftRejectEditorUserDefinedText()
   116 {
   140 {
   117     QString messageBody;
   141     EXPECT(PhoneAppLauncher::launchMessaging)
   118     // Get message body
   142         .with(KNumber, KName, KUserDefinedSoftRejectText);
   119     TInt softRejectDefaultInUseValue = 0;
   143     EXPECT(CPhoneCenRepProxy::GetInt)
   120     const TInt err = CPhoneCenRepProxy::Instance()->GetInt(
   144         .with(KCRUidTelephonySettings, KSettingsSoftRejectDefaultInUse, 0)
   121         KCRUidTelephonySettings,
   145         .willOnce(invoke(enableUserDefinedSoftRejectText));
   122         KSettingsSoftRejectDefaultInUse,
   146     EXPECT(CPhoneCenRepProxy::GetString)
   123         softRejectDefaultInUseValue );
   147         .with(KCRUidTelephonySettings, KSettingsSoftRejectText, KNullDesC())
       
   148         .willOnce(invoke(setUserDefinedSoftRejectText));
   124     
   149     
   125     if (softRejectDefaultInUseValue) {
   150     TPhoneCmdParamSfiData sfiParam;
   126         HBufC* softRejectTxt = NULL;
   151     sfiParam.SetNumber(TBuf16<20>(KNumber.utf16()));
   127         TRAP_IGNORE( softRejectTxt = HBufC::NewL( KPhoneSMSLength ) );
   152     sfiParam.SetName(TBuf16<20>(KName.utf16()));
   128         
   153     m_messageController->openSoftRejectMessageEditor(&sfiParam);
   129         if (softRejectTxt) {
       
   130             TPtr string( softRejectTxt->Des() );
       
   131         
       
   132             // Default txt used or not
       
   133             CPhoneCenRepProxy::Instance()->GetString(
       
   134                 KCRUidTelephonySettings,
       
   135                 KSettingsSoftRejectText,
       
   136                 string );
       
   137             
       
   138             messageBody = QString::fromUtf16(string.Ptr(), string.Length());
       
   139             delete softRejectTxt;
       
   140         }
       
   141     } else {
       
   142         messageBody = hbTrId("txt_phone_setlabel_soft_reject_val_default_text");
       
   143     }
       
   144     
   154     
   145     return messageBody;
   155     QVERIFY(verify());
   146 }
   156 }
   147 
   157 
   148 PHONE_QT_MESSAGE_CONTROLLER_TEST_MAIN(TestPhoneMessageController)
   158 
       
   159 int main(int argc, char *argv[])
       
   160 {
       
   161     QCoreApplication(argc, argv);
       
   162     UT_PhoneMessageController tc;
       
   163     int ret = QTest::qExec(&tc, argc, argv); \
       
   164     return ret;
       
   165 }
       
   166 
   149 #include "unit_tests.moc"
   167 #include "unit_tests.moc"