[gnome-settings-daemon] datetime: Add test-system-timezone test program



commit 5baf1b47c9f0082acfb688bf912c22c2ec1f8ecf
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Nov 12 13:56:47 2010 +0000

    datetime: Add test-system-timezone test program
    
    https://bugzilla.gnome.org/show_bug.cgi?id=626345

 plugins/datetime/Makefile.am            |    4 +
 plugins/datetime/test-system-timezone.c |  122 +++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am
index fbfc86e..b4e0e9f 100644
--- a/plugins/datetime/Makefile.am
+++ b/plugins/datetime/Makefile.am
@@ -11,8 +11,10 @@ gsd-datetime-mechanism-glue.h: $(srcdir)/gsd-datetime-mechanism.xml
 			--output=gsd-datetime-mechanism-glue.h			\
 			$(srcdir)/gsd-datetime-mechanism.xml
 
+
 if HAVE_POLKIT
 libexec_PROGRAMS = gsd-datetime-mechanism
+noinst_PROGRAMS = test-system-timezone
 endif
 
 gsd_datetime_mechanism_SOURCES =		\
@@ -30,6 +32,8 @@ endif
 AM_CFLAGS = $(SETTINGS_PLUGIN_CFLAGS) $(POLKIT_CFLAGS)
 gsd_datetime_mechanism_LDADD = $(POLKIT_LIBS) $(SETTINGS_PLUGIN_LIBS)
 
+test_system_timezone_SOURCES = test-system-timezone.c system-timezone.c system-timezone.h
+test_system_timezone_LDADD = $(POLKIT_LIBS) $(SETTINGS_PLUGIN_LIBS)
 
 if HAVE_POLKIT
 dbus_services_DATA = $(dbus_services_in_files:.service.in=.service)
diff --git a/plugins/datetime/test-system-timezone.c b/plugins/datetime/test-system-timezone.c
new file mode 100644
index 0000000..42a8061
--- /dev/null
+++ b/plugins/datetime/test-system-timezone.c
@@ -0,0 +1,122 @@
+/* Test for system timezone handling
+ *
+ * Copyright (C) 2008-2010 Novell, Inc.
+ *
+ * Authors: Vincent Untz <vuntz gnome org>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include "system-timezone.h"
+
+static void
+timezone_print (void)
+{
+	SystemTimezone *systz;
+
+	systz = system_timezone_new ();
+        g_print ("Current timezone: %s\n", system_timezone_get (systz));
+	g_object_unref (systz);
+}
+
+static int
+timezone_set (const char *new_tz)
+{
+        GError *error;
+
+        error = NULL;
+        if (!system_timezone_set (new_tz, &error)) {
+                g_printerr ("%s\n", error->message);
+                g_error_free (error);
+                return 1;
+        }
+
+	return 0;
+}
+
+static void
+timezone_changed (SystemTimezone *systz,
+		  const char     *new_tz,
+		  gpointer        data)
+{
+	g_print ("Timezone changed to: %s\n", new_tz);
+}
+
+static void
+timezone_monitor (void)
+{
+	SystemTimezone *systz;
+	GMainLoop      *mainloop;
+
+	systz = system_timezone_new ();
+	g_signal_connect (systz, "changed",
+			  G_CALLBACK (timezone_changed), NULL);
+
+	mainloop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (mainloop);
+	g_main_loop_unref (mainloop);
+
+	g_object_unref (systz);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+	int      retval;
+
+	gboolean  get = FALSE;
+	gboolean  monitor = FALSE;
+	char     *tz_set = NULL;
+
+	GError         *error;
+	GOptionContext *context;
+        GOptionEntry options[] = {
+                { "get", 'g', 0, G_OPTION_ARG_NONE, &get, "Get the current timezone", NULL },
+                { "set", 's', 0, G_OPTION_ARG_STRING, &tz_set, "Set the timezone to TIMEZONE", "TIMEZONE" },
+                { "monitor", 'm', 0, G_OPTION_ARG_NONE, &monitor, "Monitor timezone changes", NULL },
+                { NULL, 0, 0, 0, NULL, NULL, NULL }
+        };
+
+	retval = 0;
+
+	g_type_init ();
+
+	context = g_option_context_new ("");
+	g_option_context_add_main_entries (context, options, NULL);
+
+	error = NULL;
+	if (!g_option_context_parse (context, &argc, &argv, &error)) {
+		g_printerr ("%s\n", error->message);
+		g_error_free (error);
+		g_option_context_free (context);
+
+		return 1;
+	}
+
+	g_option_context_free (context);
+
+	if (get || (!tz_set && !monitor))
+		timezone_print ();
+	else if (tz_set)
+		retval = timezone_set (tz_set);
+	else if (monitor)
+		timezone_monitor ();
+	else
+		g_assert_not_reached ();
+
+        return retval;
+}



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