summaryrefslogtreecommitdiff
path: root/qt4/tests/dbus/profile-manager.cpp
blob: 226f5bdb77fd87abea56da05f2884dee9d72600d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <QtTest/QtTest>

#include <TelepathyQt4/PendingReady>
#include <TelepathyQt4/ProfileManager>

#include <tests/lib/test.h>

using namespace Tp;

class TestProfileManager : public Test
{
    Q_OBJECT

private Q_SLOTS:
    void testProfileManager();
};

void TestProfileManager::testProfileManager()
{
    ProfileManagerPtr pm = ProfileManager::create(QDBusConnection::sessionBus());
    QVERIFY(connect(pm->becomeReady(),
                    SIGNAL(finished(Tp::PendingOperation *)),
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
    QCOMPARE(mLoop->exec(), 0);
    QCOMPARE(pm->isReady(), true);

    QCOMPARE(pm->profiles().isEmpty(), false);
    QCOMPARE(pm->profiles().count(), 2);
    QCOMPARE(pm->profileForService(QLatin1String("test-profile")).isNull(), false);
    QCOMPARE(pm->profileForService(QLatin1String("test-profile-file-not-found")).isNull(), true);
    QCOMPARE(pm->profileForService(QLatin1String("test-profile-non-im-type")).isNull(), true);
    QCOMPARE(pm->profilesForCM(QLatin1String("testprofilecm")).isEmpty(), false);
    QCOMPARE(pm->profilesForCM(QLatin1String("testprofilecm")).count(), 2);
    QCOMPARE(pm->profilesForProtocol(QLatin1String("testprofileproto")).isEmpty(), false);
    QCOMPARE(pm->profilesForProtocol(QLatin1String("testprofileproto")).count(), 2);

    QVERIFY(connect(pm->becomeReady(ProfileManager::FeatureFakeProfiles),
                    SIGNAL(finished(Tp::PendingOperation *)),
                    SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
    QCOMPARE(mLoop->exec(), 0);
    QCOMPARE(pm->isReady(ProfileManager::FeatureFakeProfiles), true);

    QCOMPARE(pm->profiles().isEmpty(), false);
    QCOMPARE(pm->profiles().count(), 4);
    QCOMPARE(pm->profileForService(QLatin1String("spurious-normal")).isNull(), false);
    QCOMPARE(pm->profileForService(QLatin1String("spurious-weird")).isNull(), false);
    QCOMPARE(pm->profilesForCM(QLatin1String("spurious")).isEmpty(), false);
    QCOMPARE(pm->profilesForCM(QLatin1String("spurious")).count(), 2);
    QCOMPARE(pm->profilesForProtocol(QLatin1String("normal")).isEmpty(), false);
    QCOMPARE(pm->profilesForProtocol(QLatin1String("weird")).isEmpty(), false);

    ProfilePtr profile = pm->profileForService(QLatin1String("spurious-normal"));
    QCOMPARE(profile->type(), QLatin1String("IM"));

    QCOMPARE(profile->provider(), QString());
    QCOMPARE(profile->name(), QLatin1String("normal"));
    QCOMPARE(profile->cmName(), QLatin1String("spurious"));
    QCOMPARE(profile->protocolName(), QLatin1String("normal"));
    QCOMPARE(profile->presences().isEmpty(), true);

    QCOMPARE(profile->parameters().isEmpty(), false);
    QCOMPARE(profile->parameters().count(), 1);

    QCOMPARE(profile->hasParameter(QLatin1String("not-found")), false);

    /* profile will only return CM default params, account is ignored */
    QCOMPARE(profile->hasParameter(QLatin1String("account")), false);

    /* profile will only return CM default params, password is ignored */
    QCOMPARE(profile->hasParameter(QLatin1String("password")), false);

    Profile::Parameter param = profile->parameter(QLatin1String("register"));
    QCOMPARE(param.name(), QLatin1String("register"));
    QCOMPARE(param.dbusSignature(), QDBusSignature(QLatin1String("b")));
    QCOMPARE(param.type(), QVariant::Bool);
    QCOMPARE(param.value(), QVariant(true));
    QCOMPARE(param.label(), QString());
    QCOMPARE(param.isMandatory(), false);

    // Allow the PendingReadys to delete themselves
    mLoop->processEvents();
}

QTEST_MAIN(TestProfileManager)

#include "_gen/profile-manager.cpp.moc.hpp"