From e58da2a22d5d01cf080466a474aac2ac89198838 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 29 Aug 2012 16:11:10 +0200 Subject: [PATCH] check: add GstTestClock as a deterministic clock for testing API: GstTestClock API: gst_test_clock_new() API: gst_test_clock_new_with_start_time() API: gst_test_clock_set_time() API: gst_test_clock_advance_time() https://bugzilla.gnome.org/show_bug.cgi?id=683012 --- docs/libs/Makefile.am | 1 + docs/libs/gstreamer-libs-docs.sgml | 1 + docs/libs/gstreamer-libs-sections.txt | 22 ++ docs/libs/gstreamer-libs.types | 6 + libs/gst/check/Makefile.am | 15 +- libs/gst/check/gsttestclock.c | 339 ++++++++++++++++++++++++++ libs/gst/check/gsttestclock.h | 84 +++++++ tests/check/Makefile.am | 1 + tests/check/libs/gsttestclock.c | 111 +++++++++ 9 files changed, 576 insertions(+), 4 deletions(-) create mode 100644 libs/gst/check/gsttestclock.c create mode 100644 libs/gst/check/gsttestclock.h create mode 100644 tests/check/libs/gsttestclock.c diff --git a/docs/libs/Makefile.am b/docs/libs/Makefile.am index 4c621b531d..ba15ca7e07 100644 --- a/docs/libs/Makefile.am +++ b/docs/libs/Makefile.am @@ -62,6 +62,7 @@ GTKDOC_LIBS = \ $(top_builddir)/libs/gst/controller/libgstcontroller-@GST_API_VERSION@.la \ $(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la \ $(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \ + $(top_builddir)/libs/gst/check/libgstcheck-@GST_API_VERSION@.la \ $(GST_OBJ_LIBS) GTKDOC_CC=$(LIBTOOL) --tag=CC --mode=compile $(CC) diff --git a/docs/libs/gstreamer-libs-docs.sgml b/docs/libs/gstreamer-libs-docs.sgml index 0a1b3f89e8..f8dfc6b952 100644 --- a/docs/libs/gstreamer-libs-docs.sgml +++ b/docs/libs/gstreamer-libs-docs.sgml @@ -83,6 +83,7 @@ + diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 03400edc85..3ed14c4d05 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -999,3 +999,25 @@ gst_consistency_checker_reset gst_consistency_checker_free +
+gsttestclock +GstTestClock +libs/gst/check/gsttestclock.h +GstTestClock +GstTestClockClass +gst_test_clock_new +gst_test_clock_new_with_start_time +gst_test_clock_set_time +gst_test_clock_advance_time + +GST_TEST_CLOCK +GST_IS_TEST_CLOCK +GST_TYPE_TEST_CLOCK +GST_TEST_CLOCK_CLASS +GST_IS_TEST_CLOCK_CLASS +GST_TEST_CLOCK_GET_CLASS +GST_TEST_CLOCK_CAST + +GstTestClockPrivate +gst_test_clock_get_type +
diff --git a/docs/libs/gstreamer-libs.types b/docs/libs/gstreamer-libs.types index a75d55b4fc..4980191109 100644 --- a/docs/libs/gstreamer-libs.types +++ b/docs/libs/gstreamer-libs.types @@ -34,3 +34,9 @@ gst_trigger_control_source_get_type gst_net_client_clock_get_type gst_net_time_provider_get_type + +% check + +#include + +gst_test_clock_get_type diff --git a/libs/gst/check/Makefile.am b/libs/gst/check/Makefile.am index c41ca911fc..d4a1c2b38f 100644 --- a/libs/gst/check/Makefile.am +++ b/libs/gst/check/Makefile.am @@ -11,7 +11,8 @@ libgstcheck_@GST_API_VERSION@_la_DEPENDENCIES = \ libgstcheck_@GST_API_VERSION@_la_SOURCES = \ gstbufferstraw.c \ gstcheck.c \ - gstconsistencychecker.c + gstconsistencychecker.c \ + gsttestclock.c libgstcheck_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) \ -I$(top_builddir)/libs \ @@ -26,10 +27,11 @@ libgstcheck_@GST_API_VERSION@_la_LDFLAGS = \ libgstcheck_@GST_API_VERSION@includedir = \ $(includedir)/gstreamer-@GST_API_VERSION@/gst/check -libgstcheck_@GST_API_VERSION@include_HEADERS = \ +libgstcheck_@GST_API_VERSION@include_HEADERS = \ gstbufferstraw.h \ gstcheck.h \ - gstconsistencychecker.h + gstconsistencychecker.h \ + gsttestclock.h nodist_libgstcheck_@GST_API_VERSION@include_HEADERS = \ internal-check.h @@ -87,7 +89,12 @@ LIBGSTCHECK_EXPORTED_FUNCS = \ gst_consistency_checker_add_pad \ gst_consistency_checker_new \ gst_consistency_checker_reset \ - gst_consistency_checker_free + gst_consistency_checker_free \ + gst_test_clock_get_type \ + gst_test_clock_new \ + gst_test_clock_new_with_start_time \ + gst_test_clock_set_time \ + gst_test_clock_advance_time LIBGSTCHECK_EXPORTED_SYMBOLS = \ $(LIBGSTCHECK_EXPORTED_VARS) \ diff --git a/libs/gst/check/gsttestclock.c b/libs/gst/check/gsttestclock.c new file mode 100644 index 0000000000..01d60032bb --- /dev/null +++ b/libs/gst/check/gsttestclock.c @@ -0,0 +1,339 @@ +/* + * A deterministic clock for GStreamer unit tests + * + * Copyright (C) 2008 Ole André Vadla Ravnås + * Copyright (C) 2012 Sebastian Rasmussen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:gsttestclock + * @short_description: Controllable, deterministic clock for GStreamer unit tests + * @see_also: #GstSystemClock, #GstClock + * + * GstTestClock is an implementation of #GstClock which has different + * behaviour compared to #GstSystemClock. Time for #GstSystemClock advances + * according to the system time, while time for #GstTestClock changes only + * when gst_test_clock_set_time() or gst_test_clock_advance_time() are + * called. #GstTestClock provides unit tests with the possibility to + * precisely advance the time in a deterministic manner, independent of the + * system time or any other external factors. + * + * + * Advancing the time of a #GstTestClock + * + * #include <gst/gst.h> + * #include <gst/check/gsttestclock.h> + * + * GstClock *clock; + * GstTestClock *test_clock; + * + * clock = gst_test_clock_new (); + * test_clock = GST_TEST_CLOCK (clock); + * GST_INFO ("Time: %" GST_TIME_FORMAT, GST_TIME_ARGS (gst_clock_get_time (clock))); + * gst_test_clock_advance_time ( test_clock, 1 * GST_SECOND); + * GST_INFO ("Time: %" GST_TIME_FORMAT, GST_TIME_ARGS (gst_clock_get_time (clock))); + * g_usleep (10 * G_USEC_PER_SEC); + * GST_INFO ("Time: %" GST_TIME_FORMAT, GST_TIME_ARGS (gst_clock_get_time (clock))); + * gst_test_clock_set_time (test_clock, 42 * GST_SECOND); + * GST_INFO ("Time: %" GST_TIME_FORMAT, GST_TIME_ARGS (gst_clock_get_time (clock))); + * ... + * + * + * + * Since #GstTestClock is only supposed to be used in unit tests it calls + * g_assert(), g_assert_cmpint() or g_assert_cmpuint() to validate all function + * arguments. This will highlight any issues with the unit test code itself. + */ + +#include "gsttestclock.h" + +enum +{ + PROP_0, + PROP_START_TIME, +}; + +typedef struct _GstClockEntryContext GstClockEntryContext; + +struct _GstClockEntryContext +{ + GstClockEntry *clock_entry; + GstClockTimeDiff time_diff; +}; + +struct _GstTestClockPrivate +{ + GstClockTime start_time; + GstClockTime internal_time; +}; + +#define GST_TEST_CLOCK_GET_PRIVATE(obj) ((GST_TEST_CLOCK_CAST (obj))->priv) + +GST_DEBUG_CATEGORY_STATIC (test_clock_debug); +#define GST_CAT_TEST_CLOCK test_clock_debug + +#define _do_init \ +G_STMT_START { \ + GST_DEBUG_CATEGORY_INIT (test_clock_debug, "GST_TEST_CLOCK", \ + GST_DEBUG_BOLD, "Test clocks for unit tests"); \ +} G_STMT_END + +G_DEFINE_TYPE_WITH_CODE (GstTestClock, gst_test_clock, + GST_TYPE_CLOCK, _do_init); + +static GstObjectClass *parent_class = NULL; + +static void gst_test_clock_constructed (GObject * object); +static void gst_test_clock_dispose (GObject * object); +static void gst_test_clock_finalize (GObject * object); +static void gst_test_clock_get_property (GObject * object, guint property_id, + GValue * value, GParamSpec * pspec); +static void gst_test_clock_set_property (GObject * object, guint property_id, + const GValue * value, GParamSpec * pspec); + +static GstClockTime gst_test_clock_get_resolution (GstClock * clock); +static GstClockTime gst_test_clock_get_internal_time (GstClock * clock); + +static void +gst_test_clock_class_init (GstTestClockClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstClockClass *gstclock_class = GST_CLOCK_CLASS (klass); + GParamSpec *pspec; + + parent_class = g_type_class_peek_parent (klass); + + g_type_class_add_private (klass, sizeof (GstTestClockPrivate)); + + gobject_class->constructed = GST_DEBUG_FUNCPTR (gst_test_clock_constructed); + gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_test_clock_dispose); + gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_test_clock_finalize); + gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_test_clock_get_property); + gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_test_clock_set_property); + + gstclock_class->get_resolution = GST_DEBUG_FUNCPTR ( + gst_test_clock_get_resolution); + gstclock_class->get_internal_time = GST_DEBUG_FUNCPTR ( + gst_test_clock_get_internal_time); + + /** + * GstTestClock:start-time + * + * When a #GstTestClock is constructed it will have a certain start time set. + * If the clock was created using gst_test_clock_new_with_start_time() then + * this property contains the value of the @start_time argument. If + * gst_test_clock_new() was called the clock started at time zero, and thus + * this property contains the value 0. + */ + pspec = g_param_spec_uint64 ("start-time", "Start Time", + "Start Time of the Clock", 0, G_MAXUINT64, 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (gobject_class, PROP_START_TIME, pspec); +} + +static void +gst_test_clock_init (GstTestClock * test_clock) +{ + test_clock->priv = G_TYPE_INSTANCE_GET_PRIVATE (test_clock, + GST_TYPE_TEST_CLOCK, GstTestClockPrivate); + + GST_OBJECT_FLAG_SET (test_clock, + GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC | + GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC | + GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC | + GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC); +} + +static void +gst_test_clock_constructed (GObject * object) +{ + GstTestClock *test_clock = GST_TEST_CLOCK (object); + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + + priv->internal_time = priv->start_time; +} + +static void +gst_test_clock_dispose (GObject * object) +{ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +gst_test_clock_finalize (GObject * object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gst_test_clock_get_property (GObject * object, guint property_id, + GValue * value, GParamSpec * pspec) +{ + GstTestClock *test_clock = GST_TEST_CLOCK (object); + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + + switch (property_id) { + case PROP_START_TIME: + g_value_set_uint64 (value, priv->start_time); + break; + default: + G_OBJECT_CLASS (parent_class)->set_property (object, property_id, value, + pspec); + break; + } +} + +static void +gst_test_clock_set_property (GObject * object, guint property_id, + const GValue * value, GParamSpec * pspec) +{ + GstTestClock *test_clock = GST_TEST_CLOCK (object); + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + + switch (property_id) { + case PROP_START_TIME: + priv->start_time = g_value_get_uint64 (value); + GST_CAT_TRACE_OBJECT (GST_CAT_TEST_CLOCK, test_clock, + "test clock start time initialized at %" GST_TIME_FORMAT, + GST_TIME_ARGS (priv->start_time)); + break; + default: + G_OBJECT_CLASS (parent_class)->set_property (object, property_id, value, + pspec); + break; + } +} + +static GstClockTime +gst_test_clock_get_resolution (GstClock * clock) +{ + return 1; +} + +static GstClockTime +gst_test_clock_get_internal_time (GstClock * clock) +{ + GstTestClock *test_clock = GST_TEST_CLOCK (clock); + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + GstClockTime result; + + GST_OBJECT_LOCK (test_clock); + + GST_CAT_TRACE_OBJECT (GST_CAT_TEST_CLOCK, test_clock, + "retrieving test clock time %" GST_TIME_FORMAT, + GST_TIME_ARGS (priv->internal_time)); + result = priv->internal_time; + + GST_OBJECT_UNLOCK (test_clock); + + return result; +} + +/** + * gst_test_clock_new: + * + * Creates a new test clock with its time set to zero. + * + * MT safe. + * + * Returns: (transfer full): a #GstTestClock cast to #GstClock. + */ +GstClock * +gst_test_clock_new (void) +{ + return gst_test_clock_new_with_start_time (0); +} + +/** + * gst_test_clock_new_with_start_time: + * @start_time: a #GstClockTime set to the desired start time of the clock. + * + * Creates a new test clock with its time set to the specified time. + * + * MT safe. + * + * Returns: (transfer full): a #GstTestClock cast to #GstClock. + */ +GstClock * +gst_test_clock_new_with_start_time (GstClockTime start_time) +{ + g_assert_cmpuint (start_time, !=, GST_CLOCK_TIME_NONE); + return g_object_new (GST_TYPE_TEST_CLOCK, "start-time", start_time, NULL); +} + +/** + * gst_test_clock_set_time: + * @test_clock: a #GstTestClock of which to set the time + * @new_time: a #GstClockTime later than that returned by gst_clock_get_time() + * + * Sets the time of @test_clock to the time given by @new_time. The time of + * @test_clock is monotonically increasing, therefore providing a @new_time + * which is earlier or equal to the time of the clock as given by + * gst_clock_get_time() is a programming error. + * + * MT safe. + */ +void +gst_test_clock_set_time (GstTestClock * test_clock, GstClockTime new_time) +{ + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + + g_assert (GST_IS_TEST_CLOCK (test_clock)); + g_assert_cmpuint (new_time, !=, GST_CLOCK_TIME_NONE); + + GST_OBJECT_LOCK (test_clock); + + g_assert_cmpuint (new_time, >=, priv->internal_time); + + priv->internal_time = new_time; + GST_CAT_DEBUG_OBJECT (GST_CAT_TEST_CLOCK, test_clock, + "clock set to %" GST_TIME_FORMAT, GST_TIME_ARGS (new_time)); + + GST_OBJECT_UNLOCK (test_clock); +} + +/** + * gst_test_clock_advance_time: + * @test_clock: a #GstTestClock for which to increase the time + * @delta: a positive #GstClockTimeDiff to be added to the time of the clock + * + * Advances the time of the @test_clock by the amount given by @delta. The + * time of @test_clock is monotonically increasing, therefore providing a + * @delta which is negative or zero is a programming error. + * + * MT safe. + */ +void +gst_test_clock_advance_time (GstTestClock * test_clock, + GstClockTimeDiff delta) +{ + GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); + + g_assert (GST_IS_TEST_CLOCK (test_clock)); + g_assert_cmpint (delta, >=, 0); + g_assert_cmpuint (delta, <, G_MAXUINT64 - delta); + + GST_OBJECT_LOCK (test_clock); + + GST_CAT_DEBUG_OBJECT (GST_CAT_TEST_CLOCK, test_clock, + "advancing clock by %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT, + GST_TIME_ARGS (delta), GST_TIME_ARGS (priv->internal_time + delta)); + priv->internal_time += delta; + + GST_OBJECT_UNLOCK (test_clock); +} diff --git a/libs/gst/check/gsttestclock.h b/libs/gst/check/gsttestclock.h new file mode 100644 index 0000000000..6d47e63aae --- /dev/null +++ b/libs/gst/check/gsttestclock.h @@ -0,0 +1,84 @@ +/* + * A deterministic clock for GStreamer unit tests + * + * Copyright (C) 2008 Ole André Vadla Ravnås + * Copyright (C) 2012 Sebastian Rasmussen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_TEST_CLOCK_H__ +#define __GST_TEST_CLOCK_H__ + +#include + +G_BEGIN_DECLS + +/* --- standard type macros --- */ +#define GST_TYPE_TEST_CLOCK (gst_test_clock_get_type ()) +#define GST_TEST_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ + GST_TYPE_TEST_CLOCK, GstTestClock)) +#define GST_IS_TEST_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ + GST_TYPE_TEST_CLOCK)) +#define GST_TEST_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ + GST_TYPE_TEST_CLOCK, GstTestClockClass)) +#define GST_IS_TEST_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (\ + (klass), GST_TYPE_TEST_CLOCK)) +#define GST_TEST_CLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (\ + (obj), GST_TYPE_TEST_CLOCK, GstTestClockClass)) +#define GST_TEST_CLOCK_CAST(obj) ((GstTestClock*)(obj)) + +typedef struct _GstTestClock GstTestClock; +typedef struct _GstTestClockClass GstTestClockClass; +typedef struct _GstTestClockPrivate GstTestClockPrivate; + +/** + * GstTestClock: + * + * A #GstTestClock structure which is based on a #GstClock along with some + * private data. + */ +struct _GstTestClock +{ + GstClock parent; + + /*< private >*/ + GstTestClockPrivate *priv; +}; + +/** + * GstTestClockClass: + * @parent_class: the parent class structure + * + * The class of a #GstTestClock, which has no virtual methods to override. + */ +struct _GstTestClockClass +{ + GstClockClass parent_class; +}; + +GType gst_test_clock_get_type (void); + +GstClock *gst_test_clock_new (void); +GstClock *gst_test_clock_new_with_start_time (GstClockTime start_time); + +void gst_test_clock_set_time (GstTestClock * test_clock, GstClockTime new_time); +void gst_test_clock_advance_time (GstTestClock * test_clock, + GstClockTimeDiff delta); + +G_END_DECLS + +#endif /* __GST_TEST_CLOCK_H__ */ diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index b4880fb71f..9c0cc01003 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -138,6 +138,7 @@ check_PROGRAMS = \ libs/collectpads \ libs/gstnetclientclock \ libs/gstnettimeprovider \ + libs/gsttestclock \ libs/transform1 \ tools/gstinspect diff --git a/tests/check/libs/gsttestclock.c b/tests/check/libs/gsttestclock.c new file mode 100644 index 0000000000..0c8678f1f8 --- /dev/null +++ b/tests/check/libs/gsttestclock.c @@ -0,0 +1,111 @@ +/* + * Unit test for a deterministic clock for Gstreamer unit tests + * + * Copyright (C) 2008 Ole André Vadla Ravnås + * Copyright (C) 2012 Sebastian Rasmussen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +GST_START_TEST (test_object_flags) +{ + GstClock *clock = gst_test_clock_new (); + g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC)); + g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC)); + g_assert (GST_OBJECT_FLAG_IS_SET (clock, + GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC)); + g_assert (GST_OBJECT_FLAG_IS_SET (clock, + GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC)); + gst_object_unref (clock); +} + +GST_END_TEST; + +GST_START_TEST (test_resolution_query) +{ + GstClock *clock = gst_test_clock_new (); + g_assert_cmpuint (gst_clock_get_resolution (clock), ==, 1); + gst_object_unref (clock); +} + +GST_END_TEST; + +GST_START_TEST (test_start_time) +{ + GstClock *clock; + guint64 start_time; + + clock = gst_test_clock_new (); + g_assert_cmpuint (gst_clock_get_time (clock), ==, 0); + g_object_get (clock, "start-time", &start_time, NULL); + g_assert_cmpuint (start_time, ==, 0); + gst_object_unref (clock); + + clock = gst_test_clock_new_with_start_time (GST_SECOND); + g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND); + g_object_get (clock, "start-time", &start_time, NULL); + g_assert_cmpuint (start_time, ==, GST_SECOND); + gst_object_unref (clock); +} + +GST_END_TEST; + +GST_START_TEST (test_set_time) +{ + GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND); + gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND); + g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND); + gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND + 1); + g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND + 1); + gst_object_unref (clock); +} + +GST_END_TEST; + +GST_START_TEST (test_advance_time) +{ + GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND); + gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 0); + g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND); + gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 42 * GST_MSECOND); + g_assert_cmpuint (gst_clock_get_time (clock), ==, + GST_SECOND + (42 * GST_MSECOND)); + gst_object_unref (clock); +} + +GST_END_TEST; + +static Suite * +gst_test_clock_suite (void) +{ + Suite *s = suite_create ("GstTestClock"); + TCase *tc_chain = tcase_create ("testclock"); + + suite_add_tcase (s, tc_chain); + + tcase_add_test (tc_chain, test_object_flags); + tcase_add_test (tc_chain, test_resolution_query); + tcase_add_test (tc_chain, test_start_time); + tcase_add_test (tc_chain, test_set_time); + tcase_add_test (tc_chain, test_advance_time); + + return s; +} + +GST_CHECK_MAIN (gst_test_clock);