- create stucture for functional test

- implementation of first test
This commit is contained in:
Andreas Volz 2011-11-18 17:30:56 +01:00
parent 2185408cfa
commit 9be39fb628
12 changed files with 269 additions and 13 deletions

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -1,6 +1,7 @@
SUBDIRS = \
generator
generator\
functional
## File created by the gnome-build tools

View file

@ -0,0 +1,6 @@
SUBDIRS = \
Test1
## File created by the gnome-build tools

View file

@ -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

View file

@ -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 ();
}

View file

@ -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

View file

@ -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

View file

@ -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>

View file

@ -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

View file

@ -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;
}