From 06015064b8766bbc3efbc38ed2a62703322ca173 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 7 Apr 2012 11:27:15 -0400 Subject: [PATCH] date: Improve test coverage Add tests that exercise g_date_order, g_date_compare, g_date_clamp, and more of the date parsing functions. --- glib/tests/date.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/glib/tests/date.c b/glib/tests/date.c index 39b792f42..81635aa0c 100644 --- a/glib/tests/date.c +++ b/glib/tests/date.c @@ -130,6 +130,18 @@ test_parse (void) g_assert_cmpint (g_date_get_day (d), ==, 10); g_assert_cmpint (g_date_get_year (d), ==, 2000); + g_date_set_parse (d, "10 10 10"); + g_assert (g_date_valid (d)); + g_assert_cmpint (g_date_get_month (d), ==, 10); + g_assert_cmpint (g_date_get_day (d), ==, 10); + g_assert_cmpint (g_date_get_year (d), ==, 10); + + g_date_set_parse (d, "10 March 10"); + g_assert (g_date_valid (d)); + g_assert_cmpint (g_date_get_month (d), ==, 3); + g_assert_cmpint (g_date_get_day (d), ==, 10); + g_assert_cmpint (g_date_get_year (d), ==, 10); + g_date_free (d); } @@ -282,6 +294,41 @@ test_year (gconstpointer t) g_assert_cmpint (j + 2, ==, g_date_get_julian (&tmp)); } +static void +test_clamp (void) +{ + GDate d1, d2, d, o; + + g_date_set_dmy (&d1, 1, 1, 1970); + g_date_set_dmy (&d2, 1, 1, 1980); + g_date_set_dmy (&d, 1, 1, 1); + + o = d; + g_date_clamp (&o, NULL, NULL); + g_assert (g_date_compare (&o, &d) == 0); + + g_date_clamp (&o, &d1, &d2); + g_assert (g_date_compare (&o, &d1) == 0); + + g_date_set_dmy (&o, 1, 1, 2000); + + g_date_clamp (&o, &d1, &d2); + g_assert (g_date_compare (&o, &d2) == 0); +} + +static void +test_order (void) +{ + GDate d1, d2; + + g_date_set_dmy (&d1, 1, 1, 1970); + g_date_set_dmy (&d2, 1, 1, 1980); + + g_assert (g_date_compare (&d1, &d2) == -1); + g_date_order (&d2, &d1); + g_assert (g_date_compare (&d1, &d2) == 1); +} + int main (int argc, char** argv) { @@ -314,6 +361,8 @@ main (int argc, char** argv) g_test_add_func ("/date/julian", test_julian_constructor); g_test_add_func ("/date/dates", test_dates); g_test_add_func ("/date/parse", test_parse); + g_test_add_func ("/date/clamp", test_clamp); + g_test_add_func ("/date/order", test_order); for (i = 0; i < G_N_ELEMENTS (check_years); i++) { path = g_strdup_printf ("/date/year/%d", check_years[i]); -- 2.11.0