=== modified file '.bzrignore'
--- .bzrignore	2015-04-16 21:39:16 +0000
+++ .bzrignore	2015-04-28 21:45:15 +0000
@@ -46,6 +46,7 @@
 
 tests/*/*Test
 tests/common/dbus-test-wrapper.sh
+tests/common/MockConnectionInterface.*
 tests/common/mock/mockconnectionadaptor.*
 tests/common/mock/telepathy-mock
 tests/common/dbus-session.conf

=== modified file 'Ubuntu/Telephony/components.cpp'
--- Ubuntu/Telephony/components.cpp	2014-08-25 14:49:53 +0000
+++ Ubuntu/Telephony/components.cpp	2015-04-28 21:45:15 +0000
@@ -54,7 +54,6 @@
     mRootContext->setContextProperty("telepathyHelper", TelepathyHelper::instance());
     mRootContext->setContextProperty("chatManager", ChatManager::instance());
     mRootContext->setContextProperty("callManager", CallManager::instance());
-    mRootContext->setContextProperty("ussdManager", USSDManager::instance());
     mRootContext->setContextProperty("greeter", GreeterContacts::instance());
 
 }
@@ -66,6 +65,7 @@
     qmlRegisterUncreatableType<CallEntry>(uri, 0, 1, "CallEntry", "Objects of this type are created in CallManager and made available to QML for usage");
     qmlRegisterUncreatableType<AudioOutput>(uri, 0, 1, "AudioOutput", "Objects of this type are created in CallEntry and made available to QML for usage");
     qmlRegisterUncreatableType<AccountEntry>(uri, 0, 1, "AccountEntry", "Objects of this type are created in TelepathyHelper and made available to QML");
+    qmlRegisterUncreatableType<USSDManager>(uri, 0, 1, "USSDManager", "Objects of this type are created in AccountEntry and made available to QML");
     qmlRegisterType<ContactWatcher>(uri, 0, 1, "ContactWatcher");
     qmlRegisterType<PhoneUtils>(uri, 0, 1, "PhoneUtils");
 }

=== modified file 'cmake/modules/GenerateTest.cmake'
--- cmake/modules/GenerateTest.cmake	2015-04-16 14:20:28 +0000
+++ cmake/modules/GenerateTest.cmake	2015-04-28 21:45:15 +0000
@@ -69,7 +69,7 @@
         qt5_use_modules(${TESTNAME} ${ARG_QT5_MODULES})
 
         if (${ARG_USE_DBUS})
-            execute_process(COMMAND mktemp -d OUTPUT_VARIABLE TMPDIR)
+            execute_process(COMMAND mktemp -d /tmp/${TESTNAME}.XXXXX OUTPUT_VARIABLE TMPDIR)
             string(REPLACE "\n" "" TMPDIR ${TMPDIR})
 
             if (NOT DEFINED ARG_ENVIRONMENT)

=== modified file 'indicator/CMakeLists.txt'
--- indicator/CMakeLists.txt	2015-03-10 21:06:56 +0000
+++ indicator/CMakeLists.txt	2015-04-28 21:45:15 +0000
@@ -7,6 +7,7 @@
     ussdindicator.cpp
     ussdmenu.cpp
     voicemailindicator.cpp
+    indicatordbus.cpp
     )
 
 set_source_files_properties(
@@ -20,9 +21,11 @@
         "${DATA_DIR}/org.freedesktop.Notifications.xml"
         NotificationsInterface
 )
+qt5_add_dbus_adaptor(qt_SRCS Indicator.xml indicator/indicatordbus.h IndicatorDBus)
 
 set(indicator_SRCS main.cpp ${qt_SRCS})
 
+
 include_directories(
     ${TP_QT5_INCLUDE_DIRS}
     ${NOTIFY_INCLUDE_DIRS}

=== added file 'indicator/Indicator.xml'
--- indicator/Indicator.xml	1970-01-01 00:00:00 +0000
+++ indicator/Indicator.xml	2015-04-28 21:45:15 +0000
@@ -0,0 +1,18 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
+    <dox:d><![CDATA[
+      @mainpage
+
+      An interface to the telephony service indicator.
+    ]]></dox:d>
+    <interface name="com.canonical.TelephonyServiceIndicator" xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
+        <dox:d>
+          An interface to the phone indicator application.
+        </dox:d>
+        <method name="ClearNotifications">
+            <dox:d><![CDATA[
+                Remove any notification currently being displayed.
+            ]]></dox:d>
+        </method>
+    </interface>
+</node>

=== added file 'indicator/indicatordbus.cpp'
--- indicator/indicatordbus.cpp	1970-01-01 00:00:00 +0000
+++ indicator/indicatordbus.cpp	2015-04-28 21:45:15 +0000
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Canonical, Ltd.
+ *
+ * Authors:
+ *  Ugo Riboni <ugo.riboni@canonical.com>
+ *  Tiago Salem Herrmann <tiago.herrmann@canonical.com>
+ *
+ * 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 "indicatordbus.h"
+#include "indicatoradaptor.h"
+
+// Qt
+#include <QtDBus/QDBusConnection>
+
+static const char* DBUS_SERVICE = "com.canonical.TelephonyServiceIndicator";
+static const char* DBUS_OBJECT_PATH = "/com/canonical/TelephonyServiceIndicator";
+
+IndicatorDBus::IndicatorDBus(QObject* parent)
+: QObject(parent)
+{
+}
+
+IndicatorDBus::~IndicatorDBus()
+{
+}
+
+bool
+IndicatorDBus::connectToBus()
+{
+    bool ok = QDBusConnection::sessionBus().registerService(DBUS_SERVICE);
+    if (!ok) {
+        return false;
+    }
+    new TelephonyServiceIndicatorAdaptor(this);
+    QDBusConnection::sessionBus().registerObject(DBUS_OBJECT_PATH, this);
+
+    return true;
+}
+
+void IndicatorDBus::ClearNotifications()
+{
+    Q_EMIT clearNotificationsRequested();
+}
+

=== added file 'indicator/indicatordbus.h'
--- indicator/indicatordbus.h	1970-01-01 00:00:00 +0000
+++ indicator/indicatordbus.h	2015-04-28 21:45:15 +0000
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012-2015 Canonical, Ltd.
+ *
+ * Authors:
+ *  Ugo Riboni <ugo.riboni@canonical.com>
+ *  Tiago Salem Herrmann <tiago.herrmann@canonical.com>
+ *  Gustavo Pichorim Boiko <gustavo.boiko@gmail.com>
+ *
+ * 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/>.
+ */
+
+#ifndef INDICATORDBUS_H
+#define INDICATORDBUS_H
+
+#include <QtCore/QObject>
+#include <QtDBus/QDBusContext>
+#include "chatmanager.h"
+
+/**
+ * DBus interface for the phone approver
+ */
+class IndicatorDBus : public QObject, protected QDBusContext
+{
+    Q_OBJECT
+
+public:
+    IndicatorDBus(QObject* parent=0);
+    ~IndicatorDBus();
+
+    bool connectToBus();
+
+public Q_SLOTS:
+    Q_NOREPLY void ClearNotifications();
+
+Q_SIGNALS:
+    void clearNotificationsRequested();
+
+};
+
+#endif // IndicatorDBus_H

=== modified file 'indicator/main.cpp'
--- indicator/main.cpp	2015-01-09 13:40:24 +0000
+++ indicator/main.cpp	2015-04-28 21:45:15 +0000
@@ -24,6 +24,7 @@
 
 #include "applicationutils.h"
 #include "callchannelobserver.h"
+#include "indicatordbus.h"
 #include "metrics.h"
 #include "telepathyhelper.h"
 #include "textchannelobserver.h"
@@ -86,5 +87,11 @@
     // instanciate the metrics helper
     Metrics::instance();
 
+    // create the dbus object and connect its signals
+    IndicatorDBus dbus;
+    QObject::connect(&dbus, SIGNAL(clearNotificationsRequested()),
+                     &ussdIndicator, SLOT(clear()));
+    dbus.connectToBus();
+
     return app.exec();
 }

=== modified file 'indicator/ussdindicator.cpp'
--- indicator/ussdindicator.cpp	2014-03-31 19:37:40 +0000
+++ indicator/ussdindicator.cpp	2015-04-28 21:45:15 +0000
@@ -27,6 +27,8 @@
 #include <libnotify/notify.h>
 #include "ringtone.h"
 #include "ussdindicator.h"
+#include "ofonoaccountentry.h"
+#include "telepathyhelper.h"
 
 USSDIndicator::USSDIndicator(QObject *parent)
 : QObject(parent),
@@ -35,35 +37,63 @@
   m_notifications("org.freedesktop.Notifications",
                   "/org/freedesktop/Notifications", QDBusConnection::sessionBus())
 {
-    connect(USSDManager::instance(), SIGNAL(notificationReceived(const QString &)), SLOT(onNotificationReceived(const QString &)));
-    connect(USSDManager::instance(), SIGNAL(requestReceived(const QString &)), SLOT(onRequestReceived(const QString &)));
-    connect(USSDManager::instance(), SIGNAL(initiateUSSDComplete(const QString &)), SLOT(onInitiateUSSDComplete(const QString &)));
-    connect(USSDManager::instance(), SIGNAL(respondComplete(bool, const QString &)), SLOT(onRespondComplete(bool, const QString &)));
-    connect(USSDManager::instance(), SIGNAL(stateChanged(const QString &)), SLOT(onStateChanged(const QString &)));
-
+    setupAccounts();
+    connect(TelepathyHelper::instance(), SIGNAL(accountsChanged()), this, SLOT(setupAccounts()));
     connect(&m_notifications, SIGNAL(ActionInvoked(uint, const QString &)), this, SLOT(actionInvoked(uint, const QString &)));
     connect(&m_notifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(notificationClosed(uint, uint)));
 }
 
