diff options
author | Andreas Volz <andreas@er00923n.fritz.box> | 2011-11-18 18:07:06 +0100 |
---|---|---|
committer | Andreas Volz <andreas@er00923n.fritz.box> | 2011-11-18 18:07:06 +0100 |
commit | 84978b67b5d9b0ebfdc729cf9cd475ca1b19983b (patch) | |
tree | d59186d5eeaa6ee301bb3f61add75fcb52dd453e | |
parent | 9be39fb628a5ecdfb118a95018c8b205395bfe18 (diff) | |
download | dbus-c++-84978b67b5d9b0ebfdc729cf9cd475ca1b19983b.tar.gz |
a test for byte
-rw-r--r-- | test/functional/Test1/TestApp.cpp | 55 | ||||
-rw-r--r-- | test/functional/Test1/TestApp.h | 7 | ||||
-rw-r--r-- | test/functional/Test1/TestAppIntro.h | 13 | ||||
-rw-r--r-- | test/functional/Test1/TestAppIntro.xml | 10 | ||||
-rw-r--r-- | test/functional/Test1/TestAppIntroProvider.h | 12 |
5 files changed, 71 insertions, 26 deletions
diff --git a/test/functional/Test1/TestApp.cpp b/test/functional/Test1/TestApp.cpp index 76e3cd3..69cb3c6 100644 --- a/test/functional/Test1/TestApp.cpp +++ b/test/functional/Test1/TestApp.cpp @@ -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); + } } diff --git a/test/functional/Test1/TestApp.h b/test/functional/Test1/TestApp.h index bb14db1..2321b8e 100644 --- a/test/functional/Test1/TestApp.h +++ b/test/functional/Test1/TestApp.h @@ -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 diff --git a/test/functional/Test1/TestAppIntro.h b/test/functional/Test1/TestAppIntro.h index 6945fdf..de6aa0b 100644 --- a/test/functional/Test1/TestAppIntro.h +++ b/test/functional/Test1/TestAppIntro.h @@ -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); } diff --git a/test/functional/Test1/TestAppIntro.xml b/test/functional/Test1/TestAppIntro.xml index de8d9ab..506f021 100644 --- a/test/functional/Test1/TestAppIntro.xml +++ b/test/functional/Test1/TestAppIntro.xml @@ -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> diff --git a/test/functional/Test1/TestAppIntroProvider.h b/test/functional/Test1/TestAppIntroProvider.h index 28a09a8..45b966b 100644 --- a/test/functional/Test1/TestAppIntroProvider.h +++ b/test/functional/Test1/TestAppIntroProvider.h @@ -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; }; |