~tiagosh/telepathy-qt/group-chat2

« back to all changes in this revision

Viewing changes to tests/dbus/account-basics.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2013-06-06 04:56:14 UTC
  • Revision ID: package-import@ubuntu.com-20130606045614-inpxexo6765rnmp1
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <tests/lib/test.h>
 
2
 
 
3
#include <tests/lib/glib-helpers/test-conn-helper.h>
 
4
 
 
5
#include <tests/lib/glib/echo2/conn.h>
 
6
 
 
7
#include <TelepathyQt/Account>
 
8
#include <TelepathyQt/AccountManager>
 
9
#include <TelepathyQt/AccountSet>
 
10
#include <TelepathyQt/ConnectionCapabilities>
 
11
#include <TelepathyQt/PendingAccount>
 
12
#include <TelepathyQt/PendingOperation>
 
13
#include <TelepathyQt/PendingReady>
 
14
#include <TelepathyQt/PendingStringList>
 
15
#include <TelepathyQt/PendingVoid>
 
16
#include <TelepathyQt/Profile>
 
17
 
 
18
#include <telepathy-glib/debug.h>
 
19
 
 
20
using namespace Tp;
 
21
 
 
22
class TestAccountBasics : public Test
 
23
{
 
24
    Q_OBJECT
 
25
 
 
26
public:
 
27
    TestAccountBasics(QObject *parent = 0)
 
28
        : Test(parent),
 
29
          mConn(0),
 
30
          mAccountsCount(0)
 
31
    { }
 
32
 
 
33
protected Q_SLOTS:
 
34
    void onNewAccount(const Tp::AccountPtr &);
 
35
    void onAccountServiceNameChanged(const QString &);
 
36
    void onAccountDisplayNameChanged(const QString &);
 
37
    void onAccountIconNameChanged(const QString &);
 
38
    void onAccountNicknameChanged(const QString &);
 
39
    void onAccountAvatarChanged(const Tp::Avatar &);
 
40
    void onAccountParametersChanged(const QVariantMap &);
 
41
    void onAccountCapabilitiesChanged(const Tp::ConnectionCapabilities &);
 
42
    void onAccountConnectsAutomaticallyChanged(bool);
 
43
    void onAccountAutomaticPresenceChanged(const Tp::Presence &);
 
44
    void onAccountRequestedPresenceChanged(const Tp::Presence &);
 
45
    void onAccountCurrentPresenceChanged(const Tp::Presence &);
 
46
 
 
47
private Q_SLOTS:
 
48
    void initTestCase();
 
49
    void init();
 
50
 
 
51
    void testBasics();
 
52
 
 
53
    void cleanup();
 
54
    void cleanupTestCase();
 
55
 
 
56
private:
 
57
    QStringList pathsForAccounts(const QList<AccountPtr> &list);
 
58
    QStringList pathsForAccounts(const AccountSetPtr &set);
 
59
 
 
60
    Tp::AccountManagerPtr mAM;
 
61
    TestConnHelper *mConn;
 
62
    int mAccountsCount;
 
63
    bool mCreatingAccount;
 
64
 
 
65
    QHash<QString, QVariant> mProps;
 
66
};
 
67
 
 
68
#define TEST_VERIFY_PROPERTY_CHANGE(acc, Type, PropertyName, propertyName, expectedValue) \
 
69
    TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, Type, PropertyName, propertyName, \
 
70
            propertyName ## Changed, acc->set ## PropertyName(expectedValue), expectedValue)
 
71
 
 
72
#define TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, Type, PropertyName, propertyName, signalName, po, expectedValue) \
 