+void USSDIndicator::setupAccounts()
+{
+    Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) {
+        OfonoAccountEntry *ofonoAccount = qobject_cast<OfonoAccountEntry*>(account);
+        if (!ofonoAccount) {
+            continue;
+        }
+        
+        connect(ofonoAccount->ussdManager(), SIGNAL(notificationReceived(const QString &)), SLOT(onNotificationReceived(const QString &)), Qt::UniqueConnection);
+        connect(ofonoAccount->ussdManager(), SIGNAL(requestReceived(const QString &)), SLOT(onRequestReceived(const QString &)), Qt::UniqueConnection);
+        connect(ofonoAccount->ussdManager(), SIGNAL(initiateUSSDComplete(const QString &)), SLOT(onInitiateUSSDComplete(const QString &)), Qt::UniqueConnection);
+        connect(ofonoAccount->ussdManager(), SIGNAL(respondComplete(bool, const QString &)), SLOT(onRespondComplete(bool, const QString &)), Qt::UniqueConnection);
+        connect(ofonoAccount->ussdManager(), SIGNAL(stateChanged(const QString &)), SLOT(onStateChanged(const QString &)), Qt::UniqueConnection);
+    }
+}
+
 void USSDIndicator::onNotificationReceived(const QString &message)
 {
-    showUSSDNotification(message, false);
+    USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
+    if (!ussdManager) {
+        return;
+    }
+    showUSSDNotification(message, false, ussdManager);
 }
 
 void USSDIndicator::onRequestReceived(const QString &message)
 {
-    showUSSDNotification(message, true);
+    USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
+    if (!ussdManager) {
+        return;
+    }
+    showUSSDNotification(message, true, ussdManager);
 }
 
 void USSDIndicator::onInitiateUSSDComplete(const QString &ussdResp)
 {
-    showUSSDNotification(ussdResp, (USSDManager::instance()->state() == "user-response"));
+    USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
+    if (!ussdManager) {
+        return;
+    }
+    showUSSDNotification(ussdResp, (ussdManager->state() == "user-response"), ussdManager);
 }
 
 void USSDIndicator::onRespondComplete(bool success, const QString &ussdResp)
 {
+    USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
+    if (!ussdManager) {
+        return;
+    }
     if (success) {
-        showUSSDNotification(ussdResp, (USSDManager::instance()->state() == "user-response"));
+        showUSSDNotification(ussdResp, (ussdManager->state() == "user-response"), ussdManager);
     }
 }
 
@@ -72,7 +102,7 @@
     // TODO: check if we should close notifications when the state is idle
 }
 
-void USSDIndicator::showUSSDNotification(const QString &message, bool replyRequired)
+void USSDIndicator::showUSSDNotification(const QString &message, bool replyRequired, USSDManager *ussdManager)
 {
     USSDMenu *menu = replyRequired ? &m_menuRequest : &m_menuNotification;
     QString actionId = "ok_id";
@@ -102,7 +132,7 @@
                         "", message,
                         QStringList() << actionId << actionLabel << "cancel_id"
                                         << C::gettext("Cancel"), notificationHints, 0);
-
+    mUSSDRequests[m_notificationId] = ussdManager;
 
     Ringtone::instance()->playIncomingMessageSound();
 }
@@ -113,12 +143,17 @@
         return;
     }
 
+    USSDManager *ussdManager = mUSSDRequests.take(id);
+    if (!ussdManager) {
+        return;
+    }
+
     m_notificationId = 0;
 
     if (actionKey == "reply_id") {
-        USSDManager::instance()->respond(m_menuRequest.response(), USSDManager::instance()->activeAccountId());
+        ussdManager->respond(m_menuRequest.response());
     } else if (actionKey == "cancel_id") {
-        USSDManager::instance()->cancel(USSDManager::instance()->activeAccountId());
+        ussdManager->cancel();
     }
     m_menuRequest.clearResponse();
 }
@@ -130,3 +165,16 @@
     m_notifications.CloseNotification(m_notificationId);
     m_notificationId = 0;
 }
+
+void USSDIndicator::clear()
+{
+    if (m_notificationId != 0) {
+        USSDManager *ussdManager = mUSSDRequests.take(m_notificationId);
+        if (ussdManager) {
+            ussdManager->cancel();
+        }
+
+        m_notifications.CloseNotification(m_notificationId);
+        m_notificationId = 0;
+    }
+}

=== modified file 'indicator/ussdindicator.h'
--- indicator/ussdindicator.h	2014-03-31 19:37:40 +0000
+++ indicator/ussdindicator.h	2015-04-28 21:45:15 +0000
@@ -27,13 +27,14 @@
 #include "indicator/NotificationsInterface.h"
 #include "ussdmanager.h"
 #include "ussdmenu.h"
+#include "ofonoaccountentry.h"
 
 class USSDIndicator : public QObject
 {
     Q_OBJECT
 public:
     explicit USSDIndicator(QObject *parent = 0);
-    void showUSSDNotification(const QString &message, bool replyRequired);
+    void showUSSDNotification(const QString &message, bool replyRequired, USSDManager *ussdManager);
 
 public Q_SLOTS:
     void onNotificationReceived(const QString &message);
@@ -43,12 +44,18 @@
     void onStateChanged(const QString &state);
     void actionInvoked(uint id, const QString &actionKey);
     void notificationClosed(uint id, uint reason);
+    void clear();
+private Q_SLOTS:
+    void setupAccounts();
+
 private:
     unsigned int m_notificationId;
     USSDMenu m_menuRequest;
     USSDMenu m_menuNotification;
     QString mPendingMessage;
     org::freedesktop::Notifications m_notifications;
+    QMap<int, USSDManager*> mUSSDRequests;
+    QList<OfonoAccountEntry*> mAccounts;
 };
 
 #endif // USSDINDICATOR_H

=== modified file 'libtelephonyservice/ofonoaccountentry.cpp'
--- libtelephonyservice/ofonoaccountentry.cpp	2015-03-17 18:26:32 +0000
+++ libtelephonyservice/ofonoaccountentry.cpp	2015-04-28 21:45:15 +0000
@@ -37,6 +37,13 @@
     connect(this,
             SIGNAL(statusMessageChanged()),
             SIGNAL(emergencyCallsAvailableChanged()));
+
+    mUssdManager = new USSDManager(this, this);
+}
+
+USSDManager *OfonoAccountEntry::ussdManager() const
+{
+    return mUssdManager;
 }
 
 QStringList OfonoAccountEntry::emergencyNumbers() const

=== modified file 'libtelephonyservice/ofonoaccountentry.h'
--- libtelephonyservice/ofonoaccountentry.h	2015-03-17 18:21:59 +0000
+++ libtelephonyservice/ofonoaccountentry.h	2015-04-28 21:45:15 +0000
@@ -23,6 +23,7 @@
 #define OFONOACCOUNTENTRY_H
 
 #include "accountentry.h"
+#include "ussdmanager.h"
 
 class OfonoAccountEntry : public AccountEntry
 {
@@ -35,6 +36,7 @@
     Q_PROPERTY(bool emergencyCallsAvailable READ emergencyCallsAvailable NOTIFY emergencyCallsAvailableChanged)
     Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
     Q_PROPERTY(QString serial READ serial NOTIFY serialChanged)
+    Q_PROPERTY(USSDManager* ussdManager READ ussdManager CONSTANT)
     friend class AccountEntryFactory;
 
 public:
@@ -46,6 +48,7 @@
     bool emergencyCallsAvailable() const;
     bool simLocked() const;
     QString serial() const;
+    USSDManager *ussdManager() const;
 
     // reimplemented from AccountEntry
     virtual AccountEntry::AccountType type() const;
@@ -81,6 +84,7 @@
     uint mVoicemailCount;
     bool mVoicemailIndicator;
     QString mSerial;
+    USSDManager *mUssdManager;
 };
 
 #endif // OFONOACCOUNTENTRY_H

=== modified file 'libtelephonyservice/telepathyhelper.cpp'
--- libtelephonyservice/telepathyhelper.cpp	2015-03-26 21:52:43 +0000
+++ libtelephonyservice/telepathyhelper.cpp	2015-04-28 21:45:15 +0000
@@ -162,6 +162,22 @@
     return activeAccountList;
 }
 
+QList<AccountEntry*> TelepathyHelper::phoneAccounts() const
+{
+    QList<AccountEntry*> accountList;
+    Q_FOREACH(AccountEntry *account, mAccounts) {
+        if (account->type() == AccountEntry::PhoneAccount) {
+            accountList << account;
+        }
+    }
+    return accountList;
+}
+
+QQmlListProperty<AccountEntry> TelepathyHelper::qmlPhoneAccounts()
+{
+    return QQmlListProperty<AccountEntry>(this, 0, phoneAccountsCount, phoneAccountAt);
+}
+
 QQmlListProperty<AccountEntry> TelepathyHelper::qmlAccounts()
 {
     return QQmlListProperty<AccountEntry>(this, 0, accountsCount, accountAt);
@@ -357,12 +373,24 @@
     return spec;
 }
 
+int TelepathyHelper::phoneAccountsCount(QQmlListProperty<AccountEntry> *p)
+{
+    Q_UNUSED(p)
+    return TelepathyHelper::instance()->phoneAccounts().count();
+}
+
 int TelepathyHelper::accountsCount(QQmlListProperty<AccountEntry> *p)
 {
     Q_UNUSED(p)
     return TelepathyHelper::instance()->accounts().count();
 }
 
