adding an autotest and "dbus-ify" the build process and include scheme
authorHarald Fernengel <harry@kdevelop.org>
Fri, 23 Sep 2005 16:24:36 +0000 (16:24 +0000)
committerHarald Fernengel <harry@kdevelop.org>
Fri, 23 Sep 2005 16:24:36 +0000 (16:24 +0000)
15 files changed:
configure.in
dbus/Makefile.am
dbus/qdbus.h [moved from qt/qdbusmacros.h with 74% similarity]
qt/Makefile.am
qt/qdbus.h [deleted file]
qt/qdbusconnection.cpp
qt/qdbusconnection.h
qt/qdbusconnection_p.h
qt/qdbuserror.h
qt/qdbusmessage.h
qt/qdbusserver.h
qt/qdbusvariant.h
test/Makefile.am
test/qt/Makefile.am [new file with mode: 0644]
test/qt/tst_qdbusconnection.cpp [new file with mode: 0644]

index 7ffc429..17c8048 100644 (file)
@@ -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
index b6b50d7..7e927f2 100644 (file)
@@ -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
similarity index 74%
rename from qt/qdbusmacros.h
rename to dbus/qdbus.h
index ee88cdf..ef6e808 100644 (file)
@@ -1,4 +1,4 @@
-/* qdbusmessage.h QDBusMessage object
+/* qdbus.h precompiled header
  *
  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
  *
  *
  */
 
-#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
index 71ae352..4d99f9d 100644 (file)
@@ -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 (file)
index 3545421..0000000
+++ /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
index 6493ef2..49acc24 100644 (file)
@@ -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";
index 16ab2b1..eccc7d1 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef QDBUSCONNECTION_H
 #define QDBUSCONNECTION_H
 
-#include "qdbusmacros.h"
+#include "dbus/qdbus.h"
 #include <QtCore/qstring.h>
 
 class QDBusConnectionPrivate;
index 9dcd7d2..3f78dad 100644 (file)
@@ -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;
index d554426..07d2c56 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef QDBUSERROR_H
 #define QDBUSERROR_H
 
-#include "qdbusmacros.h"
+#include "dbus/qdbus.h"
 #include <QtCore/qstring.h>
 
 struct DBusError;
index 5f70182..03a475e 100644 (file)
@@ -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>
 
index 5560786..bc191a2 100644 (file)
@@ -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>
 
index 1a92a60..bd18bef 100644 (file)
@@ -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>
index 5f90488..a43d8f5 100644 (file)
@@ -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 (file)
index 0000000..553accd
--- /dev/null
@@ -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 (file)
index 0000000..50ed0bd
--- /dev/null
@@ -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"
+