a test for byte

This commit is contained in:
Andreas Volz 2011-11-18 18:07:06 +01:00
parent 9be39fb628
commit 84978b67b5
5 changed files with 71 additions and 26 deletions

View file

@ -15,12 +15,16 @@ DBus::BusDispatcher dispatcher;
TestAppIntro *g_testComIntro;
DBus::Pipe *mTestToDBusPipe;
bool testResult = false;
std::list <std::string> testList;
pthread_mutex_t clientMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t clientCondition = PTHREAD_COND_INITIALIZER;
TestApp::TestApp ()
{
{
testList.push_back ("test1");
testList.push_back ("testByte");
cout << "initialize DBus..." << endl;
initDBus ();
}
@ -55,25 +59,29 @@ void TestApp::initDBus ()
}
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)
{
for (std::list <std::string>::const_iterator tl_it = testList.begin ();
tl_it != testList.end ();
++tl_it)
{
cout << "client timeout!" << endl;
testResult = false;
}
pthread_mutex_unlock (&clientMutex);
const string &testString = *tl_it;
cout << "write to pipe" << endl;
mTestToDBusPipe->write (testString.c_str (), testString.length () + 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 ();
@ -87,5 +95,12 @@ void TestApp::testHandler (const void *data, void *buffer, unsigned int nbyte)
cout << "buffer1: " << str << ", size: " << nbyte << endl;
cout << "run it!" << endl;
g_testComIntro->test1 ();
if (string (str) == "test1")
{
g_testComIntro->test1 ();
}
else if (string (str) == "testByte")
{
g_testComIntro->testByte (4);
}
}

View file

@ -2,7 +2,9 @@
#define TEST_APP_H
// STD
#include <string.h>
#include <cstring>
#include <list>
#include <string>
/* DBus-cxx */
#include <dbus-c++/dbus.h>
@ -21,8 +23,7 @@ private:
static void *testThreadRunnerProvider (void *arg);
// variables
pthread_t testThread;
pthread_t testThread;
};
#endif // TEST_APP_H

View file

@ -2,8 +2,12 @@
#define TEST_APP_INTRO_H
#include "TestAppIntroPrivate.h"
#include "../../../tools/generator_utils.h"
#include <iostream>
#include <cstdio>
using namespace std;
class TestAppIntro :
public DBusCpp::Test::Com::Intro_proxy,
@ -19,7 +23,14 @@ public:
void test1Result ()
{
std::cout << "Test1Result" << std::endl;
cout << "Test1Result" << endl;
mTestResult = true;
pthread_cond_signal (&mCondition);
}
void testByteResult (const uint8_t& Byte)
{
printf ("TestByteResult: %d\n", Byte);
mTestResult = true;
pthread_cond_signal (&mCondition);
}

View file

@ -8,6 +8,16 @@
<signal name="test1Result">
</signal>
<method name="testByte">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
<arg type="y" name="Byte" direction="in"/>
</method>
<signal name="testByteResult">
<arg type="y" name="Byte" direction="in"/>
</signal>
</interface>
</node>

View file

@ -2,11 +2,13 @@
#define TEST_APP_INTRO_PROVIDER_H
#include "TestAppIntroProviderPrivate.h"
#include "TestAppIntro.h"
#include "../../../tools/generator_utils.h"
#include <iostream>
using namespace std;
class TestAppIntroProvider :
public DBusCpp::Test::Com::Intro_adaptor,
public DBus::IntrospectableAdaptor,
@ -20,10 +22,16 @@ public:
void test1 ()
{
std::cout << "Test1" << std::endl;
cout << "Test1" << endl;
mTestAppIntro->test1Result ();
}
void testByte (const uint8_t& Byte)
{
printf ("TestByte: %d\n", Byte);
mTestAppIntro->testByteResult (Byte);
}
private:
TestAppIntro *mTestAppIntro;
};