Merge lp:~boiko/telephony-service/fix_voicemail_detection into lp:telephony-service

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 1083
Merged at revision: 1071
Proposed branch: lp:~boiko/telephony-service/fix_voicemail_detection
Merge into: lp:telephony-service
Diff against target: 1384 lines (+342/-159)
20 files modified
.bzrignore (+1/-0)
cmake/modules/GenerateTest.cmake (+0/-1)
libtelephonyservice/accountentry.cpp (+7/-2)
libtelephonyservice/accountentry.h (+2/-0)
libtelephonyservice/callentry.cpp (+1/-1)
libtelephonyservice/ofonoaccountentry.cpp (+3/-1)
libtelephonyservice/telepathyhelper.cpp (+1/-0)
libtelephonyservice/telepathyhelper.h (+1/-0)
tests/common/mock/connection.cpp (+10/-2)
tests/common/mock/connection.h (+1/-0)
tests/common/mock/mockconnectiondbus.cpp (+24/-0)
tests/common/telepathytest.cpp (+13/-20)
tests/common/telepathytest.h (+7/-1)
tests/handler/HandlerTest.cpp (+23/-26)
tests/libtelephonyservice/AccountEntryTest.cpp (+30/-34)
tests/libtelephonyservice/CMakeLists.txt (+1/-0)
tests/libtelephonyservice/CallEntryTest.cpp (+129/-0)
tests/libtelephonyservice/ChatManagerTest.cpp (+9/-13)
tests/libtelephonyservice/OfonoAccountEntryTest.cpp (+29/-31)
tests/libtelephonyservice/TelepathyHelperTest.cpp (+50/-27)
To merge this branch: bzr merge lp:~boiko/telephony-service/fix_voicemail_detection
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Tiago Salem Herrmann (community) Approve
Review via email: mp+257694@code.launchpad.net

Commit message

Fix voicemail detection on CallEntry.

Description of the change

Fix voicemail detection on CallEntry.

== Checklist ==
Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1066. By Gustavo Pichorim Boiko

Try to fix some flakiness.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1067. By Gustavo Pichorim Boiko

Increase the timeout of all tests so that slow builders don't fail.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1068. By Gustavo Pichorim Boiko

Change the tests in a hope to finally remove the flakiness.

1069. By Gustavo Pichorim Boiko

Fix some possible points of flakiness. The connectedChanged() signal might be emitted more than just once.

1070. By Gustavo Pichorim Boiko

Use the account from telepathyhelper in the callentry test.

1071. By Gustavo Pichorim Boiko

Re-add dbus-monitor to debug the test failures.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1072. By Gustavo Pichorim Boiko

And one more.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1073. By Gustavo Pichorim Boiko

Only set mReady when the connection is actually ready.

1074. By Gustavo Pichorim Boiko

Revert the mReady change.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1075. By Gustavo Pichorim Boiko

Sometimes multiple status changed signals are emitted, so account for that in the tests.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1076. By Gustavo Pichorim Boiko

Some more test fixes.

1077. By Gustavo Pichorim Boiko

Merge latest changes from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1078. By Gustavo Pichorim Boiko

Add debug on the mock dbus calls.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1079. By Gustavo Pichorim Boiko

Wait for the AccountEntry to change the status.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1080. By Gustavo Pichorim Boiko

Only set offline when really necessary.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1081. By Gustavo Pichorim Boiko

Fix some more flakiness points.

1082. By Gustavo Pichorim Boiko

Ignore status changes from the client side to mimic the behavior of telepathy-ofono.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) :
review: Needs Information
1083. By Gustavo Pichorim Boiko

Not having a voicemail number is just a warning, not critical.

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Questions replied.

Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

looks good now.
Thanks.

