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);
66 /* FIXME make tests for:
82 format = GST_FORMAT_BYTES;
83 query = gst_query_new_segment (format);
85 fail_if (query == NULL);
86 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
88 gst_query_parse_segment (query, &rate, &format, &start, &stop);
90 /* see if empty gives undefined formats */
91 fail_if (rate != 0.0);
92 fail_if (format != GST_FORMAT_BYTES);
93 fail_if (start != -1);
96 /* change all values */
97 gst_query_set_segment (query, 2.0, GST_FORMAT_TIME, 1 * GST_SECOND,
100 gst_query_parse_segment (query, &rate, &format, &start, &stop);
102 /* see if the values were changed */
103 fail_if (rate != 2.0);
104 fail_if (format != GST_FORMAT_TIME);
105 fail_if (start != 1 * GST_SECOND);
106 fail_if (stop != 3 * GST_SECOND);
108 gst_query_unref (query);
116 query = gst_query_new_formats ();
117 fail_if (query == NULL);
118 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
121 gst_query_parse_formats_length (query, &size);
124 /* see if empty gives undefined formats */
125 gst_query_parse_formats_nth (query, 0, &format);
126 fail_if (format != GST_FORMAT_UNDEFINED);
127 gst_query_parse_formats_nth (query, 1, &format);
128 fail_if (format != GST_FORMAT_UNDEFINED);
131 gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
133 gst_query_parse_formats_length (query, &size);
136 format = GST_FORMAT_UNDEFINED;
138 gst_query_parse_formats_nth (query, 0, &format);
139 fail_if (format != GST_FORMAT_TIME);
140 gst_query_parse_formats_nth (query, 1, &format);
141 fail_if (format != GST_FORMAT_BYTES);
143 /* out of bounds, should return UNDEFINED */
144 gst_query_parse_formats_nth (query, 2, &format);
145 fail_if (format != GST_FORMAT_UNDEFINED);
147 /* overwrite with 3 formats */
148 gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES,
151 gst_query_parse_formats_length (query, &size);
154 gst_query_parse_formats_nth (query, 2, &format);
155 fail_if (format != GST_FORMAT_PERCENT);
157 /* create one from an array */
159 static GstFormat formats[] = {
164 gst_query_set_formatsv (query, 3, formats);
166 gst_query_parse_formats_length (query, &size);
169 gst_query_parse_formats_nth (query, 0, &format);
170 fail_if (format != GST_FORMAT_TIME);
171 gst_query_parse_formats_nth (query, 2, &format);
172 fail_if (format != GST_FORMAT_PERCENT);
174 gst_query_unref (query);
180 GST_START_TEST (test_queries)
183 GstElement *src, *sink;
184 GstStateChangeReturn ret;
188 fail_unless ((bin = (GstBin *) gst_pipeline_new (NULL)) != NULL,
189 "Could not create pipeline");
190 fail_unless ((src = gst_element_factory_make ("fakesrc", NULL)) != NULL,
191 "Could not create fakesrc");
192 g_object_set (src, "datarate", 200, "sizetype", 2, NULL);
194 fail_unless ((sink = gst_element_factory_make ("fakesink", NULL)) != NULL,
195 "Could not create fakesink");
196 g_object_set (sink, "sync", TRUE, NULL);
197 fail_unless ((dur = gst_query_new_duration (GST_FORMAT_BYTES)) != NULL,
198 "Could not prepare duration query");
199 fail_unless ((pos = gst_query_new_position (GST_FORMAT_BYTES)) != NULL,
200 "Could not prepare position query");
202 fail_unless (gst_bin_add (bin, src), "Could not add src to bin");
203 fail_unless (gst_bin_add (bin, sink), "Could not add sink to bin");
204 fail_unless (gst_element_link (src, sink), "could not link src and sink");
206 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
207 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline PLAYING");
208 if (ret == GST_STATE_CHANGE_ASYNC)
209 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
212 fail_unless (gst_element_query (GST_ELEMENT (bin), pos),
213 "Could not query pipeline position");
214 fail_unless (gst_element_query (GST_ELEMENT (bin), dur),
215 "Could not query pipeline duration");
218 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
219 "Could not query position of fakesrc");
220 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
221 "Could not query duration of fakesrc");
223 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
224 "Could not query position of fakesink");
225 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
226 "Could not query duration of fakesink");
229 fail_unless ((pad = gst_element_get_pad (src, "src")) != NULL,
230 "Could not get source pad of fakesrc");
231 fail_unless (gst_pad_query (pad, pos),
232 "Could not query position of fakesrc src pad");
233 fail_unless (gst_pad_query (pad, dur),
234 "Could not query duration of fakesrc src pad");
235 gst_object_unref (pad);
237 /* We don't query the sink pad of fakesink, it doesn't
238 * handle downstream queries atm, but it might later, who knows? */
240 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
241 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline NULL");
242 if (ret == GST_STATE_CHANGE_ASYNC)
243 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
245 gst_query_unref (dur);
246 gst_query_unref (pos);
247 gst_object_unref (bin);
253 gst_query_suite (void)
255 Suite *s = suite_create ("GstQuery");
256 TCase *tc_chain = tcase_create ("queries");
258 tcase_set_timeout (tc_chain, 20);
260 suite_add_tcase (s, tc_chain);
261 tcase_add_test (tc_chain, create_queries);
262 tcase_add_test (tc_chain, test_queries);
266 GST_CHECK_MAIN (gst_query);