+AccountEntry *TelepathyHelper::phoneAccountAt(QQmlListProperty<AccountEntry> *p, int index)
+{
+    Q_UNUSED(p)
+    return TelepathyHelper::instance()->phoneAccounts()[index];
+}
+
 AccountEntry *TelepathyHelper::accountAt(QQmlListProperty<AccountEntry> *p, int index)
 {
     Q_UNUSED(p)
@@ -391,6 +419,7 @@
 
     Q_EMIT accountIdsChanged();
     Q_EMIT accountsChanged();
+    Q_EMIT phoneAccountsChanged();
     Q_EMIT activeAccountsChanged();
     onSettingsChanged("defaultSimForMessages");
     onSettingsChanged("defaultSimForCalls");
@@ -418,6 +447,7 @@
 
     Q_EMIT accountIdsChanged();
     Q_EMIT accountsChanged();
+    Q_EMIT phoneAccountsChanged();
     Q_EMIT activeAccountsChanged();
     onSettingsChanged("defaultSimForMessages");
     onSettingsChanged("defaultSimForCalls");
@@ -452,6 +482,7 @@
 
     Q_EMIT accountIdsChanged();
     Q_EMIT accountsChanged();
+    Q_EMIT phoneAccountsChanged();
     Q_EMIT activeAccountsChanged();
     onSettingsChanged("defaultSimForMessages");
     onSettingsChanged("defaultSimForCalls");

=== modified file 'libtelephonyservice/telepathyhelper.h'
--- libtelephonyservice/telepathyhelper.h	2015-03-23 18:17:51 +0000
+++ libtelephonyservice/telepathyhelper.h	2015-04-28 21:45:15 +0000
@@ -48,6 +48,7 @@
     Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
     Q_PROPERTY(QStringList accountIds READ accountIds NOTIFY accountIdsChanged)
     Q_PROPERTY(QQmlListProperty<AccountEntry> accounts READ qmlAccounts NOTIFY accountsChanged)
+    Q_PROPERTY(QQmlListProperty<AccountEntry> phoneAccounts READ qmlPhoneAccounts NOTIFY phoneAccountsChanged)
     Q_PROPERTY(QQmlListProperty<AccountEntry> activeAccounts READ qmlActiveAccounts NOTIFY activeAccountsChanged)
     Q_PROPERTY(AccountEntry *defaultMessagingAccount READ defaultMessagingAccount NOTIFY defaultMessagingAccountChanged)
     Q_PROPERTY(AccountEntry *defaultCallAccount READ defaultCallAccount NOTIFY defaultCallAccountChanged)
@@ -65,8 +66,10 @@
 
     static TelepathyHelper *instance();
     QList<AccountEntry*> accounts() const;
+    QList<AccountEntry*> phoneAccounts() const;
     QList<AccountEntry*> activeAccounts() const;
     QQmlListProperty<AccountEntry> qmlAccounts();
+    QQmlListProperty<AccountEntry> qmlPhoneAccounts();
     QQmlListProperty<AccountEntry> qmlActiveAccounts();
     ChannelObserver *channelObserver() const;
     QDBusInterface *handlerInterface() const;
@@ -97,7 +100,9 @@
     static AccountEntry *accountAt(QQmlListProperty<AccountEntry> *p, int index);
     static int activeAccountsCount(QQmlListProperty<AccountEntry> *p);
     static AccountEntry *activeAccountAt(QQmlListProperty<AccountEntry> *p, int index);
-
+    static int phoneAccountsCount(QQmlListProperty<AccountEntry> *p);
+    static AccountEntry *phoneAccountAt(QQmlListProperty<AccountEntry> *p, int index);
+ 
 Q_SIGNALS:
     void channelObserverCreated(ChannelObserver *observer);
     void channelObserverUnregistered();
@@ -105,6 +110,7 @@
     void connectedChanged();
     void accountIdsChanged();
     void accountsChanged();
+    void phoneAccountsChanged();
     void activeAccountsChanged();
     void setupReady();
     void defaultMessagingAccountChanged();

=== modified file 'libtelephonyservice/ussdmanager.cpp'
--- libtelephonyservice/ussdmanager.cpp	2015-02-03 17:30:41 +0000
+++ libtelephonyservice/ussdmanager.cpp	2015-04-28 21:45:15 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Canonical, Ltd.
+ * Copyright (C) 2012-2015 Canonical, Ltd.
  *
  * Authors:
  *  Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
@@ -30,198 +30,105 @@
 typedef QMap<QString, QVariant> dbusQMap;
 Q_DECLARE_METATYPE(dbusQMap)
 
-USSDManager *USSDManager::instance()
-{
-    static USSDManager *self = new USSDManager();
-    return self;
-}
-
-USSDManager::USSDManager(QObject *parent)
-: QObject(parent)
-{
-    connect(TelepathyHelper::instance(), SIGNAL(accountsChanged()), SLOT(onAccountsChanged()));
-    onAccountsChanged();
-}
-
-Tp::ConnectionPtr USSDManager::connectionForAccountId(const QString &accountId)
-{
-    AccountEntry *accountEntry;
-    if (accountId.isNull()) {
-        accountEntry = TelepathyHelper::instance()->accounts()[0];
-    } else {
-        accountEntry = TelepathyHelper::instance()->accountForId(accountId);
-    }
-
-    return accountEntry->account()->connection();
-}
-
-void USSDManager::initiate(const QString &command, const QString &accountId)
-{
-    Tp::ConnectionPtr conn = connectionForAccountId(accountId);
-    QString busName = conn->busName();
-    QString objectPath = conn->objectPath();
-    QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
+USSDManager::USSDManager(AccountEntry *account, QObject *parent)
+: QObject(parent),
+  mState("idle"),
+  mAccount(account)
+{
+    connect(mAccount, SIGNAL(connectedChanged()), this, SLOT(onConnectionChanged()));
+    onConnectionChanged();
+}
+
+void USSDManager::initiate(const QString &command)
+{
+    QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
     ussdIface.asyncCall("Initiate", command);
 }
 
-void USSDManager::respond(const QString &reply, const QString &accountId)
+void USSDManager::respond(const QString &reply)
 {
-    Tp::ConnectionPtr conn = connectionForAccountId(accountId);
-    QString busName = conn->busName();
-    QString objectPath = conn->objectPath();
-    QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
+    QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
     ussdIface.asyncCall("Respond", reply);
 }
 
-void USSDManager::cancel(const QString &accountId)
+void USSDManager::cancel()
 {
-    Tp::ConnectionPtr conn = connectionForAccountId(accountId);
-    QString busName = conn->busName();
-    QString objectPath = conn->objectPath();
-    QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
+    QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
     ussdIface.asyncCall("Cancel");
 }
 
-void USSDManager::disconnectAllSignals(const Tp::ConnectionPtr& conn)
-{
-    if (conn.isNull()) {
-        return;
-    }
-
-    QString busName = conn->busName();
-    QString objectPath = conn->objectPath();
-
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
-    QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
-}
-
-void USSDManager::connectAllSignals(const Tp::ConnectionPtr& conn)
-{
-    if (conn.isNull()) {
-        return;
-    }
-
-    QString busName = conn->busName();
-    QString objectPath = conn->objectPath();
-
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
-    QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
-}
-
-void USSDManager::accountConnectedChanged()
-{
-    AccountEntry *accountEntry = qobject_cast<AccountEntry*>(sender());
-    if (!accountEntry) {
-        return;
-    }
-    Tp::ConnectionPtr conn(accountEntry->account()->connection());
-    disconnectAllSignals(conn);
-
-    if (accountEntry->connected()) {
-        QString busName = conn->busName();
-        QString objectPath = conn->objectPath();
-
-        connectAllSignals(conn);
-
-        QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
-        mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
-    }
-}
-
-void USSDManager::onAccountsChanged()
-{
-    Q_FOREACH (AccountEntry *accountEntry, TelepathyHelper::instance()->accounts()) {
-        QObject::disconnect(accountEntry, SIGNAL(connectedChanged()), this, SLOT(accountConnectedChanged()));
-        QObject::connect(accountEntry, SIGNAL(connectedChanged()), this, SLOT(accountConnectedChanged()));
-
-        // disconnect all and reconnect only the online accounts
-        Tp::ConnectionPtr conn(accountEntry->account()->connection());
-        disconnectAllSignals(conn);
-        mStates.remove(accountEntry->accountId());
-
-        if (accountEntry->connected()) {
-            QString busName = conn->busName();
-            QString objectPath = conn->objectPath();
-
-            connectAllSignals(conn);
-
-            QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
-            mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
-        }
-    }
-    Q_EMIT stateChanged(state());
+void USSDManager::connectAllSignals()
+{
+    if (mBusName.isEmpty() || mObjectPath.isEmpty()) {
+        return;
+    }
+
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
+    QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
+}
+
+void USSDManager::disconnectAllSignals()
+{
+    if (mBusName.isEmpty() || mObjectPath.isEmpty()) {
+        return;
+    }
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
+    QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
+}
+
+void USSDManager::onConnectionChanged()
+{
+    disconnectAllSignals();
+
+    if (mAccount->account()->connection().isNull()) {
+        qDebug() << "USSDManager: Failed to connect signals";
+        return;
+    }
+
+    mBusName = mAccount->account()->connection()->busName();
+    mObjectPath = mAccount->account()->connection()->objectPath();
+
+    QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
+    mState = ussdIface.property("State").toString();
+
+    connectAllSignals();
+}
+
+void USSDManager::onStateChanged(const QString &state)
+{
+    mState = state;
+    Q_EMIT stateChanged(mState);
     Q_EMIT activeChanged();
-    Q_EMIT activeAccountIdChanged();
-}
-
-void USSDManager::onStateChanged(const QString &)
-{
-    Q_FOREACH (AccountEntry *accountEntry, TelepathyHelper::instance()->accounts()) {
-        Tp::ConnectionPtr conn(accountEntry->account()->connection());
-        if (accountEntry->connected()) {
-            QString busName = conn->busName();
-            QString objectPath = conn->objectPath();
-            QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
-            mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
-        }
-    }
-    Q_EMIT stateChanged(state());
 }
 
 bool USSDManager::active() const
 {
-    QMap<QString, QString>::const_iterator i = mStates.constBegin();
-    while (i != mStates.constEnd()) {
-        if (i.value() != "idle") {
-            return true;
-        }
-        ++i;
-    }
-    return false;
-}
-
-QString USSDManager::activeAccountId() const
-{
-    QMap<QString, QString>::const_iterator i = mStates.constBegin();
-    while (i != mStates.constEnd()) {
-        if (i.value() != "idle") {
-            return i.key();
-        }
-        ++i;
-    }
-    return QString::null;
+    return mState != "idle";
 }
 
 QString USSDManager::state() const
 {
-    QMap<QString, QString>::const_iterator i = mStates.constBegin();
-    while (i != mStates.constEnd()) {
-        if (i.value() != "idle") {
-            return i.value();
-        }
-        ++i;
-    }
-    return "idle";
+    return mState;
 }

=== modified file 'libtelephonyservice/ussdmanager.h'
--- libtelephonyservice/ussdmanager.h	2015-02-03 17:30:41 +0000
+++ libtelephonyservice/ussdmanager.h	2015-04-28 21:45:15 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Canonical, Ltd.
+ * Copyright (C) 2012-2015 Canonical, Ltd.
  *
  * Authors:
  *  Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
@@ -28,6 +28,7 @@
 #include <TelepathyQt/Connection>
 
 class TelepathyHelper;
+class AccountEntry;
 
 class USSDManager : public QObject
 {
@@ -35,30 +36,23 @@
     Q_PROPERTY(bool active 
                READ active
                NOTIFY activeChanged)
-    Q_PROPERTY(QString activeAccountId
-               READ activeAccountId
-               NOTIFY activeAccountIdChanged)
     Q_PROPERTY(QString state 
                READ state
                NOTIFY stateChanged)
 public:
-    static USSDManager *instance();
-    Q_INVOKABLE void initiate(const QString &command, const QString &accountId = QString::null);
-    Q_INVOKABLE void respond(const QString &reply, const QString &accountId = QString::null);
-    Q_INVOKABLE void cancel(const QString &accountId = QString::null);
+    explicit USSDManager(AccountEntry *account, QObject *parent = 0);
+    Q_INVOKABLE void initiate(const QString &command);
+    Q_INVOKABLE void respond(const QString &reply);
+    Q_INVOKABLE void cancel();
 
     bool active() const;
-    QString activeAccountId() const;
     QString state() const;
 
 public Q_SLOTS:
-    void onAccountsChanged();
     void onStateChanged(const QString &state);
-    void accountConnectedChanged();
 
 Q_SIGNALS:
     void activeChanged();
-    void activeAccountIdChanged();
     void stateChanged(const QString &state);
 
     void notificationReceived(const QString &message);
@@ -75,15 +69,17 @@
     void connectedLineRestrictionComplete(const QString &ssOp, const QString &status);
     void initiateFailed();
 
+private Q_SLOTS:
+    void onConnectionChanged();
+
 private:
-    explicit USSDManager(QObject *parent = 0);
-
-    Tp::ConnectionPtr connectionForAccountId(const QString &accountId = QString::null);
-
-    void disconnectAllSignals(const Tp::ConnectionPtr& conn);
-    void connectAllSignals(const Tp::ConnectionPtr& conn);
-
-    QMap<QString, QString> mStates;
+    void connectAllSignals();
+    void disconnectAllSignals();
+
+    QString mState;
+    QString mBusName;
+    QString mObjectPath;
+    AccountEntry *mAccount;
 };
 
 #endif // USSDMANAGER_H

=== modified file 'tests/common/CMakeLists.txt'
--- tests/common/CMakeLists.txt	2015-03-23 18:17:51 +0000
+++ tests/common/CMakeLists.txt	2015-04-28 21:45:15 +0000
@@ -1,9 +1,11 @@
 include_directories(${TP_QT5_INCLUDE_DIRS}
-                    ${CMAKE_SOURCE_DIR}/libtelephonyservice)
+                    ${CMAKE_SOURCE_DIR}/libtelephonyservice
+                    ${CMAKE_CURRENT_BINARY_DIR})
 
 configure_file(dbus-session.conf.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-session.conf)
 
-add_library(mockcontroller STATIC mockcontroller.cpp mockcontroller.h)
+qt5_add_dbus_interface(mockcontroller_SRCS mock/MockConnection.xml MockConnectionInterface)
+add_library(mockcontroller STATIC mockcontroller.cpp mockcontroller.h ${mockcontroller_SRCS})
 qt5_use_modules(mockcontroller Core DBus)
 
 add_library(telepathytest STATIC telepathytest.cpp telepathytest.h)

=== modified file 'tests/common/mock/MockConnection.xml'
--- tests/common/mock/MockConnection.xml	2015-03-30 18:47:02 +0000
+++ tests/common/mock/MockConnection.xml	2015-04-28 21:45:15 +0000
@@ -81,6 +81,96 @@
             ]]></dox:d>
             <arg name="value" type="s" direction="out"/>
         </method>
