LCOV - code coverage report
Current view: top level - libs/gst/check - gstcheck.c (source / functions) Hit Total Coverage
Test: GStreamer 0.10.32.1 Lines: 148 262 56.5 %
Date: 2011-03-25 Functions: 20 23 87.0 %
Branches: 39 128 30.5 %

           Branch data     Line data    Source code
       1                 :            : /* GStreamer
       2                 :            :  *
       3                 :            :  * Common code for GStreamer unittests
       4                 :            :  *
       5                 :            :  * Copyright (C) 2004,2006 Thomas Vander Stichele <thomas at apestaart dot org>
       6                 :            :  * Copyright (C) 2008 Thijs Vermeir <thijsvermeir@gmail.com>
       7                 :            :  *
       8                 :            :  * This library is free software; you can redistribute it and/or
       9                 :            :  * modify it under the terms of the GNU Library General Public
      10                 :            :  * License as published by the Free Software Foundation; either
      11                 :            :  * version 2 of the License, or (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This library is distributed in the hope that it will be useful,
      14                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :            :  * Library General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU Library General Public
      19                 :            :  * License along with this library; if not, write to the
      20                 :            :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      21                 :            :  * Boston, MA 02111-1307, USA.
      22                 :            :  */
      23                 :            : /**
      24                 :            :  * SECTION:gstcheck
      25                 :            :  * @short_description: Common code for GStreamer unit tests
      26                 :            :  *
      27                 :            :  * These macros and functions are for internal use of the unit tests found
      28                 :            :  * inside the 'check' directories of various GStreamer packages.
      29                 :            :  */
      30                 :            : 
      31                 :            : #include "gstcheck.h"
      32                 :            : 
      33                 :            : GST_DEBUG_CATEGORY (check_debug);
      34                 :            : 
      35                 :            : /* logging function for tests
      36                 :            :  * a test uses g_message() to log a debug line
      37                 :            :  * a gst unit test can be run with GST_TEST_DEBUG env var set to see the
      38                 :            :  * messages
      39                 :            :  */
      40                 :            : 
      41                 :            : gboolean _gst_check_threads_running = FALSE;
      42                 :            : GList *thread_list = NULL;
      43                 :            : GMutex *mutex;
      44                 :            : GCond *start_cond;              /* used to notify main thread of thread startups */
      45                 :            : GCond *sync_cond;               /* used to synchronize all threads and main thread */
      46                 :            : 
      47                 :            : GList *buffers = NULL;
      48                 :            : GMutex *check_mutex = NULL;
      49                 :            : GCond *check_cond = NULL;
      50                 :            : 
      51                 :            : /* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */
      52                 :            : gboolean _gst_check_debug = FALSE;
      53                 :            : gboolean _gst_check_raised_critical = FALSE;
      54                 :            : gboolean _gst_check_raised_warning = FALSE;
      55                 :            : gboolean _gst_check_expecting_log = FALSE;
      56                 :            : 
      57                 :       1015 : static void gst_check_log_message_func
      58                 :            :     (const gchar * log_domain, GLogLevelFlags log_level,
      59                 :            :     const gchar * message, gpointer user_data)
      60                 :            : {
      61         [ -  + ]:       1015 :   if (_gst_check_debug) {
      62                 :          0 :     g_print ("%s", message);
      63                 :            :   }
      64                 :       1015 : }
      65                 :            : 
      66                 :        103 : static void gst_check_log_critical_func
      67                 :            :     (const gchar * log_domain, GLogLevelFlags log_level,
      68                 :            :     const gchar * message, gpointer user_data)
      69                 :            : {
      70         [ -  + ]:        103 :   if (!_gst_check_expecting_log) {
      71                 :          0 :     g_print ("\n\nUnexpected critical/warning: %s\n", message);
      72                 :          0 :     fail ("Unexpected critical/warning: %s", message);
      73                 :            :   }
      74                 :            : 
      75         [ -  + ]:        103 :   if (_gst_check_debug) {
      76                 :          0 :     g_print ("\nExpected critical/warning: %s\n", message);
      77                 :            :   }
      78                 :            : 
      79         [ +  + ]:        103 :   if (log_level & G_LOG_LEVEL_CRITICAL)
      80                 :         86 :     _gst_check_raised_critical = TRUE;
      81         [ +  + ]:        103 :   if (log_level & G_LOG_LEVEL_WARNING)
      82                 :         17 :     _gst_check_raised_warning = TRUE;
      83                 :        103 : }
      84                 :            : 
      85                 :            : static gint
      86                 :       1154 : sort_plugins (GstPlugin * a, GstPlugin * b)
      87                 :            : {
      88                 :            :   int ret;
      89                 :            : 
      90                 :       1154 :   ret = strcmp (gst_plugin_get_source (a), gst_plugin_get_source (b));
      91         [ +  - ]:       1154 :   if (ret == 0)
      92                 :       1154 :     ret = strcmp (gst_plugin_get_name (a), gst_plugin_get_name (b));
      93                 :       1154 :   return ret;
      94                 :            : }
      95                 :            : 
      96                 :            : static void
      97                 :        542 : print_plugins (void)
      98                 :            : {
      99                 :            :   GList *plugins, *l;
     100                 :            : 
     101                 :        542 :   plugins = gst_default_registry_get_plugin_list ();
     102                 :        542 :   plugins = g_list_sort (plugins, (GCompareFunc) sort_plugins);
     103         [ +  + ]:       2198 :   for (l = plugins; l != NULL; l = l->next) {
     104                 :       1656 :     GstPlugin *plugin = GST_PLUGIN (l->data);
     105                 :            : 
     106         [ +  - ]:       1656 :     if (strcmp (gst_plugin_get_source (plugin), "BLACKLIST") != 0) {
     107 [ -  + ][ #  # ]:       1656 :       GST_LOG ("%20s@%s", gst_plugin_get_name (plugin),
     108                 :            :           GST_STR_NULL (gst_plugin_get_filename (plugin)));
     109                 :            :     }
     110                 :            :   }
     111                 :        542 :   gst_plugin_list_free (plugins);
     112                 :        542 : }
     113                 :            : 
     114                 :            : /* initialize GStreamer testing */
     115                 :            : void
     116                 :        542 : gst_check_init (int *argc, char **argv[])
     117                 :            : {
     118                 :        542 :   gst_init (argc, argv);
     119                 :            : 
     120         [ +  - ]:        542 :   GST_DEBUG_CATEGORY_INIT (check_debug, "check", 0, "check regression tests");
     121                 :            : 
     122         [ -  + ]:        542 :   if (g_getenv ("GST_TEST_DEBUG"))
     123                 :          0 :     _gst_check_debug = TRUE;
     124                 :            : 
     125                 :        542 :   g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_check_log_message_func,
     126                 :            :       NULL);
     127                 :        542 :   g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
     128                 :            :       gst_check_log_critical_func, NULL);
     129                 :        542 :   g_log_set_handler ("GStreamer", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
     130                 :            :       gst_check_log_critical_func, NULL);
     131                 :        542 :   g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
     132                 :            :       gst_check_log_critical_func, NULL);
     133                 :        542 :   g_log_set_handler ("Gst-Phonon", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
     134                 :            :       gst_check_log_critical_func, NULL);
     135                 :            : 
     136                 :        542 :   print_plugins ();
     137                 :            : 
     138                 :        542 :   check_cond = g_cond_new ();
     139                 :        542 :   check_mutex = g_mutex_new ();
     140                 :        542 : }
     141                 :            : 
     142                 :            : /* message checking */
     143                 :            : void
     144                 :          2 : gst_check_message_error (GstMessage * message, GstMessageType type,
     145                 :            :     GQuark domain, gint code)
     146                 :            : {
     147                 :            :   GError *error;
     148                 :            :   gchar *debug;
     149                 :            : 
     150                 :          2 :   fail_unless (GST_MESSAGE_TYPE (message) == type,
     151                 :            :       "message is of type %s instead of expected type %s",
     152                 :            :       gst_message_type_get_name (GST_MESSAGE_TYPE (message)),
     153                 :            :       gst_message_type_get_name (type));
     154                 :          2 :   gst_message_parse_error (message, &error, &debug);
     155                 :          2 :   fail_unless_equals_int (error->domain, domain);
     156                 :          2 :   fail_unless_equals_int (error->code, code);
     157                 :          2 :   g_error_free (error);
     158                 :          2 :   g_free (debug);
     159                 :          2 : }
     160                 :            : 
     161                 :            : /* helper functions */
     162                 :            : GstFlowReturn
     163                 :        330 : gst_check_chain_func (GstPad * pad, GstBuffer * buffer)
     164                 :            : {
     165         [ -  + ]:        330 :   GST_DEBUG ("chain_func: received buffer %p", buffer);
     166                 :        330 :   buffers = g_list_append (buffers, buffer);
     167                 :            : 
     168                 :        330 :   g_mutex_lock (check_mutex);
     169                 :        330 :   g_cond_signal (check_cond);
     170                 :        330 :   g_mutex_unlock (check_mutex);
     171                 :            : 
     172                 :        330 :   return GST_FLOW_OK;
     173                 :            : }
     174                 :            : 
     175                 :            : /* setup an element for a filter test with mysrcpad and mysinkpad */
     176                 :            : GstElement *
     177                 :         99 : gst_check_setup_element (const gchar * factory)
     178                 :            : {
     179                 :            :   GstElement *element;
     180                 :            : 
     181         [ -  + ]:         99 :   GST_DEBUG ("setup_element");
     182                 :            : 
     183                 :         99 :   element = gst_element_factory_make (factory, factory);
     184                 :         99 :   fail_if (element == NULL, "Could not create a '%s' element", factory);
     185                 :         99 :   ASSERT_OBJECT_REFCOUNT (element, factory, 1);
     186                 :         99 :   return element;
     187                 :            : }
     188                 :            : 
     189                 :            : void
     190                 :         64 : gst_check_teardown_element (GstElement * element)
     191                 :            : {
     192         [ -  + ]:         64 :   GST_DEBUG ("teardown_element");
     193                 :            : 
     194                 :         64 :   fail_unless (gst_element_set_state (element, GST_STATE_NULL) ==
     195                 :            :       GST_STATE_CHANGE_SUCCESS, "could not set to null");
     196                 :         64 :   ASSERT_OBJECT_REFCOUNT (element, "element", 1);
     197                 :         64 :   gst_object_unref (element);
     198                 :         64 : }
     199                 :            : 
     200                 :            : /* FIXME: set_caps isn't that useful
     201                 :            :  */
     202                 :            : GstPad *
     203                 :         30 : gst_check_setup_src_pad (GstElement * element,
     204                 :            :     GstStaticPadTemplate * tmpl, GstCaps * caps)
     205                 :            : {
     206                 :            :   GstPad *srcpad;
     207                 :            : 
     208                 :         30 :   srcpad = gst_check_setup_src_pad_by_name (element, tmpl, "sink");
     209         [ -  + ]:         30 :   if (caps)
     210                 :          0 :     fail_unless (gst_pad_set_caps (srcpad, caps), "could not set caps on pad");
     211                 :         30 :   return srcpad;
     212                 :            : }
     213                 :            : 
     214                 :            : GstPad *
     215                 :         31 : gst_check_setup_src_pad_by_name (GstElement * element,
     216                 :            :     GstStaticPadTemplate * tmpl, const gchar * name)
     217                 :            : {
     218                 :            :   GstPad *srcpad, *sinkpad;
     219                 :            : 
     220                 :            :   /* sending pad */
     221                 :         31 :   srcpad = gst_pad_new_from_static_template (tmpl, "src");
     222         [ -  + ]:         31 :   GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad);
     223                 :         31 :   fail_if (srcpad == NULL, "Could not create a srcpad");
     224                 :         31 :   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
     225                 :            : 
     226                 :         31 :   sinkpad = gst_element_get_static_pad (element, name);
     227         [ -  + ]:         31 :   if (sinkpad == NULL)
     228                 :          0 :     sinkpad = gst_element_get_request_pad (element, name);
     229                 :         31 :   fail_if (sinkpad == NULL, "Could not get sink pad from %s",
     230                 :            :       GST_ELEMENT_NAME (element));
     231                 :         31 :   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
     232                 :         31 :   fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
     233                 :            :       "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
     234                 :         31 :   gst_object_unref (sinkpad);   /* because we got it higher up */
     235                 :         31 :   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1);
     236                 :            : 
     237                 :         31 :   return srcpad;
     238                 :            : }
     239                 :            : 
     240                 :            : void
     241                 :         70 : gst_check_teardown_pad_by_name (GstElement * element, const gchar * name)
     242                 :            : {
     243                 :            :   GstPad *pad_peer, *pad_element;
     244                 :            : 
     245                 :            :   /* clean up floating src pad */
     246                 :         70 :   pad_element = gst_element_get_static_pad (element, name);
     247                 :            :   /* We don't check the refcount here since there *might* be
     248                 :            :    * a pad cache holding an extra reference on pad_element.
     249                 :            :    * To get to a state where no pad cache will exist,
     250                 :            :    * we first unlink that pad. */
     251                 :         70 :   pad_peer = gst_pad_get_peer (pad_element);
     252                 :            : 
     253         [ +  + ]:         70 :   if (pad_peer) {
     254         [ +  + ]:         67 :     if (gst_pad_get_direction (pad_element) == GST_PAD_SINK)
     255                 :         28 :       gst_pad_unlink (pad_peer, pad_element);
     256                 :            :     else
     257                 :         39 :       gst_pad_unlink (pad_element, pad_peer);
     258                 :            : 
     259                 :            :     /* caps could have been set, make sure they get unset */
     260                 :         67 :     gst_pad_set_caps (pad_peer, NULL);
     261                 :            :   }
     262                 :            : 
     263                 :            :   /* pad refs held by both creator and this function (through _get) */
     264                 :         70 :   ASSERT_OBJECT_REFCOUNT (pad_element, "element pad_element", 2);
     265                 :         70 :   gst_object_unref (pad_element);
     266                 :            :   /* one more ref is held by element itself */
     267                 :            : 
     268         [ +  + ]:         70 :   if (pad_peer) {
     269                 :            :     /* pad refs held by both creator and this function (through _get_peer) */
     270                 :         67 :     ASSERT_OBJECT_REFCOUNT (pad_peer, "check pad_peer", 2);
     271                 :         67 :     gst_object_unref (pad_peer);
     272                 :         67 :     gst_object_unref (pad_peer);
     273                 :            :   }
     274                 :         70 : }
     275                 :            : 
     276                 :            : void
     277                 :         31 : gst_check_teardown_src_pad (GstElement * element)
     278                 :            : {
     279                 :         31 :   gst_check_teardown_pad_by_name (element, "sink");
     280                 :         31 : }
     281                 :            : 
     282                 :            : /* FIXME: set_caps isn't that useful; might want to check if fixed,
     283                 :            :  * then use set_use_fixed or somesuch */
     284                 :            : GstPad *
     285                 :         33 : gst_check_setup_sink_pad (GstElement * element, GstStaticPadTemplate * tmpl,
     286                 :            :     GstCaps * caps)
     287                 :            : {
     288                 :            :   GstPad *sinkpad;
     289                 :            : 
     290                 :         33 :   sinkpad = gst_check_setup_sink_pad_by_name (element, tmpl, "src");
     291         [ -  + ]:         33 :   if (caps)
     292                 :          0 :     fail_unless (gst_pad_set_caps (sinkpad, caps), "Could not set pad caps");
     293                 :         33 :   return sinkpad;
     294                 :            : }
     295                 :            : 
     296                 :            : GstPad *
     297                 :         34 : gst_check_setup_sink_pad_by_name (GstElement * element,
     298                 :            :     GstStaticPadTemplate * tmpl, const gchar * name)
     299                 :            : {
     300                 :            :   GstPad *srcpad, *sinkpad;
     301                 :            : 
     302                 :            :   /* receiving pad */
     303                 :         34 :   sinkpad = gst_pad_new_from_static_template (tmpl, "sink");
     304         [ -  + ]:         34 :   GST_DEBUG_OBJECT (element, "setting up receiving pad %p", sinkpad);
     305                 :         34 :   fail_if (sinkpad == NULL, "Could not create a sinkpad");
     306                 :            : 
     307                 :         34 :   srcpad = gst_element_get_static_pad (element, name);
     308         [ -  + ]:         34 :   if (srcpad == NULL)
     309                 :          0 :     srcpad = gst_element_get_request_pad (element, name);
     310                 :         34 :   fail_if (srcpad == NULL, "Could not get source pad from %s",
     311                 :            :       GST_ELEMENT_NAME (element));
     312                 :         34 :   gst_pad_set_chain_function (sinkpad, gst_check_chain_func);
     313                 :            : 
     314         [ -  + ]:         34 :   GST_DEBUG_OBJECT (element, "Linking element src pad and receiving sink pad");
     315                 :         34 :   fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
     316                 :            :       "Could not link %s source and sink pads", GST_ELEMENT_NAME (element));
     317                 :         34 :   gst_object_unref (srcpad);    /* because we got it higher up */
     318                 :         34 :   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
     319                 :            : 
     320         [ -  + ]:         34 :   GST_DEBUG_OBJECT (element, "set up srcpad, refcount is 1");
     321                 :         34 :   return sinkpad;
     322                 :            : }
     323                 :            : 
     324                 :            : void
     325                 :         39 : gst_check_teardown_sink_pad (GstElement * element)
     326                 :            : {
     327                 :         39 :   gst_check_teardown_pad_by_name (element, "src");
     328                 :         39 : }
     329                 :            : 
     330                 :            : /**
     331                 :            :  * gst_check_drop_buffers:
     332                 :            :  *
     333                 :            :  * Unref and remove all buffers that are in the global @buffers GList,
     334                 :            :  * emptying the list.
     335                 :            :  *
     336                 :            :  * Since: 0.10.18
     337                 :            :  */
     338                 :            : void
     339                 :         12 : gst_check_drop_buffers (void)
     340                 :            : {
     341         [ +  + ]:        326 :   while (buffers != NULL) {
     342                 :        314 :     gst_buffer_unref (GST_BUFFER (buffers->data));
     343                 :        314 :     buffers = g_list_delete_link (buffers, buffers);
     344                 :            :   }
     345                 :         12 : }
     346                 :            : 
     347                 :            : /**
     348                 :            :  * gst_check_caps_equal:
     349                 :            :  * @caps1: first caps to compare
     350                 :            :  * @caps2: second caps to compare
     351                 :            :  *
     352                 :            :  * Compare two caps with gst_caps_is_equal and fail unless they are
     353                 :            :  * equal.
     354                 :            :  *
     355                 :            :  * Since: 0.10.18
     356                 :            :  */
     357                 :            : void
     358                 :          0 : gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2)
     359                 :            : {
     360                 :          0 :   gchar *name1 = gst_caps_to_string (caps1);
     361                 :          0 :   gchar *name2 = gst_caps_to_string (caps2);
     362                 :            : 
     363                 :          0 :   fail_unless (gst_caps_is_equal (caps1, caps2),
     364                 :            :       "caps ('%s') is not equal to caps ('%s')", name1, name2);
     365                 :          0 :   g_free (name1);
     366                 :          0 :   g_free (name2);
     367                 :          0 : }
     368                 :            : 
     369                 :            : /**
     370                 :            :  * gst_check_element_push_buffer_list:
     371                 :            :  * @element_name: name of the element that needs to be created
     372                 :            :  * @buffer_in: a list of buffers that needs to be puched to the element
     373                 :            :  * @buffer_out: a list of buffers that we expect from the element
     374                 :            :  * @last_flow_return: the last buffer push needs to give this GstFlowReturn
     375                 :            :  *
     376                 :            :  * Create an @element with the factory with the name and push the buffers in
     377                 :            :  * @buffer_in to this element. The element should create the buffers equal to
     378                 :            :  * the buffers in @buffer_out. We only check the caps, size and the data of the
     379                 :            :  * buffers. This function unrefs the buffers in the two lists.
     380                 :            :  * The last_flow_return parameter indicates the expected flow return value from
     381                 :            :  * pushing the final buffer in the list.
     382                 :            :  * This can be used to set up a test which pushes some buffers and then an
     383                 :            :  * invalid buffer, when the final buffer is expected to fail, for example.
     384                 :            :  * 
     385                 :            :  * Since: 0.10.18
     386                 :            :  */
     387                 :            : /* FIXME 0.11: rename this function now that there's GstBufferList? */
     388                 :            : void
     389                 :          0 : gst_check_element_push_buffer_list (const gchar * element_name,
     390                 :            :     GList * buffer_in, GList * buffer_out, GstFlowReturn last_flow_return)
     391                 :            : {
     392                 :            :   GstCaps *sink_caps;
     393                 :          0 :   GstCaps *src_caps = NULL;
     394                 :            :   GstElement *element;
     395                 :            :   GstPad *pad_peer;
     396                 :          0 :   GstPad *sink_pad = NULL;
     397                 :            :   GstPad *src_pad;
     398                 :            :   GstBuffer *buffer;
     399                 :            : 
     400                 :            :   /* check that there are no buffers waiting */
     401                 :          0 :   gst_check_drop_buffers ();
     402                 :            :   /* create the element */
     403                 :          0 :   element = gst_check_setup_element (element_name);
     404                 :          0 :   fail_if (element == NULL, "failed to create the element '%s'", element_name);
     405 [ #  # ][ #  # ]:          0 :   fail_unless (GST_IS_ELEMENT (element), "the element is no element");
                 [ #  # ]
     406                 :            :   /* create the src pad */
     407                 :          0 :   buffer = GST_BUFFER (buffer_in->data);
     408                 :            : 
     409 [ #  # ][ #  # ]:          0 :   fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in");
                 [ #  # ]
     410                 :          0 :   src_caps = GST_BUFFER_CAPS (buffer);
     411                 :          0 :   src_pad = gst_pad_new (NULL, GST_PAD_SRC);
     412                 :          0 :   gst_pad_set_caps (src_pad, src_caps);
     413                 :          0 :   pad_peer = gst_element_get_static_pad (element, "sink");
     414                 :          0 :   fail_if (pad_peer == NULL);
     415                 :          0 :   fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK,
     416                 :            :       "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
     417                 :          0 :   gst_object_unref (pad_peer);
     418                 :            :   /* activate the pad */
     419                 :          0 :   gst_pad_set_active (src_pad, TRUE);
     420         [ #  # ]:          0 :   GST_DEBUG ("src pad activated");
     421                 :            :   /* don't create the sink_pad if there is no buffer_out list */
     422         [ #  # ]:          0 :   if (buffer_out != NULL) {
     423                 :            :     gchar *temp;
     424                 :            : 
     425         [ #  # ]:          0 :     GST_DEBUG ("buffer out detected, creating the sink pad");
     426                 :            :     /* get the sink caps */
     427                 :          0 :     sink_caps = GST_BUFFER_CAPS (GST_BUFFER (buffer_out->data));
     428 [ #  # ][ #  # ]:          0 :     fail_unless (GST_IS_CAPS (sink_caps), "buffer out don't have caps");
     429                 :          0 :     temp = gst_caps_to_string (sink_caps);
     430                 :            : 
     431         [ #  # ]:          0 :     GST_DEBUG ("sink caps requested by buffer out: '%s'", temp);
     432                 :          0 :     g_free (temp);
     433                 :          0 :     fail_unless (gst_caps_is_fixed (sink_caps), "we need fixed caps");
     434                 :            :     /* get the sink pad */
     435                 :          0 :     sink_pad = gst_pad_new (NULL, GST_PAD_SINK);
     436 [ #  # ][ #  # ]:          0 :     fail_unless (GST_IS_PAD (sink_pad));
                 [ #  # ]
     437                 :          0 :     gst_pad_set_caps (sink_pad, sink_caps);
     438                 :            :     /* get the peer pad */
     439                 :          0 :     pad_peer = gst_element_get_static_pad (element, "src");
     440                 :          0 :     fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK,
     441                 :            :         "Could not link sink and %s source pads", GST_ELEMENT_NAME (element));
     442                 :          0 :     gst_object_unref (pad_peer);
     443                 :            :     /* configure the sink pad */
     444                 :          0 :     gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
     445                 :          0 :     gst_pad_set_active (sink_pad, TRUE);
     446                 :            :   }
     447                 :          0 :   fail_unless (gst_element_set_state (element,
     448                 :            :           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
     449                 :            :       "could not set to playing");
     450                 :            :   /* push all the buffers in the buffer_in list */
     451                 :          0 :   fail_unless (g_list_length (buffer_in) > 0, "the buffer_in list is empty");
     452         [ #  # ]:          0 :   while (buffer_in != NULL) {
     453                 :          0 :     GstBuffer *next_buffer = GST_BUFFER (buffer_in->data);
     454                 :            : 
     455 [ #  # ][ #  # ]:          0 :     fail_unless (GST_IS_BUFFER (next_buffer),
                 [ #  # ]
     456                 :            :         "data in buffer_in should be a buffer");
     457                 :            :     /* remove the buffer from the list */
     458                 :          0 :     buffer_in = g_list_remove (buffer_in, next_buffer);
     459         [ #  # ]:          0 :     if (buffer_in == NULL) {
     460                 :          0 :       fail_unless (gst_pad_push (src_pad, next_buffer) == last_flow_return,
     461                 :            :           "we expect something else from the last buffer");
     462                 :            :     } else {
     463                 :          0 :       fail_unless (gst_pad_push (src_pad, next_buffer) == GST_FLOW_OK,
     464                 :            :           "Failed to push buffer in");
     465                 :            :     }
     466                 :            :   }
     467                 :          0 :   fail_unless (gst_element_set_state (element,
     468                 :            :           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
     469                 :            :   /* check that there is a buffer out */
     470                 :          0 :   fail_unless_equals_int (g_list_length (buffers), g_list_length (buffer_out));
     471         [ #  # ]:          0 :   while (buffers != NULL) {
     472                 :          0 :     GstBuffer *new = GST_BUFFER (buffers->data);
     473                 :          0 :     GstBuffer *orig = GST_BUFFER (buffer_out->data);
     474                 :            : 
     475         [ #  # ]:          0 :     GST_LOG ("orig buffer: size %u, caps %" GST_PTR_FORMAT,
     476                 :            :         GST_BUFFER_SIZE (orig), GST_BUFFER_CAPS (orig));
     477         [ #  # ]:          0 :     GST_LOG ("new  buffer: size %u, caps %" GST_PTR_FORMAT,
     478                 :            :         GST_BUFFER_SIZE (new), GST_BUFFER_CAPS (new));
     479         [ #  # ]:          0 :     GST_MEMDUMP ("orig buffer", GST_BUFFER_DATA (orig), GST_BUFFER_SIZE (orig));
     480         [ #  # ]:          0 :     GST_MEMDUMP ("new  buffer", GST_BUFFER_DATA (new), GST_BUFFER_SIZE (new));
     481                 :            : 
     482                 :            :     /* remove the buffers */
     483                 :          0 :     buffers = g_list_remove (buffers, new);
     484                 :          0 :     buffer_out = g_list_remove (buffer_out, orig);
     485                 :          0 :     fail_unless (GST_BUFFER_SIZE (orig) == GST_BUFFER_SIZE (new),
     486                 :            :         "size of the buffers are not the same");
     487                 :          0 :     fail_unless (memcmp (GST_BUFFER_DATA (orig), GST_BUFFER_DATA (new),
     488                 :            :             GST_BUFFER_SIZE (new)) == 0, "data is not the same");
     489                 :          0 :     gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new));
     490                 :          0 :     gst_buffer_unref (new);
     491                 :          0 :     gst_buffer_unref (orig);
     492                 :            :   }
     493                 :            :   /* teardown the element and pads */
     494                 :          0 :   gst_pad_set_active (src_pad, FALSE);
     495                 :          0 :   gst_check_teardown_src_pad (element);
     496                 :          0 :   gst_pad_set_active (sink_pad, FALSE);
     497                 :          0 :   gst_check_teardown_sink_pad (element);
     498                 :          0 :   gst_check_teardown_element (element);
     499                 :          0 : }
     500                 :            : 
     501                 :            : /**
     502                 :            :  * gst_check_element_push_buffer:
     503                 :            :  * @element_name: name of the element that needs to be created
     504                 :            :  * @buffer_in: push this buffer to the element
     505                 :            :  * @buffer_out: compare the result with this buffer
     506                 :            :  *
     507                 :            :  * Create an @element with the factory with the name and push the
     508                 :            :  * @buffer_in to this element. The element should create one buffer
     509                 :            :  * and this will be compared with @buffer_out. We only check the caps
     510                 :            :  * and the data of the buffers. This function unrefs the buffers.
     511                 :            :  * 
     512                 :            :  * Since: 0.10.18
     513                 :            :  */
     514                 :            : void
     515                 :          0 : gst_check_element_push_buffer (const gchar * element_name,
     516                 :            :     GstBuffer * buffer_in, GstBuffer * buffer_out)
     517                 :            : {
     518                 :          0 :   GList *in = NULL;
     519                 :          0 :   GList *out = NULL;
     520                 :            : 
     521                 :          0 :   in = g_list_append (in, buffer_in);
     522                 :          0 :   out = g_list_append (out, buffer_out);
     523                 :            : 
     524                 :          0 :   gst_check_element_push_buffer_list (element_name, in, out, GST_FLOW_OK);
     525                 :          0 : }
     526                 :            : 
     527                 :            : void
     528                 :          2 : gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes)
     529                 :            : {
     530         [ +  - ]:          2 :   if (have_abi_sizes) {
     531                 :          2 :     gboolean ok = TRUE;
     532                 :            :     gint i;
     533                 :            : 
     534         [ +  + ]:         91 :     for (i = 0; list[i].name; i++) {
     535         [ -  + ]:         89 :       if (list[i].size != list[i].abi_size) {
     536                 :          0 :         ok = FALSE;
     537                 :          0 :         g_print ("sizeof(%s) is %d, expected %d\n",
     538                 :          0 :             list[i].name, list[i].size, list[i].abi_size);
     539                 :            :       }
     540                 :            :     }
     541                 :          2 :     fail_unless (ok, "failed ABI check");
     542                 :            :   } else {
     543                 :            :     const gchar *fn;
     544                 :            : 
     545         [ #  # ]:          0 :     if ((fn = g_getenv ("GST_ABI"))) {
     546                 :          0 :       GError *err = NULL;
     547                 :            :       GString *s;
     548                 :            :       gint i;
     549                 :            : 
     550                 :          0 :       s = g_string_new ("\nGstCheckABIStruct list[] = {\n");
     551         [ #  # ]:          0 :       for (i = 0; list[i].name; i++) {
     552                 :          0 :         g_string_append_printf (s, "  {\"%s\", sizeof (%s), %d},\n",
     553                 :          0 :             list[i].name, list[i].name, list[i].size);
     554                 :            :       }
     555                 :          0 :       g_string_append (s, "  {NULL, 0, 0}\n");
     556                 :          0 :       g_string_append (s, "};\n");
     557         [ #  # ]:          0 :       if (!g_file_set_contents (fn, s->str, s->len, &err)) {
     558                 :          0 :         g_print ("%s", s->str);
     559                 :          0 :         g_printerr ("\nFailed to write ABI information: %s\n", err->message);
     560                 :            :       } else {
     561                 :          0 :         g_print ("\nWrote ABI information to '%s'.\n", fn);
     562                 :            :       }
     563                 :          0 :       g_string_free (s, TRUE);
     564                 :            :     } else {
     565                 :          0 :       g_print ("No structure size list was generated for this architecture.\n");
     566                 :          0 :       g_print ("Run with GST_ABI environment variable set to output header.\n");
     567                 :            :     }
     568                 :            :   }
     569                 :          2 : }
     570                 :            : 
     571                 :            : gint
     572                 :        542 : gst_check_run_suite (Suite * suite, const gchar * name, const gchar * fname)
     573                 :            : {
     574                 :            :   SRunner *sr;
     575                 :        542 :   gchar *xmlfilename = NULL;
     576                 :            :   gint nf;
     577                 :            : 
     578                 :        542 :   sr = srunner_create (suite);
     579                 :            : 
     580         [ -  + ]:        542 :   if (g_getenv ("GST_CHECK_XML")) {
     581                 :            :     /* how lucky we are to have __FILE__ end in .c */
     582                 :          0 :     xmlfilename = g_strdup_printf ("%sheck.xml", fname);
     583                 :            : 
     584                 :          0 :     srunner_set_xml (sr, xmlfilename);
     585                 :            :   }
     586                 :            : 
     587                 :        542 :   srunner_run_all (sr, CK_NORMAL);
     588                 :         71 :   nf = srunner_ntests_failed (sr);
     589                 :         71 :   g_free (xmlfilename);
     590                 :         71 :   srunner_free (sr);
     591                 :         71 :   return nf;
     592                 :            : }
     593                 :            : 
     594                 :            : gboolean
     595                 :       6830 : _gst_check_run_test_func (const gchar * func_name)
     596                 :            : {
     597                 :            :   const gchar *gst_checks;
     598                 :       6830 :   gboolean res = FALSE;
     599                 :            :   gchar **funcs, **f;
     600                 :            : 
     601                 :       6830 :   gst_checks = g_getenv ("GST_CHECKS");
     602                 :            : 
     603                 :            :   /* no filter specified => run all checks */
     604 [ -  + ][ #  # ]:       6830 :   if (gst_checks == NULL || *gst_checks == '\0')
     605                 :       6830 :     return TRUE;
     606                 :            : 
     607                 :            :   /* only run specified functions */
     608                 :          0 :   funcs = g_strsplit (gst_checks, ",", -1);
     609 [ #  # ][ #  # ]:          0 :   for (f = funcs; f != NULL && *f != NULL; ++f) {
     610         [ #  # ]:          0 :     if (g_pattern_match_simple (*f, func_name)) {
     611                 :          0 :       res = TRUE;
     612                 :          0 :       break;
     613                 :            :     }
     614                 :            :   }
     615                 :          0 :   g_strfreev (funcs);
     616                 :       6830 :   return res;
     617                 :            : }

Generated by: LCOV version 1.9