libtimezonemap/0010-Add-a-new-test-to-check-whether-all-zones-can-be-sel.patch
David Shea 51a02b6c80 Update the map data and improve behavior:
- Render the map directly from SVG (#1335158)
- Fix memory leaks in tz.c
- Fix an invalid memory access
- Do not modify TZ in the process environment
- Move all data files to /usr/share/libtimezonemap from .../libtimezonemap/ui
- Add extra city data so all timezone offsets are clickable
- Move Venezuela from -04:30 to -04:00
- Fix the conversion of points just west of 180 longitude
- Remove the out-of-date Olson map data
- Update the "backward" file
- Improve the location selected when setting the timezone by name (#1322648)
- Remove an extra line in the +10:00 layer
- Move Chile back an hour
2016-06-29 14:56:01 -04:00

286 lines
8.6 KiB
Diff

From 830abfced87aefae3f574170a9948dcdc5d4bef2 Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Fri, 24 Jun 2016 14:26:13 -0400
Subject: [PATCH 10/24] Add a new test to check whether all zones can be
selected.
Since the answer is "no", add some additional city data to provide
locations for currently unclickable zones.
---
configure.ac | 3 +
src/Makefile.am | 22 +++++--
src/data/README | 5 ++
src/data/citiesExtra.txt | 5 ++
src/test-clickability.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++
src/tz.h | 2 +-
7 files changed, 186 insertions(+), 5 deletions(-)
create mode 100644 src/data/citiesExtra.txt
create mode 100644 src/test-clickability.c
diff --git a/configure.ac b/configure.ac
index 7e647f0..31f8ffa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,6 +61,9 @@ PKG_CHECK_MODULES(LIBTIMEZONEMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
librsvg-2.0)
LIBTIMEZONEMAP_LIBS="$LIBTIMEZONEMAP_LIBS $LIBM"
+# Extra requirements for tests
+PKG_CHECK_MODULES(LIBXML, libxml-2.0)
+
GOBJECT_INTROSPECTION_CHECK([0.6.7])
###########################
diff --git a/src/Makefile.am b/src/Makefile.am
index 106f034..56e404a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,10 +5,19 @@ dist_ui_DATA = \
data/olsen_map.png \
data/pin.png \
data/time_zones_countryInfo-orig.svg \
- data/cities15000.txt \
data/admin1Codes.txt \
data/countryInfo.txt
+nodist_ui_DATA = \
+ data/citiesInfo.txt
+
+dist_noinst_DATA = \
+ data/cities15000.txt \
+ data/citiesExtra.txt
+
+data/citiesInfo.txt: data/cities15000.txt data/citiesExtra.txt
+ cat data/cities15000.txt data/citiesExtra.txt > $@
+
tzdatadir = $(pkgdatadir)/
dist_tzdata_DATA = data/backward
@@ -25,19 +34,24 @@ noinst_PROGRAMS = test-timezone
all-local: check
-AM_TESTS_ENVIRONMENT = TZ_DATA_FILE=$(srcdir)/data/cities15000.txt ; \
+AM_TESTS_ENVIRONMENT = TZ_DATA_FILE=$(srcdir)/data/citiesInfo.txt ; \
ADMIN1_FILE=$(srcdir)/data/admin1Codes.txt ; \
COUNTRY_FILE=$(srcdir)/data/countryInfo.txt ; \
DATADIR=$(srcdir)/data ; \
export TZ_DATA_FILE ADMIN1_FILE COUNTRY_FILE DATADIR ;
-check_PROGRAMS = test-timezone
+check_PROGRAMS = test-timezone \
+ test-clickability
test_timezone_SOURCES = test-timezone.c
test_timezone_LDADD = $(LIBTIMEZONEMAP_LIBS) -lm libtimezonemap.la
test_timezone_CFLAGS = $(LIBTIMEZONEMAP_CFLAGS)
-TESTS = test-timezone
+test_clickability_SOURCES = test-clickability.c
+test_clickability_LDADD = $(LIBTIMEZONEMAP_LIBS) $(LIBXML_LIBS) libtimezonemap.la
+test_clickability_CFLAGS = $(LIBTIMEZONEMAP_CFLAGS) $(LIBXML_CFLAGS)
+
+TESTS = test-timezone test-clickability
lib_LTLIBRARIES = libtimezonemap.la
diff --git a/src/data/README b/src/data/README
index 1b1a737..a643fc1 100644
--- a/src/data/README
+++ b/src/data/README
@@ -8,6 +8,11 @@ admin1Codes.txt, cities15000.txt, countryInfo.txt
These three files come from the geonames.org database. Simply find the files
in http://download.geonames.org/export/dump/ and copy them to this directory.
+citiesExtra.txt
+ These are additional cities with populations less than 15,000 used to
+ provide clickable locations for sparesly populated timezones. It consists of
+ extra lines from the geonames database.
+
backward
This file lists links between current time zone names and obsolete time zone
names. It comes from the tzdata at https://www.iana.org/time-zones
diff --git a/src/data/citiesExtra.txt b/src/data/citiesExtra.txt
new file mode 100644
index 0000000..1df5349
--- /dev/null
+++ b/src/data/citiesExtra.txt
@@ -0,0 +1,5 @@
+7521902 Tabwakea Village Tabwakea Village 2.01643 -157.48773 P PPL KI 02 KT 1881 6 Pacific/Kiritimati 2010-10-22
+8063344 Taiohae Taiohae Hakapehi -8.91093 -140.09972 P PPLA PF 04 1224 23 Pacific/Marquesas 2013-08-10
+4032824 Tuku Tuku Te Tuku -44.06667 -176.65 H STM NZ NZ 0 101 Pacific/Chatham 1993-12-30
+7731015 Eucla Airport Eucla Airport EUC,Eucla Airport,YECL -31.70674 128.87718 S AIRP AU 08 53080 0 7 Australia/Eucla 2014-11-09
+2159558 Lord Howe Island Lord Howe Island Ile Lord Howe,Lord Howe,Lord Howe Island,Lord Howe-eiland,Lord Howeoen,Lord Howeön,Lord-Howe-Eiland,Lord-Howe-Insel,Ostrov lorda Howa,Île Lord Howe,ロード・ハウ島 -31.55455 159.08246 T ISL AU 02 0 59 Australia/Lord_Howe 2015-06-01
diff --git a/src/test-clickability.c b/src/test-clickability.c
new file mode 100644
index 0000000..2784b60
--- /dev/null
+++ b/src/test-clickability.c
@@ -0,0 +1,150 @@
+#include "config.h"
+#include "tz.h"
+
+#include <string.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+/* For each offset png, check that there is at least one clickable location in
+ * the tzdb with the offset */
+int main(int argc, char **argv)
+{
+ TzDB *db;
+ GPtrArray *locs;
+ CcTimezoneLocation *loc;
+ TzInfo *info;
+ gdouble loc_offset;
+
+ xmlDocPtr doc;
+ xmlXPathContextPtr xpathCtx;
+ xmlXPathObjectPtr xpathObj;
+ xmlNodeSetPtr nodes;
+
+ const char *pixmap_dir;
+ gchar *path;
+
+ GError *error = NULL;
+ gchar *endptr;
+ gdouble timezone_offset;
+ int i, j;
+
+ int retval = 0;
+
+ if (argc == 2)
+ {
+ pixmap_dir = argv[1];
+ }
+ else if (argc == 1)
+ {
+ const char *datadir = g_getenv("DATADIR");
+ if (datadir != NULL)
+ {
+ pixmap_dir = datadir;
+ }
+ else
+ {
+ pixmap_dir = "./data";
+ }
+ }
+ else
+ {
+ g_message("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
+ return 1;
+ }
+
+ if (! g_file_test(pixmap_dir, G_FILE_TEST_IS_DIR))
+ {
+ g_message("Pixmap directory %s does not exist", pixmap_dir);
+ return 1;
+ }
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+ g_type_init();
+#endif
+
+ xmlInitParser ();
+ path = g_build_filename (pixmap_dir, "time_zones_countryInfo-orig.svg", NULL);
+ doc = xmlParseFile (path);
+ if (doc == NULL)
+ {
+ g_message("Unable to parse '%s'", path);
+ g_free (path);
+ return 1;
+ }
+ g_free (path);
+
+ /* Iterate over each layer, which can be found as <g> element wit
+ * inkscape:groupmode="layer" */
+ xpathCtx = xmlXPathNewContext(doc);
+ xmlXPathRegisterNs(xpathCtx, "svg", "http://www.w3.org/2000/svg");
+ xmlXPathRegisterNs(xpathCtx, "inkscape", "http://www.inkscape.org/namespaces/inkscape");
+
+ xpathObj = xmlXPathEvalExpression("//svg:g[@inkscape:groupmode = 'layer']", xpathCtx);
+ if (!xpathObj)
+ {
+ g_message("Unable to evaluate xpath");
+ return 1;
+ }
+
+ nodes = xpathObj->nodesetval;
+ if (nodes == NULL)
+ {
+ g_message("Unable to find layers in SVG");
+ return 1;
+ }
+
+ db = tz_load_db ();
+ locs = tz_get_locations (db);
+
+ for (i = 0; i < nodes->nodeNr; i++)
+ {
+ char *id = xmlGetProp(nodes->nodeTab[i], "id");
+
+ if (id[0] != 'm' && id[0] != 'p')
+ {
+ continue;
+ }
+
+ timezone_offset = g_ascii_strtod (id+1, &endptr);
+ if (*endptr != '\0')
+ {
+ g_message ("Unable to parse layer name %s", id);
+ retval = 1;
+ }
+ if (id[0] == 'm')
+ {
+ timezone_offset = -timezone_offset;
+ }
+
+ /* Look for a location in tzdb with the same offset */
+ loc_offset = G_MAXDOUBLE;
+ for (j = 0; j < locs->len; j++)
+ {
+ loc = locs->pdata[j];
+ info = tz_info_from_location (loc);
+ loc_offset = tz_location_get_utc_offset (loc)
+ / (60.0 * 60.0) + ((info->daylight) ? -1.0 : 0.0);
+
+ if (loc_offset == timezone_offset)
+ {
+ break;
+ }
+ }
+
+ if (loc_offset != timezone_offset)
+ {
+ g_message ("Unable to find location for offset %.02f", timezone_offset);
+ retval = 1;
+ }
+ }
+
+ tz_db_free (db);
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+
+ return retval;
+}
diff --git a/src/tz.h b/src/tz.h
index b94a886..2b03e9e 100644
--- a/src/tz.h
+++ b/src/tz.h
@@ -30,7 +30,7 @@
#include "cc-timezone-location.h"
-# define TZ_DATA_FILE "/usr/share/libtimezonemap/cities15000.txt"
+# define TZ_DATA_FILE "/usr/share/libtimezonemap/citiesInfo.txt"
# define ADMIN1_FILE "/usr/share/libtimezonemap/admin1Codes.txt"
# define COUNTRY_FILE "/usr/share/libtimezonemap/countryInfo.txt"
--
2.5.5