2 * Copyright (c) 2012 BMW
4 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
12 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
13 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 * For further information see http://www.genivi.org/.
18 #include "CAmCommandSenderDbusSignalTest.h"
26 #include "CAmCommandSenderDbusBackdoor.h"
27 #include "MockIAmCommandReceive.h"
28 #include "../include/CAmCommandSenderDbus.h"
29 #include "../include/CAmDbusMessageHandler.h"
30 #include "../../AudioManagerDaemon/include/TAmPluginTemplate.h"
31 #include "shared/CAmDltWrapper.h"
32 #include "configCommandDbus.h"
35 using namespace testing;
37 CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest() :
38 ppCommandSend(NULL) //
40 CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
41 logInfo("dbusCommandInterfaceSignalTest started");
44 CAmCommandSenderDbusSignalTest::~CAmCommandSenderDbusSignalTest()
48 void* NumberOfMainConnectionsChanged(void* ppCommandSend)
51 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
52 am_MainConnectionType_s mainConnection;
53 sender->cbNewMainConnection(mainConnection);
57 void* cbSinkAdded(void* ppCommandSend)
60 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
61 std::vector<am_SinkType_s> list;
63 mysink.name = "MySink";
65 mysink.availability.availability = A_MAX;
66 mysink.availability.availabilityReason = AR_UNKNOWN;
67 mysink.muteState = MS_UNKNOWN;
68 mysink.sinkClassID = 3;
70 sender->cbNewSink(mysink);
74 void* cbSourceAdded(void* ppCommandSend)
77 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
78 am_SourceType_s mysource;
79 mysource.name = "MySink";
80 mysource.sourceID = 42;
81 mysource.availability.availability = A_MAX;
82 mysource.availability.availabilityReason = AR_UNKNOWN;
83 mysource.sourceClassID = 15;
84 sender->cbNewSource(mysource);
88 void* cbSourceRemoved(void* ppCommandSend)
91 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
92 am_SourceType_s mysource;
93 mysource.name = "MySink";
94 mysource.sourceID = 42;
95 sender->cbRemovedSource(mysource.sourceID);
99 void* cbSinkRemoved(void* ppCommandSend)
102 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
103 am_SinkType_s mysink;
104 mysink.name = "MySink";
106 sender->cbRemovedSink(mysink.sinkID);
110 void* NumberOfSinkClassesChanged(void* ppCommandSend)
113 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
114 sender->cbNumberOfSinkClassesChanged();
118 void* NumberOfSourceClassesChanged(void* ppCommandSend)
121 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
122 sender->cbNumberOfSourceClassesChanged();
126 void* MainConnectionStateChanged(void* ppCommandSend)
129 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
130 am_connectionID_t id = 4;
131 am_ConnectionState_e state = CS_CONNECTING;
132 sender->cbMainConnectionStateChanged(id, state);
136 void* MainSinkSoundPropertyChanged(void* ppCommandSend)
139 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
140 am_sinkID_t sinkID = 3;
141 am_MainSoundProperty_s soundProperty;
142 soundProperty.type = MSP_UNKNOWN;
143 soundProperty.value = 23;
144 sender->cbMainSinkSoundPropertyChanged(sinkID, soundProperty);
148 void* MainSourceSoundPropertyChanged(void* ppCommandSend)
151 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
152 am_sourceID_t sourceID = 35;
153 am_MainSoundProperty_s soundProperty;
154 soundProperty.type = MSP_UNKNOWN;
155 soundProperty.value = 233;
156 sender->cbMainSourceSoundPropertyChanged(sourceID, soundProperty);
160 void* cbSinkAvailabilityChangedLoop(void* ppCommandSend)
163 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
164 am_Availability_s av;
165 av.availability = A_AVAILABLE;
166 av.availabilityReason = AR_UNKNOWN;
167 sender->cbSinkAvailabilityChanged(4, av);
171 void* VolumeChanged(void* ppCommandSend)
174 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
175 am_volume_t volume = 344;
176 sender->cbVolumeChanged(23, volume);
180 void* cbSourceAvailabilityChangedLoop(void* ppCommandSend)
183 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
184 am_Availability_s av;
185 av.availability = A_AVAILABLE;
186 av.availabilityReason = AR_UNKNOWN;
187 sender->cbSourceAvailabilityChanged(2, av);
191 void* SinkMuteStateChanged(void* ppCommandSend)
194 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
195 sender->cbSinkMuteStateChanged(42, MS_MUTED);
199 void* SystemPropertyChanged(void* ppCommandSend)
202 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
203 am_SystemProperty_s property;
204 property.type = SYP_UNKNOWN;
205 property.value = 355;
206 sender->cbSystemPropertyChanged(property);
210 void* TimingInformationChanged(void* ppCommandSend)
213 IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
214 sender->cbTimingInformationChanged(42, 233);
218 TEST_F(CAmCommandSenderDbusSignalTest,cbSourceAvailabilityChanged)
221 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
222 //so it is running in the main context and the signals are send from threads...
223 CAmSocketHandler pSocketHandler;
224 CAmDbusWrapper pDBusWrapper(&pSocketHandler);
225 MockIAmCommandReceive pReceiveInterface;
227 IAmCommandSend* (*createFunc)();
228 void* tempLibHandle = NULL;
229 std::string libname(LIBRARY_OUTPUT_PATH);
230 libname.append("/libPluginCommandInterfaceDbus.so");
231 createFunc = getCreateFunction<IAmCommandSend*()>(libname, tempLibHandle);
235 logError("CommandSendInterface Test Entry point of CommandPlugin not found");
239 ppCommandSend = createFunc();
243 logError("CommandSendInterface Test CommandPlugin initialization failed. Entry Function not callable");
247 // ok, here we give the DBusWrapper pointer to the Plugin and start the interface
248 EXPECT_CALL(pReceiveInterface,getDBusConnectionWrapper(_)).WillRepeatedly(DoAll(SetArgReferee<0>(&pDBusWrapper), Return(E_OK)));
249 EXPECT_CALL(pReceiveInterface, confirmCommandReady(10,_));
251 ppCommandSend->startupInterface(&pReceiveInterface);
252 ppCommandSend->setCommandReady(10);
254 pthread_t pythonloop;
255 pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) ppCommandSend);
256 PyRun_SimpleStringFlags("import sys\n"
260 "import dbus.mainloop.glib\n"
261 "print('Started thread') \n"
262 "loop = gobject.MainLoop()\n"
263 "def catchsignal(*arg, **kwarg):\n"
264 " print ('Caught NumberOfMainConnectionsChanged') \n"
266 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
267 "bus = dbus.SessionBus()\n"
268 "bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
269 "print('Started thread') \n"
270 "loop.run()\n", NULL);
271 pthread_join(pythonloop, NULL);
273 pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) ppCommandSend);
274 PyRun_SimpleStringFlags("import sys\n"
278 "import dbus.mainloop.glib\n"
279 "loop = gobject.MainLoop()\n"
280 "def catchSinkAdded(*arg, **karg):\n"
281 " print ('Caught signal (in SinkAdded handler) ') \n"
283 " f = open('/tmp/result.txt','w')\n"
284 " f.write(str(arg[0]));\n"
287 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
288 "bus = dbus.SessionBus()\n"
289 "bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
290 "loop.run()\n", NULL);
291 pthread_join(pythonloop, NULL);
293 std::ifstream ifs("/tmp/result.txt");
295 int lineCounter = 0, result = 0;
296 while (std::getline(ifs, line))
298 ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(23), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.Int16(234), dbus.Int16(0), dbus.UInt16(3)), signature=None)"), 0);
302 pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) ppCommandSend);
303 PyRun_SimpleStringFlags("import sys\n"
307 "import dbus.mainloop.glib\n"
308 "loop = gobject.MainLoop()\n"
309 "def catchSinkRemoved(*arg, **karg):\n"
310 " print ('Caught signal (in SinkRemoved handler) ') \n"
312 " f = open('/tmp/result.txt','w')\n"
313 " f.write(str(arg[0]));\n"
316 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
317 "bus = dbus.SessionBus()\n"
318 "bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
319 "loop.run()\n", NULL);
320 pthread_join(pythonloop, NULL);
322 ifs.open("/tmp/result.txt");
325 while (std::getline(ifs, line))
327 std::stringstream(line) >> result;
328 ASSERT_EQ(result, 23);
332 pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) ppCommandSend);
333 PyRun_SimpleStringFlags("import sys\n"
337 "import dbus.mainloop.glib\n"
338 "loop = gobject.MainLoop()\n"
339 "def catchSourceAdded(*arg, **karg):\n"
340 " print ('Caught signal (in SourceAdded handler) ') \n"
342 " f = open('/tmp/result.txt','w')\n"
343 " f.write(str(arg[0]));\n"
346 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
347 "bus = dbus.SessionBus()\n"
348 "bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
349 "loop.run()\n", NULL);
350 pthread_join(pythonloop, NULL);
352 ifs.open("/tmp/result.txt");
355 while (std::getline(ifs, line))
357 ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(42), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.UInt16(15)), signature=None)"), 0);
361 pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) ppCommandSend);
362 PyRun_SimpleStringFlags("import sys\n"
366 "import dbus.mainloop.glib\n"
367 "loop = gobject.MainLoop()\n"
368 "def catchSourceRemoved(*arg, **karg):\n"
369 " print ('Caught signal (in SinkRemoved handler) ') \n"
371 " f = open('/tmp/result.txt','w')\n"
372 " f.write(str(arg[0]));\n"
375 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
376 "bus = dbus.SessionBus()\n"
377 "bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
378 "loop.run()\n", NULL);
379 pthread_join(pythonloop, NULL);
381 ifs.open("/tmp/result.txt");
384 while (std::getline(ifs, line))
386 std::stringstream(line) >> result;
387 ASSERT_EQ(result, 42);
391 pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) ppCommandSend);
392 PyRun_SimpleStringFlags("import sys\n"
396 "import dbus.mainloop.glib\n"
397 "loop = gobject.MainLoop()\n"
398 "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
399 " print ('Caught catchNumberOfSinkClassesChanged') \n"
401 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
402 "bus = dbus.SessionBus()\n"
403 "bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
404 "loop.run()\n", NULL);
405 pthread_join(pythonloop, NULL);
407 pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) ppCommandSend);
408 PyRun_SimpleStringFlags("import sys\n"
412 "import dbus.mainloop.glib\n"
413 "loop = gobject.MainLoop()\n"
414 "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
415 " print ('Caught CatchNumberOfSourceClassesChanged') \n"
417 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
418 "bus = dbus.SessionBus()\n"
419 "bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
420 "loop.run()\n", NULL);
421 pthread_join(pythonloop, NULL);
423 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
424 //so it is running in the main context and the signals are send from threads...
425 pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) ppCommandSend);
426 PyRun_SimpleStringFlags("import sys\n"
430 "import dbus.mainloop.glib\n"
431 "loop = gobject.MainLoop()\n"
432 "def catchMainConnectionStateChanged(*arg, **karg):\n"
433 " print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n"
436 " f = open('/tmp/result.txt','w')\n"
437 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
440 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
441 "bus = dbus.SessionBus()\n"
442 "bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
443 "loop.run()\n", NULL);
444 pthread_join(pythonloop, NULL);
446 ifs.open("/tmp/result.txt");
449 while (std::getline(ifs, line))
451 if (lineCounter == 0)
453 std::stringstream(line) >> result;
454 ASSERT_EQ(result, 4);
456 else if (lineCounter == 1)
458 std::stringstream(line) >> result;
459 ASSERT_EQ(result, CS_CONNECTING);
465 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
466 //so it is running in the main context and the signals are send from threads...
467 pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) ppCommandSend);
468 PyRun_SimpleStringFlags("import sys\n"
472 "import dbus.mainloop.glib\n"
473 "loop = gobject.MainLoop()\n"
474 "def catchMainSinkSoundPropertyChanged(*arg, **karg):\n"
475 " print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n"
478 " f = open('/tmp/result.txt','w')\n"
479 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
482 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
483 "bus = dbus.SessionBus()\n"
484 "bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
485 "loop.run()\n", NULL);
486 pthread_join(pythonloop, NULL);
488 ifs.open("/tmp/result.txt");
491 while (std::getline(ifs, line))
493 if (lineCounter == 0)
495 std::stringstream(line) >> result;
496 ASSERT_EQ(result, 3);
498 else if (lineCounter == 1)
500 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(23)), signature=None)"), 0);
506 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
507 //so it is running in the main context and the signals are send from threads...
508 pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) ppCommandSend);
509 PyRun_SimpleStringFlags("import sys\n"
513 "import dbus.mainloop.glib\n"
514 "loop = gobject.MainLoop()\n"
515 "def catchMainSourceSoundPropertyChanged(*arg, **karg):\n"
516 " print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n"
519 " f = open('/tmp/result.txt','w')\n"
520 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
523 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
524 "bus = dbus.SessionBus()\n"
525 "bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
526 "loop.run()\n", NULL);
527 pthread_join(pythonloop, NULL);
529 ifs.open("/tmp/result.txt");
532 while (std::getline(ifs, line))
534 if (lineCounter == 0)
536 std::stringstream(line) >> result;
537 ASSERT_EQ(result, 35);
539 else if (lineCounter == 1)
541 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(233)), signature=None)"), 0);
547 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
548 //so it is running in the main context and the signals are send from threads...
549 pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) ppCommandSend);
550 PyRun_SimpleStringFlags("import sys\n"
554 "import dbus.mainloop.glib\n"
555 "loop = gobject.MainLoop()\n"
556 "def catchSinkAvailabilityChanged(*arg, **karg):\n"
557 " print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n"
560 " f = open('/tmp/result.txt','w')\n"
561 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
564 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
565 "bus = dbus.SessionBus()\n"
566 "bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
567 "loop.run()\n", NULL);
568 pthread_join(pythonloop, NULL);
570 ifs.open("/tmp/result.txt");
573 while (std::getline(ifs, line))
575 if (lineCounter == 0)
577 std::stringstream(line) >> result;
578 ASSERT_EQ(result, 4);
580 else if (lineCounter == 1)
582 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0);
588 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
589 //so it is running in the main context and the signals are send from threads...
590 pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) ppCommandSend);
591 PyRun_SimpleStringFlags("import sys\n"
595 "import dbus.mainloop.glib\n"
596 "loop = gobject.MainLoop()\n"
597 "def catchSourceAvailability(*arg, **karg):\n"
598 " print ('Caught signal (in catchSourceAvailability handler) ') \n"
601 " f = open('/tmp/result.txt','w')\n"
602 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
605 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
606 "bus = dbus.SessionBus()\n"
607 "bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
608 "loop.run()\n", NULL);
609 pthread_join(pythonloop, NULL);
611 ifs.open("/tmp/result.txt");
614 while (std::getline(ifs, line))
616 if (lineCounter == 0)
618 std::stringstream(line) >> result;
619 ASSERT_EQ(result, 2);
621 else if (lineCounter == 1)
623 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0);
629 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
630 //so it is running in the main context and the signals are send from threads...
631 pthread_create(&pythonloop, NULL, VolumeChanged, (void*) ppCommandSend);
632 PyRun_SimpleStringFlags("import sys\n"
636 "import dbus.mainloop.glib\n"
637 "loop = gobject.MainLoop()\n"
638 "def catchVolumeChanged(*arg, **karg):\n"
639 " print ('Caught signal (in catchVolumeChanged handler) ') \n"
642 " f = open('/tmp/result.txt','w')\n"
643 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
646 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
647 "bus = dbus.SessionBus()\n"
648 "bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
649 "loop.run()\n", NULL);
650 pthread_join(pythonloop, NULL);
652 ifs.open("/tmp/result.txt");
655 while (std::getline(ifs, line))
657 if (lineCounter == 0)
659 std::stringstream(line) >> result;
660 ASSERT_EQ(result, 23);
662 else if (lineCounter == 1)
664 std::stringstream(line) >> result;
665 ASSERT_EQ(result, 344);
671 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
672 //so it is running in the main context and the signals are send from threads...
673 pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) ppCommandSend);
674 PyRun_SimpleStringFlags("import sys\n"
678 "import dbus.mainloop.glib\n"
679 "loop = gobject.MainLoop()\n"
680 "def catchSinkMuteStateChanged(*arg, **karg):\n"
681 " print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n"
684 " f = open('/tmp/result.txt','w')\n"
685 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
688 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
689 "bus = dbus.SessionBus()\n"
690 "bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
691 "loop.run()\n", NULL);
692 pthread_join(pythonloop, NULL);
694 ifs.open("/tmp/result.txt");
697 while (std::getline(ifs, line))
699 if (lineCounter == 0)
701 std::stringstream(line) >> result;
702 ASSERT_EQ(result, 42);
704 else if (lineCounter == 1)
706 std::stringstream(line) >> result;
707 ASSERT_EQ(result, MS_MUTED);
713 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
714 //so it is running in the main context and the signals are send from threads...
715 pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) ppCommandSend);
716 PyRun_SimpleStringFlags("import sys\n"
720 "import dbus.mainloop.glib\n"
721 "loop = gobject.MainLoop()\n"
722 "def catchSystemPropertyChanged(*arg, **karg):\n"
723 " print ('Caught signal (in catchSystemPropertyChanged handler) ') \n"
725 " f = open('/tmp/result.txt','w')\n"
726 " f.write(str(arg[0]));\n"
729 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
730 "bus = dbus.SessionBus()\n"
731 "bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
732 "loop.run()\n", NULL);
733 pthread_join(pythonloop, NULL);
735 ifs.open("/tmp/result.txt");
738 while (std::getline(ifs, line))
740 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
744 //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended)
745 //so it is running in the main context and the signals are send from threads...
746 pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) ppCommandSend);
747 PyRun_SimpleStringFlags("import sys\n"
751 "import dbus.mainloop.glib\n"
752 "loop = gobject.MainLoop()\n"
753 "def catchTimingInformationChanged(*arg, **karg):\n"
754 " print ('Caught signal (in catchTimingInformationChanged handler) ') \n"
757 " f = open('/tmp/result.txt','w')\n"
758 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
761 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
762 "bus = dbus.SessionBus()\n"
763 "bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager.CommandInterface', message_keyword='dbus_message')\n"
764 "loop.run()\n", NULL);
765 pthread_join(pythonloop, NULL);
767 ifs.open("/tmp/result.txt");
770 while (std::getline(ifs, line))
772 if (lineCounter == 0)
774 std::stringstream(line) >> result;
775 ASSERT_EQ(result, 42);
777 else if (lineCounter == 1)
779 std::stringstream(line) >> result;
780 ASSERT_EQ(result, 233);
788 int main(int argc, char **argv)
790 ::testing::InitGoogleTest(&argc, argv);
791 return RUN_ALL_TESTS();
794 void CAmCommandSenderDbusSignalTest::SetUp()
799 void CAmCommandSenderDbusSignalTest::TearDown()