1 /* GStreamer unit tests for libgstpbutils
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
26 #include <gst/pbutils/pbutils.h>
29 #include <glib/gstdio.h>
30 #include <glib/gprintf.h>
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h> /* for chmod() and getpid () */
36 #ifdef HAVE_SYS_STAT_H
37 #include <sys/stat.h> /* for chmod() */
41 #include <unistd.h> /* for unlink() */
45 missing_msg_check_getters (GstMessage * msg)
49 str = gst_missing_plugin_message_get_installer_detail (msg);
50 fail_unless (str != NULL);
51 fail_unless (*str != '\0');
52 fail_unless (g_str_has_prefix (str, "gstreamer|"));
55 str = gst_missing_plugin_message_get_description (msg);
56 fail_unless (str != NULL);
57 fail_unless (*str != '\0');
61 GST_START_TEST (test_pb_utils_post_missing_messages)
71 pipeline = gst_pipeline_new ("pipeline");
72 bus = gst_element_get_bus (pipeline);
74 /* first, test common assertion failure cases */
75 ASSERT_CRITICAL (msg = gst_missing_uri_source_message_new (NULL, "http"));
76 ASSERT_CRITICAL (gst_missing_uri_source_message_new (pipeline, NULL));
78 ASSERT_CRITICAL (gst_missing_uri_sink_message_new (NULL, "http"));
79 ASSERT_CRITICAL (gst_missing_uri_sink_message_new (pipeline, NULL));
81 ASSERT_CRITICAL (gst_missing_element_message_new (NULL, "rgbfyltr"));
82 ASSERT_CRITICAL (gst_missing_element_message_new (pipeline, NULL));
84 caps = gst_caps_new_simple ("audio/x-dontexist", NULL);
86 ASSERT_CRITICAL (gst_missing_decoder_message_new (NULL, caps));
87 ASSERT_CRITICAL (gst_missing_decoder_message_new (pipeline, NULL));
89 ASSERT_CRITICAL (gst_missing_encoder_message_new (NULL, caps));
90 ASSERT_CRITICAL (gst_missing_encoder_message_new (pipeline, NULL));
92 gst_caps_unref (caps);
94 /* URI source (with existing protocol) */
95 msg = gst_missing_uri_source_message_new (pipeline, "http");
96 fail_unless (msg != NULL);
97 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
98 fail_unless (msg->structure != NULL);
100 fail_unless (gst_structure_has_name (s, "missing-plugin"));
101 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
102 fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource");
103 fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
104 fail_unless_equals_string (gst_structure_get_string (s, "detail"), "http");
105 missing_msg_check_getters (msg);
106 gst_message_unref (msg);
108 /* URI sink (with existing protocol) */
109 msg = gst_missing_uri_sink_message_new (pipeline, "smb");
110 fail_unless (msg != NULL);
111 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
112 fail_unless (msg->structure != NULL);
114 fail_unless (gst_structure_has_name (s, "missing-plugin"));
115 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
116 fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink");
117 fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
118 fail_unless_equals_string (gst_structure_get_string (s, "detail"), "smb");
119 missing_msg_check_getters (msg);
120 gst_message_unref (msg);
122 /* URI source (with bogus protocol) */
123 msg = gst_missing_uri_source_message_new (pipeline, "chchck");
124 fail_unless (msg != NULL);
125 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
126 fail_unless (msg->structure != NULL);
128 fail_unless (gst_structure_has_name (s, "missing-plugin"));
129 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
130 fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource");
131 fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
132 fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck");
133 missing_msg_check_getters (msg);
134 gst_message_unref (msg);
136 /* URI sink (with bogus protocol) */
137 msg = gst_missing_uri_sink_message_new (pipeline, "chchck");
138 fail_unless (msg != NULL);
139 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
140 fail_unless (msg->structure != NULL);
142 fail_unless (gst_structure_has_name (s, "missing-plugin"));
143 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
144 fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink");
145 fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
146 fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck");
147 missing_msg_check_getters (msg);
148 gst_message_unref (msg);
151 msg = gst_missing_element_message_new (pipeline, "foobar");
152 fail_unless (msg != NULL);
153 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
154 fail_unless (msg->structure != NULL);
156 fail_unless (gst_structure_has_name (s, "missing-plugin"));
157 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
158 fail_unless_equals_string (gst_structure_get_string (s, "type"), "element");
159 fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING));
160 fail_unless_equals_string (gst_structure_get_string (s, "detail"), "foobar");
161 missing_msg_check_getters (msg);
162 gst_message_unref (msg);
164 /* create bogus caps that don't exist */
165 caps = gst_caps_new_simple ("do/x-not", "exist", G_TYPE_BOOLEAN, FALSE, NULL);
167 /* decoder (with unknown caps) */
168 msg = gst_missing_decoder_message_new (pipeline, caps);
169 fail_unless (msg != NULL);
170 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
171 fail_unless (msg->structure != NULL);
173 fail_unless (gst_structure_has_name (s, "missing-plugin"));
174 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
175 fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder");
176 fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
177 missing_msg_check_getters (msg);
178 gst_message_unref (msg);
180 /* encoder (with unknown caps) */
181 msg = gst_missing_encoder_message_new (pipeline, caps);
182 fail_unless (msg != NULL);
183 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
184 fail_unless (msg->structure != NULL);
186 fail_unless (gst_structure_has_name (s, "missing-plugin"));
187 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
188 fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder");
189 fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
190 missing_msg_check_getters (msg);
191 gst_message_unref (msg);
193 gst_caps_unref (caps);
195 /* create caps that exist */
196 caps = gst_caps_new_simple ("video/x-matroska", NULL);
197 /* decoder (with known caps) */
198 msg = gst_missing_decoder_message_new (pipeline, caps);
199 fail_unless (msg != NULL);
200 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
201 fail_unless (msg->structure != NULL);
203 fail_unless (gst_structure_has_name (s, "missing-plugin"));
204 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
205 fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder");
206 fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
207 fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING));
208 fail_unless (gst_structure_get_string (s, "name") != NULL);
209 missing_msg_check_getters (msg);
210 gst_message_unref (msg);
212 /* encoder (with known caps) */
213 msg = gst_missing_encoder_message_new (pipeline, caps);
214 fail_unless (msg != NULL);
215 fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT);
216 fail_unless (msg->structure != NULL);
218 fail_unless (gst_structure_has_name (s, "missing-plugin"));
219 fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING));
220 fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder");
221 fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS));
222 fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING));
223 fail_unless (gst_structure_get_string (s, "name") != NULL);
224 missing_msg_check_getters (msg);
225 gst_message_unref (msg);
227 gst_caps_unref (caps);
229 gst_element_set_state (pipeline, GST_STATE_NULL);
230 gst_object_unref (pipeline);
231 gst_object_unref (bus);
236 GST_START_TEST (test_pb_utils_init)
238 /* should be fine to call multiple times */
239 gst_pb_utils_init ();
240 gst_pb_utils_init ();
241 gst_pb_utils_init ();
242 gst_pb_utils_init ();
247 static const gchar *caps_strings[] = {
248 /* formats with static descriptions */
249 "application/ogg", "application/vnd.rn-realmedia", "video/x-fli",
250 "video/x-flv", "video/x-matroska", "video/x-ms-asf", "video/x-msvideo",
251 "video/x-quicktime", "video/quicktime", "audio/x-ac3", "audio/ac3",
252 "audio/x-private-ac3", "audio/x-private1-ac3", "audio/x-adpcm",
253 "audio/aiff", "audio/x-alaw", "audio/amr", "audio/AMR", "audio/AMR-WB",
254 "audio/iLBC-sh", "audio/ms-gsm", "audio/qcelp", "audio/x-adpcm",
255 "audio/x-aiff", "audio/x-alac", "audio/x-amr-nb-sh", "audio/x-amr-wb-sh",
256 "audio/x-au", "audio/x-cinepak", "audio/x-dpcm", "audio/x-dts",
257 "audio/x-dv", "audio/x-flac", "audio/x-gsm", "audio/x-iec958",
258 "audio/x-iLBC", "audio/x-ircam", "audio/x-lpcm", "audio/x-private1-lpcm",
259 "audio/x-m4a", "audio/x-mod", "audio/x-mulaw", "audio/x-musepack",
260 "audio/x-nist", "audio/x-nsf", "audio/x-paris", "audio/x-qdm2",
261 "audio/x-ralf-mpeg4-generic", "audio/x-sds", "audio/x-shorten",
262 "audio/x-sid", "audio/x-sipro", "audio/x-spc", "audio/x-speex",
263 "audio/x-svx", "audio/x-tta", "audio/x-ttafile",
264 "audio/x-vnd.sony.atrac3", "audio/x-vorbis", "audio/x-voc", "audio/x-w64",
265 "audio/x-wav", "audio/x-wavpack", "audio/x-wavpack-correction",
266 "audio/x-wms", "audio/x-voxware", "video/sp5x", "video/vivo",
267 "video/x-3ivx", "video/x-4xm", "video/x-apple-video", "video/x-camtasia",
268 "video/x-cdxa", "video/x-cinepak", "video/x-cirrus-logic-accupak",
269 "video/x-compressed-yuv", "video/x-dirac", "video/x-dvd-subpicture",
270 "video/x-ffv", "video/x-flash-screen", "video/x-flash-video",
271 "video/x-h261", "video/x-huffyuv", "video/x-intel-h263", "video/x-jpeg",
272 "video/x-mjpeg", "video/x-mjpeg-b", "video/mpegts", "video/x-mng",
273 "video/x-mszh", "video/x-msvideocodec", "video/x-mve", "video/x-nut",
274 "video/x-nuv", "video/x-qdrw", "video/x-raw-gray", "video/x-smc",
275 "video/x-smoke", "video/x-tarkin", "video/x-theora", "video/x-rle",
276 "video/x-ultimotion", "video/x-vcd", "video/x-vmnc", "video/x-vp3",
277 "video/x-vp5", "video/x-vp6", "video/x-vp6-flash", "video/x-vp7",
278 "video/x-xvid", "video/x-zlib", "image/bmp", "image/x-bmp",
279 "image/x-MS-bmp", "image/gif", "image/jpeg", "image/jng", "image/png",
280 "image/pbm", "image/ppm", "image/svg+xml", "image/tiff",
281 "image/x-cmu-raster", "image/x-icon", "image/x-xcf", "image/x-pixmap",
282 "image/x-xpixmap", "image/x-quicktime", "image/x-sun-raster",
283 "image/x-tga", "video/x-dv", "video/x-dv",
284 /* some RTP formats */
285 "application/x-rtp, media=(string)video, encoding-name=(string)TimVCodec",
286 "application/x-rtp, media=(string)audio, encoding-name=(string)TimACodec",
287 "application/x-rtp, media=(string)application, encoding-name=(string)TimMux",
288 "application/x-rtp, media=(string)woohoo, encoding-name=(string)TPM",
289 /* incomplete RTP formats */
290 "application/x-rtp, media=(string)woohoo",
291 "application/x-rtp, encoding-name=(string)TPM",
292 "application/x-rtp, media=(string)woohoo",
293 /* formats with dynamic descriptions */
295 "audio/x-adpcm, layout=(string)dvi",
296 "audio/x-adpcm, layout=(string)swf",
297 "audio/x-adpcm, layout=(string)microsoft",
298 "audio/x-adpcm, layout=(string)quicktime",
299 "audio/mpeg, mpegversion=(int)4",
300 "audio/mpeg, mpegversion=(int)1, layer=(int)1",
301 "audio/mpeg, mpegversion=(int)1, layer=(int)2",
302 "audio/mpeg, mpegversion=(int)1, layer=(int)3",
303 "audio/mpeg, mpegversion=(int)1, layer=(int)99",
304 "audio/mpeg, mpegversion=(int)99",
305 "video/mpeg, mpegversion=(int)2, systemstream=(boolean)TRUE",
306 "video/mpeg, systemstream=(boolean)FALSE",
307 "video/mpeg, mpegversion=(int)2",
308 "video/mpeg, mpegversion=(int)1, systemstream=(boolean)FALSE",
309 "video/mpeg, mpegversion=(int)2, systemstream=(boolean)FALSE",
310 "video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE",
311 "video/mpeg, mpegversion=(int)99, systemstream=(boolean)TRUE",
312 "video/mpeg, mpegversion=(int)99, systemstream=(boolean)FALSE",
314 "video/x-indeo, indeoversion=(int)3",
315 "video/x-indeo, indeoversion=(int)5",
317 "video/x-wmv, wmvversion=(int)1",
318 "video/x-wmv, wmvversion=(int)2",
319 "video/x-wmv, wmvversion=(int)3",
320 "video/x-wmv, wmvversion=(int)99",
322 "audio/x-wma, wmaversion=(int)1",
323 "audio/x-wma, wmaversion=(int)2",
324 "audio/x-wma, wmaversion=(int)3",
325 "audio/x-wma, wmaversion=(int)99",
327 "video/x-divx, divxversion=(int)3",
328 "video/x-divx, divxversion=(int)4",
329 "video/x-divx, divxversion=(int)5",
330 "video/x-divx, divxversion=(int)99",
332 "video/x-svq, svqversion=(int)1",
333 "video/x-svq, svqversion=(int)3",
334 "video/x-svq, svqversion=(int)99",
336 "video/x-h264, variant=(string)itu",
337 "video/x-h264, variant=(string)videosoft",
338 "video/x-h264, variant=(string)foobar",
340 "video/x-h263, variant=(string)itu",
341 "video/x-h263, variant=(string)lead",
342 "video/x-h263, variant=(string)microsoft",
343 "video/x-h263, variant=(string)vdolive",
344 "video/x-h263, variant=(string)vivo",
345 "video/x-h263, variant=(string)xirlink",
346 "video/x-h263, variant=(string)foobar",
348 "video/x-msmpeg, msmpegversion=(int)41",
349 "video/x-msmpeg, msmpegversion=(int)42",
350 "video/x-msmpeg, msmpegversion=(int)43",
351 "video/x-msmpeg, msmpegversion=(int)99",
353 "video/x-pn-realvideo, rmversion=(int)1",
354 "video/x-pn-realvideo, rmversion=(int)2",
355 "video/x-pn-realvideo, rmversion=(int)3",
356 "video/x-pn-realvideo, rmversion=(int)4",
357 "video/x-pn-realvideo, rmversion=(int)99",
358 "video/x-pn-realvideo",
359 "audio/x-pn-realaudio, raversion=(int)1",
360 "audio/x-pn-realaudio, raversion=(int)2",
361 "audio/x-pn-realaudio, raversion=(int)99",
362 "audio/x-pn-realaudio",
363 "audio/x-mace, maceversion=(int)3",
364 "audio/x-mace, maceversion=(int)6",
365 "audio/x-mace, maceversion=(int)99",
367 "video/x-truemotion, trueversion=(int)1",
368 "video/x-truemotion, trueversion=(int)2",
369 "video/x-truemotion, trueversion=(int)99",
370 "video/x-truemotion",
371 "video/x-asus, asusversion=(int)1",
372 "video/x-asus, asusversion=(int)2",
373 "video/x-asus, asusversion=(int)99",
375 "video/x-xan, wcversion=(int)1",
376 "video/x-xan, wcversion=(int)99",
378 "video/x-ati-vcr, vcrversion=(int)1",
379 "video/x-ati-vcr, vcrversion=(int)2",
380 "video/x-ati-vcr, vcrversion=(int)99",
383 "audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)44100, channels=(int)2",
384 "audio/x-raw-float, rate=(int)22050, channels=(int)2, endianness=(int)1234, width=(int)32",
386 "video/x-raw-rgb, bpp=(int)16, endianness=(int)1234, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1",
387 "video/x-raw-yuv, format=(fourcc)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1",
388 /* and a made-up format */
392 GST_START_TEST (test_pb_utils_get_codec_description)
396 gst_pb_utils_init ();
398 for (i = 0; i < G_N_ELEMENTS (caps_strings); ++i) {
402 caps = gst_caps_from_string (caps_strings[i]);
403 fail_unless (caps != NULL, "could not create caps from string '%s'",
405 GST_LOG ("Caps %s:", caps_strings[i]);
406 desc = gst_pb_utils_get_codec_description (caps);
407 fail_unless (desc != NULL);
408 GST_LOG (" - codec : %s", desc);
410 desc = gst_pb_utils_get_decoder_description (caps);
411 fail_unless (desc != NULL);
412 GST_LOG (" - decoder : %s", desc);
414 desc = gst_pb_utils_get_encoder_description (caps);
415 fail_unless (desc != NULL);
416 GST_LOG (" - encoder : %s", desc);
418 gst_caps_unref (caps);
425 GST_START_TEST (test_pb_utils_taglist_add_codec_info)
430 gst_pb_utils_init ();
431 list = gst_tag_list_new ();
432 caps = gst_caps_new_simple ("video/x-theora", NULL);
433 ASSERT_CRITICAL (fail_if
434 (gst_pb_utils_add_codec_description_to_tag_list (NULL,
435 GST_TAG_VIDEO_CODEC, caps)));
436 ASSERT_CRITICAL (fail_if
437 (gst_pb_utils_add_codec_description_to_tag_list (list, NULL, caps)));
438 ASSERT_CRITICAL (fail_if
439 (gst_pb_utils_add_codec_description_to_tag_list (list, "asdfa", caps)));
440 ASSERT_CRITICAL (fail_if
441 (gst_pb_utils_add_codec_description_to_tag_list (list,
442 GST_TAG_IMAGE, caps)));
443 ASSERT_CRITICAL (fail_if
444 (gst_pb_utils_add_codec_description_to_tag_list (list,
445 GST_TAG_VIDEO_CODEC, NULL)));
446 /* FIXME: do something here */
447 fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list,
448 GST_TAG_VIDEO_CODEC, caps));
449 fail_if (gst_tag_list_is_empty (list));
450 gst_tag_list_free (list);
451 gst_caps_unref (caps);
459 result_cb (GstInstallPluginsReturn result, gpointer user_data)
461 GST_LOG ("result = %u, user_data = %p", result, user_data);
463 fail_unless (user_data == (gpointer) & marker);
468 #define SCRIPT_NO_XID \
470 "if test x$1 != xdetail1; then exit 21; fi;\n" \
471 "if test x$2 != xdetail2; then exit 22; fi;\n" \
474 #define SCRIPT_WITH_XID \
476 "if test x$1 != 'x--transient-for=42'; then exit 21; fi;\n" \
477 "if test x$2 != xdetail1; then exit 22; fi;\n" \
478 "if test x$3 != xdetail2; then exit 23; fi;\n" \
481 /* make sure our script gets called with the right parameters */
483 test_pb_utils_install_plugins_do_callout (gchar ** details,
484 GstInstallPluginsContext * ctx, const gchar * script,
485 GstInstallPluginsReturn expected_result)
488 GstInstallPluginsReturn ret;
492 path = g_strdup_printf ("%s/gst-plugins-base-unit-test-helper.%s.%lu",
493 g_get_tmp_dir (), (g_get_user_name ())? g_get_user_name () : "nobody",
496 if (!g_file_set_contents (path, script, -1, &err)) {
497 GST_DEBUG ("Failed to write test script to %s: %s", path, err->message);
502 if (chmod (path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
503 GST_DEBUG ("Could not set mode u+rwx on '%s'", path);
507 /* test gst_install_plugins_supported() I */
508 g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/i/do/not/ex.ist!", 1);
509 fail_if (gst_install_plugins_supported ());
511 GST_LOG ("setting GST_INSTALL_PLUGINS_HELPER to '%s'", path);
512 g_setenv ("GST_INSTALL_PLUGINS_HELPER", path, 1);
514 /* test gst_install_plugins_supported() II */
515 fail_unless (gst_install_plugins_supported ());
517 /* test sync callout */
518 ret = gst_install_plugins_sync (details, ctx);
519 fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING ||
520 ret == expected_result,
521 "gst_install_plugins_sync() failed with unexpected ret %d, which is "
522 "neither HELPER_MISSING nor %d", ret, expected_result);
524 /* test async callout */
526 ret = gst_install_plugins_async (details, ctx, result_cb,
527 (gpointer) & marker);
528 fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING ||
529 ret == GST_INSTALL_PLUGINS_STARTED_OK,
530 "gst_install_plugins_async() failed with unexpected ret %d", ret);
531 if (ret == GST_INSTALL_PLUGINS_STARTED_OK) {
532 while (marker == -333) {
534 g_main_context_iteration (NULL, FALSE);
536 /* and check that the callback was called with the expected code */
537 fail_unless_equals_int (marker, expected_result);
544 #endif /* G_OS_UNIX */
547 GST_START_TEST (test_pb_utils_install_plugins)
549 GstInstallPluginsContext *ctx;
550 GstInstallPluginsReturn ret;
551 gchar *details[] = { (char *) "detail1", (char *) "detail2", NULL };
552 gchar *details_multi[] =
553 { (char *) "detail1", (char *) "detail1", (char *) "detail2", NULL };
555 ctx = gst_install_plugins_context_new ();
557 ASSERT_CRITICAL (ret = gst_install_plugins_sync (NULL, ctx));
558 ASSERT_CRITICAL (ret =
559 gst_install_plugins_async (NULL, ctx, result_cb, (gpointer) & marker));
560 ASSERT_CRITICAL (ret =
561 gst_install_plugins_async (details, ctx, NULL, (gpointer) & marker));
563 /* make sure the functions return the right error code if the helper does
565 g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/does/not/ex/is.t", 1);
566 ret = gst_install_plugins_sync (details, NULL);
567 fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
571 gst_install_plugins_async (details, NULL, result_cb, (gpointer) & marker);
572 fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
573 /* and check that the callback wasn't called */
574 fail_unless_equals_int (marker, -333);
576 /* now make sure our scripts are actually called as expected (if possible) */
577 test_pb_utils_install_plugins_do_callout (details, NULL, SCRIPT_NO_XID,
578 GST_INSTALL_PLUGINS_NOT_FOUND);
580 /* and again with context */
581 gst_install_plugins_context_set_xid (ctx, 42);
582 test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID,
583 GST_INSTALL_PLUGINS_SUCCESS);
585 /* and make sure that duplicate detail strings get dropped */
586 test_pb_utils_install_plugins_do_callout (details_multi, NULL, SCRIPT_NO_XID,
587 GST_INSTALL_PLUGINS_NOT_FOUND);
589 /* and the same again with context */
590 gst_install_plugins_context_set_xid (ctx, 42);
591 test_pb_utils_install_plugins_do_callout (details_multi, ctx, SCRIPT_WITH_XID,
592 GST_INSTALL_PLUGINS_SUCCESS);
594 /* and free the context now that we don't need it any longer */
595 gst_install_plugins_context_free (ctx);
597 /* completely silly test to check gst_install_plugins_return_get_name()
598 * is somewhat well-behaved */
602 for (i = -99; i < 16738; ++i) {
605 s = gst_install_plugins_return_get_name ((GstInstallPluginsReturn) i);
606 fail_unless (s != NULL);
607 /* GST_LOG ("%5d = %s", i, s); */
614 GST_START_TEST (test_pb_utils_installer_details)
619 gchar *detail1, *detail2;
621 el = gst_pipeline_new ("dummy-element");
624 detail1 = gst_missing_uri_source_installer_detail_new ("http");
625 fail_unless (detail1 != NULL);
626 fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
627 fail_unless (g_str_has_suffix (detail1, "|urisource-http"));
628 msg = gst_missing_uri_source_message_new (el, "http");
629 fail_unless (msg != NULL);
630 detail2 = gst_missing_plugin_message_get_installer_detail (msg);
631 fail_unless (detail2 != NULL);
632 gst_message_unref (msg);
633 fail_unless_equals_string (detail1, detail2);
638 detail1 = gst_missing_uri_sink_installer_detail_new ("http");
639 fail_unless (detail1 != NULL);
640 fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
641 fail_unless (g_str_has_suffix (detail1, "|urisink-http"));
642 msg = gst_missing_uri_sink_message_new (el, "http");
643 fail_unless (msg != NULL);
644 detail2 = gst_missing_plugin_message_get_installer_detail (msg);
645 fail_unless (detail2 != NULL);
646 gst_message_unref (msg);
647 fail_unless_equals_string (detail1, detail2);
652 detail1 = gst_missing_element_installer_detail_new ("deinterlace");
653 fail_unless (detail1 != NULL);
654 fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
655 fail_unless (g_str_has_suffix (detail1, "|element-deinterlace"));
656 msg = gst_missing_element_message_new (el, "deinterlace");
657 fail_unless (msg != NULL);
658 detail2 = gst_missing_plugin_message_get_installer_detail (msg);
659 fail_unless (detail2 != NULL);
660 gst_message_unref (msg);
661 fail_unless_equals_string (detail1, detail2);
666 caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
667 2, "channels", G_TYPE_INT, 6, NULL);
668 detail1 = gst_missing_decoder_installer_detail_new (caps);
669 fail_unless (detail1 != NULL);
670 fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
671 fail_unless (g_str_has_suffix (detail1,
672 "|decoder-audio/x-spiffy, spiffyversion=(int)2"));
673 msg = gst_missing_decoder_message_new (el, caps);
674 fail_unless (msg != NULL);
675 detail2 = gst_missing_plugin_message_get_installer_detail (msg);
676 fail_unless (detail2 != NULL);
677 gst_message_unref (msg);
678 gst_caps_unref (caps);
679 fail_unless_equals_string (detail1, detail2);
684 caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
685 2, "channels", G_TYPE_INT, 6, NULL);
686 detail1 = gst_missing_encoder_installer_detail_new (caps);
687 fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
688 fail_unless (g_str_has_suffix (detail1,
689 "|encoder-audio/x-spiffy, spiffyversion=(int)2"));
690 fail_unless (detail1 != NULL);
691 msg = gst_missing_encoder_message_new (el, caps);
692 fail_unless (msg != NULL);
693 detail2 = gst_missing_plugin_message_get_installer_detail (msg);
694 fail_unless (detail2 != NULL);
695 gst_message_unref (msg);
696 gst_caps_unref (caps);
697 fail_unless_equals_string (detail1, detail2);
701 gst_object_unref (el);
706 GST_START_TEST (test_pb_utils_versions)
709 guint maj, min, mic, nano;
711 gst_plugins_base_version (NULL, NULL, NULL, NULL);
712 gst_plugins_base_version (&maj, &min, &mic, &nano);
713 fail_unless_equals_int (maj, GST_PLUGINS_BASE_VERSION_MAJOR);
714 fail_unless_equals_int (min, GST_PLUGINS_BASE_VERSION_MINOR);
715 fail_unless_equals_int (mic, GST_PLUGINS_BASE_VERSION_MICRO);
716 fail_unless_equals_int (nano, GST_PLUGINS_BASE_VERSION_NANO);
718 s = gst_plugins_base_version_string ();
719 if (GST_PLUGINS_BASE_VERSION_NANO == 0) {
720 fail_if (strstr (s, "GIT") || strstr (s, "git") || strstr (s, "prerel"));
722 if (GST_PLUGINS_BASE_VERSION_NANO == 1) {
723 fail_unless (strstr (s, "GIT") || strstr (s, "git"));
725 if (GST_PLUGINS_BASE_VERSION_NANO >= 2) {
726 fail_unless (strstr (s, "Prerelease") || strstr (s, "prerelease"));
734 libgstpbutils_suite (void)
736 Suite *s = suite_create ("pbutils library");
737 TCase *tc_chain = tcase_create ("general");
739 suite_add_tcase (s, tc_chain);
740 tcase_add_test (tc_chain, test_pb_utils_init);
741 tcase_add_test (tc_chain, test_pb_utils_post_missing_messages);
742 tcase_add_test (tc_chain, test_pb_utils_taglist_add_codec_info);
743 tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
744 tcase_add_test (tc_chain, test_pb_utils_install_plugins);
745 tcase_add_test (tc_chain, test_pb_utils_installer_details);
746 tcase_add_test (tc_chain, test_pb_utils_versions);
750 GST_CHECK_MAIN (libgstpbutils);