--Checklist--
Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
No, not related to the changes.

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2015-04-22 13:44:53 +0000
+++ .bzrignore 2015-05-11 13:17:00 +0000
@@ -33,6 +33,7 @@
33indicator/*.desktop33indicator/*.desktop
34indicator/*.service34indicator/*.service
35indicator/NotificationsInterface.*35indicator/NotificationsInterface.*
36indicator/indicatoradaptor.*
3637
37Testing38Testing
38Ubuntu/Telephony/qmldir39Ubuntu/Telephony/qmldir
3940
=== modified file 'cmake/modules/GenerateTest.cmake'
--- cmake/modules/GenerateTest.cmake 2015-04-22 13:20:02 +0000
+++ cmake/modules/GenerateTest.cmake 2015-05-11 13:17:00 +0000
@@ -113,7 +113,6 @@
113 --task dconf -p write -p /org/gnome/empathy/use-conn -p false --task-name dconf-write --wait-for ca.desrt.dconf --ignore-return113 --task dconf -p write -p /org/gnome/empathy/use-conn -p false --task-name dconf-write --wait-for ca.desrt.dconf --ignore-return
114 --task /usr/lib/telepathy/mission-control-5 --task-name mission-control --wait-for ca.desrt.dconf --ignore-return114 --task /usr/lib/telepathy/mission-control-5 --task-name mission-control --wait-for ca.desrt.dconf --ignore-return
115 --task ${CMAKE_BINARY_DIR}/tests/common/mock/telepathy-mock --task-name telepathy-mock --wait-for org.freedesktop.Telepathy.MissionControl5 --ignore-return115 --task ${CMAKE_BINARY_DIR}/tests/common/mock/telepathy-mock --task-name telepathy-mock --wait-for org.freedesktop.Telepathy.MissionControl5 --ignore-return
116 --task dbus-monitor --task-name dbus-monitor --ignore-return
117 # FIXME: maybe it would be better to decide whether to run the handler in a per-test basis?116 # FIXME: maybe it would be better to decide whether to run the handler in a per-test basis?
118 --task ${CMAKE_BINARY_DIR}/handler/telephony-service-handler --task-name telephony-service-handler --wait-for org.freedesktop.Telepathy.ConnectionManager.mock --ignore-return117 --task ${CMAKE_BINARY_DIR}/handler/telephony-service-handler --task-name telephony-service-handler --wait-for org.freedesktop.Telepathy.ConnectionManager.mock --ignore-return
119 ${ARG_TASKS})118 ${ARG_TASKS})
120119
=== modified file 'libtelephonyservice/accountentry.cpp'
--- libtelephonyservice/accountentry.cpp 2015-04-16 16:45:59 +0000
+++ libtelephonyservice/accountentry.cpp 2015-05-11 13:17:00 +0000
@@ -22,14 +22,18 @@
22#include <TelepathyQt/PendingOperation>22#include <TelepathyQt/PendingOperation>
23#include <QTimer>23#include <QTimer>
24#include "accountentry.h"24#include "accountentry.h"
25#include "telepathyhelper.h"
2625
27AccountEntry::AccountEntry(const Tp::AccountPtr &account, QObject *parent) :26AccountEntry::AccountEntry(const Tp::AccountPtr &account, QObject *parent) :
28 QObject(parent), mAccount(account)27 QObject(parent), mAccount(account), mReady(false)
29{28{
30 initialize();29 initialize();
31}30}
3231
32bool AccountEntry::ready() const
33{
34 return mReady;
35}
36
33QString AccountEntry::accountId() const37QString AccountEntry::accountId() const
34{38{
35 if (mAccount.isNull()) {39 if (mAccount.isNull()) {
@@ -184,6 +188,7 @@
184 onConnectionChanged();188 onConnectionChanged();
185 }189 }
186190
191 mReady = true;
187 Q_EMIT accountReady();192 Q_EMIT accountReady();
188}193}
189194
190195
=== modified file 'libtelephonyservice/accountentry.h'
--- libtelephonyservice/accountentry.h 2015-04-14 17:25:36 +0000
+++ libtelephonyservice/accountentry.h 2015-05-11 13:17:00 +0000
@@ -51,6 +51,7 @@
51 GenericAccount51 GenericAccount
52 };52 };
5353
54 bool ready() const;
54 QString accountId() const;55 QString accountId() const;
55 bool active() const;56 bool active() const;
56 QString displayName() const;57 QString displayName() const;
@@ -90,6 +91,7 @@
9091
91 Tp::AccountPtr mAccount;92 Tp::AccountPtr mAccount;
92 ConnectionInfo mConnectionInfo;93 ConnectionInfo mConnectionInfo;
94 bool mReady;
93};95};
9496
95#endif // ACCOUNTENTRY_H97#endif // ACCOUNTENTRY_H
9698
=== modified file 'libtelephonyservice/callentry.cpp'
--- libtelephonyservice/callentry.cpp 2015-02-06 20:44:14 +0000
+++ libtelephonyservice/callentry.cpp 2015-05-11 13:17:00 +0000
@@ -79,7 +79,7 @@
7979
80 // in case the account is an ofono account, we can check the voicemail number80 // in case the account is an ofono account, we can check the voicemail number
81 OfonoAccountEntry *ofonoAccount = qobject_cast<OfonoAccountEntry*>(mAccount);81 OfonoAccountEntry *ofonoAccount = qobject_cast<OfonoAccountEntry*>(mAccount);
82 if (ofonoAccount && ofonoAccount->voicemailNumber().isEmpty()) {82 if (ofonoAccount && !ofonoAccount->voicemailNumber().isEmpty()) {
83 setVoicemail(phoneNumber() == ofonoAccount->voicemailNumber());83 setVoicemail(phoneNumber() == ofonoAccount->voicemailNumber());
84 }84 }
8585
8686
=== modified file 'libtelephonyservice/ofonoaccountentry.cpp'
--- libtelephonyservice/ofonoaccountentry.cpp 2015-04-16 22:26:23 +0000
+++ libtelephonyservice/ofonoaccountentry.cpp 2015-05-11 13:17:00 +0000
@@ -20,8 +20,8 @@
20 */20 */
2121
22#include "ofonoaccountentry.h"22#include "ofonoaccountentry.h"
23#include "phoneutils.h"
23#include "telepathyhelper.h"24#include "telepathyhelper.h"
24#include "phoneutils.h"
2525
26OfonoAccountEntry::OfonoAccountEntry(const Tp::AccountPtr &account, QObject *parent) :26OfonoAccountEntry::OfonoAccountEntry(const Tp::AccountPtr &account, QObject *parent) :
27 AccountEntry(account, parent), mVoicemailCount(0), mVoicemailIndicator(false)27 AccountEntry(account, parent), mVoicemailCount(0), mVoicemailIndicator(false)
@@ -181,6 +181,8 @@
181 if (replyNumber.isValid()) {181 if (replyNumber.isValid()) {
182 mVoicemailNumber = replyNumber.value();182 mVoicemailNumber = replyNumber.value();
183 Q_EMIT voicemailNumberChanged();183 Q_EMIT voicemailNumberChanged();
184 } else {
185 qWarning() << "Could not get voicemail number!";
184 }186 }
185187
186 // connect the voicemail count changed signal188 // connect the voicemail count changed signal
187189
=== modified file 'libtelephonyservice/telepathyhelper.cpp'
--- libtelephonyservice/telepathyhelper.cpp 2015-04-17 20:09:25 +0000
+++ libtelephonyservice/telepathyhelper.cpp 2015-05-11 13:17:00 +0000
@@ -451,6 +451,7 @@
451 Q_EMIT activeAccountsChanged();451 Q_EMIT activeAccountsChanged();
452 onSettingsChanged("defaultSimForMessages");452 onSettingsChanged("defaultSimForMessages");
453 onSettingsChanged("defaultSimForCalls");453 onSettingsChanged("defaultSimForCalls");
454 Q_EMIT accountAdded(accountEntry);
454}455}
455456
456void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op)457void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op)
457458
=== modified file 'libtelephonyservice/telepathyhelper.h'
--- libtelephonyservice/telepathyhelper.h 2015-04-17 20:09:25 +0000
+++ libtelephonyservice/telepathyhelper.h 2015-05-11 13:17:00 +0000
@@ -110,6 +110,7 @@
110 void connectedChanged();110 void connectedChanged();
111 void accountIdsChanged();111 void accountIdsChanged();
112 void accountsChanged();112 void accountsChanged();
113 void accountAdded(AccountEntry *account);
113 void phoneAccountsChanged();114 void phoneAccountsChanged();
114 void activeAccountsChanged();115 void activeAccountsChanged();
115 void setupReady();116 void setupReady();
116117
=== 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-11 13:17:00 +0000
@@ -77,7 +77,7 @@
7777
78 // init presence interface78 // init presence interface
79 simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create();79 simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create();
80 simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresence));80 simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresenceFail));
81 simplePresenceIface->setMaxmimumStatusMessageLength(255);81 simplePresenceIface->setMaxmimumStatusMessageLength(255);
82 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface));82 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface));
8383
@@ -137,7 +137,7 @@
137 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface));137 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface));
138 voicemailIface->setVoicemailCount(mVoicemailCount);138 voicemailIface->setVoicemailCount(mVoicemailCount);
139 voicemailIface->setVoicemailIndicator(mVoicemailIndicator);139 voicemailIface->setVoicemailIndicator(mVoicemailIndicator);
140 mVoicemailNumber = "555";140 mVoicemailNumber = "*555";
141141
142 supplementaryServicesIface = BaseConnectionUSSDInterface::create();142 supplementaryServicesIface = BaseConnectionUSSDInterface::create();
143 supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&MockConnection::USSDInitiate));143 supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&MockConnection::USSDInitiate));
@@ -151,6 +151,8 @@
151 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface));151 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface));
152152
153 mDBus = new MockConnectionDBus(this);153 mDBus = new MockConnectionDBus(this);
154
155 setOnline(true);
154}156}
155157
156MockConnection::~MockConnection()158MockConnection::~MockConnection()
@@ -232,6 +234,12 @@
232 return selfHandle();234 return selfHandle();
233}235}
234236
237uint MockConnection::setPresenceFail(const QString &status, const QString &statusMessage, Tp::DBusError *error)
238{
239 error->set(TP_QT_ERROR_NOT_AVAILABLE, "Can't change online status: Operation not supported");
240 return selfHandle();
241}
242
235Tp::ContactAttributesMap MockConnection::getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error)243Tp::ContactAttributesMap MockConnection::getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error)
236{244{
237 qDebug() << "getContactAttributes" << handles << ifaces;245 qDebug() << "getContactAttributes" << handles << ifaces;
238246
=== 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-11 13:17:00 +0000
@@ -59,6 +59,7 @@
59 uint targetHandle, const QVariantMap& hints, Tp::DBusError *error);59 uint targetHandle, const QVariantMap& hints, Tp::DBusError *error);
60 Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error);60 Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error);
61 uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error);61 uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error);
62 uint setPresenceFail(const QString& status, const QString& statusMessage, Tp::DBusError *error);
62 void connect(Tp::DBusError *error);63 void connect(Tp::DBusError *error);
63 void setOnline(bool online);64 void setOnline(bool online);
6465
6566
=== 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-11 13:17:00 +0000
@@ -93,121 +93,145 @@
9393
94void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties)94void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties)
95{95{
96 qDebug() << __PRETTY_FUNCTION__ << message << properties;
96 mConnection->placeIncomingMessage(message, properties);97 mConnection->placeIncomingMessage(message, properties);
97}98}
9899
99QString MockConnectionDBus::PlaceCall(const QVariantMap &properties)100QString MockConnectionDBus::PlaceCall(const QVariantMap &properties)
100{101{
102 qDebug() << __PRETTY_FUNCTION__ << properties;
101 return mConnection->placeCall(properties);103 return mConnection->placeCall(properties);
102}104}
103105
104void MockConnectionDBus::HangupCall(const QString &callerId)106void MockConnectionDBus::HangupCall(const QString &callerId)
105{107{
108 qDebug() << __PRETTY_FUNCTION__ << callerId;
106 mConnection->hangupCall(callerId);109 mConnection->hangupCall(callerId);
107}110}
108111
109void MockConnectionDBus::SetCallState(const QString &phoneNumber, const QString &state)112void MockConnectionDBus::SetCallState(const QString &phoneNumber, const QString &state)
110{113{
114 qDebug() << __PRETTY_FUNCTION__ << phoneNumber << state;
111 mConnection->setCallState(phoneNumber, state);115 mConnection->setCallState(phoneNumber, state);
112}116}
113117
114void MockConnectionDBus::SetOnline(bool online)118void MockConnectionDBus::SetOnline(bool online)
115{119{
120 qDebug() << __PRETTY_FUNCTION__ << online;
116 mConnection->setOnline(online);121 mConnection->setOnline(online);
117}122}
118123
119void MockConnectionDBus::SetPresence(const QString &status, const QString &statusMessage)124void MockConnectionDBus::SetPresence(const QString &status, const QString &statusMessage)
120{125{
126 qDebug() << __PRETTY_FUNCTION__ << status << statusMessage;
121 Tp::DBusError error;127 Tp::DBusError error;
122 mConnection->setPresence(status, statusMessage, &error);128 mConnection->setPresence(status, statusMessage, &error);
123}129}
124130
125void MockConnectionDBus::SetVoicemailIndicator(bool active)131void MockConnectionDBus::SetVoicemailIndicator(bool active)
126{132{
133 qDebug() << __PRETTY_FUNCTION__ << active;
127 mConnection->setVoicemailIndicator(active);134 mConnection->setVoicemailIndicator(active);
128}135}
129136
130void MockConnectionDBus::SetVoicemailNumber(const QString &number)137void MockConnectionDBus::SetVoicemailNumber(const QString &number)
131{138{
139 qDebug() << __PRETTY_FUNCTION__ << number;
132 mConnection->setVoicemailNumber(number);140 mConnection->setVoicemailNumber(number);
133}141}
134142
135void MockConnectionDBus::SetVoicemailCount(int count)143void MockConnectionDBus::SetVoicemailCount(int count)
136{144{
145 qDebug() << __PRETTY_FUNCTION__ << count;
137 mConnection->setVoicemailCount(count);146 mConnection->setVoicemailCount(count);
138}147}
139148
140void MockConnectionDBus::SetEmergencyNumbers(const QStringList &numbers)149void MockConnectionDBus::SetEmergencyNumbers(const QStringList &numbers)
141{150{
151 qDebug() << __PRETTY_FUNCTION__ << numbers;
142 mConnection->setEmergencyNumbers(numbers);152 mConnection->setEmergencyNumbers(numbers);
143}153}
144154
145QString MockConnectionDBus::Serial()155QString MockConnectionDBus::Serial()
146{156{
157 qDebug() << __PRETTY_FUNCTION__ << mConnection->serial();
147 return mConnection->serial();158 return mConnection->serial();
148}159}
149160
150void MockConnectionDBus::TriggerUSSDNotificationReceived(const QString &message)161void MockConnectionDBus::TriggerUSSDNotificationReceived(const QString &message)
151{162{
163 qDebug() << __PRETTY_FUNCTION__ << message;
152 mConnection->supplementaryServicesIface->NotificationReceived(message);164 mConnection->supplementaryServicesIface->NotificationReceived(message);
153}165}
154166
155void MockConnectionDBus::TriggerUSSDRequestReceived(const QString &message)167void MockConnectionDBus::TriggerUSSDRequestReceived(const QString &message)
156{168{
169 qDebug() << __PRETTY_FUNCTION__ << message;
157 mConnection->supplementaryServicesIface->RequestReceived(message);170 mConnection->supplementaryServicesIface->RequestReceived(message);
158}171}
159172
160void MockConnectionDBus::TriggerUSSDInitiateUSSDComplete(const QString &ussdResp)173void MockConnectionDBus::TriggerUSSDInitiateUSSDComplete(const QString &ussdResp)
161{174{
175 qDebug() << __PRETTY_FUNCTION__ << ussdResp;
162 mConnection->supplementaryServicesIface->InitiateUSSDComplete(ussdResp);176 mConnection->supplementaryServicesIface->InitiateUSSDComplete(ussdResp);
163}177}
164178
165void MockConnectionDBus::TriggerUSSDRespondComplete(bool success, const QString &ussdResp)179void MockConnectionDBus::TriggerUSSDRespondComplete(bool success, const QString &ussdResp)
166{180{
181 qDebug() << __PRETTY_FUNCTION__ << ussdResp;
167 mConnection->supplementaryServicesIface->RespondComplete(success, ussdResp);182 mConnection->supplementaryServicesIface->RespondComplete(success, ussdResp);
168}183}
169184
170void MockConnectionDBus::TriggerUSSDBarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)185void MockConnectionDBus::TriggerUSSDBarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)
171{186{
187 qDebug() << __PRETTY_FUNCTION__ << ssOp << cbService << cbMap;
172 mConnection->supplementaryServicesIface->BarringComplete(ssOp, cbService, cbMap);188 mConnection->supplementaryServicesIface->BarringComplete(ssOp, cbService, cbMap);
173}189}
174190
175void MockConnectionDBus::TriggerUSSDForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)191void MockConnectionDBus::TriggerUSSDForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)
176{192{
193 qDebug() << __PRETTY_FUNCTION__ << ssOp << cfService << cfMap;
177 mConnection->supplementaryServicesIface->ForwardingComplete(ssOp, cfService, cfMap);194 mConnection->supplementaryServicesIface->ForwardingComplete(ssOp, cfService, cfMap);
178}195}
179196
180void MockConnectionDBus::TriggerUSSDWaitingComplete(const QString &ssOp, const QVariantMap &cwMap)197void MockConnectionDBus::TriggerUSSDWaitingComplete(const QString &ssOp, const QVariantMap &cwMap)
181{198{
199 qDebug() << __PRETTY_FUNCTION__ << ssOp << cwMap;
182 mConnection->supplementaryServicesIface->WaitingComplete(ssOp, cwMap);200 mConnection->supplementaryServicesIface->WaitingComplete(ssOp, cwMap);
183}201}
184202
185void MockConnectionDBus::TriggerUSSDCallingLinePresentationComplete(const QString &ssOp, const QString &status)203void MockConnectionDBus::TriggerUSSDCallingLinePresentationComplete(const QString &ssOp, const QString &status)
186{204{
205 qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
187 mConnection->supplementaryServicesIface->CallingLinePresentationComplete(ssOp, status);206 mConnection->supplementaryServicesIface->CallingLinePresentationComplete(ssOp, status);
188}207}
189208
190void MockConnectionDBus::TriggerUSSDConnectedLinePresentationComplete(const QString &ssOp, const QString &status)209void MockConnectionDBus::TriggerUSSDConnectedLinePresentationComplete(const QString &ssOp, const QString &status)
191{210{
211 qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
192 mConnection->supplementaryServicesIface->ConnectedLinePresentationComplete(ssOp, status);212 mConnection->supplementaryServicesIface->ConnectedLinePresentationComplete(ssOp, status);
193}213}
194214
195void MockConnectionDBus::TriggerUSSDCallingLineRestrictionComplete(const QString &ssOp, const QString &status)215void MockConnectionDBus::TriggerUSSDCallingLineRestrictionComplete(const QString &ssOp, const QString &status)
196{216{
217 qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
197 mConnection->supplementaryServicesIface->CallingLineRestrictionComplete(ssOp, status);218 mConnection->supplementaryServicesIface->CallingLineRestrictionComplete(ssOp, status);
198}219}
199220
200void MockConnectionDBus::TriggerUSSDConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)221void MockConnectionDBus::TriggerUSSDConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)
201{222{
223 qDebug() << __PRETTY_FUNCTION__ << ssOp << status;
202 mConnection->supplementaryServicesIface->ConnectedLineRestrictionComplete(ssOp, status);224 mConnection->supplementaryServicesIface->ConnectedLineRestrictionComplete(ssOp, status);
203}225}
204226
205void MockConnectionDBus::TriggerUSSDInitiateFailed()227void MockConnectionDBus::TriggerUSSDInitiateFailed()
206{228{
229 qDebug() << __PRETTY_FUNCTION__;
207 mConnection->supplementaryServicesIface->InitiateFailed();230 mConnection->supplementaryServicesIface->InitiateFailed();
208}231}
209232
210void MockConnectionDBus::TriggerUSSDStateChanged(const QString &state)233void MockConnectionDBus::TriggerUSSDStateChanged(const QString &state)
211{234{
235 qDebug() << __PRETTY_FUNCTION__ << state;
212 mConnection->supplementaryServicesIface->StateChanged(state);236 mConnection->supplementaryServicesIface->StateChanged(state);
213}237}
214238
=== modified file 'tests/common/telepathytest.cpp'
--- tests/common/telepathytest.cpp 2015-03-27 02:47:52 +0000
+++ tests/common/telepathytest.cpp 2015-05-11 13:17:00 +0000
@@ -17,7 +17,6 @@
17 */17 */
1818
19#include <QtCore/QObject>19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include <TelepathyQt/PendingAccount>20#include <TelepathyQt/PendingAccount>
22#include <TelepathyQt/PendingOperation>21#include <TelepathyQt/PendingOperation>
23#include <TelepathyQt/Account>22#include <TelepathyQt/Account>
@@ -29,15 +28,6 @@
29{28{
30 Tp::registerTypes();29 Tp::registerTypes();
3130
32 QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(setupReady()));
33 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT);
34
35 // just in case, remove any existing account that might be a leftover from
36 // previous test runs
37 Q_FOREACH(const AccountEntry *account, TelepathyHelper::instance()->accounts()) {
38 QVERIFY(removeAccount(account->account()));
39 }
40
41 // create an account manager instance to help testing31 // create an account manager instance to help testing
42 Tp::Features accountFeatures;32 Tp::Features accountFeatures;
43 accountFeatures << Tp::Account::FeatureCore33 accountFeatures << Tp::Account::FeatureCore
@@ -65,13 +55,15 @@
65 mReady = false;55 mReady = false;
66 connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore),56 connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore),
67 &Tp::PendingOperation::finished, [=]{57 &Tp::PendingOperation::finished, [=]{
58 Q_FOREACH(const Tp::AccountPtr &account, mAccountManager->allAccounts()) {
59 Tp::PendingOperation *op = account->remove();
60 WAIT_FOR(op->isFinished());
61 }
62
68 mReady = true;63 mReady = true;
69 });64 });
7065
71 QTRY_VERIFY(mReady);66 TRY_VERIFY(mReady);
72
73 // give some time for telepathy stuff to settle
74 QTest::qWait(1000);
75}67}
7668
77void TelepathyTest::doCleanup()69void TelepathyTest::doCleanup()
@@ -101,9 +93,11 @@
101 finished = true;93 finished = true;
102 });94 });
10395
104 while (!finished) {96 WAIT_FOR(finished);
105 QTest::qWait(100);97 WAIT_FOR(!account->connection().isNull());
106 }98 WAIT_FOR(account->connectionStatus() == Tp::ConnectionStatusConnected);
99 WAIT_FOR(account->connection()->selfContact()->presence().type() == Tp::ConnectionPresenceTypeAvailable);
100
107 mAccounts << account;101 mAccounts << account;
108 return account;102 return account;
109}103}
@@ -119,9 +113,8 @@
119 finished = true;113 finished = true;
120 });114 });
121115
122 while (!finished) {116 WAIT_FOR(finished);
123 QTest::qWait(100);117
124 }
125 if (success) {118 if (success) {
126 mAccounts.removeAll(account);119 mAccounts.removeAll(account);
127 }120 }
128121
=== modified file 'tests/common/telepathytest.h'
--- tests/common/telepathytest.h 2015-03-30 18:48:38 +0000
+++ tests/common/telepathytest.h 2015-05-11 13:17:00 +0000
@@ -20,11 +20,17 @@
20#define TELEPATHYTEST_H20#define TELEPATHYTEST_H
2121
22#include <QtCore/QObject>22#include <QtCore/QObject>
23#include <QtTest/QtTest>
23#include <TelepathyQt/Account>24#include <TelepathyQt/Account>
24#include "telepathyhelper.h"25#include <TelepathyQt/AccountManager>
2526
26#define DEFAULT_TIMEOUT 1500027#define DEFAULT_TIMEOUT 15000
2728
29#define TRY_VERIFY(x) QTRY_VERIFY_WITH_TIMEOUT((x), DEFAULT_TIMEOUT)
30#define TRY_COMPARE(x, y) QTRY_COMPARE_WITH_TIMEOUT((x), (y), DEFAULT_TIMEOUT)
31
32#define WAIT_FOR(x) while (!(x)) { qDebug() << "Waiting for:" << #x ; QTest::qWait(100); }
33
28class TelepathyTest : public QObject34class TelepathyTest : public QObject
29{35{
30 Q_OBJECT36 Q_OBJECT
3137
=== modified file 'tests/handler/HandlerTest.cpp'
--- tests/handler/HandlerTest.cpp 2015-04-17 21:26:25 +0000
+++ tests/handler/HandlerTest.cpp 2015-05-11 13:17:00 +0000
@@ -53,22 +53,19 @@
53{53{
54 initialize();54 initialize();
5555
56 QSignalSpy setupReadySpy(TelepathyHelper::instance(), SIGNAL(setupReady()));
57 TRY_COMPARE(setupReadySpy.count(), 1);
58
56 // register the approver59 // register the approver
57 mApprover = new Approver(this);60 mApprover = new Approver(this);
58 TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");61 TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");
59 // Tp-qt does not set registered status to approvers62 // Tp-qt does not set registered status to approvers
60 QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));63 TRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));
61}64}
6265
63void HandlerTest::init()66void HandlerTest::init()
64{67{
65 mTpAccount = addAccount("mock", "mock", "the account");68 mTpAccount = addAccount("mock", "mock", "the account");
66 QVERIFY(!mTpAccount.isNull());
67 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
68
69 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
7269
73 // and create the mock controller70 // and create the mock controller
74 mMockController = new MockController("mock", this);71 mMockController = new MockController("mock", this);
@@ -86,7 +83,7 @@
86 QSignalSpy callReceivedSpy(mMockController, SIGNAL(CallReceived(QString)));83 QSignalSpy callReceivedSpy(mMockController, SIGNAL(CallReceived(QString)));
87 // FIXME: add support for multiple accounts84 // FIXME: add support for multiple accounts
88 HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier());85 HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier());
89 QTRY_COMPARE(callReceivedSpy.count(), 1);86 TRY_COMPARE(callReceivedSpy.count(), 1);
90 QCOMPARE(callReceivedSpy.first().first().toString(), callerId);87 QCOMPARE(callReceivedSpy.first().first().toString(), callerId);
9188
92 mMockController->HangupCall(callerId);89 mMockController->HangupCall(callerId);
@@ -105,7 +102,7 @@
105 QVERIFY(!objectPath.isEmpty());102 QVERIFY(!objectPath.isEmpty());
106103
107 // wait for the channel to hit the approver104 // wait for the channel to hit the approver
108 QTRY_COMPARE(approverCallSpy.count(), 1);105 TRY_COMPARE(approverCallSpy.count(), 1);
109 mApprover->acceptCall();106 mApprover->acceptCall();
110107
111 waitForCallActive(callerId);108 waitForCallActive(callerId);
@@ -113,7 +110,7 @@
113 // and finally request the hangup110 // and finally request the hangup
114 QSignalSpy callEndedSpy(mMockController, SIGNAL(CallEnded(QString)));111 QSignalSpy callEndedSpy(mMockController, SIGNAL(CallEnded(QString)));
115 HandlerController::instance()->hangUpCall(objectPath);112 HandlerController::instance()->hangUpCall(objectPath);
116 QTRY_COMPARE(callEndedSpy.count(), 1);113 TRY_COMPARE(callEndedSpy.count(), 1);
117}114}
118115
119void HandlerTest::testCallHold()116void HandlerTest::testCallHold()
@@ -129,7 +126,7 @@
129 QVERIFY(!objectPath.isEmpty());126 QVERIFY(!objectPath.isEmpty());
130127
131 // wait for the channel to hit the approver128 // wait for the channel to hit the approver
132 QTRY_COMPARE(approverCallSpy.count(), 1);129 TRY_COMPARE(approverCallSpy.count(), 1);
133 mApprover->acceptCall();130 mApprover->acceptCall();
134131
135 waitForCallActive(callerId);132 waitForCallActive(callerId);
@@ -138,13 +135,13 @@
138135
139 // set the call on hold136 // set the call on hold
140 HandlerController::instance()->setHold(objectPath, true);137 HandlerController::instance()->setHold(objectPath, true);
141 QTRY_COMPARE(callStateSpy.count(), 1);138 TRY_COMPARE(callStateSpy.count(), 1);
142 QCOMPARE(callStateSpy.first()[2].toString(), QString("held"));139 QCOMPARE(callStateSpy.first()[2].toString(), QString("held"));
143140
144 // and now set it as unheld again141 // and now set it as unheld again
145 callStateSpy.clear();142 callStateSpy.clear();
146 HandlerController::instance()->setHold(objectPath, false);143 HandlerController::instance()->setHold(objectPath, false);
147 QTRY_COMPARE(callStateSpy.count(), 1);144 TRY_COMPARE(callStateSpy.count(), 1);
148 QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));145 QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));
149146
150 mMockController->HangupCall(callerId);147 mMockController->HangupCall(callerId);
@@ -163,11 +160,11 @@
163 mMockController->placeCall(properties);160 mMockController->placeCall(properties);
164161
165 // wait for the channel to hit the approver162 // wait for the channel to hit the approver
166 QTRY_COMPARE(approverCallSpy.count(), 1);163 TRY_COMPARE(approverCallSpy.count(), 1);
167 mApprover->acceptCall();164 mApprover->acceptCall();
168165
169 // wait until the call properties are changed166 // wait until the call properties are changed
170 QTRY_VERIFY(handlerCallPropertiesSpy.count() > 0);167 TRY_VERIFY(handlerCallPropertiesSpy.count() > 0);
171 QString objectPath = handlerCallPropertiesSpy.last()[0].toString();168 QString objectPath = handlerCallPropertiesSpy.last()[0].toString();
172 QVariantMap propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();169 QVariantMap propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();
173 QVERIFY(!propsFromSignal.isEmpty());170 QVERIFY(!propsFromSignal.isEmpty());
@@ -194,7 +191,7 @@
194 for (int i = 0; i < dtmfString.length(); ++i) {191 for (int i = 0; i < dtmfString.length(); ++i) {
195 HandlerController::instance()->sendDTMF(objectPath, QString(dtmfString[i]));192 HandlerController::instance()->sendDTMF(objectPath, QString(dtmfString[i]));
196 }193 }
197 QTRY_COMPARE(handlerCallPropertiesSpy.count(), dtmfString.length());194 TRY_COMPARE(handlerCallPropertiesSpy.count(), dtmfString.length());
198 propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();195 propsFromSignal = handlerCallPropertiesSpy.last()[1].toMap();
199 propsFromMethod = HandlerController::instance()->getCallProperties(objectPath);196 propsFromMethod = HandlerController::instance()->getCallProperties(objectPath);
200 QString dtmfStringFromSignal = propsFromSignal["dtmfString"].toString();197 QString dtmfStringFromSignal = propsFromSignal["dtmfString"].toString();
@@ -220,7 +217,7 @@
220 QString call1 = mMockController->placeCall(properties);217 QString call1 = mMockController->placeCall(properties);
221218
222 // wait for the channel to hit the approver219 // wait for the channel to hit the approver
223 QTRY_COMPARE(approverCallSpy.count(), 1);220 TRY_COMPARE(approverCallSpy.count(), 1);
224 mApprover->acceptCall();221 mApprover->acceptCall();
225 approverCallSpy.clear();222 approverCallSpy.clear();
226 waitForCallActive(callerId1);223 waitForCallActive(callerId1);
@@ -229,7 +226,7 @@
229 properties["Caller"] = callerId2;226 properties["Caller"] = callerId2;
230 QString call2 = mMockController->placeCall(properties);227 QString call2 = mMockController->placeCall(properties);
231 // wait for the channel to hit the approver228 // wait for the channel to hit the approver
232 QTRY_COMPARE(approverCallSpy.count(), 1);229 TRY_COMPARE(approverCallSpy.count(), 1);
233 mApprover->acceptCall();230 mApprover->acceptCall();
234 approverCallSpy.clear();231 approverCallSpy.clear();
235 waitForCallActive(callerId2);232 waitForCallActive(callerId2);
@@ -237,13 +234,13 @@
237 // now create the conf call234 // now create the conf call
238 QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(ConferenceCreated(QString)));235 QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(ConferenceCreated(QString)));
239 HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);236 HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);
240 QTRY_COMPARE(conferenceCreatedSpy.count(), 1);237 TRY_COMPARE(conferenceCreatedSpy.count(), 1);
241 QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();238 QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();
242239
243 // now place a third call and try to merge it240 // now place a third call and try to merge it
244 properties["Caller"] = callerId3;241 properties["Caller"] = callerId3;
245 QString call3 = mMockController->placeCall(properties);242 QString call3 = mMockController->placeCall(properties);
246 QTRY_COMPARE(approverCallSpy.count(), 1);243 TRY_COMPARE(approverCallSpy.count(), 1);
247 mApprover->acceptCall();244 mApprover->acceptCall();
248 approverCallSpy.clear();245 approverCallSpy.clear();
249 waitForCallActive(callerId3);246 waitForCallActive(callerId3);
@@ -251,13 +248,13 @@
251 // merge that call on the conference248 // merge that call on the conference
252 QSignalSpy channelMergedSpy(mMockController, SIGNAL(ChannelMerged(QString)));249 QSignalSpy channelMergedSpy(mMockController, SIGNAL(ChannelMerged(QString)));
253 HandlerController::instance()->mergeCall(conferenceObjectPath, call3);250 HandlerController::instance()->mergeCall(conferenceObjectPath, call3);
254 QTRY_COMPARE(channelMergedSpy.count(), 1);251 TRY_COMPARE(channelMergedSpy.count(), 1);
255 QCOMPARE(channelMergedSpy.first().first().toString(), call3);252 QCOMPARE(channelMergedSpy.first().first().toString(), call3);
256253
257 // now try to split one of the channels254 // now try to split one of the channels
258 QSignalSpy channelSplittedSpy(mMockController, SIGNAL(ChannelSplitted(QString)));255 QSignalSpy channelSplittedSpy(mMockController, SIGNAL(ChannelSplitted(QString)));
259 HandlerController::instance()->splitCall(call2);256 HandlerController::instance()->splitCall(call2);
260 QTRY_COMPARE(channelSplittedSpy.count(), 1);257 TRY_COMPARE(channelSplittedSpy.count(), 1);
261 QCOMPARE(channelSplittedSpy.first().first().toString(), call2);258 QCOMPARE(channelSplittedSpy.first().first().toString(), call2);
262259
263 // now hangup the conference and the individual channels260 // now hangup the conference and the individual channels
@@ -277,7 +274,7 @@
277 QSignalSpy messageSentSpy(mMockController, SIGNAL(MessageSent(QString,QVariantMap)));274 QSignalSpy messageSentSpy(mMockController, SIGNAL(MessageSent(QString,QVariantMap)));
278 // FIXME: add support for multiple accounts275 // FIXME: add support for multiple accounts
279 HandlerController::instance()->sendMessage(recipient, message, mTpAccount->uniqueIdentifier());276 HandlerController::instance()->sendMessage(recipient, message, mTpAccount->uniqueIdentifier());
280 QTRY_COMPARE(messageSentSpy.count(), 1);277 TRY_COMPARE(messageSentSpy.count(), 1);
281 QString sentMessage = messageSentSpy.first().first().toString();278 QString sentMessage = messageSentSpy.first().first().toString();
282 QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();279 QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();
283 QCOMPARE(sentMessage, message);280 QCOMPARE(sentMessage, message);
@@ -293,14 +290,14 @@
293290
294 // set the property to true291 // set the property to true
295 HandlerController::instance()->setCallIndicatorVisible(true);292 HandlerController::instance()->setCallIndicatorVisible(true);
296 QTRY_COMPARE(spy.count(), 1);293 TRY_COMPARE(spy.count(), 1);
297 QVERIFY(spy.first().first().toBool());294 QVERIFY(spy.first().first().toBool());
298 QVERIFY(HandlerController::instance()->callIndicatorVisible());295 QVERIFY(HandlerController::instance()->callIndicatorVisible());
299296
300 // and back to false297 // and back to false
301 spy.clear();298 spy.clear();
302 HandlerController::instance()->setCallIndicatorVisible(false);299 HandlerController::instance()->setCallIndicatorVisible(false);
303 QTRY_COMPARE(spy.count(), 1);300 TRY_COMPARE(spy.count(), 1);
304 QVERIFY(!spy.first().first().toBool());301 QVERIFY(!spy.first().first().toBool());
305 QVERIFY(!HandlerController::instance()->callIndicatorVisible());302 QVERIFY(!HandlerController::instance()->callIndicatorVisible());
306}303}
@@ -314,7 +311,7 @@
314 QString caller;311 QString caller;
315 int tries = 0;312 int tries = 0;
316 while (state != "active" && caller != callerId && tries < 5) {313 while (state != "active" && caller != callerId && tries < 5) {
317 QTRY_COMPARE(callStateSpy.count(), 1);314 TRY_COMPARE(callStateSpy.count(), 1);
318 caller = callStateSpy.first()[0].toString();315 caller = callStateSpy.first()[0].toString();
319 objectPath = callStateSpy.first()[1].toString();316 objectPath = callStateSpy.first()[1].toString();
320 state = callStateSpy.first()[2].toString();317 state = callStateSpy.first()[2].toString();
321318
=== modified file 'tests/libtelephonyservice/AccountEntryTest.cpp'
--- tests/libtelephonyservice/AccountEntryTest.cpp 2015-04-21 17:04:29 +0000
+++ tests/libtelephonyservice/AccountEntryTest.cpp 2015-05-11 13:17:00 +0000
@@ -21,7 +21,6 @@
21#include "telepathytest.h"21#include "telepathytest.h"
22#include "accountentry.h"22#include "accountentry.h"
23#include "accountentryfactory.h"23#include "accountentryfactory.h"
24#include "telepathyhelper.h"
25#include "mockcontroller.h"24#include "mockcontroller.h"
2625
27class AccountEntryTest : public TelepathyTest26class AccountEntryTest : public TelepathyTest
@@ -61,21 +60,19 @@
61{60{
62 mTpAccount = addAccount("mock", "mock", "the account");61 mTpAccount = addAccount("mock", "mock", "the account");
63 QVERIFY(!mTpAccount.isNull());62 QVERIFY(!mTpAccount.isNull());
64 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
6563
66 mAccount = AccountEntryFactory::createEntry(mTpAccount, this);64 mAccount = AccountEntryFactory::createEntry(mTpAccount, this);
67 QVERIFY(mAccount);65 QVERIFY(mAccount);
66 TRY_VERIFY(mAccount->ready());
6867
69 // make sure the connection is available68 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());69 TRY_VERIFY(mAccount->connected());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);70
72 QTRY_VERIFY(mAccount->connected());71 // and make sure the status and status message are the ones we expect
72 TRY_COMPARE(mAccount->status(), QString("available"));
7373
74 // and create the mock controller74 // and create the mock controller
75 mMockController = new MockController("mock", this);75 mMockController = new MockController("mock", this);
76
77 // just in case, wait some time
78 QTest::qWait(1000);
79}76}
8077
81void AccountEntryTest::cleanup()78void AccountEntryTest::cleanup()
@@ -94,21 +91,23 @@
9491
95void AccountEntryTest::testActive()92void AccountEntryTest::testActive()
96{93{
94 // the mock account is enabled/connected by default, so make sure it is like that
95 QVERIFY(mAccount->active());
96 // FIXME: setting the account as offline, triggers an automatic reconnection and the
97 // test fails. In the future we might want to re-enable this and test some other way.
97 QSignalSpy activeChangedSpy(mAccount, SIGNAL(activeChanged()));98 QSignalSpy activeChangedSpy(mAccount, SIGNAL(activeChanged()));
9899
99 // the mock account is enabled/connected by default, so make sure it is like that100 // now set the account away and see if the active flag changes correctly
100 QVERIFY(mAccount->active());
101
102 // now set the account offline and see if the active flag changes correctly
103 mMockController->SetOnline(false);101 mMockController->SetOnline(false);
104 QTRY_VERIFY(!mAccount->active());102 TRY_VERIFY(!mAccount->active());
105 QCOMPARE(activeChangedSpy.count(), 1);103 TRY_VERIFY(activeChangedSpy.count() > 0);
104
106105
107 // now re-enable the account and check that the entry is updated106 // now re-enable the account and check that the entry is updated
108 activeChangedSpy.clear();107 activeChangedSpy.clear();
109 mMockController->SetOnline(true);108 mMockController->SetOnline(true);
110 QTRY_VERIFY(mAccount->active());109 TRY_VERIFY(activeChangedSpy.count() > 0);
111 QCOMPARE(activeChangedSpy.count(), 1);110 QVERIFY(mAccount->active());
112111
113 // check that for a null account active is false112 // check that for a null account active is false
114 QVERIFY(!mNullAccount->active());113 QVERIFY(!mNullAccount->active());
@@ -124,14 +123,14 @@
124 // now try to set the display in the telepathy account directly and see that the entry gets updated123 // now try to set the display in the telepathy account directly and see that the entry gets updated
125 QString newDisplayName = "some other display name";124 QString newDisplayName = "some other display name";
126 mTpAccount->setDisplayName(newDisplayName);125 mTpAccount->setDisplayName(newDisplayName);
127 QTRY_COMPARE(mAccount->displayName(), newDisplayName);126 TRY_COMPARE(mAccount->displayName(), newDisplayName);
128 QCOMPARE(displayNameChangedSpy.count(), 1);127 QCOMPARE(displayNameChangedSpy.count(), 1);
129128
130 // and try setting the display name in the entry itself129 // and try setting the display name in the entry itself
131 displayNameChangedSpy.clear();130 displayNameChangedSpy.clear();
132 newDisplayName = "changing again";131 newDisplayName = "changing again";
133 mAccount->setDisplayName(newDisplayName);132 mAccount->setDisplayName(newDisplayName);
134 QTRY_COMPARE(mAccount->displayName(), newDisplayName);133 TRY_COMPARE(mAccount->displayName(), newDisplayName);
135 QCOMPARE(displayNameChangedSpy.count(), 1);134 QCOMPARE(displayNameChangedSpy.count(), 1);
136 QCOMPARE(mTpAccount->displayName(), newDisplayName);135 QCOMPARE(mTpAccount->displayName(), newDisplayName);
137136
@@ -147,11 +146,10 @@
147 QCOMPARE(mAccount->status(), mTpAccount->connection()->selfContact()->presence().status());146 QCOMPARE(mAccount->status(), mTpAccount->connection()->selfContact()->presence().status());
148147
149 // and now set a new value148 // and now set a new value
150 Tp::Presence presence(Tp::ConnectionPresenceTypeAway, "away", "away");149 mMockController->SetPresence("away", "away");
151 mTpAccount->setRequestedPresence(presence);
152150
153 QTRY_COMPARE(mAccount->status(), QString("away"));151 TRY_COMPARE(statusChangedSpy.count(), 1);
154 QTRY_COMPARE(statusChangedSpy.count(), 1);152 QCOMPARE(mAccount->status(), QString("away"));
155153
156 // check that for a null account the status is null154 // check that for a null account the status is null
157 QVERIFY(mNullAccount->status().isNull());155 QVERIFY(mNullAccount->status().isNull());
@@ -162,14 +160,14 @@
162 QSignalSpy statusMessageChangedSpy(mAccount, SIGNAL(statusMessageChanged()));160 QSignalSpy statusMessageChangedSpy(mAccount, SIGNAL(statusMessageChanged()));
163161
164 // check that the value is correct already162 // check that the value is correct already
165 QTRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage());163 TRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage());
166164
167 // and now set a new value165 // and now set a new value
168 QString statusMessage("I am online");166 QString statusMessage("I am online");
169 mMockController->SetPresence("available", statusMessage);167 mMockController->SetPresence("available", statusMessage);
170168
171 QTRY_COMPARE(mAccount->statusMessage(), statusMessage);169 TRY_COMPARE(statusMessageChangedSpy.count(), 1);
172 QTRY_COMPARE(statusMessageChangedSpy.count(), 1);170 QCOMPARE(mAccount->statusMessage(), statusMessage);
173171
174 // check that for a null account the displayName is null172 // check that for a null account the displayName is null
175 QVERIFY(mNullAccount->statusMessage().isNull());173 QVERIFY(mNullAccount->statusMessage().isNull());
@@ -183,18 +181,16 @@
183 QVERIFY(mAccount->connected());181 QVERIFY(mAccount->connected());
184182
185 // now set the account offline and see if the active flag changes correctly183 // now set the account offline and see if the active flag changes correctly
186 mMockController->SetOnline(false);184 mMockController->SetPresence("away", "away");
187 QTRY_VERIFY(!mAccount->connected());185 TRY_VERIFY(connectedChangedSpy.count() > 0);
188 QTRY_COMPARE(connectedChangedSpy.count(), 1);186 TRY_VERIFY(!mAccount->connected());
189
190 // it shouldn't be necessary, but in any case
191 QTest::qWait(500);
192187
193 // now re-enable the account and check that the entry is updated188 // now re-enable the account and check that the entry is updated
194 connectedChangedSpy.clear();189 connectedChangedSpy.clear();
195 mMockController->SetOnline(true);190 mMockController->SetPresence("available", "online");
196 QTRY_VERIFY(mAccount->connected());191 // because of the way the mock was implemented, sometimes this can return two connectedChanged() signals.
197 QTRY_COMPARE(connectedChangedSpy.count(), 1);192 TRY_VERIFY(connectedChangedSpy.count() > 0);
193 TRY_VERIFY(mAccount->connected());
198194
199 // check that for a null account the displayName is null195 // check that for a null account the displayName is null
200 QVERIFY(!mNullAccount->connected());196 QVERIFY(!mNullAccount->connected());
201197
=== modified file 'tests/libtelephonyservice/CMakeLists.txt'
--- tests/libtelephonyservice/CMakeLists.txt 2015-04-22 13:44:53 +0000
+++ tests/libtelephonyservice/CMakeLists.txt 2015-05-11 13:17:00 +0000
@@ -34,6 +34,7 @@
3434
35generate_telepathy_test(AccountEntryFactoryTest SOURCES AccountEntryFactoryTest.cpp)35generate_telepathy_test(AccountEntryFactoryTest SOURCES AccountEntryFactoryTest.cpp)
36generate_telepathy_test(AccountEntryTest SOURCES AccountEntryTest.cpp)36generate_telepathy_test(AccountEntryTest SOURCES AccountEntryTest.cpp)
37generate_telepathy_test(CallEntryTest SOURCES CallEntryTest.cpp)
37generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp)38generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp)
38generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp)39generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp)
39generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp)40generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp)
4041
=== added file 'tests/libtelephonyservice/CallEntryTest.cpp'
--- tests/libtelephonyservice/CallEntryTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/CallEntryTest.cpp 2015-05-11 13:17:00 +0000
@@ -0,0 +1,129 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include "telepathytest.h"
22#include "callentry.h"
23#include "callmanager.h"
24#include "telepathyhelper.h"
25#include "mockcontroller.h"
26#include "ofonoaccountentry.h"
27#include "accountentryfactory.h"
28
29Q_DECLARE_METATYPE(AccountEntry*)
30
31class CallEntryTest : public TelepathyTest
32{
33 Q_OBJECT
34
35private Q_SLOTS:
36 void initTestCase();
37 void init();
38 void cleanup();
39 void testIsVoicemail_data();
40 void testIsVoicemail();
41
42protected Q_SLOTS:
43 void onCallChannelAvailable(const Tp::CallChannelPtr &channel);
44
45private:
46 Tp::AccountPtr mTpAccount;
47 OfonoAccountEntry *mAccount;
48 Tp::CallChannelPtr mCallChannel;
49 MockController *mMockController;
50};
51
52void CallEntryTest::initTestCase()
53{
54 qRegisterMetaType<AccountEntry*>();
55 initialize();
56 TelepathyHelper::instance()->registerChannelObserver();
57 connect(TelepathyHelper::instance()->channelObserver(),
58 SIGNAL(callChannelAvailable(Tp::CallChannelPtr)),
59 SLOT(onCallChannelAvailable(Tp::CallChannelPtr)));
60}
61
62void CallEntryTest::init()
63{
64 QSignalSpy accountSpy(TelepathyHelper::instance(), SIGNAL(accountAdded(AccountEntry*)));
65 mTpAccount = addAccount("mock", "ofono", "the account");
66 QVERIFY(!mTpAccount.isNull());
67 TRY_COMPARE(accountSpy.count(), 1);
68 mAccount = qobject_cast<OfonoAccountEntry*>(accountSpy.first().first().value<AccountEntry*>());
69 QVERIFY(mAccount);
70 TRY_VERIFY(mAccount->ready());
71 TRY_COMPARE(mAccount->status(), QString("available"));
72
73 // and create the mock controller
74 mMockController = new MockController("ofono", this);
75}
76
77void CallEntryTest::cleanup()
78{
79 doCleanup();
80
81 mMockController->deleteLater();
82 mAccount->deleteLater();
83 mCallChannel = Tp::CallChannelPtr();
84
85 // wait until all the calls are gone before the next test
86 TRY_VERIFY(!CallManager::instance()->hasCalls());
87}
88
89void CallEntryTest::testIsVoicemail_data()
90{
91 QTest::addColumn<QString>("voicemailNumber");
92 QTest::addColumn<QString>("callNumber");
93 QTest::addColumn<bool>("isVoicemail");
94
95 QTest::newRow("calling voicemail") << "*1234" << "*1234" << true;
96 QTest::newRow("calling other number") << "*1234" << "5555555" << false;
97}
98
99void CallEntryTest::testIsVoicemail()
100{
101 QFETCH(QString, voicemailNumber);
102 QFETCH(QString, callNumber);
103 QFETCH(bool, isVoicemail);
104
105 mMockController->SetVoicemailNumber(voicemailNumber);
106 TRY_COMPARE(mAccount->voicemailNumber(), voicemailNumber);
107
108 // now place a call to a number that is not the voicemail number
109 QVariantMap properties;
110 properties["Caller"] = callNumber;
111 properties["State"] = "incoming";
112 mMockController->placeCall(properties);
113 TRY_VERIFY(!mCallChannel.isNull());
114 QCOMPARE(mCallChannel->targetContact()->id(), callNumber);
115
116 CallEntry *callEntry = new CallEntry(mCallChannel);
117 QCOMPARE(callEntry->isVoicemail(), isVoicemail);
118
119 callEntry->endCall();
120 callEntry->deleteLater();
121}
122
123void CallEntryTest::onCallChannelAvailable(const Tp::CallChannelPtr &channel)
124{
125 mCallChannel = channel;
126}
127
128QTEST_MAIN(CallEntryTest)
129#include "CallEntryTest.moc"
0130
=== modified file 'tests/libtelephonyservice/ChatManagerTest.cpp'
--- tests/libtelephonyservice/ChatManagerTest.cpp 2015-04-17 21:26:25 +0000
+++ tests/libtelephonyservice/ChatManagerTest.cpp 2015-05-11 13:17:00 +0000
@@ -47,21 +47,16 @@
47void ChatManagerTest::initTestCase()47void ChatManagerTest::initTestCase()
48{48{
49 initialize();49 initialize();
50
51 TelepathyHelper::instance()->registerChannelObserver();50 TelepathyHelper::instance()->registerChannelObserver();
52
53 // just give telepathy some time to register the observer
54 QTest::qWait(1000);
55}51}
5652
57void ChatManagerTest::init()53void ChatManagerTest::init()
58{54{
59 // add two accounts55 // add two accounts
60 mGenericTpAccount = addAccount("mock", "mock", "the generic account");56 mGenericTpAccount = addAccount("mock", "mock", "the generic account");
61 QTRY_VERIFY(!mGenericTpAccount->connection().isNull());57 QVERIFY(!mGenericTpAccount.isNull());
62
63 mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");58 mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");
64 QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());59 QVERIFY(!mPhoneTpAccount.isNull());
6560
66 // and create the mock controller61 // and create the mock controller
67 mGenericMockController = new MockController("mock", this);62 mGenericMockController = new MockController("mock", this);
@@ -103,7 +98,7 @@
10398
104 ChatManager::instance()->sendMessage(recipients, message, accountId);99 ChatManager::instance()->sendMessage(recipients, message, accountId);
105100
106 QTRY_COMPARE(controllerMessageSentSpy.count(), 1);101 TRY_COMPARE(controllerMessageSentSpy.count(), 1);
107 QString messageText = controllerMessageSentSpy.first()[0].toString();102 QString messageText = controllerMessageSentSpy.first()[0].toString();
108 QVariantMap messageProperties = controllerMessageSentSpy.first()[1].toMap();103 QVariantMap messageProperties = controllerMessageSentSpy.first()[1].toMap();
109 QStringList messageRecipients = messageProperties["Recipients"].toStringList();104 QStringList messageRecipients = messageProperties["Recipients"].toStringList();
@@ -111,7 +106,7 @@
111 QCOMPARE(messageText, message);106 QCOMPARE(messageText, message);
112 QCOMPARE(messageRecipients, recipients);107 QCOMPARE(messageRecipients, recipients);
113108
114 QTRY_COMPARE(messageSentSpy.count(), 1);109 TRY_COMPARE(messageSentSpy.count(), 1);
115 messageRecipients = messageSentSpy.first()[0].toStringList();110 messageRecipients = messageSentSpy.first()[0].toStringList();
116 qSort(messageRecipients);111 qSort(messageRecipients);
117 messageText = messageSentSpy.first()[1].toString();112 messageText = messageSentSpy.first()[1].toString();
@@ -129,7 +124,7 @@
129 QString message("Hi there");124 QString message("Hi there");
130 mGenericMockController->PlaceIncomingMessage(message, properties);125 mGenericMockController->PlaceIncomingMessage(message, properties);
131126
132 QTRY_COMPARE(messageReceivedSpy.count(), 1);127 TRY_COMPARE(messageReceivedSpy.count(), 1);
133 QString sender = messageReceivedSpy.first()[0].toString();128 QString sender = messageReceivedSpy.first()[0].toString();
134 QString receivedMessage = messageReceivedSpy.first()[1].toString();129 QString receivedMessage = messageReceivedSpy.first()[1].toString();
135 QCOMPARE(sender, properties["Sender"].toString());130 QCOMPARE(sender, properties["Sender"].toString());
@@ -147,9 +142,10 @@
147 messages << "Hi there" << "How are you" << "Always look on the bright side of life";142 messages << "Hi there" << "How are you" << "Always look on the bright side of life";
148 Q_FOREACH(const QString &message, messages) {143 Q_FOREACH(const QString &message, messages) {
149 mGenericMockController->PlaceIncomingMessage(message, properties);144 mGenericMockController->PlaceIncomingMessage(message, properties);
150 QTest::qWait(100);145 // the wait shouldn't be needed, but just in case
146 QTest::qWait(50);
151 }147 }
152 QTRY_COMPARE(messageReceivedSpy.count(), messages.count());148 TRY_COMPARE(messageReceivedSpy.count(), messages.count());
153149
154 QStringList messageIds;150 QStringList messageIds;
155 for (int i = 0; i < messages.count(); ++i) {151 for (int i = 0; i < messages.count(); ++i) {
@@ -162,7 +158,7 @@
162 ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0");158 ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0");
163 }159 }
164160
165 QTRY_COMPARE(messageReadSpy.count(), messageIds.count());161 TRY_COMPARE(messageReadSpy.count(), messageIds.count());
166 QStringList receivedIds;162 QStringList receivedIds;
167 for (int i = 0; i < messageReadSpy.count(); ++i) {163 for (int i = 0; i < messageReadSpy.count(); ++i) {
168 receivedIds << messageReadSpy[i][0].toString();164 receivedIds << messageReadSpy[i][0].toString();
169165
=== modified file 'tests/libtelephonyservice/OfonoAccountEntryTest.cpp'
--- tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-04-22 14:26:41 +0000
+++ tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-05-11 13:17:00 +0000
@@ -61,21 +61,18 @@
61{61{
62 mTpAccount = addAccount("mock", "ofono", "phone account");62 mTpAccount = addAccount("mock", "ofono", "phone account");
63 QVERIFY(!mTpAccount.isNull());63 QVERIFY(!mTpAccount.isNull());
64 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
65
66 mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this));64 mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this));
67 QVERIFY(mAccount);65 QVERIFY(mAccount);
66 TRY_VERIFY(mAccount->ready());
6867
69 // make sure the connection is available68 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());69 TRY_VERIFY(mAccount->connected());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);70
72 QTRY_VERIFY(mAccount->connected());71 // and make sure the status and status message are the ones we expect
72 TRY_COMPARE(mAccount->status(), QString("available"));
7373
74 // create the mock controller74 // create the mock controller
75 mMockController = new MockController("ofono", this);75 mMockController = new MockController("ofono", this);
76
77 // just in case, wait some time
78 QTest::qWait(1000);
79}76}
8077
81void OfonoAccountEntryTest::cleanup()78void OfonoAccountEntryTest::cleanup()
@@ -93,22 +90,23 @@
93void OfonoAccountEntryTest::testConnected()90void OfonoAccountEntryTest::testConnected()
94{91{
95 // the mock account is enabled/connected by default, so make sure it is like that92 // the mock account is enabled/connected by default, so make sure it is like that
96 QTRY_VERIFY(mAccount->connected());93 TRY_VERIFY(mAccount->connected());
9794
98 // right now the ofono account connection status behave exactly like the generic class,95 // right now the ofono account connection status behave exactly like the generic class,
99 // but as the code path is different, test it again96 // but as the code path is different, test it again
100 QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));97 QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));
10198
102 // now set the account offline and see if the active flag changes correctly99 // now set the account offline and see if the active flag changes correctly
103 mMockController->SetOnline(false);100 mMockController->SetPresence("away", "away");
104 QTRY_VERIFY(!mAccount->connected());101 TRY_VERIFY(connectedChangedSpy.count() > 0);
105 QTRY_COMPARE(connectedChangedSpy.count(), 1);102 TRY_VERIFY(!mAccount->connected());
106103
107 // now re-enable the account and check that the entry is updated104 // now re-enable the account and check that the entry is updated
108 connectedChangedSpy.clear();105 connectedChangedSpy.clear();
109 mMockController->SetOnline(true);106 mMockController->SetPresence("available", "online");
110 QTRY_VERIFY(mAccount->connected());107 // because of the way the mock was implemented, sometimes this can return two connectedChanged() signals.
111 QTRY_COMPARE(connectedChangedSpy.count(), 1);108 TRY_VERIFY(connectedChangedSpy.count() > 0);
109 TRY_VERIFY(mAccount->connected());
112}110}
113111
114void OfonoAccountEntryTest::testCompareIds_data()112void OfonoAccountEntryTest::testCompareIds_data()
@@ -142,7 +140,7 @@
142 numbers << "111" << "190" << "911";140 numbers << "111" << "190" << "911";
143 qSort(numbers);141 qSort(numbers);
144 mMockController->SetEmergencyNumbers(numbers);142 mMockController->SetEmergencyNumbers(numbers);
145 QTRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);143 TRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);
146144
147 QStringList emergencyNumbers = mAccount->emergencyNumbers();145 QStringList emergencyNumbers = mAccount->emergencyNumbers();
148 qSort(emergencyNumbers);146 qSort(emergencyNumbers);
@@ -152,7 +150,7 @@
152150
153void OfonoAccountEntryTest::testSerial()151void OfonoAccountEntryTest::testSerial()
154{152{
155 QTRY_COMPARE(mAccount->serial(), mMockController->serial());153 TRY_COMPARE(mAccount->serial(), mMockController->serial());
156}154}
157155
158void OfonoAccountEntryTest::testVoicemailIndicator()156void OfonoAccountEntryTest::testVoicemailIndicator()
@@ -164,27 +162,27 @@
164162
165 // set to true163 // set to true
166 mMockController->SetVoicemailIndicator(true);164 mMockController->SetVoicemailIndicator(true);
167 QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);165 TRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
168 QTRY_VERIFY(mAccount->voicemailIndicator());166 QVERIFY(mAccount->voicemailIndicator());
169167
170 // and set back to false168 // and set back to false
171 voiceMailIndicatorSpy.clear();169 voiceMailIndicatorSpy.clear();
172 mMockController->SetVoicemailIndicator(false);170 mMockController->SetVoicemailIndicator(false);
173 QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);171 TRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
174 QTRY_VERIFY(!mAccount->voicemailIndicator());172 QVERIFY(!mAccount->voicemailIndicator());
175}173}
176174
177void OfonoAccountEntryTest::testVoicemailNumber()175void OfonoAccountEntryTest::testVoicemailNumber()
178{176{
177 // check that the number is not empty at startup
178 TRY_VERIFY(!mAccount->voicemailNumber().isEmpty());
179
179 QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged()));180 QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged()));
180181
181 // check that the number is not empty at startup
182 QTRY_VERIFY(!mAccount->voicemailNumber().isEmpty());
183
184 // try changing the number182 // try changing the number
185 QString number("12345");183 QString number("12345");
186 mMockController->SetVoicemailNumber(number);184 mMockController->SetVoicemailNumber(number);
187 QTRY_COMPARE(voicemailNumberSpy.count(), 1);185 TRY_COMPARE(voicemailNumberSpy.count(), 1);
188 QCOMPARE(mAccount->voicemailNumber(), number);186 QCOMPARE(mAccount->voicemailNumber(), number);
189}187}
190188
@@ -198,13 +196,13 @@
198 // set it to a bigger value196 // set it to a bigger value
199 int count = 10;197 int count = 10;
200 mMockController->SetVoicemailCount(count);198 mMockController->SetVoicemailCount(count);
201 QTRY_COMPARE(voicemailCountSpy.count(), 1);199 TRY_COMPARE(voicemailCountSpy.count(), 1);
202 QCOMPARE((int)mAccount->voicemailCount(), count);200 QCOMPARE((int)mAccount->voicemailCount(), count);
203201
204 // and back to zero202 // and back to zero
205 voicemailCountSpy.clear();203 voicemailCountSpy.clear();
206 mMockController->SetVoicemailCount(0);204 mMockController->SetVoicemailCount(0);
207 QTRY_COMPARE(voicemailCountSpy.count(), 1);205 TRY_COMPARE(voicemailCountSpy.count(), 1);
208 QCOMPARE((int)mAccount->voicemailCount(), 0);206 QCOMPARE((int)mAccount->voicemailCount(), 0);
209}207}
210208
@@ -217,7 +215,7 @@
217215
218 // now try to set the status to simlocked216 // now try to set the status to simlocked
219 mMockController->SetPresence("simlocked", "simlocked");217 mMockController->SetPresence("simlocked", "simlocked");
220 QTRY_COMPARE(simLockedSpy.count(), 1);218 TRY_COMPARE(simLockedSpy.count(), 1);
221 QVERIFY(mAccount->simLocked());219 QVERIFY(mAccount->simLocked());
222}220}
223221
@@ -246,7 +244,7 @@
246 QFETCH(bool, available);244 QFETCH(bool, available);
247245
248 mMockController->SetPresence(status, "");246 mMockController->SetPresence(status, "");
249 QTRY_COMPARE(mAccount->status(), status);247 TRY_COMPARE(mAccount->status(), status);
250 QCOMPARE(mAccount->emergencyCallsAvailable(), available);248 QCOMPARE(mAccount->emergencyCallsAvailable(), available);
251}249}
252250
@@ -258,8 +256,8 @@
258 QString statusMessage("SomeNetwork");256 QString statusMessage("SomeNetwork");
259 mMockController->SetPresence("available", statusMessage);257 mMockController->SetPresence("available", statusMessage);
260258
261 QTRY_COMPARE(mAccount->networkName(), statusMessage);259 TRY_COMPARE(networkNameChangedSpy.count(), 1);
262 QTRY_COMPARE(networkNameChangedSpy.count(), 1);260 QCOMPARE(mAccount->networkName(), statusMessage);
263}261}
264262
265void OfonoAccountEntryTest::testAddressableVCardFields()263void OfonoAccountEntryTest::testAddressableVCardFields()
266264
=== modified file 'tests/libtelephonyservice/TelepathyHelperTest.cpp'
--- tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-04-21 16:47:31 +0000
+++ tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-05-11 13:17:00 +0000
@@ -27,6 +27,8 @@
27#include "telepathyhelper.h"27#include "telepathyhelper.h"
28#include "mockcontroller.h"28#include "mockcontroller.h"
2929
30Q_DECLARE_METATYPE(AccountEntry*)
31
30class TelepathyHelperTest : public TelepathyTest32class TelepathyHelperTest : public TelepathyTest
31{33{
32 Q_OBJECT34 Q_OBJECT
@@ -45,6 +47,11 @@
45 void testAccountForConnection();47 void testAccountForConnection();
46 void testEmergencyCallsAvailable();48 void testEmergencyCallsAvailable();
4749
50protected:
51 Tp::AccountPtr addAccountAndWait(const QString &manager,
52 const QString &protocol,
53 const QString &displayName,
54 const QVariantMap &parameters = QVariantMap());
48private:55private:
49 Tp::AccountPtr mGenericTpAccount;56 Tp::AccountPtr mGenericTpAccount;
50 Tp::AccountPtr mPhoneTpAccount;57 Tp::AccountPtr mPhoneTpAccount;
@@ -54,24 +61,24 @@
5461
55void TelepathyHelperTest::initTestCase()62void TelepathyHelperTest::initTestCase()
56{63{
64 qRegisterMetaType<AccountEntry*>();
57 initialize();65 initialize();
66 QSignalSpy setupReadySpy(TelepathyHelper::instance(), SIGNAL(setupReady()));
67 TRY_COMPARE(setupReadySpy.count(), 1);
58}68}
5969
60void TelepathyHelperTest::init()70void TelepathyHelperTest::init()
61{71{
62 // add two accounts72 // add two accounts
63 mGenericTpAccount = addAccount("mock", "mock", "the generic account");73 mGenericTpAccount = addAccountAndWait("mock", "mock", "the generic account");
64 QTRY_VERIFY(!mGenericTpAccount->connection().isNull());74 QVERIFY(!mGenericTpAccount.isNull());
6575
66 mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");76 mPhoneTpAccount = addAccountAndWait("mock", "ofono", "the phone account");
67 QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());77 QVERIFY(!mPhoneTpAccount.isNull());
6878
69 // and create the mock controller79 // and create the mock controller
70 mGenericController = new MockController("mock", this);80 mGenericController = new MockController("mock", this);
71 mPhoneController = new MockController("ofono", this);81 mPhoneController = new MockController("ofono", this);
72
73 // just in case, wait some time
74 QTest::qWait(1000);
75}82}
7683
77void TelepathyHelperTest::cleanup()84void TelepathyHelperTest::cleanup()
@@ -98,13 +105,13 @@
98105
99 // and set the other account as offline too. This time connected needs to change to false106 // and set the other account as offline too. This time connected needs to change to false
100 mPhoneController->SetOnline(false);107 mPhoneController->SetOnline(false);
101 QTRY_COMPARE(connectedChangedSpy.count(), 1);108 TRY_COMPARE(connectedChangedSpy.count(), 1);
102 QVERIFY(!TelepathyHelper::instance()->connected());109 QVERIFY(!TelepathyHelper::instance()->connected());
103110
104 // now set one of the accounts back online111 // now set one of the accounts back online
105 connectedChangedSpy.clear();112 connectedChangedSpy.clear();
106 mPhoneController->SetOnline(true);113 mPhoneController->SetOnline(true);
107 QTRY_COMPARE(connectedChangedSpy.count(), 1);114 TRY_COMPARE(connectedChangedSpy.count(), 1);
108 QVERIFY(TelepathyHelper::instance()->connected());115 QVERIFY(TelepathyHelper::instance()->connected());
109116
110 // and the other one just in case117 // and the other one just in case
@@ -124,10 +131,10 @@
124131
125 // now check that new accounts are captured132 // now check that new accounts are captured
126 QSignalSpy accountsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountsChanged()));133 QSignalSpy accountsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountsChanged()));
127 Tp::AccountPtr newAccount = addAccount("mock", "mock", "extra");134 Tp::AccountPtr newAccount = addAccountAndWait("mock", "mock", "extra");
128 QVERIFY(!newAccount.isNull());135 QVERIFY(!newAccount.isNull());
129136
130 QTRY_COMPARE(accountsChangedSpy.count(), 1);137 TRY_COMPARE(accountsChangedSpy.count(), 1);
131 QCOMPARE(TelepathyHelper::instance()->accounts().count(), 3);138 QCOMPARE(TelepathyHelper::instance()->accounts().count(), 3);
132139
133 bool accountFound = false;140 bool accountFound = false;
@@ -142,7 +149,7 @@
142 // now remove the extra account and make sure it is properly removed149 // now remove the extra account and make sure it is properly removed
143 accountsChangedSpy.clear();150 accountsChangedSpy.clear();
144 QVERIFY(removeAccount(newAccount));151 QVERIFY(removeAccount(newAccount));
145 QTRY_COMPARE(accountsChangedSpy.count(), 1);152 TRY_COMPARE(accountsChangedSpy.count(), 1);
146 QCOMPARE(TelepathyHelper::instance()->accounts().count(), 2);153 QCOMPARE(TelepathyHelper::instance()->accounts().count(), 2);
147 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), first->accountId());154 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), first->accountId());
148 QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());155 QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());
@@ -184,15 +191,15 @@
184 // create two accounts with modem-objpath parameters and make sure they are listed first191 // create two accounts with modem-objpath parameters and make sure they are listed first
185 QVariantMap parameters;192 QVariantMap parameters;
186 parameters["modem-objpath"] = "/phonesim1";193 parameters["modem-objpath"] = "/phonesim1";
187 Tp::AccountPtr firstAccount = addAccount("mock", "ofono", "firstPhoneAccount", parameters);194 Tp::AccountPtr firstAccount = addAccountAndWait("mock", "ofono", "firstPhoneAccount", parameters);
188 QVERIFY(!firstAccount.isNull());195 QVERIFY(!firstAccount.isNull());
189196
190 parameters["modem-objpath"] = "/phonesim2";197 parameters["modem-objpath"] = "/phonesim2";
191 Tp::AccountPtr secondAccount = addAccount("mock", "ofono", "secondPhoneAccount", parameters);198 Tp::AccountPtr secondAccount = addAccountAndWait("mock", "ofono", "secondPhoneAccount", parameters);
192 QVERIFY(!secondAccount.isNull());199 QVERIFY(!secondAccount.isNull());
193200
194 // wait for the accounts to appear;201 // wait for the accounts to appear;
195 QTRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 4);202 TRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 4);
196203
197 // and check the order204 // and check the order
198 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), firstAccount->uniqueIdentifier());205 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), firstAccount->uniqueIdentifier());
@@ -200,11 +207,11 @@
200207
201 // now add a third account that should go before the two others208 // now add a third account that should go before the two others
202 parameters["modem-objpath"] = "/phonesim0";209 parameters["modem-objpath"] = "/phonesim0";
203 Tp::AccountPtr thirdAccount = addAccount("mock", "ofono", "thirdPhoneAccount", parameters);210 Tp::AccountPtr thirdAccount = addAccountAndWait("mock", "ofono", "thirdPhoneAccount", parameters);
204 QVERIFY(!thirdAccount.isNull());211 QVERIFY(!thirdAccount.isNull());
205212
206 // wait for the accounts to appear;213 // wait for the accounts to appear;
207 QTRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 5);214 TRY_COMPARE(TelepathyHelper::instance()->accounts().count(), 5);
208 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), thirdAccount->uniqueIdentifier());215 QCOMPARE(TelepathyHelper::instance()->accounts()[0]->accountId(), thirdAccount->uniqueIdentifier());
209216
210 // and remove the created accounts217 // and remove the created accounts
@@ -219,10 +226,10 @@
219226
220 // now check that new accounts are captured227 // now check that new accounts are captured
221 QSignalSpy accountIdsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountIdsChanged()));228 QSignalSpy accountIdsChangedSpy(TelepathyHelper::instance(), SIGNAL(accountIdsChanged()));
222 Tp::AccountPtr newAccount = addAccount("mock", "mock", "extra");229 Tp::AccountPtr newAccount = addAccountAndWait("mock", "mock", "extra");
223 QVERIFY(!newAccount.isNull());230 QVERIFY(!newAccount.isNull());
224231
225 QTRY_COMPARE(accountIdsChangedSpy.count(), 1);232 TRY_COMPARE(accountIdsChangedSpy.count(), 1);
226 QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 3);233 QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 3);
227234
228 // just to make sure check that each account id matches one account235 // just to make sure check that each account id matches one account
@@ -233,7 +240,7 @@
233 // now remove the extra account and make sure it is properly removed240 // now remove the extra account and make sure it is properly removed
234 accountIdsChangedSpy.clear();241 accountIdsChangedSpy.clear();
235 QVERIFY(removeAccount(newAccount));242 QVERIFY(removeAccount(newAccount));
236 QTRY_COMPARE(accountIdsChangedSpy.count(), 1);243 TRY_COMPARE(accountIdsChangedSpy.count(), 1);
237 QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 2);244 QCOMPARE(TelepathyHelper::instance()->accountIds().count(), 2);
238 QCOMPARE(TelepathyHelper::instance()->accountIds()[0], TelepathyHelper::instance()->accounts()[0]->accountId());245 QCOMPARE(TelepathyHelper::instance()->accountIds()[0], TelepathyHelper::instance()->accounts()[0]->accountId());
239 QCOMPARE(TelepathyHelper::instance()->accountIds()[1], TelepathyHelper::instance()->accounts()[1]->accountId());246 QCOMPARE(TelepathyHelper::instance()->accountIds()[1], TelepathyHelper::instance()->accounts()[1]->accountId());
@@ -248,22 +255,22 @@
248255
249 // now set one of the accounts as offline and make sure it is captured256 // now set one of the accounts as offline and make sure it is captured
250 mGenericController->SetOnline(false);257 mGenericController->SetOnline(false);
251 QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);258 TRY_COMPARE(activeAccountsSpy.count(), 1);
252 QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 1);259 QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 1);
253 QCOMPARE(TelepathyHelper::instance()->activeAccounts()[0]->accountId(), mPhoneTpAccount->uniqueIdentifier());260 QCOMPARE(TelepathyHelper::instance()->activeAccounts()[0]->accountId(), mPhoneTpAccount->uniqueIdentifier());
254261
255 // set the other account offline to make sure262 // set the other account offline to make sure
256 activeAccountsSpy.clear();263 activeAccountsSpy.clear();
257 mPhoneController->SetOnline(false);264 mPhoneController->SetOnline(false);
258 QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 1, DEFAULT_TIMEOUT);265 TRY_COMPARE(activeAccountsSpy.count(), 1);
259 QVERIFY(TelepathyHelper::instance()->activeAccounts().isEmpty());266 QVERIFY(TelepathyHelper::instance()->activeAccounts().isEmpty());
260267
261 // and set both accounts online again268 // and set both accounts online again
262 activeAccountsSpy.clear();269 activeAccountsSpy.clear();
263 mGenericController->SetOnline(true);270 mGenericController->SetOnline(true);
264 mPhoneController->SetOnline(true);271 mPhoneController->SetOnline(true);
265 QTRY_COMPARE_WITH_TIMEOUT(activeAccountsSpy.count(), 2, DEFAULT_TIMEOUT);272 TRY_COMPARE(activeAccountsSpy.count(), 2);
266 QTRY_COMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);273 QCOMPARE(TelepathyHelper::instance()->activeAccounts().count(), 2);
267}274}
268275
269void TelepathyHelperTest::testAccountForId()276void TelepathyHelperTest::testAccountForId()
@@ -291,7 +298,7 @@
291 QSignalSpy emergencyCallsSpy(TelepathyHelper::instance(), SIGNAL(emergencyCallsAvailableChanged()));298 QSignalSpy emergencyCallsSpy(TelepathyHelper::instance(), SIGNAL(emergencyCallsAvailableChanged()));
292299
293 // check that calls are available by default300 // check that calls are available by default
294 QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());301 TRY_VERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
295302
296 // set the generic account as "flightmode" and make sure it doesn't affect the emergencyCallsAvailable303 // set the generic account as "flightmode" and make sure it doesn't affect the emergencyCallsAvailable
297 mGenericController->SetPresence("flightmode", "");304 mGenericController->SetPresence("flightmode", "");
@@ -301,7 +308,7 @@
301308
302 // now set the phone account as "flightmode", and see if the emergencyCallsAvailable value309 // now set the phone account as "flightmode", and see if the emergencyCallsAvailable value
303 mPhoneController->SetPresence("flightmode", "");310 mPhoneController->SetPresence("flightmode", "");
304 QTRY_COMPARE(emergencyCallsSpy.count(), 1);311 TRY_VERIFY(emergencyCallsSpy.count() > 0);
305 QVERIFY(!TelepathyHelper::instance()->emergencyCallsAvailable());312 QVERIFY(!TelepathyHelper::instance()->emergencyCallsAvailable());
306313
307 // set the generic account online and check if it affects the value314 // set the generic account online and check if it affects the value
@@ -313,9 +320,25 @@
313320
314 // and finally set the phone account back online321 // and finally set the phone account back online
315 mPhoneController->SetOnline(true);322 mPhoneController->SetOnline(true);
316 QTRY_COMPARE(emergencyCallsSpy.count(), 1);323 TRY_VERIFY(emergencyCallsSpy.count() > 0);
317 QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());324 QVERIFY(TelepathyHelper::instance()->emergencyCallsAvailable());
318}325}
319326
327Tp::AccountPtr TelepathyHelperTest::addAccountAndWait(const QString &manager, const QString &protocol, const QString &displayName, const QVariantMap &parameters)
328{
329 QSignalSpy accountAddedSpy(TelepathyHelper::instance(), SIGNAL(accountAdded(AccountEntry*)));
330 Tp::AccountPtr account = addAccount(manager, protocol, displayName, parameters);
331
332 WAIT_FOR(accountAddedSpy.count() == 1);
333
334 AccountEntry *accountEntry = accountAddedSpy.first().first().value<AccountEntry*>();
335 WAIT_FOR(accountEntry->ready());
336
337 // and make sure the status and status message are the ones we expect
338 WAIT_FOR(accountEntry->status() == QString("available"));
339
340 return account;
341}
342
320QTEST_MAIN(TelepathyHelperTest)343QTEST_MAIN(TelepathyHelperTest)
321#include "TelepathyHelperTest.moc"344#include "TelepathyHelperTest.moc"

Subscribers

People subscribed via source and target branches