"Fossies" - the Fresh Open Source Software Archive

Member "gstreamer-1.16.1/tests/check/gst/gstclock.c" (19 Apr 2019, 3797 Bytes) of package /linux/misc/gstreamer-1.16.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gstclock.c" see the Fossies "Dox" file reference documentation.

    1 /* GStreamer
    2  * Copyright (C) 2010 Alessandro Decina <alessandro.decina@collabora.co.uk>
    3  *
    4  * This library is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU Library General Public
    6  * License as published by the Free Software Foundation; either
    7  * version 2 of the License, or (at your option) any later version.
    8  *
    9  * This library is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12  * Library General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU Library General Public
   15  * License along with this library; if not, write to the
   16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   17  * Boston, MA 02110-1301, USA.
   18  */
   19 #ifdef HAVE_CONFIG_H
   20 #include "config.h"
   21 #endif
   22 
   23 #include <gst/check/gstcheck.h>
   24 
   25 typedef struct
   26 {
   27   GstClock parent;
   28 } TestClock;
   29 
   30 typedef struct
   31 {
   32   GstClockClass parent_class;
   33 } TestClockClass;
   34 
   35 #define TYPE_TEST_CLOCK                   (test_clock_get_type ())
   36 #define TEST_CLOCK(obj)                   (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST_CLOCK, TestClock))
   37 #define TEST_CLOCK_CAST(obj)              ((TestClock *)(obj))
   38 #define IS_TEST_CLOCK(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST_CLOCK))
   39 #define TEST_CLOCK_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST_CLOCK, TestClockClass))
   40 #define IS_TEST_CLOCK_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST_CLOCK))
   41 #define TEST_CLOCK_GET_CLASS(obj)         (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST_CLOCK, TestClockClass))
   42 
   43 
   44 GType test_clock_get_type (void);
   45 G_DEFINE_TYPE (TestClock, test_clock, GST_TYPE_CLOCK);
   46 
   47 static GstClockReturn
   48 fake_wait_async (GstClock * clock, GstClockEntry * entry)
   49 {
   50   return GST_CLOCK_OK;
   51 }
   52 
   53 static void
   54 test_clock_class_init (TestClockClass * klass)
   55 {
   56   GstClockClass *clock_class;
   57 
   58   clock_class = GST_CLOCK_CLASS (klass);
   59 
   60   clock_class->wait_async = fake_wait_async;
   61 }
   62 
   63 static void
   64 test_clock_init (TestClock * clock)
   65 {
   66 }
   67 
   68 
   69 static void
   70 weak_notify (gpointer data, GObject * object)
   71 {
   72   *(gboolean *) data = FALSE;
   73 }
   74 
   75 GST_START_TEST (test_set_master_refcount)
   76 {
   77   GstClock *master, *slave;
   78   gboolean master_alive = TRUE;
   79 
   80   /* create master and slave */
   81   master = g_object_new (TYPE_TEST_CLOCK, "name", "TestClockMaster", NULL);
   82   gst_object_ref_sink (master);
   83   slave = g_object_new (TYPE_TEST_CLOCK, "name", "TestClockSlave", NULL);
   84   gst_object_ref_sink (slave);
   85   GST_OBJECT_FLAG_SET (slave, GST_CLOCK_FLAG_CAN_SET_MASTER);
   86 
   87   fail_unless_equals_int (GST_OBJECT_REFCOUNT (master), 1);
   88   fail_unless_equals_int (GST_OBJECT_REFCOUNT (slave), 1);
   89 
   90   g_object_weak_ref (G_OBJECT (master), weak_notify, &master_alive);
   91   fail_unless_equals_int (GST_OBJECT_REFCOUNT (master), 1);
   92 
   93   gst_clock_set_master (slave, master);
   94   /* slave stores master in slave->master */
   95   fail_unless_equals_int (GST_OBJECT_REFCOUNT (master), 2);
   96   /* master stores a ref to slave in master->clockid */
   97   fail_unless_equals_int (GST_OBJECT_REFCOUNT (slave), 2);
   98 
   99   /* discard our ref */
  100   gst_object_unref (master);
  101 
  102   /* master should still be reffed inside slave */
  103   fail_unless_equals_int (GST_OBJECT_REFCOUNT (master), 1);
  104   fail_unless (master_alive);
  105 
  106   /* drop the last ref to mater */
  107   gst_clock_set_master (slave, NULL);
  108 
  109   fail_if (master_alive);
  110   fail_unless_equals_int (GST_OBJECT_REFCOUNT (slave), 1);
  111 
  112   gst_object_unref (slave);
  113 }
  114 
  115 GST_END_TEST;
  116 
  117 static Suite *
  118 gst_clock_suite (void)
  119 {
  120   Suite *s = suite_create ("GstClock");
  121   TCase *tc_chain = tcase_create ("clock");
  122 
  123   suite_add_tcase (s, tc_chain);
  124   tcase_add_test (tc_chain, test_set_master_refcount);
  125 
  126   return s;
  127 }
  128 
  129 GST_CHECK_MAIN (gst_clock);