* wrapping DLT calls in a new Class because of performance, codesize and lazyness...
[profile/ivi/audiomanager.git] / PluginCommandInterfaceDbus / test / dbuscommaninterfacesignalsTest.cpp
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * GeniviAudioMananger AudioManagerDaemon
5  *
6  * \file dbuscommandinterfacesignalsTest.cpp
7  *
8  * \date 20-Oct-2011 3:42:04 PM
9  * \author Christian Mueller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
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
14  *
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.
22  *
23  * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
24  */
25
26 #include "dbuscommaninterfacesignalsTest.h"
27 #include <iostream>
28 #include <fstream>
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"
35
36 using namespace am;
37 using namespace testing;
38
39
40 dbuscommaninterfacesignalsTest::dbuscommaninterfacesignalsTest()
41 {
42     DLTWrapper::instance()->registerApp("dbusTest","dbusTest");
43     logInfo("dbusCommandInterfaceSignalTest started");
44 }
45
46 dbuscommaninterfacesignalsTest::~dbuscommaninterfacesignalsTest()
47 {
48 }
49
50 void* NumberOfMainConnectionsChanged(void*)
51 {
52     sleep(1);
53     DbusCommandSender sender;
54     MockCommandReceiveInterface receiver;
55     DbusCommandInterfaceBackdoor backdoor;
56     backdoor.setReceiveInterface(&sender, &receiver);
57     DBusError error;
58     dbus_error_init(&error);
59     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
60     backdoor.setDbusConnection(&sender, co);
61     sender.cbNumberOfMainConnectionsChanged();
62     return (NULL);
63 }
64
65 void* cbSinkAdded(void*)
66 {
67     sleep(1);
68     std::vector<am_SinkType_s> list;
69     am_SinkType_s mysink;
70     mysink.name = "MySink";
71     mysink.sinkID = 23;
72     mysink.availability.availability = A_MAX;
73     mysink.availability.availabilityReason = AR_MIN;
74     mysink.muteState = MS_MIN;
75     mysink.sinkClassID = 3;
76     mysink.volume = 234;
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);
83     DBusError error;
84     dbus_error_init(&error);
85     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
86     backdoor.setDbusConnection(&sender, co);
87     sender.cbNumberOfSinksChanged();
88     return (NULL);
89 }
90
91 void* cbSourceAdded(void*)
92 {
93     sleep(1);
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);
106     DBusError error;
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();
112     return (NULL);
113 }
114
115 void* cbSourceRemoved(void*)
116 {
117     sleep(1);
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);
131     DBusError error;
132     dbus_error_init(&error);
133     list.clear();
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();
138     return (NULL);
139 }
140
141 void* cbSinkRemoved(void*)
142 {
143     sleep(1);
144     std::vector<am_SinkType_s> list;
145     am_SinkType_s mysink;
146     mysink.name = "MySink";
147     mysink.sinkID = 23;
148     mysink.availability.availability = A_MAX;
149     mysink.availability.availabilityReason = AR_MIN;
150     mysink.muteState = MS_MIN;
151     mysink.sinkClassID = 3;
152     mysink.volume = 234;
153     list.push_back(mysink);
154     DbusCommandSender sender;
155     MockCommandReceiveInterface receiver;
156     DbusCommandInterfaceBackdoor backdoor;
157     backdoor.setReceiveInterface(&sender, &receiver);
158     backdoor.setListSinks(&sender, list);
159     DBusError error;
160     dbus_error_init(&error);
161     list.clear();
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();
166     return (NULL);
167 }
168
169 void* NumberOfSinkClassesChanged(void*)
170 {
171     sleep(1);
172     DbusCommandSender sender;
173     MockCommandReceiveInterface receiver;
174     DbusCommandInterfaceBackdoor backdoor;
175     backdoor.setReceiveInterface(&sender, &receiver);
176     DBusError error;
177     dbus_error_init(&error);
178     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
179     backdoor.setDbusConnection(&sender, co);
180     sender.cbNumberOfSinkClassesChanged();
181     return (NULL);
182 }
183
184 void* NumberOfSourceClassesChanged(void*)
185 {
186     sleep(1);
187     DbusCommandSender sender;
188     MockCommandReceiveInterface receiver;
189     DbusCommandInterfaceBackdoor backdoor;
190     backdoor.setReceiveInterface(&sender, &receiver);
191     DBusError error;
192     dbus_error_init(&error);
193     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
194     backdoor.setDbusConnection(&sender, co);
195     sender.cbNumberOfSourceClassesChanged();
196     return (NULL);
197 }
198
199 void* MainConnectionStateChanged(void*)
200 {
201     sleep(1);
202     DbusCommandSender sender;
203     MockCommandReceiveInterface receiver;
204     DbusCommandInterfaceBackdoor backdoor;
205     backdoor.setReceiveInterface(&sender, &receiver);
206     DBusError error;
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);
213     return (NULL);
214 }
215
216 void* MainSinkSoundPropertyChanged(void*)
217 {
218     sleep(1);
219     DbusCommandSender sender;
220     MockCommandReceiveInterface receiver;
221     DbusCommandInterfaceBackdoor backdoor;
222     backdoor.setReceiveInterface(&sender, &receiver);
223     DBusError error;
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);
232     return (NULL);
233 }
234
235 void* MainSourceSoundPropertyChanged(void*)
236 {
237     sleep(1);
238     DbusCommandSender sender;
239     MockCommandReceiveInterface receiver;
240     DbusCommandInterfaceBackdoor backdoor;
241     backdoor.setReceiveInterface(&sender, &receiver);
242     DBusError error;
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);
251     return (NULL);
252 }
253
254 void* cbSinkAvailabilityChangedLoop(void*)
255 {
256     sleep(1);
257     DbusCommandSender sender;
258     MockCommandReceiveInterface receiver;
259     DbusCommandInterfaceBackdoor backdoor;
260     backdoor.setReceiveInterface(&sender, &receiver);
261     DBusError error;
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);
269     return (NULL);
270 }
271
272 void* VolumeChanged(void*)
273 {
274     sleep(1);
275     DbusCommandSender sender;
276     MockCommandReceiveInterface receiver;
277     DbusCommandInterfaceBackdoor backdoor;
278     backdoor.setReceiveInterface(&sender, &receiver);
279     DBusError error;
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);
285     return (NULL);
286 }
287
288 void* cbSourceAvailabilityChangedLoop(void*)
289 {
290     sleep(1);
291     DbusCommandSender sender;
292     MockCommandReceiveInterface receiver;
293     DbusCommandInterfaceBackdoor backdoor;
294     backdoor.setReceiveInterface(&sender, &receiver);
295     DBusError error;
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);
303     return (NULL);
304 }
305
306 void* SinkMuteStateChanged(void*)
307 {
308     sleep(1);
309     DbusCommandSender sender;
310     MockCommandReceiveInterface receiver;
311     DbusCommandInterfaceBackdoor backdoor;
312     backdoor.setReceiveInterface(&sender, &receiver);
313     DBusError error;
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);
318     return (NULL);
319 }
320
321 void* SystemPropertyChanged(void*)
322 {
323     sleep(1);
324     DbusCommandSender sender;
325     MockCommandReceiveInterface receiver;
326     DbusCommandInterfaceBackdoor backdoor;
327     backdoor.setReceiveInterface(&sender, &receiver);
328     DBusError error;
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);
336     return (NULL);
337 }
338
339 void* TimingInformationChanged(void*)
340 {
341     sleep(1);
342     DbusCommandSender sender;
343     MockCommandReceiveInterface receiver;
344     DbusCommandInterfaceBackdoor backdoor;
345     backdoor.setReceiveInterface(&sender, &receiver);
346     DBusError error;
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);
351     return (NULL);
352 }
353
354 TEST_F(dbuscommaninterfacesignalsTest,cbSourceAvailabilityChanged)
355 {
356
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"
362             "import traceback\n"
363             "import gobject\n"
364             "import dbus\n"
365             "import dbus.mainloop.glib\n"
366             "loop = gobject.MainLoop()\n"
367             "def catchsignal(*arg, **kwarg):\n"
368             "   print ('Caught NumberOfMainConnectionsChanged') \n"
369             "   loop.quit()\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);
375
376     pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) NULL);
377     PyRun_SimpleStringFlags("import sys\n"
378             "import traceback\n"
379             "import gobject\n"
380             "import dbus\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"
385             "   print (arg[0])\n"
386             "   f = open('/tmp/result.txt','w')\n"
387             "   f.write(str(arg[0]));\n"
388             "   f.close()\n"
389             "   loop.quit()\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);
395
396     std::ifstream ifs("/tmp/result.txt");
397     std::string line;
398     int lineCounter = 0, result = 0;
399     while (std::getline(ifs, line))
400     {
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);
402     }
403     ifs.close();
404
405     pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) NULL);
406     PyRun_SimpleStringFlags("import sys\n"
407             "import traceback\n"
408             "import gobject\n"
409             "import dbus\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"
414             "   print (arg[0])\n"
415             "   f = open('/tmp/result.txt','w')\n"
416             "   f.write(str(arg[0]));\n"
417             "   f.close()\n"
418             "   loop.quit()\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);
424
425     ifs.open("/tmp/result.txt");
426     lineCounter = 0;
427     result = 0;
428     while (std::getline(ifs, line))
429     {
430         std::stringstream(line) >> result;
431         ASSERT_EQ(result, 23);
432     }
433     ifs.close();
434
435     pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) NULL);
436     PyRun_SimpleStringFlags("import sys\n"
437             "import traceback\n"
438             "import gobject\n"
439             "import dbus\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"
444             "   print (arg[0])\n"
445             "   f = open('/tmp/result.txt','w')\n"
446             "   f.write(str(arg[0]));\n"
447             "   f.close()\n"
448             "   loop.quit()\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);
454
455     ifs.open("/tmp/result.txt");
456     lineCounter = 0;
457     result = 0;
458     while (std::getline(ifs, line))
459     {
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);
461     }
462     ifs.close();
463
464     pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) NULL);
465     PyRun_SimpleStringFlags("import sys\n"
466             "import traceback\n"
467             "import gobject\n"
468             "import dbus\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"
473             "   print (arg[0])\n"
474             "   f = open('/tmp/result.txt','w')\n"
475             "   f.write(str(arg[0]));\n"
476             "   f.close()\n"
477             "   loop.quit()\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);
483
484     ifs.open("/tmp/result.txt");
485     lineCounter = 0;
486     result = 0;
487     while (std::getline(ifs, line))
488     {
489         std::stringstream(line) >> result;
490         ASSERT_EQ(result, 42);
491     }
492     ifs.close();
493
494     pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) NULL);
495     PyRun_SimpleStringFlags("import sys\n"
496             "import traceback\n"
497             "import gobject\n"
498             "import dbus\n"
499             "import dbus.mainloop.glib\n"
500             "loop = gobject.MainLoop()\n"
501             "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
502             "   print ('Caught catchNumberOfSinkClassesChanged') \n"
503             "   loop.quit()\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);
509
510     pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) NULL);
511     PyRun_SimpleStringFlags("import sys\n"
512             "import traceback\n"
513             "import gobject\n"
514             "import dbus\n"
515             "import dbus.mainloop.glib\n"
516             "loop = gobject.MainLoop()\n"
517             "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
518             "   print ('Caught CatchNumberOfSourceClassesChanged') \n"
519             "   loop.quit()\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);
525
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"
530             "import traceback\n"
531             "import gobject\n"
532             "import dbus\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"
537             "   print (arg[0])\n"
538             "   print (arg[1])\n"
539             "   f = open('/tmp/result.txt','w')\n"
540             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
541             "   f.close()\n"
542             "   loop.quit()\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);
548
549     ifs.open("/tmp/result.txt");
550     lineCounter = 0;
551     result = 0;
552     while (std::getline(ifs, line))
553     {
554         if (lineCounter == 0)
555         {
556             std::stringstream(line) >> result;
557             ASSERT_EQ(result, 4);
558         }
559         else if (lineCounter == 1)
560         {
561             std::stringstream(line) >> result;
562             ASSERT_EQ(result, CS_CONNECTING);
563         }
564         lineCounter++;
565     }
566     ifs.close();
567
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"
572             "import traceback\n"
573             "import gobject\n"
574             "import dbus\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"
579             "   print (arg[0])\n"
580             "   print (arg[1])\n"
581             "   f = open('/tmp/result.txt','w')\n"
582             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
583             "   f.close()\n"
584             "   loop.quit()\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);
590
591     ifs.open("/tmp/result.txt");
592     lineCounter = 0;
593     result = 0;
594     while (std::getline(ifs, line))
595     {
596         if (lineCounter == 0)
597         {
598             std::stringstream(line) >> result;
599             ASSERT_EQ(result, 3);
600         }
601         else if (lineCounter == 1)
602         {
603             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(23)), signature=None)"), 0);
604         }
605         lineCounter++;
606     }
607     ifs.close();
608
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"
613             "import traceback\n"
614             "import gobject\n"
615             "import dbus\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"
620             "   print (arg[0])\n"
621             "   print (arg[1])\n"
622             "   f = open('/tmp/result.txt','w')\n"
623             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
624             "   f.close()\n"
625             "   loop.quit()\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);
631
632     ifs.open("/tmp/result.txt");
633     lineCounter = 0;
634     result = 0;
635     while (std::getline(ifs, line))
636     {
637         if (lineCounter == 0)
638         {
639             std::stringstream(line) >> result;
640             ASSERT_EQ(result, 35);
641         }
642         else if (lineCounter == 1)
643         {
644             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(233)), signature=None)"), 0);
645         }
646         lineCounter++;
647     }
648     ifs.close();
649
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"
654             "import traceback\n"
655             "import gobject\n"
656             "import dbus\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"
661             "   print (arg[0])\n"
662             "   print (arg[1])\n"
663             "   f = open('/tmp/result.txt','w')\n"
664             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
665             "   f.close()\n"
666             "   loop.quit()\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);
672
673     ifs.open("/tmp/result.txt");
674     lineCounter = 0;
675     result = 0;
676     while (std::getline(ifs, line))
677     {
678         if (lineCounter == 0)
679         {
680             std::stringstream(line) >> result;
681             ASSERT_EQ(result, 4);
682         }
683         else if (lineCounter == 1)
684         {
685             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
686         }
687         lineCounter++;
688     }
689     ifs.close();
690
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"
695             "import traceback\n"
696             "import gobject\n"
697             "import dbus\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"
702             "   print (arg[0])\n"
703             "   print (arg[1])\n"
704             "   f = open('/tmp/result.txt','w')\n"
705             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
706             "   f.close()\n"
707             "   loop.quit()\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);
713
714     ifs.open("/tmp/result.txt");
715     lineCounter = 0;
716     result = 0;
717     while (std::getline(ifs, line))
718     {
719         if (lineCounter == 0)
720         {
721             std::stringstream(line) >> result;
722             ASSERT_EQ(result, 2);
723         }
724         else if (lineCounter == 1)
725         {
726             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
727         }
728         lineCounter++;
729     }
730     ifs.close();
731
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"
736             "import traceback\n"
737             "import gobject\n"
738             "import dbus\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"
743             "   print (arg[0])\n"
744             "   print (arg[1])\n"
745             "   f = open('/tmp/result.txt','w')\n"
746             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
747             "   f.close()\n"
748             "   loop.quit()\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);
754
755     ifs.open("/tmp/result.txt");
756     lineCounter = 0;
757     result = 0;
758     while (std::getline(ifs, line))
759     {
760         if (lineCounter == 0)
761         {
762             std::stringstream(line) >> result;
763             ASSERT_EQ(result, 23);
764         }
765         else if (lineCounter == 1)
766         {
767             std::stringstream(line) >> result;
768             ASSERT_EQ(result, 344);
769         }
770         lineCounter++;
771     }
772     ifs.close();
773
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"
778             "import traceback\n"
779             "import gobject\n"
780             "import dbus\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"
785             "   print (arg[0])\n"
786             "   print (arg[1])\n"
787             "   f = open('/tmp/result.txt','w')\n"
788             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
789             "   f.close()\n"
790             "   loop.quit()\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);
796
797     ifs.open("/tmp/result.txt");
798     lineCounter = 0;
799     result = 0;
800     while (std::getline(ifs, line))
801     {
802         if (lineCounter == 0)
803         {
804             std::stringstream(line) >> result;
805             ASSERT_EQ(result, 42);
806         }
807         else if (lineCounter == 1)
808         {
809             std::stringstream(line) >> result;
810             ASSERT_EQ(result, MS_MUTED);
811         }
812         lineCounter++;
813     }
814     ifs.close();
815
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"
820             "import traceback\n"
821             "import gobject\n"
822             "import dbus\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"
827             "   print (arg[0])\n"
828             "   f = open('/tmp/result.txt','w')\n"
829             "   f.write(str(arg[0]));\n"
830             "   f.close()\n"
831             "   loop.quit()\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);
837
838     ifs.open("/tmp/result.txt");
839     lineCounter = 0;
840     result = 0;
841     while (std::getline(ifs, line))
842     {
843         ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
844     }
845     ifs.close();
846
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"
851             "import traceback\n"
852             "import gobject\n"
853             "import dbus\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"
858             "   print (arg[0])\n"
859             "   print (arg[1])\n"
860             "   f = open('/tmp/result.txt','w')\n"
861             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
862             "   f.close()\n"
863             "   loop.quit()\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);
869
870     ifs.open("/tmp/result.txt");
871     lineCounter = 0;
872     result = 0;
873     while (std::getline(ifs, line))
874     {
875         if (lineCounter == 0)
876         {
877             std::stringstream(line) >> result;
878             ASSERT_EQ(result, 42);
879         }
880         else if (lineCounter == 1)
881         {
882             std::stringstream(line) >> result;
883             ASSERT_EQ(result, 233);
884         }
885         lineCounter++;
886     }
887     ifs.close();
888
889 }
890
891 int main(int argc, char **argv)
892 {
893     ::testing::InitGoogleTest(&argc, argv);
894     return RUN_ALL_TESTS();
895 }
896
897 void dbuscommaninterfacesignalsTest::SetUp()
898 {
899     Py_Initialize();
900 }
901
902 void dbuscommaninterfacesignalsTest::TearDown()
903 {
904     Py_Finalize();
905 }
906