tests: videorate: remove obsolete color-matrix caps field
[platform/upstream/gstreamer.git] / tests / check / elements / alsa.c
1 /* GStreamer
2  *
3  * unit test for alsa elements
4  *
5  * Copyright (C) 2006  Tim-Philipp Müller  <tim centricular net>
6  *
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.
11  *
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.
16  *
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.
21  */
22
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
26
27 #include <unistd.h>
28
29 #include <gst/check/gstcheck.h>
30 #include <gst/audio/mixer.h>
31
32 #if 0
33 /* just a simple test that runs device probing on
34  * an alsasrc, alsasink and alsamixer instance */
35
36 GST_START_TEST (test_device_property_probe)
37 {
38   const gchar *elements[] = { "alsasink", "alsasrc", "alsamixer" };
39   gint n;
40
41   for (n = 0; n < G_N_ELEMENTS (elements); ++n) {
42     GstPropertyProbe *probe;
43     GValueArray *arr;
44     GstElement *element;
45     gint i;
46
47     element = gst_element_factory_make (elements[n], elements[n]);
48     fail_unless (element != NULL);
49
50     probe = GST_PROPERTY_PROBE (element);
51     fail_unless (probe != NULL);
52
53     arr = gst_property_probe_probe_and_get_values_name (probe, "device");
54     if (arr) {
55       for (i = 0; i < arr->n_values; ++i) {
56         const gchar *device;
57         GValue *val;
58
59         val = g_value_array_get_nth (arr, i);
60         fail_unless (val != NULL);
61         fail_unless (G_VALUE_HOLDS_STRING (val));
62
63         device = g_value_get_string (val);
64         fail_unless (device != NULL);
65         GST_LOG_OBJECT (element, "device[%d] = %s", i, device);
66       }
67       g_value_array_free (arr);
68     } else {
69       GST_LOG_OBJECT (element, "no devices found");
70     }
71
72     gst_object_unref (element);
73   }
74 }
75
76 GST_END_TEST;
77 #endif
78
79 GST_START_TEST (test_alsa_mixer_track)
80 {
81   GstStateChangeReturn state_ret;
82   GstElement *mixer;
83   GList *tracks, *l;
84
85   mixer = gst_element_factory_make ("alsamixer", "alsamixer");
86   fail_unless (mixer != NULL, "Failed to create 'alsamixer' element!");
87
88   state_ret = gst_element_set_state (mixer, GST_STATE_READY);
89   if (state_ret != GST_STATE_CHANGE_SUCCESS) {
90     gst_object_unref (mixer);
91     return;
92   }
93
94   GST_LOG ("opened alsamixer");
95   fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!");
96
97   tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer));
98   for (l = tracks; l != NULL; l = l->next) {
99     GstMixerTrack *track;
100     gchar *ulabel = NULL, *label = NULL;
101
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) {
106       gchar *p;
107
108       for (p = ulabel; p != NULL && *p != '\0'; ++p) {
109         fail_unless (g_ascii_isprint (*p),
110             "untranslated label '%s' not printable ASCII", ulabel);
111       }
112     }
113     GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label));
114     g_free (label);
115     g_free (ulabel);
116   }
117
118   fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL),
119       GST_STATE_CHANGE_SUCCESS);
120
121   gst_object_unref (mixer);
122 }
123
124 GST_END_TEST;
125
126 static Suite *
127 alsa_suite (void)
128 {
129   Suite *s = suite_create ("alsa");
130   TCase *tc_chain = tcase_create ("general");
131
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);
135
136   return s;
137 }
138
139 GST_CHECK_MAIN (alsa)