diff options
Diffstat (limited to 'tests/t-version.c')
-rw-r--r-- | tests/t-version.c | 93 |
1 files changed, 86 insertions, 7 deletions
diff --git a/tests/t-version.c b/tests/t-version.c index 4606dbc..240d4b4 100644 --- a/tests/t-version.c +++ b/tests/t-version.c @@ -26,12 +26,90 @@ #include <string.h> #include <assert.h> -#include "../src/gpg-error.h" +#define PGM "t-version" +#include "t-common.h" + +static const char *logpfx = PGM; + + +static void +t_gpgrt_cmp_version (void) +{ + struct { int result; int level; const char *a; const char *b; } t[] = { + { 0, 1, "0", "0" }, + { -1, 1, "0", "1" }, + { 1, 1, "1", "0" }, + { -1, 1, "0.0", "0.1" }, + { -1, 1, "0.1", "1.2" }, + { 1, 1, "1.0", "0.9" }, + { -1, 1, "-1.0", "0.9" }, /* A is invalid */ + { 0, 1, "0rc0", "0rc0" }, + { 1, 1, "0rc1", "0rc0" }, + { -1, 1, "0rc1", "0rc2" }, + { 0, 1, "0.rc0", "0.rc0" }, + { 1, 1, "0.rc1", "0.rc0" }, + { -1, 1, "0.rc1", "0.rc2" }, + { 0, 1, "0.rc1", "0.rc1" }, + { -1, 1, "0qc1", "0rc0" }, + { -1, 1, "0.qc1", "0.rc0" }, + { 0, 2, "0.0", "0.0" }, + { -1, 2, "0.1", "0.2" }, + { -1, 2, "3.1", "3.2" }, + { -1, 2, "3.1", "4.0" }, + { 0, 2, "1.1rc0", "1.1rc0" }, + { 1, 2, "1.1rc1", "1.1rc0" }, + { -1, 2, "1.1rc0", "1.1rc1" }, + { 0, 3, "7.0.0", "7.0.0" }, + { -1, 3, "7.0.1", "7.0.2" }, + { -1, 3, "7.3.1", "7.3.2" }, + { -1, 3, "7.3.1", "7.4.0" }, + { 0, 3, "7.1.1rc0", "7.1.1rc0" }, + { 1, 3, "7.1.1rc1", "7.1.1rc0" }, + { -1, 3, "7.1.1rc0", "7.1.1rc1" }, + { 1, 3, "6.0.0", "5.0.0" }, + { 0, 3, "6.0.0", "6.0.0" }, + { 1, 3, "6.0.1", "6.0.0" }, + { 1, 3, "6.1.0", "6.0.0" }, + { 1, 3, "6.2.1", "6.2.0" }, + { -1, 3, "6.2.1", "6.2.2" }, + { -1, 3, "6.0.0", "6.0.2" }, + { -1, 3, "6.0.0", "6.1.0" }, + { -1, 3, "6.2.0", "6.2.1" }, + { 1, 3, "6.0.0-beta1", "6.0.0-beta0" }, + { 0, 3, "6.0.0-beta2", "6.0.0-beta2" }, + { 1, 3, "6.0.0-beta20", "6.0.0-beta19" }, + { -1, 3, "6.0.0-beta1", "6.0.0-beta2" }, + { 1, 3, "6.0.0-beta2", "6.0.0-beta1" }, + { -1, 3, "6.0.0-beta20", "6.0.0-beta21" }, + { 0,13, "6.0.0-beta1", "6.0.0-beta0" }, + { 0,13, "6.0.0-beta2", "6.0.0-beta2" }, + { 0,13, "6.0.0-beta20", "6.0.0-beta19" }, + { 0,13, "6.0.0-beta1", "6.0.0-beta2" }, + { 0,13, "6.0.0-beta2", "6.0.0-beta1" }, + { 0,13, "6.0.0-beta20", "6.0.0-beta21" } + }; + int i; + int result, expected; + + for (i=0; i < DIM (t); i++) + { + expected = t[i].result; + result = gpgrt_cmp_version (t[i].a, t[i].b, t[i].level); + if (result != expected) + fail ("test %d failed: cmp('%s','%s',%d) = %d expected %d", + i, t[i].a, t[i].b, t[i].level, result, expected); + } + for (i=0; i < DIM (t); i++) + { + expected = 0 - t[i].result; + result = gpgrt_cmp_version (t[i].a, t[i].b, -t[i].level); + if (result != expected) + fail ("test %d-rev failed: cmp('%s','%s',%d) = %d expected %d", + i, t[i].a, t[i].b, -t[i].level, result, expected); + } +} + -static const char *logpfx = ""; -static int verbose; -static int debug; -static int errorcount; int main (int argc, char **argv) @@ -40,7 +118,6 @@ main (int argc, char **argv) if (argc) { - logpfx = *argv; argc--; argv++; } while (argc && last_argc != argc ) @@ -68,6 +145,8 @@ main (int argc, char **argv) } } + t_gpgrt_cmp_version (); + if (!gpg_error_check_version (GPG_ERROR_VERSION)) { fprintf (stderr, "%s: gpg_error_check_version returned an error\n", @@ -80,7 +159,7 @@ main (int argc, char **argv) "error for an old version\n", logpfx); errorcount++; } - if (gpg_error_check_version ("15")) + if (gpg_error_check_version ("15.0")) { fprintf (stderr, "%s: gpg_error_check_version did not return an error" " for a newer version\n", logpfx); |