2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file dbuscommandinterfacesignalsTest.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
26 #include "dbuscommaninterfacesignalsTest.h"
29 #include <python2.6/Python.h>
30 #include "../include/DBusCommandSender.h"
31 #include "../include/DBusMessageHandler.h"
32 #include "DbusCommandInterfaceBackdoor.h"
33 #include "MockInterfaces.h"
34 #include "DLTWrapper.h"
37 using namespace testing;
40 dbuscommaninterfacesignalsTest::dbuscommaninterfacesignalsTest()
42 DLTWrapper::instance()->registerApp("dbusTest","dbusTest");
43 logInfo("dbusCommandInterfaceSignalTest started");
46 dbuscommaninterfacesignalsTest::~dbuscommaninterfacesignalsTest()
50 void* NumberOfMainConnectionsChanged(void*)
53 DbusCommandSender sender;
54 MockCommandReceiveInterface receiver;
55 DbusCommandInterfaceBackdoor backdoor;
56 backdoor.setReceiveInterface(&sender, &receiver);
58 dbus_error_init(&error);
59 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
60 backdoor.setDbusConnection(&sender, co);
61 sender.cbNumberOfMainConnectionsChanged();
65 void* cbSinkAdded(void*)
68 std::vector<am_SinkType_s> list;
70 mysink.name = "MySink";
72 mysink.availability.availability = A_MAX;
73 mysink.availability.availabilityReason = AR_MIN;
74 mysink.muteState = MS_MIN;
75 mysink.sinkClassID = 3;
77 list.push_back(mysink);
78 DbusCommandSender sender;
79 MockCommandReceiveInterface receiver;
80 EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
81 DbusCommandInterfaceBackdoor backdoor;
82 backdoor.setReceiveInterface(&sender, &receiver);
84 dbus_error_init(&error);
85 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
86 backdoor.setDbusConnection(&sender, co);
87 sender.cbNumberOfSinksChanged();
91 void* cbSourceAdded(void*)
94 std::vector<am_SourceType_s> list;
95 am_SourceType_s myource;
96 myource.name = "MySink";
97 myource.sourceID = 42;
98 myource.availability.availability = A_MAX;
99 myource.availability.availabilityReason = AR_MIN;
100 myource.sourceClassID = 15;
101 list.push_back(myource);
102 DbusCommandSender sender;
103 MockCommandReceiveInterface receiver;
104 DbusCommandInterfaceBackdoor backdoor;
105 backdoor.setReceiveInterface(&sender, &receiver);
107 dbus_error_init(&error);
108 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
109 backdoor.setDbusConnection(&sender, co);
110 EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
111 sender.cbNumberOfSourcesChanged();
115 void* cbSourceRemoved(void*)
118 std::vector<am_SourceType_s> list;
119 am_SourceType_s myource;
120 myource.name = "MySink";
121 myource.sourceID = 42;
122 myource.availability.availability = A_MAX;
123 myource.availability.availabilityReason = AR_MIN;
124 myource.sourceClassID = 15;
125 list.push_back(myource);
126 DbusCommandSender sender;
127 MockCommandReceiveInterface receiver;
128 DbusCommandInterfaceBackdoor backdoor;
129 backdoor.setReceiveInterface(&sender, &receiver);
130 backdoor.setListSources(&sender, list);
132 dbus_error_init(&error);
134 EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
135 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
136 backdoor.setDbusConnection(&sender, co);
137 sender.cbNumberOfSourcesChanged();
141 void* cbSinkRemoved(void*)
144 std::vector<am_SinkType_s> list;
145 am_SinkType_s mysink;
146 mysink.name = "MySink";
148 mysink.availability.availability = A_MAX;
149 mysink.availability.availabilityReason = AR_MIN;
150 mysink.muteState = MS_MIN;
151 mysink.sinkClassID = 3;
153 list.push_back(mysink);
154 DbusCommandSender sender;
155 MockCommandReceiveInterface receiver;
156 DbusCommandInterfaceBackdoor backdoor;
157 backdoor.setReceiveInterface(&sender, &receiver);
158 backdoor.setListSinks(&sender, list);
160 dbus_error_init(&error);
162 EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
163 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
164 backdoor.setDbusConnection(&sender, co);
165 sender.cbNumberOfSinksChanged();
169 void* NumberOfSinkClassesChanged(void*)
172 DbusCommandSender sender;
173 MockCommandReceiveInterface receiver;
174 DbusCommandInterfaceBackdoor backdoor;
175 backdoor.setReceiveInterface(&sender, &receiver);
177 dbus_error_init(&error);
178 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
179 backdoor.setDbusConnection(&sender, co);
180 sender.cbNumberOfSinkClassesChanged();
184 void* NumberOfSourceClassesChanged(void*)
187 DbusCommandSender sender;
188 MockCommandReceiveInterface receiver;
189 DbusCommandInterfaceBackdoor backdoor;
190 backdoor.setReceiveInterface(&sender, &receiver);
192 dbus_error_init(&error);
193 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
194 backdoor.setDbusConnection(&sender, co);
195 sender.cbNumberOfSourceClassesChanged();
199 void* MainConnectionStateChanged(void*)
202 DbusCommandSender sender;
203 MockCommandReceiveInterface receiver;
204 DbusCommandInterfaceBackdoor backdoor;
205 backdoor.setReceiveInterface(&sender, &receiver);
207 dbus_error_init(&error);
208 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
209 backdoor.setDbusConnection(&sender, co);
210 am_connectionID_t id = 4;
211 am_ConnectionState_e state = CS_CONNECTING;
212 sender.cbMainConnectionStateChanged(id, state);
216 void* MainSinkSoundPropertyChanged(void*)
219 DbusCommandSender sender;
220 MockCommandReceiveInterface receiver;
221 DbusCommandInterfaceBackdoor backdoor;
222 backdoor.setReceiveInterface(&sender, &receiver);
224 dbus_error_init(&error);
225 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
226 backdoor.setDbusConnection(&sender, co);
227 am_sinkID_t sinkID = 3;
228 am_MainSoundProperty_s soundProperty;
229 soundProperty.type = MSP_TEST;
230 soundProperty.value = 23;
231 sender.cbMainSinkSoundPropertyChanged(sinkID, soundProperty);
235 void* MainSourceSoundPropertyChanged(void*)
238 DbusCommandSender sender;
239 MockCommandReceiveInterface receiver;
240 DbusCommandInterfaceBackdoor backdoor;
241 backdoor.setReceiveInterface(&sender, &receiver);
243 dbus_error_init(&error);
244 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
245 backdoor.setDbusConnection(&sender, co);
246 am_sourceID_t sourceID = 35;
247 am_MainSoundProperty_s soundProperty;
248 soundProperty.type = MSP_TEST;
249 soundProperty.value = 233;
250 sender.cbMainSourceSoundPropertyChanged(sourceID, soundProperty);
254 void* cbSinkAvailabilityChangedLoop(void*)
257 DbusCommandSender sender;
258 MockCommandReceiveInterface receiver;
259 DbusCommandInterfaceBackdoor backdoor;
260 backdoor.setReceiveInterface(&sender, &receiver);
262 dbus_error_init(&error);
263 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
264 backdoor.setDbusConnection(&sender, co);
265 am_Availability_s av;
266 av.availability = A_AVAILABLE;
267 av.availabilityReason = AR_UNKNOWN;
268 sender.cbSinkAvailabilityChanged(4, av);
272 void* VolumeChanged(void*)
275 DbusCommandSender sender;
276 MockCommandReceiveInterface receiver;
277 DbusCommandInterfaceBackdoor backdoor;
278 backdoor.setReceiveInterface(&sender, &receiver);
280 dbus_error_init(&error);
281 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
282 backdoor.setDbusConnection(&sender, co);
283 am_volume_t volume = 344;
284 sender.cbVolumeChanged(23, volume);
288 void* cbSourceAvailabilityChangedLoop(void*)
291 DbusCommandSender sender;
292 MockCommandReceiveInterface receiver;
293 DbusCommandInterfaceBackdoor backdoor;
294 backdoor.setReceiveInterface(&sender, &receiver);
296 dbus_error_init(&error);
297 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
298 backdoor.setDbusConnection(&sender, co);
299 am_Availability_s av;
300 av.availability = A_AVAILABLE;
301 av.availabilityReason = AR_UNKNOWN;
302 sender.cbSourceAvailabilityChanged(2, av);
306 void* SinkMuteStateChanged(void*)
309 DbusCommandSender sender;
310 MockCommandReceiveInterface receiver;
311 DbusCommandInterfaceBackdoor backdoor;
312 backdoor.setReceiveInterface(&sender, &receiver);
314 dbus_error_init(&error);
315 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
316 backdoor.setDbusConnection(&sender, co);
317 sender.cbSinkMuteStateChanged(42, MS_MUTED);
321 void* SystemPropertyChanged(void*)
324 DbusCommandSender sender;
325 MockCommandReceiveInterface receiver;
326 DbusCommandInterfaceBackdoor backdoor;
327 backdoor.setReceiveInterface(&sender, &receiver);
329 dbus_error_init(&error);
330 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
331 backdoor.setDbusConnection(&sender, co);
332 am_SystemProperty_s property;
333 property.type = SYP_TEST;
334 property.value = 355;
335 sender.cbSystemPropertyChanged(property);
339 void* TimingInformationChanged(void*)
342 DbusCommandSender sender;
343 MockCommandReceiveInterface receiver;
344 DbusCommandInterfaceBackdoor backdoor;
345 backdoor.setReceiveInterface(&sender, &receiver);
347 dbus_error_init(&error);
348 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
349 backdoor.setDbusConnection(&sender, co);
350 sender.cbTimingInformationChanged(42, 233);
354 TEST_F(dbuscommaninterfacesignalsTest,cbSourceAvailabilityChanged)
357 //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)
358 //so it is running in the main context and the signals are send from threads...
359 pthread_t pythonloop;
360 pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) NULL);
361 PyRun_SimpleStringFlags("import sys\n"
365 "import dbus.mainloop.glib\n"
366 "loop = gobject.MainLoop()\n"
367 "def catchsignal(*arg, **kwarg):\n"
368 " print ('Caught NumberOfMainConnectionsChanged') \n"
370 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
371 "bus = dbus.SessionBus()\n"
372 "bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
373 "loop.run()\n", NULL);
374 pthread_join(pythonloop, NULL);
376 pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) NULL);
377 PyRun_SimpleStringFlags("import sys\n"
381 "import dbus.mainloop.glib\n"
382 "loop = gobject.MainLoop()\n"
383 "def catchSinkAdded(*arg, **karg):\n"
384 " print ('Caught signal (in SinkAdded handler) ') \n"
386 " f = open('/tmp/result.txt','w')\n"
387 " f.write(str(arg[0]));\n"
390 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
391 "bus = dbus.SessionBus()\n"
392 "bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
393 "loop.run()\n", NULL);
394 pthread_join(pythonloop, NULL);
396 std::ifstream ifs("/tmp/result.txt");
398 int lineCounter = 0, result = 0;
399 while (std::getline(ifs, line))
401 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);
405 pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) NULL);
406 PyRun_SimpleStringFlags("import sys\n"
410 "import dbus.mainloop.glib\n"
411 "loop = gobject.MainLoop()\n"
412 "def catchSinkRemoved(*arg, **karg):\n"
413 " print ('Caught signal (in SinkRemoved handler) ') \n"
415 " f = open('/tmp/result.txt','w')\n"
416 " f.write(str(arg[0]));\n"
419 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
420 "bus = dbus.SessionBus()\n"
421 "bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
422 "loop.run()\n", NULL);
423 pthread_join(pythonloop, NULL);
425 ifs.open("/tmp/result.txt");
428 while (std::getline(ifs, line))
430 std::stringstream(line) >> result;
431 ASSERT_EQ(result, 23);
435 pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) NULL);
436 PyRun_SimpleStringFlags("import sys\n"
440 "import dbus.mainloop.glib\n"
441 "loop = gobject.MainLoop()\n"
442 "def catchSourceAdded(*arg, **karg):\n"
443 " print ('Caught signal (in SourceAdded handler) ') \n"
445 " f = open('/tmp/result.txt','w')\n"
446 " f.write(str(arg[0]));\n"
449 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
450 "bus = dbus.SessionBus()\n"
451 "bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
452 "loop.run()\n", NULL);
453 pthread_join(pythonloop, NULL);
455 ifs.open("/tmp/result.txt");
458 while (std::getline(ifs, line))
460 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);
464 pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) NULL);
465 PyRun_SimpleStringFlags("import sys\n"
469 "import dbus.mainloop.glib\n"
470 "loop = gobject.MainLoop()\n"
471 "def catchSourceRemoved(*arg, **karg):\n"
472 " print ('Caught signal (in SinkRemoved handler) ') \n"
474 " f = open('/tmp/result.txt','w')\n"
475 " f.write(str(arg[0]));\n"
478 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
479 "bus = dbus.SessionBus()\n"
480 "bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
481 "loop.run()\n", NULL);
482 pthread_join(pythonloop, NULL);
484 ifs.open("/tmp/result.txt");
487 while (std::getline(ifs, line))
489 std::stringstream(line) >> result;
490 ASSERT_EQ(result, 42);
494 pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) NULL);
495 PyRun_SimpleStringFlags("import sys\n"
499 "import dbus.mainloop.glib\n"
500 "loop = gobject.MainLoop()\n"
501 "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
502 " print ('Caught catchNumberOfSinkClassesChanged') \n"
504 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
505 "bus = dbus.SessionBus()\n"
506 "bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
507 "loop.run()\n", NULL);
508 pthread_join(pythonloop, NULL);
510 pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) NULL);
511 PyRun_SimpleStringFlags("import sys\n"
515 "import dbus.mainloop.glib\n"
516 "loop = gobject.MainLoop()\n"
517 "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
518 " print ('Caught CatchNumberOfSourceClassesChanged') \n"
520 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
521 "bus = dbus.SessionBus()\n"
522 "bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
523 "loop.run()\n", NULL);
524 pthread_join(pythonloop, NULL);
526 //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)
527 //so it is running in the main context and the signals are send from threads...
528 pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) NULL);
529 PyRun_SimpleStringFlags("import sys\n"
533 "import dbus.mainloop.glib\n"
534 "loop = gobject.MainLoop()\n"
535 "def catchMainConnectionStateChanged(*arg, **karg):\n"
536 " print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n"
539 " f = open('/tmp/result.txt','w')\n"
540 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
543 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
544 "bus = dbus.SessionBus()\n"
545 "bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
546 "loop.run()\n", NULL);
547 pthread_join(pythonloop, NULL);
549 ifs.open("/tmp/result.txt");
552 while (std::getline(ifs, line))
554 if (lineCounter == 0)
556 std::stringstream(line) >> result;
557 ASSERT_EQ(result, 4);
559 else if (lineCounter == 1)
561 std::stringstream(line) >> result;
562 ASSERT_EQ(result, CS_CONNECTING);
568 //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)
569 //so it is running in the main context and the signals are send from threads...
570 pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) NULL);
571 PyRun_SimpleStringFlags("import sys\n"
575 "import dbus.mainloop.glib\n"
576 "loop = gobject.MainLoop()\n"
577 "def catchMainSinkSoundPropertyChanged(*arg, **karg):\n"
578 " print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n"
581 " f = open('/tmp/result.txt','w')\n"
582 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
585 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
586 "bus = dbus.SessionBus()\n"
587 "bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
588 "loop.run()\n", NULL);
589 pthread_join(pythonloop, NULL);
591 ifs.open("/tmp/result.txt");
594 while (std::getline(ifs, line))
596 if (lineCounter == 0)
598 std::stringstream(line) >> result;
599 ASSERT_EQ(result, 3);
601 else if (lineCounter == 1)
603 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(23)), signature=None)"), 0);
609 //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)
610 //so it is running in the main context and the signals are send from threads...
611 pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) NULL);
612 PyRun_SimpleStringFlags("import sys\n"
616 "import dbus.mainloop.glib\n"
617 "loop = gobject.MainLoop()\n"
618 "def catchMainSourceSoundPropertyChanged(*arg, **karg):\n"
619 " print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n"
622 " f = open('/tmp/result.txt','w')\n"
623 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
626 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
627 "bus = dbus.SessionBus()\n"
628 "bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
629 "loop.run()\n", NULL);
630 pthread_join(pythonloop, NULL);
632 ifs.open("/tmp/result.txt");
635 while (std::getline(ifs, line))
637 if (lineCounter == 0)
639 std::stringstream(line) >> result;
640 ASSERT_EQ(result, 35);
642 else if (lineCounter == 1)
644 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(233)), signature=None)"), 0);
650 //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)
651 //so it is running in the main context and the signals are send from threads...
652 pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) NULL);
653 PyRun_SimpleStringFlags("import sys\n"
657 "import dbus.mainloop.glib\n"
658 "loop = gobject.MainLoop()\n"
659 "def catchSinkAvailabilityChanged(*arg, **karg):\n"
660 " print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n"
663 " f = open('/tmp/result.txt','w')\n"
664 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
667 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
668 "bus = dbus.SessionBus()\n"
669 "bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
670 "loop.run()\n", NULL);
671 pthread_join(pythonloop, NULL);
673 ifs.open("/tmp/result.txt");
676 while (std::getline(ifs, line))
678 if (lineCounter == 0)
680 std::stringstream(line) >> result;
681 ASSERT_EQ(result, 4);
683 else if (lineCounter == 1)
685 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
691 //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)
692 //so it is running in the main context and the signals are send from threads...
693 pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) NULL);
694 PyRun_SimpleStringFlags("import sys\n"
698 "import dbus.mainloop.glib\n"
699 "loop = gobject.MainLoop()\n"
700 "def catchSourceAvailability(*arg, **karg):\n"
701 " print ('Caught signal (in catchSourceAvailability handler) ') \n"
704 " f = open('/tmp/result.txt','w')\n"
705 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
708 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
709 "bus = dbus.SessionBus()\n"
710 "bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
711 "loop.run()\n", NULL);
712 pthread_join(pythonloop, NULL);
714 ifs.open("/tmp/result.txt");
717 while (std::getline(ifs, line))
719 if (lineCounter == 0)
721 std::stringstream(line) >> result;
722 ASSERT_EQ(result, 2);
724 else if (lineCounter == 1)
726 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
732 //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)
733 //so it is running in the main context and the signals are send from threads...
734 pthread_create(&pythonloop, NULL, VolumeChanged, (void*) NULL);
735 PyRun_SimpleStringFlags("import sys\n"
739 "import dbus.mainloop.glib\n"
740 "loop = gobject.MainLoop()\n"
741 "def catchVolumeChanged(*arg, **karg):\n"
742 " print ('Caught signal (in catchVolumeChanged handler) ') \n"
745 " f = open('/tmp/result.txt','w')\n"
746 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
749 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
750 "bus = dbus.SessionBus()\n"
751 "bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
752 "loop.run()\n", NULL);
753 pthread_join(pythonloop, NULL);
755 ifs.open("/tmp/result.txt");
758 while (std::getline(ifs, line))
760 if (lineCounter == 0)
762 std::stringstream(line) >> result;
763 ASSERT_EQ(result, 23);
765 else if (lineCounter == 1)
767 std::stringstream(line) >> result;
768 ASSERT_EQ(result, 344);
774 //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)
775 //so it is running in the main context and the signals are send from threads...
776 pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) NULL);
777 PyRun_SimpleStringFlags("import sys\n"
781 "import dbus.mainloop.glib\n"
782 "loop = gobject.MainLoop()\n"
783 "def catchSinkMuteStateChanged(*arg, **karg):\n"
784 " print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n"
787 " f = open('/tmp/result.txt','w')\n"
788 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
791 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
792 "bus = dbus.SessionBus()\n"
793 "bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
794 "loop.run()\n", NULL);
795 pthread_join(pythonloop, NULL);
797 ifs.open("/tmp/result.txt");
800 while (std::getline(ifs, line))
802 if (lineCounter == 0)
804 std::stringstream(line) >> result;
805 ASSERT_EQ(result, 42);
807 else if (lineCounter == 1)
809 std::stringstream(line) >> result;
810 ASSERT_EQ(result, MS_MUTED);
816 //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)
817 //so it is running in the main context and the signals are send from threads...
818 pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) NULL);
819 PyRun_SimpleStringFlags("import sys\n"
823 "import dbus.mainloop.glib\n"
824 "loop = gobject.MainLoop()\n"
825 "def catchSystemPropertyChanged(*arg, **karg):\n"
826 " print ('Caught signal (in catchSystemPropertyChanged handler) ') \n"
828 " f = open('/tmp/result.txt','w')\n"
829 " f.write(str(arg[0]));\n"
832 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
833 "bus = dbus.SessionBus()\n"
834 "bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
835 "loop.run()\n", NULL);
836 pthread_join(pythonloop, NULL);
838 ifs.open("/tmp/result.txt");
841 while (std::getline(ifs, line))
843 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
847 //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)
848 //so it is running in the main context and the signals are send from threads...
849 pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) NULL);
850 PyRun_SimpleStringFlags("import sys\n"
854 "import dbus.mainloop.glib\n"
855 "loop = gobject.MainLoop()\n"
856 "def catchTimingInformationChanged(*arg, **karg):\n"
857 " print ('Caught signal (in catchTimingInformationChanged handler) ') \n"
860 " f = open('/tmp/result.txt','w')\n"
861 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
864 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
865 "bus = dbus.SessionBus()\n"
866 "bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
867 "loop.run()\n", NULL);
868 pthread_join(pythonloop, NULL);
870 ifs.open("/tmp/result.txt");
873 while (std::getline(ifs, line))
875 if (lineCounter == 0)
877 std::stringstream(line) >> result;
878 ASSERT_EQ(result, 42);
880 else if (lineCounter == 1)
882 std::stringstream(line) >> result;
883 ASSERT_EQ(result, 233);
891 int main(int argc, char **argv)
893 ::testing::InitGoogleTest(&argc, argv);
894 return RUN_ALL_TESTS();
897 void dbuscommaninterfacesignalsTest::SetUp()
902 void dbuscommaninterfacesignalsTest::TearDown()