+        <method name="TriggerUSSDNotificationReceived">
+            <dox:d><![CDATA[
+                Trigger USSD method NotificationReceived
+            ]]></dox:d>
+            <arg name="message" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDRequestReceived">
+            <dox:d><![CDATA[
+                Trigger USSD method RequestReceived
+            ]]></dox:d>
+            <arg name="message" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDInitiateUSSDComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method InitiateUSSDComplete
+            ]]></dox:d>
+            <arg name="ussdResp" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDRespondComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method RespondComplete
+            ]]></dox:d>
+            <arg name="success" type="b" direction="in"/>
+            <arg name="ussdResp" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDBarringComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method BarringComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="cbService" type="s" direction="in"/>
+            <arg name="cbMap" type="a{sv}" direction="in"/>
+            <annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QVariantMap"/>
+        </method>
+        <method name="TriggerUSSDForwardingComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method ForwardingComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="cfService" type="s" direction="in"/>
+            <arg name="cfMap" type="a{sv}" direction="in"/>
+            <annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QVariantMap"/>
+        </method>
+        <method name="TriggerUSSDWaitingComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method WaitingComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="cwMap" type="a{sv}" direction="in"/>
+            <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
+        </method>
+        <method name="TriggerUSSDCallingLinePresentationComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method CallingLinePresentationComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="status" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDConnectedLinePresentationComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method ConnectedLinePresentationComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="status" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDCallingLineRestrictionComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method CallingLineRestrictionComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="status" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDConnectedLineRestrictionComplete">
+            <dox:d><![CDATA[
+                Trigger USSD method ConnectedLineRestrictionComplete
+            ]]></dox:d>
+            <arg name="ssOp" type="s" direction="in"/>
+            <arg name="status" type="s" direction="in"/>
+        </method>
+        <method name="TriggerUSSDInitiateFailed">
+            <dox:d><![CDATA[
+                Trigger USSD method InitiateFailed
+            ]]></dox:d>
+        </method>
+        <method name="TriggerUSSDStateChanged">
+            <dox:d><![CDATA[
+                Trigger USSD method StateChanged
+            ]]></dox:d>
+            <arg name="state" type="s" direction="in"/>
+        </method>
         <signal name="MessageRead">
             <dox:d><![CDATA[
                 A message was acknowledged
@@ -134,6 +224,23 @@
             ]]></dox:d>
             <arg name="objectPath" type="s"/>
         </signal>
+        <signal name="USSDInitiateCalled">
+            <dox:d><![CDATA[
+                USSDInitiate was called
+            ]]></dox:d>
+            <arg name="command" type="s"/>
+        </signal>
+        <signal name="USSDRespondCalled">
+            <dox:d><![CDATA[
+                USSDRespond was called
+            ]]></dox:d>
+            <arg name="reply" type="s"/>
+        </signal>
+        <signal name="USSDCancelCalled">
+            <dox:d><![CDATA[
+                USSDInitiate was called
+            ]]></dox:d>
+        </signal>
         <signal name="Disconnected">
             <dox:d><![CDATA[
                 The account was disconnected

=== modified file 'tests/common/mock/connection.cpp'
--- tests/common/mock/connection.cpp	2015-03-23 21:37:16 +0000
+++ tests/common/mock/connection.cpp	2015-04-28 21:45:15 +0000
@@ -610,17 +610,20 @@
 
 void MockConnection::USSDInitiate(const QString &command, Tp::DBusError *error)
 {
-    // FIXME: implement
+    // just emit a signal saying we received the command
+    Q_EMIT ussdInitiateCalled(command);
 }
 
 void MockConnection::USSDRespond(const QString &reply, Tp::DBusError *error)
 {
-    // FIXME: implement
+    // just emit a signal saying we received the reply
+    Q_EMIT ussdRespondCalled(reply);
 }
 
 void MockConnection::USSDCancel(Tp::DBusError *error)
 {
-    // FIXME: implement
+    // just emit a signal saying the operation was cancelled
+    Q_EMIT ussdCancelCalled();
 }
 
 QString MockConnection::serial()

=== modified file 'tests/common/mock/connection.h'
--- tests/common/mock/connection.h	2015-03-23 19:59:50 +0000
+++ tests/common/mock/connection.h	2015-04-28 21:45:15 +0000
@@ -117,6 +117,11 @@
     void channelSplitted(const QString &objectPath);
     void channelSplitted(const QDBusObjectPath &objectPath);
 
+    // USSD notifications
+    void ussdInitiateCalled(const QString &command);
+    void ussdRespondCalled(const QString &reply);
+    void ussdCancelCalled();
+
 public Q_SLOTS:
     void placeIncomingMessage(const QString &message, const QVariantMap &info);
     void hangupCall(const QString &callerId);

=== modified file 'tests/common/mock/mockconnectiondbus.cpp'
--- tests/common/mock/mockconnectiondbus.cpp	2015-03-23 21:37:16 +0000
+++ tests/common/mock/mockconnectiondbus.cpp	2015-04-28 21:45:15 +0000
@@ -53,6 +53,15 @@
             SIGNAL(channelSplitted(QString)),
             SIGNAL(ChannelSplitted(QString)));
     connect(mConnection,
+            SIGNAL(ussdInitiateCalled(QString)),
+            SIGNAL(USSDInitiateCalled(QString)));
+    connect(mConnection,
+            SIGNAL(ussdRespondCalled(QString)),
+            SIGNAL(USSDRespondCalled(QString)));
+    connect(mConnection,
+            SIGNAL(ussdCancelCalled()),
+            SIGNAL(USSDCancelCalled()));
+    connect(mConnection,
             SIGNAL(disconnected()),
             SIGNAL(Disconnected()));
     connect(mConnection,
@@ -137,3 +146,68 @@
 {
     return mConnection->serial();
 }
+
+void MockConnectionDBus::TriggerUSSDNotificationReceived(const QString &message)
+{
+    mConnection->supplementaryServicesIface->NotificationReceived(message);
+}
+
+void MockConnectionDBus::TriggerUSSDRequestReceived(const QString &message)
+{
+    mConnection->supplementaryServicesIface->RequestReceived(message);
+}
+
+void MockConnectionDBus::TriggerUSSDInitiateUSSDComplete(const QString &ussdResp)
+{
+    mConnection->supplementaryServicesIface->InitiateUSSDComplete(ussdResp);
+}
+
+void MockConnectionDBus::TriggerUSSDRespondComplete(bool success, const QString &ussdResp)
+{
+    mConnection->supplementaryServicesIface->RespondComplete(success, ussdResp);
+}
+
+void MockConnectionDBus::TriggerUSSDBarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)
+{
+    mConnection->supplementaryServicesIface->BarringComplete(ssOp, cbService, cbMap);
+}
+
+void MockConnectionDBus::TriggerUSSDForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)
+{
+    mConnection->supplementaryServicesIface->ForwardingComplete(ssOp, cfService, cfMap);
+}
+
+void MockConnectionDBus::TriggerUSSDWaitingComplete(const QString &ssOp, const QVariantMap &cwMap)
+{
+    mConnection->supplementaryServicesIface->WaitingComplete(ssOp, cwMap);
+}
+
+void MockConnectionDBus::TriggerUSSDCallingLinePresentationComplete(const QString &ssOp, const QString &status)
+{
+    mConnection->supplementaryServicesIface->CallingLinePresentationComplete(ssOp, status);
+}
+
+void MockConnectionDBus::TriggerUSSDConnectedLinePresentationComplete(const QString &ssOp, const QString &status)
+{
+    mConnection->supplementaryServicesIface->ConnectedLinePresentationComplete(ssOp, status);
+}
+
+void MockConnectionDBus::TriggerUSSDCallingLineRestrictionComplete(const QString &ssOp, const QString &status)
+{
+    mConnection->supplementaryServicesIface->CallingLineRestrictionComplete(ssOp, status);
+}
+
+void MockConnectionDBus::TriggerUSSDConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)
+{
+    mConnection->supplementaryServicesIface->ConnectedLineRestrictionComplete(ssOp, status);
+}
+
+void MockConnectionDBus::TriggerUSSDInitiateFailed()
+{
+    mConnection->supplementaryServicesIface->InitiateFailed();
+}
+
+void MockConnectionDBus::TriggerUSSDStateChanged(const QString &state)
+{
+    mConnection->supplementaryServicesIface->StateChanged(state);
+}

