1 #include <QtTest/QtTest>
2
3 #include <TelepathyQt/Debug>
4 #include <TelepathyQt/Profile>
5
6 using namespace Tp;
7
8 class TestProfile : public QObject
9 {
10 Q_OBJECT
11
12 public:
13 TestProfile(QObject *parent = 0);
14
15 private Q_SLOTS:
16 void testProfile();
17 };
18
TestProfile(QObject * parent)19 TestProfile::TestProfile(QObject *parent)
20 : QObject(parent)
21 {
22 Tp::enableDebug(true);
23 Tp::enableWarnings(true);
24 }
25
testProfile()26 void TestProfile::testProfile()
27 {
28 QString top_srcdir = QString::fromLocal8Bit(::getenv("abs_top_srcdir"));
29 if (!top_srcdir.isEmpty()) {
30 QDir::setCurrent(top_srcdir + QLatin1String("/tests"));
31 }
32
33 ProfilePtr profile = Profile::createForServiceName(QLatin1String("test-profile-file-not-found"));
34 QCOMPARE(profile->isValid(), false);
35
36 profile = Profile::createForServiceName(QLatin1String("test-profile-malformed"));
37 QCOMPARE(profile->isValid(), false);
38
39 profile = Profile::createForServiceName(QLatin1String("test-profile-invalid-service-id"));
40 QCOMPARE(profile->isValid(), false);
41
42 profile = Profile::createForServiceName(QLatin1String("test-profile-non-im-type"));
43 QCOMPARE(profile->isValid(), false);
44
45 profile = Profile::createForFileName(QLatin1String("telepathy/profiles/test-profile-non-im-type.profile"));
46 QCOMPARE(profile->isValid(), true);
47
48 profile = Profile::createForServiceName(QLatin1String("test-profile"));
49 QCOMPARE(profile->isValid(), true);
50
51 QCOMPARE(profile->serviceName(), QLatin1String("test-profile"));
52 QCOMPARE(profile->type(), QLatin1String("IM"));
53 QCOMPARE(profile->provider(), QLatin1String("TestProfileProvider"));
54 QCOMPARE(profile->name(), QLatin1String("TestProfile"));
55 QCOMPARE(profile->cmName(), QLatin1String("testprofilecm"));
56 QCOMPARE(profile->protocolName(), QLatin1String("testprofileproto"));
57
58 QCOMPARE(profile->parameters().isEmpty(), false);
59 QCOMPARE(profile->parameters().count(), 2);
60
61 QCOMPARE(profile->hasParameter(QLatin1String("foo")), false);
62
63 QCOMPARE(profile->hasParameter(QLatin1String("server")), true);
64 Profile::Parameter param = profile->parameter(QLatin1String("server"));
65 QCOMPARE(param.name(), QLatin1String("server"));
66 QCOMPARE(param.dbusSignature(), QDBusSignature(QLatin1String("s")));
67 QCOMPARE(param.type(), QVariant::String);
68 QCOMPARE(param.value(), QVariant(QLatin1String("profile.com")));
69 QCOMPARE(param.label(), QString());
70 QCOMPARE(param.isMandatory(), true);
71
72 QCOMPARE(profile->hasParameter(QLatin1String("port")), true);
73 param = profile->parameter(QLatin1String("port"));
74 QCOMPARE(param.name(), QLatin1String("port"));
75 QCOMPARE(param.dbusSignature(), QDBusSignature(QLatin1String("u")));
76 QCOMPARE(param.type(), QVariant::UInt);
77 QCOMPARE(param.value(), QVariant(QLatin1String("1111")));
78 QCOMPARE(param.label(), QString());
79 QCOMPARE(param.isMandatory(), true);
80
81 QCOMPARE(profile->presences().isEmpty(), false);
82 QCOMPARE(profile->presences().count(), 5);
83
84 QCOMPARE(profile->hasPresence(QLatin1String("foo")), false);
85
86 QCOMPARE(profile->hasPresence(QLatin1String("available")), true);
87 Profile::Presence presence = profile->presence(QLatin1String("available"));
88 QCOMPARE(presence.id(), QLatin1String("available"));
89 QCOMPARE(presence.label(), QLatin1String("Online"));
90 QCOMPARE(presence.iconName(), QLatin1String("online"));
91 QCOMPARE(presence.isDisabled(), false);
92
93 QCOMPARE(profile->hasPresence(QLatin1String("offline")), true);
94 presence = profile->presence(QLatin1String("offline"));
95 QCOMPARE(presence.id(), QLatin1String("offline"));
96 QCOMPARE(presence.label(), QLatin1String("Offline"));
97 QCOMPARE(presence.iconName(), QString());
98 QCOMPARE(presence.isDisabled(), false);
99
100 QCOMPARE(profile->hasPresence(QLatin1String("away")), true);
101 presence = profile->presence(QLatin1String("away"));
102 QCOMPARE(presence.id(), QLatin1String("away"));
103 QCOMPARE(presence.label(), QLatin1String("Gone"));
104 QCOMPARE(presence.iconName(), QString());
105 QCOMPARE(presence.isDisabled(), false);
106
107 QCOMPARE(profile->hasPresence(QLatin1String("hidden")), true);
108 presence = profile->presence(QLatin1String("hidden"));
109 QCOMPARE(presence.id(), QLatin1String("hidden"));
110 QCOMPARE(presence.label(), QString());
111 QCOMPARE(presence.iconName(), QString());
112 QCOMPARE(presence.isDisabled(), true);
113
114 QCOMPARE(profile->unsupportedChannelClassSpecs().isEmpty(), false);
115 QCOMPARE(profile->unsupportedChannelClassSpecs().count(), 2);
116
117 RequestableChannelClassSpec rccSpec = profile->unsupportedChannelClassSpecs().first();
118 QCOMPARE(rccSpec.hasTargetHandleType(), true);
119 QCOMPARE(rccSpec.targetHandleType(), HandleTypeContact);
120 QCOMPARE(rccSpec.channelType(), QLatin1String("org.freedesktop.Telepathy.Channel.Type.Text"));
121
122 profile = Profile::createForServiceName(QLatin1String("test-profile-no-icon-and-provider"));
123 QCOMPARE(profile->isValid(), true);
124
125 QCOMPARE(profile->serviceName(), QLatin1String("test-profile-no-icon-and-provider"));
126 QCOMPARE(profile->type(), QLatin1String("IM"));
127 QCOMPARE(profile->provider().isEmpty(), true);
128 QCOMPARE(profile->cmName(), QLatin1String("testprofilecm"));
129 QCOMPARE(profile->protocolName(), QLatin1String("testprofileproto"));
130 QCOMPARE(profile->iconName().isEmpty(), true);
131 }
132
133 QTEST_MAIN(TestProfile)
134
135 #include "_gen/profile.cpp.moc.hpp"
136