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"
36 using namespace testing;
38 DLT_IMPORT_CONTEXT(DLT_CONTEXT)
40 dbuscommaninterfacesignalsTest::dbuscommaninterfacesignalsTest()
42 DLT_REGISTER_APP("DPtest", "RoutingInterfacetest");
43 DLT_REGISTER_CONTEXT(DLT_CONTEXT, "Main", "Main Context");
44 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
48 dbuscommaninterfacesignalsTest::~dbuscommaninterfacesignalsTest()
50 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
53 void* NumberOfMainConnectionsChanged(void*)
56 DbusCommandSender sender;
57 MockCommandReceiveInterface receiver;
58 DbusCommandInterfaceBackdoor backdoor;
59 backdoor.setReceiveInterface(&sender, &receiver);
61 dbus_error_init(&error);
62 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
63 backdoor.setDbusConnection(&sender, co);
64 sender.cbNumberOfMainConnectionsChanged();
68 void* cbSinkAdded(void*)
71 std::vector<am_SinkType_s> list;
73 mysink.name = "MySink";
75 mysink.availability.availability = A_MAX;
76 mysink.availability.availabilityReason = AR_MIN;
77 mysink.muteState = MS_MIN;
78 mysink.sinkClassID = 3;
80 list.push_back(mysink);
81 DbusCommandSender sender;
82 MockCommandReceiveInterface receiver;
83 EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
84 DbusCommandInterfaceBackdoor backdoor;
85 backdoor.setReceiveInterface(&sender, &receiver);
87 dbus_error_init(&error);
88 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
89 backdoor.setDbusConnection(&sender, co);
90 sender.cbNumberOfSinksChanged();
94 void* cbSourceAdded(void*)
97 std::vector<am_SourceType_s> list;
98 am_SourceType_s myource;
99 myource.name = "MySink";
100 myource.sourceID = 42;
101 myource.availability.availability = A_MAX;
102 myource.availability.availabilityReason = AR_MIN;
103 myource.sourceClassID = 15;
104 list.push_back(myource);
105 DbusCommandSender sender;
106 MockCommandReceiveInterface receiver;
107 DbusCommandInterfaceBackdoor backdoor;
108 backdoor.setReceiveInterface(&sender, &receiver);
110 dbus_error_init(&error);
111 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
112 backdoor.setDbusConnection(&sender, co);
113 EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
114 sender.cbNumberOfSourcesChanged();
118 void* cbSourceRemoved(void*)
121 std::vector<am_SourceType_s> list;
122 am_SourceType_s myource;
123 myource.name = "MySink";
124 myource.sourceID = 42;
125 myource.availability.availability = A_MAX;
126 myource.availability.availabilityReason = AR_MIN;
127 myource.sourceClassID = 15;
128 list.push_back(myource);
129 DbusCommandSender sender;
130 MockCommandReceiveInterface receiver;
131 DbusCommandInterfaceBackdoor backdoor;
132 backdoor.setReceiveInterface(&sender, &receiver);
133 backdoor.setListSources(&sender, list);
135 dbus_error_init(&error);
137 EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
138 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
139 backdoor.setDbusConnection(&sender, co);
140 sender.cbNumberOfSourcesChanged();
144 void* cbSinkRemoved(void*)
147 std::vector<am_SinkType_s> list;
148 am_SinkType_s mysink;
149 mysink.name = "MySink";
151 mysink.availability.availability = A_MAX;
152 mysink.availability.availabilityReason = AR_MIN;
153 mysink.muteState = MS_MIN;
154 mysink.sinkClassID = 3;
156 list.push_back(mysink);
157 DbusCommandSender sender;
158 MockCommandReceiveInterface receiver;
159 DbusCommandInterfaceBackdoor backdoor;
160 backdoor.setReceiveInterface(&sender, &receiver);
161 backdoor.setListSinks(&sender, list);
163 dbus_error_init(&error);
165 EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK)));
166 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
167 backdoor.setDbusConnection(&sender, co);
168 sender.cbNumberOfSinksChanged();
172 void* NumberOfSinkClassesChanged(void*)
175 DbusCommandSender sender;
176 MockCommandReceiveInterface receiver;
177 DbusCommandInterfaceBackdoor backdoor;
178 backdoor.setReceiveInterface(&sender, &receiver);
180 dbus_error_init(&error);
181 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
182 backdoor.setDbusConnection(&sender, co);
183 sender.cbNumberOfSinkClassesChanged();
187 void* NumberOfSourceClassesChanged(void*)
190 DbusCommandSender sender;
191 MockCommandReceiveInterface receiver;
192 DbusCommandInterfaceBackdoor backdoor;
193 backdoor.setReceiveInterface(&sender, &receiver);
195 dbus_error_init(&error);
196 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
197 backdoor.setDbusConnection(&sender, co);
198 sender.cbNumberOfSourceClassesChanged();
202 void* MainConnectionStateChanged(void*)
205 DbusCommandSender sender;
206 MockCommandReceiveInterface receiver;
207 DbusCommandInterfaceBackdoor backdoor;
208 backdoor.setReceiveInterface(&sender, &receiver);
210 dbus_error_init(&error);
211 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
212 backdoor.setDbusConnection(&sender, co);
213 am_connectionID_t id = 4;
214 am_ConnectionState_e state = CS_CONNECTING;
215 sender.cbMainConnectionStateChanged(id, state);
219 void* MainSinkSoundPropertyChanged(void*)
222 DbusCommandSender sender;
223 MockCommandReceiveInterface receiver;
224 DbusCommandInterfaceBackdoor backdoor;
225 backdoor.setReceiveInterface(&sender, &receiver);
227 dbus_error_init(&error);
228 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
229 backdoor.setDbusConnection(&sender, co);
230 am_sinkID_t sinkID = 3;
231 am_MainSoundProperty_s soundProperty;
232 soundProperty.type = MSP_TEST;
233 soundProperty.value = 23;
234 sender.cbMainSinkSoundPropertyChanged(sinkID, soundProperty);
238 void* MainSourceSoundPropertyChanged(void*)
241 DbusCommandSender sender;
242 MockCommandReceiveInterface receiver;
243 DbusCommandInterfaceBackdoor backdoor;
244 backdoor.setReceiveInterface(&sender, &receiver);
246 dbus_error_init(&error);
247 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
248 backdoor.setDbusConnection(&sender, co);
249 am_sourceID_t sourceID = 35;
250 am_MainSoundProperty_s soundProperty;
251 soundProperty.type = MSP_TEST;
252 soundProperty.value = 233;
253 sender.cbMainSourceSoundPropertyChanged(sourceID, soundProperty);
257 void* cbSinkAvailabilityChangedLoop(void*)
260 DbusCommandSender sender;
261 MockCommandReceiveInterface receiver;
262 DbusCommandInterfaceBackdoor backdoor;
263 backdoor.setReceiveInterface(&sender, &receiver);
265 dbus_error_init(&error);
266 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
267 backdoor.setDbusConnection(&sender, co);
268 am_Availability_s av;
269 av.availability = A_AVAILABLE;
270 av.availabilityReason = AR_UNKNOWN;
271 sender.cbSinkAvailabilityChanged(4, av);
275 void* VolumeChanged(void*)
278 DbusCommandSender sender;
279 MockCommandReceiveInterface receiver;
280 DbusCommandInterfaceBackdoor backdoor;
281 backdoor.setReceiveInterface(&sender, &receiver);
283 dbus_error_init(&error);
284 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
285 backdoor.setDbusConnection(&sender, co);
286 am_volume_t volume = 344;
287 sender.cbVolumeChanged(23, volume);
291 void* cbSourceAvailabilityChangedLoop(void*)
294 DbusCommandSender sender;
295 MockCommandReceiveInterface receiver;
296 DbusCommandInterfaceBackdoor backdoor;
297 backdoor.setReceiveInterface(&sender, &receiver);
299 dbus_error_init(&error);
300 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
301 backdoor.setDbusConnection(&sender, co);
302 am_Availability_s av;
303 av.availability = A_AVAILABLE;
304 av.availabilityReason = AR_UNKNOWN;
305 sender.cbSourceAvailabilityChanged(2, av);
309 void* SinkMuteStateChanged(void*)
312 DbusCommandSender sender;
313 MockCommandReceiveInterface receiver;
314 DbusCommandInterfaceBackdoor backdoor;
315 backdoor.setReceiveInterface(&sender, &receiver);
317 dbus_error_init(&error);
318 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
319 backdoor.setDbusConnection(&sender, co);
320 sender.cbSinkMuteStateChanged(42, MS_MUTED);
324 void* SystemPropertyChanged(void*)
327 DbusCommandSender sender;
328 MockCommandReceiveInterface receiver;
329 DbusCommandInterfaceBackdoor backdoor;
330 backdoor.setReceiveInterface(&sender, &receiver);
332 dbus_error_init(&error);
333 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
334 backdoor.setDbusConnection(&sender, co);
335 am_SystemProperty_s property;
336 property.type = SYP_TEST;
337 property.value = 355;
338 sender.cbSystemPropertyChanged(property);
342 void* TimingInformationChanged(void*)
345 DbusCommandSender sender;
346 MockCommandReceiveInterface receiver;
347 DbusCommandInterfaceBackdoor backdoor;
348 backdoor.setReceiveInterface(&sender, &receiver);
350 dbus_error_init(&error);
351 DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
352 backdoor.setDbusConnection(&sender, co);
353 sender.cbTimingInformationChanged(42, 233);
357 TEST_F(dbuscommaninterfacesignalsTest,cbSourceAvailabilityChanged)
360 //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)
361 //so it is running in the main context and the signals are send from threads...
362 pthread_t pythonloop;
363 pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) NULL);
364 PyRun_SimpleStringFlags("import sys\n"
368 "import dbus.mainloop.glib\n"
369 "loop = gobject.MainLoop()\n"
370 "def catchsignal(*arg, **kwarg):\n"
371 " print ('Caught NumberOfMainConnectionsChanged') \n"
373 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
374 "bus = dbus.SessionBus()\n"
375 "bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
376 "loop.run()\n", NULL);
377 pthread_join(pythonloop, NULL);
379 pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) NULL);
380 PyRun_SimpleStringFlags("import sys\n"
384 "import dbus.mainloop.glib\n"
385 "loop = gobject.MainLoop()\n"
386 "def catchSinkAdded(*arg, **karg):\n"
387 " print ('Caught signal (in SinkAdded handler) ') \n"
389 " f = open('/tmp/result.txt','w')\n"
390 " f.write(str(arg[0]));\n"
393 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
394 "bus = dbus.SessionBus()\n"
395 "bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
396 "loop.run()\n", NULL);
397 pthread_join(pythonloop, NULL);
399 std::ifstream ifs("/tmp/result.txt");
401 int lineCounter = 0, result = 0;
402 while (std::getline(ifs, line))
404 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);
408 pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) NULL);
409 PyRun_SimpleStringFlags("import sys\n"
413 "import dbus.mainloop.glib\n"
414 "loop = gobject.MainLoop()\n"
415 "def catchSinkRemoved(*arg, **karg):\n"
416 " print ('Caught signal (in SinkRemoved handler) ') \n"
418 " f = open('/tmp/result.txt','w')\n"
419 " f.write(str(arg[0]));\n"
422 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
423 "bus = dbus.SessionBus()\n"
424 "bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
425 "loop.run()\n", NULL);
426 pthread_join(pythonloop, NULL);
428 ifs.open("/tmp/result.txt");
431 while (std::getline(ifs, line))
433 std::stringstream(line) >> result;
434 ASSERT_EQ(result, 23);
438 pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) NULL);
439 PyRun_SimpleStringFlags("import sys\n"
443 "import dbus.mainloop.glib\n"
444 "loop = gobject.MainLoop()\n"
445 "def catchSourceAdded(*arg, **karg):\n"
446 " print ('Caught signal (in SourceAdded handler) ') \n"
448 " f = open('/tmp/result.txt','w')\n"
449 " f.write(str(arg[0]));\n"
452 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
453 "bus = dbus.SessionBus()\n"
454 "bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
455 "loop.run()\n", NULL);
456 pthread_join(pythonloop, NULL);
458 ifs.open("/tmp/result.txt");
461 while (std::getline(ifs, line))
463 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);
467 pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) NULL);
468 PyRun_SimpleStringFlags("import sys\n"
472 "import dbus.mainloop.glib\n"
473 "loop = gobject.MainLoop()\n"
474 "def catchSourceRemoved(*arg, **karg):\n"
475 " print ('Caught signal (in SinkRemoved handler) ') \n"
477 " f = open('/tmp/result.txt','w')\n"
478 " f.write(str(arg[0]));\n"
481 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
482 "bus = dbus.SessionBus()\n"
483 "bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
484 "loop.run()\n", NULL);
485 pthread_join(pythonloop, NULL);
487 ifs.open("/tmp/result.txt");
490 while (std::getline(ifs, line))
492 std::stringstream(line) >> result;
493 ASSERT_EQ(result, 42);
497 pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) NULL);
498 PyRun_SimpleStringFlags("import sys\n"
502 "import dbus.mainloop.glib\n"
503 "loop = gobject.MainLoop()\n"
504 "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
505 " print ('Caught catchNumberOfSinkClassesChanged') \n"
507 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
508 "bus = dbus.SessionBus()\n"
509 "bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
510 "loop.run()\n", NULL);
511 pthread_join(pythonloop, NULL);
513 pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) NULL);
514 PyRun_SimpleStringFlags("import sys\n"
518 "import dbus.mainloop.glib\n"
519 "loop = gobject.MainLoop()\n"
520 "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
521 " print ('Caught CatchNumberOfSourceClassesChanged') \n"
523 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
524 "bus = dbus.SessionBus()\n"
525 "bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
526 "loop.run()\n", NULL);
527 pthread_join(pythonloop, NULL);
529 //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)
530 //so it is running in the main context and the signals are send from threads...
531 pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) NULL);
532 PyRun_SimpleStringFlags("import sys\n"
536 "import dbus.mainloop.glib\n"
537 "loop = gobject.MainLoop()\n"
538 "def catchMainConnectionStateChanged(*arg, **karg):\n"
539 " print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n"
542 " f = open('/tmp/result.txt','w')\n"
543 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
546 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
547 "bus = dbus.SessionBus()\n"
548 "bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
549 "loop.run()\n", NULL);
550 pthread_join(pythonloop, NULL);
552 ifs.open("/tmp/result.txt");
555 while (std::getline(ifs, line))
557 if (lineCounter == 0)
559 std::stringstream(line) >> result;
560 ASSERT_EQ(result, 4);
562 else if (lineCounter == 1)
564 std::stringstream(line) >> result;
565 ASSERT_EQ(result, CS_CONNECTING);
571 //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)
572 //so it is running in the main context and the signals are send from threads...
573 pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) NULL);
574 PyRun_SimpleStringFlags("import sys\n"
578 "import dbus.mainloop.glib\n"
579 "loop = gobject.MainLoop()\n"
580 "def catchMainSinkSoundPropertyChanged(*arg, **karg):\n"
581 " print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n"
584 " f = open('/tmp/result.txt','w')\n"
585 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
588 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
589 "bus = dbus.SessionBus()\n"
590 "bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
591 "loop.run()\n", NULL);
592 pthread_join(pythonloop, NULL);
594 ifs.open("/tmp/result.txt");
597 while (std::getline(ifs, line))
599 if (lineCounter == 0)
601 std::stringstream(line) >> result;
602 ASSERT_EQ(result, 3);
604 else if (lineCounter == 1)
606 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(23)), signature=None)"), 0);
612 //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)
613 //so it is running in the main context and the signals are send from threads...
614 pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) NULL);
615 PyRun_SimpleStringFlags("import sys\n"
619 "import dbus.mainloop.glib\n"
620 "loop = gobject.MainLoop()\n"
621 "def catchMainSourceSoundPropertyChanged(*arg, **karg):\n"
622 " print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n"
625 " f = open('/tmp/result.txt','w')\n"
626 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
629 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
630 "bus = dbus.SessionBus()\n"
631 "bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
632 "loop.run()\n", NULL);
633 pthread_join(pythonloop, NULL);
635 ifs.open("/tmp/result.txt");
638 while (std::getline(ifs, line))
640 if (lineCounter == 0)
642 std::stringstream(line) >> result;
643 ASSERT_EQ(result, 35);
645 else if (lineCounter == 1)
647 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(233)), signature=None)"), 0);
653 //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)
654 //so it is running in the main context and the signals are send from threads...
655 pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) NULL);
656 PyRun_SimpleStringFlags("import sys\n"
660 "import dbus.mainloop.glib\n"
661 "loop = gobject.MainLoop()\n"
662 "def catchSinkAvailabilityChanged(*arg, **karg):\n"
663 " print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n"
666 " f = open('/tmp/result.txt','w')\n"
667 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
670 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
671 "bus = dbus.SessionBus()\n"
672 "bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
673 "loop.run()\n", NULL);
674 pthread_join(pythonloop, NULL);
676 ifs.open("/tmp/result.txt");
679 while (std::getline(ifs, line))
681 if (lineCounter == 0)
683 std::stringstream(line) >> result;
684 ASSERT_EQ(result, 4);
686 else if (lineCounter == 1)
688 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
694 //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)
695 //so it is running in the main context and the signals are send from threads...
696 pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) NULL);
697 PyRun_SimpleStringFlags("import sys\n"
701 "import dbus.mainloop.glib\n"
702 "loop = gobject.MainLoop()\n"
703 "def catchSourceAvailability(*arg, **karg):\n"
704 " print ('Caught signal (in catchSourceAvailability handler) ') \n"
707 " f = open('/tmp/result.txt','w')\n"
708 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
711 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
712 "bus = dbus.SessionBus()\n"
713 "bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
714 "loop.run()\n", NULL);
715 pthread_join(pythonloop, NULL);
717 ifs.open("/tmp/result.txt");
720 while (std::getline(ifs, line))
722 if (lineCounter == 0)
724 std::stringstream(line) >> result;
725 ASSERT_EQ(result, 2);
727 else if (lineCounter == 1)
729 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
735 //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)
736 //so it is running in the main context and the signals are send from threads...
737 pthread_create(&pythonloop, NULL, VolumeChanged, (void*) NULL);
738 PyRun_SimpleStringFlags("import sys\n"
742 "import dbus.mainloop.glib\n"
743 "loop = gobject.MainLoop()\n"
744 "def catchVolumeChanged(*arg, **karg):\n"
745 " print ('Caught signal (in catchVolumeChanged handler) ') \n"
748 " f = open('/tmp/result.txt','w')\n"
749 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
752 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
753 "bus = dbus.SessionBus()\n"
754 "bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
755 "loop.run()\n", NULL);
756 pthread_join(pythonloop, NULL);
758 ifs.open("/tmp/result.txt");
761 while (std::getline(ifs, line))
763 if (lineCounter == 0)
765 std::stringstream(line) >> result;
766 ASSERT_EQ(result, 23);
768 else if (lineCounter == 1)
770 std::stringstream(line) >> result;
771 ASSERT_EQ(result, 344);
777 //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)
778 //so it is running in the main context and the signals are send from threads...
779 pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) NULL);
780 PyRun_SimpleStringFlags("import sys\n"
784 "import dbus.mainloop.glib\n"
785 "loop = gobject.MainLoop()\n"
786 "def catchSinkMuteStateChanged(*arg, **karg):\n"
787 " print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n"
790 " f = open('/tmp/result.txt','w')\n"
791 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
794 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
795 "bus = dbus.SessionBus()\n"
796 "bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
797 "loop.run()\n", NULL);
798 pthread_join(pythonloop, NULL);
800 ifs.open("/tmp/result.txt");
803 while (std::getline(ifs, line))
805 if (lineCounter == 0)
807 std::stringstream(line) >> result;
808 ASSERT_EQ(result, 42);
810 else if (lineCounter == 1)
812 std::stringstream(line) >> result;
813 ASSERT_EQ(result, MS_MUTED);
819 //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)
820 //so it is running in the main context and the signals are send from threads...
821 pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) NULL);
822 PyRun_SimpleStringFlags("import sys\n"
826 "import dbus.mainloop.glib\n"
827 "loop = gobject.MainLoop()\n"
828 "def catchSystemPropertyChanged(*arg, **karg):\n"
829 " print ('Caught signal (in catchSystemPropertyChanged handler) ') \n"
831 " f = open('/tmp/result.txt','w')\n"
832 " f.write(str(arg[0]));\n"
835 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
836 "bus = dbus.SessionBus()\n"
837 "bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
838 "loop.run()\n", NULL);
839 pthread_join(pythonloop, NULL);
841 ifs.open("/tmp/result.txt");
844 while (std::getline(ifs, line))
846 ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
850 //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)
851 //so it is running in the main context and the signals are send from threads...
852 pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) NULL);
853 PyRun_SimpleStringFlags("import sys\n"
857 "import dbus.mainloop.glib\n"
858 "loop = gobject.MainLoop()\n"
859 "def catchTimingInformationChanged(*arg, **karg):\n"
860 " print ('Caught signal (in catchTimingInformationChanged handler) ') \n"
863 " f = open('/tmp/result.txt','w')\n"
864 " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
867 "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
868 "bus = dbus.SessionBus()\n"
869 "bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
870 "loop.run()\n", NULL);
871 pthread_join(pythonloop, NULL);
873 ifs.open("/tmp/result.txt");
876 while (std::getline(ifs, line))
878 if (lineCounter == 0)
880 std::stringstream(line) >> result;
881 ASSERT_EQ(result, 42);
883 else if (lineCounter == 1)
885 std::stringstream(line) >> result;
886 ASSERT_EQ(result, 233);
894 int main(int argc, char **argv)
896 ::testing::InitGoogleTest(&argc, argv);
897 return RUN_ALL_TESTS();
900 void dbuscommaninterfacesignalsTest::SetUp()
905 void dbuscommaninterfacesignalsTest::TearDown()