=== modified file 'tests/common/mock/mockconnectiondbus.h'
--- tests/common/mock/mockconnectiondbus.h	2015-03-23 21:37:16 +0000
+++ tests/common/mock/mockconnectiondbus.h	2015-04-28 21:45:15 +0000
@@ -50,6 +50,19 @@
 
     // USSD stuff
     QString Serial();
+    void TriggerUSSDNotificationReceived(const QString &message);
+    void TriggerUSSDRequestReceived(const QString &message);
+    void TriggerUSSDInitiateUSSDComplete(const QString &ussdResp);
+    void TriggerUSSDRespondComplete(bool success, const QString &ussdResp);
+    void TriggerUSSDBarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap);
+    void TriggerUSSDForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap);
+    void TriggerUSSDWaitingComplete(const QString &ssOp, const QVariantMap &cwMap);
+    void TriggerUSSDCallingLinePresentationComplete(const QString &ssOp, const QString &status);
+    void TriggerUSSDConnectedLinePresentationComplete(const QString &ssOp, const QString &status);
+    void TriggerUSSDCallingLineRestrictionComplete(const QString &ssOp, const QString &status);
+    void TriggerUSSDConnectedLineRestrictionComplete(const QString &ssOp, const QString &status);
+    void TriggerUSSDInitiateFailed();
+    void TriggerUSSDStateChanged(const QString &state);
 
 Q_SIGNALS:
     // signals that will be relayed into the bus
@@ -62,6 +75,11 @@
     void ChannelMerged(const QString &objectPath);
     void ChannelSplitted(const QString &objectPath);
 
+    // USSD stuff
+    void USSDInitiateCalled(const QString &command);
+    void USSDRespondCalled(const QString &reply);
+    void USSDCancelCalled();
+
     void Disconnected();
     void Destroyed();
 

=== modified file 'tests/common/mockcontroller.cpp'
--- tests/common/mockcontroller.cpp	2015-03-23 18:17:51 +0000
+++ tests/common/mockcontroller.cpp	2015-04-28 21:45:15 +0000
@@ -23,88 +23,27 @@
 
 static const QString mockService("com.canonical.MockConnection");
 static const QString mockObject("/com/canonical/MockConnection/%1");
-static const QString mockInterface("com.canonical.MockConnection");
 
 MockController::MockController(const QString &protocol, QObject *parent) :
-    QObject(parent), mProtocol(protocol), mMockObject(mockObject.arg(protocol)),
-    mMockInterface(mockService, mockObject.arg(protocol), mockInterface)
-{
-    connect(&mMockInterface, SIGNAL(MessageRead(QString)),
-            this, SIGNAL(messageRead(QString)));
-    connect(&mMockInterface, SIGNAL(MessageSent(QString, QVariantMap)),
-            this, SIGNAL(messageSent(QString, QVariantMap)));
-    connect(&mMockInterface, SIGNAL(CallReceived(QString)),
-            this, SIGNAL(callReceived(QString)));
-    connect(&mMockInterface, SIGNAL(CallEnded(QString)),
-            this, SIGNAL(callEnded(QString)));
-    connect(&mMockInterface, SIGNAL(CallStateChanged(QString, QString, QString)),
-            this, SIGNAL(callStateChanged(QString,QString,QString)));
-    connect(&mMockInterface, SIGNAL(ConferenceCreated(QString)),
-            this, SIGNAL(conferenceCreated(QString)));
-    connect(&mMockInterface, SIGNAL(ChannelMerged(QString)),
-            this, SIGNAL(channelMerged(QString)));
-    connect(&mMockInterface, SIGNAL(ChannelSplitted(QString)),
-            this, SIGNAL(channelSplitted(QString)));
-    connect(&mMockInterface, SIGNAL(Disconnected()),
-            this, SIGNAL(disconnected()));
-    connect(&mMockInterface, SIGNAL(Destroyed()),
-            this, SIGNAL(connectionDestroyed()));
-}
-
-void MockController::placeIncomingMessage(const QString &message, const QVariantMap &properties)
-{
-    mMockInterface.call("PlaceIncomingMessage", message, properties);
+    ComCanonicalMockConnectionInterface(mockService, mockObject.arg(protocol), QDBusConnection::sessionBus(), parent),
+    mProtocol(protocol), mMockObject(mockObject.arg(protocol))
+{
 }
 
 QString MockController::placeCall(const QVariantMap &properties)
 {
-    QDBusReply<QString> reply = mMockInterface.call("PlaceCall", properties);
-    return reply;
-}
-
-void MockController::hangupCall(const QString &callerId)
-{
-    mMockInterface.call("HangupCall", callerId);
-}
-
-void MockController::setCallState(const QString &phoneNumber, const QString &state)
-{
-    mMockInterface.call("SetCallState", phoneNumber, state);
-}
-
-void MockController::setOnline(bool online)
-{
-    mMockInterface.call("SetOnline", online);
-}
-
-void MockController::setPresence(const QString &status, const QString &statusMessage)
-{
-    mMockInterface.call("SetPresence", status, statusMessage);
-}
-
-void MockController::setVoicemailNumber(const QString &number)
-{
-    mMockInterface.call("SetVoicemailNumber", number);
-}
-
-void MockController::setVoicemailIndicator(bool active)
-{
-    mMockInterface.call("SetVoicemailIndicator", active);
-}
-
-void MockController::setVoicemailCount(int count)
-{
-    mMockInterface.call("SetVoicemailCount", count);
-}
-
-void MockController::setEmergencyNumbers(const QStringList &numbers)
-{
-    mMockInterface.call("SetEmergencyNumbers", numbers);
+    QDBusPendingReply<QString> reply = PlaceCall(properties);
+    reply.waitForFinished();
+    if (!reply.isValid()) {
+        return QString::null;
+    }
+    return reply.value();
 }
 
 QString MockController::serial()
 {
-    QDBusReply<QString> reply = mMockInterface.call("Serial");
+    QDBusPendingReply<QString> reply = Serial();
+    reply.waitForFinished();
     if (!reply.isValid()) {
         return QString::null;
     }

=== modified file 'tests/common/mockcontroller.h'
--- tests/common/mockcontroller.h	2015-03-23 18:17:51 +0000
+++ tests/common/mockcontroller.h	2015-04-28 21:45:15 +0000
@@ -22,47 +22,21 @@
 #define MOCKCONTROLLER_H
 
 #include <QObject>
-#include <QDBusInterface>
+#include "MockConnectionInterface.h"
 
-class MockController : public QObject
+class MockController : public ComCanonicalMockConnectionInterface
 {
     Q_OBJECT
 public:
     explicit MockController(const QString &protocol, QObject *parent = 0);
 
-Q_SIGNALS:
-    void messageRead(const QString &messageId);
-    void messageSent(const QString &message, const QVariantMap &properties);
-    void callReceived(const QString &callerId);
-    void callEnded(const QString &callerId);
-    void callStateChanged(const QString &callerId, const QString &objectPath, const QString &state);
-    void conferenceCreated(const QString &objectPath);
-    void channelMerged(const QString &objectPath);
-    void channelSplitted(const QString &objectPath);
-    void disconnected();
-    void connectionDestroyed();
 
 public Q_SLOTS:
-    void placeIncomingMessage(const QString &message, const QVariantMap &properties);
+    // We only reimplement the methods that need sync replies
     QString placeCall(const QVariantMap &properties);
-    void hangupCall(const QString &callerId);
-    void setCallState(const QString &phoneNumber, const QString &state);
-    void setOnline(bool online);
-    void setPresence(const QString &status, const QString &statusMessage);
-
-    // voicemail stuff
-    void setVoicemailNumber(const QString &number);
-    void setVoicemailIndicator(bool active);
-    void setVoicemailCount(int count);
-
-    // emergency numbers stuff
-    void setEmergencyNumbers(const QStringList &numbers);
-
-    // USSD stuff
     QString serial();
 
 private:
-    QDBusInterface mMockInterface;
     QString mProtocol;
     QString mMockObject;
 };

=== modified file 'tests/handler/CMakeLists.txt'
--- tests/handler/CMakeLists.txt	2015-03-26 00:12:38 +0000
+++ tests/handler/CMakeLists.txt	2015-04-28 21:45:15 +0000
@@ -3,6 +3,7 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/../common
     ${CMAKE_SOURCE_DIR}
     ${CMAKE_SOURCE_DIR}/libtelephonyservice
+    ${CMAKE_BINARY_DIR}/tests/common
     ${TP_QT5_INCLUDE_DIRS}
     )
 

=== modified file 'tests/handler/HandlerTest.cpp'
--- tests/handler/HandlerTest.cpp	2015-03-26 21:51:29 +0000
+++ tests/handler/HandlerTest.cpp	2015-04-28 21:45:15 +0000
@@ -83,13 +83,13 @@
 void HandlerTest::testMakingCalls()
 {
     QString callerId("1234567");
-    QSignalSpy callReceivedSpy(mMockController, SIGNAL(callReceived(QString)));
+    QSignalSpy callReceivedSpy(mMockController, SIGNAL(CallReceived(QString)));
     // FIXME: add support for multiple accounts
     HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier());
     QTRY_COMPARE(callReceivedSpy.count(), 1);
     QCOMPARE(callReceivedSpy.first().first().toString(), callerId);
 
-    mMockController->hangupCall(callerId);
+    mMockController->HangupCall(callerId);
 }
 
 void HandlerTest::testHangUpCall()
