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 query = gst_query_new_formats ();
83 fail_if (query == NULL);
84 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
87 gst_query_parse_formats_length (query, &size);
90 /* see if empty gives undefined formats */
91 gst_query_parse_formats_nth (query, 0, &format);
92 fail_if (format != GST_FORMAT_UNDEFINED);
93 gst_query_parse_formats_nth (query, 1, &format);
94 fail_if (format != GST_FORMAT_UNDEFINED);
97 gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
99 gst_query_parse_formats_length (query, &size);
102 format = GST_FORMAT_UNDEFINED;
104 gst_query_parse_formats_nth (query, 0, &format);
105 fail_if (format != GST_FORMAT_TIME);
106 gst_query_parse_formats_nth (query, 1, &format);
107 fail_if (format != GST_FORMAT_BYTES);
109 /* out of bounds, should return UNDEFINED */
110 gst_query_parse_formats_nth (query, 2, &format);
111 fail_if (format != GST_FORMAT_UNDEFINED);
113 /* overwrite with 3 formats */
114 gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES,
117 gst_query_parse_formats_length (query, &size);
120 gst_query_parse_formats_nth (query, 2, &format);
121 fail_if (format != GST_FORMAT_PERCENT);
123 /* create one from an array */
125 static GstFormat formats[] = {
130 gst_query_set_formatsv (query, 3, formats);
132 gst_query_parse_formats_length (query, &size);
135 gst_query_parse_formats_nth (query, 0, &format);
136 fail_if (format != GST_FORMAT_TIME);
137 gst_query_parse_formats_nth (query, 2, &format);
138 fail_if (format != GST_FORMAT_PERCENT);
140 gst_query_unref (query);
146 GST_START_TEST (test_queries)
149 GstElement *src, *sink;
150 GstStateChangeReturn ret;
154 fail_unless ((bin = (GstBin *) gst_pipeline_new (NULL)) != NULL,
155 "Could not create pipeline");
156 fail_unless ((src = gst_element_factory_make ("fakesrc", NULL)) != NULL,
157 "Could not create fakesrc");
158 g_object_set (src, "datarate", 200, "sizetype", 2, NULL);
160 fail_unless ((sink = gst_element_factory_make ("fakesink", NULL)) != NULL,
161 "Could not create fakesink");
162 g_object_set (sink, "sync", TRUE, NULL);
163 fail_unless ((dur = gst_query_new_duration (GST_FORMAT_BYTES)) != NULL,
164 "Could not prepare duration query");
165 fail_unless ((pos = gst_query_new_position (GST_FORMAT_BYTES)) != NULL,
166 "Could not prepare position query");
168 fail_unless (gst_bin_add (bin, src), "Could not add src to bin");
169 fail_unless (gst_bin_add (bin, sink), "Could not add sink to bin");
170 fail_unless (gst_element_link (src, sink), "could not link src and sink");
172 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
173 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline PLAYING");
174 if (ret == GST_STATE_CHANGE_ASYNC)
175 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
178 fail_unless (gst_element_query (GST_ELEMENT (bin), pos),
179 "Could not query pipeline position");
180 fail_unless (gst_element_query (GST_ELEMENT (bin), dur),
181 "Could not query pipeline duration");
184 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
185 "Could not query position of fakesrc");
186 fail_unless (gst_element_query (GST_ELEMENT (src), pos),
187 "Could not query duration of fakesrc");
189 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
190 "Could not query position of fakesink");
191 fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
192 "Could not query duration of fakesink");
195 fail_unless ((pad = gst_element_get_pad (src, "src")) != NULL,
196 "Could not get source pad of fakesrc");
197 fail_unless (gst_pad_query (pad, pos),
198 "Could not query position of fakesrc src pad");
199 fail_unless (gst_pad_query (pad, dur),
200 "Could not query duration of fakesrc src pad");
201 gst_object_unref (pad);
203 /* We don't query the sink pad of fakesink, it doesn't
204 * handle downstream queries atm, but it might later, who knows? */
206 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
207 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline NULL");
208 if (ret == GST_STATE_CHANGE_ASYNC)
209 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);
211 gst_query_unref (dur);
212 gst_query_unref (pos);
213 gst_object_unref (bin);
219 gst_query_suite (void)
221 Suite *s = suite_create ("GstQuery");
222 TCase *tc_chain = tcase_create ("queries");
224 tcase_set_timeout (tc_chain, 20);
226 suite_add_tcase (s, tc_chain);
227 tcase_add_test (tc_chain, create_queries);
228 tcase_add_test (tc_chain, test_queries);
232 GST_CHECK_MAIN (gst_query);