tests: Add a Makefile for tests

And add a test for the audio device selection feature, added in
GNOME 3.20.
This commit is contained in:
Bastien Nocera 2016-04-17 20:42:08 +02:00
parent 0a500795bd
commit 2a117d6024
4 changed files with 109 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ Makefile
*.o
*.gir
*.typelib
test-audio-device-selection

43
Makefile.tests Normal file
View File

@ -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

View File

@ -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;
}

3
tests-include/config.h Normal file
View File

@ -0,0 +1,3 @@
#define GETTEXT_PACKAGE "libgvc-test"
#define PACKAGE_VERSION "1.0-test"
#define HAVE_ALSA 1