|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* GStreamer |
|
18 * |
|
19 * This library is free software; you can redistribute it and/or |
|
20 * modify it under the terms of the GNU Library General Public |
|
21 * License as published by the Free Software Foundation; either |
|
22 * version 2 of the License, or (at your option) any later version. |
|
23 * |
|
24 * This library is distributed in the hope that it will be useful, |
|
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
27 * Library General Public License for more details. |
|
28 * |
|
29 * You should have received a copy of the GNU Library General Public |
|
30 * License along with this library; if not, write to the |
|
31 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
32 * Boston, MA 02111-1307, USA. |
|
33 */ |
|
34 |
|
35 |
|
36 |
|
37 #include <gst/gst_global.h> |
|
38 #include <gst/check/gstcheck.h> |
|
39 |
|
40 #include <gst/check/gstcheck.h> |
|
41 #include <glib_global.h> |
|
42 #include <glib.h> |
|
43 #include <glib/gstdio.h> |
|
44 |
|
45 #include "libgstreamer_wsd_solution.h" |
|
46 #include <libgstreamer_wsd_macros.h> |
|
47 #ifndef EMULATOR |
|
48 #define assert_failed *(get_assert_failed()) |
|
49 #define fp_std_log *(get_fp_std_log()) |
|
50 #define xmlfile *(get_xmlfile()) |
|
51 #endif |
|
52 |
|
53 #define LOG_FILE "c:\\logs\\gstquery_log1.txt" |
|
54 #include "std_log_result.h" |
|
55 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
56 |
|
57 |
|
58 |
|
59 #if EMULATOR |
|
60 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
|
61 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
|
62 #else |
|
63 extern GList *buffers = NULL; |
|
64 #endif |
|
65 |
|
66 void create_xml(int result) |
|
67 { |
|
68 if(result) |
|
69 assert_failed = 1; |
|
70 |
|
71 testResultXml(xmlfile); |
|
72 close_log_file(); |
|
73 } |
|
74 |
|
75 |
|
76 void create_queries() |
|
77 { |
|
78 GstQuery *query; |
|
79 |
|
80 /* POSITION */ |
|
81 { |
|
82 GstFormat format; |
|
83 gint64 position; |
|
84 xmlfile = "gstquery_create_queries"; |
|
85 std_log(LOG_FILENAME_LINE, "Test Started create_queries"); |
|
86 query = gst_query_new_position (GST_FORMAT_TIME); |
|
87 fail_if (query == NULL); |
|
88 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_POSITION); |
|
89 |
|
90 gst_query_parse_position (query, &format, NULL); |
|
91 fail_if (format != GST_FORMAT_TIME); |
|
92 |
|
93 gst_query_set_position (query, GST_FORMAT_TIME, 0xdeadbeaf); |
|
94 |
|
95 gst_query_parse_position (query, &format, &position); |
|
96 fail_if (format != GST_FORMAT_TIME); |
|
97 fail_if (position != 0xdeadbeaf); |
|
98 |
|
99 gst_query_unref (query); |
|
100 } |
|
101 /* DURATION */ |
|
102 { |
|
103 GstFormat format; |
|
104 gint64 duration; |
|
105 |
|
106 query = gst_query_new_duration (GST_FORMAT_TIME); |
|
107 fail_if (query == NULL); |
|
108 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_DURATION); |
|
109 |
|
110 gst_query_parse_duration (query, &format, NULL); |
|
111 fail_if (format != GST_FORMAT_TIME); |
|
112 |
|
113 gst_query_set_duration (query, GST_FORMAT_TIME, 0xdeadbeaf); |
|
114 |
|
115 gst_query_parse_duration (query, &format, &duration); |
|
116 fail_if (format != GST_FORMAT_TIME); |
|
117 fail_if (duration != 0xdeadbeaf); |
|
118 |
|
119 gst_query_unref (query); |
|
120 } |
|
121 { |
|
122 /* FIXME make tests for: |
|
123 * |
|
124 * LATENCY |
|
125 * JITTER |
|
126 * RATE |
|
127 * SEEKING |
|
128 * SEGMENT |
|
129 * CONVERT |
|
130 */ |
|
131 } |
|
132 /* SEGMENT */ |
|
133 { |
|
134 gdouble rate; |
|
135 GstFormat format; |
|
136 gint64 start, stop; |
|
137 |
|
138 format = GST_FORMAT_BYTES; |
|
139 query = gst_query_new_segment (format); |
|
140 |
|
141 fail_if (query == NULL); |
|
142 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT); |
|
143 |
|
144 gst_query_parse_segment (query, &rate, &format, &start, &stop); |
|
145 |
|
146 /* see if empty gives undefined formats */ |
|
147 fail_if (rate != 0.0); |
|
148 fail_if (format != GST_FORMAT_BYTES); |
|
149 fail_if (start != -1); |
|
150 fail_if (stop != -1); |
|
151 |
|
152 /* change all values */ |
|
153 gst_query_set_segment (query, 2.0, GST_FORMAT_TIME, 1 * GST_SECOND, |
|
154 3 * GST_SECOND); |
|
155 |
|
156 gst_query_parse_segment (query, &rate, &format, &start, &stop); |
|
157 |
|
158 /* see if the values were changed */ |
|
159 fail_if (rate != 2.0); |
|
160 fail_if (format != GST_FORMAT_TIME); |
|
161 fail_if (start != 1 * GST_SECOND); |
|
162 fail_if (stop != 3 * GST_SECOND); |
|
163 |
|
164 gst_query_unref (query); |
|
165 } |
|
166 |
|
167 /* FORMATS */ |
|
168 { |
|
169 guint size; |
|
170 GstFormat format; |
|
171 |
|
172 query = gst_query_new_formats (); |
|
173 fail_if (query == NULL); |
|
174 fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS); |
|
175 |
|
176 /* empty */ |
|
177 gst_query_parse_formats_length (query, &size); |
|
178 fail_if (size != 0); |
|
179 |
|
180 /* see if empty gives undefined formats */ |
|
181 gst_query_parse_formats_nth (query, 0, &format); |
|
182 fail_if (format != GST_FORMAT_UNDEFINED); |
|
183 gst_query_parse_formats_nth (query, 1, &format); |
|
184 fail_if (format != GST_FORMAT_UNDEFINED); |
|
185 |
|
186 /* set 2 formats */ |
|
187 gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES); |
|
188 |
|
189 gst_query_parse_formats_length (query, &size); |
|
190 fail_if (size != 2); |
|
191 |
|
192 format = GST_FORMAT_UNDEFINED; |
|
193 |
|
194 gst_query_parse_formats_nth (query, 0, &format); |
|
195 fail_if (format != GST_FORMAT_TIME); |
|
196 gst_query_parse_formats_nth (query, 1, &format); |
|
197 fail_if (format != GST_FORMAT_BYTES); |
|
198 |
|
199 /* out of bounds, should return UNDEFINED */ |
|
200 gst_query_parse_formats_nth (query, 2, &format); |
|
201 fail_if (format != GST_FORMAT_UNDEFINED); |
|
202 |
|
203 /* overwrite with 3 formats */ |
|
204 gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES, |
|
205 GST_FORMAT_PERCENT); |
|
206 |
|
207 gst_query_parse_formats_length (query, &size); |
|
208 fail_if (size != 3); |
|
209 |
|
210 gst_query_parse_formats_nth (query, 2, &format); |
|
211 fail_if (format != GST_FORMAT_PERCENT); |
|
212 |
|
213 /* create one from an array */ |
|
214 { |
|
215 static GstFormat formats[] = { |
|
216 GST_FORMAT_TIME, |
|
217 GST_FORMAT_BYTES, |
|
218 GST_FORMAT_PERCENT |
|
219 }; |
|
220 gst_query_set_formatsv (query, 3, formats); |
|
221 |
|
222 gst_query_parse_formats_length (query, &size); |
|
223 fail_if (size != 3); |
|
224 |
|
225 gst_query_parse_formats_nth (query, 0, &format); |
|
226 fail_if (format != GST_FORMAT_TIME); |
|
227 gst_query_parse_formats_nth (query, 2, &format); |
|
228 fail_if (format != GST_FORMAT_PERCENT); |
|
229 } |
|
230 gst_query_unref (query); |
|
231 } |
|
232 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
233 create_xml(0); |
|
234 |
|
235 |
|
236 } |
|
237 |
|
238 |
|
239 |
|
240 void test_queries() |
|
241 { |
|
242 GstBin *bin; |
|
243 GstElement *src, *sink; |
|
244 GstStateChangeReturn ret; |
|
245 GstPad *pad; |
|
246 GstQuery *dur, *pos; |
|
247 xmlfile = "gstquery_test_queries"; |
|
248 std_log(LOG_FILENAME_LINE, "Test Started test_queries"); |
|
249 fail_unless ((bin = (GstBin *) gst_pipeline_new (NULL)) != NULL, |
|
250 "Could not create pipeline"); |
|
251 fail_unless ((src = gst_element_factory_make ("fakesrc", NULL)) != NULL, |
|
252 "Could not create fakesrc"); |
|
253 g_object_set (src, "datarate", 200, "sizetype", 2, NULL); |
|
254 |
|
255 fail_unless ((sink = gst_element_factory_make ("fakesink", NULL)) != NULL, |
|
256 "Could not create fakesink"); |
|
257 g_object_set (sink, "sync", TRUE, NULL); |
|
258 fail_unless ((dur = gst_query_new_duration (GST_FORMAT_BYTES)) != NULL, |
|
259 "Could not prepare duration query"); |
|
260 fail_unless ((pos = gst_query_new_position (GST_FORMAT_BYTES)) != NULL, |
|
261 "Could not prepare position query"); |
|
262 |
|
263 fail_unless (gst_bin_add (bin, src), "Could not add src to bin"); |
|
264 fail_unless (gst_bin_add (bin, sink), "Could not add sink to bin"); |
|
265 fail_unless (gst_element_link (src, sink), "could not link src and sink"); |
|
266 |
|
267 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING); |
|
268 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline PLAYING"); |
|
269 if (ret == GST_STATE_CHANGE_ASYNC) |
|
270 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE); |
|
271 |
|
272 /* Query the bin */ |
|
273 fail_unless (gst_element_query (GST_ELEMENT (bin), pos), |
|
274 "Could not query pipeline position"); |
|
275 fail_unless (gst_element_query (GST_ELEMENT (bin), dur), |
|
276 "Could not query pipeline duration"); |
|
277 |
|
278 /* Query elements */ |
|
279 fail_unless (gst_element_query (GST_ELEMENT (src), pos), |
|
280 "Could not query position of fakesrc"); |
|
281 fail_unless (gst_element_query (GST_ELEMENT (src), pos), |
|
282 "Could not query duration of fakesrc"); |
|
283 |
|
284 fail_unless (gst_element_query (GST_ELEMENT (sink), pos), |
|
285 "Could not query position of fakesink"); |
|
286 fail_unless (gst_element_query (GST_ELEMENT (sink), pos), |
|
287 "Could not query duration of fakesink"); |
|
288 |
|
289 /* Query pads */ |
|
290 fail_unless ((pad = gst_element_get_pad (src, "src")) != NULL, |
|
291 "Could not get source pad of fakesrc"); |
|
292 fail_unless (gst_pad_query (pad, pos), |
|
293 "Could not query position of fakesrc src pad"); |
|
294 fail_unless (gst_pad_query (pad, dur), |
|
295 "Could not query duration of fakesrc src pad"); |
|
296 gst_object_unref (pad); |
|
297 |
|
298 /* We don't query the sink pad of fakesink, it doesn't |
|
299 * handle downstream queries atm, but it might later, who knows? */ |
|
300 |
|
301 ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL); |
|
302 fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline NULL"); |
|
303 if (ret == GST_STATE_CHANGE_ASYNC) |
|
304 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE); |
|
305 |
|
306 gst_query_unref (dur); |
|
307 gst_query_unref (pos); |
|
308 gst_object_unref (bin); |
|
309 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
310 create_xml(0); |
|
311 |
|
312 } |
|
313 |
|
314 #if 1 |
|
315 void (*fn[2]) (void) = { |
|
316 create_queries, |
|
317 test_queries |
|
318 }; |
|
319 |
|
320 char *args[] = { |
|
321 "create_queries", |
|
322 "test_queries" |
|
323 }; |
|
324 |
|
325 |
|
326 |
|
327 GST_CHECK_MAIN (gst_query); |
|
328 #endif |
|
329 |
|
330 |
|
331 #if 0 |
|
332 int main() |
|
333 { |
|
334 |
|
335 |
|
336 gst_check_init (NULL, NULL); |
|
337 create_queries(); |
|
338 test_queries(); |
|
339 } |
|
340 #endif |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |