3 * unit test for alsa elements
5 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
24 * with newer GLib versions (>= 2.31.0) */
25 #define GLIB_DISABLE_DEPRECATION_WARNINGS
29 #include <gst/check/gstcheck.h>
30 #include <gst/audio/mixer.h>
33 /* just a simple test that runs device probing on
34 * an alsasrc, alsasink and alsamixer instance */
36 GST_START_TEST (test_device_property_probe)
38 const gchar *elements[] = { "alsasink", "alsasrc", "alsamixer" };
41 for (n = 0; n < G_N_ELEMENTS (elements); ++n) {
42 GstPropertyProbe *probe;
47 element = gst_element_factory_make (elements[n], elements[n]);
48 fail_unless (element != NULL);
50 probe = GST_PROPERTY_PROBE (element);
51 fail_unless (probe != NULL);
53 arr = gst_property_probe_probe_and_get_values_name (probe, "device");
55 for (i = 0; i < arr->n_values; ++i) {
59 val = g_value_array_get_nth (arr, i);
60 fail_unless (val != NULL);
61 fail_unless (G_VALUE_HOLDS_STRING (val));
63 device = g_value_get_string (val);
64 fail_unless (device != NULL);
65 GST_LOG_OBJECT (element, "device[%d] = %s", i, device);
67 g_value_array_free (arr);
69 GST_LOG_OBJECT (element, "no devices found");
72 gst_object_unref (element);
79 GST_START_TEST (test_alsa_mixer_track)
81 GstStateChangeReturn state_ret;
85 mixer = gst_element_factory_make ("alsamixer", "alsamixer");
86 fail_unless (mixer != NULL, "Failed to create 'alsamixer' element!");
88 state_ret = gst_element_set_state (mixer, GST_STATE_READY);
89 if (state_ret != GST_STATE_CHANGE_SUCCESS) {
90 gst_object_unref (mixer);
94 GST_LOG ("opened alsamixer");
95 fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!");
97 tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer));
98 for (l = tracks; l != NULL; l = l->next) {
100 gchar *ulabel = NULL, *label = NULL;
102 track = GST_MIXER_TRACK (l->data);
103 g_object_get (track, "label", &label, "untranslated-label", &ulabel, NULL);
104 fail_unless (label == NULL || g_utf8_validate (label, -1, NULL));
105 if (ulabel != NULL) {
108 for (p = ulabel; p != NULL && *p != '\0'; ++p) {
109 fail_unless (g_ascii_isprint (*p),
110 "untranslated label '%s' not printable ASCII", ulabel);
113 GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label));
118 fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL),
119 GST_STATE_CHANGE_SUCCESS);
121 gst_object_unref (mixer);
129 Suite *s = suite_create ("alsa");
130 TCase *tc_chain = tcase_create ("general");
132 suite_add_tcase (s, tc_chain);
133 /* tcase_add_test (tc_chain, test_device_property_probe); */
134 tcase_add_test (tc_chain, test_alsa_mixer_track);
139 GST_CHECK_MAIN (alsa)