mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 15:04:46 +00:00
tests: make datetime test more reliably when comparing two almost identical nows
Account for rounding errors in some places, and that two nows are not always entirely identical, so allow some leeway when comparing microseconds and seconds. Ran into this too often, esp. when the system is under load.
This commit is contained in:
parent
daa5cae78b
commit
64effe78e7
1 changed files with 10 additions and 8 deletions
|
@ -24,11 +24,13 @@
|
|||
#include <time.h>
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
#define ASSERT_TIME(dt,H,M,S) G_STMT_START { \
|
||||
assert_equals_int ((H), gst_date_time_get_hour ((dt))); \
|
||||
assert_equals_int ((M), gst_date_time_get_minute ((dt))); \
|
||||
assert_equals_int ((S), gst_date_time_get_second ((dt))); \
|
||||
} G_STMT_END
|
||||
#define assert_almost_equals_int(a, b) \
|
||||
G_STMT_START { \
|
||||
int first = a; \
|
||||
int second = b; \
|
||||
fail_unless(ABS (first - second) <= 1, \
|
||||
"'" #a "' (%d) is not almost equal to '" #b"' (%d)", first, second); \
|
||||
} G_STMT_END;
|
||||
|
||||
GST_START_TEST (test_GstDateTime_now)
|
||||
{
|
||||
|
@ -49,7 +51,7 @@ GST_START_TEST (test_GstDateTime_now)
|
|||
assert_equals_int (gst_date_time_get_day (dt), tm.tm_mday);
|
||||
assert_equals_int (gst_date_time_get_hour (dt), tm.tm_hour);
|
||||
assert_equals_int (gst_date_time_get_minute (dt), tm.tm_min);
|
||||
assert_equals_int (gst_date_time_get_second (dt), tm.tm_sec);
|
||||
assert_almost_equals_int (gst_date_time_get_second (dt), tm.tm_sec);
|
||||
gst_date_time_unref (dt);
|
||||
}
|
||||
|
||||
|
@ -177,7 +179,7 @@ GST_START_TEST (test_GstDateTime_get_microsecond)
|
|||
g_get_current_time (&tv);
|
||||
dt = gst_date_time_new (0, 2010, 7, 15, 11, 12,
|
||||
13 + (tv.tv_usec / 1000000.0));
|
||||
assert_equals_int (tv.tv_usec, gst_date_time_get_microsecond (dt));
|
||||
assert_almost_equals_int (tv.tv_usec, gst_date_time_get_microsecond (dt));
|
||||
gst_date_time_unref (dt);
|
||||
}
|
||||
|
||||
|
@ -252,7 +254,7 @@ GST_START_TEST (test_GstDateTime_utc_now)
|
|||
assert_equals_int (tm.tm_mday, gst_date_time_get_day (dt));
|
||||
assert_equals_int (tm.tm_hour, gst_date_time_get_hour (dt));
|
||||
assert_equals_int (tm.tm_min, gst_date_time_get_minute (dt));
|
||||
assert_equals_int (tm.tm_sec, gst_date_time_get_second (dt));
|
||||
assert_almost_equals_int (tm.tm_sec, gst_date_time_get_second (dt));
|
||||
gst_date_time_unref (dt);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue