Merge lp:~dobey/indicator-sound/drop-greeeter into lp:indicator-sound

Proposed by dobey on 2017-03-23
Status: Approved
Approved by: dobey on 2017-03-24
Approved revision: 552
Proposed branch: lp:~dobey/indicator-sound/drop-greeeter
Merge into: lp:indicator-sound
Diff against target: 867 lines (+4/-697)
11 files modified
debian/control (+0/-1)
src/CMakeLists.txt (+2/-20)
src/accounts-service-user.vala (+0/-47)
src/greeter-broadcast.vala (+0/-34)
src/main.c (+2/-6)
src/media-player-list-greeter.vala (+0/-123)
src/media-player-user.vala (+0/-18)
src/service.vala (+0/-9)
tests/CMakeLists.txt (+0/-51)
tests/greeter-list.cc (+0/-68)
tests/media-player-user.cc (+0/-320)
To merge this branch: bzr merge lp:~dobey/indicator-sound/drop-greeeter
Reviewer Review Type Date Requested Status
unity-api-1-bot continuous-integration Approve on 2017-03-30
Charles Kerr (community) 2017-03-23 Approve on 2017-03-23
Review via email: mp+320858@code.launchpad.net

Commit message

Strip out the complicated non-working greeter support.

Description of the change

This removes the code which theoretically proxies the player controls out to the greeter screen, that doesn't work.

The Sound menu spec states that the player controls should NOT appear on the greeter screen:

https://wiki.ubuntu.com/Sound#Music_player_sections
"Whenever you are logged in (that is, not in the standalone installer session or at the login screen), any music player that advertises itself over http://mpris.org/ Mpris should have its own section in the sound menu."

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

So, first off, I'm not super happy with the tone of the MR, e.g. "theoretically". If the code needs fixing then that's something that should be addressed, but bugs happen and there's no need to be snide about it.

Secondly, I still disagree with the removal of this feature. Controlling play from the greeter is a worthwhile feature IMO.

But as per the discussion in the Indicator meeting today, I'm in the minority on this. If neither the coder doing the work, NOR the designer, want this feature, I'm not going to block the change. :P

review: Approve
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:552
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-sound-ci/24/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1892
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1899
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1681/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1681/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1681/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1681/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1681/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1681
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1681/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-sound-ci/24/rebuild

review: Approve (continuous-integration)

Unmerged revisions

552. By dobey on 2017-03-23

Strip out the complicated non-working greeter support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2017-02-07 22:04:35 +0000
3+++ debian/control 2017-03-23 19:32:45 +0000
4@@ -56,7 +56,6 @@
5 indicator-common,
6 Recommends: unity-control-center | gnome-control-center | ubuntu-system-settings | pavucontrol | mate-media,
7 accountsservice,
8-Suggests: unity-greeter-session-broadcast,
9 Description: System sound indicator.
10 System sound indicator which provides easy control of the PulseAudio sound
11 daemon.
12
13=== modified file 'src/CMakeLists.txt'
14--- src/CMakeLists.txt 2017-02-07 21:50:25 +0000
15+++ src/CMakeLists.txt 2017-03-23 19:32:45 +0000
16@@ -134,13 +134,6 @@
17 mpris2-interfaces
18 )
19 vala_add(indicator-sound-service
20- media-player-user.vala
21- DEPENDS
22- media-player
23- accounts-service-sound-settings
24- greeter-broadcast
25-)
26-vala_add(indicator-sound-service
27 media-player-list.vala
28 DEPENDS
29 media-player
30@@ -154,13 +147,6 @@
31 mpris2-interfaces
32 )
33 vala_add(indicator-sound-service
34- media-player-list-greeter.vala
35- DEPENDS
36- media-player-list
37- media-player-user
38- media-player
39-)
40-vala_add(indicator-sound-service
41 mpris2-interfaces.vala
42 )
43 vala_add(indicator-sound-service
44@@ -183,7 +169,6 @@
45 accounts-service-sound-settings
46 accounts-service-privacy-settings
47 accounts-service-system-sound-settings
48- greeter-broadcast
49 )
50 vala_add(indicator-sound-service
51 accounts-service-sound-settings.vala
52@@ -194,9 +179,6 @@
53 vala_add(indicator-sound-service
54 accounts-service-system-sound-settings.vala
55 )
56-vala_add(indicator-sound-service
57- greeter-broadcast.vala
58-)
59
60 vala_finish(indicator-sound-service
61 SOURCES
62@@ -235,8 +217,8 @@
63 )
64
65 add_library(
66- indicator-sound-service-lib STATIC
67- ${INDICATOR_SOUND_SOURCES}
68+ indicator-sound-service-lib STATIC
69+ ${INDICATOR_SOUND_SOURCES}
70 )
71
72 target_link_libraries(
73
74=== modified file 'src/accounts-service-user.vala'
75--- src/accounts-service-user.vala 2015-12-31 20:49:42 +0000
76+++ src/accounts-service-user.vala 2017-03-23 19:32:45 +0000
77@@ -25,9 +25,6 @@
78 AccountsServiceSystemSoundSettings? syssoundproxy = null;
79 uint timer = 0;
80 MediaPlayer? _player = null;
81- GreeterBroadcast? greeter = null;
82-
83- public bool showDataOnGreeter { get; set; }
84
85 bool _silentMode = false;
86 public bool silentMode {
87@@ -118,14 +115,6 @@
88 user = accounts_manager.get_user(GLib.Environment.get_user_name());
89 user.notify["is-loaded"].connect(() => user_loaded_changed());
90 user_loaded_changed();
91-
92- Bus.get_proxy.begin<GreeterBroadcast> (
93- BusType.SYSTEM,
94- "com.canonical.Unity.Greeter.Broadcast",
95- "/com/canonical/Unity/Greeter/Broadcast",
96- DBusProxyFlags.NONE,
97- null,
98- greeter_proxy_new);
99 }
100
101 void user_loaded_changed () {
102@@ -188,11 +177,8 @@
103 var welcomeval = changed.lookup_value("MessagesWelcomeScreen", VariantType.BOOLEAN);
104 if (welcomeval != null) {
105 debug("Messages on welcome screen changed");
106- this.showDataOnGreeter = welcomeval.get_boolean();
107 }
108 });
109-
110- this.showDataOnGreeter = this.privacyproxy.messages_welcome_screen;
111 } catch (Error e) {
112 this.privacyproxy = null;
113 warning("Unable to get proxy to user privacy settings: %s", e.message);
114@@ -219,37 +205,4 @@
115 warning("Unable to get proxy to system sound settings: %s", e.message);
116 }
117 }
118-
119- void greeter_proxy_new (GLib.Object? obj, AsyncResult res) {
120- try {
121- this.greeter = Bus.get_proxy.end (res);
122-
123- this.greeter.SoundPlayPause.connect((username) => {
124- if (username != GLib.Environment.get_user_name())
125- return;
126- if (this._player == null)
127- return;
128- this._player.play_pause();
129- });
130-
131- this.greeter.SoundNext.connect((username) => {
132- if (username != GLib.Environment.get_user_name())
133- return;
134- if (this._player == null)
135- return;
136- this._player.next();
137- });
138-
139- this.greeter.SoundPrev.connect((username) => {
140- if (username != GLib.Environment.get_user_name())
141- return;
142- if (this._player == null)
143- return;
144- this._player.previous();
145- });
146- } catch (Error e) {
147- this.greeter = null;
148- warning("Unable to get greeter proxy: %s", e.message);
149- }
150- }
151 }
152
153=== removed file 'src/greeter-broadcast.vala'
154--- src/greeter-broadcast.vala 2014-03-13 18:38:55 +0000
155+++ src/greeter-broadcast.vala 1970-01-01 00:00:00 +0000
156@@ -1,34 +0,0 @@
157-/*
158- * Copyright 2014 © Canonical Ltd.
159- *
160- * This program is free software; you can redistribute it and/or modify
161- * it under the terms of the GNU General Public License as published by
162- * the Free Software Foundation; version 3.
163- *
164- * This program is distributed in the hope that it will be useful,
165- * but WITHOUT ANY WARRANTY; without even the implied warranty of
166- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167- * GNU General Public License for more details.
168- *
169- * You should have received a copy of the GNU General Public License
170- * along with this program. If not, see <http://www.gnu.org/licenses/>.
171- *
172- * Authors:
173- * Ted Gould <ted@canonical.com>
174- */
175-
176-[DBus (name = "com.canonical.Unity.Greeter.Broadcast")]
177-public interface GreeterBroadcast : Object {
178- // methods
179- // unused public abstract async void RequestApplicationStart(string name, string appid) throws IOError;
180- // unused public abstract async void RequestHomeShown(string name) throws IOError;
181- public abstract async void RequestSoundPlayPause(string name) throws IOError;
182- public abstract async void RequestSoundNext(string name) throws IOError;
183- public abstract async void RequestSoundPrev(string name) throws IOError;
184- // signals
185- // unused public signal void StartApplication(string username, string appid);
186- // unused public signal void ShowHome(string username);
187- public signal void SoundPlayPause(string username);
188- public signal void SoundNext(string username);
189- public signal void SoundPrev(string username);
190-}
191
192=== modified file 'src/main.c'
193--- src/main.c 2016-02-23 12:48:46 +0000
194+++ src/main.c 2017-03-23 19:32:45 +0000
195@@ -54,12 +54,8 @@
196 AccountsServiceAccess * accounts_service_access = NULL;
197
198
199- if (g_strcmp0("lightdm", g_get_user_name()) == 0) {
200- playerlist = MEDIA_PLAYER_LIST(media_player_list_greeter_new());
201- } else {
202- playerlist = MEDIA_PLAYER_LIST(media_player_list_mpris_new());
203- accounts = accounts_service_user_new();
204- }
205+ playerlist = MEDIA_PLAYER_LIST(media_player_list_mpris_new());
206+ accounts = accounts_service_user_new();
207
208 pgloop = pa_glib_mainloop_new(NULL);
209 options = indicator_sound_options_gsettings_new();
210
211=== removed file 'src/media-player-list-greeter.vala'
212--- src/media-player-list-greeter.vala 2014-04-01 23:20:56 +0000
213+++ src/media-player-list-greeter.vala 1970-01-01 00:00:00 +0000
214@@ -1,123 +0,0 @@
215-/*
216- * Copyright © 2014 Canonical Ltd.
217- *
218- * This program is free software; you can redistribute it and/or modify
219- * it under the terms of the GNU General Public License as published by
220- * the Free Software Foundation; version 3.
221- *
222- * This program is distributed in the hope that it will be useful,
223- * but WITHOUT ANY WARRANTY; without even the implied warranty of
224- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
225- * GNU General Public License for more details.
226- *
227- * You should have received a copy of the GNU General Public License
228- * along with this program. If not, see <http://www.gnu.org/licenses/>.
229- *
230- * Authors:
231- * Ted Gould <ted@canonical.com>
232- */
233-
234-[DBus (name="com.canonical.UnityGreeter.List")]
235-public interface UnityGreeterList : Object {
236- public abstract async string get_active_entry () throws IOError;
237- public signal void entry_selected (string entry_name);
238-}
239-
240-public class MediaPlayerListGreeter : MediaPlayerList {
241- string? selected_user = null;
242- UnityGreeterList? proxy = null;
243- HashTable<string, MediaPlayerUser> players = new HashTable<string, MediaPlayerUser>(str_hash, str_equal);
244-
245- public MediaPlayerListGreeter () {
246- Bus.get_proxy.begin<UnityGreeterList> (
247- BusType.SESSION,
248- "com.canonical.UnityGreeter",
249- "/list",
250- DBusProxyFlags.NONE,
251- null,
252- new_proxy);
253- }
254-
255- void new_proxy (GLib.Object? obj, AsyncResult res) {
256- try {
257- this.proxy = Bus.get_proxy.end(res);
258-
259- this.proxy.entry_selected.connect(active_user_changed);
260- this.proxy.get_active_entry.begin ((obj, res) => {
261- try {
262- var value = (obj as UnityGreeterList).get_active_entry.end(res);
263- active_user_changed(value);
264- } catch (Error e) {
265- warning("Unable to get active entry: %s", e.message);
266- }
267- });
268- } catch (Error e) {
269- this.proxy = null;
270- warning("Unable to create proxy to the greeter: %s", e.message);
271- }
272- }
273-
274- void active_user_changed (string active_user) {
275- /* No change, move along */
276- if (selected_user == active_user) {
277- return;
278- }
279-
280- debug(@"Active user changed to: $active_user");
281-
282- var old_user = selected_user;
283-
284- /* Protect against a null user */
285- if (active_user != "" && active_user[0] != '*') {
286- selected_user = active_user;
287- } else {
288- debug(@"Blocking active user change for '$active_user'");
289- selected_user = null;
290- }
291-
292- if (selected_user != null && !players.contains(selected_user)) {
293- players.insert(selected_user, new MediaPlayerUser(selected_user));
294- }
295-
296- if (old_user != null) {
297- var old_player = players.lookup(old_user);
298- debug("Removing player for user: %s", old_user);
299- player_removed(old_player);
300- }
301-
302- if (selected_user != null) {
303- var new_player = players.lookup(selected_user);
304-
305- if (new_player != null) {
306- debug("Adding player for user: %s", selected_user);
307- player_added(new_player);
308- }
309- }
310- }
311-
312- /* We need to have an iterator for the interface, but eh, we can
313- only ever have one player for the current user */
314- public class Iterator : MediaPlayerList.Iterator {
315- int i = 0;
316- MediaPlayerListGreeter list;
317-
318- public Iterator (MediaPlayerListGreeter in_list) {
319- list = in_list;
320- }
321-
322- public override MediaPlayer? next_value () {
323- MediaPlayer? retval = null;
324-
325- if (i == 0 && list.selected_user != null) {
326- retval = list.players.lookup(list.selected_user);
327- }
328- i++;
329-
330- return retval;
331- }
332- }
333-
334- public override MediaPlayerList.Iterator iterator() {
335- return new Iterator(this) as MediaPlayerList.Iterator;
336- }
337-}
338
339=== modified file 'src/media-player-user.vala'
340--- src/media-player-user.vala 2015-12-29 17:05:16 +0000
341+++ src/media-player-user.vala 2017-03-23 19:32:45 +0000
342@@ -22,7 +22,6 @@
343 string username;
344 Act.User? actuser = null;
345 AccountsServiceSoundSettings? proxy = null;
346- GreeterBroadcast? greeter = null;
347
348 HashTable<string, bool> properties_queued = new HashTable<string, bool>(str_hash, str_equal);
349 uint properties_timeout = 0;
350@@ -46,14 +45,6 @@
351 null,
352 new_proxy);
353 });
354-
355- Bus.get_proxy.begin<GreeterBroadcast> (
356- BusType.SYSTEM,
357- "com.canonical.Unity.Greeter.Broadcast",
358- "/com/canonical/Unity/Greeter/Broadcast",
359- DBusProxyFlags.NONE,
360- null,
361- greeter_proxy_new);
362 }
363
364 ~MediaPlayerUser () {
365@@ -219,15 +210,6 @@
366 set { }
367 }
368
369- void greeter_proxy_new (GLib.Object? obj, AsyncResult res) {
370- try {
371- this.greeter = Bus.get_proxy.end (res);
372- } catch (Error e) {
373- this.greeter = null;
374- warning("Unable to get greeter proxy: %s", e.message);
375- }
376- }
377-
378 /* Control functions through unity-greeter-session-broadcast */
379 public override void activate () {
380 /* TODO: */
381
382=== modified file 'src/service.vala'
383--- src/service.vala 2016-04-15 09:55:49 +0000
384+++ src/service.vala 2017-03-23 19:32:45 +0000
385@@ -73,15 +73,6 @@
386 });
387
388 this.accounts_service = accounts;
389- /* If we're on the greeter, don't export */
390- if (this.accounts_service != null) {
391- this.accounts_service.notify["showDataOnGreeter"].connect(() => {
392- this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
393- eventually_update_player_actions();
394- });
395-
396- this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
397- }
398
399 this.players = playerlist;
400 this.players.player_added.connect (this.player_added);
401
402=== modified file 'tests/CMakeLists.txt'
403--- tests/CMakeLists.txt 2017-02-07 21:50:25 +0000
404+++ tests/CMakeLists.txt 2017-03-23 19:32:45 +0000
405@@ -212,55 +212,6 @@
406 add_test(notifications-test notifications-test)
407
408 ###########################
409-# Accounts Service User
410-###########################
411-
412-include_directories(${CMAKE_SOURCE_DIR}/src)
413-add_executable (media-player-user-test media-player-user.cc)
414-target_link_libraries (
415- media-player-user-test
416- indicator-sound-service-lib
417- vala-mocks-lib
418- ${SOUNDSERVICE_LIBRARIES}
419- ${TEST_LIBRARIES}
420- ${GMOCK_LIBRARIES}
421-)
422-
423-# Split tests to work around libaccountservice sucking
424-add_test(media-player-user-test-basic
425- media-player-user-test --gtest_filter=MediaPlayerUserTest.BasicObject
426-)
427-add_test(media-player-user-test-dataset
428- media-player-user-test --gtest_filter=MediaPlayerUserTest.DataSet
429-)
430-add_test(media-player-user-test-timeout
431- media-player-user-test --gtest_filter=MediaPlayerUserTest.TimeoutTest
432-)
433-
434-###########################
435-# Greeter List
436-###########################
437-
438-include_directories(${CMAKE_SOURCE_DIR}/src)
439-add_executable (greeter-list-test greeter-list.cc)
440-target_link_libraries (
441- greeter-list-test
442- indicator-sound-service-lib
443- vala-mocks-lib
444- ${SOUNDSERVICE_LIBRARIES}
445- ${TEST_LIBRARIES}
446- ${GMOCK_LIBRARIES}
447-)
448-
449-# Split tests to work around libaccountservice sucking
450-add_test(greeter-list-test-basic
451- greeter-list-test --gtest_filter=GreeterListTest.BasicObject
452-)
453-add_test(greeter-list-test-iterator
454- greeter-list-test --gtest_filter=GreeterListTest.BasicIterator
455-)
456-
457-###########################
458 # Indicator Test
459 ###########################
460
461@@ -293,8 +244,6 @@
462 volume-control-test
463 sound-menu-test
464 notifications-test
465- media-player-user-test
466- greeter-list-test
467 indicator-test
468 PARENT_SCOPE
469 )
470
471=== removed file 'tests/greeter-list.cc'
472--- tests/greeter-list.cc 2014-03-25 13:52:31 +0000
473+++ tests/greeter-list.cc 1970-01-01 00:00:00 +0000
474@@ -1,68 +0,0 @@
475-/*
476- * Copyright © 2014 Canonical Ltd.
477- *
478- * This program is free software; you can redistribute it and/or modify
479- * it under the terms of the GNU General Public License as published by
480- * the Free Software Foundation; version 3.
481- *
482- * This program is distributed in the hope that it will be useful,
483- * but WITHOUT ANY WARRANTY; without even the implied warranty of
484- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
485- * GNU General Public License for more details.
486- *
487- * You should have received a copy of the GNU General Public License
488- * along with this program. If not, see <http://www.gnu.org/licenses/>.
489- *
490- * Authors:
491- * Ted Gould <ted@canonical.com>
492- */
493-
494-#include <gtest/gtest.h>
495-#include <gio/gio.h>
496-
497-extern "C" {
498-#include "indicator-sound-service.h"
499-#include "vala-mocks.h"
500-}
501-
502-class GreeterListTest : public ::testing::Test
503-{
504- protected:
505- GTestDBus * bus = nullptr;
506-
507- virtual void SetUp() {
508- bus = g_test_dbus_new(G_TEST_DBUS_NONE);
509- g_test_dbus_up(bus);
510- }
511-
512- virtual void TearDown() {
513- g_test_dbus_down(bus);
514- g_clear_object(&bus);
515- }
516-
517-};
518-
519-TEST_F(GreeterListTest, BasicObject) {
520- MediaPlayerListGreeter * list = media_player_list_greeter_new();
521-
522- ASSERT_NE(nullptr, list);
523-
524- g_clear_object(&list);
525- return;
526-}
527-
528-TEST_F(GreeterListTest, BasicIterator) {
529- MediaPlayerListGreeter * list = media_player_list_greeter_new();
530- ASSERT_NE(nullptr, list);
531-
532- MediaPlayerListGreeterIterator * iter = media_player_list_greeter_iterator_new(list);
533- ASSERT_NE(nullptr, iter);
534-
535- MediaPlayer * player = media_player_list_iterator_next_value (MEDIA_PLAYER_LIST_ITERATOR(iter));
536- ASSERT_EQ(nullptr, player);
537-
538- g_clear_object(&iter);
539- g_clear_object(&list);
540- return;
541-}
542-
543
544=== removed file 'tests/media-player-user.cc'
545--- tests/media-player-user.cc 2015-08-12 00:13:59 +0000
546+++ tests/media-player-user.cc 1970-01-01 00:00:00 +0000
547@@ -1,320 +0,0 @@
548-/*
549- * Copyright © 2014 Canonical Ltd.
550- *
551- * This program is free software; you can redistribute it and/or modify
552- * it under the terms of the GNU General Public License as published by
553- * the Free Software Foundation; version 3.
554- *
555- * This program is distributed in the hope that it will be useful,
556- * but WITHOUT ANY WARRANTY; without even the implied warranty of
557- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
558- * GNU General Public License for more details.
559- *
560- * You should have received a copy of the GNU General Public License
561- * along with this program. If not, see <http://www.gnu.org/licenses/>.
562- *
563- * Authors:
564- * Ted Gould <ted@canonical.com>
565- */
566-
567-#include <chrono>
568-#include <future>
569-
570-#include <gtest/gtest.h>
571-#include <gio/gio.h>
572-#include <libdbustest/dbus-test.h>
573-
574-#include "accounts-service-mock.h"
575-
576-extern "C" {
577-#include "indicator-sound-service.h"
578-}
579-
580-class MediaPlayerUserTest : public ::testing::Test
581-{
582-
583- protected:
584- DbusTestService * testsystem = NULL;
585- AccountsServiceMock service_mock;
586-
587- DbusTestService * testsession = NULL;
588-
589- DbusTestProcess * systemmonitor = nullptr;
590- DbusTestProcess * sessionmonitor = nullptr;
591-
592- GDBusConnection * system = NULL;
593- GDBusConnection * session = NULL;
594- GDBusProxy * proxy = NULL;
595-
596- std::chrono::milliseconds _eventuallyTime = std::chrono::seconds{5};
597-
598- virtual void SetUp() {
599- /* System Bus */
600- testsystem = dbus_test_service_new(NULL);
601- dbus_test_service_set_bus(testsystem, DBUS_TEST_SERVICE_BUS_SYSTEM);
602-
603- systemmonitor = dbus_test_process_new("dbus-monitor");
604- dbus_test_process_append_param(systemmonitor, "--system");
605- dbus_test_task_set_name(DBUS_TEST_TASK(systemmonitor), "System");
606- dbus_test_service_add_task(testsystem, DBUS_TEST_TASK(systemmonitor));
607-
608- dbus_test_service_add_task(testsystem, (DbusTestTask*)service_mock);
609- dbus_test_service_start_tasks(testsystem);
610-
611- system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
612- ASSERT_NE(nullptr, system);
613- g_dbus_connection_set_exit_on_close(system, FALSE);
614- g_object_add_weak_pointer(G_OBJECT(system), (gpointer *)&system);
615-
616- /* Session Bus */
617- testsession = dbus_test_service_new(NULL);
618- dbus_test_service_set_bus(testsession, DBUS_TEST_SERVICE_BUS_SESSION);
619-
620- sessionmonitor = dbus_test_process_new("dbus-monitor");
621- dbus_test_process_append_param(sessionmonitor, "--session");
622- dbus_test_task_set_name(DBUS_TEST_TASK(sessionmonitor), "Session");
623- dbus_test_service_add_task(testsession, DBUS_TEST_TASK(sessionmonitor));
624-
625- dbus_test_service_start_tasks(testsession);
626-
627- session = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
628- ASSERT_NE(nullptr, session);
629- g_dbus_connection_set_exit_on_close(session, FALSE);
630- g_object_add_weak_pointer(G_OBJECT(session), (gpointer *)&session);
631-
632- /* Setup proxy */
633- proxy = g_dbus_proxy_new_sync(system,
634- G_DBUS_PROXY_FLAGS_NONE,
635- NULL,
636- "org.freedesktop.Accounts",
637- "/user",
638- "org.freedesktop.DBus.Properties",
639- NULL, NULL);
640- ASSERT_NE(nullptr, proxy);
641- }
642-
643- virtual void TearDown() {
644- g_clear_object(&sessionmonitor);
645- g_clear_object(&systemmonitor);
646-
647- g_clear_object(&proxy);
648- g_clear_object(&testsystem);
649- g_clear_object(&testsession);
650-
651- g_object_unref(system);
652- g_object_unref(session);
653-
654- #if 0
655- /* Accounts Service keeps a bunch of references around so we
656- have to split the tests and can't check this :-( */
657- unsigned int cleartry = 0;
658- while ((session != NULL || system != NULL) && cleartry < 100) {
659- loop(100);
660- cleartry++;
661- }
662-
663- ASSERT_EQ(nullptr, session);
664- ASSERT_EQ(nullptr, system);
665- #endif
666- }
667-
668- static gboolean timeout_cb (gpointer user_data) {
669- GMainLoop * loop = static_cast<GMainLoop *>(user_data);
670- g_main_loop_quit(loop);
671- return G_SOURCE_REMOVE;
672- }
673-
674- void loop (unsigned int ms) {
675- GMainLoop * loop = g_main_loop_new(NULL, FALSE);
676- g_timeout_add(ms, timeout_cb, loop);
677- g_main_loop_run(loop);
678- g_main_loop_unref(loop);
679- }
680-
681- void set_property (const gchar * name, GVariant * value) {
682- dbus_test_dbus_mock_object_update_property((DbusTestDbusMock *)service_mock, service_mock.get_sound(), name, value, NULL);
683- }
684-
685- testing::AssertionResult expectEventually (std::function<testing::AssertionResult(void)> &testfunc) {
686- auto loop = std::shared_ptr<GMainLoop>(g_main_loop_new(nullptr, FALSE), [](GMainLoop * loop) { if (loop != nullptr) g_main_loop_unref(loop); });
687-
688- std::promise<testing::AssertionResult> retpromise;
689- auto retfuture = retpromise.get_future();
690- auto start = std::chrono::steady_clock::now();
691-
692- /* The core of the idle function as an object so we can use the C++-isms
693- of attaching the variables and make this code reasonably readable */
694- std::function<void(void)> idlefunc = [&loop, &retpromise, &testfunc, &start, this]() -> void {
695- auto result = testfunc();
696-
697- if (result == false && _eventuallyTime > (std::chrono::steady_clock::now() - start)) {
698- return;
699- }
700-
701- retpromise.set_value(result);
702- g_main_loop_quit(loop.get());
703- };
704-
705- auto idlesrc = g_idle_add([](gpointer data) -> gboolean {
706- auto func = reinterpret_cast<std::function<void(void)> *>(data);
707- (*func)();
708- return G_SOURCE_CONTINUE;
709- }, &idlefunc);
710-
711- g_main_loop_run(loop.get());
712- g_source_remove(idlesrc);
713-
714- return retfuture.get();
715- }
716-
717- /* Eventually Helpers */
718- #define _EVENTUALLY_HELPER(oper) \
719- template <typename... Args> testing::AssertionResult expectEventually##oper (Args&& ... args) { \
720- std::function<testing::AssertionResult(void)> func = [&]() { \
721- return testing::internal::CmpHelper##oper(std::forward<Args>(args)...); \
722- }; \
723- return expectEventually(func); \
724- }
725-
726- _EVENTUALLY_HELPER(EQ);
727- _EVENTUALLY_HELPER(NE);
728- _EVENTUALLY_HELPER(LT);
729- _EVENTUALLY_HELPER(GT);
730- _EVENTUALLY_HELPER(STREQ);
731- _EVENTUALLY_HELPER(STRNE);
732-
733- #undef _EVENTUALLY_HELPER
734-};
735-
736-/* Helpers */
737-#define EXPECT_EVENTUALLY_EQ(expected, actual) \
738- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallyEQ, expected, actual)
739-
740-#define EXPECT_EVENTUALLY_NE(expected, actual) \
741- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallyNE, expected, actual)
742-
743-#define EXPECT_EVENTUALLY_LT(expected, actual) \
744- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallyLT, expected, actual)
745-
746-#define EXPECT_EVENTUALLY_GT(expected, actual) \
747- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallyGT, expected, actual)
748-
749-#define EXPECT_EVENTUALLY_STREQ(expected, actual) \
750- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallySTREQ, expected, actual)
751-
752-#define EXPECT_EVENTUALLY_STRNE(expected, actual) \
753- EXPECT_PRED_FORMAT2(MediaPlayerUserTest::expectEventuallySTRNE, expected, actual)
754-
755-
756-TEST_F(MediaPlayerUserTest, BasicObject) {
757- MediaPlayerUser * player = media_player_user_new("user");
758- ASSERT_NE(nullptr, player);
759-
760- /* Protected, but no useful data */
761- EXPECT_FALSE(media_player_get_is_running(MEDIA_PLAYER(player)));
762- EXPECT_TRUE(media_player_get_can_raise(MEDIA_PLAYER(player)));
763- EXPECT_STREQ("user", media_player_get_id(MEDIA_PLAYER(player)));
764- EXPECT_STREQ("", media_player_get_name(MEDIA_PLAYER(player)));
765- EXPECT_STREQ("", media_player_get_state(MEDIA_PLAYER(player)));
766- EXPECT_EQ(nullptr, media_player_get_icon(MEDIA_PLAYER(player)));
767- EXPECT_EQ(nullptr, media_player_get_current_track(MEDIA_PLAYER(player)));
768-
769- /* Get the proxy -- but no good data */
770- loop(100);
771-
772- /* Ensure even with the proxy we don't have anything */
773- EXPECT_FALSE(media_player_get_is_running(MEDIA_PLAYER(player)));
774- EXPECT_TRUE(media_player_get_can_raise(MEDIA_PLAYER(player)));
775- EXPECT_STREQ("user", media_player_get_id(MEDIA_PLAYER(player)));
776- EXPECT_STREQ("", media_player_get_name(MEDIA_PLAYER(player)));
777- EXPECT_STREQ("", media_player_get_state(MEDIA_PLAYER(player)));
778- EXPECT_EQ(nullptr, media_player_get_icon(MEDIA_PLAYER(player)));
779- EXPECT_EQ(nullptr, media_player_get_current_track(MEDIA_PLAYER(player)));
780-
781- g_clear_object(&player);
782-}
783-
784-void
785-running_update (GObject * obj, GParamSpec * pspec, bool * running) {
786- *running = media_player_get_is_running(MEDIA_PLAYER(obj)) == TRUE;
787-};
788-
789-TEST_F(MediaPlayerUserTest, DISABLED_DataSet) {
790- /* Put data into Acts */
791- set_property("Timestamp", g_variant_new_uint64(g_get_monotonic_time()));
792- set_property("PlayerName", g_variant_new_string("The Player Formerly Known as Prince"));
793- GIcon * in_icon = g_themed_icon_new_with_default_fallbacks("foo-bar-fallback");
794- set_property("PlayerIcon", g_variant_new_variant(g_icon_serialize(in_icon)));
795- set_property("State", g_variant_new_string("Chillin'"));
796- set_property("Title", g_variant_new_string("Dictator"));
797- set_property("Artist", g_variant_new_string("Bansky"));
798- set_property("Album", g_variant_new_string("Vinyl is dead"));
799- set_property("ArtUrl", g_variant_new_string("http://art.url"));
800-
801- /* Build our media player */
802- MediaPlayerUser * player = media_player_user_new("user");
803- ASSERT_NE(nullptr, player);
804-
805- /* Ensure even with the proxy we don't have anything */
806- bool running = false;
807- g_signal_connect(G_OBJECT(player), "notify::is-running", G_CALLBACK(running_update), &running);
808- running_update(G_OBJECT(player), nullptr, &running);
809- EXPECT_EVENTUALLY_EQ(true, running);
810- EXPECT_TRUE(media_player_get_can_raise(MEDIA_PLAYER(player)));
811- EXPECT_STREQ("user", media_player_get_id(MEDIA_PLAYER(player)));
812- EXPECT_STREQ("The Player Formerly Known as Prince", media_player_get_name(MEDIA_PLAYER(player)));
813- EXPECT_STREQ("Chillin'", media_player_get_state(MEDIA_PLAYER(player)));
814-
815- GIcon * out_icon = media_player_get_icon(MEDIA_PLAYER(player));
816- EXPECT_NE(nullptr, out_icon);
817- EXPECT_TRUE(g_icon_equal(in_icon, out_icon));
818- // NOTE: No reference in 'out_icon' returned
819-
820- MediaPlayerTrack * track = media_player_get_current_track(MEDIA_PLAYER(player));
821- EXPECT_NE(nullptr, track);
822- EXPECT_STREQ("Dictator", media_player_track_get_title(track));
823- EXPECT_STREQ("Bansky", media_player_track_get_artist(track));
824- EXPECT_STREQ("Vinyl is dead", media_player_track_get_album(track));
825- EXPECT_STREQ("http://art.url", media_player_track_get_art_url(track));
826- // NOTE: No reference in 'track' returned
827-
828- g_clear_object(&in_icon);
829- g_clear_object(&player);
830-}
831-
832-TEST_F(MediaPlayerUserTest, DISABLED_TimeoutTest) {
833- /* Put data into Acts -- but 15 minutes ago */
834- set_property("Timestamp", g_variant_new_uint64(g_get_monotonic_time() - 15 * 60 * 1000 * 1000));
835- set_property("PlayerName", g_variant_new_string("The Player Formerly Known as Prince"));
836- GIcon * in_icon = g_themed_icon_new_with_default_fallbacks("foo-bar-fallback");
837- set_property("PlayerIcon", g_variant_new_variant(g_icon_serialize(in_icon)));
838- set_property("State", g_variant_new_string("Chillin'"));
839- set_property("Title", g_variant_new_string("Dictator"));
840- set_property("Artist", g_variant_new_string("Bansky"));
841- set_property("Album", g_variant_new_string("Vinyl is dead"));
842- set_property("ArtUrl", g_variant_new_string("http://art.url"));
843-
844- /* Build our media player */
845- MediaPlayerUser * player = media_player_user_new("user");
846- ASSERT_NE(nullptr, player);
847-
848- bool running = false;
849- g_signal_connect(G_OBJECT(player), "notify::is-running", G_CALLBACK(running_update), &running);
850- running_update(G_OBJECT(player), nullptr, &running);
851-
852- /* Ensure that we show up as not running */
853- EXPECT_EVENTUALLY_EQ(false, running);
854-
855- /* Update to make running */
856- set_property("Timestamp", g_variant_new_uint64(g_get_monotonic_time()));
857-
858- EXPECT_EVENTUALLY_EQ(true, running);
859-
860- /* Clear to not run */
861- set_property("Timestamp", g_variant_new_uint64(1));
862-
863- EXPECT_EVENTUALLY_EQ(false, running);
864-
865- g_clear_object(&in_icon);
866- g_clear_object(&player);
867-}

Subscribers

People subscribed via source and target branches