Blob Blame History Raw
From ab31d932b5d1b433dc091d688dadf0211f341a9e Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Fri, 24 Jun 2016 13:45:46 -0400
Subject: [PATCH 07/24] Make the test program more automake-y

Add a $DATADIR environment variable to allow test-timezone to be more
easily run from automake without arguments. Use the various check_* and
TEST variables to define and run the test program.
---
 src/Makefile.am     | 21 ++++++++++++++-------
 src/test-timezone.c | 16 ++++++++++++++--
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 9386d1d..9711706 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,15 +24,22 @@ AM_CPPFLAGS =						\
 
 noinst_PROGRAMS = test-timezone
 
-test_timezone_SOURCES = test-timezone.c cc-timezone-location.c tz.c tz.h
-test_timezone_LDADD = $(LIBTIMEZONEMAP_LIBS) -lm
+
+all-local: check
+
+AM_TESTS_ENVIRONMENT = TZ_DATA_FILE=$(srcdir)/data/cities15000.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
+
+test_timezone_SOURCES = test-timezone.c
+test_timezone_LDADD = $(LIBTIMEZONEMAP_LIBS) -lm libtimezonemap.la
 test_timezone_CFLAGS = $(LIBTIMEZONEMAP_CFLAGS)
 
-all-local: check-local
-
-check-local: test-timezone
-	TZ_DATA_FILE=$(srcdir)/data/cities15000.txt ADMIN1_FILE=$(srcdir)/data/admin1Codes.txt COUNTRY_FILE=$(srcdir)/data/countryInfo.txt \
-				 $(builddir)/test-timezone $(srcdir)/data
+TESTS = test-timezone
 
 lib_LTLIBRARIES = libtimezonemap.la
 
diff --git a/src/test-timezone.c b/src/test-timezone.c
index 504deb9..692c240 100644
--- a/src/test-timezone.c
+++ b/src/test-timezone.c
@@ -15,13 +15,25 @@ int main (int argc, char **argv)
     RsvgHandle *svg;
     gchar *path;
 
-        setlocale (LC_ALL, "");
+    setlocale (LC_ALL, "");
 
     if (argc == 2) 
       {
         pixmap_dir = g_strdup (argv[1]);
       } else if (argc == 1) {
-        pixmap_dir = g_strdup ("data/");
+        const char *datadir = g_getenv("DATADIR");
+        if (datadir != NULL)
+          { 
+            pixmap_dir = g_strdup (datadir);
+          } else {
+            pixmap_dir = g_strdup ("./data");
+          }
+
+        if (! g_file_test (pixmap_dir, G_FILE_TEST_IS_DIR))
+          {
+            g_message("Pixmap directory %s does not exist", pixmap_dir);
+            return 1;
+          }
       } else {
         g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
         return 1;
-- 
2.5.5