Merge lp:~larsu/indicator-messages/notify-stopped-running into lp:~indicator-applet-developers/indicator-messages/trunk.13.10

Proposed by Lars Karlitski
Status: Merged
Approved by: Ted Gould
Approved revision: 343
Merged at revision: 348
Proposed branch: lp:~larsu/indicator-messages/notify-stopped-running
Merge into: lp:~indicator-applet-developers/indicator-messages/trunk.13.10
Diff against target: 288 lines (+183/-6)
9 files modified
configure.ac (+12/-6)
debian/control (+1/-0)
libmessaging-menu/messaging-menu.c (+4/-0)
m4/ax_python_module.m4 (+49/-0)
src/messages-service.c (+25/-0)
src/messages-service.xml (+4/-0)
test/Makefile.am (+11/-0)
test/applications/test.desktop (+2/-0)
test/test-client.py (+75/-0)
To merge this branch: bzr merge lp:~larsu/indicator-messages/notify-stopped-running
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Mathieu Trudel-Lapierre Pending
Review via email: mp+168202@code.launchpad.net

This proposal supersedes a proposal from 2013-06-07.

Commit message

Notify the service when an app unrefs its MessagingMenuApp

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote : Posted in a previous version of this proposal

Can we add some kind of automated test for this?

review: Needs Information
Revision history for this message
Lars Karlitski (larsu) wrote : Posted in a previous version of this proposal

You're right of course. I didn't add them originally because the client lib wasn't tested at all.

Added testing for registration in r338.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote : Posted in a previous version of this proposal

Look fine, however both autoconf-archive and python3-dbusmock are in universe and are going to need to get to main for indicator-messages to be buildable once released with this changeset.

Can you please follow the steps in the wiki for the Main Inclusion Process and file the appropriate two bugs for this?

https://wiki.ubuntu.com/MainInclusionProcess

review: Needs Information
Revision history for this message
Ted Gould (ted) wrote :

