summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-02-23 20:18:49 +0100
committerWerner Koch <wk@gnupg.org>2013-02-23 20:18:49 +0100
commite6943de88627c6662fba3fe905c8761dbf0ccfa1 (patch)
treeca32f43f64134265645e6db68421734ef26ce491 /tests
parentb78200135ce1d20fb4680174eed2106d6012dc14 (diff)
downloadlibgpg-error-e6943de88627c6662fba3fe905c8761dbf0ccfa1.tar.gz
Add version macros and check function.
* configure.ac (VERSION_NUMBER): New ac_subst. (BUILD_FILEVERSION): Build on all platforms (BUILD_TIMESTAMP): Try to use an ISO string. * src/Makefile.am (extra-h.in): Add new version numbers. * src/versioninfo.rc.in: Update copyright year. * src/version.c: New. (gpg_error_check_version): New API. * src/gpg-error.h.in: Add gpg_error_check_version prototype. * src/gpg-error.def.in: Add gpg_error_check_version * tests/t-version.c: New. * tests/Makefile.am (TESTS): Add t-version.c * src/gpg-error-config.in: s/VERSION/PACKAGE_VERSION/. -- All other GnuPG libraries do this, thus we do it here as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am12
-rw-r--r--tests/t-version.c98
2 files changed, 104 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index be63260..1a27f81 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,18 +1,18 @@
# Makefile.am for libgpg-error/tests.
# Copyright (C) 2003 g10 Code GmbH
-#
+#
# This file is part of libgpg-error.
-#
+#
# libgpg-error 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.1 of the
# License, or (at your option) any later version.
-#
+#
# libgpg-error 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 program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
@@ -22,11 +22,11 @@
if HAVE_W32CE_SYSTEM
extra_includes = -idirafter $(top_builddir)/src/gpg-extra
else
-extra_includes =
+extra_includes =
endif
-TESTS = t-strerror t-syserror
+TESTS = t-version t-strerror t-syserror
INCLUDES = -I$(top_builddir)/src $(extra_includes)
diff --git a/tests/t-version.c b/tests/t-version.c
new file mode 100644
index 0000000..d6c6399
--- /dev/null
+++ b/tests/t-version.c
@@ -0,0 +1,98 @@
+/* t-version.c - Check the version info function
+ * Copyright (C) 2013 g10 Code GmbH
+ *
+ * This file is part of libgpg-error.
+ *
+ * libgpg-error 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * libgpg-error 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 program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "../src/gpg-error.h"
+
+static const char *logpfx = "";
+static int verbose;
+static int debug;
+static int errorcount;
+
+int
+main (int argc, char **argv)
+{
+ int last_argc = -1;
+
+ if (argc)
+ {
+ logpfx = *argv;
+ argc--; argv++;
+ }
+ while (argc && last_argc != argc )
+ {
+ last_argc = argc;
+ if (!strcmp (*argv, "--help"))
+ {
+ puts (
+"usage: ./version [options]\n"
+"\n"
+"Options:\n"
+" --verbose Show what is going on\n"
+);
+ exit (0);
+ }
+ if (!strcmp (*argv, "--verbose"))
+ {
+ verbose = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--debug"))
+ {
+ verbose = debug = 1;
+ argc--; argv++;
+ }
+ }
+
+ if (!gpg_error_check_version (GPG_ERROR_VERSION))
+ {
+ fprintf (stderr, "%s: gpg_error_check_version returned an error\n",
+ logpfx);
+ errorcount++;
+ }
+ if (!gpg_error_check_version ("1.10"))
+ {
+ fprintf (stderr, "%s: gpg_error_check_version returned an "
+ "error for an old version\n", logpfx);
+ errorcount++;
+ }
+ if (gpg_error_check_version ("15"))
+ {
+ fprintf (stderr, "gpg_error_check_version did not return an error"
+ " for a newer version\n", logpfx);
+ errorcount++;
+ }
+ if (verbose || errorcount)
+ {
+ printf ("Version from header: %s (0x%06x)\n",
+ GPG_ERROR_VERSION, GPG_ERROR_VERSION_NUMBER);
+ printf ("Version from binary: %s\n", gpg_error_check_version (NULL));
+ printf ("Copyright blurb ...:%s\n", gpg_error_check_version ("\x01\x01"));
+ }
+
+ return errorcount ? 1 : 0;
+}