summaryrefslogtreecommitdiff
path: root/qt4/tests/profile.cpp
blob: 7aeea6f727871c13078c13101523c1d7b196a384 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <QtTest/QtTest>

#include <TelepathyQt4/Debug>
#include <TelepathyQt4/Profile>

using namespace Tp;

class TestProfile : public QObject
{
    Q_OBJECT

public:
    TestProfile(QObject *parent = 0);

private Q_SLOTS:
    void testProfile();
};

TestProfile::TestProfile(QObject *parent)
    : QObject(parent)
{
    Tp::enableDebug(true);
    Tp::enableWarnings(true);
}

void TestProfile::testProfile()
{
    QString top_srcdir = QString::fromLocal8Bit(::getenv("abs_top_srcdir"));
    if (!top_srcdir.isEmpty()) {
        QDir::setCurrent(top_srcdir + QLatin1String("/tests"));
    }

    ProfilePtr profile = Profile::createForServiceName(QLatin1String("test-profile-file-not-found"));
    QCOMPARE(profile->isValid(), false);

    profile = Profile::createForServiceName(QLatin1String("test-profile-malformed"));
    QCOMPARE(profile->isValid(), false);

    profile = Profile::createForServiceName(QLatin1String("test-profile-invalid-service-id"));
    QCOMPARE(profile->isValid(), false);

    profile = Profile::createForServiceName(QLatin1String("test-profile-non-im-type"));
    QCOMPARE(profile->isValid(), false);

    profile = Profile::createForFileName(QLatin1String("telepathy/profiles/test-profile-non-im-type.profile"));
    QCOMPARE(profile->isValid(), true);

    profile = Profile::createForServiceName(QLatin1String("test-profile"));
    QCOMPARE(profile->isValid(), true);

    QCOMPARE(profile->serviceName(), QLatin1String("test-profile"));
    QCOMPARE(profile->type(), QLatin1String("IM"));
    QCOMPARE(profile->provider(), QLatin1String("TestProfileProvider"));
    QCOMPARE(profile->name(), QLatin1String("TestProfile"));
    QCOMPARE(profile->cmName(), QLatin1String("testprofilecm"));
    QCOMPARE(profile->protocolName(), QLatin1String("testprofileproto"));

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

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

    QCOMPARE(profile->hasParameter(QLatin1String("server")), true);
    Profile::Parameter param = profile->parameter(QLatin1String("server"));
    QCOMPARE(param.name(), QLatin1String("server"));
    QCOMPARE(param.dbusSignature(), QDBusSignature(QLatin1String("s")));
    QCOMPARE(param.type(), QVariant::String);
    QCOMPARE(param.value(), QVariant(QLatin1String("profile.com")));
    QCOMPARE(param.label(), QString());
    QCOMPARE(param.isMandatory(), true);

    QCOMPARE(profile->hasParameter(QLatin1String("port")), true);
    param = profile->parameter(QLatin1String("port"));
    QCOMPARE(param.name(), QLatin1String("port"));
    QCOMPARE(param.dbusSignature(), QDBusSignature(QLatin1String("u")));
    QCOMPARE(param.type(), QVariant::UInt);
    QCOMPARE(param.value(), QVariant(QLatin1String("1111")));
    QCOMPARE(param.label(), QString());
    QCOMPARE(param.isMandatory(), true);

    QCOMPARE(profile->presences().isEmpty(), false);
    QCOMPARE(profile->presences().count(), 5);

    QCOMPARE(profile->hasPresence(QLatin1String("foo")), false);

    QCOMPARE(profile->hasPresence(QLatin1String("available")), true);
    Profile::Presence presence = profile->presence(QLatin1String("available"));
    QCOMPARE(presence.id(), QLatin1String("available"));
    QCOMPARE(presence.label(), QLatin1String("Online"));
    QCOMPARE(presence.iconName(), QLatin1String("online"));
    QCOMPARE(presence.isDisabled(), false);

    QCOMPARE(profile->hasPresence(QLatin1String("offline")), true);
    presence = profile->presence(QLatin1String("offline"));
    QCOMPARE(presence.id(), QLatin1String("offline"));
    QCOMPARE(presence.label(), QLatin1String("Offline"));
    QCOMPARE(presence.iconName(), QString());
    QCOMPARE(presence.isDisabled(), false);

    QCOMPARE(profile->hasPresence(QLatin1String("away")), true);
    presence = profile->presence(QLatin1String("away"));
    QCOMPARE(presence.id(), QLatin1String("away"));
    QCOMPARE(presence.label(), QLatin1String("Gone"));
    QCOMPARE(presence.iconName(), QString());
    QCOMPARE(presence.isDisabled(), false);

    QCOMPARE(profile->hasPresence(QLatin1String("hidden")), true);
    presence = profile->presence(QLatin1String("hidden"));
    QCOMPARE(presence.id(), QLatin1String("hidden"));
    QCOMPARE(presence.label(), QString());
    QCOMPARE(presence.iconName(), QString());
    QCOMPARE(presence.isDisabled(), true);

    QCOMPARE(profile->unsupportedChannelClassSpecs().isEmpty(), false);
    QCOMPARE(profile->unsupportedChannelClassSpecs().count(), 2);

    RequestableChannelClassSpec rccSpec = profile->unsupportedChannelClassSpecs().first();
    QCOMPARE(rccSpec.hasTargetHandleType(), true);
    QCOMPARE(rccSpec.targetHandleType(), HandleTypeContact);
    QCOMPARE(rccSpec.channelType(), QLatin1String("org.freedesktop.Telepathy.Channel.Type.Text"));

    profile = Profile::createForServiceName(QLatin1String("test-profile-no-icon-and-provider"));
    QCOMPARE(profile->isValid(), true);

    QCOMPARE(profile->serviceName(), QLatin1String("test-profile-no-icon-and-provider"));
    QCOMPARE(profile->type(), QLatin1String("IM"));
    QCOMPARE(profile->provider().isEmpty(), true);
    QCOMPARE(profile->cmName(), QLatin1String("testprofilecm"));
    QCOMPARE(profile->protocolName(), QLatin1String("testprofileproto"));
    QCOMPARE(profile->iconName().isEmpty(), true);
}

QTEST_MAIN(TestProfile)

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