Looks like Mathieu's issues have been solved with dbusmock getting into main and autoconf-archive being removed.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-01-22 20:30:05 +0000
3+++ configure.ac 2013-06-07 21:40:41 +0000
4@@ -75,7 +75,7 @@
5 AC_SUBST(COVERAGE_LDFLAGS)
6
7 ###########################
8-# Google Test framework
9+# Tests
10 ###########################
11
12 AC_ARG_ENABLE([tests],
13@@ -85,10 +85,16 @@
14 if test "x$enable_tests" != "xno"; then
15 m4_include([m4/gtest.m4])
16 CHECK_GTEST
17- if test "x$enable_tests" = "xauto"; then
18- enable_tests=${have_gtest}
19- elif test "x$enable_tests" = "xyes" && test "x$have_gtest" != "xyes"; then
20- AC_MSG_ERROR([tests were requested but gtest is not installed.])
21+ AM_PATH_PYTHON(3.0,, [:])
22+ AC_PYTHON_MODULE(dbusmock)
23+ if test "x$have_gtest" = "xyes" -a "x$HAVE_PYMOD_DBUSMOCK" = "xyes"; then
24+ enable_tests="yes"
25+ else
26+ if test "x$enable_tests" = "xyes"; then
27+ AC_MSG_ERROR([tests were requested but gtest or dbusmock are not installed.])
28+ else
29+ enable_tests="no"
30+ fi
31 fi
32 fi
33 AM_CONDITIONAL([BUILD_TESTS],[test "x$enable_tests" = "xyes"])
34@@ -193,7 +199,7 @@
35
36 Prefix: $prefix
37 Indicator Dir: $INDICATORDIR
38- gtest: $enable_tests
39+ tests: $enable_tests
40 gcov: $use_gcov
41 introspecion: $enable_introspection
42 documentation: $enable_gtk_doc
43
44=== modified file 'debian/control'
45--- debian/control 2013-06-07 12:19:11 +0000
46+++ debian/control 2013-06-07 21:40:41 +0000
47@@ -19,6 +19,7 @@
48 libgirepository1.0-dev (>= 0.9.12),
49 gtk-doc-tools,
50 libgtest-dev,
51+ python3-dbusmock,
52 Standards-Version: 3.9.3
53 Homepage: https://launchpad.net/indicator-messages
54 # If you aren't a member of ~indicator-applet-developers but need to upload
55
56=== modified file 'libmessaging-menu/messaging-menu.c'
57--- libmessaging-menu/messaging-menu.c 2013-05-15 16:09:18 +0000
58+++ libmessaging-menu/messaging-menu.c 2013-06-07 21:40:41 +0000
59@@ -277,6 +277,10 @@
60
61 if (app->messages_service)
62 {
63+ indicator_messages_service_call_application_stopped_running (app->messages_service,
64+ g_app_info_get_id (G_APP_INFO (app->appinfo)),
65+ NULL, NULL, NULL);
66+
67 g_signal_handlers_disconnect_by_func (app->messages_service,
68 global_status_changed,
69 app);
70
71=== added file 'm4/ax_python_module.m4'
72--- m4/ax_python_module.m4 1970-01-01 00:00:00 +0000
73+++ m4/ax_python_module.m4 2013-06-07 21:40:41 +0000
74@@ -0,0 +1,49 @@
75+# ===========================================================================
76+# http://www.gnu.org/software/autoconf-archive/ax_python_module.html
77+# ===========================================================================
78+#
79+# SYNOPSIS
80+#
81+# AX_PYTHON_MODULE(modname[, fatal])
82+#
83+# DESCRIPTION
84+#
85+# Checks for Python module.
86+#
87+# If fatal is non-empty then absence of a module will trigger an error.
88+#
89+# LICENSE
90+#
91+# Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
92+#
93+# Copying and distribution of this file, with or without modification, are
94+# permitted in any medium without royalty provided the copyright notice
95+# and this notice are preserved. This file is offered as-is, without any
96+# warranty.
97+
98+#serial 5
99+
100+AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE])
101+AC_DEFUN([AX_PYTHON_MODULE],[
102+ if test -z $PYTHON;
103+ then
104+ PYTHON="python"
105+ fi
106+ PYTHON_NAME=`basename $PYTHON`
107+ AC_MSG_CHECKING($PYTHON_NAME module: $1)
108+ $PYTHON -c "import $1" 2>/dev/null
109+ if test $? -eq 0;
110+ then
111+ AC_MSG_RESULT(yes)
112+ eval AS_TR_CPP(HAVE_PYMOD_$1)=yes
113+ else
114+ AC_MSG_RESULT(no)
115+ eval AS_TR_CPP(HAVE_PYMOD_$1)=no
116+ #
117+ if test -n "$2"
118+ then
119+ AC_MSG_ERROR(failed to find required module $1)
120+ exit 1
121+ fi
122+ fi
123+])
124
125=== modified file 'src/messages-service.c'
126--- src/messages-service.c 2013-04-03 15:40:56 +0000
127+++ src/messages-service.c 2013-06-07 21:40:41 +0000
128@@ -474,6 +474,29 @@
129 }
130
131 static void
132+application_stopped_running (IndicatorMessagesService *service,
133+ GDBusMethodInvocation *invocation,
134+ const gchar *desktop_id,
135+ gpointer user_data)
136+{
137+ GDesktopAppInfo *appinfo;
138+ gchar *id;
139+ AppSection *section;
140+
141+ indicator_messages_service_complete_application_stopped_running (service, invocation);
142+
143+ if (!(appinfo = g_desktop_app_info_new (desktop_id)))
144+ return;
145+
146+ id = g_app_info_get_simple_id (G_APP_INFO (appinfo));
147+ section = g_hash_table_lookup (applications, id);
148+ app_section_unset_object_path (section);
149+
150+ g_free (id);
151+ g_object_unref (appinfo);
152+}
153+
154+static void
155 set_status (IndicatorMessagesService *service,
156 GDBusMethodInvocation *invocation,
157 const gchar *desktop_id,
158@@ -650,6 +673,8 @@
159 G_CALLBACK (register_application), NULL);
160 g_signal_connect (messages_service, "handle-unregister-application",
161 G_CALLBACK (unregister_application), NULL);
162+ g_signal_connect (messages_service, "handle-application-stopped-running",
163+ G_CALLBACK (application_stopped_running), NULL);
164 g_signal_connect (messages_service, "handle-set-status",
165 G_CALLBACK (set_status), NULL);
166
167
168=== modified file 'src/messages-service.xml'
169--- src/messages-service.xml 2012-09-18 19:54:37 +0000
170+++ src/messages-service.xml 2013-06-07 21:40:41 +0000
171@@ -11,6 +11,10 @@
172 <arg type="s" name="desktop_id" direction="in" />
173 </method>
174
175+ <method name="ApplicationStoppedRunning">
176+ <arg type="s" name="desktop_id" direction="in" />
177+ </method>
178+
179 <method name="SetStatus">
180 <arg type="s" name="desktop_id" direction="in" />
181 <arg type="s" name="status" direction="in" />
182
183=== modified file 'test/Makefile.am'
184--- test/Makefile.am 2012-08-21 10:07:19 +0000
185+++ test/Makefile.am 2013-06-07 21:40:41 +0000
186@@ -65,3 +65,14 @@
187
188 libindicator_messages_service_la_LDFLAGS = \
189 $(COVERAGE_LDFLAGS)
190+
191+######################################
192+# Test client with dbusmock
193+######################################
194+
195+TESTS_ENVIRONMENT = \
196+ export LD_LIBRARY_PATH=$(top_builddir)/libmessaging-menu/.libs; \
197+ export GI_TYPELIB_PATH=$(top_builddir)/libmessaging-menu; \
198+ export XDG_DATA_DIRS=$(abs_srcdir);
199+
200+TESTS += test-client.py
201
202=== added directory 'test/applications'
203=== added file 'test/applications/test.desktop'
204--- test/applications/test.desktop 1970-01-01 00:00:00 +0000
205+++ test/applications/test.desktop 2013-06-07 21:40:41 +0000
206@@ -0,0 +1,2 @@
207+[Desktop Entry]
208+Type=Application
209
210=== added file 'test/test-client.py'
211--- test/test-client.py 1970-01-01 00:00:00 +0000
212+++ test/test-client.py 2013-06-07 21:40:41 +0000
213@@ -0,0 +1,75 @@
214+#!/usr/bin/env python3
215+
216+import unittest
217+import dbus
218+from dbus.mainloop.glib import DBusGMainLoop
219+import dbusmock
220+import subprocess
221+from gi.repository import GLib, Gio, MessagingMenu
222+
223+DBusGMainLoop(set_as_default=True)
224+
225+class MessagingMenuTest(dbusmock.DBusTestCase):
226+ @classmethod
227+ def setUpClass(klass):
228+ klass.start_session_bus()
229+ klass.bus = klass.get_dbus(False)
230+
231+ def setUp(self):
232+ name = 'com.canonical.indicator.messages'
233+ obj_path = '/com/canonical/indicator/messages/service'
234+ iface = 'com.canonical.indicator.messages.service'
235+
236+ self.messaging_service = self.spawn_server(name, obj_path, iface, stdout=subprocess.PIPE)
237+ self.mock = dbus.Interface(self.bus.get_object(name, obj_path), dbusmock.MOCK_IFACE)
238+ self.mock.AddMethod('', 'RegisterApplication', 'so', '', '')
239+ self.mock.AddMethod('', 'UnregisterApplication', 's', '', '')
240+ self.mock.AddMethod('', 'ApplicationStoppedRunning', 's', '', '')
241+ self.mock.AddMethod('', 'SetStatus', 'ss', '', '')
242+
243+ self.loop = GLib.MainLoop()
244+
245+ def tearDown(self):
246+ self.messaging_service.terminate()
247+ self.messaging_service.wait()
248+
249+ def assertArgumentsEqual(self, args, *expected_args):
250+ self.assertEqual(len(args), len(expected_args))
251+ for i in range(len(args)):
252+ if expected_args[i]:
253+ self.assertEqual(args[i], expected_args[i])
254+
255+ def assertMethodCalled(self, name, *expected_args):
256+ # set a flag on timeout, assertions don't get bubbled up through c functions
257+ self.timed_out = False
258+ def timeout(): self.timed_out = True
259+ timeout_id = GLib.timeout_add_seconds(10, timeout)
260+ while 1:
261+ calls = self.mock.GetMethodCalls(name)
262+ if len(calls) > 0:
263+ GLib.source_remove(timeout_id)
264+ self.assertArgumentsEqual(calls[0][1], *expected_args)
265+ break
266+ GLib.MainContext.default().iteration(True)
267+ if self.timed_out:
268+ raise self.failureException('method %s was not called after 10 seconds' % name)
269+
270+ def test_registration(self):
271+ mmapp = MessagingMenu.App.new('test.desktop')
272+ mmapp.register()
273+ self.assertMethodCalled('RegisterApplication', 'test.desktop', None)
274+
275+ mmapp.unregister()
276+ self.assertMethodCalled('UnregisterApplication', 'test.desktop')
277+
278+ # ApplicationStoppedRunning is called when the last ref on mmapp is dropped
279+ del mmapp
280+ self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop')
281+
282+ def test_status(self):
283+ mmapp = MessagingMenu.App.new('test.desktop')
284+ mmapp.register()
285+ mmapp.set_status(MessagingMenu.Status.AWAY)
286+ self.assertMethodCalled('SetStatus', 'test.desktop', 'away')
287+
288+unittest.main(testRunner=unittest.TextTestRunner())

Subscribers

People subscribed via source and target branches