1 /* GStreamer WavParse unit tests
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <gst/check/gstcheck.h>
23
24 #define SIMPLE_WAV_PATH GST_TEST_FILES_PATH G_DIR_SEPARATOR_S "audiotestsrc.wav"
25
26 static void
do_test_simple_file(GstPadMode mode)27 do_test_simple_file (GstPadMode mode)
28 {
29 GstStateChangeReturn ret;
30 GstElement *pipeline;
31 GstElement *src, *q = NULL;
32 GstElement *wavparse;
33 GstElement *fakesink;
34 GstMessage *msg;
35
36 pipeline = gst_pipeline_new ("testpipe");
37 src = gst_element_factory_make ("filesrc", NULL);
38 fail_if (src == NULL);
39 if (mode == GST_PAD_MODE_PUSH)
40 q = gst_element_factory_make ("queue", NULL);
41 wavparse = gst_element_factory_make ("wavparse", NULL);
42 fail_if (wavparse == NULL);
43 fakesink = gst_element_factory_make ("fakesink", NULL);
44 fail_if (fakesink == NULL);
45
46 gst_bin_add_many (GST_BIN (pipeline), src, wavparse, fakesink, q, NULL);
47
48 g_object_set (src, "location", SIMPLE_WAV_PATH, NULL);
49
50 if (mode == GST_PAD_MODE_PUSH)
51 fail_unless (gst_element_link_many (src, q, wavparse, fakesink, NULL));
52 else
53 fail_unless (gst_element_link_many (src, wavparse, fakesink, NULL));
54
55 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
56 fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
57
58 ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
59 fail_unless_equals_int (ret, GST_STATE_CHANGE_SUCCESS);
60
61 msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline),
62 GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
63
64 fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "eos");
65
66 gst_message_unref (msg);
67 gst_element_set_state (pipeline, GST_STATE_NULL);
68 gst_object_unref (pipeline);
69 }
70
GST_START_TEST(test_simple_file_pull)71 GST_START_TEST (test_simple_file_pull)
72 {
73 do_test_simple_file (TRUE);
74 }
75
76 GST_END_TEST;
77
GST_START_TEST(test_simple_file_push)78 GST_START_TEST (test_simple_file_push)
79 {
80 do_test_simple_file (FALSE);
81 }
82
83 GST_END_TEST;
84
85 static void
do_test_empty_file(gboolean can_activate_pull)86 do_test_empty_file (gboolean can_activate_pull)
87 {
88 GstStateChangeReturn ret1, ret2;
89 GstElement *pipeline;
90 GstElement *src;
91 GstElement *wavparse;
92 GstElement *fakesink;
93
94 /* Pull mode */
95 pipeline = gst_pipeline_new ("testpipe");
96 src = gst_element_factory_make ("fakesrc", NULL);
97 fail_if (src == NULL);
98 wavparse = gst_element_factory_make ("wavparse", NULL);
99 fail_if (wavparse == NULL);
100 fakesink = gst_element_factory_make ("fakesink", NULL);
101 fail_if (fakesink == NULL);
102
103 gst_bin_add_many (GST_BIN (pipeline), src, wavparse, fakesink, NULL);
104 g_object_set (src, "num-buffers", 0, "can-activate-pull", can_activate_pull,
105 NULL);
106
107 fail_unless (gst_element_link_many (src, wavparse, fakesink, NULL));
108
109 ret1 = gst_element_set_state (pipeline, GST_STATE_PLAYING);
110 if (ret1 == GST_STATE_CHANGE_ASYNC)
111 ret2 = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
112 else
113 ret2 = ret1;
114
115 /* should have gotten an error on the bus, no output to fakesink */
116 fail_unless_equals_int (ret2, GST_STATE_CHANGE_FAILURE);
117
118 gst_element_set_state (pipeline, GST_STATE_NULL);
119 gst_object_unref (pipeline);
120 }
121
GST_START_TEST(test_empty_file_pull)122 GST_START_TEST (test_empty_file_pull)
123 {
124 do_test_empty_file (TRUE);
125 }
126
127 GST_END_TEST;
128
GST_START_TEST(test_empty_file_push)129 GST_START_TEST (test_empty_file_push)
130 {
131 do_test_empty_file (FALSE);
132 }
133
134 GST_END_TEST;
135
136 static Suite *
wavparse_suite(void)137 wavparse_suite (void)
138 {
139 Suite *s = suite_create ("wavparse");
140 TCase *tc_chain = tcase_create ("wavparse");
141
142 suite_add_tcase (s, tc_chain);
143 tcase_add_test (tc_chain, test_empty_file_pull);
144 tcase_add_test (tc_chain, test_empty_file_push);
145 tcase_add_test (tc_chain, test_simple_file_pull);
146 tcase_add_test (tc_chain, test_simple_file_push);
147 return s;
148 }
149
150 GST_CHECK_MAIN (wavparse)
151