1
#include <tests/lib/test.h>
3
#include <tests/lib/glib-helpers/test-conn-helper.h>
5
#include <tests/lib/glib/echo/chan.h>
6
#include <tests/lib/glib/echo/conn.h>
7
#include <tests/lib/glib/future/conference/chan.h>
9
#include <TelepathyQt/Connection>
10
#include <TelepathyQt/PendingReady>
12
#include <telepathy-glib/debug.h>
16
class TestConferenceChan : public Test
21
TestConferenceChan(QObject *parent = 0)
23
mConn(0), mContactRepo(0),
24
mTextChan1Service(0), mTextChan2Service(0), mConferenceChanService(0)
28
void onConferenceChannelMerged(const Tp::ChannelPtr &);
29
void onConferenceChannelRemoved(const Tp::ChannelPtr &channel,
30
const Tp::Channel::GroupMemberChangeDetails &details);
36
void testConference();
39
void cleanupTestCase();
42
TestConnHelper *mConn;
43
TpHandleRepoIface *mContactRepo;
46
QString mTextChan1Path;
47
ExampleEchoChannel *mTextChan1Service;
48
QString mTextChan2Path;
49
ExampleEchoChannel *mTextChan2Service;
50
QString mTextChan3Path;
51
ExampleEchoChannel *mTextChan3Service;
52
QString mConferenceChanPath;
53
TpTestsConferenceChannel *mConferenceChanService;
55
ChannelPtr mChannelMerged;
56
ChannelPtr mChannelRemovedDetailed;
57
Channel::GroupMemberChangeDetails mChannelRemovedDetailedDetails;
60
void TestConferenceChan::onConferenceChannelMerged(const Tp::ChannelPtr &channel)
62
mChannelMerged = channel;
66
void TestConferenceChan::onConferenceChannelRemoved(const Tp::ChannelPtr &channel,
67
const Tp::Channel::GroupMemberChangeDetails &details)
69
mChannelRemovedDetailed = channel;
70
mChannelRemovedDetailedDetails = details;
74
void TestConferenceChan::initTestCase()
79
g_set_prgname("chan-conference");
80
tp_debug_set_flags("all");
81
dbus_g_bus_get(DBUS_BUS_STARTER, 0);
83
mConn = new TestConnHelper(this,
84
EXAMPLE_TYPE_ECHO_CONNECTION,
85
"account", "me@example.com",
86
"protocol", "example",
88
QCOMPARE(mConn->connect(), true);
90
// create a Channel by magic, rather than doing D-Bus round-trips for it
91
mContactRepo = tp_base_connection_get_handles(TP_BASE_CONNECTION(mConn->service()),
92
TP_HANDLE_TYPE_CONTACT);
93
guint handle1 = tp_handle_ensure(mContactRepo, "someone1@localhost", 0, 0);
94
guint handle2 = tp_handle_ensure(mContactRepo, "someone2@localhost", 0, 0);
95
guint handle3 = tp_handle_ensure(mContactRepo, "someone3@localhost", 0, 0);
98
GPtrArray *initialChannels = g_ptr_array_new();
100
mTextChan1Path = mConn->objectPath() + QLatin1String("/TextChannel/1");
101
chanPath = mTextChan1Path.toAscii();
102
mTextChan1Service = EXAMPLE_ECHO_CHANNEL(g_object_new(
103
EXAMPLE_TYPE_ECHO_CHANNEL,
104
"connection", mConn->service(),
105
"object-path", chanPath.data(),
108
g_ptr_array_add(initialChannels, g_strdup(chanPath.data()));
110
mTextChan2Path = mConn->objectPath() + QLatin1String("/TextChannel/2");
111
chanPath = mTextChan2Path.toAscii();
112
mTextChan2Service = EXAMPLE_ECHO_CHANNEL(g_object_new(
113
EXAMPLE_TYPE_ECHO_CHANNEL,
114
"connection", mConn->service(),
115
"object-path", chanPath.data(),
118
g_ptr_array_add(initialChannels, g_strdup(chanPath.data()));
120
// let's not add this one to initial channels
121
mTextChan3Path = mConn->objectPath() + QLatin1String("/TextChannel/3");
122
chanPath = mTextChan3Path.toAscii();
123
mTextChan3Service = EXAMPLE_ECHO_CHANNEL(g_object_new(
124
EXAMPLE_TYPE_ECHO_CHANNEL,
125
"connection", mConn->service(),
126
"object-path", chanPath.data(),
130
mConferenceChanPath = mConn->objectPath() + QLatin1String("/ConferenceChannel");
131
chanPath = mConferenceChanPath.toAscii();
132
mConferenceChanService = TP_TESTS_CONFERENCE_CHANNEL(g_object_new(
133
TP_TESTS_TYPE_CONFERENCE_CHANNEL,
134
"connection", mConn->service(),
135
"object-path", chanPath.data(),
136
"initial-channels", initialChannels,
139
g_ptr_array_foreach(initialChannels, (GFunc) g_free, NULL);
140
g_ptr_array_free(initialChannels, TRUE);
143
void TestConferenceChan::init()
148
void TestConferenceChan::testConference()
150
mChan = Channel::create(mConn->client(), mConferenceChanPath, QVariantMap());
151
QCOMPARE(mChan->isConference(), false);
152
QVERIFY(mChan->conferenceInitialInviteeContacts().isEmpty());
153
QVERIFY(mChan->conferenceChannels().isEmpty());
154
QVERIFY(mChan->conferenceInitialChannels().isEmpty());
155
QVERIFY(mChan->conferenceOriginalChannels().isEmpty());
156
QCOMPARE(mChan->supportsConferenceMerging(), false);
157
QCOMPARE(mChan->supportsConferenceSplitting(), false);
159
QVERIFY(connect(mChan->becomeReady(),
160
SIGNAL(finished(Tp::PendingOperation*)),
161
SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
162
QCOMPARE(mLoop->exec(), 0);
163
QCOMPARE(mChan->isReady(), true);
165
QStringList expectedObjectPaths;
166
expectedObjectPaths << mTextChan1Path << mTextChan2Path;
168
QStringList objectPaths;
169
Q_FOREACH (const ChannelPtr &channel, mChan->conferenceInitialChannels()) {
170
objectPaths << channel->objectPath();
172
QCOMPARE(expectedObjectPaths, objectPaths);
175
Q_FOREACH (const ChannelPtr &channel, mChan->conferenceChannels()) {
176
objectPaths << channel->objectPath();
178
QCOMPARE(expectedObjectPaths, objectPaths);
181
// TODO - Properly check for initial invitee contacts if/when a test CM supports it
182
QVERIFY(!mChan->isReady(Channel::FeatureConferenceInitialInviteeContacts));
183
QCOMPARE(mChan->conferenceInitialInviteeContacts(), Contacts());
185
QVERIFY(connect(mChan->becomeReady(Channel::FeatureConferenceInitialInviteeContacts),
186
SIGNAL(finished(Tp::PendingOperation*)),
187
SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
188
QCOMPARE(mLoop->exec(), 0);
189
QCOMPARE(mChan->isReady(Channel::FeatureConferenceInitialInviteeContacts), true);
191
QCOMPARE(mChan->conferenceInitialInviteeContacts(), Contacts());
194
QCOMPARE(mChan->supportsConferenceMerging(), true);
195
QCOMPARE(mChan->supportsConferenceSplitting(), false);
196
QVERIFY(connect(mChan->conferenceSplitChannel(),
197
SIGNAL(finished(Tp::PendingOperation*)),
198
SLOT(expectFailure(Tp::PendingOperation*))));
199
QCOMPARE(mLoop->exec(), 0);
200
QCOMPARE(mLastError, TP_QT_ERROR_NOT_IMPLEMENTED);
201
QVERIFY(!mLastErrorMessage.isEmpty());
203
ChannelPtr otherChannel = Channel::create(mConn->client(), mTextChan3Path, QVariantMap());
205
QVERIFY(connect(mChan.data(),
206
SIGNAL(conferenceChannelMerged(const Tp::ChannelPtr &)),
207
SLOT(onConferenceChannelMerged(const Tp::ChannelPtr &))));
208
QVERIFY(connect(mChan->conferenceMergeChannel(otherChannel),
209
SIGNAL(finished(Tp::PendingOperation*)),
210
SLOT(expectSuccessfulCall(Tp::PendingOperation*))));
211
QCOMPARE(mLoop->exec(), 0);
212
QCOMPARE(mChan->isReady(), true);
213
while (!mChannelMerged) {
214
QCOMPARE(mLoop->exec(), 0);
217
QCOMPARE(mChannelMerged->objectPath(), otherChannel->objectPath());
219
expectedObjectPaths << mTextChan3Path;
221
Q_FOREACH (const ChannelPtr &channel, mChan->conferenceChannels()) {
222
objectPaths << channel->objectPath();
224
QCOMPARE(expectedObjectPaths, objectPaths);
226
QVERIFY(connect(mChan.data(),
227
SIGNAL(conferenceChannelRemoved(const Tp::ChannelPtr &,
228
const Tp::Channel::GroupMemberChangeDetails &)),
229
SLOT(onConferenceChannelRemoved(const Tp::ChannelPtr &,
230
const Tp::Channel::GroupMemberChangeDetails &))));
231
tp_tests_conference_channel_remove_channel (mConferenceChanService,
232
mChannelMerged->objectPath().toAscii().data());
233
while (!mChannelRemovedDetailed) {
234
QCOMPARE(mLoop->exec(), 0);
236
QCOMPARE(mChannelRemovedDetailed, mChannelMerged);
237
QCOMPARE(mChannelRemovedDetailedDetails.allDetails().isEmpty(), false);
238
QCOMPARE(qdbus_cast<int>(mChannelRemovedDetailedDetails.allDetails().value(
239
QLatin1String("domain-specific-detail-uint"))), 3);
240
QCOMPARE(mChannelRemovedDetailedDetails.hasActor(), true);
241
QCOMPARE(mChannelRemovedDetailedDetails.actor(), mChan->groupSelfContact());
243
expectedObjectPaths.clear();
244
expectedObjectPaths << mTextChan1Path << mTextChan2Path;
246
Q_FOREACH (const ChannelPtr &channel, mChan->conferenceChannels()) {
247
objectPaths << channel->objectPath();
249
QCOMPARE(expectedObjectPaths, objectPaths);
252
mChannelMerged.reset();
255
void TestConferenceChan::cleanup()
260
void TestConferenceChan::cleanupTestCase()
262
QCOMPARE(mConn->disconnect(), true);
265
if (mTextChan1Service != 0) {
266
g_object_unref(mTextChan1Service);
267
mTextChan1Service = 0;
270
if (mTextChan2Service != 0) {
271
g_object_unref(mTextChan2Service);
272
mTextChan2Service = 0;
275
if (mConferenceChanService != 0) {
276
g_object_unref(mConferenceChanService);
277
mConferenceChanService = 0;
280
cleanupTestCaseImpl();
283
QTEST_MAIN(TestConferenceChan)
284
#include "_gen/chan-conference.cpp.moc.hpp"