|
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 #include <unistd.h> |
|
24 |
|
25 #include <gst/check/gstcheck.h> |
|
26 #include <gst/interfaces/propertyprobe.h> |
|
27 #include <gst/interfaces/mixer.h> |
|
28 |
|
29 /* just a simple test that runs device probing on |
|
30 * an alsasrc, alsasink and alsamixer instance */ |
|
31 |
|
32 GST_START_TEST (test_device_property_probe) |
|
33 { |
|
34 const gchar *elements[] = { "alsasink", "alsasrc", "alsamixer" }; |
|
35 gint n; |
|
36 |
|
37 for (n = 0; n < G_N_ELEMENTS (elements); ++n) { |
|
38 GstPropertyProbe *probe; |
|
39 GValueArray *arr; |
|
40 GstElement *element; |
|
41 gint i; |
|
42 |
|
43 element = gst_element_factory_make (elements[n], elements[n]); |
|
44 fail_unless (element != NULL); |
|
45 |
|
46 probe = GST_PROPERTY_PROBE (element); |
|
47 fail_unless (probe != NULL); |
|
48 |
|
49 arr = gst_property_probe_probe_and_get_values_name (probe, "device"); |
|
50 if (arr) { |
|
51 for (i = 0; i < arr->n_values; ++i) { |
|
52 const gchar *device; |
|
53 GValue *val; |
|
54 |
|
55 val = g_value_array_get_nth (arr, i); |
|
56 fail_unless (val != NULL); |
|
57 fail_unless (G_VALUE_HOLDS_STRING (val)); |
|
58 |
|
59 device = g_value_get_string (val); |
|
60 fail_unless (device != NULL); |
|
61 GST_LOG_OBJECT (element, "device[%d] = %s", i, device); |
|
62 } |
|
63 g_value_array_free (arr); |
|
64 } else { |
|
65 GST_LOG_OBJECT (element, "no devices found"); |
|
66 } |
|
67 |
|
68 gst_object_unref (element); |
|
69 } |
|
70 } |
|
71 |
|
72 GST_END_TEST; |
|
73 |
|
74 GST_START_TEST (test_alsa_mixer_track) |
|
75 { |
|
76 GstStateChangeReturn state_ret; |
|
77 GstElement *mixer; |
|
78 GList *tracks, *l; |
|
79 |
|
80 mixer = gst_element_factory_make ("alsamixer", "alsamixer"); |
|
81 fail_unless (mixer != NULL, "Failed to create 'alsamixer' element!"); |
|
82 |
|
83 state_ret = gst_element_set_state (mixer, GST_STATE_READY); |
|
84 if (state_ret != GST_STATE_CHANGE_SUCCESS) { |
|
85 gst_object_unref (mixer); |
|
86 return; |
|
87 } |
|
88 |
|
89 GST_LOG ("opened alsamixer"); |
|
90 fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!"); |
|
91 |
|
92 tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer)); |
|
93 for (l = tracks; l != NULL; l = l->next) { |
|
94 GstMixerTrack *track; |
|
95 gchar *ulabel = NULL, *label = NULL; |
|
96 |
|
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) { |
|
101 gchar *p; |
|
102 |
|
103 for (p = ulabel; p != NULL && *p != '\0'; ++p) { |
|
104 fail_unless (g_ascii_isprint (*p), |
|
105 "untranslated label '%s' not printable ASCII", ulabel); |
|
106 } |
|
107 } |
|
108 GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label)); |
|
109 g_free (label); |
|
110 g_free (ulabel); |
|
111 } |
|
112 |
|
113 fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL), |
|
114 GST_STATE_CHANGE_SUCCESS); |
|
115 |
|
116 gst_object_unref (mixer); |
|
117 } |
|
118 |
|
119 GST_END_TEST; |
|
120 |
|
121 static Suite * |
|
122 alsa_suite (void) |
|
123 { |
|
124 Suite *s = suite_create ("alsa"); |
|
125 TCase *tc_chain = tcase_create ("general"); |
|
126 |
|
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); |
|
130 |
|
131 return s; |
|
132 } |
|
133 |
|
134 GST_CHECK_MAIN (alsa) |