73
    { \
 
74
        mProps.clear(); \
 
75
        qDebug().nospace() << "connecting to " << #propertyName << "Changed()"; \
 
76
        QVERIFY(connect(acc.data(), \
 
77
                    SIGNAL(signalName(Type)), \
 
78
                    SLOT(onAccount ## PropertyName ## Changed(Type)))); \
 
79
        qDebug().nospace() << "setting " << #propertyName; \
 
80
        QVERIFY(connect(po, \
 
81
                    SIGNAL(finished(Tp::PendingOperation*)), \
 
82
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); \
 
83
        QCOMPARE(mLoop->exec(), 0); \
 
84
        \
 
85
        if (!mProps.contains(QLatin1String(#PropertyName))) { \
 
86
            qDebug().nospace() << "waiting for the " << #propertyName << "Changed signal"; \
 
87
            QCOMPARE(mLoop->exec(), 0); \
 
88
        } else { \
 
89
            qDebug().nospace() << "not waiting for " << #propertyName << "Changed because we already got it"; \
 
90
        } \
 
91
        \
 
92
        QCOMPARE(acc->propertyName(), expectedValue); \
 
93
        QCOMPARE(acc->propertyName(), \
 
94
                 mProps[QLatin1String(#PropertyName)].value< Type >()); \
 
95
        \
 
96
        QVERIFY(disconnect(acc.data(), \
 
97
                    SIGNAL(signalName(Type)), \
 
98
                    this, \
 
99
                    SLOT(onAccount ## PropertyName ## Changed(Type)))); \
 
100
        processDBusQueue(acc.data()); \
 
101
    }
 
102
 
 
103
#define TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(Type, PropertyName) \
 
104
void TestAccountBasics::onAccount ## PropertyName ## Changed(Type value) \
 
105
{ \
 
106
    mProps[QLatin1String(#PropertyName)] = qVariantFromValue(value); \
 
107
    mLoop->exit(0); \
 
108
}
 
109
 
 
110
void TestAccountBasics::onNewAccount(const Tp::AccountPtr &acc)
 
111
{
 
112
    Q_UNUSED(acc);
 
113
 
 
114
    mAccountsCount++;
 
115
    if (!mCreatingAccount) {
 
116
        mLoop->exit(0);
 
117
    }
 
118
}
 
119
 
 
120
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const QString &, ServiceName)
 
121
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const QString &, DisplayName)
 
122
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const QString &, IconName)
 
123
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const QString &, Nickname)
 
124
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const Avatar &, Avatar)
 
125
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const QVariantMap &, Parameters)
 
126
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const ConnectionCapabilities &, Capabilities)
 
127
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(bool, ConnectsAutomatically)
 
128
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const Presence &, AutomaticPresence)
 
129
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const Presence &, RequestedPresence)
 
130
TEST_IMPLEMENT_PROPERTY_CHANGE_SLOT(const Presence &, CurrentPresence)
 
131
 
 
132
QStringList TestAccountBasics::pathsForAccounts(const QList<AccountPtr> &list)
 
133
{
 
134
    QStringList ret;
 
135
    Q_FOREACH (const AccountPtr &account, list) {
 
136
        ret << account->objectPath();
 
137
    }
 
138
    return ret;
 
139
}
 
140
 
 
141
QStringList TestAccountBasics::pathsForAccounts(const AccountSetPtr &set)
 
142
{
 
143
    QStringList ret;
 
144
    Q_FOREACH (const AccountPtr &account, set->accounts()) {
 
145
        ret << account->objectPath();
 
146
    }
 
147
    return ret;
 
148
}
 
149
 
 
150
void TestAccountBasics::initTestCase()
 
151
{
 
152
    initTestCaseImpl();
 
153
 
 
154
    g_type_init();
 
155
    g_set_prgname("account-basics");
 
156
    tp_debug_set_flags("all");
 
157
    dbus_g_bus_get(DBUS_BUS_STARTER, 0);
 
158
 
 
159
    mAM = AccountManager::create(AccountFactory::create(QDBusConnection::sessionBus(),
 
160
                Account::FeatureCore | Account::FeatureCapabilities));
 
161
    QVERIFY(!mAM->isReady());
 
162
 
 
163
    mConn = new TestConnHelper(this,
 
164
            EXAMPLE_TYPE_ECHO_2_CONNECTION,
 
165
            "account", "me@example.com",
 
166
            "protocol", "echo2",
 
167
            NULL);
 
168
    QVERIFY(mConn->connect());
 
169
}
 
170
 
 
171
void TestAccountBasics::init()
 
172
{
 
173
    mProps.clear();
 
174
    mCreatingAccount = false;
 
175
 
 
176
    initImpl();
 
177
}
 
178
 
 
179
void TestAccountBasics::testBasics()
 
180
{
 
181
    QVERIFY(connect(mAM->becomeReady(),
 
182
                    SIGNAL(finished(Tp::PendingOperation *)),
 
183
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
184
    QCOMPARE(mLoop->exec(), 0);
 
185
    QVERIFY(mAM->isReady());
 
186
    QCOMPARE(mAM->interfaces(), QStringList());
 
187
    QCOMPARE(mAM->supportedAccountProperties(), QStringList() <<
 
188
            QLatin1String("org.freedesktop.Telepathy.Account.Enabled"));
 
189
 
 
190
    QVERIFY(connect(mAM.data(),
 
191
                    SIGNAL(newAccount(const Tp::AccountPtr &)),
 
192
                    SLOT(onNewAccount(const Tp::AccountPtr &))));
 
193
 
 
194
    QVariantMap parameters;
 
195
    parameters[QLatin1String("account")] = QLatin1String("foobar");
 
196
    PendingAccount *pacc = mAM->createAccount(QLatin1String("foo"),
 
197
            QLatin1String("bar"), QLatin1String("foobar"), parameters);
 
198
    QVERIFY(connect(pacc,
 
199
                    SIGNAL(finished(Tp::PendingOperation *)),
 
200
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
201
    mCreatingAccount = true;
 
202
    QCOMPARE(mLoop->exec(), 0);
 
203
    mCreatingAccount = false;
 
204
    QVERIFY(pacc->account());
 
205
 
 
206
    while (mAccountsCount != 1) {
 
207
        QCOMPARE(mLoop->exec(), 0);
 
208
    }
 
209
    processDBusQueue(mConn->client().data());
 
210
 
 
211
    QStringList paths;
 
212
    QString accPath(QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
 
213
    QCOMPARE(pathsForAccounts(mAM->allAccounts()), QStringList() << accPath);
 
214
    QList<AccountPtr> accs = mAM->accountsForObjectPaths(
 
215
            QStringList() << accPath << QLatin1String("/invalid/path"));
 
216
    QCOMPARE(accs.size(), 2);
 
217
    QCOMPARE(accs[0]->objectPath(), accPath);
 
218
    QVERIFY(!accs[1]);
 
219
 
 
220
    QVERIFY(mAM->allAccounts()[0]->isReady(
 
221
                Account::FeatureCore | Account::FeatureCapabilities));
 
222
 
 
223
    AccountPtr acc = Account::create(mAM->dbusConnection(), mAM->busName(),
 
224
            QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"),
 
225
            mAM->connectionFactory(), mAM->channelFactory(), mAM->contactFactory());
 
226
    QVERIFY(connect(acc->becomeReady(),
 
227
                    SIGNAL(finished(Tp::PendingOperation *)),
 
228
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
229
    QCOMPARE(mLoop->exec(), 0);
 
230
    QVERIFY(acc->isReady());
 
231
 
 
232
    QCOMPARE(acc->connectionFactory(), mAM->connectionFactory());
 
233
    QCOMPARE(acc->channelFactory(), mAM->channelFactory());
 
234
    QCOMPARE(acc->contactFactory(), mAM->contactFactory());
 
235
    QVERIFY(acc->isValidAccount());
 
236
    QVERIFY(acc->isEnabled());
 
237
    QCOMPARE(acc->cmName(), QLatin1String("foo"));
 
238
    QCOMPARE(acc->protocolName(), QLatin1String("bar"));
 
239
    // Service name is empty, fallback to protocol name
 
240
    QCOMPARE(acc->serviceName(), QLatin1String("bar"));
 
241
    // FeatureProfile not ready yet
 
242
    QVERIFY(!acc->profile());
 
243
    QCOMPARE(acc->displayName(), QString(QLatin1String("foobar (account 0)")));
 
244
    QCOMPARE(acc->iconName(), QLatin1String("bob.png"));
 
245
    QCOMPARE(acc->nickname(), QLatin1String("Bob"));
 
246
    // FeatureProtocolInfo not ready yet
 
247
    QVERIFY(!acc->avatarRequirements().isValid());
 
248
    // FeatureAvatar not ready yet
 
249
    QVERIFY(acc->avatar().avatarData.isEmpty());
 
250
    QVERIFY(acc->avatar().MIMEType.isEmpty());
 
251
    QCOMPARE(acc->parameters().size(), 1);
 
252
    QVERIFY(acc->parameters().contains(QLatin1String("account")));
 
253
    QCOMPARE(qdbus_cast<QString>(acc->parameters().value(QLatin1String("account"))),
 
254
            QLatin1String("foobar"));
 
255
    // FeatureProtocolInfo not ready yet
 
256
    QVERIFY(!acc->protocolInfo().isValid());
 
257
    // FeatureCapabilities not ready yet
 
258
    ConnectionCapabilities caps = acc->capabilities();
 
259
    QVERIFY(!caps.isSpecificToContact());
 
260
    QVERIFY(!caps.textChats());
 
261
    QVERIFY(!caps.streamedMediaCalls());
 
262
    QVERIFY(!caps.streamedMediaAudioCalls());
 
263
    QVERIFY(!caps.streamedMediaVideoCalls());
 
264
    QVERIFY(!caps.streamedMediaVideoCallsWithAudio());
 
265
    QVERIFY(!caps.upgradingStreamedMediaCalls());
 
266
    QVERIFY(!caps.fileTransfers());
 
267
    QVERIFY(!caps.textChatrooms());
 
268
    QVERIFY(!caps.conferenceStreamedMediaCalls());
 
269
    QVERIFY(!caps.conferenceStreamedMediaCallsWithInvitees());
 
270
    QVERIFY(!caps.conferenceTextChats());
 
271
    QVERIFY(!caps.conferenceTextChatsWithInvitees());
 
272
    QVERIFY(!caps.conferenceTextChatrooms());
 
273
    QVERIFY(!caps.conferenceTextChatroomsWithInvitees());
 
274
    QVERIFY(!caps.contactSearches());
 
275
    QVERIFY(!caps.contactSearchesWithSpecificServer());
 
276
    QVERIFY(!caps.contactSearchesWithLimit());
 
277
    QVERIFY(!caps.streamTubes());
 
278
    QVERIFY(caps.allClassSpecs().isEmpty());
 
279
    QVERIFY(!acc->connectsAutomatically());
 
280
    QVERIFY(!acc->hasBeenOnline());
 
281
    QCOMPARE(acc->connectionStatus(), ConnectionStatusDisconnected);
 
282
    QCOMPARE(acc->connectionStatusReason(), ConnectionStatusReasonNoneSpecified);
 
283
    QVERIFY(acc->connectionError().isEmpty());
 
284
    QVERIFY(!acc->connectionErrorDetails().isValid());
 
285
    QVERIFY(acc->connectionErrorDetails().allDetails().isEmpty());
 
286
    QVERIFY(!acc->connection());
 
287
    QVERIFY(!acc->isChangingPresence());
 
288
    // Neither FeatureProtocolInfo or FeatureProfile are ready yet and we have no connection
 
289
    PresenceSpecList expectedPresences;
 
290
    {
 
291
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeAvailable, true, false };
 
292
        expectedPresences.append(PresenceSpec(QLatin1String("available"), prSpec));
 
293
    }
 
294
    {
 
295
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeOffline, true, false };
 
296
        expectedPresences.append(PresenceSpec(QLatin1String("offline"), prSpec));
 
297
    }
 
298
    qSort(expectedPresences);
 
299
 
 
300
    PresenceSpecList presences = acc->allowedPresenceStatuses(false);
 
301
    qSort(presences);
 
302
    QCOMPARE(presences.size(), 2);
 
303
    QCOMPARE(presences, expectedPresences);
 
304
 
 
305
    presences = acc->allowedPresenceStatuses(true);
 
306
    qSort(presences);
 
307
    QCOMPARE(presences.size(), 2);
 
308
    QCOMPARE(presences, expectedPresences);
 
309
 
 
310
    // No connection
 
311
    QCOMPARE(acc->maxPresenceStatusMessageLength(), static_cast<uint>(0));
 
312
    QCOMPARE(acc->automaticPresence(), Presence::available());
 
313
    QCOMPARE(acc->currentPresence(), Presence::offline());
 
314
    QCOMPARE(acc->requestedPresence(), Presence::offline());
 
315
    QVERIFY(!acc->isOnline());
 
316
    QCOMPARE(acc->uniqueIdentifier(), QLatin1String("foo/bar/Account0"));
 
317
    QCOMPARE(acc->normalizedName(), QLatin1String("bob"));
 
318
 
 
319
    TEST_VERIFY_PROPERTY_CHANGE(acc, QString, DisplayName, displayName, QLatin1String("foo@bar"));
 
320
 
 
321
    TEST_VERIFY_PROPERTY_CHANGE(acc, QString, IconName, iconName, QLatin1String("im-foo"));
 
322
 
 
323
    // Setting icon to an empty string should fallback to im-$protocol as FeatureProtocolInfo and
 
324
    // FeatureProtocolInfo are not ready yet
 
325
    TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, QString, IconName, iconName, iconNameChanged,
 
326
            acc->setIconName(QString()), QLatin1String("im-bar"));
 
327
 
 
328
    TEST_VERIFY_PROPERTY_CHANGE(acc, QString, Nickname, nickname, QLatin1String("Bob rocks!"));
 
329
 
 
330
    qDebug() << "making Account::FeatureAvatar ready";
 
331
    QVERIFY(connect(acc->becomeReady(Account::FeatureAvatar),
 
332
                    SIGNAL(finished(Tp::PendingOperation *)),
 
333
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
334
    QCOMPARE(mLoop->exec(), 0);
 
335
    QVERIFY(acc->isReady(Account::FeatureAvatar));
 
336
 
 
337
    Avatar expectedAvatar = { QByteArray("asdfg"), QLatin1String("image/jpeg") };
 
338
    TEST_VERIFY_PROPERTY_CHANGE(acc, Tp::Avatar, Avatar, avatar, expectedAvatar);
 
339
 
 
340
    QVariantMap expectedParameters = acc->parameters();
 
341
    expectedParameters[QLatin1String("foo")] = QLatin1String("bar");
 
342
    TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, QVariantMap, Parameters, parameters,
 
343
            parametersChanged, acc->updateParameters(expectedParameters, QStringList()), expectedParameters);
 
344
 
 
345
    TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, bool,
 
346
            ConnectsAutomatically, connectsAutomatically, connectsAutomaticallyPropertyChanged,
 
347
            acc->setConnectsAutomatically(true), true);
 
348
 
 
349
    TEST_VERIFY_PROPERTY_CHANGE(acc, Tp::Presence, AutomaticPresence, automaticPresence,
 
350
            Presence::busy());
 
351
 
 
352
    // Changing requested presence will also change hasBeenOnline/isOnline/currentPresence
 
353
    Presence expectedPresence = Presence::busy();
 
354
    TEST_VERIFY_PROPERTY_CHANGE(acc, Tp::Presence, RequestedPresence, requestedPresence,
 
355
            expectedPresence);
 
356
    QVERIFY(acc->hasBeenOnline());
 
357
    QVERIFY(acc->isOnline());
 
358
    QCOMPARE(acc->currentPresence(), expectedPresence);
 
359
 
 
360
    qDebug() << "creating another account";
 
361
    pacc = mAM->createAccount(QLatin1String("spurious"),
 
362
            QLatin1String("normal"), QLatin1String("foobar"), QVariantMap());
 
363
    QVERIFY(connect(pacc,
 
364
                    SIGNAL(finished(Tp::PendingOperation *)),
 
365
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
366
    mCreatingAccount = true;
 
367
    QCOMPARE(mLoop->exec(), 0);
 
368
    mCreatingAccount = false;
 
369
 
 
370
    while (mAccountsCount != 2) {
 
371
        QCOMPARE(mLoop->exec(), 0);
 
372
    }
 
373
    processDBusQueue(mConn->client().data());
 
374
 
 
375
    acc = Account::create(mAM->dbusConnection(), mAM->busName(),
 
376
            QLatin1String("/org/freedesktop/Telepathy/Account/spurious/normal/Account0"),
 
377
            mAM->connectionFactory(), mAM->channelFactory(), mAM->contactFactory());
 
378
    QVERIFY(connect(acc->becomeReady(),
 
379
                    SIGNAL(finished(Tp::PendingOperation *)),
 
380
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
381
    QCOMPARE(mLoop->exec(), 0);
 
382
    QVERIFY(acc->isReady());
 
383
 
 
384
    QCOMPARE(acc->iconName(), QLatin1String("bob.png"));
 
385
    // Setting icon to an empty string should fallback to Profile/ProtocolInfo/im-$protocol
 
386
    TEST_VERIFY_PROPERTY_CHANGE_EXTENDED(acc, QString, IconName, iconName, iconNameChanged,
 
387
            acc->setIconName(QString()), QLatin1String("im-normal"));
 
388
 
 
389
    QVERIFY(connect(acc->becomeReady(Account::FeatureProtocolInfo),
 
390
                    SIGNAL(finished(Tp::PendingOperation *)),
 
391
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
392
    QCOMPARE(mLoop->exec(), 0);
 
393
    QVERIFY(acc->isReady(Account::FeatureProtocolInfo));
 
394
 
 
395
    // This time it's fetched from the protocol object (although it probably internally just
 
396
    // infers it from the protocol name too)
 
397
    QCOMPARE(acc->iconName(), QLatin1String("im-normal"));
 
398
 
 
399
    ProtocolInfo protocolInfo = acc->protocolInfo();
 
400
    QVERIFY(protocolInfo.isValid());
 
401
    QCOMPARE(protocolInfo.iconName(), QLatin1String("im-normal"));
 
402
    QVERIFY(protocolInfo.hasParameter(QLatin1String("account")));
 
403
    QVERIFY(protocolInfo.hasParameter(QLatin1String("password")));
 
404
    QVERIFY(protocolInfo.hasParameter(QLatin1String("register")));
 
405
    QVERIFY(!protocolInfo.hasParameter(QLatin1String("bogusparam")));
 
406
    QCOMPARE(protocolInfo.parameters().size(), 3);
 
407
 
 
408
    QVERIFY(connect(acc->becomeReady(Account::FeatureProfile),
 
409
                    SIGNAL(finished(Tp::PendingOperation *)),
 
410
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
411
    QCOMPARE(mLoop->exec(), 0);
 
412
    QVERIFY(acc->isReady(Account::FeatureProfile));
 
413
 
 
414
    ProfilePtr profile = acc->profile();
 
415
    QVERIFY(!profile.isNull());
 
416
    QVERIFY(profile->isFake());
 
417
    QVERIFY(profile->isValid());
 
418
    QCOMPARE(profile->serviceName(), QString(QLatin1String("%1-%2"))
 
419
                .arg(acc->cmName()).arg(acc->serviceName()));
 
420
    QCOMPARE(profile->type(), QLatin1String("IM"));
 
421
    QCOMPARE(profile->provider(), QString());
 
422
    QCOMPARE(profile->name(), acc->protocolName());
 
423
    QCOMPARE(profile->cmName(), acc->cmName());
 
424
    QCOMPARE(profile->protocolName(), acc->protocolName());
 
425
    QVERIFY(!profile->parameters().isEmpty());
 
426
    QVERIFY(profile->allowOtherPresences());
 
427
    QVERIFY(profile->presences().isEmpty());
 
428
    QVERIFY(profile->unsupportedChannelClassSpecs().isEmpty());
 
429
 
 
430
    QCOMPARE(acc->serviceName(), acc->protocolName());
 
431
    TEST_VERIFY_PROPERTY_CHANGE(acc, QString, ServiceName, serviceName,
 
432
            QLatin1String("spurious-service"));
 
433
 
 
434
    QVERIFY(connect(acc->becomeReady(Account::FeatureAvatar),
 
435
                    SIGNAL(finished(Tp::PendingOperation *)),
 
436
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
437
    QCOMPARE(mLoop->exec(), 0);
 
438
    QVERIFY(acc->isReady(Account::FeatureAvatar));
 
439
    QVERIFY(acc->avatar().avatarData.isEmpty());
 
440
    QCOMPARE(acc->avatar().MIMEType, QString(QLatin1String("image/png")));
 
441
 
 
442
    // make redundant becomeReady calls
 
443
    QVERIFY(connect(acc->becomeReady(Account::FeatureAvatar | Account::FeatureProtocolInfo),
 
444
                    SIGNAL(finished(Tp::PendingOperation *)),
 
445
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
446
    QCOMPARE(mLoop->exec(), 0);
 
447
    QVERIFY(acc->isReady(Account::FeatureAvatar | Account::FeatureProtocolInfo));
 
448
 
 
449
    QVERIFY(acc->avatar().avatarData.isEmpty());
 
450
    QCOMPARE(acc->avatar().MIMEType, QString(QLatin1String("image/png")));
 
451
    protocolInfo = acc->protocolInfo();
 
452
    QVERIFY(protocolInfo.isValid());
 
453
    QCOMPARE(protocolInfo.iconName(), QLatin1String("im-normal"));
 
454
    QVERIFY(protocolInfo.hasParameter(QLatin1String("account")));
 
455
    QVERIFY(protocolInfo.hasParameter(QLatin1String("password")));
 
456
    QVERIFY(protocolInfo.hasParameter(QLatin1String("register")));
 
457
 
 
458
    QVERIFY(connect(acc->becomeReady(Account::FeatureCapabilities),
 
459
                    SIGNAL(finished(Tp::PendingOperation *)),
 
460
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
 
461
    QCOMPARE(mLoop->exec(), 0);
 
462
    QVERIFY(acc->isReady(Account::FeatureCapabilities));
 
463
 
 
464
    // using protocol info
 
465
    caps = acc->capabilities();
 
466
    QVERIFY(caps.textChats());
 
467
 
 
468
    // set new service name will change caps, icon and serviceName
 
469
    QVERIFY(connect(acc.data(),
 
470
                    SIGNAL(capabilitiesChanged(const Tp::ConnectionCapabilities &)),
 
471
                    SLOT(onAccountCapabilitiesChanged(const Tp::ConnectionCapabilities &))));
 
472
    TEST_VERIFY_PROPERTY_CHANGE(acc, QString, ServiceName, serviceName,
 
473
            QLatin1String("test-profile"));
 
474
    while (!mProps.contains(QLatin1String("IconName")) &&
 
475
           !mProps.contains(QLatin1String("Capabilities"))) {
 
476
        QCOMPARE(mLoop->exec(), 0);
 
477
    }
 
478
 
 
479
    // Now that both FeatureProtocolInfo and FeatureProfile are ready, let's check the allowed
 
480
    // presences
 
481
    expectedPresences.clear();
 
482
    {
 
483
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeAvailable, true, true };
 
484
        expectedPresences.append(PresenceSpec(QLatin1String("available"), prSpec));
 
485
    }
 
486
    {
 
487
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeAway, true, true };
 
488
        expectedPresences.append(PresenceSpec(QLatin1String("away"), prSpec));
 
489
    }
 
490
    {
 
491
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeOffline, true, false };
 
492
        expectedPresences.append(PresenceSpec(QLatin1String("offline"), prSpec));
 
493
    }
 
494
    qSort(expectedPresences);
 
495
 
 
496
    presences = acc->allowedPresenceStatuses(false);
 
497
    qSort(presences);
 
498
    QCOMPARE(presences.size(), 3);
 
499
    QCOMPARE(presences, expectedPresences);
 
500
 
 
501
    {
 
502
        SimpleStatusSpec prSpec = { ConnectionPresenceTypeExtendedAway, false, false };
 
503
        expectedPresences.append(PresenceSpec(QLatin1String("xa"), prSpec));
 
504
    }
 
505
    qSort(expectedPresences);
 
506
 
 
507
    presences = acc->allowedPresenceStatuses(true);
 
508
    qSort(presences);
 
509
    QCOMPARE(presences.size(), 4);
 
510
    QCOMPARE(presences, expectedPresences);
 
511
 
 
512
    QCOMPARE(acc->iconName(), QLatin1String("test-profile-icon"));
 
513
 
 
514
    // using merged protocol info caps and profile caps
 
515
    caps = acc->capabilities();
 
516
    QVERIFY(!caps.textChats());
 
517
 
 
518
    Client::DBus::PropertiesInterface *accPropertiesInterface =
 
519
        acc->interface<Client::DBus::PropertiesInterface>();
 
520
 
 
521
    // simulate that the account has a connection
 
522
    QVERIFY(connect(new PendingVoid(
 
523
                        accPropertiesInterface->Set(
 
524
                            TP_QT_IFACE_ACCOUNT,
 
525
                            QLatin1String("Connection"),
 
526
                            QDBusVariant(mConn->objectPath())),
 
527
                        acc),
 
528
                    SIGNAL(finished(Tp::PendingOperation*)),
 
529
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
 
530
    // wait for the connection to be built in Account
 
531
    while (acc->connection().isNull()) {
 
532
        QCOMPARE(mLoop->exec(), 0);
 
533
    }
 
534
 
 
535
    QVERIFY(connect(acc->connection()->becomeReady(),
 
536
                    SIGNAL(finished(Tp::PendingOperation*)),
 
537
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
 
538
    QCOMPARE(mLoop->exec(), 0);
 
539
    QVERIFY(acc->isReady());
 
540
 
 
541
    // once the status change the capabilities will be updated
 
542
    mProps.clear();
 
543
    QVERIFY(connect(acc->setRequestedPresence(Presence::available()),
 
544
                    SIGNAL(finished(Tp::PendingOperation*)),
 
545
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
 
546
    while (!mProps.contains(QLatin1String("Capabilities"))) {
 
547
        QCOMPARE(mLoop->exec(), 0);
 
548
    }
 
549
 
 
550
    // using connection caps now
 
551
    caps = acc->capabilities();
 
552
    QVERIFY(caps.textChats());
 
553
    QVERIFY(!caps.textChatrooms());
 
554
    QVERIFY(!caps.streamedMediaCalls());
 
555
    QVERIFY(!caps.streamedMediaAudioCalls());
 
556
    QVERIFY(!caps.streamedMediaVideoCalls());
 
557
    QVERIFY(!caps.streamedMediaVideoCallsWithAudio());
 
558
    QVERIFY(!caps.upgradingStreamedMediaCalls());
 
559
 
 
560
    // once the status change the capabilities will be updated
 
561
    mProps.clear();
 
562
    QVERIFY(connect(new PendingVoid(
 
563
                        accPropertiesInterface->Set(
 
564
                            TP_QT_IFACE_ACCOUNT,
 
565
                            QLatin1String("Connection"),
 
566
                            QDBusVariant(QLatin1String("/"))),
 
567
                        acc),
 
568
                    SIGNAL(finished(Tp::PendingOperation*)),
 
569
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
 
570
    QVERIFY(connect(acc->setRequestedPresence(Presence::offline()),
 
571
                    SIGNAL(finished(Tp::PendingOperation*)),
 
572
                    SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
 
573
    while (!mProps.contains(QLatin1String("Capabilities"))) {
 
574
        QCOMPARE(mLoop->exec(), 0);
 
575
    }
 
576
 
 
577
    // back to using merged protocol info caps and profile caps
 
578
    caps = acc->capabilities();
 
579
    QVERIFY(!caps.textChats());
 
580
 
 
581
    processDBusQueue(mConn->client().data());
 
582
}
 
583
 
 
584
void TestAccountBasics::cleanup()
 
585
{
 
586
    cleanupImpl();
 
587
}
 
588
 
 
589
void TestAccountBasics::cleanupTestCase()
 
590
{
 
591
    if (mConn) {
 
592
        QVERIFY(mConn->disconnect());
 
593
        delete mConn;
 
594
    }
 
595
 
 
596
    cleanupTestCaseImpl();
 
597
}
 
598
 
 
599
QTEST_MAIN(TestAccountBasics)
 
600
#include "_gen/account-basics.cpp.moc.hpp"