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.
25 #include <gst/check/gstcheck.h>
26 #include <gst/interfaces/propertyprobe.h>
27 #include <gst/interfaces/mixer.h>
29 /* just a simple test that runs device probing on
30 * an alsasrc, alsasink and alsamixer instance */
32 GST_START_TEST (test_device_property_probe)
34 const gchar *elements[] = { "alsasink", "alsasrc", "alsamixer" };
37 for (n = 0; n < G_N_ELEMENTS (elements); ++n) {
38 GstPropertyProbe *probe;
43 element = gst_element_factory_make (elements[n], elements[n]);
44 fail_unless (element != NULL);
46 probe = GST_PROPERTY_PROBE (element);
47 fail_unless (probe != NULL);
49 arr = gst_property_probe_probe_and_get_values_name (probe, "device");
51 for (i = 0; i < arr->n_values; ++i) {
55 val = g_value_array_get_nth (arr, i);
56 fail_unless (val != NULL);
57 fail_unless (G_VALUE_HOLDS_STRING (val));
59 device = g_value_get_string (val);
60 fail_unless (device != NULL);
61 GST_LOG_OBJECT (element, "device[%d] = %s", i, device);
63 g_value_array_free (arr);
65 GST_LOG_OBJECT (element, "no devices found");
68 gst_object_unref (element);
74 GST_START_TEST (test_alsa_mixer_track)
76 GstStateChangeReturn state_ret;
80 mixer = gst_element_factory_make ("alsamixer", "alsamixer");
81 fail_unless (mixer != NULL, "Failed to create 'alsamixer' element!");
83 state_ret = gst_element_set_state (mixer, GST_STATE_READY);
84 if (state_ret != GST_STATE_CHANGE_SUCCESS) {
85 gst_object_unref (mixer);
89 GST_LOG ("opened alsamixer");
90 fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!");
92 tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer));
93 for (l = tracks; l != NULL; l = l->next) {
95 gchar *ulabel = NULL, *label = NULL;
97 track = GST_MIXER_TRACK (l->data);
98 g_object_get (track, "label", &label, "untranslated-label", &ulabel, NULL);
99 fail_unless (label == NULL || g_utf8_validate (label, -1, NULL));
100 if (ulabel != NULL) {
103 for (p = ulabel; p != NULL && *p != '\0'; ++p) {
104 fail_unless (g_ascii_isprint (*p),
105 "untranslated label '%s' not printable ASCII", ulabel);
108 GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label));
113 fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL),
114 GST_STATE_CHANGE_SUCCESS);
116 gst_object_unref (mixer);
124 Suite *s = suite_create ("alsa");
125 TCase *tc_chain = tcase_create ("general");
127 suite_add_tcase (s, tc_chain);
128 tcase_add_test (tc_chain, test_device_property_probe);
129 tcase_add_test (tc_chain, test_alsa_mixer_track);
134 GST_CHECK_MAIN (alsa)