2 * Unit test for a deterministic clock for Gstreamer unit tests
4 * Copyright (C) 2008 Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com>
5 * Copyright (C) 2012 Sebastian Rasmussen <sebastian.rasmussen@axis.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
24 #include <gst/check/gsttestclock.h>
26 GST_START_TEST (test_object_flags)
28 GstClock *clock = gst_test_clock_new ();
29 g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC));
30 g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC));
31 g_assert (GST_OBJECT_FLAG_IS_SET (clock,
32 GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC));
33 g_assert (GST_OBJECT_FLAG_IS_SET (clock,
34 GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC));
35 gst_object_unref (clock);
40 GST_START_TEST (test_resolution_query)
42 GstClock *clock = gst_test_clock_new ();
43 g_assert_cmpuint (gst_clock_get_resolution (clock), ==, 1);
44 gst_object_unref (clock);
49 GST_START_TEST (test_start_time)
54 clock = gst_test_clock_new ();
55 g_assert_cmpuint (gst_clock_get_time (clock), ==, 0);
56 g_object_get (clock, "start-time", &start_time, NULL);
57 g_assert_cmpuint (start_time, ==, 0);
58 gst_object_unref (clock);
60 clock = gst_test_clock_new_with_start_time (GST_SECOND);
61 g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
62 g_object_get (clock, "start-time", &start_time, NULL);
63 g_assert_cmpuint (start_time, ==, GST_SECOND);
64 gst_object_unref (clock);
69 GST_START_TEST (test_set_time)
71 GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND);
72 gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND);
73 g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
74 gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND + 1);
75 g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND + 1);
76 gst_object_unref (clock);
81 GST_START_TEST (test_advance_time)
83 GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND);
84 gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 0);
85 g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
86 gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 42 * GST_MSECOND);
87 g_assert_cmpuint (gst_clock_get_time (clock), ==,
88 GST_SECOND + (42 * GST_MSECOND));
89 gst_object_unref (clock);
95 gst_test_clock_suite (void)
97 Suite *s = suite_create ("GstTestClock");
98 TCase *tc_chain = tcase_create ("testclock");
100 suite_add_tcase (s, tc_chain);
102 tcase_add_test (tc_chain, test_object_flags);
103 tcase_add_test (tc_chain, test_resolution_query);
104 tcase_add_test (tc_chain, test_start_time);
105 tcase_add_test (tc_chain, test_set_time);
106 tcase_add_test (tc_chain, test_advance_time);
111 GST_CHECK_MAIN (gst_test_clock);