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.
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.
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., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
20 #include <gst/check/gstcheck.h>
21 GST_START_TEST (create_queries)
30 query = gst_query_new_position (GST_FORMAT_TIME);
31 fail_if (query == NULL);
32 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
34 gst_query_parse_position (query, &format, NULL);
35 fail_if (format != GST_FORMAT_TIME);
37 gst_query_set_position (query, GST_FORMAT_TIME, 0xdeadbeaf);
39 gst_query_parse_position (query, &format, &position);
40 fail_if (format != GST_FORMAT_TIME);
41 fail_if (position != 0xdeadbeaf);
43 gst_query_unref (query);
50 query = gst_query_new_duration (GST_FORMAT_TIME);
51 fail_if (query == NULL);
52 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
54 gst_query_parse_duration (query, &format, NULL);
55 fail_if (format != GST_FORMAT_TIME);
57 gst_query_set_duration (query, GST_FORMAT_TIME, 0xdeadbeaf);
59 gst_query_parse_duration (query, &format, &duration);
60 fail_if (format != GST_FORMAT_TIME);
61 fail_if (duration != 0xdeadbeaf);
63 gst_query_unref (query);
65 /* BUFFERING RANGES */
69 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
70 fail_if (query == NULL);
71 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
73 fail_unless (gst_query_add_buffering_range (query, 0, 20));
74 fail_unless (gst_query_add_buffering_range (query, 25, 30));
76 /* check incoherent range insertion */
77 fail_if (gst_query_add_buffering_range (query, 10, 15));
78 fail_if (gst_query_add_buffering_range (query, 50, 40));
80 fail_unless (gst_query_get_n_buffering_ranges (query) == 2);
82 fail_unless (gst_query_parse_nth_buffering_range (query, 0, &start, &stop));
83 fail_unless (start == 0);
84 fail_unless (stop == 20);
86 fail_unless (gst_query_parse_nth_buffering_range (query, 1, &start, &stop));
87 fail_unless (start == 25);
88 fail_unless (stop == 30);
90 gst_query_unref (query);
93 /* FIXME make tests for:
109 format = GST_FORMAT_BYTES;
110 query = gst_query_new_segment (format);
112 fail_if (query == NULL);
113 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
115 gst_query_parse_segment (query, &rate, &format, &start, &stop);
117 /* see if empty gives undefined formats */
118 fail_if (rate != 0.0);
119 fail_if (format != GST_FORMAT_BYTES);
120 fail_if (start != -1);
121 fail_if (stop != -1);
123 /* change all values */
124 gst_query_set_segment (query, 2.0, GST_FORMAT_TIME, 1 * GST_SECOND,
127 gst_query_parse_segment (query, &rate, &format, &start, &stop);
129 /* see if the values were changed */
130 fail_if (rate != 2.0);
131 fail_if (format != GST_FORMAT_TIME);
132 fail_if (start != 1 * GST_SECOND);
133 fail_if (stop != 3 * GST_SECOND);
135 gst_query_unref (query);
143 query = gst_query_new_formats ();
144 fail_if (query == NULL);
145 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
148 gst_query_parse_n_formats (query, &size);
151 /* see if empty gives undefined formats */
152 gst_query_parse_nth_format (query, 0, &format);
153 fail_if (format != GST_FORMAT_UNDEFINED);
154 gst_query_parse_nth_format (query, 1, &format);
155 fail_if (format != GST_FORMAT_UNDEFINED);
158 gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
160 gst_query_parse_n_formats (query, &size);
163 format = GST_FORMAT_UNDEFINED;
165 gst_query_parse_nth_format (query, 0, &format);
166 fail_if (format != GST_FORMAT_TIME);
167 gst_query_parse_nth_format (query, 1, &format);
168 fail_if (format != GST_FORMAT_BYTES);
170 /* out of bounds, should return UNDEFINED */
171 gst_query_parse_nth_format (query, 2, &format);
172 fail_if (format != GST_FORMAT_UNDEFINED);
174 /* overwrite with 3 formats */
175 gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES,
178 gst_query_parse_n_formats (query, &size);
181 gst_query_parse_nth_format (query, 2, &format);
182 fail_if (format != GST_FORMAT_PERCENT);
184 /* create one from an array */
186 static GstFormat formats[] = {
191 gst_query_set_formatsv (query, 3, formats);
193 gst_query_parse_n_formats (query, &size);
196 gst_query_parse_nth_format (query, 0, &format);
197 fail_if (format != GST_FORMAT_TIME);
198 gst_query_parse_nth_format (query, 2, &format);
199 fail_if (format != GST_FORMAT_PERCENT);
201 gst_query_unref (query);
207 GST_START_TEST (test_queries)
210 GstElement *src, *sink;
211 GstStateChangeReturn ret;
215 fail_unless ((bin = (GstBin *) gst_pipeline_new (NULL)) != NULL,
216 "Could not create pipeline");
217 fail_unless ((src = gst_element_factory_make ("fakesrc", NULL)) != NULL,
218 "Could not create fakesrc");
219 g_object_set (src, "datarate", 200, "sizetype", 2, NULL);
221 fail_unless ((sink = gst_element_factory_make ("fakesink", NULL)) != NULL,
222 "Could not create fakesink");
223 g_object_set (sink, "sync", TRUE, NULL);
224 fail_unless ((dur = gst_query_new_duration (GST_FORMAT_BYTES)) != NULL,
225 "Could not prepare duration query");
226 fail_unless ((pos = gst_query_new_position (GST_FORMAT_BYTES)) != NULL,
227 "Could not prepare position query");
229 fail_unless (gst_bin_add (bin, src), "Could not add src to bin");
230 fail_unless (gst_bin_add (bin, sink), "Could not add sink to bin");
231 fail_unless (gst_element_link (src, sink), "could not link src and sink");
233 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
234 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline PLAYING");
235 if (ret == GST_STATE_CHANGE_ASYNC)
236 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
239 fail_unless (gst_element_query (GST_ELEMENT (bin), pos),
240 "Could not query pipeline position");
241 fail_unless (gst_element_query (GST_ELEMENT (bin), dur),
242 "Could not query pipeline duration");
245 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
246 "Could not query position of fakesrc");
247 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
248 "Could not query duration of fakesrc");
250 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
251 "Could not query position of fakesink");
252 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
253 "Could not query duration of fakesink");
256 fail_unless ((pad = gst_element_get_static_pad (src, "src")) != NULL,
257 "Could not get source pad of fakesrc");
258 fail_unless (gst_pad_query (pad, pos),
259 "Could not query position of fakesrc src pad");
260 fail_unless (gst_pad_query (pad, dur),
261 "Could not query duration of fakesrc src pad");
262 gst_object_unref (pad);
264 /* We don't query the sink pad of fakesink, it doesn't
265 * handle downstream queries atm, but it might later, who knows? */
267 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
268 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline NULL");
269 if (ret == GST_STATE_CHANGE_ASYNC)
270 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
272 gst_query_unref (dur);
273 gst_query_unref (pos);
274 gst_object_unref (bin);
280 gst_query_suite (void)
282 Suite *s = suite_create ("GstQuery");
283 TCase *tc_chain = tcase_create ("queries");
285 tcase_set_timeout (tc_chain, 20);
287 suite_add_tcase (s, tc_chain);
288 tcase_add_test (tc_chain, create_queries);
289 tcase_add_test (tc_chain, test_queries);
293 GST_CHECK_MAIN (gst_query);