| 1 |
/* t-version.c - Check the version info function |
| 2 |
* Copyright (C) 2013 g10 Code GmbH |
| 3 |
* |
| 4 |
* This file is part of libgpg-error. |
| 5 |
* |
| 6 |
* libgpg-error is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2.1 of |
| 9 |
* the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* libgpg-error is distributed in the hope that it will be useful, but |
| 12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifdef HAVE_CONFIG_H |
| 21 |
#include <config.h> |
| 22 |
#endif |
| 23 |
#undef GPG_ERR_ENABLE_GETTEXT_MACROS |
| 24 |
#undef GPGRT_ENABLE_ES_MACROS |
| 25 |
#undef GPGRT_ENABLE_LOG_MACROS |
| 26 |
#undef GPGRT_ENABLE_ARGPARSE_MACROS |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <string.h> |
| 31 |
#include <assert.h> |
| 32 |
|
| 33 |
#define PGM "t-version" |
| 34 |
#include "t-common.h" |
| 35 |
|
| 36 |
static const char *logpfx = PGM; |
| 37 |
|
| 38 |
|
| 39 |
static void |
| 40 |
t_gpgrt_cmp_version (void) |
| 41 |
{ |
| 42 |
struct { int result; int level; const char *a; const char *b; } t[] = { |
| 43 |
{ 0, 1, "0", "0" }, |
| 44 |
{ -1, 1, "0", "1" }, |
| 45 |
{ 1, 1, "1", "0" }, |
| 46 |
{ -1, 1, "0.0", "0.1" }, |
| 47 |
{ -1, 1, "0.1", "1.2" }, |
| 48 |
{ 1, 1, "1.0", "0.9" }, |
| 49 |
{ -1, 1, "-1.0", "0.9" }, /* A is invalid */ |
| 50 |
{ 0, 1, "0rc0", "0rc0" }, |
| 51 |
{ 1, 1, "0rc1", "0rc0" }, |
| 52 |
{ -1, 1, "0rc1", "0rc2" }, |
| 53 |
{ 0, 1, "0.rc0", "0.rc0" }, |
| 54 |
{ 1, 1, "0.rc1", "0.rc0" }, |
| 55 |
{ -1, 1, "0.rc1", "0.rc2" }, |
| 56 |
{ 0, 1, "0.rc1", "0.rc1" }, |
| 57 |
{ -1, 1, "0qc1", "0rc0" }, |
| 58 |
{ -1, 1, "0.qc1", "0.rc0" }, |
| 59 |
{ 0, 2, "0.0", "0.0" }, |
| 60 |
{ -1, 2, "0.1", "0.2" }, |
| 61 |
{ -1, 2, "3.1", "3.2" }, |
| 62 |
{ -1, 2, "3.1", "4.0" }, |
| 63 |
{ 0, 2, "1.1rc0", "1.1rc0" }, |
| 64 |
{ 1, 2, "1.1rc1", "1.1rc0" }, |
| 65 |
{ -1, 2, "1.1rc0", "1.1rc1" }, |
| 66 |
{ 0, 3, "7.0.0", "7.0.0" }, |
| 67 |
{ -1, 3, "7.0.1", "7.0.2" }, |
| 68 |
{ -1, 3, "7.3.1", "7.3.2" }, |
| 69 |
{ -1, 3, "7.3.1", "7.4.0" }, |
| 70 |
{ 0, 3, "7.1.1rc0", "7.1.1rc0" }, |
| 71 |
{ 1, 3, "7.1.1rc1", "7.1.1rc0" }, |
| 72 |
{ -1, 3, "7.1.1rc0", "7.1.1rc1" }, |
| 73 |
{ 1, 3, "6.0.0", "5.0.0" }, |
| 74 |
{ 0, 3, "6.0.0", "6.0.0" }, |
| 75 |
{ 1, 3, "6.0.1", "6.0.0" }, |
| 76 |
{ 1, 3, "6.1.0", "6.0.0" }, |
| 77 |
{ 1, 3, "6.2.1", "6.2.0" }, |
| 78 |
{ -1, 3, "6.2.1", "6.2.2" }, |
| 79 |
{ -1, 3, "6.0.0", "6.0.2" }, |
| 80 |
{ -1, 3, "6.0.0", "6.1.0" }, |
| 81 |
{ -1, 3, "6.2.0", "6.2.1" }, |
| 82 |
{ 1, 3, "6.0.0-beta1", "6.0.0-beta0" }, |
| 83 |
{ 0, 3, "6.0.0-beta2", "6.0.0-beta2" }, |
| 84 |
{ 1, 3, "6.0.0-beta20", "6.0.0-beta19" }, |
| 85 |
{ -1, 3, "6.0.0-beta1", "6.0.0-beta2" }, |
| 86 |
{ 1, 3, "6.0.0-beta2", "6.0.0-beta1" }, |
| 87 |
{ -1, 3, "6.0.0-beta20", "6.0.0-beta21" }, |
| 88 |
{ 0,13, "6.0.0-beta1", "6.0.0-beta0" }, |
| 89 |
{ 0,13, "6.0.0-beta2", "6.0.0-beta2" }, |
| 90 |
{ 0,13, "6.0.0-beta20", "6.0.0-beta19" }, |
| 91 |
{ 0,13, "6.0.0-beta1", "6.0.0-beta2" }, |
| 92 |
{ 0,13, "6.0.0-beta2", "6.0.0-beta1" }, |
| 93 |
{ 0,13, "6.0.0-beta20", "6.0.0-beta21" } |
| 94 |
}; |
| 95 |
int i; |
| 96 |
int result, expected; |
| 97 |
|
| 98 |
for (i=0; i < DIM (t); i++) |
| 99 |
{ |
| 100 |
expected = t[i].result; |
| 101 |
result = gpgrt_cmp_version (t[i].a, t[i].b, t[i].level); |
| 102 |
if (result != expected) |
| 103 |
fail ("test %d failed: cmp('%s','%s',%d) = %d expected %d", |
| 104 |
i, t[i].a, t[i].b, t[i].level, result, expected); |
| 105 |
} |
| 106 |
for (i=0; i < DIM (t); i++) |
| 107 |
{ |
| 108 |
expected = 0 - t[i].result; |
| 109 |
result = gpgrt_cmp_version (t[i].a, t[i].b, -t[i].level); |
| 110 |
if (result != expected) |
| 111 |
fail ("test %d-rev failed: cmp('%s','%s',%d) = %d expected %d", |
| 112 |
i, t[i].a, t[i].b, -t[i].level, result, expected); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
int |
| 119 |
main (int argc, char **argv) |
| 120 |
{ |
| 121 |
int last_argc = -1; |
| 122 |
|
| 123 |
if (argc) |
| 124 |
{ |
| 125 |
argc--; argv++; |
| 126 |
} |
| 127 |
while (argc && last_argc != argc ) |
| 128 |
{ |
| 129 |
last_argc = argc; |
| 130 |
if (!strcmp (*argv, "--help")) |
| 131 |
{ |
| 132 |
puts ( |
| 133 |
"usage: ./version [options]\n" |
| 134 |
"\n" |
| 135 |
"Options:\n" |
| 136 |
" --verbose Show what is going on\n" |
| 137 |
); |
| 138 |
exit (0); |
| 139 |
} |
| 140 |
if (!strcmp (*argv, "--verbose")) |
| 141 |
{ |
| 142 |
verbose = 1; |
| 143 |
argc--; argv++; |
| 144 |
} |
| 145 |
else if (!strcmp (*argv, "--debug")) |
| 146 |
{ |
| 147 |
verbose = debug = 1; |
| 148 |
argc--; argv++; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
t_gpgrt_cmp_version (); |
| 153 |
|
| 154 |
if (!gpg_error_check_version (GPG_ERROR_VERSION)) |
| 155 |
{ |
| 156 |
fprintf (stderr, "%s: gpg_error_check_version returned an error\n", |
| 157 |
logpfx); |
| 158 |
errorcount++; |
| 159 |
} |
| 160 |
if (!gpg_error_check_version ("1.10")) |
| 161 |
{ |
| 162 |
fprintf (stderr, "%s: gpg_error_check_version returned an " |
| 163 |
"error for an old version\n", logpfx); |
| 164 |
errorcount++; |
| 165 |
} |
| 166 |
if (gpg_error_check_version ("15.0")) |
| 167 |
{ |
| 168 |
fprintf (stderr, "%s: gpg_error_check_version did not return an error" |
| 169 |
" for a newer version\n", logpfx); |
| 170 |
errorcount++; |
| 171 |
show ("\n"); /* Reference this function to silence gcc. */ |
| 172 |
} |
| 173 |
if (verbose || errorcount) |
| 174 |
{ |
| 175 |
printf ("Version from header: %s (0x%06x)\n", |
| 176 |
GPG_ERROR_VERSION, GPG_ERROR_VERSION_NUMBER); |
| 177 |
printf ("Version from binary: %s\n", gpg_error_check_version (NULL)); |
| 178 |
printf ("Copyright blurb ...:%s\n", gpg_error_check_version ("\x01\x01")); |
| 179 |
} |
| 180 |
|
| 181 |
return errorcount ? 1 : 0; |
| 182 |
} |