summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2018-05-09 15:31:01 -0300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2018-05-09 15:38:12 -0300
commit0b854910bb806f2662d083d9c5e7bdcc07c61084 (patch)
treedca8caef10ce383e7e12cbc8f4a6ec0d4f2a24ba
parent197ed1ed55d1d55108ee44ea009089babf4f0fed (diff)
downloadgnome-control-center-0b854910bb806f2662d083d9c5e7bdcc07c61084.tar.gz
tests: Rely only on zone.tab
First of all, this is a complete rewrite of the timezone tests. Everything was revisited, starting from code style, to concepts, etc. The problem with the previous timezone test was that is was relying on listing the /usr/share/zoneinfo directory, and assuming that those entries would be always present. Turns out, some of them are extensions, some of them are undocumented files, etc. A huge mess. I could've blacklisted the undesired files and folders, but that would still be insufficient for other OSes like *BSDs and Sun. The final solution was pretty straightforward: only use the information from zone.tab to run the tests.
-rw-r--r--tests/datetime/test-timezone.c134
1 files changed, 44 insertions, 90 deletions
diff --git a/tests/datetime/test-timezone.c b/tests/datetime/test-timezone.c
index 436f536b5..5962fc45e 100644
--- a/tests/datetime/test-timezone.c
+++ b/tests/datetime/test-timezone.c
@@ -3,109 +3,63 @@
#include "cc-datetime-resources.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)
+static void
+test_timezone (void)
{
- 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) {
- g_autofree gchar *path = NULL;
+ g_autoptr(GHashTable) ht = NULL;
+ CcTimezoneMap *map;
+ TzDB *tz_db;
+ guint i;
- if (g_str_has_suffix (name, ".tab"))
- continue;
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ map = cc_timezone_map_new ();
+ tz_db = tz_load_db ();
- 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 {
- g_autofree gchar *new_subpath = NULL;
- new_subpath = g_strdup_printf ("%s/%s", subpath, name);
- tzs = get_timezone_list (tzs, top_path, 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_dir_close (dir);
+ g_assert_nonnull (tz_db);
+ g_assert_nonnull (tz_db->locations);
- return tzs;
-}
+ for (i = 0; tz_db->locations && i < tz_db->locations->len; i++)
+ {
+ g_autofree gchar *clean_tz = NULL;
+ TzLocation *location = NULL;
-static void
-test_timezone (void)
-{
- CcTimezoneMap *map;
- TzDB *tz_db;
- GList *tzs, *l;
- GHashTable *ht;
+ location = g_ptr_array_index (tz_db->locations, i);
+ clean_tz = tz_info_get_clean_name (tz_db, location->zone);
- ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- map = cc_timezone_map_new ();
- tz_db = tz_load_db ();
- tzs = get_timezone_list (NULL, TZ_DIR, NULL);
- for (l = tzs; l != NULL; l = l->next) {
- const gchar *timezone = l->data;
- g_autofree gchar *clean_tz = NULL;
+ if (!cc_timezone_map_set_timezone (map, location->zone))
+ {
+ if (!g_hash_table_contains (ht, clean_tz))
+ {
+ if (g_strcmp0 (clean_tz, location->zone) == 0)
+ g_printerr ("Failed to locate timezone '%s'\n", location->zone);
+ else
+ g_printerr ("Failed to locate timezone '%s' (original name: '%s')\n", clean_tz, location->zone);
+ g_hash_table_insert (ht, g_strdup (clean_tz), GINT_TO_POINTER (TRUE));
+ }
- clean_tz = tz_info_get_clean_name (tz_db, timezone);
+ /* We don't warn for those, we'll just fallback
+ * in the panel code */
+ if (!g_str_equal (clean_tz, "posixrules") && !g_str_equal (clean_tz, "Factory"))
+ g_test_fail ();
+ }
+ }
- if (cc_timezone_map_set_timezone (map, clean_tz) == FALSE) {
- if (g_hash_table_lookup (ht, clean_tz) == NULL) {
- if (g_strcmp0 (clean_tz, timezone) == 0)
- g_print ("Failed to locate timezone '%s'\n", timezone);
- else
- g_print ("Failed to locate timezone '%s' (original name: '%s')\n", clean_tz, timezone);
- g_hash_table_insert (ht, g_strdup (clean_tz), GINT_TO_POINTER (TRUE));
- g_test_fail ();
- }
- /* We don't warn for those two, we'll just fallback
- * in the panel code */
- if (!g_str_equal (clean_tz, "posixrules") &&
- !g_str_equal (clean_tz, "Factory"))
- g_test_fail ();
- }
- }
- g_list_free_full (tzs, g_free);
- tz_db_free (tz_db);
- g_hash_table_destroy (ht);
+ tz_db_free (tz_db);
}
-int main (int argc, char **argv)
+gint
+main (gint argc,
+ gchar **argv)
{
- setlocale (LC_ALL, "");
- gtk_init (NULL, NULL);
- g_test_init (&argc, &argv, NULL);
+ setlocale (LC_ALL, "");
+ gtk_init (NULL, NULL);
+ g_test_init (&argc, &argv, NULL);
- g_resources_register (cc_datetime_get_resource ());
+ g_resources_register (cc_datetime_get_resource ());
- g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+ g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
- g_test_add_func ("/datetime/timezone", test_timezone);
+ g_test_add_func ("/datetime/timezone", test_timezone);
- return g_test_run ();
+ return g_test_run ();
}