systemclock: Add test for gst_clock_get_resolution
authorHeinrich Fink <hfink@toolsonair.com>
Thu, 12 Nov 2015 15:14:18 +0000 (16:14 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 13 Nov 2015 08:23:44 +0000 (09:23 +0100)
In a series of time measurements, the diff between now and previous
timestamps is either 0 or at least as long as get_resolution returned.

https://bugzilla.gnome.org/show_bug.cgi?id=758012

tests/check/gst/gstsystemclock.c

index 86f012b..a8dbcca 100644 (file)
@@ -670,6 +670,36 @@ GST_START_TEST (test_async_full)
 
 GST_END_TEST;
 
+GST_START_TEST (test_resolution)
+{
+  GstClock *clock;
+  GstClockTime now_t, prev_t, resolution;
+  int i;
+
+  now_t = prev_t = GST_CLOCK_TIME_NONE;
+  clock = gst_system_clock_obtain ();
+  fail_unless (clock != NULL, "Could not create default system clock");
+  resolution = gst_clock_get_resolution (clock);
+  fail_unless (resolution != GST_CLOCK_TIME_NONE);
+
+  for (i = 0; i < 100000; ++i) {
+    now_t = gst_clock_get_internal_time (clock);
+    fail_unless (now_t != GST_CLOCK_TIME_NONE);
+    if (prev_t != GST_CLOCK_TIME_NONE) {
+      GstClockTime diff;
+      fail_unless (now_t >= prev_t);
+      diff = now_t - prev_t;
+      fail_unless (diff == 0 || diff >= resolution);
+    }
+    prev_t = now_t;
+    g_thread_yield ();
+  }
+  g_object_unref (clock);
+  clock = NULL;
+}
+
+GST_END_TEST;
+
 static Suite *
 gst_systemclock_suite (void)
 {
@@ -688,6 +718,7 @@ gst_systemclock_suite (void)
   tcase_add_test (tc_chain, test_mixed);
   tcase_add_test (tc_chain, test_async_full);
   tcase_add_test (tc_chain, test_set_default);
+  tcase_add_test (tc_chain, test_resolution);
 
   return s;
 }