--- a/phoneapp/phoneuiqtviewadapter/tsrc/ut_phonemessagecontroller/unit_tests.cpp Tue Jul 06 14:15:47 2010 +0300
+++ b/phoneapp/phoneuiqtviewadapter/tsrc/ut_phonemessagecontroller/unit_tests.cpp Wed Aug 18 09:48:26 2010 +0300
@@ -1,5 +1,5 @@
/*!
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
@@ -11,46 +11,55 @@
*
* Contributors:
*
-* Description: Unit tests for PhoneNoteController.
+* Description: Unit tests for PhoneMessageController.
*
*/
#include <QtTest/QtTest>
#include <QtGui>
-#include <hbapplication.h>
-#include <QSignalSpy>
-#include "phoneconstants.h"
-#include "cphonecenrepproxy.h"
-#include "cphonepubsubproxy.h"
+#include <HbGlobal>
+#include <mockservice.h>
#include <settingsinternalcrkeys.h>
#include "phoneapplauncher.h"
#include "phonemessagecontroller.h"
#include "tphonecmdparamsfidata.h"
+#include "phoneconstants.h"
+#include "cphonecenrepproxy.h"
-extern QList<QVariant> gList;
+const QString KNumber = "1234567";
+const QString KName = "Tester";
+const QString KUserDefinedSoftRejectText = "user defined text";
+
+void enableUserDefinedSoftRejectText(
+ const TUid & aUid,
+ const TUint aId,
+ TInt & aValue)
+{
+ Q_UNUSED(aUid)
+ Q_UNUSED(aId)
+
+ aValue = 1;
+}
-#define PHONE_QT_MESSAGE_CONTROLLER_TEST_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
- HbApplication app(argc, argv); \
- TestObject tc; \
- QResource::registerResource("../hbcore.rcc"); \
- int ret = QTest::qExec(&tc, argc, argv); \
- /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
- /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
- /* app.exec() where the signal is normally emitted is not called here. */ \
- /* So, invoking the signal explicitly. */ \
- QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
- return ret; \
+void setUserDefinedSoftRejectText(
+ const TUid & aUid,
+ const TUint aId,
+ TDes & aValue)
+{
+ Q_UNUSED(aUid)
+ Q_UNUSED(aId)
+
+ aValue.Copy(KUserDefinedSoftRejectText.utf16());
}
-class TestPhoneMessageController : public QObject
+
+class UT_PhoneMessageController : public QObject, public MockService
{
Q_OBJECT
public:
- TestPhoneMessageController();
- virtual ~TestPhoneMessageController();
+ UT_PhoneMessageController();
+ virtual ~UT_PhoneMessageController();
public slots:
void initTestCase();
@@ -59,91 +68,100 @@
void cleanup();
private slots:
- void testOpenSoftRejectEditor();
-
+ void t_openSoftRejectEditorDefaultText();
+ void t_openSoftRejectEditorUserDefinedText();
private:
- QString softRejectText();
-
-private:
PhoneAppLauncher *m_launcher;
PhoneMessageController *m_messageController; // class under test
};
-TestPhoneMessageController::TestPhoneMessageController()
-{
-}
-TestPhoneMessageController::~TestPhoneMessageController()
+UT_PhoneMessageController::UT_PhoneMessageController()
+ :
+ m_launcher(NULL),
+ m_messageController(NULL)
{
}
-void TestPhoneMessageController::initTestCase()
-{
- m_launcher = new PhoneAppLauncher(this);
- m_messageController = new PhoneMessageController(*m_launcher, this);
-}
-void TestPhoneMessageController::cleanupTestCase()
+UT_PhoneMessageController::~UT_PhoneMessageController()
{
delete m_messageController;
delete m_launcher;
}
-void TestPhoneMessageController::init()
+
+void UT_PhoneMessageController::initTestCase()
{
-}
-
-void TestPhoneMessageController::cleanup()
-{
+ m_launcher = new PhoneAppLauncher(this);
+ m_messageController = new PhoneMessageController(*m_launcher, this);
}
-void TestPhoneMessageController::testOpenSoftRejectEditor()
+
+void UT_PhoneMessageController::cleanupTestCase()
{
- QString text = softRejectText();
- TPhoneCmdParamSfiData sfiParam;
- sfiParam.SetNumber(_L("1234567"));
- sfiParam.SetName(_L("Tester"));
-
- m_messageController->openSoftRejectMessageEditor(&sfiParam);
-
- QVERIFY( gList.contains("1234567") );
- QVERIFY( gList.contains("Tester") );
- QVERIFY( gList.contains(text) );
+ delete m_messageController;
+ m_messageController = NULL;
+ delete m_launcher;
+ m_launcher = NULL;
+}
+
+
+void UT_PhoneMessageController::init()
+{
+ initialize();
+}
+
+
+void UT_PhoneMessageController::cleanup()
+{
+ reset();
}
-QString TestPhoneMessageController::softRejectText()
+
+void UT_PhoneMessageController::t_openSoftRejectEditorDefaultText()
{
- QString messageBody;
- // Get message body
- TInt softRejectDefaultInUseValue = 0;
- const TInt err = CPhoneCenRepProxy::Instance()->GetInt(
- KCRUidTelephonySettings,
- KSettingsSoftRejectDefaultInUse,
- softRejectDefaultInUseValue );
+ const QString KDefaultSoftRejectText =
+ hbTrId("txt_phone_setlabel_soft_reject_val_default_text");
+ EXPECT(PhoneAppLauncher::launchMessaging)
+ .with(KNumber, KName, KDefaultSoftRejectText);
- if (softRejectDefaultInUseValue) {
- HBufC* softRejectTxt = NULL;
- TRAP_IGNORE( softRejectTxt = HBufC::NewL( KPhoneSMSLength ) );
-
- if (softRejectTxt) {
- TPtr string( softRejectTxt->Des() );
-
- // Default txt used or not
- CPhoneCenRepProxy::Instance()->GetString(
- KCRUidTelephonySettings,
- KSettingsSoftRejectText,
- string );
-
- messageBody = QString::fromUtf16(string.Ptr(), string.Length());
- delete softRejectTxt;
- }
- } else {
- messageBody = hbTrId("txt_phone_setlabel_soft_reject_val_default_text");
- }
+ TPhoneCmdParamSfiData sfiParam;
+ sfiParam.SetNumber(TBuf16<20>(KNumber.utf16()));
+ sfiParam.SetName(TBuf16<20>(KName.utf16()));
+ m_messageController->openSoftRejectMessageEditor(&sfiParam);
- return messageBody;
+ QVERIFY(verify());
}
-PHONE_QT_MESSAGE_CONTROLLER_TEST_MAIN(TestPhoneMessageController)
+
+void UT_PhoneMessageController::t_openSoftRejectEditorUserDefinedText()
+{
+ EXPECT(PhoneAppLauncher::launchMessaging)
+ .with(KNumber, KName, KUserDefinedSoftRejectText);
+ EXPECT(CPhoneCenRepProxy::GetInt)
+ .with(KCRUidTelephonySettings, KSettingsSoftRejectDefaultInUse, 0)
+ .willOnce(invoke(enableUserDefinedSoftRejectText));
+ EXPECT(CPhoneCenRepProxy::GetString)
+ .with(KCRUidTelephonySettings, KSettingsSoftRejectText, KNullDesC())
+ .willOnce(invoke(setUserDefinedSoftRejectText));
+
+ TPhoneCmdParamSfiData sfiParam;
+ sfiParam.SetNumber(TBuf16<20>(KNumber.utf16()));
+ sfiParam.SetName(TBuf16<20>(KName.utf16()));
+ m_messageController->openSoftRejectMessageEditor(&sfiParam);
+
+ QVERIFY(verify());
+}
+
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication(argc, argv);
+ UT_PhoneMessageController tc;
+ int ret = QTest::qExec(&tc, argc, argv); \
+ return ret;
+}
+
#include "unit_tests.moc"