1c90d5511807c79ac750cb17d3d1a9c29d3106db
[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
35 using namespace am;
36 using namespace testing;
37
38 DLT_IMPORT_CONTEXT(DLT_CONTEXT)
39
40 dbuscommaninterfacesignalsTest::dbuscommaninterfacesignalsTest()
41 {
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 "));
45
46 }
47
48 dbuscommaninterfacesignalsTest::~dbuscommaninterfacesignalsTest()
49 {
50     DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
51 }
52
53 void* NumberOfMainConnectionsChanged(void*)
54 {
55     sleep(1);
56     DbusCommandSender sender;
57     MockCommandReceiveInterface receiver;
58     DbusCommandInterfaceBackdoor backdoor;
59     backdoor.setReceiveInterface(&sender, &receiver);
60     DBusError error;
61     dbus_error_init(&error);
62     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
63     backdoor.setDbusConnection(&sender, co);
64     sender.cbNumberOfMainConnectionsChanged();
65     return (NULL);
66 }
67
68 void* cbSinkAdded(void*)
69 {
70     sleep(1);
71     std::vector<am_SinkType_s> list;
72     am_SinkType_s mysink;
73     mysink.name = "MySink";
74     mysink.sinkID = 23;
75     mysink.availability.availability = A_MAX;
76     mysink.availability.availabilityReason = AR_MIN;
77     mysink.muteState = MS_MIN;
78     mysink.sinkClassID = 3;
79     mysink.volume = 234;
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);
86     DBusError error;
87     dbus_error_init(&error);
88     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
89     backdoor.setDbusConnection(&sender, co);
90     sender.cbNumberOfSinksChanged();
91     return (NULL);
92 }
93
94 void* cbSourceAdded(void*)
95 {
96     sleep(1);
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);
109     DBusError error;
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();
115     return (NULL);
116 }
117
118 void* cbSourceRemoved(void*)
119 {
120     sleep(1);
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);
134     DBusError error;
135     dbus_error_init(&error);
136     list.clear();
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();
141     return (NULL);
142 }
143
144 void* cbSinkRemoved(void*)
145 {
146     sleep(1);
147     std::vector<am_SinkType_s> list;
148     am_SinkType_s mysink;
149     mysink.name = "MySink";
150     mysink.sinkID = 23;
151     mysink.availability.availability = A_MAX;
152     mysink.availability.availabilityReason = AR_MIN;
153     mysink.muteState = MS_MIN;
154     mysink.sinkClassID = 3;
155     mysink.volume = 234;
156     list.push_back(mysink);
157     DbusCommandSender sender;
158     MockCommandReceiveInterface receiver;
159     DbusCommandInterfaceBackdoor backdoor;
160     backdoor.setReceiveInterface(&sender, &receiver);
161     backdoor.setListSinks(&sender, list);
162     DBusError error;
163     dbus_error_init(&error);
164     list.clear();
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();
169     return (NULL);
170 }
171
172 void* NumberOfSinkClassesChanged(void*)
173 {
174     sleep(1);
175     DbusCommandSender sender;
176     MockCommandReceiveInterface receiver;
177     DbusCommandInterfaceBackdoor backdoor;
178     backdoor.setReceiveInterface(&sender, &receiver);
179     DBusError error;
180     dbus_error_init(&error);
181     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
182     backdoor.setDbusConnection(&sender, co);
183     sender.cbNumberOfSinkClassesChanged();
184     return (NULL);
185 }
186
187 void* NumberOfSourceClassesChanged(void*)
188 {
189     sleep(1);
190     DbusCommandSender sender;
191     MockCommandReceiveInterface receiver;
192     DbusCommandInterfaceBackdoor backdoor;
193     backdoor.setReceiveInterface(&sender, &receiver);
194     DBusError error;
195     dbus_error_init(&error);
196     DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error);
197     backdoor.setDbusConnection(&sender, co);
198     sender.cbNumberOfSourceClassesChanged();
199     return (NULL);
200 }
201
202 void* MainConnectionStateChanged(void*)
203 {
204     sleep(1);
205     DbusCommandSender sender;
206     MockCommandReceiveInterface receiver;
207     DbusCommandInterfaceBackdoor backdoor;
208     backdoor.setReceiveInterface(&sender, &receiver);
209     DBusError error;
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);
216     return (NULL);
217 }
218
219 void* MainSinkSoundPropertyChanged(void*)
220 {
221     sleep(1);
222     DbusCommandSender sender;
223     MockCommandReceiveInterface receiver;
224     DbusCommandInterfaceBackdoor backdoor;
225     backdoor.setReceiveInterface(&sender, &receiver);
226     DBusError error;
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);
235     return (NULL);
236 }
237
238 void* MainSourceSoundPropertyChanged(void*)
239 {
240     sleep(1);
241     DbusCommandSender sender;
242     MockCommandReceiveInterface receiver;
243     DbusCommandInterfaceBackdoor backdoor;
244     backdoor.setReceiveInterface(&sender, &receiver);
245     DBusError error;
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);
254     return (NULL);
255 }
256
257 void* cbSinkAvailabilityChangedLoop(void*)
258 {
259     sleep(1);
260     DbusCommandSender sender;
261     MockCommandReceiveInterface receiver;
262     DbusCommandInterfaceBackdoor backdoor;
263     backdoor.setReceiveInterface(&sender, &receiver);
264     DBusError error;
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);
272     return (NULL);
273 }
274
275 void* VolumeChanged(void*)
276 {
277     sleep(1);
278     DbusCommandSender sender;
279     MockCommandReceiveInterface receiver;
280     DbusCommandInterfaceBackdoor backdoor;
281     backdoor.setReceiveInterface(&sender, &receiver);
282     DBusError error;
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);
288     return (NULL);
289 }
290
291 void* cbSourceAvailabilityChangedLoop(void*)
292 {
293     sleep(1);
294     DbusCommandSender sender;
295     MockCommandReceiveInterface receiver;
296     DbusCommandInterfaceBackdoor backdoor;
297     backdoor.setReceiveInterface(&sender, &receiver);
298     DBusError error;
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);
306     return (NULL);
307 }
308
309 void* SinkMuteStateChanged(void*)
310 {
311     sleep(1);
312     DbusCommandSender sender;
313     MockCommandReceiveInterface receiver;
314     DbusCommandInterfaceBackdoor backdoor;
315     backdoor.setReceiveInterface(&sender, &receiver);
316     DBusError error;
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);
321     return (NULL);
322 }
323
324 void* SystemPropertyChanged(void*)
325 {
326     sleep(1);
327     DbusCommandSender sender;
328     MockCommandReceiveInterface receiver;
329     DbusCommandInterfaceBackdoor backdoor;
330     backdoor.setReceiveInterface(&sender, &receiver);
331     DBusError error;
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);
339     return (NULL);
340 }
341
342 void* TimingInformationChanged(void*)
343 {
344     sleep(1);
345     DbusCommandSender sender;
346     MockCommandReceiveInterface receiver;
347     DbusCommandInterfaceBackdoor backdoor;
348     backdoor.setReceiveInterface(&sender, &receiver);
349     DBusError error;
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);
354     return (NULL);
355 }
356
357 TEST_F(dbuscommaninterfacesignalsTest,cbSourceAvailabilityChanged)
358 {
359
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"
365             "import traceback\n"
366             "import gobject\n"
367             "import dbus\n"
368             "import dbus.mainloop.glib\n"
369             "loop = gobject.MainLoop()\n"
370             "def catchsignal(*arg, **kwarg):\n"
371             "   print ('Caught NumberOfMainConnectionsChanged') \n"
372             "   loop.quit()\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);
378
379     pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) NULL);
380     PyRun_SimpleStringFlags("import sys\n"
381             "import traceback\n"
382             "import gobject\n"
383             "import dbus\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"
388             "   print (arg[0])\n"
389             "   f = open('/tmp/result.txt','w')\n"
390             "   f.write(str(arg[0]));\n"
391             "   f.close()\n"
392             "   loop.quit()\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);
398
399     std::ifstream ifs("/tmp/result.txt");
400     std::string line;
401     int lineCounter = 0, result = 0;
402     while (std::getline(ifs, line))
403     {
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);
405     }
406     ifs.close();
407
408     pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) NULL);
409     PyRun_SimpleStringFlags("import sys\n"
410             "import traceback\n"
411             "import gobject\n"
412             "import dbus\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"
417             "   print (arg[0])\n"
418             "   f = open('/tmp/result.txt','w')\n"
419             "   f.write(str(arg[0]));\n"
420             "   f.close()\n"
421             "   loop.quit()\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);
427
428     ifs.open("/tmp/result.txt");
429     lineCounter = 0;
430     result = 0;
431     while (std::getline(ifs, line))
432     {
433         std::stringstream(line) >> result;
434         ASSERT_EQ(result, 23);
435     }
436     ifs.close();
437
438     pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) NULL);
439     PyRun_SimpleStringFlags("import sys\n"
440             "import traceback\n"
441             "import gobject\n"
442             "import dbus\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"
447             "   print (arg[0])\n"
448             "   f = open('/tmp/result.txt','w')\n"
449             "   f.write(str(arg[0]));\n"
450             "   f.close()\n"
451             "   loop.quit()\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);
457
458     ifs.open("/tmp/result.txt");
459     lineCounter = 0;
460     result = 0;
461     while (std::getline(ifs, line))
462     {
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);
464     }
465     ifs.close();
466
467     pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) NULL);
468     PyRun_SimpleStringFlags("import sys\n"
469             "import traceback\n"
470             "import gobject\n"
471             "import dbus\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"
476             "   print (arg[0])\n"
477             "   f = open('/tmp/result.txt','w')\n"
478             "   f.write(str(arg[0]));\n"
479             "   f.close()\n"
480             "   loop.quit()\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);
486
487     ifs.open("/tmp/result.txt");
488     lineCounter = 0;
489     result = 0;
490     while (std::getline(ifs, line))
491     {
492         std::stringstream(line) >> result;
493         ASSERT_EQ(result, 42);
494     }
495     ifs.close();
496
497     pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) NULL);
498     PyRun_SimpleStringFlags("import sys\n"
499             "import traceback\n"
500             "import gobject\n"
501             "import dbus\n"
502             "import dbus.mainloop.glib\n"
503             "loop = gobject.MainLoop()\n"
504             "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
505             "   print ('Caught catchNumberOfSinkClassesChanged') \n"
506             "   loop.quit()\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);
512
513     pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) NULL);
514     PyRun_SimpleStringFlags("import sys\n"
515             "import traceback\n"
516             "import gobject\n"
517             "import dbus\n"
518             "import dbus.mainloop.glib\n"
519             "loop = gobject.MainLoop()\n"
520             "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
521             "   print ('Caught CatchNumberOfSourceClassesChanged') \n"
522             "   loop.quit()\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);
528
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"
533             "import traceback\n"
534             "import gobject\n"
535             "import dbus\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"
540             "   print (arg[0])\n"
541             "   print (arg[1])\n"
542             "   f = open('/tmp/result.txt','w')\n"
543             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
544             "   f.close()\n"
545             "   loop.quit()\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);
551
552     ifs.open("/tmp/result.txt");
553     lineCounter = 0;
554     result = 0;
555     while (std::getline(ifs, line))
556     {
557         if (lineCounter == 0)
558         {
559             std::stringstream(line) >> result;
560             ASSERT_EQ(result, 4);
561         }
562         else if (lineCounter == 1)
563         {
564             std::stringstream(line) >> result;
565             ASSERT_EQ(result, CS_CONNECTING);
566         }
567         lineCounter++;
568     }
569     ifs.close();
570
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"
575             "import traceback\n"
576             "import gobject\n"
577             "import dbus\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"
582             "   print (arg[0])\n"
583             "   print (arg[1])\n"
584             "   f = open('/tmp/result.txt','w')\n"
585             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
586             "   f.close()\n"
587             "   loop.quit()\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);
593
594     ifs.open("/tmp/result.txt");
595     lineCounter = 0;
596     result = 0;
597     while (std::getline(ifs, line))
598     {
599         if (lineCounter == 0)
600         {
601             std::stringstream(line) >> result;
602             ASSERT_EQ(result, 3);
603         }
604         else if (lineCounter == 1)
605         {
606             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(23)), signature=None)"), 0);
607         }
608         lineCounter++;
609     }
610     ifs.close();
611
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"
616             "import traceback\n"
617             "import gobject\n"
618             "import dbus\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"
623             "   print (arg[0])\n"
624             "   print (arg[1])\n"
625             "   f = open('/tmp/result.txt','w')\n"
626             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
627             "   f.close()\n"
628             "   loop.quit()\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);
634
635     ifs.open("/tmp/result.txt");
636     lineCounter = 0;
637     result = 0;
638     while (std::getline(ifs, line))
639     {
640         if (lineCounter == 0)
641         {
642             std::stringstream(line) >> result;
643             ASSERT_EQ(result, 35);
644         }
645         else if (lineCounter == 1)
646         {
647             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(233)), signature=None)"), 0);
648         }
649         lineCounter++;
650     }
651     ifs.close();
652
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"
657             "import traceback\n"
658             "import gobject\n"
659             "import dbus\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"
664             "   print (arg[0])\n"
665             "   print (arg[1])\n"
666             "   f = open('/tmp/result.txt','w')\n"
667             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
668             "   f.close()\n"
669             "   loop.quit()\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);
675
676     ifs.open("/tmp/result.txt");
677     lineCounter = 0;
678     result = 0;
679     while (std::getline(ifs, line))
680     {
681         if (lineCounter == 0)
682         {
683             std::stringstream(line) >> result;
684             ASSERT_EQ(result, 4);
685         }
686         else if (lineCounter == 1)
687         {
688             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
689         }
690         lineCounter++;
691     }
692     ifs.close();
693
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"
698             "import traceback\n"
699             "import gobject\n"
700             "import dbus\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"
705             "   print (arg[0])\n"
706             "   print (arg[1])\n"
707             "   f = open('/tmp/result.txt','w')\n"
708             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
709             "   f.close()\n"
710             "   loop.quit()\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);
716
717     ifs.open("/tmp/result.txt");
718     lineCounter = 0;
719     result = 0;
720     while (std::getline(ifs, line))
721     {
722         if (lineCounter == 0)
723         {
724             std::stringstream(line) >> result;
725             ASSERT_EQ(result, 2);
726         }
727         else if (lineCounter == 1)
728         {
729             ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0);
730         }
731         lineCounter++;
732     }
733     ifs.close();
734
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"
739             "import traceback\n"
740             "import gobject\n"
741             "import dbus\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"
746             "   print (arg[0])\n"
747             "   print (arg[1])\n"
748             "   f = open('/tmp/result.txt','w')\n"
749             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
750             "   f.close()\n"
751             "   loop.quit()\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);
757
758     ifs.open("/tmp/result.txt");
759     lineCounter = 0;
760     result = 0;
761     while (std::getline(ifs, line))
762     {
763         if (lineCounter == 0)
764         {
765             std::stringstream(line) >> result;
766             ASSERT_EQ(result, 23);
767         }
768         else if (lineCounter == 1)
769         {
770             std::stringstream(line) >> result;
771             ASSERT_EQ(result, 344);
772         }
773         lineCounter++;
774     }
775     ifs.close();
776
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"
781             "import traceback\n"
782             "import gobject\n"
783             "import dbus\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"
788             "   print (arg[0])\n"
789             "   print (arg[1])\n"
790             "   f = open('/tmp/result.txt','w')\n"
791             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
792             "   f.close()\n"
793             "   loop.quit()\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);
799
800     ifs.open("/tmp/result.txt");
801     lineCounter = 0;
802     result = 0;
803     while (std::getline(ifs, line))
804     {
805         if (lineCounter == 0)
806         {
807             std::stringstream(line) >> result;
808             ASSERT_EQ(result, 42);
809         }
810         else if (lineCounter == 1)
811         {
812             std::stringstream(line) >> result;
813             ASSERT_EQ(result, MS_MUTED);
814         }
815         lineCounter++;
816     }
817     ifs.close();
818
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"
823             "import traceback\n"
824             "import gobject\n"
825             "import dbus\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"
830             "   print (arg[0])\n"
831             "   f = open('/tmp/result.txt','w')\n"
832             "   f.write(str(arg[0]));\n"
833             "   f.close()\n"
834             "   loop.quit()\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);
840
841     ifs.open("/tmp/result.txt");
842     lineCounter = 0;
843     result = 0;
844     while (std::getline(ifs, line))
845     {
846         ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
847     }
848     ifs.close();
849
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"
854             "import traceback\n"
855             "import gobject\n"
856             "import dbus\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"
861             "   print (arg[0])\n"
862             "   print (arg[1])\n"
863             "   f = open('/tmp/result.txt','w')\n"
864             "   f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
865             "   f.close()\n"
866             "   loop.quit()\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);
872
873     ifs.open("/tmp/result.txt");
874     lineCounter = 0;
875     result = 0;
876     while (std::getline(ifs, line))
877     {
878         if (lineCounter == 0)
879         {
880             std::stringstream(line) >> result;
881             ASSERT_EQ(result, 42);
882         }
883         else if (lineCounter == 1)
884         {
885             std::stringstream(line) >> result;
886             ASSERT_EQ(result, 233);
887         }
888         lineCounter++;
889     }
890     ifs.close();
891
892 }
893
894 int main(int argc, char **argv)
895 {
896     ::testing::InitGoogleTest(&argc, argv);
897     return RUN_ALL_TESTS();
898 }
899
900 void dbuscommaninterfacesignalsTest::SetUp()
901 {
902     Py_Initialize();
903 }
904
905 void dbuscommaninterfacesignalsTest::TearDown()
906 {
907     Py_Finalize();
908 }
909