summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2020-02-14 11:42:26 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2020-02-15 02:56:38 +0100
commit94c0fdb0e15b1309ab3de81de8da5d7ca3912ca4 (patch)
tree56443502f10a0c665eab836b4f4a9fb2e11ade4f /tests
parentd15f0d7167618df0b431af5e8c33cc18046fa799 (diff)
downloadlibgphoto2-94c0fdb0e15b1309ab3de81de8da5d7ca3912ca4.tar.gz
Add print-libgphoto2-version program
The new print-libgphoto2-version program prints the complete libgphoto2 version message in both short and verbose. This functionality had not been available before, and we want it for checking later changes to the camlib list part of the version messages.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/print-libgphoto2-version.c150
2 files changed, 161 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..f425e6c72
--- /dev/null
+++ b/tests/print-libgphoto2-version.c
@@ -0,0 +1,150 @@
+/* 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-libgphoto2-version"
+
+
+#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_verbose()"); }
+ 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);
+ printf("\n");
+ print_version_verbose(stdout, NULL, "\n", NULL, NULL);
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * c-file-style:"linux"
+ * indent-tabs-mode:t
+ * End:
+ */