diff options
-rw-r--r-- | tests/dbus/dbus-tube-chan.cpp | 86 | ||||
-rw-r--r-- | tests/lib/glib/dbus-tube-chan.c | 57 | ||||
-rw-r--r-- | tests/lib/glib/dbus-tube-chan.h | 9 |
3 files changed, 99 insertions, 53 deletions
diff --git a/tests/dbus/dbus-tube-chan.cpp b/tests/dbus/dbus-tube-chan.cpp index a113b103..3f4295c2 100644 --- a/tests/dbus/dbus-tube-chan.cpp +++ b/tests/dbus/dbus-tube-chan.cpp @@ -135,13 +135,17 @@ void TestDBusTubeChan::onBusNamesChanged(const QHash<ContactPtr, QString> &added for (QHash<ContactPtr, QString>::const_iterator i = added.constBegin(); i != added.constEnd(); ++i) { mCurrentBusNames.insert(i.key(), i.value()); + mGotRemoteConnection = true; } Q_FOREACH (const ContactPtr &contact, removed) { QVERIFY(mCurrentBusNames.contains(contact)); mCurrentBusNames.remove(contact); + mGotConnectionClosed = true; } QCOMPARE(mChan->busNames().size(), mCurrentBusNames.size()); + + mLoop->quit(); } void TestDBusTubeChan::onNewSocketConnection() @@ -390,9 +394,7 @@ void TestDBusTubeChan::testAcceptSuccess() if (contexts[i].addressType == TP_SOCKET_ADDRESS_TYPE_UNIX) { qDebug() << "Connecting to bus" << mChan->address(); - QDBusConnection conn(QLatin1String("tmp")); - - conn = QDBusConnection::connectToPeer(mChan->address(), mChan->serviceName()); + QDBusConnection conn = QDBusConnection::connectToPeer(mChan->address(), mChan->serviceName()); QCOMPARE(conn.isConnected(), true); qDebug() << "Connected to host"; @@ -477,6 +479,7 @@ void TestDBusTubeChan::testOfferSuccess() OutgoingDBusTubeChannelPtr chan = OutgoingDBusTubeChannelPtr::qObjectCast(mChan); QVariantMap offerParameters; offerParameters.insert(QLatin1String("mushroom"), 44); + qDebug() << "About to offer tube"; if (contexts[i].addressType == TP_SOCKET_ADDRESS_TYPE_UNIX) { QVERIFY(connect(chan->offerTube(offerParameters, requiresCredentials), SIGNAL(finished(Tp::PendingOperation *)), @@ -485,7 +488,10 @@ void TestDBusTubeChan::testOfferSuccess() QVERIFY(false); } + qDebug() << "Tube offered"; + while (mChan->state() != TubeChannelStateRemotePending) { + qDebug() << mLoop; mLoop->processEvents(); } @@ -493,80 +499,64 @@ void TestDBusTubeChan::testOfferSuccess() // A client now connects to the tube if (contexts[i].addressType == TP_SOCKET_ADDRESS_TYPE_UNIX) { -// qDebug() << "Connecting to host" << localServer->fullServerName(); -// localSocket = new QLocalSocket(this); -// localSocket->connectToServer(localServer->fullServerName()); + QDBusConnection conn = QDBusConnection::connectToPeer(mChan->address(), mChan->serviceName()); + + QCOMPARE(conn.isConnected(), true); } else { QVERIFY(false); } - QCOMPARE(mGotSocketConnection, false); - QCOMPARE(mLoop->exec(), 0); - QCOMPARE(mGotSocketConnection, true); - - /* simulate CM when peer connects */ - GValue *connParam = 0; - mCredentialByte = 0; - switch (contexts[i].accessControl) { - case TP_SOCKET_ACCESS_CONTROL_LOCALHOST: - connParam = tp_g_value_slice_new_static_string(""); - break; - - case TP_SOCKET_ACCESS_CONTROL_CREDENTIALS: - { -// mCredentialByte = g_random_int_range(0, G_MAXUINT8); -// -// localSocket->write(reinterpret_cast<const char*>(&mCredentialByte), 1); -// connParam = tp_g_value_slice_new_byte(mCredentialByte); - } - break; - - default: - Q_ASSERT(false); - } + qDebug() << "Connected"; TpHandleRepoIface *contactRepo = tp_base_connection_get_handles( TP_BASE_CONNECTION(mConn->service()), TP_HANDLE_TYPE_CONTACT); TpHandle bobHandle = tp_handle_ensure(contactRepo, "bob", NULL, NULL); -// tp_tests_dbus_tube_channel_peer_connected_no_stream(mChanService, -// connParam, bobHandle); - - tp_g_value_slice_free(connParam); + gchar *bobService = g_strdup("org.bob.test"); + tp_tests_dbus_tube_channel_peer_connected_no_stream(mChanService, + bobService, bobHandle); + g_free(bobService); mExpectedHandle = bobHandle; mExpectedId = QLatin1String("bob"); QCOMPARE(mChan->state(), TubeChannelStateRemotePending); + qDebug() << "Waiting for offer finished"; + while (!mOfferFinished) { QCOMPARE(mLoop->exec(), 0); } + qDebug() << "Offer finished"; + QCOMPARE(mChan->state(), TubeChannelStateOpen); QCOMPARE(mChan->parameters().isEmpty(), false); QCOMPARE(mChan->parameters().size(), 1); QCOMPARE(mChan->parameters().contains(QLatin1String("mushroom")), true); QCOMPARE(mChan->parameters().value(QLatin1String("mushroom")), QVariant(44)); - if (!mGotRemoteConnection) { - QCOMPARE(mLoop->exec(), 0); - } + // This section makes sense just in a room environment + if (!contexts[i].withContact) { + if (!mGotRemoteConnection) { + QCOMPARE(mLoop->exec(), 0); + } - QCOMPARE(mGotRemoteConnection, true); + QCOMPARE(mGotRemoteConnection, true); - qDebug() << "Connected to host"; + qDebug() << "Connected to host"; - mGotConnectionClosed = false; -// tp_tests_dbus_tube_channel_last_connection_disconnected(mChanService, -// TP_ERROR_STR_DISCONNECTED); - QCOMPARE(mLoop->exec(), 0); - QCOMPARE(mGotConnectionClosed, true); + mGotConnectionClosed = false; + tp_tests_dbus_tube_channel_peer_disconnected(mChanService, + mExpectedHandle); + QCOMPARE(mLoop->exec(), 0); + QCOMPARE(mGotConnectionClosed, true); - /* let the internal OutgoingDBusTubeChannel::onConnectionClosed slot be called before - * checking the data for that connection */ - mLoop->processEvents(); + /* let the internal OutgoingDBusTubeChannel::onConnectionClosed slot be called before + * checking the data for that connection */ + mLoop->processEvents(); - QCOMPARE(chan->busNames().isEmpty(), true); + QCOMPARE(chan->busNames().isEmpty(), true); + } /* as we run several tests here, let's init/cleanup properly */ cleanup(); diff --git a/tests/lib/glib/dbus-tube-chan.c b/tests/lib/glib/dbus-tube-chan.c index 43b0cacc..17060266 100644 --- a/tests/lib/glib/dbus-tube-chan.c +++ b/tests/lib/glib/dbus-tube-chan.c @@ -312,7 +312,7 @@ tp_tests_dbus_tube_channel_class_init (TpTestsDBusTubeChannelClass *klass) "parameters", "Parameters", "parameters of the tube", TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_PARAMETERS, param_spec); @@ -606,15 +606,14 @@ dbus_tube_offer (TpSvcChannelTypeDBusTube *iface, self->priv->access_control = access_control; -// self->priv->address_type = address_type; -// self->priv->address = tp_g_value_slice_dup (address); -// self->priv->access_control = access_control; + if (!create_dbus_server (self, &error)) + goto fail; g_object_set (self, "parameters", parameters, NULL); change_state (self, TP_TUBE_CHANNEL_STATE_REMOTE_PENDING); - tp_svc_channel_type_stream_tube_return_from_offer (context); + tp_svc_channel_type_dbus_tube_return_from_offer (context, self->priv->dbus_srv_addr); return; fail: @@ -675,6 +674,54 @@ dbus_tube_iface_init (gpointer iface, #undef IMPLEMENT } +/* Called to emulate a peer connecting to an offered tube */ +void +tp_tests_dbus_tube_channel_peer_connected_no_stream (TpTestsDBusTubeChannel *self, + gchar *bus_name, + TpHandle handle) +{ + GHashTable *added; + GArray *removed; + + if (self->priv->state == TP_TUBE_CHANNEL_STATE_REMOTE_PENDING) + change_state (self, TP_TUBE_CHANNEL_STATE_OPEN); + + g_assert (self->priv->state == TP_TUBE_CHANNEL_STATE_OPEN); + + added = g_hash_table_new (g_direct_hash, g_direct_equal); + removed = g_array_new (FALSE, FALSE, sizeof (TpHandle)); + + g_hash_table_insert (added, GUINT_TO_POINTER (handle), bus_name); + + tp_svc_channel_type_dbus_tube_emit_dbus_names_changed (self, added, + removed); + + g_hash_table_destroy (added); + g_array_free (removed, TRUE); +} + +/* Called to emulate a peer connecting to an offered tube */ +void +tp_tests_dbus_tube_channel_peer_disconnected (TpTestsDBusTubeChannel *self, + TpHandle handle) +{ + GHashTable *added; + GArray *removed; + + g_assert (self->priv->state == TP_TUBE_CHANNEL_STATE_OPEN); + + added = g_hash_table_new (g_direct_hash, g_direct_equal); + removed = g_array_new (FALSE, FALSE, sizeof (TpHandle)); + + g_array_append_val (removed, handle); + + tp_svc_channel_type_dbus_tube_emit_dbus_names_changed (self, added, + removed); + + g_hash_table_destroy (added); + g_array_free (removed, TRUE); +} + void tp_tests_dbus_tube_channel_set_close_on_accept ( TpTestsDBusTubeChannel *self, diff --git a/tests/lib/glib/dbus-tube-chan.h b/tests/lib/glib/dbus-tube-chan.h index e0c25e4e..0619dd23 100644 --- a/tests/lib/glib/dbus-tube-chan.h +++ b/tests/lib/glib/dbus-tube-chan.h @@ -65,6 +65,15 @@ void tp_tests_dbus_tube_channel_set_close_on_accept ( TpTestsDBusTubeChannel *self, gboolean close_on_accept); +void tp_tests_dbus_tube_channel_peer_connected_no_stream ( + TpTestsDBusTubeChannel *self, + gchar *bus_name, + TpHandle handle); + +void tp_tests_dbus_tube_channel_peer_disconnected ( + TpTestsDBusTubeChannel *self, + TpHandle handle); + #define TP_TESTS_TYPE_CONTACT_DBUS_TUBE_CHANNEL \ (tp_tests_contact_dbus_tube_channel_get_type ()) #define TP_TESTS_CONTACT_DBUS_TUBE_CHANNEL(obj) \ |