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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#include <tests/lib/test.h>
#include <tests/lib/test-thread-helper.h>
#define TP_QT_ENABLE_LOWLEVEL_API
#include <TelepathyQt/BaseConnectionManager>
#include <TelepathyQt/BaseProtocol>
#include <TelepathyQt/ConnectionManager>
#include <TelepathyQt/ConnectionManagerLowlevel>
#include <TelepathyQt/DBusError>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/PendingConnection>
using namespace Tp;
class TestBaseCM : public Test
{
Q_OBJECT
public:
TestBaseCM(QObject *parent = 0)
: Test(parent)
{ }
private Q_SLOTS:
void initTestCase();
void init();
void testNoProtocols();
void testProtocols();
void cleanup();
void cleanupTestCase();
private:
static void testNoProtocolsCreateCM(BaseConnectionManagerPtr &cm);
static void testProtocolsCreateCM(BaseConnectionManagerPtr &cm);
};
void TestBaseCM::initTestCase()
{
initTestCaseImpl();
}
void TestBaseCM::init()
{
initImpl();
}
void TestBaseCM::testNoProtocolsCreateCM(BaseConnectionManagerPtr &cm)
{
cm = BaseConnectionManager::create(QLatin1String("testcm"));
Tp::DBusError err;
QVERIFY(cm->registerObject(&err));
QVERIFY(!err.isValid());
QCOMPARE(cm->protocols().size(), 0);
}
void TestBaseCM::testNoProtocols()
{
qDebug() << "Introspecting non-existing CM";
ConnectionManagerPtr cliCM = ConnectionManager::create(
QLatin1String("testcm"));
PendingReady *pr = cliCM->becomeReady(ConnectionManager::FeatureCore);
connect(pr, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(expectFailure(Tp::PendingOperation*)));
QCOMPARE(mLoop->exec(), 0);
qDebug() << "Creating CM";
TestThreadHelper<BaseConnectionManagerPtr> helper;
TEST_THREAD_HELPER_EXECUTE(&helper, &testNoProtocolsCreateCM);
qDebug() << "Introspecting new CM";
cliCM = ConnectionManager::create(QLatin1String("testcm"));
pr = cliCM->becomeReady(ConnectionManager::FeatureCore);
connect(pr, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(expectSuccessfulCall(Tp::PendingOperation*)));
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(cliCM->supportedProtocols().size(), 0);
qDebug() << "Requesting connection";
PendingConnection *pc = cliCM->lowlevel()->requestConnection(
QLatin1String("jabber"), QVariantMap());
connect(pc, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(expectFailure(Tp::PendingOperation*)));
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(mLastError, TP_QT_ERROR_NOT_IMPLEMENTED);
}
void TestBaseCM::testProtocolsCreateCM(BaseConnectionManagerPtr &cm)
{
cm = BaseConnectionManager::create(QLatin1String("testcm"));
BaseProtocolPtr protocol = BaseProtocol::create(QLatin1String("myprotocol"));
QVERIFY(!protocol.isNull());
QVERIFY(cm->addProtocol(protocol));
QVERIFY(cm->hasProtocol(QLatin1String("myprotocol")));
QCOMPARE(cm->protocol(QLatin1String("myprotocol")), protocol);
QCOMPARE(cm->protocols().size(), 1);
QVERIFY(!cm->hasProtocol(QLatin1String("otherprotocol")));
QVERIFY(cm->protocol(QLatin1String("otherprotocol")).isNull());
//can't add the same protocol twice
QVERIFY(!cm->addProtocol(protocol));
Tp::DBusError err;
QVERIFY(cm->registerObject(&err));
QVERIFY(!err.isValid());
//can't add another protocol after registerObject()
protocol = BaseProtocol::create(QLatin1String("otherprotocol"));
QVERIFY(!protocol.isNull());
QVERIFY(!cm->addProtocol(protocol));
QCOMPARE(cm->protocols().size(), 1);
protocol.reset();
QVariantMap props = cm->immutableProperties();
QVERIFY(props.contains(TP_QT_IFACE_CONNECTION_MANAGER + QLatin1String(".Protocols")));
ProtocolPropertiesMap protocols = qvariant_cast<Tp::ProtocolPropertiesMap>(
props[TP_QT_IFACE_CONNECTION_MANAGER + QLatin1String(".Protocols")]);
QVERIFY(protocols.contains(QLatin1String("myprotocol")));
QVERIFY(!protocols.contains(QLatin1String("otherprotocol")));
}
void TestBaseCM::testProtocols()
{
qDebug() << "Creating CM";
TestThreadHelper<BaseConnectionManagerPtr> helper;
TEST_THREAD_HELPER_EXECUTE(&helper, &testProtocolsCreateCM);
qDebug() << "Introspecting CM";
ConnectionManagerPtr cliCM = ConnectionManager::create(
QLatin1String("testcm"));
PendingReady *pr = cliCM->becomeReady(ConnectionManager::FeatureCore);
connect(pr, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(expectSuccessfulCall(Tp::PendingOperation*)));
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(cliCM->supportedProtocols().size(), 1);
QVERIFY(cliCM->hasProtocol(QLatin1String("myprotocol")));
PendingConnection *pc = cliCM->lowlevel()->requestConnection(
QLatin1String("myprotocol"), QVariantMap());
connect(pc, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(expectFailure(Tp::PendingOperation*)));
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(mLastError, TP_QT_ERROR_NOT_IMPLEMENTED);
}
void TestBaseCM::cleanup()
{
cleanupImpl();
}
void TestBaseCM::cleanupTestCase()
{
cleanupTestCaseImpl();
}
QTEST_MAIN(TestBaseCM)
#include "_gen/base-cm.cpp.moc.hpp"
|