From cd883ae0436e0be1234cd0cde3c2e9a8b994d0e8 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 23 Sep 2005 16:24:36 +0000 Subject: adding an autotest and "dbus-ify" the build process and include scheme --- configure.in | 19 ++++- dbus/Makefile.am | 7 +- dbus/qdbus.h | 42 ++++++++++ qt/Makefile.am | 9 +-- qt/qdbus.h | 31 -------- qt/qdbusconnection.cpp | 2 - qt/qdbusconnection.h | 2 +- qt/qdbusconnection_p.h | 4 +- qt/qdbuserror.h | 2 +- qt/qdbusmacros.h | 34 --------- qt/qdbusmessage.h | 3 +- qt/qdbusserver.h | 2 +- qt/qdbusvariant.h | 2 +- test/Makefile.am | 7 +- test/qt/Makefile.am | 26 +++++++ test/qt/tst_qdbusconnection.cpp | 164 ++++++++++++++++++++++++++++++++++++++++ 16 files changed, 272 insertions(+), 84 deletions(-) create mode 100644 dbus/qdbus.h delete mode 100644 qt/qdbus.h delete mode 100644 qt/qdbusmacros.h create mode 100644 test/qt/Makefile.am create mode 100644 test/qt/tst_qdbusconnection.cpp diff --git a/configure.in b/configure.in index 7ffc429e..17c80482 100644 --- a/configure.in +++ b/configure.in @@ -943,7 +943,7 @@ fi if test x$enable_qt = xno; then have_qt=no; - fi +fi QT_MOC=`$PKG_CONFIG --variable=exec_prefix QtCore` QT_MOC=${QT_MOC}/bin/moc @@ -955,6 +955,22 @@ AC_SUBST(DBUS_QT_CFLAGS) AC_SUBST(DBUS_QT_LIBS) AC_SUBST(QT_MOC) +dnl QTestLib detection +PKG_CHECK_MODULES(DBUS_QTESTLIB, QtTest, have_qtest=yes, have_qtest=no) + +if test x$have_qtest = xno ; then + AC_MSG_WARN([Qt Unit Test library not found]) +fi + +if test x$have_qt = xno; then + have_qtest=no +fi + +AM_CONDITIONAL(HAVE_QTESTLIB, test x$have_qtest = xyes) + +AC_SUBST(DBUS_QTESTLIB_CFLAGS) +AC_SUBST(DBUS_QTESTLIB_LIBS) + ### X11 detection AC_PATH_XTRA @@ -1276,6 +1292,7 @@ tools/Makefile test/Makefile test/glib/Makefile test/python/Makefile +test/qt/Makefile doc/Makefile dbus-1.pc dbus-glib-1.pc diff --git a/dbus/Makefile.am b/dbus/Makefile.am index b6b50d70..7e927f21 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -15,6 +15,10 @@ dbus-glib-error-enum.h: dbus-protocol.h make-dbus-glib-error-enum.sh endif +if HAVE_QT +QT_INCLUDES=qdbus.h +endif + dbusincludedir=$(includedir)/dbus-1.0/dbus dbusarchincludedir=$(libdir)/dbus-1.0/include/dbus @@ -35,7 +39,8 @@ dbusinclude_HEADERS= \ dbus-shared.h \ dbus-threads.h \ dbus-types.h \ - $(GLIB_INCLUDES) + $(GLIB_INCLUDES) \ + $(QT_INCLUDES) dbusarchinclude_HEADERS= \ dbus-arch-deps.h diff --git a/dbus/qdbus.h b/dbus/qdbus.h new file mode 100644 index 00000000..ef6e8084 --- /dev/null +++ b/dbus/qdbus.h @@ -0,0 +1,42 @@ +/* qdbus.h precompiled header + * + * Copyright (C) 2005 Harald Fernengel + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef QDBUS_H +#define QDBUS_H + +#include + +#ifndef DBUS_COMPILATION +# define QDBUS_EXPORT Q_DECL_IMPORT +# include +# include +# include +# include +#else +# define QDBUS_EXPORT Q_DECL_EXPORT +# include +# include +# include +# include +#endif + +#endif diff --git a/qt/Makefile.am b/qt/Makefile.am index 71ae3527..4d99f9d5 100644 --- a/qt/Makefile.am +++ b/qt/Makefile.am @@ -1,5 +1,5 @@ if HAVE_QT -INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) +INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) -DDBUS_COMPILATION dbusincludedir=$(includedir)/dbus-1.0/dbus @@ -7,11 +7,9 @@ lib_LTLIBRARIES=libdbus-qt-1.la dbusinclude_HEADERS= \ qdbuserror.h \ - qdbusmacros.h \ qdbusmessage.h \ qdbusserver.h \ - qdbus.h \ - qdbusmarshall.h \ + qdbusconnection.h \ qdbusvariant.h libdbus_qt_1_la_SOURCES = \ @@ -23,11 +21,10 @@ libdbus_qt_1_la_SOURCES = \ $(top_srcdir)/qt/qdbusserver.cpp \ $(top_srcdir)/qt/qdbusconnection.h \ $(top_srcdir)/qt/qdbuserror.h \ - $(top_srcdir)/qt/qdbusmacros.h \ $(top_srcdir)/qt/qdbusmessage.h \ $(top_srcdir)/qt/qdbusserver.h \ $(top_srcdir)/qt/qdbusconnection_p.h \ - $(top_srcdir)/qt/qdbus.h \ + $(top_srcdir)/dbus/qdbus.h \ $(top_srcdir)/qt/qdbusmarshall.h \ $(top_srcdir)/qt/qdbusmessage_p.h \ $(top_srcdir)/qt/qdbusvariant.h diff --git a/qt/qdbus.h b/qt/qdbus.h deleted file mode 100644 index 35454219..00000000 --- a/qt/qdbus.h +++ /dev/null @@ -1,31 +0,0 @@ -/* qdbus.h precompiled header - * - * Copyright (C) 2005 Harald Fernengel - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef QDBUS_H -#define QDBUS_H - -#include -#include -#include -#include - -#endif diff --git a/qt/qdbusconnection.cpp b/qt/qdbusconnection.cpp index 6493ef2a..49acc247 100644 --- a/qt/qdbusconnection.cpp +++ b/qt/qdbusconnection.cpp @@ -24,8 +24,6 @@ #include #include "qdbusconnection.h" -#include "qdbuserror.h" -#include "qdbusmessage.h" #include "qdbusconnection_p.h" QT_STATIC_CONST_IMPL char *QDBusConnection::default_connection_name = "qt_dbus_default_connection"; diff --git a/qt/qdbusconnection.h b/qt/qdbusconnection.h index 16ab2b1a..eccc7d19 100644 --- a/qt/qdbusconnection.h +++ b/qt/qdbusconnection.h @@ -23,7 +23,7 @@ #ifndef QDBUSCONNECTION_H #define QDBUSCONNECTION_H -#include "qdbusmacros.h" +#include "dbus/qdbus.h" #include class QDBusConnectionPrivate; diff --git a/qt/qdbusconnection_p.h b/qt/qdbusconnection_p.h index 9dcd7d20..3f78dad2 100644 --- a/qt/qdbusconnection_p.h +++ b/qt/qdbusconnection_p.h @@ -35,6 +35,8 @@ #ifndef QDBUSCONNECTION_P_H #define QDBUSCONNECTION_P_H +#include "qdbuserror.h" + #include #include #include @@ -43,8 +45,6 @@ #include -#include "qdbuserror.h" - class QDBusMessage; class QSocketNotifier; class QTimerEvent; diff --git a/qt/qdbuserror.h b/qt/qdbuserror.h index d554426d..07d2c566 100644 --- a/qt/qdbuserror.h +++ b/qt/qdbuserror.h @@ -23,7 +23,7 @@ #ifndef QDBUSERROR_H #define QDBUSERROR_H -#include "qdbusmacros.h" +#include "dbus/qdbus.h" #include struct DBusError; diff --git a/qt/qdbusmacros.h b/qt/qdbusmacros.h deleted file mode 100644 index ee88cdfa..00000000 --- a/qt/qdbusmacros.h +++ /dev/null @@ -1,34 +0,0 @@ -/* qdbusmessage.h QDBusMessage object - * - * Copyright (C) 2005 Harald Fernengel - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef QDBUSMACROS_H -#define QDBUSMACROS_H - -#include - -#ifdef QDBUS_MAKEDLL -# define QDBUS_EXPORT Q_DECL_EXPORT -#else -# define QDBUS_EXPORT Q_DECL_IMPORT -#endif - -#endif diff --git a/qt/qdbusmessage.h b/qt/qdbusmessage.h index 5f70182c..03a475eb 100644 --- a/qt/qdbusmessage.h +++ b/qt/qdbusmessage.h @@ -23,7 +23,8 @@ #ifndef QDBUSMESSAGE_H #define QDBUSMESSAGE_H -#include "qdbusmacros.h" +#include "dbus/qdbus.h" + #include #include diff --git a/qt/qdbusserver.h b/qt/qdbusserver.h index 55607860..bc191a28 100644 --- a/qt/qdbusserver.h +++ b/qt/qdbusserver.h @@ -23,7 +23,7 @@ #ifndef QDBUSSERVER_H #define QDBUSSERVER_H -#include "qdbusmacros.h" +#include "dbus/qdbus.h" #include #include diff --git a/qt/qdbusvariant.h b/qt/qdbusvariant.h index 1a92a600..bd18beff 100644 --- a/qt/qdbusvariant.h +++ b/qt/qdbusvariant.h @@ -23,7 +23,7 @@ #ifndef QDBUSVARIANT_H #define QDBUSVARIANT_H -#include "qdbusmacros.h" +#include "dbus/qdbus.h" #include #include diff --git a/test/Makefile.am b/test/Makefile.am index 5f904887..a43d8f54 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -5,9 +5,12 @@ endif if HAVE_PYTHON PYTHON_SUBDIR=python endif +if HAVE_QTESTLIB + QT_SUBDIR=qt +endif -SUBDIRS=$(GLIB_SUBDIR) $(PYTHON_SUBDIR) -DIST_SUBDIRS=glib python +SUBDIRS=$(GLIB_SUBDIR) $(PYTHON_SUBDIR) $(QT_SUBDIR) +DIST_SUBDIRS=glib python qt INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS) diff --git a/test/qt/Makefile.am b/test/qt/Makefile.am new file mode 100644 index 00000000..553accd4 --- /dev/null +++ b/test/qt/Makefile.am @@ -0,0 +1,26 @@ +INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/qt $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) $(DBUS_QTESTLIB_CFLAGS) -DDBUS_COMPILATION + +if DBUS_BUILD_TESTS +TEST_BINARIES=qdbusconnection +TESTS= +else +TEST_BINARIES= +TESTS= +endif + + +noinst_PROGRAMS= $(TEST_BINARIES) + +qdbusconnection_SOURCES= \ + tst_qdbusconnection.cpp + +$(top_srcdir)/test/qt/tst_qdbusconnection.cpp: tst_qdbusconnection.moc + +TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/libdbus-qt-1.la + +qdbusconnection_LDADD=$(TEST_LIBS) + +CLEANFILES=tst_qdbusconnection.moc + +%.moc: %.cpp + $(QT_MOC) $< > $@ diff --git a/test/qt/tst_qdbusconnection.cpp b/test/qt/tst_qdbusconnection.cpp new file mode 100644 index 00000000..50ed0bde --- /dev/null +++ b/test/qt/tst_qdbusconnection.cpp @@ -0,0 +1,164 @@ +#include +#include + +#include + +#include + +class tst_QDBusConnection: public QObject +{ + Q_OBJECT + +private slots: + void addConnection(); + void connect(); + void send(); + void sendAsync(); + void sendSignal(); +}; + +class QDBusSpy: public QObject +{ + Q_OBJECT +public slots: + void handlePing(const QString &str) { args.clear(); args << str; } + void asyncReply(const QDBusMessage &msg) { args << msg; serial = msg.replySerialNumber(); } + +public: + QList args; + int serial; +}; + +void tst_QDBusConnection::sendSignal() +{ + QDBusConnection con = QDBusConnection::addConnection( + QDBusConnection::SessionBus); + + VERIFY(con.isConnected()); + + QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", + "Ping"); + msg << QLatin1String("ping"); + + VERIFY(con.send(msg)); + + QTest::wait(1000); +} + +void tst_QDBusConnection::send() +{ + QDBusConnection con = QDBusConnection::addConnection( + QDBusConnection::SessionBus); + + VERIFY(con.isConnected()); + + QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", + "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); + + QDBusMessage reply = con.sendWithReply(msg); + + COMPARE(reply.count(), 1); + COMPARE(reply.at(0).typeName(), "QStringList"); + VERIFY(reply.at(0).toStringList().contains(con.baseService())); +} + +void tst_QDBusConnection::sendAsync() +{ + QDBusConnection con = QDBusConnection::addConnection(QDBusConnection::SessionBus); + VERIFY(con.isConnected()); + + QDBusSpy spy; + + QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", + "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); + int msgId = con.sendWithReplyAsync(msg, &spy, SLOT(asyncReply(QDBusMessage))); + VERIFY(msgId != 0); + + QTest::wait(1000); + + COMPARE(spy.args.value(0).typeName(), "QStringList"); + VERIFY(spy.args.at(0).toStringList().contains(con.baseService())); + COMPARE(spy.serial, msgId); +} + +void tst_QDBusConnection::connect() +{ + QDBusSpy spy; + + QDBusConnection con = QDBusConnection::addConnection( + QDBusConnection::SessionBus); + + con.connect("/org/kde/selftest", "org.kde.selftest", "ping", &spy, + SLOT(handlePing(QString))); + + QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", + "ping"); + msg << QLatin1String("ping"); + + VERIFY(con.send(msg)); + + QTest::wait(1000); + + COMPARE(spy.args.count(), 1); + COMPARE(spy.args.at(0).toString(), QString("ping")); +} + +void tst_QDBusConnection::addConnection() +{ + { + QDBusConnection con = QDBusConnection::addConnection( + QDBusConnection::SessionBus, "bubu"); + + VERIFY(con.isConnected()); + VERIFY(!con.lastError().isValid()); + + QDBusConnection con2; + VERIFY(!con2.isConnected()); + VERIFY(!con2.lastError().isValid()); + + con2 = con; + VERIFY(con.isConnected()); + VERIFY(con2.isConnected()); + VERIFY(!con.lastError().isValid()); + VERIFY(!con2.lastError().isValid()); + } + + { + QDBusConnection con("bubu"); + VERIFY(con.isConnected()); + VERIFY(!con.lastError().isValid()); + } + + QDBusConnection::closeConnection("bubu"); + + { + QDBusConnection con("bubu"); + VERIFY(!con.isConnected()); + VERIFY(!con.lastError().isValid()); + } + + { + { + QDBusConnection con = QDBusConnection::addConnection( + QDBusConnection::SessionBus); + VERIFY(con.isConnected()); + } + + { + QDBusConnection con; + VERIFY(con.isConnected()); + QDBusConnection::closeConnection(); + VERIFY(con.isConnected()); + } + + { + QDBusConnection con; + VERIFY(!con.isConnected()); + } + } +} + +QTEST_MAIN(tst_QDBusConnection) + +#include "tst_qdbusconnection.moc" + -- cgit