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
136
137
138
139
140
141
142
143
144
145
|
#include <QtTest/QtTest>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/ManagerFile>
using namespace Tp;
bool containsParam(const ParamSpecList ¶ms, const char *name);
const ParamSpec *getParam(const ParamSpecList ¶ms, const QString &name);
class TestManagerFile : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testManagerFile();
};
void TestManagerFile::testManagerFile()
{
ManagerFile notFoundManagerFile(QLatin1String("test-manager-file-not-found"));
QCOMPARE(notFoundManagerFile.isValid(), false);
ManagerFile invalidManagerFile(QLatin1String("test-manager-file-malformed-keyfile"));
QCOMPARE(invalidManagerFile.isValid(), false);
ManagerFile invalidManagerFile2(QLatin1String("test-manager-file-invalid-signature"));
QCOMPARE(invalidManagerFile2.isValid(), false);
ManagerFile managerFile(QLatin1String("test-manager-file"));
QCOMPARE(managerFile.isValid(), true);
QStringList protocols = managerFile.protocols();
protocols.sort();
QCOMPARE(protocols,
QStringList() << QLatin1String("bar") << QLatin1String("foo") << QLatin1String("somewhat-pathological"));
ParamSpecList params = managerFile.parameters(QLatin1String("foo"));
QCOMPARE(containsParam(params, "account"), true);
QCOMPARE(containsParam(params, "encryption-key"), true);
QCOMPARE(containsParam(params, "password"), true);
QCOMPARE(containsParam(params, "port"), true);
QCOMPARE(containsParam(params, "register"), true);
QCOMPARE(containsParam(params, "server-list"), true);
QCOMPARE(containsParam(params, "non-existant"), false);
QCOMPARE(QLatin1String("x-foo"), managerFile.vcardField(QLatin1String("foo")));
QCOMPARE(QLatin1String("Foo"), managerFile.englishName(QLatin1String("foo")));
QCOMPARE(QLatin1String("im-foo"), managerFile.iconName(QLatin1String("foo")));
RequestableChannelClass expectedRcc;
expectedRcc.fixedProperties.insert(
QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT));
expectedRcc.fixedProperties.insert(
QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
HandleTypeContact);
expectedRcc.allowedProperties.append(
QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"));
expectedRcc.allowedProperties.append(
QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"));
RequestableChannelClassList expectedRccs;
expectedRccs.append(expectedRcc);
QCOMPARE(expectedRccs, managerFile.requestableChannelClasses(QLatin1String("foo")));
const ParamSpec *param;
param = getParam(params, QLatin1String("account"));
QCOMPARE(param->flags, (uint) ConnMgrParamFlagRequired | ConnMgrParamFlagHasDefault);
QCOMPARE(param->signature, QString(QLatin1String("s")));
param = getParam(params, QLatin1String("password"));
QCOMPARE(param->flags, (uint) ConnMgrParamFlagRequired | ConnMgrParamFlagSecret);
QCOMPARE(param->signature, QString(QLatin1String("s")));
param = getParam(params, QLatin1String("encryption-key"));
QCOMPARE(param->flags, (uint) ConnMgrParamFlagSecret);
QCOMPARE(param->signature, QString(QLatin1String("s")));
params = managerFile.parameters(QLatin1String("somewhat-pathological"));
QCOMPARE(containsParam(params, "foo"), true);
QCOMPARE(containsParam(params, "semicolons"), true);
QCOMPARE(containsParam(params, "list"), true);
QCOMPARE(containsParam(params, "unterminated-list"), true);
QCOMPARE(containsParam(params, "spaces-in-list"), true);
QCOMPARE(containsParam(params, "escaped-semicolon-in-list"), true);
QCOMPARE(containsParam(params, "doubly-escaped-semicolon-in-list"), true);
QCOMPARE(containsParam(params, "triply-escaped-semicolon-in-list"), true);
QCOMPARE(containsParam(params, "empty-list"), true);
QCOMPARE(containsParam(params, "escaped-semicolon"), true);
QCOMPARE(containsParam(params, "object"), true);
QCOMPARE(containsParam(params, "non-existant"), false);
param = getParam(params, QLatin1String("foo"));
QCOMPARE(param->flags, (uint) ConnMgrParamFlagRequired | ConnMgrParamFlagHasDefault);
QCOMPARE(param->signature, QString(QLatin1String("s")));
param = getParam(params, QLatin1String("semicolons"));
QCOMPARE(param->flags, (uint) ConnMgrParamFlagSecret | ConnMgrParamFlagHasDefault);
QCOMPARE(param->signature, QString(QLatin1String("s")));
param = getParam(params, QLatin1String("list"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList() << QLatin1String("list") << QLatin1String("of") << QLatin1String("misc"));
param = getParam(params, QLatin1String("escaped-semicolon-in-list"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList() << QLatin1String("list;of") << QLatin1String("misc"));
param = getParam(params, QLatin1String("doubly-escaped-semicolon-in-list"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList() << QLatin1String("list\\") << QLatin1String("of") << QLatin1String("misc"));
param = getParam(params, QLatin1String("triply-escaped-semicolon-in-list"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList() << QLatin1String("list\\;of") << QLatin1String("misc"));
param = getParam(params, QLatin1String("empty-list"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList());
param = getParam(params, QLatin1String("list-of-empty-string"));
QCOMPARE(param->signature, QString(QLatin1String("as")));
QCOMPARE(param->defaultValue.variant().toStringList(),
QStringList() << QString());
}
bool containsParam(const ParamSpecList ¶ms, const char *name)
{
Q_FOREACH (const ParamSpec ¶m, params) {
if (param.name == QLatin1String(name)) {
return true;
}
}
return false;
}
const ParamSpec *getParam(const ParamSpecList ¶ms, const QString &name)
{
Q_FOREACH (const ParamSpec ¶m, params) {
if (param.name == name) {
return ¶m;
}
}
return NULL;
}
QTEST_MAIN(TestManagerFile)
#include "_gen/manager-file.cpp.moc.hpp"
|