@@ -111,7 +111,7 @@
     waitForCallActive(callerId);
 
     // and finally request the hangup
-    QSignalSpy callEndedSpy(mMockController, SIGNAL(callEnded(QString)));
+    QSignalSpy callEndedSpy(mMockController, SIGNAL(CallEnded(QString)));
     HandlerController::instance()->hangUpCall(objectPath);
     QTRY_COMPARE(callEndedSpy.count(), 1);
 }
@@ -134,7 +134,7 @@
 
     waitForCallActive(callerId);
 
-    QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString)));
+    QSignalSpy callStateSpy(mMockController, SIGNAL(CallStateChanged(QString,QString,QString)));
 
     // set the call on hold
     HandlerController::instance()->setHold(objectPath, true);
@@ -147,7 +147,7 @@
     QTRY_COMPARE(callStateSpy.count(), 1);
     QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));
 
-    mMockController->hangupCall(callerId);
+    mMockController->HangupCall(callerId);
 }
 
 void HandlerTest::testCallProperties()
@@ -235,7 +235,7 @@
     waitForCallActive(callerId2);
 
     // now create the conf call
-    QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(conferenceCreated(QString)));
+    QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(ConferenceCreated(QString)));
     HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);
     QTRY_COMPARE(conferenceCreatedSpy.count(), 1);
     QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();
@@ -249,13 +249,13 @@
     waitForCallActive(callerId3);
 
     // merge that call on the conference
-    QSignalSpy channelMergedSpy(mMockController, SIGNAL(channelMerged(QString)));
+    QSignalSpy channelMergedSpy(mMockController, SIGNAL(ChannelMerged(QString)));
     HandlerController::instance()->mergeCall(conferenceObjectPath, call3);
     QTRY_COMPARE(channelMergedSpy.count(), 1);
     QCOMPARE(channelMergedSpy.first().first().toString(), call3);
 
     // now try to split one of the channels
-    QSignalSpy channelSplittedSpy(mMockController, SIGNAL(channelSplitted(QString)));
+    QSignalSpy channelSplittedSpy(mMockController, SIGNAL(ChannelSplitted(QString)));
     HandlerController::instance()->splitCall(call2);
     QTRY_COMPARE(channelSplittedSpy.count(), 1);
     QCOMPARE(channelSplittedSpy.first().first().toString(), call2);
@@ -274,7 +274,7 @@
 {
     QString recipient("22222222");
     QString message("Hello, world!");
-    QSignalSpy messageSentSpy(mMockController, SIGNAL(messageSent(QString,QVariantMap)));
+    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);
@@ -308,7 +308,7 @@
 void HandlerTest::waitForCallActive(const QString &callerId)
 {
     // wait until the call state is "accepted"
-    QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString)));
+    QSignalSpy callStateSpy(mMockController, SIGNAL(CallStateChanged(QString,QString,QString)));
     QString state;
     QString objectPath;
     QString caller;

=== modified file 'tests/libtelephonyservice/AccountEntryTest.cpp'
--- tests/libtelephonyservice/AccountEntryTest.cpp	2015-04-16 16:45:59 +0000
+++ tests/libtelephonyservice/AccountEntryTest.cpp	2015-04-28 21:45:15 +0000
@@ -100,13 +100,13 @@
     QVERIFY(mAccount->active());
 
     // now set the account offline and see if the active flag changes correctly
-    mMockController->setOnline(false);
+    mMockController->SetOnline(false);
     QTRY_VERIFY(!mAccount->active());
     QCOMPARE(activeChangedSpy.count(), 1);
 
     // now re-enable the account and check that the entry is updated
     activeChangedSpy.clear();
-    mMockController->setOnline(true);
+    mMockController->SetOnline(true);
     QTRY_VERIFY(mAccount->active());
     QCOMPARE(activeChangedSpy.count(), 1);
 
@@ -166,7 +166,7 @@
 
     // and now set a new value
     QString statusMessage("I am online");
-    mMockController->setPresence("available", statusMessage);
+    mMockController->SetPresence("available", statusMessage);
 
     QTRY_COMPARE(mAccount->statusMessage(), statusMessage);
     QTRY_COMPARE(statusMessageChangedSpy.count(), 1);
@@ -183,7 +183,7 @@
     QVERIFY(mAccount->connected());
 
     // now set the account offline and see if the active flag changes correctly
-    mMockController->setOnline(false);
+    mMockController->SetOnline(false);
     QTRY_VERIFY(!mAccount->connected());
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
 
@@ -192,7 +192,7 @@
 
     // now re-enable the account and check that the entry is updated
     connectedChangedSpy.clear();
-    mMockController->setOnline(true);
+    mMockController->SetOnline(true);
     QTRY_VERIFY(mAccount->connected());
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
 

=== modified file 'tests/libtelephonyservice/CMakeLists.txt'
--- tests/libtelephonyservice/CMakeLists.txt	2015-04-16 21:39:16 +0000
+++ tests/libtelephonyservice/CMakeLists.txt	2015-04-28 21:45:15 +0000
@@ -4,6 +4,7 @@
     ${LIBTELEPHONYSERVICE_DIR}
     ${TP_QT5_INCLUDE_DIRS}
     ${CMAKE_SOURCE_DIR}/tests/common
+    ${CMAKE_BINARY_DIR}/tests/common
     )
 
 add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)
@@ -36,3 +37,4 @@
 generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp)
 generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp)
 generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp)
+generate_telepathy_test(USSDManagerTest SOURCES USSDManagerTest.cpp)

=== modified file 'tests/libtelephonyservice/ChatManagerTest.cpp'
--- tests/libtelephonyservice/ChatManagerTest.cpp	2015-03-23 19:59:50 +0000
+++ tests/libtelephonyservice/ChatManagerTest.cpp	2015-04-28 21:45:15 +0000
@@ -98,7 +98,7 @@
     qSort(recipients);
 
     MockController *controller = accountId.startsWith("mock/mock") ? mGenericMockController : mPhoneMockController;
-    QSignalSpy controllerMessageSentSpy(controller, SIGNAL(messageSent(QString,QVariantMap)));
+    QSignalSpy controllerMessageSentSpy(controller, SIGNAL(MessageSent(QString,QVariantMap)));
     QSignalSpy messageSentSpy(ChatManager::instance(), SIGNAL(messageSent(QStringList,QString)));
 
     ChatManager::instance()->sendMessage(recipients, message, accountId);
@@ -127,7 +127,7 @@
     properties["Sender"] = "12345";
     properties["Recipients"] = (QStringList() << "12345");
     QString message("Hi there");
-    mGenericMockController->placeIncomingMessage(message, properties);
+    mGenericMockController->PlaceIncomingMessage(message, properties);
 
     QTRY_COMPARE(messageReceivedSpy.count(), 1);
     QString sender = messageReceivedSpy.first()[0].toString();
@@ -146,7 +146,7 @@
     QStringList messages;
     messages << "Hi there" << "How are you" << "Always look on the bright side of life";
     Q_FOREACH(const QString &message, messages) {
-        mGenericMockController->placeIncomingMessage(message, properties);
+        mGenericMockController->PlaceIncomingMessage(message, properties);
         QTest::qWait(100);
     }
     QTRY_COMPARE(messageReceivedSpy.count(), messages.count());
@@ -157,7 +157,7 @@
         messageIds << messageId;
     }
 
-    QSignalSpy messageReadSpy(mGenericMockController, SIGNAL(messageRead(QString)));
+    QSignalSpy messageReadSpy(mGenericMockController, SIGNAL(MessageRead(QString)));
     Q_FOREACH(const QString &messageId, messageIds) {
         ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0");
     }

=== modified file 'tests/libtelephonyservice/OfonoAccountEntryTest.cpp'
--- tests/libtelephonyservice/OfonoAccountEntryTest.cpp	2015-04-16 16:45:59 +0000
+++ tests/libtelephonyservice/OfonoAccountEntryTest.cpp	2015-04-28 21:45:15 +0000
@@ -100,13 +100,13 @@
     QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));
 
     // now set the account offline and see if the active flag changes correctly
-    mMockController->setOnline(false);
+    mMockController->SetOnline(false);
     QTRY_VERIFY(!mAccount->connected());
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
 
     // now re-enable the account and check that the entry is updated
     connectedChangedSpy.clear();
-    mMockController->setOnline(true);
+    mMockController->SetOnline(true);
     QTRY_VERIFY(mAccount->connected());
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
 }
@@ -141,7 +141,7 @@
     QStringList numbers;
     numbers << "111" << "190" << "911";
     qSort(numbers);
-    mMockController->setEmergencyNumbers(numbers);
+    mMockController->SetEmergencyNumbers(numbers);
     QTRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);
 
     QStringList emergencyNumbers = mAccount->emergencyNumbers();
@@ -163,13 +163,13 @@
     QSignalSpy voiceMailIndicatorSpy(mAccount, SIGNAL(voicemailIndicatorChanged()));
 
     // set to true
