Make QtDBus unit tests compile with runtime dbus-1 too
There's a change in Qt 5.4.0 that makes Qt compile with its own set of D-Bus headers, which means QT_CFLAGS_DBUS may be empty. Thus, we can't compile or link if we're using the actual libdbus-1 API to build the test. This commit makes these unit tests use the same dynamic loading mechanism. Change-Id: I56b2a7320086ef88793f6552cb54ca6224010451 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
1fc4053337
commit
cf4b413fa4
@ -107,6 +107,9 @@ DEFINEFUNC(dbus_bool_t , dbus_connection_add_filter, (DBusConnection
|
||||
void *user_data,
|
||||
DBusFreeFunction free_data_function),
|
||||
(connection, function, user_data, free_data_function), return)
|
||||
DEFINEFUNC(dbus_bool_t , dbus_connection_can_send_type, (DBusConnection *connection,
|
||||
int type),
|
||||
(connection, type), return)
|
||||
DEFINEFUNC(void , dbus_connection_close, (DBusConnection *connection),
|
||||
(connection), return)
|
||||
DEFINEFUNC(DBusDispatchStatus , dbus_connection_dispatch, (DBusConnection *connection),
|
||||
|
@ -5,8 +5,13 @@ DESTDIR = ./
|
||||
|
||||
QT = core-private dbus-private testlib
|
||||
|
||||
LIBS += $$QT_LIBS_DBUS
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
contains(QT_CONFIG, dbus-linked) {
|
||||
DEFINES += QT_LINKED_LIBDBUS
|
||||
LIBS += $$QT_LIBS_DBUS
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
} else {
|
||||
SOURCES += ../../../../../src/dbus/qdbus_symbols.cpp
|
||||
}
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||
|
||||
macx:CONFIG += insignificant_test # QTBUG-37469
|
||||
|
@ -37,7 +37,8 @@
|
||||
#include "common.h"
|
||||
#include <limits>
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
#include <QtDBus/private/qdbusutil_p.h>
|
||||
#include <QtDBus/private/qdbusconnection_p.h>
|
||||
|
||||
#define QT_LINKED_LIBDBUS
|
||||
#include <QtDBus/private/qdbusutil_p.h>
|
||||
@ -1033,23 +1034,31 @@ struct DisconnectRawDBus {
|
||||
{
|
||||
if (!connection)
|
||||
return;
|
||||
dbus_connection_close(connection);
|
||||
dbus_connection_unref(connection);
|
||||
q_dbus_connection_close(connection);
|
||||
q_dbus_connection_unref(connection);
|
||||
}
|
||||
};
|
||||
template <typename T, void (*unref)(T *)> struct GenericUnref
|
||||
struct UnrefDBusMessage
|
||||
{
|
||||
static void cleanup(T *type)
|
||||
static void cleanup(DBusMessage *type)
|
||||
{
|
||||
if (!type) return;
|
||||
unref(type);
|
||||
q_dbus_message_unref(type);
|
||||
}
|
||||
};
|
||||
struct UnrefDBusPendingCall
|
||||
{
|
||||
static void cleanup(DBusPendingCall *type)
|
||||
{
|
||||
if (!type) return;
|
||||
q_dbus_pending_call_unref(type);
|
||||
}
|
||||
};
|
||||
|
||||
// use these scoped types to avoid memory leaks if QVERIFY or QCOMPARE fails
|
||||
typedef QScopedPointer<DBusConnection, DisconnectRawDBus> ScopedDBusConnection;
|
||||
typedef QScopedPointer<DBusMessage, GenericUnref<DBusMessage, dbus_message_unref> > ScopedDBusMessage;
|
||||
typedef QScopedPointer<DBusPendingCall, GenericUnref<DBusPendingCall, dbus_pending_call_unref> > ScopedDBusPendingCall;
|
||||
typedef QScopedPointer<DBusMessage, UnrefDBusMessage> ScopedDBusMessage;
|
||||
typedef QScopedPointer<DBusPendingCall, UnrefDBusPendingCall> ScopedDBusPendingCall;
|
||||
|
||||
template <typename T> struct SetResetValue
|
||||
{
|
||||
@ -1074,12 +1083,12 @@ void tst_QDBusMarshall::receiveUnknownType()
|
||||
// this needs to be implemented in raw
|
||||
// open a new connection to the bus daemon
|
||||
DBusError error;
|
||||
dbus_error_init(&error);
|
||||
ScopedDBusConnection rawcon(dbus_bus_get_private(DBUS_BUS_SESSION, &error));
|
||||
q_dbus_error_init(&error);
|
||||
ScopedDBusConnection rawcon(q_dbus_bus_get_private(DBUS_BUS_SESSION, &error));
|
||||
QVERIFY2(rawcon.data(), error.name);
|
||||
|
||||
// check if this bus supports passing file descriptors
|
||||
if (!dbus_connection_can_send_type(rawcon.data(), DBUS_TYPE_UNIX_FD))
|
||||
if (!q_dbus_connection_can_send_type(rawcon.data(), DBUS_TYPE_UNIX_FD))
|
||||
QSKIP("Your session bus does not allow sending Unix file descriptors");
|
||||
|
||||
// make sure this QDBusConnection won't handle Unix file descriptors
|
||||
@ -1090,18 +1099,20 @@ void tst_QDBusMarshall::receiveUnknownType()
|
||||
// create a call back to us containing a file descriptor
|
||||
QDBusMessageSpy spy;
|
||||
con.registerObject("/spyObject", &spy, QDBusConnection::ExportAllSlots);
|
||||
ScopedDBusMessage msg(dbus_message_new_method_call(con.baseService().toLatin1(), "/spyObject", NULL, "theSlot"));
|
||||
ScopedDBusMessage msg(q_dbus_message_new_method_call(con.baseService().toLatin1(), "/spyObject", NULL, "theSlot"));
|
||||
|
||||
int fd = fileno(stdout);
|
||||
dbus_message_append_args(msg.data(), DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID);
|
||||
DBusMessageIter iter;
|
||||
q_dbus_message_iter_init_append(msg.data(), &iter);
|
||||
q_dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd);
|
||||
|
||||
// try to send to us
|
||||
DBusPendingCall *pending_ptr;
|
||||
dbus_connection_send_with_reply(rawcon.data(), msg.data(), &pending_ptr, 1000);
|
||||
q_dbus_connection_send_with_reply(rawcon.data(), msg.data(), &pending_ptr, 1000);
|
||||
ScopedDBusPendingCall pending(pending_ptr);
|
||||
|
||||
// check that it got sent
|
||||
while (dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
|
||||
while (q_dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
|
||||
;
|
||||
|
||||
// now spin our event loop. We don't catch this call, so let's get the reply
|
||||
@ -1110,7 +1121,7 @@ void tst_QDBusMarshall::receiveUnknownType()
|
||||
loop.exec();
|
||||
|
||||
// now try to receive the reply
|
||||
dbus_pending_call_block(pending.data());
|
||||
q_dbus_pending_call_block(pending.data());
|
||||
|
||||
// check that the spy received what it was supposed to receive
|
||||
QCOMPARE(spy.list.size(), 1);
|
||||
@ -1118,48 +1129,49 @@ void tst_QDBusMarshall::receiveUnknownType()
|
||||
QFETCH(int, receivedTypeId);
|
||||
QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId);
|
||||
|
||||
msg.reset(dbus_pending_call_steal_reply(pending.data()));
|
||||
msg.reset(q_dbus_pending_call_steal_reply(pending.data()));
|
||||
QVERIFY(msg);
|
||||
QCOMPARE(dbus_message_get_type(msg.data()), DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
QCOMPARE(dbus_message_get_signature(msg.data()), DBUS_TYPE_INT32_AS_STRING);
|
||||
QCOMPARE(q_dbus_message_get_type(msg.data()), DBUS_MESSAGE_TYPE_METHOD_RETURN);
|
||||
QCOMPARE(q_dbus_message_get_signature(msg.data()), DBUS_TYPE_INT32_AS_STRING);
|
||||
|
||||
int retval;
|
||||
QVERIFY(dbus_message_get_args(msg.data(), &error, DBUS_TYPE_INT32, &retval, DBUS_TYPE_INVALID));
|
||||
QVERIFY(q_dbus_message_iter_init(msg.data(), &iter));
|
||||
q_dbus_message_iter_get_basic(&iter, &retval);
|
||||
QCOMPARE(retval, 42);
|
||||
} else {
|
||||
// create a signal that we'll emit
|
||||
static const char signalName[] = "signalName";
|
||||
static const char interfaceName[] = "local.interface.name";
|
||||
ScopedDBusMessage msg(dbus_message_new_signal("/", interfaceName, signalName));
|
||||
con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
ScopedDBusMessage msg(q_dbus_message_new_signal("/", interfaceName, signalName));
|
||||
con.connect(q_dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
|
||||
QDBusMessageSpy spy;
|
||||
con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &spy, SLOT(theSlot(QDBusMessage)));
|
||||
con.connect(q_dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &spy, SLOT(theSlot(QDBusMessage)));
|
||||
|
||||
DBusMessageIter iter;
|
||||
dbus_message_iter_init_append(msg.data(), &iter);
|
||||
q_dbus_message_iter_init_append(msg.data(), &iter);
|
||||
int fd = fileno(stdout);
|
||||
|
||||
if (qstrcmp(QTest::currentDataTag(), "type-naked") == 0) {
|
||||
// send naked
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd);
|
||||
q_dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd);
|
||||
} else {
|
||||
DBusMessageIter subiter;
|
||||
if (qstrcmp(QTest::currentDataTag(), "type-variant") == 0)
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
|
||||
q_dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
|
||||
else if (qstrcmp(QTest::currentDataTag(), "type-array") == 0)
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
|
||||
q_dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
|
||||
else if (qstrcmp(QTest::currentDataTag(), "type-struct") == 0)
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, 0, &subiter);
|
||||
dbus_message_iter_append_basic(&subiter, DBUS_TYPE_UNIX_FD, &fd);
|
||||
dbus_message_iter_close_container(&iter, &subiter);
|
||||
q_dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, 0, &subiter);
|
||||
q_dbus_message_iter_append_basic(&subiter, DBUS_TYPE_UNIX_FD, &fd);
|
||||
q_dbus_message_iter_close_container(&iter, &subiter);
|
||||
}
|
||||
|
||||
// send it
|
||||
dbus_connection_send(rawcon.data(), msg.data(), 0);
|
||||
q_dbus_connection_send(rawcon.data(), msg.data(), 0);
|
||||
|
||||
// check that it got sent
|
||||
while (dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
|
||||
while (q_dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
|
||||
;
|
||||
|
||||
// now let's see what happens
|
||||
|
@ -2,6 +2,11 @@ CONFIG += testcase
|
||||
TARGET = tst_qdbustype
|
||||
QT = core-private dbus-private testlib
|
||||
SOURCES += tst_qdbustype.cpp
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
LIBS_PRIVATE += $$QT_LIBS_DBUS
|
||||
contains(QT_CONFIG, dbus-linked) {
|
||||
DEFINES += QT_LINKED_LIBDBUS
|
||||
LIBS += $$QT_LIBS_DBUS
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
} else {
|
||||
SOURCES += ../../../../src/dbus/qdbus_symbols.cpp
|
||||
}
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||
|
@ -35,8 +35,18 @@
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <QtDBus/private/qdbusutil_p.h>
|
||||
#include <QtDBus/private/qdbus_symbols_p.h>
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
DEFINEFUNC(dbus_bool_t, dbus_signature_validate, (const char *signature,
|
||||
DBusError *error),
|
||||
(signature, error), return)
|
||||
DEFINEFUNC(dbus_bool_t, dbus_signature_validate_single, (const char *signature,
|
||||
DBusError *error),
|
||||
(signature, error), return)
|
||||
DEFINEFUNC(dbus_bool_t, dbus_type_is_basic, (int typecode),
|
||||
(typecode), return)
|
||||
DEFINEFUNC(dbus_bool_t, dbus_type_is_fixed, (int typecode),
|
||||
(typecode), return)
|
||||
|
||||
class tst_QDBusType : public QObject
|
||||
{
|
||||
@ -182,7 +192,7 @@ void tst_QDBusType::isValidFixedType()
|
||||
|
||||
int type = data.at(0).unicode();
|
||||
if (isValid)
|
||||
QCOMPARE(bool(dbus_type_is_fixed(type)), result);
|
||||
QCOMPARE(bool(q_dbus_type_is_fixed(type)), result);
|
||||
QCOMPARE(QDBusUtil::isValidFixedType(type), result);
|
||||
}
|
||||
|
||||
@ -204,7 +214,7 @@ void tst_QDBusType::isValidBasicType()
|
||||
|
||||
int type = data.at(0).unicode();
|
||||
if (isValid)
|
||||
QCOMPARE(bool(dbus_type_is_basic(type)), result);
|
||||
QCOMPARE(bool(q_dbus_type_is_basic(type)), result);
|
||||
QCOMPARE(QDBusUtil::isValidBasicType(type), result);
|
||||
}
|
||||
|
||||
@ -220,7 +230,7 @@ void tst_QDBusType::isValidSingleSignature()
|
||||
QFETCH(QString, data);
|
||||
QFETCH(bool, result);
|
||||
|
||||
QCOMPARE(bool(dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(bool(q_dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(QDBusUtil::isValidSingleSignature(data), result);
|
||||
}
|
||||
|
||||
@ -236,11 +246,11 @@ void tst_QDBusType::isValidArray()
|
||||
QFETCH(bool, result);
|
||||
|
||||
data.prepend("a");
|
||||
QCOMPARE(bool(dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(bool(q_dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(QDBusUtil::isValidSingleSignature(data), result);
|
||||
|
||||
data.prepend("a");
|
||||
QCOMPARE(bool(dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(bool(q_dbus_signature_validate_single(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(QDBusUtil::isValidSingleSignature(data), result);
|
||||
}
|
||||
|
||||
@ -256,7 +266,7 @@ void tst_QDBusType::isValidSignature()
|
||||
|
||||
data.append(data);
|
||||
if (data.at(0).unicode())
|
||||
QCOMPARE(bool(dbus_signature_validate(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(bool(q_dbus_signature_validate(data.toLatin1(), 0)), result);
|
||||
QCOMPARE(QDBusUtil::isValidSignature(data), result);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,9 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
// We just need the DBUS_TYPE_* constants, so use our own copy
|
||||
#include "../../../../src/dbus/dbus_minimal_p.h"
|
||||
|
||||
class tst_qdbusxml2cpp : public QObject
|
||||
{
|
||||
|
@ -35,8 +35,11 @@
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <QtDBus/private/qdbusutil_p.h>
|
||||
#include <QtDBus/private/qdbus_symbols_p.h>
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
DEFINEFUNC(dbus_bool_t, dbus_signature_validate, (const char *signature,
|
||||
DBusError *error),
|
||||
(signature, error), return)
|
||||
|
||||
class tst_QDBusType: public QObject
|
||||
{
|
||||
@ -85,9 +88,9 @@ void tst_QDBusType::benchmarkSignature()
|
||||
|
||||
bool result;
|
||||
if (useNative) {
|
||||
dbus_signature_validate(data.toLatin1(), 0);
|
||||
q_dbus_signature_validate(data.toLatin1(), 0);
|
||||
QBENCHMARK {
|
||||
result = dbus_signature_validate(data.toLatin1(), 0);
|
||||
result = q_dbus_signature_validate(data.toLatin1(), 0);
|
||||
}
|
||||
} else {
|
||||
QDBusUtil::isValidSignature(data);
|
||||
|
@ -1,8 +1,13 @@
|
||||
TARGET = tst_bench_qdbustype
|
||||
QT -= gui
|
||||
QT += dbus dbus-private testlib
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
LIBS_PRIVATE += $$QT_LIBS_DBUS
|
||||
QT += core-private dbus-private testlib
|
||||
contains(QT_CONFIG, dbus-linked) {
|
||||
DEFINES += QT_LINKED_LIBDBUS
|
||||
LIBS += $$QT_LIBS_DBUS
|
||||
QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
|
||||
} else {
|
||||
SOURCES += ../../../../src/dbus/qdbus_symbols.cpp
|
||||
}
|
||||
|
||||
SOURCES += main.cpp
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||
|
Loading…
Reference in New Issue
Block a user