summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Volz <andreas@er00923n.fritz.box>2011-11-18 17:30:56 +0100
committerAndreas Volz <andreas@er00923n.fritz.box>2011-11-18 17:30:56 +0100
commit9be39fb628a5ecdfb118a95018c8b205395bfe18 (patch)
tree7f918fa832f218f0018a23060e89dd48194f2393
parent2185408cfa372ff0e14128fabd6d9aa57bf56833 (diff)
downloaddbus-c++-9be39fb628a5ecdfb118a95018c8b205395bfe18.tar.gz
- create stucture for functional test
- implementation of first test
-rw-r--r--configure.ac3
-rw-r--r--examples/echo/echo-client.cpp4
-rw-r--r--examples/echo_ecore/Makefile18
-rw-r--r--test/Makefile.am3
-rw-r--r--test/functional/Makefile.am6
-rw-r--r--test/functional/Test1/Makefile.am40
-rw-r--r--test/functional/Test1/TestApp.cpp91
-rw-r--r--test/functional/Test1/TestApp.h28
-rw-r--r--test/functional/Test1/TestAppIntro.h32
-rw-r--r--test/functional/Test1/TestAppIntro.xml13
-rw-r--r--test/functional/Test1/TestAppIntroProvider.h32
-rw-r--r--test/functional/Test1/TestAppMain.cpp12
12 files changed, 269 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index a92b440..9c1002c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,12 +178,15 @@ AC_SUBST(BUILD_LIBDBUS_CXX_DIR)
# Save processed files
+PKG_CHECK_MODULES(CPPUNIT, cppunit)
AC_OUTPUT(
Makefile
src/Makefile
tools/Makefile
test/Makefile
test/generator/Makefile
+ test/functional/Makefile
+ test/functional/Test1/Makefile
data/Makefile
doc/Makefile
doc/Doxyfile
diff --git a/examples/echo/echo-client.cpp b/examples/echo/echo-client.cpp
index f84c093..10c9a78 100644
--- a/examples/echo/echo-client.cpp
+++ b/examples/echo/echo-client.cpp
@@ -24,10 +24,6 @@ void EchoClient::Echoed(const DBus::Variant &value)
cout << "!";
}
-/*
- * For some strange reason, libdbus frequently dies with an OOM
- */
-
static const size_t THREADS = 3;
static bool spin = true;
diff --git a/examples/echo_ecore/Makefile b/examples/echo_ecore/Makefile
index 33c8ec1..f3920b7 100644
--- a/examples/echo_ecore/Makefile
+++ b/examples/echo_ecore/Makefile
@@ -34,8 +34,8 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = i686-pc-linux-gnu
host_triplet = i686-pc-linux-gnu
-noinst_PROGRAMS = echo-server$(EXEEXT) \
- echo-client-mt$(EXEEXT)
+#noinst_PROGRAMS = echo-server$(EXEEXT) \
+# echo-client-mt$(EXEEXT)
subdir = examples/echo_ecore
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -100,6 +100,8 @@ CCDEPMODE = depmode=gcc3
CFLAGS = -O0 -ggdb
CPP = gcc -E
CPPFLAGS =
+CPPUNIT_CFLAGS =
+CPPUNIT_LIBS = -lcppunit
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=gcc3
@@ -183,13 +185,13 @@ dbus_CFLAGS = -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include
dbus_LIBS = -L/lib -ldbus-1 -lpthread -lrt
docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}
dvidir = ${docdir}
-ecore_CFLAGS = -I/opt/e17/include/ecore-1 -I/opt/e17/include/eina-1 -I/opt/e17/include/eina-1/eina -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/valgrind
-ecore_LIBS = -L/opt/e17/lib -lecore
+ecore_CFLAGS =
+ecore_LIBS =
exec_prefix = ${prefix}
-glib_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-glib_LIBS = -lglib-2.0
-gtkmm_CFLAGS = -pthread -D_REENTRANT -I/usr/include/gtkmm-2.4 -I/usr/lib/gtkmm-2.4/include -I/usr/include/giomm-2.4 -I/usr/lib/giomm-2.4/include -I/usr/include/pangomm-1.4 -I/usr/lib/pangomm-1.4/include -I/usr/include/gtk-2.0 -I/usr/include/gtk-unix-print-2.0 -I/usr/include/atkmm-1.6 -I/usr/include/gdkmm-2.4 -I/usr/lib/gdkmm-2.4/include -I/usr/include/glibmm-2.4 -I/usr/lib/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include -I/usr/include/cairomm-1.0 -I/usr/lib/cairomm-1.0/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/gio-unix-2.0/
-gtkmm_LIBS = -pthread -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-x11-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
+glib_CFLAGS =
+glib_LIBS =
+gtkmm_CFLAGS =
+gtkmm_LIBS =
host = i686-pc-linux-gnu
host_alias =
host_cpu = i686
diff --git a/test/Makefile.am b/test/Makefile.am
index 536fbaf..5fabcfe 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS = \
- generator
+ generator\
+ functional
## File created by the gnome-build tools
diff --git a/test/functional/Makefile.am b/test/functional/Makefile.am
new file mode 100644
index 0000000..c627072
--- /dev/null
+++ b/test/functional/Makefile.am
@@ -0,0 +1,6 @@
+
+SUBDIRS = \
+ Test1
+
+## File created by the gnome-build tools
+
diff --git a/test/functional/Test1/Makefile.am b/test/functional/Test1/Makefile.am
new file mode 100644
index 0000000..f2bb38f
--- /dev/null
+++ b/test/functional/Test1/Makefile.am
@@ -0,0 +1,40 @@
+BUILT_SOURCES = TestAppIntroProviderPrivate.h TestAppIntroPrivate.h
+
+# We don't want to install this header
+noinst_HEADERS = $(BUILT_SOURCES)
+
+# Correctly clean the generated headers, but keep the xml description
+CLEANFILES = $(BUILT_SOURCES)
+
+EXTRA_DIST = TestAppIntro.xml
+
+noinst_PROGRAMS = \
+ TestApp
+
+## Rule to generate the binding headers
+
+TestAppIntroProviderPrivate.h: TestAppIntro.xml
+ $(top_builddir)/tools/dbusxx-xml2cpp $< --adaptor=$@
+
+TestAppIntroPrivate.h: TestAppIntro.xml
+ $(top_builddir)/tools/dbusxx-xml2cpp $< --proxy=$@
+
+TestApp_SOURCES = \
+ TestAppMain.cpp \
+ TestApp.cpp \
+ TestApp.h \
+ TestAppIntroProviderPrivate.h \
+ TestAppIntroPrivate.h \
+ TestAppIntro.h \
+ TestAppIntroProvider.h
+
+TestApp_LDFLAGS = \
+ ../../../src/libdbus-c++-1.la
+
+TestApp_CXXFLAGS = \
+ -I../../../include
+
+AM_CPPFLAGS =
+
+## File created by the gnome-build tools
+
diff --git a/test/functional/Test1/TestApp.cpp b/test/functional/Test1/TestApp.cpp
new file mode 100644
index 0000000..76e3cd3
--- /dev/null
+++ b/test/functional/Test1/TestApp.cpp
@@ -0,0 +1,91 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+// STD
+#include <cstdio>
+
+// local
+#include "TestApp.h"
+#include "TestAppIntro.h"
+
+using namespace std;
+
+DBus::BusDispatcher dispatcher;
+TestAppIntro *g_testComIntro;
+DBus::Pipe *mTestToDBusPipe;
+bool testResult = false;
+
+pthread_mutex_t clientMutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t clientCondition = PTHREAD_COND_INITIALIZER;
+
+TestApp::TestApp ()
+{
+ cout << "initialize DBus..." << endl;
+ initDBus ();
+}
+
+void TestApp::initDBus ()
+{
+ DBus::_init_threading();
+
+ DBus::default_dispatcher = &dispatcher;
+
+ new DBus::DefaultTimeout(100, false, &dispatcher);
+
+ DBus::Connection conn = DBus::Connection::SessionBus();
+
+ TestAppIntro testComIntro (conn, clientCondition, testResult);
+ g_testComIntro = &testComIntro;
+
+ cout << "Start server..." << endl;
+ TestAppIntroProvider testComProviderIntro (conn, &testComIntro);
+ conn.request_name ("DBusCpp.Test.Com.Intro");
+
+ mTestToDBusPipe = dispatcher.add_pipe (TestApp::testHandler, NULL);
+
+ cout << "Start client thread..." << endl;
+ pthread_create (&testThread, NULL, TestApp::testThreadRunner, &conn);
+
+ dispatcher.enter();
+
+ pthread_join (testThread, NULL);
+
+ cout << "Testresult = " << string (testResult ? "OK" : "NOK") << endl;
+}
+
+void *TestApp::testThreadRunner (void *arg)
+{
+ char idstr[16];
+
+ snprintf (idstr, sizeof(idstr), "%lu", pthread_self());
+
+ mTestToDBusPipe->write (idstr, strlen (idstr) + 1);
+
+ struct timespec abstime;
+
+ clock_gettime(CLOCK_REALTIME, &abstime);
+ abstime.tv_sec += 1;
+
+ pthread_mutex_lock (&clientMutex);
+ if (pthread_cond_timedwait (&clientCondition, &clientMutex, &abstime) == ETIMEDOUT)
+ {
+ cout << "client timeout!" << endl;
+ testResult = false;
+ }
+ pthread_mutex_unlock (&clientMutex);
+
+ cout << "leave!" << endl;
+ dispatcher.leave ();
+
+ return NULL;
+}
+
+void TestApp::testHandler (const void *data, void *buffer, unsigned int nbyte)
+{
+ char *str = (char*) buffer;
+ cout << "buffer1: " << str << ", size: " << nbyte << endl;
+
+ cout << "run it!" << endl;
+ g_testComIntro->test1 ();
+}
diff --git a/test/functional/Test1/TestApp.h b/test/functional/Test1/TestApp.h
new file mode 100644
index 0000000..bb14db1
--- /dev/null
+++ b/test/functional/Test1/TestApp.h
@@ -0,0 +1,28 @@
+#ifndef TEST_APP_H
+#define TEST_APP_H
+
+// STD
+#include <string.h>
+
+/* DBus-cxx */
+#include <dbus-c++/dbus.h>
+#include "TestAppIntroProvider.h"
+
+class TestApp
+{
+public:
+ TestApp ();
+
+private:
+ void initDBus ();
+
+ static void testHandler (const void *data, void *buffer, unsigned int nbyte);
+ static void *testThreadRunner (void *arg);
+ static void *testThreadRunnerProvider (void *arg);
+
+ // variables
+
+ pthread_t testThread;
+};
+
+#endif // TEST_APP_H
diff --git a/test/functional/Test1/TestAppIntro.h b/test/functional/Test1/TestAppIntro.h
new file mode 100644
index 0000000..6945fdf
--- /dev/null
+++ b/test/functional/Test1/TestAppIntro.h
@@ -0,0 +1,32 @@
+#ifndef TEST_APP_INTRO_H
+#define TEST_APP_INTRO_H
+
+#include "TestAppIntroPrivate.h"
+
+#include <iostream>
+
+class TestAppIntro :
+ public DBusCpp::Test::Com::Intro_proxy,
+ public DBus::IntrospectableProxy,
+ public DBus::ObjectProxy
+{
+public:
+ TestAppIntro (DBus::Connection& connection, pthread_cond_t &condition, bool &testResult) :
+ DBus::ObjectProxy (connection, "/DBusCpp/Test/Com/Intro", "DBusCpp.Test.Com.Intro"),
+ mCondition (condition),
+ mTestResult (testResult)
+ {}
+
+ void test1Result ()
+ {
+ std::cout << "Test1Result" << std::endl;
+ mTestResult = true;
+ pthread_cond_signal (&mCondition);
+ }
+
+private:
+ pthread_cond_t &mCondition;
+ bool &mTestResult;
+};
+
+#endif // TEST_COM_INTRO_H
diff --git a/test/functional/Test1/TestAppIntro.xml b/test/functional/Test1/TestAppIntro.xml
new file mode 100644
index 0000000..de8d9ab
--- /dev/null
+++ b/test/functional/Test1/TestAppIntro.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" ?>
+<node name="/DBusCpp/Test/Com/Intro">
+ <interface name="DBusCpp.Test.Com.Intro">
+
+ <method name="test1">
+ <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
+ </method>
+
+ <signal name="test1Result">
+ </signal>
+
+ </interface>
+</node>
diff --git a/test/functional/Test1/TestAppIntroProvider.h b/test/functional/Test1/TestAppIntroProvider.h
new file mode 100644
index 0000000..28a09a8
--- /dev/null
+++ b/test/functional/Test1/TestAppIntroProvider.h
@@ -0,0 +1,32 @@
+#ifndef TEST_APP_INTRO_PROVIDER_H
+#define TEST_APP_INTRO_PROVIDER_H
+
+#include "TestAppIntroProviderPrivate.h"
+
+#include "TestAppIntro.h"
+
+#include <iostream>
+
+class TestAppIntroProvider :
+ public DBusCpp::Test::Com::Intro_adaptor,
+ public DBus::IntrospectableAdaptor,
+ public DBus::ObjectAdaptor
+{
+public:
+ TestAppIntroProvider (DBus::Connection& connection, TestAppIntro *testComIntro) :
+ DBus::ObjectAdaptor(connection, "/DBusCpp/Test/Com/Intro"),
+ mTestAppIntro (testComIntro)
+ {}
+
+ void test1 ()
+ {
+ std::cout << "Test1" << std::endl;
+ mTestAppIntro->test1Result ();
+ }
+
+private:
+ TestAppIntro *mTestAppIntro;
+};
+
+#endif // TEST_COM_INTRO_PROVIDER_H
+
diff --git a/test/functional/Test1/TestAppMain.cpp b/test/functional/Test1/TestAppMain.cpp
new file mode 100644
index 0000000..7b8e51d
--- /dev/null
+++ b/test/functional/Test1/TestAppMain.cpp
@@ -0,0 +1,12 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "TestApp.h"
+
+using namespace std;
+
+int main (int argc, char **argv)
+{
+ TestApp testCom;
+}