- 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

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