1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
/**
* Copyright (c) 2012 BMW
*
* \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
*
* \copyright
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* For further information see http://www.genivi.org/.
*/
#include "CAmCommandSenderDbusSignalTest.h"
#include <python2.6/Python.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include "CAmCommandSenderDbusBackdoor.h"
#include "MockIAmCommandReceive.h"
#include "../include/CAmCommandSenderDbus.h"
#include "../include/CAmDbusMessageHandler.h"
#include "../../AudioManagerDaemon/include/TAmPluginTemplate.h"
#include "shared/CAmDltWrapper.h"
using namespace am;
using namespace testing;
CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest()
{
CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest");
logInfo("dbusCommandInterfaceSignalTest started");
}
CAmCommandSenderDbusSignalTest::~CAmCommandSenderDbusSignalTest()
{
}
void* NumberOfMainConnectionsChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_MainConnectionType_s mainConnection;
sender->cbNewMainConnection(mainConnection);
return (NULL);
}
void* cbSinkAdded(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
std::vector<am_SinkType_s> list;
am_SinkType_s mysink;
mysink.name = "MySink";
mysink.sinkID = 23;
mysink.availability.availability = A_MAX;
mysink.availability.availabilityReason = AR_UNKNOWN;
mysink.muteState = MS_UNKNOWN;
mysink.sinkClassID = 3;
mysink.volume = 234;
sender->cbNewSink(mysink);
return (NULL);
}
void* cbSourceAdded(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_SourceType_s mysource;
mysource.name = "MySink";
mysource.sourceID = 42;
mysource.availability.availability = A_MAX;
mysource.availability.availabilityReason = AR_UNKNOWN;
mysource.sourceClassID = 15;
sender->cbNewSource(mysource);
return (NULL);
}
void* cbSourceRemoved(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_SourceType_s mysource;
mysource.name = "MySink";
mysource.sourceID = 42;
sender->cbRemovedSource(mysource.sourceID);
return (NULL);
}
void* cbSinkRemoved(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_SinkType_s mysink;
mysink.name = "MySink";
mysink.sinkID = 23;
sender->cbRemovedSink(mysink.sinkID);
return (NULL);
}
void* NumberOfSinkClassesChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
sender->cbNumberOfSinkClassesChanged();
return (NULL);
}
void* NumberOfSourceClassesChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
sender->cbNumberOfSourceClassesChanged();
return (NULL);
}
void* MainConnectionStateChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_connectionID_t id = 4;
am_ConnectionState_e state = CS_CONNECTING;
sender->cbMainConnectionStateChanged(id, state);
return (NULL);
}
void* MainSinkSoundPropertyChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_sinkID_t sinkID = 3;
am_MainSoundProperty_s soundProperty;
soundProperty.type = MSP_UNKNOWN;
soundProperty.value = 23;
sender->cbMainSinkSoundPropertyChanged(sinkID, soundProperty);
return (NULL);
}
void* MainSourceSoundPropertyChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_sourceID_t sourceID = 35;
am_MainSoundProperty_s soundProperty;
soundProperty.type = MSP_UNKNOWN;
soundProperty.value = 233;
sender->cbMainSourceSoundPropertyChanged(sourceID, soundProperty);
return (NULL);
}
void* cbSinkAvailabilityChangedLoop(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_Availability_s av;
av.availability = A_AVAILABLE;
av.availabilityReason = AR_UNKNOWN;
sender->cbSinkAvailabilityChanged(4, av);
return (NULL);
}
void* VolumeChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_volume_t volume = 344;
sender->cbVolumeChanged(23, volume);
return (NULL);
}
void* cbSourceAvailabilityChangedLoop(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_Availability_s av;
av.availability = A_AVAILABLE;
av.availabilityReason = AR_UNKNOWN;
sender->cbSourceAvailabilityChanged(2, av);
return (NULL);
}
void* SinkMuteStateChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
sender->cbSinkMuteStateChanged(42, MS_MUTED);
return (NULL);
}
void* SystemPropertyChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
am_SystemProperty_s property;
property.type = SYP_UNKNOWN;
property.value = 355;
sender->cbSystemPropertyChanged(property);
return (NULL);
}
void* TimingInformationChanged(void* ppCommandSend)
{
sleep(1);
IAmCommandSend* sender=static_cast<IAmCommandSend*>(ppCommandSend);
sender->cbTimingInformationChanged(42, 233);
return (NULL);
}
TEST_F(CAmCommandSenderDbusSignalTest,cbSourceAvailabilityChanged)
{
//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)
//so it is running in the main context and the signals are send from threads...
CAmSocketHandler pSocketHandler;
CAmDbusWrapper pDBusWrapper(&pSocketHandler);
MockIAmCommandReceive pReceiveInterface;
IAmCommandSend* (*createFunc)();
void* tempLibHandle = NULL;
std::string libname("../plugins/command/libPluginCommandInterfaceDbus.so");
createFunc = getCreateFunction<IAmCommandSend*()>(libname, tempLibHandle);
if (!createFunc)
{
logError("CommandSendInterface Test Entry point of RoutingPlugin not found");
exit(1);
}
ppCommandSend = createFunc();
if (!ppCommandSend)
{
logError("CommandSendInterface Test RoutingPlugin initialization failed. Entry Function not callable");
exit(1);
}
// ok, here we give the DBusWrapper pointer to the Plugin and start the interface
EXPECT_CALL(pReceiveInterface,getDBusConnectionWrapper(_)).WillRepeatedly(DoAll(SetArgReferee<0>(&pDBusWrapper), Return(E_OK)));
EXPECT_CALL(pReceiveInterface, confirmCommandReady(10));
ppCommandSend->startupInterface(&pReceiveInterface);
ppCommandSend->setCommandReady(10);
pthread_t pythonloop;
pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchsignal(*arg, **kwarg):\n"
" print ('Caught NumberOfMainConnectionsChanged') \n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSinkAdded(*arg, **karg):\n"
" print ('Caught signal (in SinkAdded handler) ') \n"
" print (arg[0])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
std::ifstream ifs("/tmp/result.txt");
std::string line;
int lineCounter = 0, result = 0;
while (std::getline(ifs, line))
{
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);
}
ifs.close();
pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSinkRemoved(*arg, **karg):\n"
" print ('Caught signal (in SinkRemoved handler) ') \n"
" print (arg[0])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 23);
}
ifs.close();
pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSourceAdded(*arg, **karg):\n"
" print ('Caught signal (in SourceAdded handler) ') \n"
" print (arg[0])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
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);
}
ifs.close();
pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSourceRemoved(*arg, **karg):\n"
" print ('Caught signal (in SinkRemoved handler) ') \n"
" print (arg[0])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 42);
}
ifs.close();
pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n"
" print ('Caught catchNumberOfSinkClassesChanged') \n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n"
" print ('Caught CatchNumberOfSourceClassesChanged') \n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchMainConnectionStateChanged(*arg, **karg):\n"
" print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 4);
}
else if (lineCounter == 1)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, CS_CONNECTING);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchMainSinkSoundPropertyChanged(*arg, **karg):\n"
" print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 3);
}
else if (lineCounter == 1)
{
ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(23)), signature=None)"), 0);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchMainSourceSoundPropertyChanged(*arg, **karg):\n"
" print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 35);
}
else if (lineCounter == 1)
{
ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(233)), signature=None)"), 0);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSinkAvailabilityChanged(*arg, **karg):\n"
" print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 4);
}
else if (lineCounter == 1)
{
ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSourceAvailability(*arg, **karg):\n"
" print ('Caught signal (in catchSourceAvailability handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 2);
}
else if (lineCounter == 1)
{
ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, VolumeChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchVolumeChanged(*arg, **karg):\n"
" print ('Caught signal (in catchVolumeChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 23);
}
else if (lineCounter == 1)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 344);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSinkMuteStateChanged(*arg, **karg):\n"
" print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 42);
}
else if (lineCounter == 1)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, MS_MUTED);
}
lineCounter++;
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchSystemPropertyChanged(*arg, **karg):\n"
" print ('Caught signal (in catchSystemPropertyChanged handler) ') \n"
" print (arg[0])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0);
}
ifs.close();
//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)
//so it is running in the main context and the signals are send from threads...
pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) ppCommandSend);
PyRun_SimpleStringFlags("import sys\n"
"import traceback\n"
"import gobject\n"
"import dbus\n"
"import dbus.mainloop.glib\n"
"loop = gobject.MainLoop()\n"
"def catchTimingInformationChanged(*arg, **karg):\n"
" print ('Caught signal (in catchTimingInformationChanged handler) ') \n"
" print (arg[0])\n"
" print (arg[1])\n"
" f = open('/tmp/result.txt','w')\n"
" f.write(str(arg[0]) + '\\n' + str (arg[1]));\n"
" f.close()\n"
" loop.quit()\n"
"dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n"
"bus = dbus.SessionBus()\n"
"bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n"
"loop.run()\n", NULL);
pthread_join(pythonloop, NULL);
ifs.open("/tmp/result.txt");
lineCounter = 0;
result = 0;
while (std::getline(ifs, line))
{
if (lineCounter == 0)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 42);
}
else if (lineCounter == 1)
{
std::stringstream(line) >> result;
ASSERT_EQ(result, 233);
}
lineCounter++;
}
ifs.close();
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
void CAmCommandSenderDbusSignalTest::SetUp()
{
Py_Initialize();
}
void CAmCommandSenderDbusSignalTest::TearDown()
{
Py_Finalize();
}
|