a test for byte
This commit is contained in:
parent
9be39fb628
commit
84978b67b5
5 changed files with 71 additions and 26 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue