[PATCH 4/9] Added a test for the prescence of the timezone images.
David Shea
dshea at redhat.com
Wed Nov 6 22:56:54 UTC 2013
Ensure that each timezone offset defined in TimezoneMap.c has a matching
image in the tzmapdata data directory.
---
widgets/tests/tzmapdata/.gitignore | 1 +
widgets/tests/tzmapdata/Makefile.am | 11 ++-
.../tests/tzmapdata/test-tzmapdata-backgrounds.c | 102 +++++++++++++++++++++
3 files changed, 112 insertions(+), 2 deletions(-)
create mode 100644 widgets/tests/tzmapdata/test-tzmapdata-backgrounds.c
diff --git a/widgets/tests/tzmapdata/.gitignore b/widgets/tests/tzmapdata/.gitignore
index 3be8047..f982879 100644
--- a/widgets/tests/tzmapdata/.gitignore
+++ b/widgets/tests/tzmapdata/.gitignore
@@ -1,2 +1,3 @@
test-tzmapdata-cc
test-tzmapdata-locations
+test-tzmapdata-backgrounds
diff --git a/widgets/tests/tzmapdata/Makefile.am b/widgets/tests/tzmapdata/Makefile.am
index f19e8a0..1a924fe 100644
--- a/widgets/tests/tzmapdata/Makefile.am
+++ b/widgets/tests/tzmapdata/Makefile.am
@@ -21,7 +21,8 @@
WIDGETSDATA = '"$(datadir)/anaconda"'
TZMAPDATA='"tzmapdata"'
-check_PROGRAMS = test-tzmapdata-cc test-tzmapdata-locations
+check_PROGRAMS = test-tzmapdata-cc test-tzmapdata-locations \
+ test-tzmapdata-backgrounds
test_tzmapdata_cc_SOURCES = test-tzmapdata-cc.c $(top_srcdir)/src/tz.c
test_tzmapdata_cc_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
@@ -35,5 +36,11 @@ test_tzmapdata_locations_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
-DTZMAP_DATADIR=$(TZMAPDATA)
test_tzmapdata_locations_LDADD = $(GTK_LIBS) -lm
+test_tzmapdata_backgrounds_SOURCES = test-tzmapdata-backgrounds.c $(top_srcdir)/src/tz.c
+test_tzmapdata_backgrounds_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src \
+ -DWIDGETS_DATADIR=$(WIDGETSDATA) \
+ -DTZMAP_DATADIR=$(TZMAPDATA)
+test_tzmapdata_backgrounds_LDADD = $(GTK_LIBS) -lm
+
AM_TESTS_ENVIRONMENT = ANACONDA_WIDGETS_DATA=$(top_srcdir)/data; export ANACONDA_WIDGETS_DATA;
-TESTS = test-tzmapdata-cc
+TESTS = test-tzmapdata-cc test-tzmapdata-backgrounds
diff --git a/widgets/tests/tzmapdata/test-tzmapdata-backgrounds.c b/widgets/tests/tzmapdata/test-tzmapdata-backgrounds.c
new file mode 100644
index 0000000..7d4c650
--- /dev/null
+++ b/widgets/tests/tzmapdata/test-tzmapdata-backgrounds.c
@@ -0,0 +1,102 @@
+/* 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 a
+ * matching background image in the tzmapdata directory.
+ */
+
+/* Include the TimezoneMap file so we can use the color_codes array */
+#include "TimezoneMap.c"
+
+#include <string.h>
+#include <stdlib.h>
+#include <glob.h>
+#include <libgen.h>
+
+int main(void)
+{
+ gchar *file;
+ char buf[16];
+ int i, j;
+ glob_t globbuf;
+ int status = 0;
+
+ /* Check that every entry in color_codes has a highlight image */
+ printf("Checking for timezone images...\n");
+ for (i = 0; color_codes[i].offset != -100; i++)
+ {
+ file = g_strdup_printf("%s/" TZMAP_DATADIR "/timezone_%s.png",
+ get_widgets_datadir(),
+ g_ascii_formatd(buf, sizeof(buf),
+ "%g", color_codes[i].offset));
+ if (!g_file_test(file, G_FILE_TEST_EXISTS))
+ {
+ printf("Unable to find file %s\n", file);
+ status = 1;
+ }
+ g_free(file);
+ }
+
+ /* Now check that every highlight image has a color code */
+ printf("Checking for color codes for timezone images...\n");
+ file = g_strdup_printf("%s/" TZMAP_DATADIR "/timezone_*.png",
+ get_widgets_datadir());
+ if (glob(file, GLOB_NOSORT, NULL, &globbuf) != 0)
+ {
+ fprintf(stderr, "Unable to find timezone files\n");
+ exit(99); /* hard error */
+ }
+ for (i = 0; i < globbuf.gl_pathc; i++)
+ {
+ double tz_offset;
+ char *end;
+ gboolean color_code_found = FALSE;
+
+ /* Cut off the directory name and the .png */
+ globbuf.gl_pathv[i] = basename(globbuf.gl_pathv[i]);
+ globbuf.gl_pathv[i][strlen(globbuf.gl_pathv[i]) - 4] = '\0';
+
+ tz_offset = strtod(globbuf.gl_pathv[i] + sizeof("timezone_") - 1, &end);
+ if (*end != '\0')
+ {
+ printf("Bad filename: %s.png\n", globbuf.gl_pathv[i]);
+ status = 1;
+ continue;
+ }
+
+ for (j = 0; color_codes[j].offset != -100; j++)
+ {
+ if (color_codes[j].offset == tz_offset)
+ {
+ color_code_found = TRUE;
+ break;
+ }
+ }
+
+ if (!color_code_found)
+ {
+ printf("No color code found for offset %g\n", tz_offset);
+ status = 1;
+ }
+ }
+
+ return status;
+}
--
1.8.3.1
More information about the anaconda-patches
mailing list