aboutsummaryrefslogtreecommitdiffstats
path: root/common/t-stringhelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-01-08 07:58:21 +0000
committerWerner Koch <[email protected]>2016-01-08 07:58:21 +0000
commit4d7ac43ff71fdadfd2e04621f74840a82fbe788a (patch)
treeacdc15bbc063cec98d836327a8129ccbf0aaaef2 /common/t-stringhelp.c
parentcommon: New function get_assuan_server_version. (diff)
downloadgnupg-4d7ac43ff71fdadfd2e04621f74840a82fbe788a.tar.gz
gnupg-4d7ac43ff71fdadfd2e04621f74840a82fbe788a.zip
common: New function compare_version_strings.
* common/stringhelp.c (parse_version_number): New. (parse_version_string): New. (compare_version_strings): New. * common/t-stringhelp.c (test_compare_version_strings): New. (main): Call test. Return ERRCOUNT instead of 0. -- The code for that function is based on code from libgcrypt. Similar code is in all GnuPG related libraries this function is a candidates for inclusion in libgpg-error. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r--common/t-stringhelp.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c
index af79cb5cd..b4a41ac39 100644
--- a/common/t-stringhelp.c
+++ b/common/t-stringhelp.c
@@ -705,6 +705,7 @@ stresc (char *s)
return p;
}
+
static void
test_format_text (void)
{
@@ -813,6 +814,65 @@ test_format_text (void)
fail(0);
}
+
+static void
+test_compare_version_strings (void)
+{
+ struct { const char *a; const char *b; int okay; } tests[] = {
+ { "1.0.0", "1.0.0", 1 },
+ { "1.0.0-", "1.0.0", 1 },
+ { "1.0.0-1", "1.0.0", 1 },
+ { "1.0.0.1", "1.0.0", 1 },
+ { "1.0.0", "1.0.1", 0 },
+ { "1.0.0-", "1.0.1", 0 },
+ { "1.0.0-1", "1.0.1", 0 },
+ { "1.0.0.1", "1.0.1", 0 },
+ { "1.0.0", "1.1.0", 0 },
+ { "1.0.0-", "1.1.0", 0 },
+ { "1.0.0-1", "1.1.0", 0 },
+ { "1.0.0.1", "1.1.0", 0 },
+
+ { "1.0.0", "1.0.0-", 1 },
+ { "1.0.0", "1.0.0-1", 1 },
+ { "1.0.0", "1.0.0.1", 1 },
+ { "1.1.0", "1.0.0", 1 },
+ { "1.1.1", "1.1.0", 1 },
+ { "1.1.2", "1.1.2", 1 },
+ { "1.1.2", "1.0.2", 1 },
+ { "1.1.2", "0.0.2", 1 },
+ { "1.1.2", "1.1.3", 0 },
+
+ { "0.99.1", "0.9.9", 1 },
+ { "0.9.1", "0.91.0", 0 },
+
+ { "1.5.3", "1.5", 1 },
+ { "1.5.0", "1.5", 1 },
+ { "1.4.99", "1.5", 0 },
+ { "1.5", "1.4.99", 1 },
+ { "1.5", "1.5.0", 1 },
+ { "1.5", "1.5.1", 0 },
+
+ { "1.5.3-x17", "1.5-23", 1 },
+
+ { "1.5.3a", "1.5.3", 1 },
+ { "1.5.3a", "1.5.3b", 1 },
+
+ { NULL, NULL, 0 }
+ };
+ int idx;
+ int res;
+
+ for (idx=0; idx < DIM(tests); idx++)
+ {
+ res = compare_version_strings (tests[idx].a, tests[idx].b);
+ /* printf ("test %d: '%s' '%s' %d -> %d\n", */
+ /* idx, tests[idx].a, tests[idx].b, tests[idx].okay, res); */
+ if (res != tests[idx].okay)
+ fail (idx);
+ }
+}
+
+
int
main (int argc, char **argv)
{
@@ -827,8 +887,9 @@ main (int argc, char **argv)
test_make_absfilename_try ();
test_strsplit ();
test_strtokenize ();
+ test_compare_version_strings ();
test_format_text ();
xfree (home_buffer);
- return 0;
+ return !!errcount;
}