2016-06-10 14:33:32 +02:00
|
|
|
#include <locale.h>
|
2011-03-15 01:56:24 +00:00
|
|
|
#include <gtk/gtk.h>
|
2018-04-03 19:26:57 +02:00
|
|
|
#include "cc-datetime-resources.h"
|
2011-03-15 01:56:24 +00:00
|
|
|
#include "cc-timezone-map.h"
|
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
static void
|
|
|
|
test_timezone (void)
|
2011-03-15 01:56:24 +00:00
|
|
|
{
|
2018-05-09 15:31:01 -03:00
|
|
|
g_autoptr(GHashTable) ht = NULL;
|
|
|
|
CcTimezoneMap *map;
|
|
|
|
TzDB *tz_db;
|
|
|
|
guint i;
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
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 ();
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
g_assert_nonnull (tz_db);
|
|
|
|
g_assert_nonnull (tz_db->locations);
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
for (i = 0; tz_db->locations && i < tz_db->locations->len; i++)
|
|
|
|
{
|
|
|
|
g_autofree gchar *clean_tz = NULL;
|
|
|
|
TzLocation *location = NULL;
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
location = g_ptr_array_index (tz_db->locations, i);
|
|
|
|
clean_tz = tz_info_get_clean_name (tz_db, location->zone);
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
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));
|
|
|
|
}
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
/* 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 ();
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 17:07:07 +01:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
tz_db_free (tz_db);
|
2016-06-10 14:33:32 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
gint
|
|
|
|
main (gint argc,
|
|
|
|
gchar **argv)
|
2016-06-10 14:33:32 +02:00
|
|
|
{
|
2018-05-09 15:31:01 -03:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
gtk_init (NULL, NULL);
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
2016-06-10 14:33:32 +02:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
g_resources_register (cc_datetime_get_resource ());
|
2018-04-03 19:26:57 +02:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
|
2016-06-10 14:33:32 +02:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
g_test_add_func ("/datetime/timezone", test_timezone);
|
2011-03-15 01:56:24 +00:00
|
|
|
|
2018-05-09 15:31:01 -03:00
|
|
|
return g_test_run ();
|
2011-03-15 01:56:24 +00:00
|
|
|
}
|