aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac7
-rw-r--r--src/Makefile.am4
-rw-r--r--src/indicator-sound.c4
-rw-r--r--src/pulse-manager.c2
-rw-r--r--tests/Makefile.am125
-rw-r--r--tests/mockpulse.c99
-rw-r--r--tests/mockpulse.h26
-rw-r--r--tests/test-indicator-sound.c5
-rw-r--r--tests/test-pulse-manager.c80
10 files changed, 302 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am
index 357fa33..9f75289 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS = \
src \
- data \
- tests \
+ data \
+ tests \
po
EXTRA_DIST = autogen.sh
diff --git a/configure.ac b/configure.ac
index 2a465ba..61b1e71 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ INDICATOR_DISPLAY_OBJECTS=0.1.4
PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
indicator >= $INDICATOR_REQUIRED_VERSION
- dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION
+ dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION
libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS)
AC_SUBST(APPLET_CFLAGS)
@@ -42,9 +42,12 @@ AC_SUBST(APPLET_LIBS)
DBUSMENUGLIB_REQUIRED_VERSION=0.1.1
+PKG_CHECK_MODULES(PULSEAUDIO, libpulse-mainloop-glib >= $PULSE_AUDIO_REQUIRED_VERSION)
+AC_SUBST(PULSEAUDIO_CFLAGS)
+AC_SUBST(PULSEAUDIO_LIBS)
+
PKG_CHECK_MODULES(SOUNDSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION
indicator >= $INDICATOR_REQUIRED_VERSION
- libpulse-mainloop-glib >= $PULSE_AUDIO_REQUIRED_VERSION
)
AC_SUBST(SOUNDSERVICE_CFLAGS)
diff --git a/src/Makefile.am b/src/Makefile.am
index b7de930..d9fd14c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,8 +45,8 @@ indicator_sound_service_SOURCES = \
sound-service-server.h \
slider-menu-item.h \
slider-menu-item.c
-indicator_sound_service_CFLAGS = $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
-indicator_sound_service_LDADD = $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
+indicator_sound_service_CFLAGS = $(PULSEAUDIO_CFLAGS) $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
+indicator_sound_service_LDADD = $(PULSEAUDIO_LIBS) $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
sound-service-server.h: $(srcdir)/sound-service.xml
dbus-binding-tool \
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index e9a8e73..3bb5416 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -144,9 +144,9 @@ indicator_sound_class_init (IndicatorSoundClass *klass)
io_class->get_label = get_label;
io_class->get_image = get_icon;
io_class->get_menu = get_menu;
- io_class->scroll = scroll;
+ io_class->scroll = scroll;
- design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
+ design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
return;
}
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index e1634a9..2f86a90 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -463,7 +463,7 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
{
if(index == DEFAULT_SINK_INDEX)
- g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL event triggered");
+ g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL event triggered - default sink has been removed !!");
sound_service_dbus_update_sink_availability(dbus_service, FALSE);
}
else
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4767f76..a0562a4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,12 +1,19 @@
-
check_PROGRAMS = \
test-indicator-sound
# test-indicator-sound-dbus-client \
# test-indicator-sound-dbus-server
-TESTS =
+TESTS = \
+ test-indicator-sound \
+ test-pulse-manager
+
DISTCLEANFILES = $(TESTS)
+noinst_LTLIBRARIES = libmockpulse.la
+libmockpulse_la_SOURCES = mockpulse.c mockpulse.h
+libmockpulse_la_CFLAGS = $(PULSEAUDIO_CFLAGS)
+
+
#########################################
## test-indicator-sound
#########################################
@@ -15,79 +22,113 @@ test_indicator_sound_SOURCES = \
$(top_builddir)/src/indicator-sound.c
test_indicator_sound_CFLAGS = \
+ $(PULSEAUDIO_CFLAGS) \
$(APPLET_CFLAGS) \
-Wall -Werror \
-I$(srcdir) \
-DTOP_BUILD_DIR="\"${abs_top_builddir}\""
test_indicator_sound_LDADD = \
+ libmockpulse.la \
+ $(PULSEAUDIO_LIBS) \
$(APPLET_LIBS)
#########################################
## test-indicator-sound-dbus-client
#########################################
-#test_indicator_sound_dbus_client_SOURCES = \
-# test-defines.h \
-# test-indicator-sound-dbus-client.c
+test_indicator_sound_dbus_client_SOURCES = \
+ test-defines.h \
+ test-indicator-sound-dbus-client.c
-#test_indicator_sound_dbus_client_CFLAGS = \
-# $(SOUNDSERVICE_CFLAGS) \
-# -Wall -Werror \
-# -I$(srcdir)
+test_indicator_sound_dbus_client_CFLAGS = \
+ $(PULSEAUDIO_CFLAGS) \
+ $(SOUNDSERVICE_CFLAGS) \
+ -Wall -Werror \
+ -I$(srcdir) \
+ -I$(SOUNDSERVICE_CFLAGS)
-#test_indicator_sound_dbus_client_LDADD = \
-# $(SOUNDSERVICE_LIBS)
+test_indicator_sound_dbus_client_LDADD = \
+ $(PULSEAUDIO_LIBS) \
+ $(SOUNDSERVICE_LIBS)
########################################
# test-indicator-sound-dbus-server
########################################
-#test_indicator_sound_dbus_server_SOURCES = \
-# test-defines.h \
-# test-indicator-sound-dbus-server.c \
-# $(top_builddir)/src/sound-service-dbus.c \
-# $(top_builddir)/src/pulse-manager.c \
-# $(top_builddir)/src/slider-menu-item.c \
-# $(top_builddir)/src/dbus-menu-manager.c
+test_indicator_sound_dbus_server_SOURCES = \
+ test-defines.h \
+ test-indicator-sound-dbus-server.c \
+ $(top_builddir)/src/sound-service-dbus.c \
+ $(top_builddir)/src/pulse-manager.c \
+ $(top_builddir)/src/slider-menu-item.c \
+ $(top_builddir)/src/dbus-menu-manager.c
+
+test_indicator_sound_dbus_server_CFLAGS = \
+ $(SOUNDSERVICE_CFLAGS) \
+ -Wall -Werror \
+ -I$(srcdir)
+
+test_indicator_sound_dbus_server_LDADD = \
+ $(SOUNDSERVICE_LIBS) \
+ $(PULSEAUDIO_LIBS)
-#test_indicator_sound_dbus_server_CFLAGS = \
-# $(SOUNDSERVICE_CFLAGS) \
-# -Wall -Werror \
-# -I$(srcdir)
+#########################################
+## test-pulse-manager
+#########################################
+
+check_PROGRAMS += test-pulse-manager
+
+test_pulse_manager_SOURCES = \
+ test-pulse-manager.c \
+ $(top_builddir)/src/dbus-menu-manager.c \
+ $(top_builddir)/src/sound-service-dbus.c \
+ $(top_builddir)/src/slider-menu-item.c
-#test_indicator_sound_dbus_server_LDADD = \
-# $(SOUNDSERVICE_LIBS)
+test_pulse_manager_CFLAGS = \
+ $(PULSEAUDIO_CFLAGS) \
+ $(SOUNDSERVICE_CFLAGS) \
+ $(GCONF_CFLAGS) \
+ -Wall -Werror \
+ -I$(srcdir) \
+ -I$(SOUNDSERVICE_CFLAGS)
+test_pulse_manager_LDADD = \
+ libmockpulse.la \
+ $(PULSEAUDIO_LIBS) \
+ $(SOUNDSERVICE_LIBS) \
+ $(GCONF_LIBS) \
+ $(APPLET_LIBS)
#########################################
## Actual tests
#########################################
-#XML_REPORT = indicator-sound-check-results.xml
-#HTML_REPORT = indicator-sound-check-results.html
+XML_REPORT = indicator-sound-check-results.xml
+HTML_REPORT = indicator-sound-check-results.html
+
+indicator-sound-tests: indicator-sound-tests-gtester Makefile.am
+ @echo "#!/bin/sh" > $@
+ @echo $(DBUS_RUNNER) --task ./indicator-sound-tests-gtester >> $@
+ @chmod +x $@
-#indicator-sound-tests: indicator-sound-tests-gtester Makefile.am
-# @echo "#!/bin/sh" > $@
-# @echo $(DBUS_RUNNER) --task ./indicator-sound-tests-gtester >> $@
-# @chmod +x $@
+indicator-sound-tests-gtester: test-indicator-sound Makefile.am
+ @echo "#!/bin/sh" > $@
+ @echo gtester -k --verbose -o=indicator-sound-check-results.xml ./test-indicator-sound >> $@
+ @chmod +x $@
-#indicator-sound-tests-gtester: test-indicator-sound Makefile.am
-# @echo "#!/bin/sh" > $@
-# @echo gtester -k --verbose -o=$(XML_REPORT) ./test-indicator-sound >> $@
-# @chmod +x $@
+ TESTS += indicator-sound-tests-gtester
-#TESTS += indicator-sound-tests
+DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) indicator-sound-tests-gtester
-#DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) indicator-sound-tests-gtester
+DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
-#DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
+test-indicator-sound-dbus: test-indicator-sound-dbus-client test-indicator-sound-dbus-server Makefile.am
+ @echo "#!/bin/sh" > test-indicator-sound-dbus
+ @echo $(DBUS_RUNNER) --task ./test-indicator-sound-dbus-client --task-name Client --task ./test-indicator-sound-dbus-server --task-name Server --ignore-return >> test-indicator-sound-dbus
+ @chmod +x test-indicator-sound-dbus
-#test-indicator-sound-dbus: test-indicator-sound-dbus-client test-indicator-sound-dbus-server Makefile.am
-# @echo "#!/bin/sh" > test-indicator-sound-dbus
-# @echo $(DBUS_RUNNER) --task ./test-indicator-sound-dbus-client --task-name Client --task ./test-indicator-sound-dbus-server --task-name Server --ignore-return >> test-indicator-sound-dbus
-# @chmod +x test-indicator-sound-dbus
+TESTS += test-indicator-sound-dbus
-#TESTS += test-indicator-sound-dbus
diff --git a/tests/mockpulse.c b/tests/mockpulse.c
new file mode 100644
index 0000000..a41de30
--- /dev/null
+++ b/tests/mockpulse.c
@@ -0,0 +1,99 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Robert Collins <robert.collins@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <pulse/glib-mainloop.h>
+#include <pulse/context.h>
+#include <pulse/operation.h>
+#include <pulse/introspect.h>
+#include "mockpulse.h"
+
+struct pa_context {
+ int refcount;
+ pa_context_notify_cb_t cb;
+ void *cbdata;
+ pa_context_state_t state;
+};
+
+pa_glib_mainloop *
+pa_glib_mainloop_new(GMainContext *c)
+{
+ return NULL;
+}
+
+pa_context *
+pa_context_new(pa_mainloop_api *loop, char const *name) {
+ struct pa_context * result = g_new(pa_context, 1);
+ result->refcount = 1;
+ return result;
+}
+
+void
+pa_context_unref(pa_context * context) {
+ context->refcount--;
+ if (!context->refcount)
+ g_free(context);
+}
+
+void
+pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, void *userdata)
+{
+ c->cb = cb;
+ c->cbdata = userdata;
+}
+
+void set_pa_context_get_state_result(pa_context *c, pa_context_state_t state)
+{
+ c->state = state;
+}
+
+pa_context_state_t
+pa_context_get_state(pa_context *c)
+{
+ return c->state;
+}
+
+struct pa_operation {
+ int refcount;
+};
+
+/* Can be made into a list if we need multiple callbacks */
+static pa_sink_info *next_sink_info;
+
+void
+set_pa_context_get_sink_info(pa_sink_info *info) {
+ next_sink_info = info;
+}
+
+pa_operation *
+pa_context_get_sink_info_by_index(pa_context *c, uint32_t idx, pa_sink_info_cb_t cb, void * userdata)
+{
+ pa_operation *result = g_new(pa_operation, 1);
+ result->refcount = 1;
+ cb(c, next_sink_info, 0, userdata);
+ return result;
+}
+
+void
+pa_operation_unref(pa_operation * foo)
+{
+ foo->refcount--;
+ if (!foo->refcount)
+ g_free(foo);
+}
diff --git a/tests/mockpulse.h b/tests/mockpulse.h
new file mode 100644
index 0000000..71cd85b
--- /dev/null
+++ b/tests/mockpulse.h
@@ -0,0 +1,26 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Robert Collins <robert.collins@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * Control interface for the mocked pa-glib-mainloop test library
+ */
+#include <pulse/glib-mainloop.h>
+
+void set_pa_context_get_state_result(pa_context *, pa_context_state_t state);
+void set_pa_context_get_sink_info(pa_sink_info *info);
diff --git a/tests/test-indicator-sound.c b/tests/test-indicator-sound.c
index eb68b17..cd28587 100644
--- a/tests/test-indicator-sound.c
+++ b/tests/test-indicator-sound.c
@@ -86,14 +86,13 @@ void test_libindicator_image_names()
}
-
gint main (gint argc, gchar * argv[])
{
g_type_init();
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/indicator-sound/indicator-sound/init", test_libindicator_sound_init);
- g_test_add_func("/indicator-sound/indicator-sound/state_machine", test_libindicator_determine_state);
+/* g_test_add_func("/indicator-sound/indicator-sound/init", test_libindicator_sound_init);*/
+/* g_test_add_func("/indicator-sound/indicator-sound/state_machine", test_libindicator_determine_state);*/
g_test_add_func("/indicator-sound/indicator-sound/image_names", test_libindicator_image_names);
return g_test_run ();
diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c
new file mode 100644
index 0000000..169acbd
--- /dev/null
+++ b/tests/test-pulse-manager.c
@@ -0,0 +1,80 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Robert Collins <robert.collins@canonical.com>
+ Conor Curran <conor.curran@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* we test static functions */
+#include "../src/pulse-manager.c"
+#include "mockpulse.h"
+
+
+static void test_pa_context_exit()
+{
+ pa_context* context = pa_context_new(NULL, "foo");
+ pa_context_set_state_callback(context, context_state_callback, NULL);
+ // => call context_state_callback(context, NULL);
+ // pa_context_get_state is mocked to return the right FAIL flag.
+ set_pa_context_get_state_result(context, PA_CONTEXT_FAILED);
+ context_state_callback(context, NULL);
+ // 1. test to make sure relevant variables are tidied up
+ // XXX: Conor to do.
+ // 2. then using the same pa_context_get_state we could ensure the manager
+ // is attempting to reconnect to PA.
+ pa_context_unref(context);
+}
+
+static void test_sink_insert()
+{
+ sink_info *sink_details;
+ pa_context* context = pa_context_new(NULL, "foo");
+ sink_details = g_new0(sink_info, 1);
+ sink_details->index = 8;
+ sink_details->name = "mock_sink";
+ sink_details->description = "mock description";
+ sink_details->mute = FALSE;
+ pa_cvolume volume; // nearly full volume:
+ pa_cvolume_set(&volume, 1, 30000);
+ sink_details->volume = volume;
+ pa_sink_info *expected = g_new0(pa_sink_info, 1);
+ expected->name = g_strdup("foo");
+ expected->index = 8;
+ expected->description = g_strdup("more details");
+ // fill it out here more.
+ // hook into our pa_context_get_sink_info_by_index to pass exppected to
+ // update_sink_info
+ set_pa_context_get_sink_info(expected);
+ // update_sink_info is a static method in pulse-manager.c ?
+ pa_context_get_sink_info_by_index(context, sink_details->index, update_sink_info, NULL);
+ // the mockinkg lib should then return this mocked up sink_info to the
+ // method update_sink_info which tests could be wrote against to make sure
+ // everthing is populated correctly.
+ pa_context_unref(context);
+ g_free(expected);
+}
+
+
+gint main (gint argc, gchar * argv[])
+{
+ g_type_init();
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/indicator-sound/pulse-manager/sink-insert", test_sink_insert);
+ g_test_add_func("/indicator-sound/pulse-manager/pa-context-exit", test_pa_context_exit);
+
+ return g_test_run ();
+}