[libgnome-volume-control] tests: Add a Makefile for tests



commit 2a117d60245cbdd892cdf92aacb2e8f645dcb5e1
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Apr 17 20:42:08 2016 +0200

    tests: Add a Makefile for tests
    
    And add a test for the audio device selection feature, added in
    GNOME 3.20.

 .gitignore                    |    1 +
 Makefile.tests                |   43 ++++++++++++++++++++++++++++
 test-audio-device-selection.c |   62 +++++++++++++++++++++++++++++++++++++++++
 tests-include/config.h        |    3 ++
 4 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 942d240..eb3554e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ Makefile
 *.o
 *.gir
 *.typelib
+test-audio-device-selection
diff --git a/Makefile.tests b/Makefile.tests
new file mode 100644
index 0000000..813630e
--- /dev/null
+++ b/Makefile.tests
@@ -0,0 +1,43 @@
+LIBGVC_SOURCES =                               \
+       gvc-mixer-card.h                        \
+       gvc-mixer-card.c                        \
+       gvc-mixer-stream.h                      \
+       gvc-mixer-stream.c                      \
+       gvc-channel-map.h                       \
+       gvc-channel-map.c                       \
+       gvc-mixer-ui-device.h                   \
+       gvc-mixer-ui-device.c                   \
+       gvc-mixer-sink.h                        \
+       gvc-mixer-sink.c                        \
+       gvc-mixer-source.h                      \
+       gvc-mixer-source.c                      \
+       gvc-mixer-sink-input.h                  \
+       gvc-mixer-sink-input.c                  \
+       gvc-mixer-source-output.h               \
+       gvc-mixer-source-output.c               \
+       gvc-mixer-event-role.h                  \
+       gvc-mixer-event-role.c                  \
+       gvc-mixer-control.h                     \
+       gvc-mixer-control.c                     \
+       gvc-mixer-card-private.h                \
+       gvc-mixer-stream-private.h              \
+       gvc-channel-map-private.h               \
+       gvc-mixer-control-private.h             \
+       gvc-pulseaudio-fake.h
+
+GVC_CFLAGS = `pkg-config --cflags gtk+-3.0 libpulse libpulse-mainloop-glib alsa`
+GVC_LIBS = `pkg-config --libs gtk+-3.0 libpulse libpulse-mainloop-glib alsa`
+
+all: test-audio-device-selection $(LIBGVC_SOURCES) tests-include/config.h
+
+.c.o:
+       $(CC) -c $(GVC_CFLAGS) -I. -Itests-include/ $< -o $@
+
+C_SOURCES = $(filter %.c,$(LIBGVC_SOURCES))
+OBJECTS=$(C_SOURCES:.c=.o)
+
+test-audio-device-selection: $(OBJECTS) test-audio-device-selection.o
+       $(CC) $(GVC_LIBS) $(OBJECTS) test-audio-device-selection.o -o $@
+
+clean:
+       rm -f *.o test-audio-device-selection
diff --git a/test-audio-device-selection.c b/test-audio-device-selection.c
new file mode 100644
index 0000000..efc6d66
--- /dev/null
+++ b/test-audio-device-selection.c
@@ -0,0 +1,62 @@
+
+#include <pulse/pulseaudio.h>
+#include "gvc-mixer-control.h"
+
+typedef struct {
+       GvcHeadsetPortChoice choice;
+       gchar *name;
+} AudioSelectionChoice;
+
+static AudioSelectionChoice audio_selection_choices[] = {
+       { GVC_HEADSET_PORT_CHOICE_HEADPHONES,   "headphones" },
+       { GVC_HEADSET_PORT_CHOICE_HEADSET,      "headset" },
+       { GVC_HEADSET_PORT_CHOICE_MIC,          "microphone" },
+};
+
+static void
+audio_selection_needed (GvcMixerControl      *control,
+                       guint                 id,
+                       gboolean              show_dialog,
+                       GvcHeadsetPortChoice  choices,
+                       gpointer              user_data)
+{
+       char *args[G_N_ELEMENTS (audio_selection_choices) + 1];
+       char *choices_str;
+       guint i, n;
+
+       if (!show_dialog) {
+               g_print ("Audio selection not needed anymore for id %d\n", id);
+               return;
+       }
+
+       n = 0;
+       for (i = 0; i < G_N_ELEMENTS (audio_selection_choices); ++i) {
+               if (choices & audio_selection_choices[i].choice)
+                       args[n++] = audio_selection_choices[i].name;
+       }
+       args[n] = NULL;
+
+       choices_str = g_strjoinv (", ", args);
+       g_print ("+++ Audio selection needed for id %d\n", id);
+       g_print ("    Choices are: %s\n", choices_str);
+       g_free (choices_str);
+}
+
+int main (int argc, char **argv)
+{
+       GMainLoop *loop;
+       GvcMixerControl *volume;
+
+       loop = g_main_loop_new (NULL, FALSE);
+
+       volume = gvc_mixer_control_new ("GNOME Volume Control test");
+       g_signal_connect (volume,
+                         "audio-device-selection-needed",
+                         G_CALLBACK (audio_selection_needed),
+                         NULL);
+       gvc_mixer_control_open (volume);
+
+       g_main_loop_run (loop);
+
+       return 0;
+}
diff --git a/tests-include/config.h b/tests-include/config.h
new file mode 100644
index 0000000..9326f4c
--- /dev/null
+++ b/tests-include/config.h
@@ -0,0 +1,3 @@
+#define GETTEXT_PACKAGE "libgvc-test"
+#define PACKAGE_VERSION "1.0-test"
+#define HAVE_ALSA       1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]