summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2020-01-21 00:56:12 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2020-01-21 01:12:20 +0100
commitffdc4a4dcc9d1a015dcf0005564add04d3b6f284 (patch)
treea74ece35c2bc34f3e5939cc08d12d12e059d9b96
parentfbf389c8e71b45d6a2cdab1d51062f28524cafbd (diff)
downloadlibgphoto2-ffdc4a4dcc9d1a015dcf0005564add04d3b6f284.tar.gz
test program to print verbose version message
To help with fixing issue 467, add a new program tests/print-libgphoto2-version.c to print both the short and verbose version messages.
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/print-libgphoto2-version.c149
2 files changed, 160 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc8512e3c..8e2ef92fe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,6 +34,17 @@ test_endian_LDADD = \
$(LIBEXIF_LIBS) \
$(INTLLIBS)
+
+noinst_PROGRAMS += print-libgphoto2-version
+print_libgphoto2_version_SOURCE = print-libgphoto2-version.c
+print_libgphoto2_version_LDADD =
+print_libgphoto2_version_LDADD += $(top_builddir)/libgphoto2/libgphoto2.la
+print_libgphoto2_version_LDADD += $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
+print_libgphoto2_version_LDADD += $(LIBLTDL)
+print_libgphoto2_version_LDADD += $(LIBEXIF_LIBS)
+print_libgphoto2_version_LDADD += $(INTLLIBS)
+
+
noinst_PROGRAMS += test-gphoto2
test_gphoto2_SOURCE = test-gphoto2.c
test_gphoto2_LDADD = \
diff --git a/tests/print-libgphoto2-version.c b/tests/print-libgphoto2-version.c
new file mode 100644
index 000000000..b5a1d8764
--- /dev/null
+++ b/tests/print-libgphoto2-version.c
@@ -0,0 +1,149 @@
+/* print-libgphoto2-version.c - print libgphoto2 library version
+ *
+ * Copyright 2002,2005 Hans Ulrich Niedermann <hun@users.sourceforge.net>
+ * Portions Copyright 2002 Lutz Mueller <lutz@users.sourceforge.net>
+ * Portions Copyright 2005 Julien BLACHE <jblache@debian.org>
+ * Portions Copyright 2020 Hans Ulrich Niedermann <hun@n-dimensional.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ *
+ * This has been mostly copied from the file
+ *
+ * packaging/generic/print-camera-list.c
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gphoto2/gphoto2-version.h"
+
+
+/* Not sure whether this is the best possible name */
+#define ARGV0 "print-camera-list"
+
+
+#define FATAL(msg...) \
+ do { \
+ fprintf(stderr, ARGV0 ": Fatal: " msg); \
+ fprintf(stderr, "\n"); \
+ exit(13); \
+ } while (0)
+
+
+typedef struct {
+ char *name;
+ GPVersionFunc version_func;
+} module_version;
+
+
+const module_version module_versions[] = {
+ { "libgphoto2", gp_library_version },
+ { "libgphoto2_port", gp_port_library_version },
+ { NULL, NULL }
+};
+
+
+/* print_version_comment
+ * Print comment to output containing information on library versions
+ *
+ * out the file to write the comment to
+ * startline printed at the start of each line, e.g. "# " or " | "
+ * endline printed as the end of each line, e.g. "\n" or "\n"
+ * firstline printed before first line, e.g. NULL or "<!--+\n"
+ * lastline printed after last line, e.g. "\n" or " +-->\n"
+ */
+
+static void
+print_version_comment(FILE *out,
+ const char *startline, const char *endline,
+ const char *firstline, const char *lastline)
+{
+ unsigned int n;
+ if (out == NULL) { FATAL("Internal error: NULL out in print_version_comment()"); }
+ if (firstline != NULL) { fputs(firstline, out); }
+ if (startline != NULL) { fputs(startline, out); }
+ fputs("Short runtime version information on the libgphoto2 build:", out);
+ if (endline != NULL) { fputs(endline, out); }
+ for (n=0; (module_versions[n].name != NULL) && (module_versions[n].version_func != NULL); n++) {
+ const char *name = module_versions[n].name;
+ GPVersionFunc func = module_versions[n].version_func;
+ const char **v = func(GP_VERSION_SHORT);
+ unsigned int i;
+ if (!v) { continue; }
+ if (!v[0]) { continue; }
+ if (startline != NULL) { fputs(startline, out); }
+ fputs(" ", out);
+ fprintf(out,"%-15s %-14s ", name, v[0]);
+ for (i=1; v[i] != NULL; i++) {
+ fputs(v[i], out);
+ if (v[i+1] != NULL) {
+ fputs(", ", out);
+ }
+ }
+ if (endline != NULL) { fputs(endline, out); }
+ }
+ if (lastline != NULL) { fputs(lastline, out); }
+}
+
+
+static void
+print_version_verbose(FILE *out,
+ const char *startline, const char *endline,
+ const char *firstline, const char *lastline)
+{
+ unsigned int n;
+ if (out == NULL) { FATAL("Internal error: NULL out in print_version_comment()"); }
+ if (firstline != NULL) { fputs(firstline, out); }
+ if (startline != NULL) { fputs(startline, out); }
+ fputs("Verbose runtime version information on the libgphoto2 build:", out);
+ if (endline != NULL) { fputs(endline, out); }
+ for (n=0; (module_versions[n].name != NULL) && (module_versions[n].version_func != NULL); n++) {
+ const char *name = module_versions[n].name;
+ GPVersionFunc func = module_versions[n].version_func;
+ const char **v = func(GP_VERSION_VERBOSE);
+ unsigned int i;
+ if (!v) { continue; }
+ if (!v[0]) { continue; }
+ if (startline != NULL) { fputs(startline, out); }
+ fputs(" * ", out);
+ fprintf(out,"%s %s", name, v[0]);
+ if (endline != NULL) { fputs(endline, out); }
+ for (i=1; v[i] != NULL; i++) {
+ fprintf(out, " * %s", v[i]);
+ if (endline != NULL) { fputs(endline, out); }
+ }
+ }
+ if (lastline != NULL) { fputs(lastline, out); }
+}
+
+
+int main()
+{
+ print_version_comment(stdout, NULL, "\n", NULL, NULL);
+ print_version_verbose(stdout, NULL, "\n", NULL, NULL);
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * c-file-style:"linux"
+ * indent-tabs-mode:t
+ * End:
+ */