[Merge] lp:~boiko/telephony-service/fix_voicemail_detection into lp:telephony-service
Gustavo Pichorim Boiko
gustavo.boiko at canonical.com
Mon May 11 13:17:03 UTC 2015
Questions replied.
Diff comments:
> === modified file '.bzrignore'
> --- .bzrignore 2015-04-22 13:44:53 +0000
> +++ .bzrignore 2015-05-08 21:57:41 +0000
> @@ -33,6 +33,7 @@
> indicator/*.desktop
> indicator/*.service
> indicator/NotificationsInterface.*
> +indicator/indicatoradaptor.*
>
> Testing
> Ubuntu/Telephony/qmldir
>
> === modified file 'cmake/modules/GenerateTest.cmake'
> --- cmake/modules/GenerateTest.cmake 2015-04-22 13:20:02 +0000
> +++ cmake/modules/GenerateTest.cmake 2015-05-08 21:57:41 +0000
> @@ -113,7 +113,6 @@
> --task dconf -p write -p /org/gnome/empathy/use-conn -p false --task-name dconf-write --wait-for ca.desrt.dconf --ignore-return
> --task /usr/lib/telepathy/mission-control-5 --task-name mission-control --wait-for ca.desrt.dconf --ignore-return
> --task ${CMAKE_BINARY_DIR}/tests/common/mock/telepathy-mock --task-name telepathy-mock --wait-for org.freedesktop.Telepathy.MissionControl5 --ignore-return
> - --task dbus-monitor --task-name dbus-monitor --ignore-return
> # FIXME: maybe it would be better to decide whether to run the handler in a per-test basis?
> --task ${CMAKE_BINARY_DIR}/handler/telephony-service-handler --task-name telephony-service-handler --wait-for org.freedesktop.Telepathy.ConnectionManager.mock --ignore-return
> ${ARG_TASKS})
>
> === modified file 'libtelephonyservice/accountentry.cpp'
> --- libtelephonyservice/accountentry.cpp 2015-04-16 16:45:59 +0000
> +++ libtelephonyservice/accountentry.cpp 2015-05-08 21:57:41 +0000
> @@ -22,14 +22,18 @@
> #include <TelepathyQt/PendingOperation>
> #include <QTimer>
> #include "accountentry.h"
> -#include "telepathyhelper.h"
>
> AccountEntry::AccountEntry(const Tp::AccountPtr &account, QObject *parent) :
> - QObject(parent), mAccount(account)
> + QObject(parent), mAccount(account), mReady(false)
> {
> initialize();
> }
>
> +bool AccountEntry::ready() const
> +{
> + return mReady;
> +}
> +
> QString AccountEntry::accountId() const
> {
> if (mAccount.isNull()) {
> @@ -184,6 +188,7 @@
> onConnectionChanged();
> }
>
> + mReady = true;
> Q_EMIT accountReady();
> }
>
>
> === modified file 'libtelephonyservice/accountentry.h'
> --- libtelephonyservice/accountentry.h 2015-04-14 17:25:36 +0000
> +++ libtelephonyservice/accountentry.h 2015-05-08 21:57:41 +0000
> @@ -51,6 +51,7 @@
> GenericAccount
> };
>
> + bool ready() const;
> QString accountId() const;
> bool active() const;
> QString displayName() const;
> @@ -90,6 +91,7 @@
>
> Tp::AccountPtr mAccount;
> ConnectionInfo mConnectionInfo;
> + bool mReady;
> };
>
> #endif // ACCOUNTENTRY_H
>
> === modified file 'libtelephonyservice/callentry.cpp'
> --- libtelephonyservice/callentry.cpp 2015-02-06 20:44:14 +0000
> +++ libtelephonyservice/callentry.cpp 2015-05-08 21:57:41 +0000
> @@ -79,7 +79,7 @@
>
> // in case the account is an ofono account, we can check the voicemail number
> OfonoAccountEntry *ofonoAccount = qobject_cast<OfonoAccountEntry*>(mAccount);
> - if (ofonoAccount && ofonoAccount->voicemailNumber().isEmpty()) {
> + if (ofonoAccount && !ofonoAccount->voicemailNumber().isEmpty()) {
> setVoicemail(phoneNumber() == ofonoAccount->voicemailNumber());
> }
>
>
> === modified file 'libtelephonyservice/ofonoaccountentry.cpp'
> --- libtelephonyservice/ofonoaccountentry.cpp 2015-04-16 22:26:23 +0000
> +++ libtelephonyservice/ofonoaccountentry.cpp 2015-05-08 21:57:41 +0000
> @@ -20,8 +20,8 @@
> */
>
> #include "ofonoaccountentry.h"
> +#include "phoneutils.h"
> #include "telepathyhelper.h"
> -#include "phoneutils.h"
>
> OfonoAccountEntry::OfonoAccountEntry(const Tp::AccountPtr &account, QObject *parent) :
> AccountEntry(account, parent), mVoicemailCount(0), mVoicemailIndicator(false)
> @@ -181,6 +181,8 @@
> if (replyNumber.isValid()) {
> mVoicemailNumber = replyNumber.value();
> Q_EMIT voicemailNumberChanged();
> + } else {
> + qCritical() << "Could not get voicemail number!";
Yes, let me change that.
> }
>
> // connect the voicemail count changed signal
>
> === modified file 'libtelephonyservice/telepathyhelper.cpp'
> --- libtelephonyservice/telepathyhelper.cpp 2015-04-17 20:09:25 +0000
> +++ libtelephonyservice/telepathyhelper.cpp 2015-05-08 21:57:41 +0000
> @@ -451,6 +451,7 @@
> Q_EMIT activeAccountsChanged();
> onSettingsChanged("defaultSimForMessages");
> onSettingsChanged("defaultSimForCalls");
> + Q_EMIT accountAdded(accountEntry);
> }
>
> void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op)
>
> === modified file 'libtelephonyservice/telepathyhelper.h'
> --- libtelephonyservice/telepathyhelper.h 2015-04-17 20:09:25 +0000
> +++ libtelephonyservice/telepathyhelper.h 2015-05-08 21:57:41 +0000
> @@ -110,6 +110,7 @@
> void connectedChanged();
> void accountIdsChanged();
> void accountsChanged();
> + void accountAdded(AccountEntry *account);
> void phoneAccountsChanged();
> void activeAccountsChanged();
> void setupReady();
>
> === modified file 'tests/common/mock/connection.cpp'
> --- tests/common/mock/connection.cpp 2015-04-17 19:52:20 +0000
> +++ tests/common/mock/connection.cpp 2015-05-08 21:57:41 +0000
> @@ -77,7 +77,7 @@
>
> // init presence interface
> simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create();
> - simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresence));
> + simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresenceFail));
> simplePresenceIface->setMaxmimumStatusMessageLength(255);
> plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface));
>
> @@ -137,7 +137,7 @@
> plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface));
> voicemailIface->setVoicemailCount(mVoicemailCount);
> voicemailIface->setVoicemailIndicator(mVoicemailIndicator);
> - mVoicemailNumber = "555";
> + mVoicemailNumber = "*555";
>
> supplementaryServicesIface = BaseConnectionUSSDInterface::create();
> supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&MockConnection::USSDInitiate));
> @@ -151,6 +151,8 @@
> plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface));
>
> mDBus = new MockConnectionDBus(this);
> +
> + setOnline(true);
> }
>
> MockConnection::~MockConnection()
> @@ -232,6 +234,12 @@
> return selfHandle();
> }
>
> +uint MockConnection::setPresenceFail(const QString &status, const QString &statusMessage, Tp::DBusError *error)
> +{
> + error->set(TP_QT_ERROR_NOT_AVAILABLE, "Can't change online status: Operation not supported");
> + return selfHandle();
> +}
> +
> Tp::ContactAttributesMap MockConnection::getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error)
> {
> qDebug() << "getContactAttributes" << handles << ifaces;
>
> === modified file 'tests/common/mock/connection.h'
> --- tests/common/mock/connection.h 2015-04-17 19:52:20 +0000
> +++ tests/common/mock/connection.h 2015-05-08 21:57:41 +0000
> @@ -59,6 +59,7 @@
> uint targetHandle, const QVariantMap& hints, Tp::DBusError *error);
> Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error);
> uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error);
> + uint setPresenceFail(const QString& status, const QString& statusMessage, Tp::DBusError *error);
Yes, there is an equivalent exposed via DBus (SetPresence) that calls the method to simulate presence changes in the mock.
> void connect(Tp::DBusError *error);
> void setOnline(bool online);
>
>
> === modified file 'tests/common/mock/mockconnectiondbus.cpp'
> --- tests/common/mock/mockconnectiondbus.cpp 2015-04-17 19:52:20 +0000
> +++ tests/common/mock/mockconnectiondbus.cpp 2015-05-08 21:57:41 +0000
> @@ -93,121 +93,145 @@
>
> void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties)
> {
> + qDebug() << __PRETTY_FUNCTION__ << message << properties;
> mConnection->placeIncomingMessage(message, properties);
> }
>
> QString MockConnectionDBus::PlaceCall(const QVariantMap &properties)
> {
> + qDebug() << __PRETTY_FUNCTION__ << properties;
> return mConnection->placeCall(properties);
> }
>
> void MockConnectionDBus::HangupCall(const QString &callerId)
> {
> + qDebug() << __PRETTY_FUNCTION__ << callerId;
> mConnection->hangupCall(callerId);
> }
>
> void MockConnectionDBus::SetCallState(const QString &phoneNumber, const QString &state)
> {
> + qDebug() << __PRETTY_FUNCTION__ << phoneNumber << state;
> mConnection->setCallState(phoneNumber, state);
> }
>
> void MockConnectionDBus::SetOnline(bool online)
> {
> + qDebug() << __PRETTY_FUNCTION__ << online;
> mConnection->setOnline(online);
> }
>
> void MockConnectionDBus::SetPresence(const QString &status, const QString &statusMessage)
> {
> + qDebug() << __PRETTY_FUNCTION__ << status << statusMessage;
> Tp::DBusError error;
> mConnection->setPresence(status, statusMessage, &error);
> }
>
> void MockConnectionDBus::SetVoicemailIndicator(bool active)
> {
> + qDebug() << __PRETTY_FUNCTION__ << active;
> mConnection->setVoicemailIndicator(active);
> }
>
> void MockConnectionDBus::SetVoicemailNumber(const QString &number)
> {
> + qDebug() << __PRETTY_FUNCTION__ << number;
> mConnection->setVoicemailNumber(number);
> }
>
> void MockConnectionDBus::SetVoicemailCount(int count)
> {
> + qDebug() << __PRETTY_FUNCTION__ << count;
> mConnection->setVoicemailCount(count);
> }
>
> void MockConnectionDBus::SetEmergencyNumbers(const QStringList &numbers)
> {
> + qDebug() << __PRETTY_FUNCTION__ << numbers;
> mConnection->setEmergencyNumbers(numbers);
> }
>
> QString MockConnectionDBus::Serial()
> {
> + qDebug() << __PRETTY_FUNCTION__ << mConnection->serial();
> return mConnection->serial();
> }
>
> void MockConnectionDBus::TriggerUSSDNotificationReceived(const QString &message)
> {
> + qDebug() << __PRETTY_FUNCTION__ << message;
> mConnection->supplementaryServicesIface->NotificationReceived(message);
> }
>
> void MockConnectionDBus::TriggerUSSDRequestReceived(const QString &message)
> {
> + qDebug() << __PRETTY_FUNCTION__ << message;
> mConnection->supplementaryServicesIface->RequestReceived(message);
> }
>
> void MockConnectionDBus::TriggerUSSDInitiateUSSDComplete(const QString &ussdResp)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ussdResp;
> mConnection->supplementaryServicesIface->InitiateUSSDComplete(ussdResp);
> }
>
> void MockConnectionDBus::TriggerUSSDRespondComplete(bool success, const QString &ussdResp)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ussdResp;
> mConnection->supplementaryServicesIface->RespondComplete(success, ussdResp);
> }
>
> void MockConnectionDBus::TriggerUSSDBarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << cbService << cbMap;
> mConnection->supplementaryServicesIface->BarringComplete(ssOp, cbService, cbMap);
> }
>
> void MockConnectionDBus::TriggerUSSDForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << cfService << cfMap;
> mConnection->supplementaryServicesIface->ForwardingComplete(ssOp, cfService, cfMap);
> }
>
> void MockConnectionDBus::TriggerUSSDWaitingComplete(const QString &ssOp, const QVariantMap &cwMap)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << cwMap;
> mConnection->supplementaryServicesIface->WaitingComplete(ssOp, cwMap);
> }
>
> void MockConnectionDBus::TriggerUSSDCallingLinePresentationComplete(const QString &ssOp, const QString &status)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
> mConnection->supplementaryServicesIface->CallingLinePresentationComplete(ssOp, status);
> }
>
> void MockConnectionDBus::TriggerUSSDConnectedLinePresentationComplete(const QString &ssOp, const QString &status)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
> mConnection->supplementaryServicesIface->ConnectedLinePresentationComplete(ssOp, status);
> }
>
> void MockConnectionDBus::TriggerUSSDCallingLineRestrictionComplete(const QString &ssOp, const QString &status)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
> mConnection->supplementaryServicesIface->CallingLineRestrictionComplete(ssOp, status);
> }
>
> void MockConnectionDBus::TriggerUSSDConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)
> {
> + qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
> mConnection->supplementaryServicesIface->ConnectedLineRestrictionComplete(ssOp, status);
> }
>
> void MockConnectionDBus::TriggerUSSDInitiateFailed()
> {
> + qDebug() << __PRETTY_FUNCTION__;
> mConnection->supplementaryServicesIface->InitiateFailed();
> }
>
> void MockConnectionDBus::TriggerUSSDStateChanged(const QString &state)
> {
> + qDebug() << __PRETTY_FUNCTION__ << state;
> mConnection->supplementaryServicesIface->StateChanged(state);
> }
>
> === modified file 'tests/common/telepathytest.cpp'
> --- tests/common/telepathytest.cpp 2015-03-27 02:47:52 +0000
> +++ tests/common/telepathytest.cpp 2015-05-08 21:57:41 +0000
> @@ -17,7 +17,6 @@
> */
>
> #include <QtCore/QObject>
> -#include <QtTest/QtTest>
> #include <TelepathyQt/PendingAccount>
> #include <TelepathyQt/PendingOperation>
> #include <TelepathyQt/Account>
> @@ -29,15 +28,6 @@
> {
> Tp::registerTypes();
>
> - QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(setupReady()));
> - QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT);
> -
> - // just in case, remove any existing account that might be a leftover from
> - // previous test runs
> - Q_FOREACH(const AccountEntry *account, TelepathyHelper::instance()->accounts()) {
> - QVERIFY(removeAccount(account->account()));
> - }
> -
> // create an account manager instance to help testing
> Tp::Features accountFeatures;
> accountFeatures << Tp::Account::FeatureCore
> @@ -65,13 +55,15 @@
> mReady = false;
> connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore),
> &Tp::PendingOperation::finished, [=]{
> + Q_FOREACH(const Tp::AccountPtr &account, mAccountManager->allAccounts()) {
> + Tp::PendingOperation *op = account->remove();
> + WAIT_FOR(op->isFinished());
> + }
> +
> mReady = true;
> });
>
> - QTRY_VERIFY(mReady);
> -
> - // give some time for telepathy stuff to settle
> - QTest::qWait(1000);
> + TRY_VERIFY(mReady);
> }
>
> void TelepathyTest::doCleanup()
> @@ -101,9 +93,11 @@
> finished = true;
> });
>
> - while (!finished) {
> - QTest::qWait(100);
> - }
> + WAIT_FOR(finished);
> + WAIT_FOR(!account->connection().isNull());
> + WAIT_FOR(account->connectionStatus() == Tp::ConnectionStatusConnected);
> + WAIT_FOR(account->connection()->selfContact()->presence().type() == Tp::ConnectionPresenceTypeAvailable);
> +
> mAccounts << account;
> return account;
> }
> @@ -119,9 +113,8 @@
> finished = true;
> });
>
> - while (!finished) {
> - QTest::qWait(100);
> - }
> + WAIT_FOR(finished);
> +
> if (success) {
> mAccounts.removeAll(account);
> }
>
> === modified file 'tests/common/telepathytest.h'
> --- tests/common/telepathytest.h 2015-03-30 18:48:38 +0000
> +++ tests/common/telepathytest.h 2015-05-08 21:57:41 +0000
> @@ -20,11 +20,17 @@
> #define TELEPATHYTEST_H
>
> #include <QtCore/QObject>
> +#include <QtTest/QtTest>
> #include <TelepathyQt/Account>
> -#include "telepathyhelper.h"
> +#include <TelepathyQt/AccountManager>
>
> #define DEFAULT_TIMEOUT 15000
>
> +#define TRY_VERIFY(x) QTRY_VERIFY_WITH_TIMEOUT((x), DEFAULT_TIMEOUT)
> +#define TRY_COMPARE(x, y) QTRY_COMPARE_WITH_TIMEOUT((x), (y), DEFAULT_TIMEOUT)
> +
> +#define WAIT_FOR(x) while (!(x)) { qDebug() << "Waiting for:" << #x ; QTest::qWait(100); }
> +
> class TelepathyTest : public QObject
> {
> Q_OBJECT
>
> === modified file 'tests/handler/HandlerTest.cpp'
> --- tests/handler/HandlerTest.cpp 2015-04-17 21:26:25 +0000
> +++ tests/handler/HandlerTest.cpp 2015-05-08 21:57:41 +0000
> @@ -53,22 +53,19 @@
> {
> initialize();
>
> + QSignalSpy setupReadySpy(TelepathyHelper::instance(), SIGNAL(setupReady()));
> + TRY_COMPARE(setupReadySpy.count(), 1);
> +
> // register the approver
> mApprover = new Approver(this);
> TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");
> // Tp-qt does not set registered status to approvers
> - QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));
> + TRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));
> }
>
> void HandlerTest::init()
> {
> mTpAccount = addAccount("mock", "mock", "the account");
> - QVERIFY(!mTpAccount.isNull());
> - QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
> -
> - // make sure the connection is available
> - QTRY_VERIFY(!mTpAccount->connection().isNull());
> - QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
>
> // and create the mock controller
> mMockController = new MockController("mock", this);
> @@ -86,7 +83,7 @@
> QSignalSpy callReceivedSpy(mMockController, SIGNAL(CallReceived(QString)));
> // FIXME: add support for multiple accounts
> HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier());
> - QTRY_COMPARE(callReceivedSpy.count(), 1);
> + TRY_COMPARE(callReceivedSpy.count(), 1);
> QCOMPARE(callReceivedSpy.first().first().toString(), callerId);
>
> mMockController->HangupCall(callerId);
> @@ -105,7 +102,7 @@
> QVERIFY(!objectPath.isEmpty());
>
> // wait for the channel to hit the approver
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
>
> waitForCallActive(callerId);
> @@ -113,7 +110,7 @@
> // and finally request the hangup
> QSignalSpy callEndedSpy(mMockController, SIGNAL(CallEnded(QString)));
> HandlerController::instance()->hangUpCall(objectPath);
> - QTRY_COMPARE(callEndedSpy.count(), 1);
> + TRY_COMPARE(callEndedSpy.count(), 1);
> }
>
> void HandlerTest::testCallHold()
> @@ -129,7 +126,7 @@
> QVERIFY(!objectPath.isEmpty());
>
> // wait for the channel to hit the approver
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
>
> waitForCallActive(callerId);
> @@ -138,13 +135,13 @@
>
> // set the call on hold
> HandlerController::instance()->setHold(objectPath, true);
> - QTRY_COMPARE(callStateSpy.count(), 1);
> + TRY_COMPARE(callStateSpy.count(), 1);
> QCOMPARE(callStateSpy.first()[2].toString(), QString("held"));
>
> // and now set it as unheld again
> callStateSpy.clear();
> HandlerController::instance()->setHold(objectPath, false);
> - QTRY_COMPARE(callStateSpy.count(), 1);
> + TRY_COMPARE(callStateSpy.count(), 1);
> QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));
>
> mMockController->HangupCall(callerId);
> @@ -163,11 +160,11 @@
> mMockController->placeCall(properties);
>
> // wait for the channel to hit the approver
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
>
> // wait until the call properties are changed
> - QTRY_VERIFY(handlerCallPropertiesSpy.count() > 0);
> + TRY_VERIFY(handlerCallPropertiesSpy.count() > 0);
> QString objectPath = handlerCallPropertiesSpy.last()[0].toString();
> QVariantMap propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();
> QVERIFY(!propsFromSignal.isEmpty());
> @@ -194,7 +191,7 @@
> for (int i = 0; i < dtmfString.length(); ++i) {
> HandlerController::instance()->sendDTMF(objectPath, QString(dtmfString[i]));
> }
> - QTRY_COMPARE(handlerCallPropertiesSpy.count(), dtmfString.length());
> + TRY_COMPARE(handlerCallPropertiesSpy.count(), dtmfString.length());
> propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();
> propsFromMethod = HandlerController::instance()->getCallProperties(objectPath);
> QString dtmfStringFromSignal = propsFromSignal["dtmfString"].toString();
> @@ -220,7 +217,7 @@
> QString call1 = mMockController->placeCall(properties);
>
> // wait for the channel to hit the approver
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
> approverCallSpy.clear();
> waitForCallActive(callerId1);
> @@ -229,7 +226,7 @@
> properties["Caller"] = callerId2;
> QString call2 = mMockController->placeCall(properties);
> // wait for the channel to hit the approver
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
> approverCallSpy.clear();
> waitForCallActive(callerId2);
> @@ -237,13 +234,13 @@
> // now create the conf call
> QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(ConferenceCreated(QString)));
> HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);
> - QTRY_COMPARE(conferenceCreatedSpy.count(), 1);
> + TRY_COMPARE(conferenceCreatedSpy.count(), 1);
> QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();
>
> // now place a third call and try to merge it
> properties["Caller"] = callerId3;
> QString call3 = mMockController->placeCall(properties);
> - QTRY_COMPARE(approverCallSpy.count(), 1);
> + TRY_COMPARE(approverCallSpy.count(), 1);
> mApprover->acceptCall();
> approverCallSpy.clear();
> waitForCallActive(callerId3);
> @@ -251,13 +248,13 @@
> // merge that call on the conference
> QSignalSpy channelMergedSpy(mMockController, SIGNAL(ChannelMerged(QString)));
> HandlerController::instance()->mergeCall(conferenceObjectPath, call3);
> - QTRY_COMPARE(channelMergedSpy.count(), 1);
> + TRY_COMPARE(channelMergedSpy.count(), 1);
> QCOMPARE(channelMergedSpy.first().first().toString(), call3);
>
> // now try to split one of the channels
> QSignalSpy channelSplittedSpy(mMockController, SIGNAL(ChannelSplitted(QString)));
> HandlerController::instance()->splitCall(call2);
> - QTRY_COMPARE(channelSplittedSpy.count(), 1);
> + TRY_COMPARE(channelSplittedSpy.count(), 1);
> QCOMPARE(channelSplittedSpy.first().first().toString(), call2);
>
> // now hangup the conference and the individual channels
> @@ -277,7 +274,7 @@
> QSignalSpy messageSentSpy(mMockController, SIGNAL(MessageSent(QString,QVariantMap)));
> // FIXME: add support for multiple accounts
> HandlerController::instance()->sendMessage(recipient, message, mTpAccount->uniqueIdentifier());
> - QTRY_COMPARE(messageSentSpy.count(), 1);
> + TRY_COMPARE(messageSentSpy.count(), 1);
> QString sentMessage = messageSentSpy.first().first().toString();
> QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();
> QCOMPARE(sentMessage, message);
> @@ -293,14 +290,14 @@
>
> // set the property to true
> HandlerController::instance()->setCallIndicatorVisible(true);
> - QTRY_COMPARE(spy.count(), 1);
> + TRY_COMPARE(spy.count(), 1);
> QVERIFY(spy.first().first().toBool());
> QVERIFY(HandlerController::instance()->callIndicatorVisible());
>
> // and back to false
> spy.clear();
> HandlerController::instance()->setCallIndicatorVisible(false);
> - QTRY_COMPARE(spy.count(), 1);
> + TRY_COMPARE(spy.count(), 1);
> QVERIFY(!spy.first().first().toBool());
> QVERIFY(!HandlerController::instance()->callIndicatorVisible());
> }
> @@ -314,7 +311,7 @@
> QString caller;
> int tries = 0;
> while (state != "active" && caller != callerId && tries < 5) {
> - QTRY_COMPARE(callStateSpy.count(), 1);
> + TRY_COMPARE(callStateSpy.count(), 1);
> caller = callStateSpy.first()[0].toString();
> objectPath = callStateSpy.first()[1].toString();
> state = callStateSpy.first()[2].toString();
>
> === modified file 'tests/libtelephonyservice/AccountEntryTest.cpp'
> --- tests/libtelephonyservice/AccountEntryTest.cpp 2015-04-21 17:04:29 +0000
> +++ tests/libtelephonyservice/AccountEntryTest.cpp 2015-05-08 21:57:41 +0000
> @@ -21,7 +21,6 @@
> #include "telepathytest.h"
> #include "accountentry.h"
> #include "accountentryfactory.h"
> -#include "telepathyhelper.h"
> #include "mockcontroller.h"
>
> class AccountEntryTest : public TelepathyTest
> @@ -61,21 +60,19 @@
> {
> mTpAccount = addAccount("mock", "mock", "the account");
> QVERIFY(!mTpAccount.isNull());
> - QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
>
> mAccount = AccountEntryFactory::createEntry(mTpAccount, this);
> QVERIFY(mAccount);
> + TRY_VERIFY(mAccount->ready());
>
> // make sure the connection is available
> - QTRY_VERIFY(!mTpAccount->connection().isNull());
> - QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
> - QTRY_VERIFY(mAccount->connected());
> + TRY_VERIFY(mAccount->connected());
> +
> + // and make sure the status and status message are the ones we expect
> + TRY_COMPARE(mAccount->status(), QString("available"));
>
> // and create the mock controller
> mMockController = new MockController("mock", this);
> -
> - // just in case, wait some time
> - QTest::qWait(1000);
> }
>
> void AccountEntryTest::cleanup()
> @@ -94,21 +91,23 @@
>
> void AccountEntryTest::testActive()
> {
> + // the mock account is enabled/connected by default, so make sure it is like that
> + QVERIFY(mAccount->active());
> + // FIXME: setting the account as offline, triggers an automatic reconnection and the
> + // test fails. In the future we might want to re-enable this and test some other way.
> QSignalSpy activeChangedSpy(mAccount, SIGNAL(activeChanged()));
>
> - // the mock account is enabled/connected by default, so make sure it is like that
> - QVERIFY(mAccount->active());
> -
> - // now set the account offline and see if the active flag changes correctly
> + // now set the account away and see if the active flag changes correctly
> mMockController->SetOnline(false);
> - QTRY_VERIFY(!mAccount->active());
> - QCOMPARE(activeChangedSpy.count(), 1);
> + TRY_VERIFY(!mAccount->active());
> + TRY_VERIFY(activeChangedSpy.count() > 0);
> +
>
> // now re-enable the account and check that the entry is updated
> activeChangedSpy.clear();
> mMockController->SetOnline(true);
> - QTRY_VERIFY(mAccount->active());
> - QCOMPARE(activeChangedSpy.count(), 1);
> + TRY_VERIFY(activeChangedSpy.count() > 0);
> + QVERIFY(mAccount->active());
>
> // check that for a null account active is false
> QVERIFY(!mNullAccount->active());
> @@ -124,14 +123,14 @@
> // now try to set the display in the telepathy account directly and see that the entry gets updated
> QString newDisplayName = "some other display name";
> mTpAccount->setDisplayName(newDisplayName);
> - QTRY_COMPARE(mAccount->displayName(), newDisplayName);
> + TRY_COMPARE(mAccount->displayName(), newDisplayName);
> QCOMPARE(displayNameChangedSpy.count(), 1);
>
> // and try setting the display name in the entry itself
> displayNameChangedSpy.clear();
> newDisplayName = "changing again";
> mAccount->setDisplayName(newDisplayName);
> - QTRY_COMPARE(mAccount->displayName(), newDisplayName);
> + TRY_COMPARE(mAccount->displayName(), newDisplayName);
> QCOMPARE(displayNameChangedSpy.count(), 1);
> QCOMPARE(mTpAccount->displayName(), newDisplayName);
>
> @@ -147,11 +146,10 @@
> QCOMPARE(mAccount->status(), mTpAccount->connection()->selfContact()->presence().status());
>
> // and now set a new value
> - Tp::Presence presence(Tp::ConnectionPresenceTypeAway, "away", "away");
> - mTpAccount->setRequestedPresence(presence);
> + mMockController->SetPresence("away", "away");
>
> - QTRY_COMPARE(mAccount->status(), QString("away"));
> - QTRY_COMPARE(statusChangedSpy.count(), 1);
> + TRY_COMPARE(statusChangedSpy.count(), 1);
> + QCOMPARE(mAccount->status(), QString("away"));
>
> // check that for a null account the status is null
> QVERIFY(mNullAccount->status().isNull());
> @@ -162,14 +160,14 @@
> QSignalSpy statusMessageChangedSpy(mAccount, SIGNAL(statusMessageChanged()));
>
> // check that the value is correct already
> - QTRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage());
> + TRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage());
>
> // and now set a new value
> QString statusMessage("I am online");
> mMockController->SetPresence("available", statusMessage);
>
> - QTRY_COMPARE(mAccount->statusMessage(), statusMessage);
> - QTRY_COMPARE(statusMessageChangedSpy.count(), 1);
> + TRY_COMPARE(statusMessageChangedSpy.count(), 1);
> + QCOMPARE(mAccount->statusMessage(), statusMessage);
>
> // check that for a null account the displayName is null
> QVERIFY(mNullAccount->statusMessage().isNull());
> @@ -183,18 +181,16 @@
> QVERIFY(mAccount->connected());
>
> // now set the account offline and see if the active flag changes correctly
> - mMockController->SetOnline(false);
> - QTRY_VERIFY(!mAccount->connected());
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> -
> - // it shouldn't be necessary, but in any case
> - QTest::qWait(500);
> + mMockController->SetPresence("away", "away");
> + TRY_VERIFY(connectedChangedSpy.count() > 0);
> + TRY_VERIFY(!mAccount->connected());
>
> // now re-enable the account and check that the entry is updated
> connectedChangedSpy.clear();
> - mMockController->SetOnline(true);
> - QTRY_VERIFY(mAccount->connected());
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> + mMockController->SetPresence("available", "online");
> + // because of the way the mock was implemented, sometimes this can return two connectedChanged() signals.
> + TRY_VERIFY(connectedChangedSpy.count() > 0);
> + TRY_VERIFY(mAccount->connected());
>
> // check that for a null account the displayName is null
> QVERIFY(!mNullAccount->connected());
>
> === modified file 'tests/libtelephonyservice/CMakeLists.txt'
> --- tests/libtelephonyservice/CMakeLists.txt 2015-04-22 13:44:53 +0000
> +++ tests/libtelephonyservice/CMakeLists.txt 2015-05-08 21:57:41 +0000
> @@ -34,6 +34,7 @@
>
> generate_telepathy_test(AccountEntryFactoryTest SOURCES AccountEntryFactoryTest.cpp)
> generate_telepathy_test(AccountEntryTest SOURCES AccountEntryTest.cpp)
> +generate_telepathy_test(CallEntryTest SOURCES CallEntryTest.cpp)
> generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp)
> generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp)
> generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp)
>
> === added file 'tests/libtelephonyservice/CallEntryTest.cpp'
> --- tests/libtelephonyservice/CallEntryTest.cpp 1970-01-01 00:00:00 +0000
> +++ tests/libtelephonyservice/CallEntryTest.cpp 2015-05-08 21:57:41 +0000
> @@ -0,0 +1,129 @@
> +/*
> + * Copyright (C) 2015 Canonical, Ltd.
> + *
> + * This file is part of telephony-service.
> + *
> + * telephony-service is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 3.
> + *
> + * telephony-service is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <QtCore/QObject>
> +#include <QtTest/QtTest>
> +#include "telepathytest.h"
> +#include "callentry.h"
> +#include "callmanager.h"
> +#include "telepathyhelper.h"
> +#include "mockcontroller.h"
> +#include "ofonoaccountentry.h"
> +#include "accountentryfactory.h"
> +
> +Q_DECLARE_METATYPE(AccountEntry*)
> +
> +class CallEntryTest : public TelepathyTest
> +{
> + Q_OBJECT
> +
> +private Q_SLOTS:
> + void initTestCase();
> + void init();
> + void cleanup();
> + void testIsVoicemail_data();
> + void testIsVoicemail();
> +
> +protected Q_SLOTS:
> + void onCallChannelAvailable(const Tp::CallChannelPtr &channel);
> +
> +private:
> + Tp::AccountPtr mTpAccount;
> + OfonoAccountEntry *mAccount;
> + Tp::CallChannelPtr mCallChannel;
> + MockController *mMockController;
> +};
> +
> +void CallEntryTest::initTestCase()
> +{
> + qRegisterMetaType<AccountEntry*>();
> + initialize();
> + TelepathyHelper::instance()->registerChannelObserver();
> + connect(TelepathyHelper::instance()->channelObserver(),
> + SIGNAL(callChannelAvailable(Tp::CallChannelPtr)),
> + SLOT(onCallChannelAvailable(Tp::CallChannelPtr)));
> +}
> +
> +void CallEntryTest::init()
> +{
> + QSignalSpy accountSpy(TelepathyHelper::instance(), SIGNAL(accountAdded(AccountEntry*)));
> + mTpAccount = addAccount("mock", "ofono", "the account");
> + QVERIFY(!mTpAccount.isNull());
> + TRY_COMPARE(accountSpy.count(), 1);
> + mAccount = qobject_cast<OfonoAccountEntry*>(accountSpy.first().first().value<AccountEntry*>());
> + QVERIFY(mAccount);
> + TRY_VERIFY(mAccount->ready());
> + TRY_COMPARE(mAccount->status(), QString("available"));
> +
> + // and create the mock controller
> + mMockController = new MockController("ofono", this);
> +}
> +
> +void CallEntryTest::cleanup()
> +{
> + doCleanup();
> +
> + mMockController->deleteLater();
> + mAccount->deleteLater();
> + mCallChannel = Tp::CallChannelPtr();
> +
> + // wait until all the calls are gone before the next test
> + TRY_VERIFY(!CallManager::instance()->hasCalls());
> +}
> +
> +void CallEntryTest::testIsVoicemail_data()
> +{
> + QTest::addColumn<QString>("voicemailNumber");
> + QTest::addColumn<QString>("callNumber");
> + QTest::addColumn<bool>("isVoicemail");
> +
> + QTest::newRow("calling voicemail") << "*1234" << "*1234" << true;
> + QTest::newRow("calling other number") << "*1234" << "5555555" << false;
> +}
> +
> +void CallEntryTest::testIsVoicemail()
> +{
> + QFETCH(QString, voicemailNumber);
> + QFETCH(QString, callNumber);
> + QFETCH(bool, isVoicemail);
> +
> + mMockController->SetVoicemailNumber(voicemailNumber);
> + TRY_COMPARE(mAccount->voicemailNumber(), voicemailNumber);
> +
> + // now place a call to a number that is not the voicemail number
> + QVariantMap properties;
> + properties["Caller"] = callNumber;
> + properties["State"] = "incoming";
> + mMockController->placeCall(properties);
> + TRY_VERIFY(!mCallChannel.isNull());
> + QCOMPARE(mCallChannel->targetContact()->id(), callNumber);
> +
> + CallEntry *callEntry = new CallEntry(mCallChannel);
> + QCOMPARE(callEntry->isVoicemail(), isVoicemail);
> +
> + callEntry->endCall();
> + callEntry->deleteLater();
> +}
> +
> +void CallEntryTest::onCallChannelAvailable(const Tp::CallChannelPtr &channel)
> +{
> + mCallChannel = channel;
> +}
> +
> +QTEST_MAIN(CallEntryTest)
> +#include "CallEntryTest.moc"
>
> === modified file 'tests/libtelephonyservice/ChatManagerTest.cpp'
> --- tests/libtelephonyservice/ChatManagerTest.cpp 2015-04-17 21:26:25 +0000
> +++ tests/libtelephonyservice/ChatManagerTest.cpp 2015-05-08 21:57:41 +0000
> @@ -47,21 +47,16 @@
> void ChatManagerTest::initTestCase()
> {
> initialize();
> -
> TelepathyHelper::instance()->registerChannelObserver();
> -
> - // just give telepathy some time to register the observer
> - QTest::qWait(1000);
> }
>
> void ChatManagerTest::init()
> {
> // add two accounts
> mGenericTpAccount = addAccount("mock", "mock", "the generic account");
> - QTRY_VERIFY(!mGenericTpAccount->connection().isNull());
> -
> + QVERIFY(!mGenericTpAccount.isNull());
> mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");
> - QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());
> + QVERIFY(!mPhoneTpAccount.isNull());
>
> // and create the mock controller
> mGenericMockController = new MockController("mock", this);
> @@ -103,7 +98,7 @@
>
> ChatManager::instance()->sendMessage(recipients, message, accountId);
>
> - QTRY_COMPARE(controllerMessageSentSpy.count(), 1);
> + TRY_COMPARE(controllerMessageSentSpy.count(), 1);
> QString messageText = controllerMessageSentSpy.first()[0].toString();
> QVariantMap messageProperties = controllerMessageSentSpy.first()[1].toMap();
> QStringList messageRecipients = messageProperties["Recipients"].toStringList();
> @@ -111,7 +106,7 @@
> QCOMPARE(messageText, message);
> QCOMPARE(messageRecipients, recipients);
>
> - QTRY_COMPARE(messageSentSpy.count(), 1);
> + TRY_COMPARE(messageSentSpy.count(), 1);
> messageRecipients = messageSentSpy.first()[0].toStringList();
> qSort(messageRecipients);
> messageText = messageSentSpy.first()[1].toString();
> @@ -129,7 +124,7 @@
> QString message("Hi there");
> mGenericMockController->PlaceIncomingMessage(message, properties);
>
> - QTRY_COMPARE(messageReceivedSpy.count(), 1);
> + TRY_COMPARE(messageReceivedSpy.count(), 1);
> QString sender = messageReceivedSpy.first()[0].toString();
> QString receivedMessage = messageReceivedSpy.first()[1].toString();
> QCOMPARE(sender, properties["Sender"].toString());
> @@ -147,9 +142,10 @@
> messages << "Hi there" << "How are you" << "Always look on the bright side of life";
> Q_FOREACH(const QString &message, messages) {
> mGenericMockController->PlaceIncomingMessage(message, properties);
> - QTest::qWait(100);
> + // the wait shouldn't be needed, but just in case
> + QTest::qWait(50);
> }
> - QTRY_COMPARE(messageReceivedSpy.count(), messages.count());
> + TRY_COMPARE(messageReceivedSpy.count(), messages.count());
>
> QStringList messageIds;
> for (int i = 0; i < messages.count(); ++i) {
> @@ -162,7 +158,7 @@
> ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0");
> }
>
> - QTRY_COMPARE(messageReadSpy.count(), messageIds.count());
> + TRY_COMPARE(messageReadSpy.count(), messageIds.count());
> QStringList receivedIds;
> for (int i = 0; i < messageReadSpy.count(); ++i) {
> receivedIds << messageReadSpy[i][0].toString();
>
> === modified file 'tests/libtelephonyservice/OfonoAccountEntryTest.cpp'
> --- tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-04-22 14:26:41 +0000
> +++ tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-05-08 21:57:41 +0000
> @@ -61,21 +61,18 @@
> {
> mTpAccount = addAccount("mock", "ofono", "phone account");
> QVERIFY(!mTpAccount.isNull());
> - QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
> -
> mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this));
> QVERIFY(mAccount);
> + TRY_VERIFY(mAccount->ready());
>
> // make sure the connection is available
> - QTRY_VERIFY(!mTpAccount->connection().isNull());
> - QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
> - QTRY_VERIFY(mAccount->connected());
> + TRY_VERIFY(mAccount->connected());
> +
> + // and make sure the status and status message are the ones we expect
> + TRY_COMPARE(mAccount->status(), QString("available"));
>
> // create the mock controller
> mMockController = new MockController("ofono", this);
> -
> - // just in case, wait some time
> - QTest::qWait(1000);
> }
>
> void OfonoAccountEntryTest::cleanup()
> @@ -93,22 +90,23 @@
> void OfonoAccountEntryTest::testConnected()
> {
> // the mock account is enabled/connected by default, so make sure it is like that
> - QTRY_VERIFY(mAccount->connected());
> + TRY_VERIFY(mAccount->connected());
>
> // right now the ofono account connection status behave exactly like the generic class,
> // but as the code path is different, test it again
> QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));
>
> // now set the account offline and see if the active flag changes correctly
> - mMockController->SetOnline(false);
> - QTRY_VERIFY(!mAccount->connected());
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> + mMockController->SetPresence("away", "away");
> + TRY_VERIFY(connectedChangedSpy.count() > 0);
> + TRY_VERIFY(!mAccount->connected());
>
> // now re-enable the account and check that the entry is updated
> connectedChangedSpy.clear();
> - mMockController->SetOnline(true);
> - QTRY_VERIFY(mAccount->connected());
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> + mMockController->SetPresence("available", "online");
> + // because of the way the mock was implemented, sometimes this can return two connectedChanged() signals.
> + TRY_VERIFY(connectedChangedSpy.count() > 0);
> + TRY_VERIFY(mAccount->connected());
> }
>
> void OfonoAccountEntryTest::testCompareIds_data()
> @@ -142,7 +140,7 @@
> numbers << "111" << "190" << "911";
> qSort(numbers);
> mMockController->SetEmergencyNumbers(numbers);
> - QTRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);
> + TRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);
>
> QStringList emergencyNumbers = mAccount->emergencyNumbers();
> qSort(emergencyNumbers);
> @@ -152,7 +150,7 @@
>
> void OfonoAccountEntryTest::testSerial()
> {
> - QTRY_COMPARE(mAccount->serial(), mMockController->serial());
> + TRY_COMPARE(mAccount->serial(), mMockController->serial());
> }
>
> void OfonoAccountEntryTest::testVoicemailIndicator()
> @@ -164,27 +162,27 @@
>
> // set to true
> mMockController->SetVoicemailIndicator(true);
> - QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
> - QTRY_VERIFY(mAccount->voicemailIndicator());
> + TRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
> + QVERIFY(mAccount->voicemailIndicator());
>
> // and set back to false
> voiceMailIndicatorSpy.clear();
> mMockController->SetVoicemailIndicator(false);
> - QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
> - QTRY_VERIFY(!mAccount->voicemailIndicator());
> + TRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
> + QVERIFY(!mAccount->voicemailIndicator());
> }
>
> void OfonoAccountEntryTest::testVoicemailNumber()
> {
> + // check that the number is not empty at startup
> + TRY_VERIFY(!mAccount->voicemailNumber().isEmpty());
> +
> QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged()));
>
> - // check that the number is not empty at startup
> - QTRY_VERIFY(!mAccount->voicemailNumber().isEmpty());
> -
> // try changing the number
> QString number("12345");
> mMockController->SetVoicemailNumber(number);
> - QTRY_COMPARE(voicemailNumberSpy.count(), 1);
> + TRY_COMPARE(voicemailNumberSpy.count(), 1);
> QCOMPARE(mAccount->voicemailNumber(), number);
> }
>
> @@ -198,13 +196,13 @@
> // set it to a bigger value
> int count = 10;
> mMockController->SetVoicemailCount(count);
> - QTRY_COMPARE(voicemailCountSpy.count(), 1);
> + TRY_COMPARE(voicemailCountSpy.count(), 1);
> QCOMPARE((int)mAccount->voicemailCount(), count);
>
> // and back to zero
> voicemailCountSpy.clear();
> mMockController->SetVoicemailCount(0);
> - QTRY_COMPARE(voicemailCountSpy.count(), 1);
> + TRY_COMPARE(voicemailCountSpy.count(), 1);
> QCOMPARE((int)mAccount->voicemailCount(), 0);
> }
>
> @@ -217,7 +215,7 @@
>
> // now try to set the status to simlocked
> mMockController->SetPresence("simlocked", "simlocked");
> - QTRY_COMPARE(simLockedSpy.count(), 1);
> + TRY_COMPARE(simLockedSpy.count(), 1);
> QVERIFY(mAccount->simLocked());
> }
>
> @@ -246,7 +244,7 @@
> QFETCH(bool, available);
>
> mMockController->SetPresence(status, "");
> - QTRY_COMPARE(mAccount->status(), status);
> + TRY_COMPARE(mAccount->status(), status);
> QCOMPARE(mAccount->emergencyCallsAvailable(), available);
> }
>
> @@ -258,8 +256,8 @@
> QString statusMessage("SomeNetwork");
> mMockController->SetPresence("available", statusMessage);
>
> - QTRY_COMPARE(mAccount->networkName(), statusMessage);
> - QTRY_COMPARE(networkNameChangedSpy.count(), 1);
> + TRY_COMPARE(networkNameChangedSpy.count(), 1);
> + QCOMPARE(mAccount->networkName(), statusMessage);
> }
>
> void OfonoAccountEntryTest::testAddressableVCardFields()
>
> === modified file 'tests/libtelephonyservice/TelepathyHelperTest.cpp'
> --- tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-04-21 16:47:31 +0000
> +++ tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-05-08 21:57:41 +0000
> @@ -27,6 +27,8 @@
> #include "telepathyhelper.h"
> #include "mockcontroller.h"
>
> +Q_DECLARE_METATYPE(AccountEntry*)
> +
> class TelepathyHelperTest : public TelepathyTest
> {
> Q_OBJECT
> @@ -45,6 +47,11 @@
> void testAccountForConnection();
> void testEmergencyCallsAvailable();
>
> +protected:
> + Tp::AccountPtr addAccountAndWait(const QString &manager,
> + const QString &protocol,
> + const QString &displayName,
> + const QVariantMap ¶meters = QVariantMap());
> private:
> Tp::AccountPtr mGenericTpAccount;
> Tp::AccountPtr mPhoneTpAccount;
> @@ -54,24 +61,24 @@
>
> void TelepathyHelperTest::initTestCase()
> {
> + qRegisterMetaType<AccountEntry*>();
> initialize();
> + QSignalSpy setupReadySpy(TelepathyHelper::instance(), SIGNAL(setupReady()));
> + TRY_COMPARE(setupReadySpy.count(), 1);
> }
>
> void TelepathyHelperTest::init()
> {
> // add two accounts
> - mGenericTpAccount = addAccount("mock", "mock", "the generic account");
> - QTRY_VERIFY(!mGenericTpAccount->connection().isNull());
> + mGenericTpAccount = addAccountAndWait("mock", "mock", "the generic account");
> + QVERIFY(!mGenericTpAccount.isNull());
>
> - mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");
> - QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());
> + mPhoneTpAccount = addAccountAndWait("mock", "ofono", "the phone account");
> + QVERIFY(!mPhoneTpAccount.isNull());
>
> // and create the mock controller
> mGenericController = new MockController("mock", this);
> mPhoneController = new MockController("ofono", this);
> -
> - // just in case, wait some time
> - QTest::qWait(1000);
> }
>
> void TelepathyHelperTest::cleanup()
> @@ -98,13 +105,13 @@
>
> // and set the other account as offline too. This time connected needs to change to false
> mPhoneController->SetOnline(false);
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> + TRY_COMPARE(connectedChangedSpy.count(), 1);
> QVERIFY(!TelepathyHelper::instance()->connected());
>
> // now set one of the accounts back online
> connectedChangedSpy.clear();
> mPhoneController->SetOnline(true);
> - QTRY_COMPARE(connectedChangedSpy.count(), 1);
> + TRY_COMPARE(connectedChangedSpy.count(), 1);
> QVERIFY(TelepathyHelper::instance()->connected());
>
> // and the other one just in case
> @@ -124,10 +131,10 @@
>
> // now check that new accounts are captured
> QSignalSpy accountsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountsChanged()));
> - Tp::AccountPtr newAccount = addAccount("mock", "mock", "extra");
> + Tp::AccountPtr newAccount = addAccountAndWait("mock", "mock", "extra");
> QVERIFY(!newAccount.isNull());
>
> - QTRY_COMPARE(accountsChangedSpy.count(), 1);
> + TRY_COMPARE(accountsChangedSpy.count(), 1);
> QCOMPARE(TelepathyHelper::instance()->accounts().count(), 3);
>
> bool accountFound = false;
> @@ -142,7 +149,7 @@
> // now remove the extra account and make sure it is properly removed
> accountsChangedSpy.clear();
> QVERIFY(removeAccount(newAccount));
> - QTRY_COMPARE(accountsChangedSpy.count(), 1);
> + TRY_COMPARE(accountsChangedSpy.count(), 1);
> QCOMPARE(TelepathyHelper::instance()->accounts().count(), 2);
> QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), first->accountId());
> QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());
> @@ -184,15 +191,15 @@
> // create two accounts with modem-objpath parameters and make sure they are listed first
> QVariantMap parameters;
> parameters["modem-objpath"] = "/phonesim1";
> - Tp::AccountPtr firstAccount = addAccount("mock", "ofono", "firstPhoneAccount", parameters);
> + Tp::AccountPtr firstAccount = addAccountAndWait("mock", "ofono", "firstPhoneAccount", parameters);
> QVERIFY(!firstAccount.isNull());
>
> parameters["modem-objpath"] = "/phonesim2";
> - Tp::AccountPtr secondAccount = addAccount("mock", "ofono", "secondPhoneAccount", parameters);
> + Tp::AccountPtr secondAccount = addAccountAndWait("mock", "ofono", "secondPhoneAccount", parameters);
> QVERIFY(!secondAccount.isNull());
>
> // wait for the accounts to appear;
> - QTRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 4);
> + TRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 4);
>
> // and check the order
> QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), firstAccount->uniqueIdentifier());
> @@ -200,11 +207,11 @@
>
> // now add a third account that should go before the two others
> parameters["modem-objpath"] = "/phonesim0";
> - Tp::AccountPtr thirdAccount = addAccount("mock", "ofono", "thirdPhoneAccount", parameters);
> + Tp::AccountPtr thirdAccount = addAccountAndWait("mock", "ofono", "thirdPhoneAccount", parameters);
> QVERIFY(!thirdAccount.isNull());
>
> // wait for the accounts to appear;
> - QTRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 5);
> + TRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 5);
> QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), thirdAccount->uniqueIdentifier());
>
> // and remove the created accounts
> @@ -219,10 +226,10 @@
>
> // now check that new accounts are captured
> QSignalSpy accountIdsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountIdsChanged()));
> - Tp::AccountPtr newAccount = addAccount("mock", "mock", "extra");
> + Tp::AccountPtr newAccount = addAccountAndWait("mock", "mock", "extra");
> QVERIFY(!newAccount.isNull());
>
> - QTRY_COMPARE(accountIdsChangedSpy.count(), 1);
> + TRY_COMPARE(accountIdsChangedSpy.count(), 1);
> QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 3);
>
> // just to make sure check that each account id matches one account
> @@ -233,7 +240,7 @@
> // now remove the extra account and make sure it is properly removed
> accountIdsChangedSpy.clear();
> QVERIFY(removeAccount(newAccount));
> - QTRY_COMPARE(accountIdsChangedSpy.count(), 1);
> + TRY_COMPARE(accountIdsChangedSpy.count(), 1);
> QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 2);
> QCOMPARE(TelepathyHelper::instance()->accountIds()[0], TelepathyHelper::instance()->accounts()[0]->accountId());
> QCOMPARE(TelepathyHelper::instance()->accountIds()[1], TelepathyHelper::instance()->accounts()[1]->accountId());
> @@ -248,22 +255,22 @@
>
> // now set one of the accounts as offline and make sure it is captured
> mGenericController->SetOnline(false);
> - QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);
> + TRY_COMPARE(activeAccountsSpy.count(), 1);
> QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 1);
> QCOMPARE(TelepathyHelper::instance()->activeAccounts()[0]->accountId(), mPhoneTpAccount->uniqueIdentifier());
>
> // set the other account offline to make sure
> activeAccountsSpy.clear();
> mPhoneController->SetOnline(false);
> - QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);
> + TRY_COMPARE(activeAccountsSpy.count(), 1);
> QVERIFY(TelepathyHelper::instance()->activeAccounts().isEmpty());
>
> // and set both accounts online again
> activeAccountsSpy.clear();
> mGenericController->SetOnline(true);
> mPhoneController->SetOnline(true);
> - QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 2, DEFAULT_TIMEOUT);
> - QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);
> + TRY_COMPARE(activeAccountsSpy.count(), 2);
> + QCOMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);
> }
>
> void TelepathyHelperTest::testAccountForId()
> @@ -291,7 +298,7 @@
> QSignalSpy emergencyCallsSpy(TelepathyHelper::instance(), SIGNAL(emergencyCallsAvailableChanged()));
>
> // check that calls are available by default
> - QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
> + TRY_VERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
>
> // set the generic account as "flightmode" and make sure it doesn't affect the emergencyCallsAvailable
> mGenericController->SetPresence("flightmode", "");
> @@ -301,7 +308,7 @@
>
> // now set the phone account as "flightmode", and see if the emergencyCallsAvailable value
> mPhoneController->SetPresence("flightmode", "");
> - QTRY_COMPARE(emergencyCallsSpy.count(), 1);
> + TRY_VERIFY(emergencyCallsSpy.count() > 0);
> QVERIFY(!TelepathyHelper::instance()->emergencyCallsAvailable());
>
> // set the generic account online and check if it affects the value
> @@ -313,9 +320,25 @@
>
> // and finally set the phone account back online
> mPhoneController->SetOnline(true);
> - QTRY_COMPARE(emergencyCallsSpy.count(), 1);
> + TRY_VERIFY(emergencyCallsSpy.count() > 0);
> QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
> }
>
> +Tp::AccountPtr TelepathyHelperTest::addAccountAndWait(const QString &manager, const QString &protocol, const QString &displayName, const QVariantMap ¶meters)
> +{
> + QSignalSpy accountAddedSpy(TelepathyHelper::instance(), SIGNAL(accountAdded(AccountEntry*)));
> + Tp::AccountPtr account = addAccount(manager, protocol, displayName, parameters);
> +
> + WAIT_FOR(accountAddedSpy.count() == 1);
> +
> + AccountEntry *accountEntry = accountAddedSpy.first().first().value<AccountEntry*>();
> + WAIT_FOR(accountEntry->ready());
> +
> + // and make sure the status and status message are the ones we expect
> + WAIT_FOR(accountEntry->status() == QString("available"));
> +
> + return account;
> +}
> +
> QTEST_MAIN(TelepathyHelperTest)
> #include "TelepathyHelperTest.moc"
>
--
https://code.launchpad.net/~boiko/telephony-service/fix_voicemail_detection/+merge/257694
Your team Ubuntu Phablet Team is subscribed to branch lp:telephony-service.
More information about the Ubuntu-reviews
mailing list