[gnome-panel] [clock] Move the system-timezone tests to test-system-timezone
- From: Vincent Untz <vuntz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-panel] [clock] Move the system-timezone tests to test-system-timezone
- Date: Thu, 14 Jan 2010 01:51:32 +0000 (UTC)
commit 33ba10e9aba8b5490ee3d749d8aa0f62e383d5a1
Author: Vincent Untz <vuntz gnome org>
Date: Thu Jan 14 01:34:19 2010 +0100
[clock] Move the system-timezone tests to test-system-timezone
Also add a monitor mode.
applets/clock/Makefile.am | 11 +++
applets/clock/system-timezone.c | 76 ---------------------
applets/clock/test-system-timezone.c | 122 ++++++++++++++++++++++++++++++++++
3 files changed, 133 insertions(+), 76 deletions(-)
---
diff --git a/applets/clock/Makefile.am b/applets/clock/Makefile.am
index da5e0d9..7a6b931 100644
--- a/applets/clock/Makefile.am
+++ b/applets/clock/Makefile.am
@@ -225,6 +225,17 @@ dbus_conf_DATA =
polkit_DATA =
endif
+noinst_PROGRAMS = test-system-timezone
+
+test_system_timezone_SOURCES = \
+ system-timezone.c \
+ system-timezone.h \
+ test-system-timezone.c \
+ $(NULL)
+
+test_system_timezone_LDADD = \
+ $(CLOCK_LDADD) \
+ $(NULL)
EXTRA_DIST = \
GNOME_ClockApplet_Factory.server.in.in \
diff --git a/applets/clock/system-timezone.c b/applets/clock/system-timezone.c
index 20cc325..bcd7f4a 100644
--- a/applets/clock/system-timezone.c
+++ b/applets/clock/system-timezone.c
@@ -40,18 +40,6 @@
* Largely based on Michael Fulbright's work on Anaconda.
*/
-/* To compile a test program, do:
- * $ gcc -DSYSTZ_GET_TEST -Wall -g -O0 -o system-timezone-get `pkg-config --cflags --libs glib-2.0 gobject-2.0 gio-2.0` system-timezone.c
- * or:
- * $ gcc -DSYSTZ_SET_TEST -Wall -g -O0 -o system-timezone-set `pkg-config --cflags --libs glib-2.0 gobject-2.0 gio-2.0` system-timezone.c
- *
- * You can then read the system timezone with:
- * $ system-timezone-get
- * and simulate a set of system timezone (in /tmp/etc/...) with:
- * $ system-timezone-set "Europe/Paris"
- */
-
-
/* FIXME: it'd be nice to filter out the timezones that we might get when
* parsing config files that are not in zone.tab. Note that it's also wrong
* in some cases: eg, in tzdata2008b, Asia/Calcutta got renamed to
@@ -68,23 +56,12 @@
/* Files that we look at and that should be monitored */
#define CHECK_NB 5
-#ifndef SYSTZ_SET_TEST
#define ETC_TIMEZONE "/etc/timezone"
#define ETC_TIMEZONE_MAJ "/etc/TIMEZONE"
#define ETC_RC_CONF "/etc/rc.conf"
#define ETC_SYSCONFIG_CLOCK "/etc/sysconfig/clock"
#define ETC_CONF_D_CLOCK "/etc/conf.d/clock"
#define ETC_LOCALTIME "/etc/localtime"
-#else
-/* Filenames that will be writable for testing */
-#define TEST_PREFIX "/tmp/systz-test"
-#define ETC_TIMEZONE TEST_PREFIX"/etc/timezone"
-#define ETC_TIMEZONE_MAJ TEST_PREFIX"/etc/TIMEZONE"
-#define ETC_RC_CONF TEST_PREFIX"/etc/rc.conf"
-#define ETC_SYSCONFIG_CLOCK TEST_PREFIX"/etc/sysconfig/clock"
-#define ETC_CONF_D_CLOCK TEST_PREFIX"/etc/conf.d/clock"
-#define ETC_LOCALTIME TEST_PREFIX"/etc/localtime"
-#endif /* SYSTZ_SET_TEST */
/* The first 4 characters in a timezone file, from tzfile.h */
#define TZ_MAGIC "TZif"
@@ -1053,56 +1030,3 @@ system_timezone_error_quark (void)
return ret;
}
-
-#ifdef SYSTZ_GET_TEST
-int
-main (int argc,
- char **argv)
-{
- char *tz;
-
- tz = system_timezone_find ();
- g_print ("%s\n", tz);
- g_free (tz);
-
- return 0;
-}
-#endif /* SYSTZ_GET_TEST */
-
-#ifdef SYSTZ_SET_TEST
-int
-main (int argc,
- char **argv)
-{
- GError *error;
- char *dirname;
-
- if (argc != 2) {
- g_print ("Usage: %s TIMEZONE\n", argv[0]);
- return 1;
- }
-
- dirname = g_path_get_dirname (ETC_TIMEZONE);
- g_mkdir_with_parents (dirname, 0755);
- g_free (dirname);
- dirname = g_path_get_dirname (ETC_SYSCONFIG_CLOCK);
- g_mkdir_with_parents (dirname, 0755);
- g_free (dirname);
- dirname = g_path_get_dirname (ETC_CONF_D_CLOCK);
- g_mkdir_with_parents (dirname, 0755);
- g_free (dirname);
-
- error = NULL;
- if (!system_timezone_set (argv[1], &error)) {
- g_print ("%s\n", error->message);
- g_error_free (error);
- return 1;
- }
-
- g_print (TEST_PREFIX" is the test directory where files "
- "were written (feel free to populate this directory with "
- "files that should be modified by this program).\n");
-
- return 0;
-}
-#endif /* SYSTZ_SET_TEST */
diff --git a/applets/clock/test-system-timezone.c b/applets/clock/test-system-timezone.c
new file mode 100644
index 0000000..42a8061
--- /dev/null
+++ b/applets/clock/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]