-    mMockController->setVoicemailIndicator(true);
+    mMockController->SetVoicemailIndicator(true);
     QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
     QTRY_VERIFY(mAccount->voicemailIndicator());
 
     // and set back to false
     voiceMailIndicatorSpy.clear();
-    mMockController->setVoicemailIndicator(false);
+    mMockController->SetVoicemailIndicator(false);
     QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
     QTRY_VERIFY(!mAccount->voicemailIndicator());
 }
@@ -179,11 +179,11 @@
     QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged()));
 
     // check that the number is not empty at startup
-    QVERIFY(!mAccount->voicemailNumber().isEmpty());
+    QTRY_VERIFY(!mAccount->voicemailNumber().isEmpty());
 
     // try changing the number
     QString number("12345");
-    mMockController->setVoicemailNumber(number);
+    mMockController->SetVoicemailNumber(number);
     QTRY_COMPARE(voicemailNumberSpy.count(), 1);
     QCOMPARE(mAccount->voicemailNumber(), number);
 }
@@ -197,13 +197,13 @@
 
     // set it to a bigger value
     int count = 10;
-    mMockController->setVoicemailCount(count);
+    mMockController->SetVoicemailCount(count);
     QTRY_COMPARE(voicemailCountSpy.count(), 1);
     QCOMPARE((int)mAccount->voicemailCount(), count);
 
     // and back to zero
     voicemailCountSpy.clear();
-    mMockController->setVoicemailCount(0);
+    mMockController->SetVoicemailCount(0);
     QTRY_COMPARE(voicemailCountSpy.count(), 1);
     QCOMPARE((int)mAccount->voicemailCount(), 0);
 }
@@ -216,7 +216,7 @@
     QVERIFY(!mAccount->simLocked());
 
     // now try to set the status to simlocked
-    mMockController->setPresence("simlocked", "simlocked");
+    mMockController->SetPresence("simlocked", "simlocked");
     QTRY_COMPARE(simLockedSpy.count(), 1);
     QVERIFY(mAccount->simLocked());
 }
@@ -245,7 +245,7 @@
     QFETCH(QString, status);
     QFETCH(bool, available);
 
-    mMockController->setPresence(status, "");
+    mMockController->SetPresence(status, "");
     QTRY_COMPARE(mAccount->status(), status);
     QCOMPARE(mAccount->emergencyCallsAvailable(), available);
 }
@@ -256,7 +256,7 @@
 
     // set the value
     QString statusMessage("SomeNetwork");
-    mMockController->setPresence("available", statusMessage);
+    mMockController->SetPresence("available", statusMessage);
 
     QTRY_COMPARE(mAccount->networkName(), statusMessage);
     QTRY_COMPARE(networkNameChangedSpy.count(), 1);

=== modified file 'tests/libtelephonyservice/TelepathyHelperTest.cpp'
--- tests/libtelephonyservice/TelepathyHelperTest.cpp	2015-04-16 02:51:08 +0000
+++ tests/libtelephonyservice/TelepathyHelperTest.cpp	2015-04-28 21:45:15 +0000
@@ -37,6 +37,7 @@
     void cleanup();
     void testConnected();
     void testAccounts();
+    void testPhoneAccounts();
     void testAccountSorting();
     void testAccountIds();
     void testActiveAccounts();
@@ -90,25 +91,25 @@
     QVERIFY(TelepathyHelper::instance()->connected());
 
     // set one of the accounts offline and check that the connected status stays true
-    mGenericController->setOnline(false);
+    mGenericController->SetOnline(false);
     QTest::qWait(1000);
     QCOMPARE(connectedChangedSpy.count(), 0);
     QVERIFY(TelepathyHelper::instance()->connected());
 
     // and set the other account as offline too. This time connected needs to change to false
-    mPhoneController->setOnline(false);
+    mPhoneController->SetOnline(false);
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
     QVERIFY(!TelepathyHelper::instance()->connected());
 
     // now set one of the accounts back online
     connectedChangedSpy.clear();
-    mPhoneController->setOnline(true);
+    mPhoneController->SetOnline(true);
     QTRY_COMPARE(connectedChangedSpy.count(), 1);
     QVERIFY(TelepathyHelper::instance()->connected());
 
     // and the other one just in case
     connectedChangedSpy.clear();
-    mGenericController->setOnline(true);
+    mGenericController->SetOnline(true);
     QTest::qWait(1000);
     QCOMPARE(connectedChangedSpy.count(), 0);
     QVERIFY(TelepathyHelper::instance()->connected());
@@ -147,6 +148,37 @@
     QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());
 }
 
+void TelepathyHelperTest::testPhoneAccounts()
+{
+    QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 1);
+    AccountEntry *phoneAccount = TelepathyHelper::instance()->phoneAccounts()[0];
+    QVERIFY(phoneAccount->accountId() == mPhoneTpAccount->uniqueIdentifier());
+
+    // now check that new phone accounts are captured
+    QSignalSpy phoneAccountsChangedSpy(TelepathyHelper::instance(), SIGNAL(phoneAccountsChanged()));
+    Tp::AccountPtr newAccount = addAccount("mock", "ofono", "extra");
+    QVERIFY(!newAccount.isNull());
+
+    QTRY_COMPARE(phoneAccountsChangedSpy.count(), 1);
+    QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 2);
+
+    bool accountFound = false;
+    Q_FOREACH(AccountEntry *entry, TelepathyHelper::instance()->phoneAccounts()) {
+        if (entry->accountId() == newAccount->uniqueIdentifier()) {
+            accountFound = true;
+            break;
+        }
+    }
+    QVERIFY(accountFound);
+
+    // now remove the extra phone account and make sure it is properly removed
+    phoneAccountsChangedSpy.clear();
+    QVERIFY(removeAccount(newAccount));
+    QTRY_COMPARE(phoneAccountsChangedSpy.count(), 1);
+    QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 1);
+    QCOMPARE(TelepathyHelper::instance()->phoneAccounts()[0]->accountId(), phoneAccount->accountId());
+}
+
 void TelepathyHelperTest::testAccountSorting()
 {
     // create two accounts with modem-objpath parameters and make sure they are listed first
@@ -215,21 +247,21 @@
     QCOMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);
 
     // now set one of the accounts as offline and make sure it is captured
-    mGenericController->setOnline(false);
+    mGenericController->SetOnline(false);
     QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);
     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);
+    mPhoneController->SetOnline(false);
     QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);
     QVERIFY(TelepathyHelper::instance()->activeAccounts().isEmpty());
 
     // and set both accounts online again
     activeAccountsSpy.clear();
-    mGenericController->setOnline(true);
-    mPhoneController->setOnline(true);
+    mGenericController->SetOnline(true);
+    mPhoneController->SetOnline(true);
     QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 2, DEFAULT_TIMEOUT);
     QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);
 }
@@ -262,25 +294,25 @@
     QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
 
     // set the generic account as "flightmode" and make sure it doesn't affect the emergencyCallsAvailable
-    mGenericController->setPresence("flightmode", "");
+    mGenericController->SetPresence("flightmode", "");
     QTest::qWait(500);
     QCOMPARE(emergencyCallsSpy.count(), 0);
     QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
 
     // now set the phone account as "flightmode", and see if the emergencyCallsAvailable value
-    mPhoneController->setPresence("flightmode", "");
+    mPhoneController->SetPresence("flightmode", "");
     QTRY_COMPARE(emergencyCallsSpy.count(), 1);
     QVERIFY(!TelepathyHelper::instance()->emergencyCallsAvailable());
 
     // set the generic account online and check if it affects the value
     emergencyCallsSpy.clear();
-    mGenericController->setOnline(true);
+    mGenericController->SetOnline(true);
     QTest::qWait(500);
     QCOMPARE(emergencyCallsSpy.count(), 0);
     QVERIFY(!TelepathyHelper::instance()->emergencyCallsAvailable());
 
     // and finally set the phone account back online
-    mPhoneController->setOnline(true);
+    mPhoneController->SetOnline(true);
     QTRY_COMPARE(emergencyCallsSpy.count(), 1);
     QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
 }

