gst_plugins_base/tests/check/libs/pbutils.c
changeset 2 5505e8908944
parent 0 0e761a78d257
equal deleted inserted replaced
1:4c282e7dd6d3 2:5505e8908944
       
     1 /* GStreamer unit tests for libgstpbutils
       
     2  *
       
     3  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
       
     4  *
       
     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.
       
     9  *
       
    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.
       
    14  *
       
    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.
       
    19  */
       
    20 
       
    21 #ifdef HAVE_CONFIG_H
       
    22 # include <config.h>
       
    23 #endif
       
    24 
       
    25 #include <gst/check/gstcheck.h>
       
    26 #include <gst/pbutils/pbutils.h>
       
    27 
       
    28 #include <stdio.h>
       
    29 #include <glib/gstdio.h>
       
    30 #include <glib/gprintf.h>
       
    31 
       
    32 #ifdef HAVE_SYS_TYPES_H
       
    33 #include <sys/types.h>          /* for chmod() and getpid () */
       
    34 #endif
       
    35 
       
    36 #ifdef HAVE_SYS_STAT_H
       
    37 #include <sys/stat.h>           /* for chmod() */
       
    38 #endif
       
    39 
       
    40 #ifdef HAVE_UNISTD_H
       
    41 #include <unistd.h>             /* for unlink() */
       
    42 #endif
       
    43 
       
    44 static void
       
    45 missing_msg_check_getters (GstMessage * msg)
       
    46 {
       
    47   gchar *str;
       
    48 
       
    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|"));
       
    53   g_free (str);
       
    54 
       
    55   str = gst_missing_plugin_message_get_description (msg);
       
    56   fail_unless (str != NULL);
       
    57   fail_unless (*str != '\0');
       
    58   g_free (str);
       
    59 }
       
    60 
       
    61 GST_START_TEST (test_pb_utils_post_missing_messages)
       
    62 {
       
    63   GstElement *pipeline;
       
    64   GstStructure *s;
       
    65   GstMessage *msg;
       
    66   GstCaps *caps;
       
    67   GstBus *bus;
       
    68 
       
    69   gst_pb_utils_init ();
       
    70 
       
    71   pipeline = gst_pipeline_new ("pipeline");
       
    72   bus = gst_element_get_bus (pipeline);
       
    73 
       
    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));
       
    77 
       
    78   ASSERT_CRITICAL (gst_missing_uri_sink_message_new (NULL, "http"));
       
    79   ASSERT_CRITICAL (gst_missing_uri_sink_message_new (pipeline, NULL));
       
    80 
       
    81   ASSERT_CRITICAL (gst_missing_element_message_new (NULL, "rgbfyltr"));
       
    82   ASSERT_CRITICAL (gst_missing_element_message_new (pipeline, NULL));
       
    83 
       
    84   caps = gst_caps_new_simple ("audio/x-dontexist", NULL);
       
    85 
       
    86   ASSERT_CRITICAL (gst_missing_decoder_message_new (NULL, caps));
       
    87   ASSERT_CRITICAL (gst_missing_decoder_message_new (pipeline, NULL));
       
    88 
       
    89   ASSERT_CRITICAL (gst_missing_encoder_message_new (NULL, caps));
       
    90   ASSERT_CRITICAL (gst_missing_encoder_message_new (pipeline, NULL));
       
    91 
       
    92   gst_caps_unref (caps);
       
    93 
       
    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);
       
    99   s = msg->structure;
       
   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);
       
   107 
       
   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);
       
   113   s = msg->structure;
       
   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);
       
   121 
       
   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);
       
   127   s = msg->structure;
       
   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);
       
   135 
       
   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);
       
   141   s = msg->structure;
       
   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);
       
   149 
       
   150   /* element */
       
   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);
       
   155   s = msg->structure;
       
   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);
       
   163 
       
   164   /* create bogus caps that don't exist */
       
   165   caps = gst_caps_new_simple ("do/x-not", "exist", G_TYPE_BOOLEAN, FALSE, NULL);
       
   166 
       
   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);
       
   172   s = msg->structure;
       
   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);
       
   179 
       
   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);
       
   185   s = msg->structure;
       
   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);
       
   192 
       
   193   gst_caps_unref (caps);
       
   194 
       
   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);
       
   202   s = msg->structure;
       
   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);
       
   211 
       
   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);
       
   217   s = msg->structure;
       
   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);
       
   226 
       
   227   gst_caps_unref (caps);
       
   228 
       
   229   gst_element_set_state (pipeline, GST_STATE_NULL);
       
   230   gst_object_unref (pipeline);
       
   231   gst_object_unref (bus);
       
   232 }
       
   233 
       
   234 GST_END_TEST;
       
   235 
       
   236 GST_START_TEST (test_pb_utils_init)
       
   237 {
       
   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 ();
       
   243 }
       
   244 
       
   245 GST_END_TEST;
       
   246 
       
   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 */
       
   294   "audio/x-adpcm",
       
   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",
       
   313   "video/mpeg",
       
   314   "video/x-indeo, indeoversion=(int)3",
       
   315   "video/x-indeo, indeoversion=(int)5",
       
   316   "video/x-indeo",
       
   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",
       
   321   "video/x-wmv",
       
   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",
       
   326   "audio/x-wma",
       
   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",
       
   331   "video/x-divx",
       
   332   "video/x-svq, svqversion=(int)1",
       
   333   "video/x-svq, svqversion=(int)3",
       
   334   "video/x-svq, svqversion=(int)99",
       
   335   "video/x-svq",
       
   336   "video/x-h264, variant=(string)itu",
       
   337   "video/x-h264, variant=(string)videosoft",
       
   338   "video/x-h264, variant=(string)foobar",
       
   339   "video/x-h264",
       
   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",
       
   347   "video/x-h263",
       
   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",
       
   352   "video/x-msmpeg",
       
   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",
       
   366   "audio/x-mace",
       
   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",
       
   374   "video/x-asus",
       
   375   "video/x-xan, wcversion=(int)1",
       
   376   "video/x-xan, wcversion=(int)99",
       
   377   "video/x-xan",
       
   378   "video/x-ati-vcr, vcrversion=(int)1",
       
   379   "video/x-ati-vcr, vcrversion=(int)2",
       
   380   "video/x-ati-vcr, vcrversion=(int)99",
       
   381   "video/x-ati-vcr",
       
   382   /* raw audio */
       
   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",
       
   385   /* raw video */
       
   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 */
       
   389   "video/x-tpm"
       
   390 };
       
   391 
       
   392 GST_START_TEST (test_pb_utils_get_codec_description)
       
   393 {
       
   394   gint i;
       
   395 
       
   396   gst_pb_utils_init ();
       
   397 
       
   398   for (i = 0; i < G_N_ELEMENTS (caps_strings); ++i) {
       
   399     GstCaps *caps;
       
   400     gchar *desc;
       
   401 
       
   402     caps = gst_caps_from_string (caps_strings[i]);
       
   403     fail_unless (caps != NULL, "could not create caps from string '%s'",
       
   404         caps_strings[i]);
       
   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);
       
   409     g_free (desc);
       
   410     desc = gst_pb_utils_get_decoder_description (caps);
       
   411     fail_unless (desc != NULL);
       
   412     GST_LOG (" - decoder : %s", desc);
       
   413     g_free (desc);
       
   414     desc = gst_pb_utils_get_encoder_description (caps);
       
   415     fail_unless (desc != NULL);
       
   416     GST_LOG (" - encoder : %s", desc);
       
   417     g_free (desc);
       
   418     gst_caps_unref (caps);
       
   419   }
       
   420 }
       
   421 
       
   422 GST_END_TEST;
       
   423 
       
   424 
       
   425 GST_START_TEST (test_pb_utils_taglist_add_codec_info)
       
   426 {
       
   427   GstTagList *list;
       
   428   GstCaps *caps;
       
   429 
       
   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);
       
   452 }
       
   453 
       
   454 GST_END_TEST;
       
   455 
       
   456 static gint marker;
       
   457 
       
   458 static void
       
   459 result_cb (GstInstallPluginsReturn result, gpointer user_data)
       
   460 {
       
   461   GST_LOG ("result = %u, user_data = %p", result, user_data);
       
   462 
       
   463   fail_unless (user_data == (gpointer) & marker);
       
   464 
       
   465   marker = result;
       
   466 }
       
   467 
       
   468 #define SCRIPT_NO_XID \
       
   469     "#!/bin/sh\n"                                  \
       
   470     "if test x$1 != xdetail1; then exit 21; fi;\n" \
       
   471     "if test x$2 != xdetail2; then exit 22; fi;\n" \
       
   472     "exit 1\n"
       
   473 
       
   474 #define SCRIPT_WITH_XID \
       
   475     "#!/bin/sh\n"                                  \
       
   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" \
       
   479     "exit 0\n"
       
   480 
       
   481 /* make sure our script gets called with the right parameters */
       
   482 static void
       
   483 test_pb_utils_install_plugins_do_callout (gchar ** details,
       
   484     GstInstallPluginsContext * ctx, const gchar * script,
       
   485     GstInstallPluginsReturn expected_result)
       
   486 {
       
   487 #ifdef G_OS_UNIX
       
   488   GstInstallPluginsReturn ret;
       
   489   GError *err = NULL;
       
   490   gchar *path;
       
   491 
       
   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",
       
   494       (gulong) getpid ());
       
   495 
       
   496   if (!g_file_set_contents (path, script, -1, &err)) {
       
   497     GST_DEBUG ("Failed to write test script to %s: %s", path, err->message);
       
   498     g_error_free (err);
       
   499     goto done;
       
   500   }
       
   501 
       
   502   if (chmod (path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
       
   503     GST_DEBUG ("Could not set mode u+rwx on '%s'", path);
       
   504     goto done;
       
   505   }
       
   506 
       
   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 ());
       
   510 
       
   511   GST_LOG ("setting GST_INSTALL_PLUGINS_HELPER to '%s'", path);
       
   512   g_setenv ("GST_INSTALL_PLUGINS_HELPER", path, 1);
       
   513 
       
   514   /* test gst_install_plugins_supported() II */
       
   515   fail_unless (gst_install_plugins_supported ());
       
   516 
       
   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);
       
   523 
       
   524   /* test async callout */
       
   525   marker = -333;
       
   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) {
       
   533       g_usleep (500);
       
   534       g_main_context_iteration (NULL, FALSE);
       
   535     }
       
   536     /* and check that the callback was called with the expected code */
       
   537     fail_unless_equals_int (marker, expected_result);
       
   538   }
       
   539 
       
   540 done:
       
   541 
       
   542   unlink (path);
       
   543   g_free (path);
       
   544 #endif /* G_OS_UNIX */
       
   545 }
       
   546 
       
   547 GST_START_TEST (test_pb_utils_install_plugins)
       
   548 {
       
   549   GstInstallPluginsContext *ctx;
       
   550   GstInstallPluginsReturn ret;
       
   551   gchar *details[] = { "detail1", "detail2", NULL };
       
   552 
       
   553   ctx = gst_install_plugins_context_new ();
       
   554 
       
   555   ASSERT_CRITICAL (ret = gst_install_plugins_sync (NULL, ctx);
       
   556       );
       
   557   ASSERT_CRITICAL (ret =
       
   558       gst_install_plugins_async (NULL, ctx, result_cb, (gpointer) & marker);
       
   559       );
       
   560   ASSERT_CRITICAL (ret =
       
   561       gst_install_plugins_async (details, ctx, NULL, (gpointer) & marker);
       
   562       );
       
   563 
       
   564   /* make sure the functions return the right error code if the helper does
       
   565    * not exist */
       
   566   g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/does/not/ex/is.t", 1);
       
   567   ret = gst_install_plugins_sync (details, NULL);
       
   568   fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
       
   569 
       
   570   marker = -333;
       
   571   ret =
       
   572       gst_install_plugins_async (details, NULL, result_cb, (gpointer) & marker);
       
   573   fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING);
       
   574   /* and check that the callback wasn't called */
       
   575   fail_unless_equals_int (marker, -333);
       
   576 
       
   577   /* now make sure our scripts are actually called as expected (if possible) */
       
   578   test_pb_utils_install_plugins_do_callout (details, NULL, SCRIPT_NO_XID,
       
   579       GST_INSTALL_PLUGINS_NOT_FOUND);
       
   580 
       
   581   /* and again with context */
       
   582   gst_install_plugins_context_set_xid (ctx, 42);
       
   583   test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID,
       
   584       GST_INSTALL_PLUGINS_SUCCESS);
       
   585 
       
   586   /* and free the context now that we don't need it any longer */
       
   587   gst_install_plugins_context_free (ctx);
       
   588 
       
   589   /* completely silly test to check gst_install_plugins_return_get_name()
       
   590    * is somewhat well-behaved */
       
   591   {
       
   592     gint i;
       
   593 
       
   594     for (i = -99; i < 16738; ++i) {
       
   595       const gchar *s;
       
   596 
       
   597       s = gst_install_plugins_return_get_name ((GstInstallPluginsReturn) i);
       
   598       fail_unless (s != NULL);
       
   599       /* GST_LOG ("%5d = %s", i, s); */
       
   600     }
       
   601   }
       
   602 }
       
   603 
       
   604 GST_END_TEST;
       
   605 
       
   606 GST_START_TEST (test_pb_utils_installer_details)
       
   607 {
       
   608   GstMessage *msg;
       
   609   GstElement *el;
       
   610   GstCaps *caps;
       
   611   gchar *detail1, *detail2;
       
   612 
       
   613   el = gst_pipeline_new ("dummy-element");
       
   614 
       
   615   /* uri source */
       
   616   detail1 = gst_missing_uri_source_installer_detail_new ("http");
       
   617   fail_unless (detail1 != NULL);
       
   618   fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
       
   619   fail_unless (g_str_has_suffix (detail1, "|urisource-http"));
       
   620   msg = gst_missing_uri_source_message_new (el, "http");
       
   621   fail_unless (msg != NULL);
       
   622   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
       
   623   fail_unless (detail2 != NULL);
       
   624   gst_message_unref (msg);
       
   625   fail_unless_equals_string (detail1, detail2);
       
   626   g_free (detail1);
       
   627   g_free (detail2);
       
   628 
       
   629   /* uri sink */
       
   630   detail1 = gst_missing_uri_sink_installer_detail_new ("http");
       
   631   fail_unless (detail1 != NULL);
       
   632   fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
       
   633   fail_unless (g_str_has_suffix (detail1, "|urisink-http"));
       
   634   msg = gst_missing_uri_sink_message_new (el, "http");
       
   635   fail_unless (msg != NULL);
       
   636   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
       
   637   fail_unless (detail2 != NULL);
       
   638   gst_message_unref (msg);
       
   639   fail_unless_equals_string (detail1, detail2);
       
   640   g_free (detail1);
       
   641   g_free (detail2);
       
   642 
       
   643   /* element */
       
   644   detail1 = gst_missing_element_installer_detail_new ("deinterlace");
       
   645   fail_unless (detail1 != NULL);
       
   646   fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
       
   647   fail_unless (g_str_has_suffix (detail1, "|element-deinterlace"));
       
   648   msg = gst_missing_element_message_new (el, "deinterlace");
       
   649   fail_unless (msg != NULL);
       
   650   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
       
   651   fail_unless (detail2 != NULL);
       
   652   gst_message_unref (msg);
       
   653   fail_unless_equals_string (detail1, detail2);
       
   654   g_free (detail1);
       
   655   g_free (detail2);
       
   656 
       
   657   /* decoder */
       
   658   caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
       
   659       2, "channels", G_TYPE_INT, 6, NULL);
       
   660   detail1 = gst_missing_decoder_installer_detail_new (caps);
       
   661   fail_unless (detail1 != NULL);
       
   662   fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
       
   663   fail_unless (g_str_has_suffix (detail1,
       
   664           "|decoder-audio/x-spiffy, spiffyversion=(int)2"));
       
   665   msg = gst_missing_decoder_message_new (el, caps);
       
   666   fail_unless (msg != NULL);
       
   667   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
       
   668   fail_unless (detail2 != NULL);
       
   669   gst_message_unref (msg);
       
   670   gst_caps_unref (caps);
       
   671   fail_unless_equals_string (detail1, detail2);
       
   672   g_free (detail1);
       
   673   g_free (detail2);
       
   674 
       
   675   /* encoder */
       
   676   caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT,
       
   677       2, "channels", G_TYPE_INT, 6, NULL);
       
   678   detail1 = gst_missing_encoder_installer_detail_new (caps);
       
   679   fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|"));
       
   680   fail_unless (g_str_has_suffix (detail1,
       
   681           "|encoder-audio/x-spiffy, spiffyversion=(int)2"));
       
   682   fail_unless (detail1 != NULL);
       
   683   msg = gst_missing_encoder_message_new (el, caps);
       
   684   fail_unless (msg != NULL);
       
   685   detail2 = gst_missing_plugin_message_get_installer_detail (msg);
       
   686   fail_unless (detail2 != NULL);
       
   687   gst_message_unref (msg);
       
   688   gst_caps_unref (caps);
       
   689   fail_unless_equals_string (detail1, detail2);
       
   690   g_free (detail1);
       
   691   g_free (detail2);
       
   692 
       
   693   gst_object_unref (el);
       
   694 }
       
   695 
       
   696 GST_END_TEST;
       
   697 
       
   698 static Suite *
       
   699 libgstpbutils_suite (void)
       
   700 {
       
   701   Suite *s = suite_create ("pbutils library");
       
   702   TCase *tc_chain = tcase_create ("general");
       
   703 
       
   704   suite_add_tcase (s, tc_chain);
       
   705   tcase_add_test (tc_chain, test_pb_utils_init);
       
   706   tcase_add_test (tc_chain, test_pb_utils_post_missing_messages);
       
   707   tcase_add_test (tc_chain, test_pb_utils_taglist_add_codec_info);
       
   708   tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
       
   709   tcase_add_test (tc_chain, test_pb_utils_install_plugins);
       
   710   tcase_add_test (tc_chain, test_pb_utils_installer_details);
       
   711   return s;
       
   712 }
       
   713 
       
   714 GST_CHECK_MAIN (libgstpbutils);