From 156418b432ed3d7f07fd0faae67ce5054defe94a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 22 Jan 2013 14:23:57 -0600 Subject: remove g_type_init() calls, bump glib requirement to 2.35.4 --- test/indicator-messages-service-activate.c | 2 -- test/test-gactionmuxer.cpp | 8 -------- 2 files changed, 10 deletions(-) (limited to 'test') diff --git a/test/indicator-messages-service-activate.c b/test/indicator-messages-service-activate.c index 98c6522..b0ec9b7 100644 --- a/test/indicator-messages-service-activate.c +++ b/test/indicator-messages-service-activate.c @@ -28,8 +28,6 @@ with this program. If not, see . int main (int argc, char ** argv) { - g_type_init(); - guint returnval = 0; GError * error = NULL; diff --git a/test/test-gactionmuxer.cpp b/test/test-gactionmuxer.cpp index 6304853..b80f86d 100644 --- a/test/test-gactionmuxer.cpp +++ b/test/test-gactionmuxer.cpp @@ -25,8 +25,6 @@ strv_contains (gchar **str_array, TEST(GActionMuxerTest, Sanity) { GActionMuxer *muxer; - g_type_init (); - g_action_muxer_insert (NULL, NULL, NULL); g_action_muxer_remove (NULL, NULL); @@ -46,8 +44,6 @@ TEST(GActionMuxerTest, Empty) { GActionMuxer *muxer; gchar **actions; - g_type_init (); - muxer = g_action_muxer_new (); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); @@ -67,8 +63,6 @@ TEST(GActionMuxerTest, AddAndRemove) { GActionMuxer *muxer; gchar **actions; - g_type_init (); - group1 = g_simple_action_group_new (); g_simple_action_group_add_entries (group1, entries1, @@ -160,8 +154,6 @@ TEST(GActionMuxerTest, ActionAttributes) { GVariant *state_hint[2]; GVariant *state[2]; - g_type_init (); - group = g_simple_action_group_new (); action = g_simple_action_new ("one", G_VARIANT_TYPE_STRING); g_simple_action_group_insert (group, G_ACTION (action)); -- cgit v1.2.3 From 5c47f6dbe75e413d2acbcef3e9750e937fb18431 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 25 Feb 2013 19:34:56 -0500 Subject: Test libmessaging-menu Use dbusmock to test whether libmessaging-menu calls the right functions on registration and deregistration. --- test/Makefile.am | 10 ++++++++ test/test-client.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100755 test/test-client.py (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 4671446..87ae2c3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -65,3 +65,13 @@ libindicator_messages_service_la_LIBADD = \ libindicator_messages_service_la_LDFLAGS = \ $(COVERAGE_LDFLAGS) + +###################################### +# Test client with dbusmock +###################################### + +TESTS_ENVIRONMENT = \ + export LD_LIBRARY_PATH=$(top_builddir)/libmessaging-menu/.libs; \ + export GI_TYPELIB_PATH=$(top_builddir)/libmessaging-menu; + +TESTS += test-client.py diff --git a/test/test-client.py b/test/test-client.py new file mode 100755 index 0000000..e012d6e --- /dev/null +++ b/test/test-client.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import unittest +import dbus +import dbusmock +import subprocess +from gi.repository import GLib, Gio, MessagingMenu + +class MessagingMenuTest(dbusmock.DBusTestCase): + @classmethod + def setUpClass(klass): + klass.start_session_bus() + klass.bus = klass.get_dbus(False) + + def setUp(self): + name = 'com.canonical.indicator.messages' + obj_path = '/com/canonical/indicator/messages/service' + iface = 'com.canonical.indicator.messages.service' + + self.messaging_service = self.spawn_server(name, obj_path, iface, stdout=subprocess.PIPE) + self.mock = dbus.Interface(self.bus.get_object(name, obj_path), dbusmock.MOCK_IFACE) + self.mock.AddMethod('', 'RegisterApplication', 'so', '', '') + self.mock.AddMethod('', 'UnregisterApplication', 's', '', '') + self.mock.AddMethod('', 'ApplicationStoppedRunning', 's', '', '') + self.mock.AddMethod('', 'SetStatus', 'ss', '', '') + + self.loop = GLib.MainLoop() + + def tearDown(self): + self.messaging_service.terminate() + self.messaging_service.wait() + + def spin_loop(self, ms=10): + GLib.timeout_add(ms, lambda: self.loop.quit()) + self.loop.run() + + def assertMethodCalled(self, name, *expected_args): + calls = self.mock.GetMethodCalls(name) + self.assertEqual(len(calls), 1, 'method %s was not called' % name) + args = calls[0][1] + self.assertEqual(len(args), len(expected_args)) + for i in range(len(args)): + if expected_args[i]: + self.assertEqual(args[i], expected_args[i]) + + def test_registration(self): + mmapp = MessagingMenu.App.new('empathy.desktop') + mmapp.register() + self.spin_loop() + self.assertMethodCalled('RegisterApplication', 'empathy.desktop', None) + + mmapp.unregister() + self.spin_loop() + self.assertMethodCalled('UnregisterApplication', 'empathy.desktop') + + # ApplicationStoppedRunning is called when the last ref on mmapp is dropped + del mmapp + self.spin_loop() + self.assertMethodCalled('ApplicationStoppedRunning', 'empathy.desktop') + + def test_status(self): + mmapp = MessagingMenu.App.new('empathy.desktop') + mmapp.register() + mmapp.set_status(MessagingMenu.Status.AWAY) + self.spin_loop() + self.assertMethodCalled('SetStatus', 'empathy.desktop', 'away') + +unittest.main(testRunner=unittest.TextTestRunner()) -- cgit v1.2.3 From 83b5fdc85d50f68722bd1b2cad69e4519ab9b25f Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 26 Feb 2013 19:34:14 -0500 Subject: Use a special desktop file for testing --- test/Makefile.am | 3 ++- test/applications/test.desktop | 2 ++ test/test-client.py | 12 ++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 test/applications/test.desktop (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 87ae2c3..4f1a163 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -72,6 +72,7 @@ libindicator_messages_service_la_LDFLAGS = \ TESTS_ENVIRONMENT = \ export LD_LIBRARY_PATH=$(top_builddir)/libmessaging-menu/.libs; \ - export GI_TYPELIB_PATH=$(top_builddir)/libmessaging-menu; + export GI_TYPELIB_PATH=$(top_builddir)/libmessaging-menu; \ + export XDG_DATA_DIRS=$(abs_srcdir); TESTS += test-client.py diff --git a/test/applications/test.desktop b/test/applications/test.desktop new file mode 100644 index 0000000..c2332b9 --- /dev/null +++ b/test/applications/test.desktop @@ -0,0 +1,2 @@ +[Desktop Entry] +Type=Application diff --git a/test/test-client.py b/test/test-client.py index e012d6e..af5d119 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -44,25 +44,25 @@ class MessagingMenuTest(dbusmock.DBusTestCase): self.assertEqual(args[i], expected_args[i]) def test_registration(self): - mmapp = MessagingMenu.App.new('empathy.desktop') + mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() self.spin_loop() - self.assertMethodCalled('RegisterApplication', 'empathy.desktop', None) + self.assertMethodCalled('RegisterApplication', 'test.desktop', None) mmapp.unregister() self.spin_loop() - self.assertMethodCalled('UnregisterApplication', 'empathy.desktop') + self.assertMethodCalled('UnregisterApplication', 'test.desktop') # ApplicationStoppedRunning is called when the last ref on mmapp is dropped del mmapp self.spin_loop() - self.assertMethodCalled('ApplicationStoppedRunning', 'empathy.desktop') + self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop') def test_status(self): - mmapp = MessagingMenu.App.new('empathy.desktop') + mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() mmapp.set_status(MessagingMenu.Status.AWAY) self.spin_loop() - self.assertMethodCalled('SetStatus', 'empathy.desktop', 'away') + self.assertMethodCalled('SetStatus', 'test.desktop', 'away') unittest.main(testRunner=unittest.TextTestRunner()) -- cgit v1.2.3 From 701aadff88796f71250442156f6e3385648d7b05 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 27 Feb 2013 12:56:24 -0500 Subject: test-client: wait a bit longer until checking that mock methods were called --- test/test-client.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/test-client.py b/test/test-client.py index af5d119..a4ac8d2 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -30,39 +30,43 @@ class MessagingMenuTest(dbusmock.DBusTestCase): self.messaging_service.terminate() self.messaging_service.wait() - def spin_loop(self, ms=10): - GLib.timeout_add(ms, lambda: self.loop.quit()) - self.loop.run() - - def assertMethodCalled(self, name, *expected_args): - calls = self.mock.GetMethodCalls(name) - self.assertEqual(len(calls), 1, 'method %s was not called' % name) - args = calls[0][1] + def assertArgumentsEqual(self, args, *expected_args): self.assertEqual(len(args), len(expected_args)) for i in range(len(args)): if expected_args[i]: self.assertEqual(args[i], expected_args[i]) + def assertMethodCalled(self, name, *expected_args): + # set a flag on timeout, assertions don't get bubbled up through c functions + self.timed_out = False + def timeout(): self.timed_out = True + timeout_id = GLib.timeout_add_seconds(10, timeout) + while 1: + calls = self.mock.GetMethodCalls(name) + if len(calls) > 0: + GLib.source_remove(timeout_id) + self.assertArgumentsEqual(calls[0][1], *expected_args) + break + GLib.MainContext.default().iteration(True) + if self.timed_out: + raise self.failureException('method %s was not called after 10 seconds' % name) + def test_registration(self): mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() - self.spin_loop() self.assertMethodCalled('RegisterApplication', 'test.desktop', None) mmapp.unregister() - self.spin_loop() self.assertMethodCalled('UnregisterApplication', 'test.desktop') # ApplicationStoppedRunning is called when the last ref on mmapp is dropped del mmapp - self.spin_loop() self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop') def test_status(self): mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() mmapp.set_status(MessagingMenu.Status.AWAY) - self.spin_loop() self.assertMethodCalled('SetStatus', 'test.desktop', 'away') unittest.main(testRunner=unittest.TextTestRunner()) -- cgit v1.2.3 From 36a89063932aea9ae94bf67d9c51d80c01bebaa8 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 5 Mar 2013 17:54:26 -0500 Subject: Use glib mainloop in dbusmock test --- test/test-client.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/test-client.py b/test/test-client.py index a4ac8d2..a1d503f 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -2,10 +2,13 @@ import unittest import dbus +from dbus.mainloop.glib import DBusGMainLoop import dbusmock import subprocess from gi.repository import GLib, Gio, MessagingMenu +DBusGMainLoop(set_as_default=True) + class MessagingMenuTest(dbusmock.DBusTestCase): @classmethod def setUpClass(klass): -- cgit v1.2.3