=== added file 'tests/libtelephonyservice/USSDManagerTest.cpp'
--- tests/libtelephonyservice/USSDManagerTest.cpp	1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/USSDManagerTest.cpp	2015-04-28 21:45:15 +0000
@@ -0,0 +1,331 @@
+/*
+ * 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 "ofonoaccountentry.h"
+#include "accountentryfactory.h"
+#include "telepathyhelper.h"
+#include "mockcontroller.h"
+#include "ussdmanager.h"
+
+class USSDManagerTest : public TelepathyTest
+{
+    Q_OBJECT
+
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+    void cleanup();
+    void testInitiate();
+    void testRespond();
+    void testCancel();
+    void testActive_data();
+    void testActive();
+    void testActiveChanged();
+    void testState();
+    void testNotificationReceived();
+    void testRequestReceived();
+    void testInitiateUSSDComplete();
+    void testRespondComplete_data();
+    void testRespondComplete();
+    void testBarringComplete();
+    void testForwardingComplete();
+    void testWaitingComplete();
+    void testCallingLinePresentationComplete();
+    void testConnectedLinePresentationComplete();
+    void testCallingLineRestrictionComplete();
+    void testConnectedLineRestrictionComplete();
+    void testInitiateFailed();
+    void testAccountReconnect();
+
+private:
+    OfonoAccountEntry *mAccount;
+    Tp::AccountPtr mTpAccount;
+    MockController *mMockController;
+    USSDManager *mManager;
+};
+
+void USSDManagerTest::initTestCase()
+{
+    initialize();
+}
+
+void USSDManagerTest::init()
+{
+    mTpAccount = addAccount("mock", "ofono", "the account");
+    QVERIFY(!mTpAccount.isNull());
+    QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
+
+    mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this));
+    QVERIFY(mAccount);
+
+    // make sure the connection is available
+    QTRY_VERIFY(!mTpAccount->connection().isNull());
+    QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
+    QTRY_VERIFY(mAccount->connected());
+
+    // and create the mock controller
+    mMockController = new MockController("ofono", this);
+    mManager = new USSDManager(mAccount, mAccount);
+}
+
+void USSDManagerTest::cleanup()
+{
+    doCleanup();
+
+    mAccount->deleteLater();
+    mMockController->deleteLater();
+    mManager->deleteLater();
+}
+
+void USSDManagerTest::testInitiate()
+{
+    QString command("initiatecommand");
+    QSignalSpy initiateSpy(mMockController, SIGNAL(USSDInitiateCalled(QString)));
+    mManager->initiate(command);
+    QTRY_COMPARE(initiateSpy.count(), 1);
+    QCOMPARE(initiateSpy.first()[0].toString(), command);
+}
+
+void USSDManagerTest::testRespond()
+{
+    QString reply("somereply");
+    QSignalSpy respondSpy(mMockController, SIGNAL(USSDRespondCalled(QString)));
+    mManager->respond(reply);
+    QTRY_COMPARE(respondSpy.count(), 1);
+    QCOMPARE(respondSpy.first()[0].toString(), reply);
+}
+
+void USSDManagerTest::testCancel()
+{
+    QSignalSpy cancelSpy(mMockController, SIGNAL(USSDCancelCalled()));
+    mManager->cancel();
+    QTRY_COMPARE(cancelSpy.count(), 1);
+}
+
+void USSDManagerTest::testActive_data()
+{
+    QTest::addColumn<QString>("state");
+    QTest::addColumn<bool>("active");
+
+    QTest::newRow("idle is inactive") << "idle" << false;
+    QTest::newRow("active is active") << "active" << true;
+    QTest::newRow("anything else is active") << "blabla" << true;
+}
+
+void USSDManagerTest::testActive()
+{
+    QFETCH(QString, state);
+    QFETCH(bool, active);
+    mMockController->TriggerUSSDStateChanged(state);
+    QTRY_COMPARE(mManager->active(), active);
+}
+
+void USSDManagerTest::testActiveChanged()
+{
+    QSignalSpy activeSpy(mManager, SIGNAL(activeChanged()));
+    mMockController->TriggerUSSDStateChanged("active");
+    QTRY_COMPARE(activeSpy.count(), 1);
+}
+
+void USSDManagerTest::testState()
+{
+    QString state = "foobar";
+    QSignalSpy stateSpy(mManager, SIGNAL(stateChanged(QString)));
+    mMockController->TriggerUSSDStateChanged(state);
+    QTRY_COMPARE(stateSpy.count(), 1);
+    QCOMPARE(stateSpy.first()[0].toString(), state);
+    QCOMPARE(mManager->state(), state);
+}
+
+void USSDManagerTest::testNotificationReceived()
+{
+    QString notification("the notification");
+    QSignalSpy notificationReceivedSpy(mManager, SIGNAL(notificationReceived(QString)));
+    mMockController->TriggerUSSDNotificationReceived(notification);
+    QTRY_COMPARE(notificationReceivedSpy.count(), 1);
+    QCOMPARE(notificationReceivedSpy.first()[0].toString(), notification);
+}
+
+void USSDManagerTest::testRequestReceived()
+{
+    QString request("the notification");
+    QSignalSpy requestReceivedSpy(mManager, SIGNAL(requestReceived(QString)));
+    mMockController->TriggerUSSDRequestReceived(request);
+    QTRY_COMPARE(requestReceivedSpy.count(), 1);
+    QCOMPARE(requestReceivedSpy.first()[0].toString(), request);
+}
+
+void USSDManagerTest::testInitiateUSSDComplete()
+{
+    QString response("some response");
+    QSignalSpy initiateUSSDCompleteSpy(mManager, SIGNAL(initiateUSSDComplete(QString)));
+    mMockController->TriggerUSSDInitiateUSSDComplete(response);
+    QTRY_COMPARE(initiateUSSDCompleteSpy.count(), 1);
+    QCOMPARE(initiateUSSDCompleteSpy.first()[0].toString(), response);
+}
+
+void USSDManagerTest::testRespondComplete_data()
+{
+    QTest::addColumn<bool>("success");
+    QTest::addColumn<QString>("response");
+
+    QTest::newRow("success") << true << "somesuccessvalue";
+    QTest::newRow("failure") << false << "somefailurevalue";
+}
+
+void USSDManagerTest::testRespondComplete()
+{
+    QFETCH(bool, success);
+    QFETCH(QString, response);
+    QSignalSpy respondCompleteSpy(mManager, SIGNAL(respondComplete(bool,QString)));
+    mMockController->TriggerUSSDRespondComplete(success, response);
+    QTRY_COMPARE(respondCompleteSpy.count(), 1);
+    QCOMPARE(respondCompleteSpy.first()[0].toBool(), success);
+    QCOMPARE(respondCompleteSpy.first()[1].toString(), response);
+}
+
+void USSDManagerTest::testBarringComplete()
+{
+    QString op("theOp");
+    QString service("theService");
+    QVariantMap map;
+    map["op"] = op;
+    map["service"] = service;
+
+    QSignalSpy barringCompleteSpy(mManager, SIGNAL(barringComplete(QString,QString,QVariantMap)));
+    mMockController->TriggerUSSDBarringComplete(op, service, map);
+    QTRY_COMPARE(barringCompleteSpy.count(), 1);
+    QCOMPARE(barringCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(barringCompleteSpy.first()[1].toString(), service);
+    QCOMPARE(barringCompleteSpy.first()[2].toMap(), map);
+}
+
+void USSDManagerTest::testForwardingComplete()
+{
+    QString op("theOtherOp");
+    QString service("theOtherService");
+    QVariantMap map;
+    map["op"] = op;
+    map["service"] = service;
+    map["count"] = 1;
+
+    QSignalSpy forwardingCompleteSpy(mManager, SIGNAL(forwardingComplete(QString,QString,QVariantMap)));
+    mMockController->TriggerUSSDForwardingComplete(op, service, map);
+    QTRY_COMPARE(forwardingCompleteSpy.count(), 1);
+    QCOMPARE(forwardingCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(forwardingCompleteSpy.first()[1].toString(), service);
+    QCOMPARE(forwardingCompleteSpy.first()[2].toMap(), map);
+}
+
+void USSDManagerTest::testWaitingComplete()
+{
+    QString op("anotherOp");
+    QVariantMap map;
+    map["op"] = op;
+    map["one"] = 1;
+    map["two"] = 2;
+
+    QSignalSpy waitingCompleteSpy(mManager, SIGNAL(waitingComplete(QString,QVariantMap)));
+    mMockController->TriggerUSSDWaitingComplete(op, map);
+    QTRY_COMPARE(waitingCompleteSpy.count(), 1);
+    QCOMPARE(waitingCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(waitingCompleteSpy.first()[1].toMap(), map);
+}
+
+void USSDManagerTest::testCallingLinePresentationComplete()
+{
+    QString op("clpOp");
+    QString status("clpStatus");
+
+    QSignalSpy clpCompleteSpy(mManager, SIGNAL(callingLinePresentationComplete(QString,QString)));
+    mMockController->TriggerUSSDCallingLinePresentationComplete(op, status);
+    QTRY_COMPARE(clpCompleteSpy.count(), 1);
+    QCOMPARE(clpCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(clpCompleteSpy.first()[1].toString(), status);
+}
+
+void USSDManagerTest::testConnectedLinePresentationComplete()
+{
+    QString op("clp2Op");
+    QString status("clp2Status");
+
+    QSignalSpy clpCompleteSpy(mManager, SIGNAL(connectedLinePresentationComplete(QString,QString)));
+    mMockController->TriggerUSSDConnectedLinePresentationComplete(op, status);
+    QTRY_COMPARE(clpCompleteSpy.count(), 1);
+    QCOMPARE(clpCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(clpCompleteSpy.first()[1].toString(), status);
+}
+
+void USSDManagerTest::testCallingLineRestrictionComplete()
+{
+    QString op("clrOp");
+    QString status("clrStatus");
+
+    QSignalSpy clrCompleteSpy(mManager, SIGNAL(callingLineRestrictionComplete(QString,QString)));
+    mMockController->TriggerUSSDCallingLineRestrictionComplete(op, status);
+    QTRY_COMPARE(clrCompleteSpy.count(), 1);
+    QCOMPARE(clrCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(clrCompleteSpy.first()[1].toString(), status);
+}
+
+void USSDManagerTest::testConnectedLineRestrictionComplete()
+{
+    QString op("clr2Op");
+    QString status("clr2Status");
+
+    QSignalSpy clrCompleteSpy(mManager, SIGNAL(connectedLineRestrictionComplete(QString,QString)));
+    mMockController->TriggerUSSDConnectedLineRestrictionComplete(op, status);
+    QTRY_COMPARE(clrCompleteSpy.count(), 1);
+    QCOMPARE(clrCompleteSpy.first()[0].toString(), op);
+    QCOMPARE(clrCompleteSpy.first()[1].toString(), status);
+}
+
+void USSDManagerTest::testInitiateFailed()
+{
+    QSignalSpy initiateFailedSpy(mManager, SIGNAL(initiateFailed()));
+    mMockController->TriggerUSSDInitiateFailed();
+    QTRY_COMPARE(initiateFailedSpy.count(), 1);
+}
+
+void USSDManagerTest::testAccountReconnect()
+{
+    // make sure that methods and signals are working after an account reconnects
+    Q_EMIT mAccount->connectedChanged();
+
+    // and now try one method call
+    QString command("reinitiatecommand");
+    QSignalSpy initiateSpy(mMockController, SIGNAL(USSDInitiateCalled(QString)));
+    mManager->initiate(command);
+    QTRY_COMPARE(initiateSpy.count(), 1);
+    QCOMPARE(initiateSpy.first()[0].toString(), command);
+
+    // and check one of the signals
+    QString state("someCorrectState");
+    QSignalSpy stateChangedSpy(mManager, SIGNAL(stateChanged(QString)));
+    mMockController->TriggerUSSDStateChanged(state);
+    QTRY_COMPARE(stateChangedSpy.count(), 1);
+    QCOMPARE(stateChangedSpy.first()[0].toString(), state);
+    QCOMPARE(mManager->state(), state);
+
+}
+
+QTEST_MAIN(USSDManagerTest)
+#include "USSDManagerTest.moc"

