3 * unit tests for audio support library
5 * Copyright (C) 2007 Jan Schmidt <thaytan@noraisin.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.
27 #include <gst/check/gstcheck.h>
29 #include <gst/audio/mixer.h>
33 #define TEST_ELEMENT_TYPE (test_element_get_type())
35 /* FIXME 0.11: possibly remove mixer interface entirely, or simplify, or
37 typedef struct TestElement TestElement;
38 typedef struct TestElementClass TestElementClass;
45 struct TestElementClass
47 GstElementClass parent_class;
50 GType test_element_get_type (void);
52 static void init_interface (GType type);
54 G_DEFINE_TYPE_WITH_CODE (TestElement, test_element, GST_TYPE_ELEMENT,
55 init_interface (g_define_type_id));
58 test_element_mixer_interface_init (GstMixerInterface * iface)
60 /* Not actually implementing any interfaces for this test atm */
64 init_interface (GType type)
66 static const GInterfaceInfo mixer_iface_info = {
67 (GInterfaceInitFunc) test_element_mixer_interface_init,
72 g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info);
76 test_element_class_init (TestElementClass * klass)
81 test_element_init (TestElement * this)
85 GST_START_TEST (test_messages)
87 /* Create an empty GstElement that has a GstMixer interface and then
88 * send some notifications and validate them */
89 GstElement *test_element =
90 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
91 GstBus *bus = gst_bus_new ();
92 GstMixerTrack *mtrack = g_object_new (GST_TYPE_MIXER_TRACK, NULL);
93 GstMixerOptions *mopts = g_object_new (GST_TYPE_MIXER_OPTIONS, NULL);
96 gint vols_in[2] = { 50, 75 };
97 gboolean mute, record;
103 mtrack->num_channels = 2;
104 mtrack->flags = GST_MIXER_TRACK_MUTE | GST_MIXER_TRACK_RECORD;
106 gst_element_set_bus (test_element, bus);
108 /* Test mute-toggled */
109 gst_mixer_mute_toggled (GST_MIXER (test_element), mtrack, TRUE);
110 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
111 fail_if (message == NULL);
112 fail_unless (gst_mixer_message_get_type (message) ==
113 GST_MIXER_MESSAGE_MUTE_TOGGLED);
114 /* Test that we can pass NULL args */
115 gst_mixer_message_parse_mute_toggled (message, NULL, NULL);
116 /* Test the parsing */
117 gst_mixer_message_parse_mute_toggled (message, &t, &mute);
118 fail_unless (t == mtrack);
119 fail_unless (mute == TRUE);
120 gst_message_unref (message);
122 /* Test record-toggled */
123 gst_mixer_record_toggled (GST_MIXER (test_element), mtrack, TRUE);
124 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
125 fail_if (message == NULL);
126 fail_unless (gst_mixer_message_get_type (message) ==
127 GST_MIXER_MESSAGE_RECORD_TOGGLED);
128 gst_mixer_message_parse_record_toggled (message, NULL, NULL);
129 gst_mixer_message_parse_record_toggled (message, &t, &record);
130 fail_unless (t == mtrack);
131 fail_unless (record == TRUE);
132 gst_message_unref (message);
134 /* Test volume-changed */
135 gst_mixer_volume_changed (GST_MIXER (test_element), mtrack, vols_in);
136 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
137 fail_if (message == NULL);
138 fail_unless (gst_mixer_message_get_type (message) ==
139 GST_MIXER_MESSAGE_VOLUME_CHANGED);
140 gst_mixer_message_parse_volume_changed (message, NULL, NULL, NULL);
141 gst_mixer_message_parse_volume_changed (message, NULL, NULL, &n_chans);
142 fail_unless (n_chans == 2);
143 gst_mixer_message_parse_volume_changed (message, &t, &vols_out, &n_chans);
144 fail_unless (mtrack == t);
145 for (i = 0; i < n_chans; i++)
146 fail_unless (vols_out[i] == vols_in[i]);
148 gst_message_unref (message);
151 /* Test option-changed */
152 gst_mixer_option_changed (GST_MIXER (test_element), mopts, "TESTING");
153 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
154 fail_if (message == NULL);
155 fail_unless (gst_mixer_message_get_type (message) ==
156 GST_MIXER_MESSAGE_OPTION_CHANGED);
157 gst_mixer_message_parse_option_changed (message, NULL, NULL);
158 gst_mixer_message_parse_option_changed (message, &o, &val);
159 fail_unless (o == mopts);
160 fail_unless (g_str_equal (val, "TESTING"));
161 gst_message_unref (message);
163 /* Test options-list-changed */
164 gst_mixer_options_list_changed (GST_MIXER (test_element), mopts);
165 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
166 fail_if (message == NULL);
167 fail_unless (gst_mixer_message_get_type (message) ==
168 GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED);
169 gst_mixer_message_parse_options_list_changed (message, &o);
170 fail_unless (o == mopts);
171 gst_message_unref (message);
173 /* Test mixer-changed */
174 gst_mixer_mixer_changed (GST_MIXER (test_element));
175 message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE);
176 fail_if (message == NULL);
177 fail_unless (gst_mixer_message_get_type (message) ==
178 GST_MIXER_MESSAGE_MIXER_CHANGED);
179 gst_message_unref (message);
181 gst_object_unref (mtrack);
182 gst_object_unref (mopts);
183 gst_object_unref (bus);
184 gst_object_unref (test_element);
192 Suite *s = suite_create ("mixer interface");
193 TCase *tc_chain = tcase_create ("notifications");
195 suite_add_tcase (s, tc_chain);
196 tcase_add_test (tc_chain, test_messages);
202 main (int argc, char **argv)
206 Suite *s = mixer_suite ();
207 SRunner *sr = srunner_create (s);
209 gst_check_init (&argc, &argv);
211 srunner_run_all (sr, CK_NORMAL);
212 nf = srunner_ntests_failed (sr);