[gnome-control-center] datetime: Add test program for missing TZ support



commit 33fb810c846c68a2cde2a784057b965287322aa6
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Mar 15 01:56:24 2011 +0000

    datetime: Add test program for missing TZ support
    
    We don't handle a number of timezones currently, including
    things like "posixrules", or even "Etc/GMT".

 panels/datetime/Makefile.am     |    9 +++-
 panels/datetime/test-timezone.c |   81 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 2 deletions(-)
---
diff --git a/panels/datetime/Makefile.am b/panels/datetime/Makefile.am
index c982bba..e76a24b 100644
--- a/panels/datetime/Makefile.am
+++ b/panels/datetime/Makefile.am
@@ -74,7 +74,11 @@ AM_CPPFLAGS =						\
 	-DDATADIR="\"$(uidir)\""			\
 	$(NULL)
 
-noinst_PROGRAMS = test-timezone-gfx test-endianess
+noinst_PROGRAMS = test-timezone-gfx test-endianess test-timezone
+
+test_timezone_SOURCES = test-timezone.c cc-timezone-map.h cc-timezone-map.c tz.c tz.h
+test_timezone_LDADD = $(DATETIME_PANEL_LIBS)
+test_timezone_CFLAGS = $(DATETIME_PANEL_CFLAGS)
 
 test_timezone_gfx_SOURCES = test-timezone-gfx.c tz.c tz.h
 test_timezone_gfx_LDADD = $(DATETIME_PANEL_LIBS)
@@ -86,9 +90,10 @@ test_endianess_CFLAGS = $(DATETIME_PANEL_CFLAGS)
 
 all-local: check-local
 
-check-local: test-timezone-gfx test-endianess
+check-local: test-timezone-gfx test-endianess test-timezone
 	$(builddir)/test-timezone-gfx $(srcdir)/data
 	$(builddir)/test-endianess
+	$(builddir)/test-timezone
 
 ccpanelsdir = $(PANELS_DIR)
 ccpanels_LTLIBRARIES = libdate_time.la
diff --git a/panels/datetime/test-timezone.c b/panels/datetime/test-timezone.c
new file mode 100644
index 0000000..2dc744e
--- /dev/null
+++ b/panels/datetime/test-timezone.c
@@ -0,0 +1,81 @@
+#include <gtk/gtk.h>
+#include "cc-timezone-map.h"
+
+#define TZ_DIR "/usr/share/zoneinfo/"
+
+static GList *
+get_timezone_list (GList *tzs,
+		   const char *top_path,
+		   const char *subpath)
+{
+	GDir *dir;
+	char *fullpath;
+	const char *name;
+
+	if (subpath == NULL)
+		fullpath = g_strdup (top_path);
+	else
+		fullpath = g_build_filename (top_path, subpath, NULL);
+	dir = g_dir_open (fullpath, 0, NULL);
+	if (dir == NULL) {
+		g_warning ("Could not open %s", fullpath);
+		return NULL;
+	}
+	while ((name = g_dir_read_name (dir)) != NULL) {
+		char *path;
+
+		if (g_str_has_suffix (name, ".tab"))
+			continue;
+
+		if (subpath != NULL)
+			path = g_build_filename (top_path, subpath, name, NULL);
+		else
+			path = g_build_filename (top_path, name, NULL);
+		if (g_file_test (path, G_FILE_TEST_IS_DIR)) {
+			if (subpath == NULL) {
+				tzs = get_timezone_list (tzs, top_path, name);
+			} else {
+				char *new_subpath;
+				new_subpath = g_strdup_printf ("%s/%s", subpath, name);
+				tzs = get_timezone_list (tzs, top_path, new_subpath);
+				g_free (new_subpath);
+			}
+		} else if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
+			if (subpath == NULL)
+				tzs = g_list_prepend (tzs, g_strdup (name));
+			else {
+				char *tz;
+				tz = g_strdup_printf ("%s/%s", subpath, name);
+				tzs = g_list_prepend (tzs, tz);
+			}
+		}
+		g_free (path);
+	}
+	g_dir_close (dir);
+
+	return tzs;
+}
+
+int main (int argc, char **argv)
+{
+	CcTimezoneMap *map;
+	GList *tzs, *l;
+	int ret = 0;
+
+	gtk_init (&argc, &argv);
+
+	map = cc_timezone_map_new ();
+	tzs = get_timezone_list (NULL, TZ_DIR, NULL);
+	for (l = tzs; l != NULL; l = l->next) {
+		char *timezone = l->data;
+
+		if (cc_timezone_map_set_timezone (map, timezone) == FALSE) {
+			g_warning ("Failed to locate timezone '%s'", timezone);
+			ret = 1;
+		}
+		g_free (timezone);
+	}
+	g_list_free (tzs);
+
+	return ret;
+}



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