[PATCH 3/9] Added a test for whether a timezone contains locations

David Shea dshea at redhat.com
Wed Nov 6 22:56:53 UTC 2013


This test is not run as part of make check since it depends on data
outside of our control (and it currently fails on UTC-1).
---
 widgets/tests/tzmapdata/.gitignore                 |  1 +
 widgets/tests/tzmapdata/Makefile.am                |  8 ++-
 widgets/tests/tzmapdata/test-tzmapdata-locations.c | 68 ++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 widgets/tests/tzmapdata/test-tzmapdata-locations.c

diff --git a/widgets/tests/tzmapdata/.gitignore b/widgets/tests/tzmapdata/.gitignore
index 65e10db..3be8047 100644
--- a/widgets/tests/tzmapdata/.gitignore
+++ b/widgets/tests/tzmapdata/.gitignore
@@ -1 +1,2 @@
 test-tzmapdata-cc
+test-tzmapdata-locations
diff --git a/widgets/tests/tzmapdata/Makefile.am b/widgets/tests/tzmapdata/Makefile.am
index 2f05d28..f19e8a0 100644
--- a/widgets/tests/tzmapdata/Makefile.am
+++ b/widgets/tests/tzmapdata/Makefile.am
@@ -21,7 +21,7 @@
 WIDGETSDATA = '"$(datadir)/anaconda"'
 TZMAPDATA='"tzmapdata"'
 
-check_PROGRAMS = test-tzmapdata-cc
+check_PROGRAMS = test-tzmapdata-cc test-tzmapdata-locations
 
 test_tzmapdata_cc_SOURCES = test-tzmapdata-cc.c $(top_srcdir)/src/tz.c
 test_tzmapdata_cc_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
@@ -29,5 +29,11 @@ test_tzmapdata_cc_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
 			   -DTZMAP_DATADIR=$(TZMAPDATA)
 test_tzmapdata_cc_LDADD = $(GTK_LIBS) -lm
 
+test_tzmapdata_locations_SOURCES = test-tzmapdata-locations.c $(top_srcdir)/src/tz.c
+test_tzmapdata_locations_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
+				  -DWIDGETS_DATADIR=$(WIDGETSDATA) \
+				  -DTZMAP_DATADIR=$(TZMAPDATA)
+test_tzmapdata_locations_LDADD = $(GTK_LIBS) -lm
+
 AM_TESTS_ENVIRONMENT = ANACONDA_WIDGETS_DATA=$(top_srcdir)/data; export ANACONDA_WIDGETS_DATA;
 TESTS = test-tzmapdata-cc
diff --git a/widgets/tests/tzmapdata/test-tzmapdata-locations.c b/widgets/tests/tzmapdata/test-tzmapdata-locations.c
new file mode 100644
index 0000000..ac079ef
--- /dev/null
+++ b/widgets/tests/tzmapdata/test-tzmapdata-locations.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2013 Red Hat, Inc
+ *
+ * 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.
+ *
+ * Author: David Shea <dshea at redhat.com>
+ *
+ */
+
+/*
+ * This test ensures that every UTC offset defined in TimezoneMap.c has
+ * at least one location defined for it.
+ */
+
+/* Include the TimezoneMap file so we can use the color_codes array */
+#include "TimezoneMap.c"
+
+#include "tz.h"
+
+int main(void)
+{
+    TzDB *tzdb;
+    const GPtrArray *array;
+    gboolean found_location;
+    int i, j;
+    int status = 0;
+
+    tzdb = tz_load_db();
+    array = tz_get_locations(tzdb);
+
+    /* Walk through color codes and try to find a matching location */
+    for (i = 0; color_codes[i].offset != -100; i++)
+    {
+        found_location = FALSE;
+        for (j = 0; j < array->len; j++)
+        {
+            TzLocation *loc = array->pdata[j];
+            TzInfo *info = tz_info_from_location(loc);
+
+            if (tz_offset_to_double(tz_location_get_utc_offset(loc), info->daylight) ==
+                    color_codes[i].offset)
+            {
+                found_location = TRUE;
+                break;
+            }
+        }
+
+        if (!found_location)
+        {
+            printf("No locations found for offset %d\n", color_codes[i].offset);
+            status = 1;
+        }
+    }
+    tz_db_free(tzdb);
+
+    return status;
+}
-- 
1.8.3.1



More information about the anaconda-patches mailing list