summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2016-04-17 22:26:16 +0200
committerBastien Nocera <hadess@hadess.net>2016-04-17 22:27:26 +0200
commit8fc9c62a69b78ceeb349b1aa753dbcfca8971192 (patch)
tree0d1fe081b46ed140a89fcecb7e34fbc4885af699
parent2a117d60245cbdd892cdf92aacb2e8f645dcb5e1 (diff)
downloadlibgnome-volume-control-8fc9c62a69b78ceeb349b1aa753dbcfca8971192.tar.gz
tests: Add audio device selection question
So that the test utility mimicks the code in gnome-settings-daemon.
-rw-r--r--Makefile.tests4
-rw-r--r--test-audio-device-selection.c34
2 files changed, 30 insertions, 8 deletions
diff --git a/Makefile.tests b/Makefile.tests
index 813630e..a05689c 100644
--- a/Makefile.tests
+++ b/Makefile.tests
@@ -31,13 +31,13 @@ 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 $@
+ $(CC) -g3 -ggdb -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 $@
+ $(CC) -g3 -ggdb $(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
index efc6d66..294c0f7 100644
--- a/test-audio-device-selection.c
+++ b/test-audio-device-selection.c
@@ -1,7 +1,11 @@
+#include <stdio.h>
+#include <locale.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-control.h"
+#define MAX_ATTEMPTS 3
+
typedef struct {
GvcHeadsetPortChoice choice;
gchar *name;
@@ -14,18 +18,18 @@ static AudioSelectionChoice audio_selection_choices[] = {
};
static void
-audio_selection_needed (GvcMixerControl *control,
+audio_selection_needed (GvcMixerControl *volume,
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;
+ int response = -1;
if (!show_dialog) {
- g_print ("Audio selection not needed anymore for id %d\n", id);
+ g_print ("--- Audio selection not needed anymore for id %d\n", id);
return;
}
@@ -36,10 +40,26 @@ audio_selection_needed (GvcMixerControl *control,
}
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);
+ g_print (" Choices are: %s\n");
+ for (i = 0; args[i] != NULL; i++)
+ g_print (" %d. %s\n", i + 1, args[i]);
+
+ for (i = 0; response < 0 && i < MAX_ATTEMPTS; i++) {
+ int res;
+
+ g_print ("What is your choice?\n");
+ if (scanf ("%d", &res) == 1 &&
+ res > 0 &&
+ res < g_strv_length (args)) {
+ response = res;
+ break;
+ }
+ }
+
+ gvc_mixer_control_set_headset_port (volume,
+ id,
+ audio_selection_choices[response - 1].choice);
}
int main (int argc, char **argv)
@@ -47,6 +67,8 @@ int main (int argc, char **argv)
GMainLoop *loop;
GvcMixerControl *volume;
+ setlocale (LC_ALL, "");
+
loop = g_main_loop_new (NULL, FALSE);
volume = gvc_mixer_control_new ("GNOME Volume Control test");