[gexiv2] Add gexiv2-dump utility to test/ directory



commit 7d687ba1a6eb2cb0281605fdac539e594353b92d
Author: Jim Nelson <jim yorba org>
Date:   Tue Feb 4 14:49:25 2014 -0800

    Add gexiv2-dump utility to test/ directory
    
    gexiv2 lacks any command-line utilities, tools, or tests, so this
    is a first stab at providing some.  gexiv2-dump will simply dump
    the entire Exiv2 tag list and their interpreted values to stdout.

 .gitignore            |    1 +
 Makefile.am           |   14 +++++++++++++-
 configure.ac          |   30 ++++++++++++++++++++++++++++++
 test/gexiv2-dump.vala |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c823b6d..281b25e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ gexiv2/gexiv2-version.h
 /GExiv2-0.4.gir
 /GExiv2-0.4.typelib
 vapi/gexiv2.gi
+test/gexiv2-dump
 
 # Autotools files.
 Makefile.in
diff --git a/Makefile.am b/Makefile.am
index a565aed..1cc4a0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,7 +80,7 @@ if WORD_64
 REQUIRED_CXXFLAGS += -fPIC -DPIC
 endif
 
-CXXFLAGS += $(REQUIRED_CXXFLAGS)
+AM_CXXFLAGS = $(REQUIRED_CXXFLAGS)
 
 $(GEXIV2_sources): gexiv2/gexiv2-version.h
 
@@ -97,6 +97,7 @@ lib PACKAGE_NAME@_la_LDFLAGS  = \
 clean-local:
        rm -f gexiv2/gexiv2-version.h
        rm -f gexiv2.pc
+       rm -f test/gexiv2-dump
 
 # Vala #
 
@@ -114,6 +115,17 @@ vapi/@PACKAGE_NAME  gi:
 
 endif
 
+# Tests and utilities #
+
+if ENABLE_TESTS
+
+tests: test/gexiv2-dump
+
+test/gexiv2-dump: test/gexiv2-dump.vala
+       valac -g --enable-checking --vapidir=. --pkg gexiv2 $< -o $@
+
+endif
+
 # Optional Introspection #
 
 if ENABLE_INTROSPECTION
diff --git a/configure.ac b/configure.ac
index 4c50f41..aca5f56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,6 +6,7 @@ AC_CONFIG_MACRO_DIR([m4])
 # Will install auxiliary build tools (depcomp, install-sh, missing...) under build-aux/
 AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([1.11 -Wall no-define foreign dist-xz tar-ustar])
+AM_PROG_AR
 LT_PREREQ([2.2])
 LT_INIT([disable-static win32-dll])
 
@@ -162,6 +163,29 @@ AM_CONDITIONAL(ENABLE_VALA, test "x$enable_vala" = "xyes")
 AC_MSG_CHECKING([enable vala])
 AC_MSG_RESULT([$enable_vala])
 
+#######################
+# Tests and utilities #
+#######################
+
+AC_ARG_ENABLE(tests, [  --enable-tests         enable tests and utilities (requires Vala) [[default=no]]],
+              if eval "test x$enable_tests = xno"; then
+              enable_tests=no
+              else
+              enable_tests=yes
+              fi,
+              enable_tests=no)
+
+if test "x$enable_tests" != "xno"; then
+    AC_CHECK_TOOL([VALAC], [valac], [:])
+    if test "x$VALAC" = "x:"; then
+        enable_tests="no (missing valac)"
+    fi
+fi
+AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" = "xyes")
+
+AC_MSG_CHECKING([enable tests])
+AC_MSG_RESULT([$enable_tests])
+
 ###################
 # Check Word Size #
 ###################
@@ -241,6 +265,7 @@ Options:
     Introspection:      $enable_introspection
     Python2 binding:    $enable_python2
     Python3 binding:    $enable_python3
+    Tests and utils:    $enable_tests
 ])
 
 if test "x$enable_vala" = "xyes"; then
@@ -249,3 +274,8 @@ NOTE: the Vala binding can only be built and installed after the C API.
 After installing with "make install", run "make vapi" to build the bindings and "make install-vapi" to 
install them.
 ])
 fi
+
+if test "x$enable_tests" = "xyes"; then
+AC_MSG_RESULT([To build tests and utiliies, run "make tests".])
+fi
+
diff --git a/test/gexiv2-dump.vala b/test/gexiv2-dump.vala
new file mode 100644
index 0000000..7bf6ef3
--- /dev/null
+++ b/test/gexiv2-dump.vala
@@ -0,0 +1,47 @@
+/*
+ * gexiv2-dump.vala
+ *
+ * Author(s)
+ *  Jim Nelson <jim yorba org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+int main(string[] args) {
+    if (args.length < 2 || ("--help" in args) || ("-h" in args)) {
+        usage();
+        
+        return 1;
+    }
+    
+    // skip args[0]
+    foreach (string filename in args[1:args.length]) {
+        try {
+            GExiv2.Metadata metadata = new GExiv2.Metadata();
+            metadata.open_path(filename);
+            
+            dump_tags(metadata, metadata.get_exif_tags());
+            dump_tags(metadata, metadata.get_iptc_tags());
+            dump_tags(metadata, metadata.get_xmp_tags());
+        } catch (Error err) {
+            stderr.printf("Unable to dump metadata for %s: %s\n", filename, err.message);
+        }
+    }
+    
+    return 0;
+}
+
+void usage() {
+    stdout.printf("usage: gexiv2-dump FILE...\n\n");
+}
+
+void dump_tags(GExiv2.Metadata metadata, string[] tags) throws Error {
+    foreach (string tag in tags) {
+        stdout.printf("%s%*s%s\n",
+            tag,
+            (64 - tag.length).clamp(1, 64), "",
+            metadata.get_tag_interpreted_string(tag)
+        );
+    }
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]