[tracker] fix timezone tests



commit e36ba9a0369b76310328507bf8e52c13bfa49fc1
Author: Saleem Abdulrasool <compnerd compnerd org>
Date:   Mon Oct 5 09:39:35 2009 -0700

    fix timezone tests
    
    g_date_set_time_t uses the environment variable TZ to convert the time between
    timezones.  If the timezone is not UTC, the tests would fail previously.  We now
    save and restore the TZ value, and set the value to UTC while running the test.

 tests/libtracker-common/tracker-type-utils-test.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c
index 4c2ad0b..105cba0 100644
--- a/tests/libtracker-common/tracker-type-utils-test.c
+++ b/tests/libtracker-common/tracker-type-utils-test.c
@@ -75,6 +75,15 @@ test_string_to_date (void)
 	GDate	  *result;
 	time_t	   result_time_t;
 	const gchar  *input = "2008-06-16T11:10:10+0600";
+	gchar  *timezone = g_strdup (g_getenv ("TZ"));
+
+	if (! g_setenv ("TZ", "UTC", TRUE)) {
+		g_test_message ("unable to set timezone, test results are invalid, skipping\n");
+		if (timezone) {
+			g_free (timezone);
+		}
+		return;
+	}
 
 	expected = g_date_new_dmy (16, G_DATE_JUNE, 2008);
 
@@ -83,6 +92,11 @@ test_string_to_date (void)
 	result = g_date_new ();
 	g_date_set_time_t (result, result_time_t);
 
+	g_setenv ("TZ", timezone, TRUE);
+	if (timezone) {
+		g_free (timezone);
+	}
+
 	g_assert_cmpint (g_date_get_year (expected), ==, g_date_get_year (result));
 	g_assert_cmpint (g_date_get_day (expected), ==, g_date_get_day (result));
 	g_assert_cmpint (g_date_get_month (expected), ==, g_date_get_month (result));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]