summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Fernengel <harry@kdevelop.org>2005-09-23 16:24:36 +0000
committerHarald Fernengel <harry@kdevelop.org>2005-09-23 16:24:36 +0000
commitcd883ae0436e0be1234cd0cde3c2e9a8b994d0e8 (patch)
treee911fc2383e9fc4d91cb51774e4037efa439acd2
parentac2de419da28379195da11120ddb0e19f601aa24 (diff)
adding an autotest and "dbus-ify" the build process and include scheme
-rw-r--r--configure.in19
-rw-r--r--dbus/Makefile.am7
-rw-r--r--dbus/qdbus.h (renamed from qt/qdbusmacros.h)20
-rw-r--r--qt/Makefile.am9
-rw-r--r--qt/qdbus.h31
-rw-r--r--qt/qdbusconnection.cpp2
-rw-r--r--qt/qdbusconnection.h2
-rw-r--r--qt/qdbusconnection_p.h4
-rw-r--r--qt/qdbuserror.h2
-rw-r--r--qt/qdbusmessage.h3
-rw-r--r--qt/qdbusserver.h2
-rw-r--r--qt/qdbusvariant.h2
-rw-r--r--test/Makefile.am7
-rw-r--r--test/qt/Makefile.am26
-rw-r--r--test/qt/tst_qdbusconnection.cpp164
15 files changed, 244 insertions, 56 deletions
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/qt/qdbusmacros.h b/dbus/qdbus.h
index ee88cdfa..ef6e8084 100644
--- a/qt/qdbusmacros.h
+++ b/dbus/qdbus.h
@@ -1,4 +1,4 @@
-/* qdbusmessage.h QDBusMessage object
+/* qdbus.h precompiled header
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
*
@@ -20,15 +20,23 @@
*
*/
-#ifndef QDBUSMACROS_H
-#define QDBUSMACROS_H
+#ifndef QDBUS_H
+#define QDBUS_H
#include <QtCore/qglobal.h>
-#ifdef QDBUS_MAKEDLL
-# define QDBUS_EXPORT Q_DECL_EXPORT
-#else
+#ifndef DBUS_COMPILATION
# define QDBUS_EXPORT Q_DECL_IMPORT
+# include <dbus/qdbusconnection.h>
+# include <dbus/qdbuserror.h>
+# include <dbus/qdbusmessage.h>
+# include <dbus/qdbusserver.h>
+#else
+# define QDBUS_EXPORT Q_DECL_EXPORT
+# include <qt/qdbusconnection.h>
+# include <qt/qdbuserror.h>
+# include <qt/qdbusmessage.h>
+# include <qt/qdbusserver.h>
#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 <harry@kdevelop.org>
- *
- * 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 <QtDBUS/qdbusconnection.h>
-#include <QtDBUS/qdbuserror.h>
-#include <QtDBUS/qdbusmessage.h>
-#include <QtDBUS/qdbusserver.h>
-
-#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 <QtCore/qcoreapplication.h>
#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 <QtCore/qstring.h>
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 <QtCore/qatomic.h>
#include <QtCore/qhash.h>
#include <QtCore/qobject.h>
@@ -43,8 +45,6 @@
#include <dbus/dbus.h>
-#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 <QtCore/qstring.h>
struct DBusError;
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 <QtCore/qlist.h>
#include <QtCore/qvariant.h>
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 <QtCore/qobject.h>
#include <QtCore/qstring.h>
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 <QtCore/qmetatype.h>
#include <QtCore/qstring.h>
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 <qcoreapplication.h>
+#include <qdebug.h>
+
+#include <QtTest/QtTest>
+
+#include <qdbus.h>
+
+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<QVariant> 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"
+