Commit cd883ae0 authored by Harald Fernengel's avatar Harald Fernengel

adding an autotest and "dbus-ify" the build process and include scheme

parent ac2de419
......@@ -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
......
......@@ -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
......
/* 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
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
......
/* 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
......@@ -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";
......
......@@ -23,7 +23,7 @@
#ifndef QDBUSCONNECTION_H
#define QDBUSCONNECTION_H
#include "qdbusmacros.h"
#include "dbus/qdbus.h"
#include <QtCore/qstring.h>
class QDBusConnectionPrivate;
......
......@@ -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;
......
......@@ -23,7 +23,7 @@
#ifndef QDBUSERROR_H
#define QDBUSERROR_H
#include "qdbusmacros.h"
#include "dbus/qdbus.h"
#include <QtCore/qstring.h>
struct DBusError;
......
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
......@@ -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)
......
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) $< > $@
#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"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment