aboutsummaryrefslogtreecommitdiffstats
path: root/common/t-stringhelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-11-02 15:24:58 +0000
committerWerner Koch <[email protected]>2016-11-02 16:58:11 +0000
commit488b183811fc25c1ae49b4730491accf1adf518e (patch)
tree1c86b55b957697b398f8320cb86c55055eed9dc1 /common/t-stringhelp.c
parentgpgscm: Fix inclusion of readline header. (diff)
downloadgnupg-488b183811fc25c1ae49b4730491accf1adf518e.tar.gz
gnupg-488b183811fc25c1ae49b4730491accf1adf518e.zip
common: Improve compare_string_versions.
* common/stringhelp.c: Include limits.h. (compare_version_strings): Change semantics to behave like strcmp. Include the patch lebel in the comparison. Allow checking a single version string. * common/t-stringhelp.c (test_compare_version_strings): Adjust test vectors and a few new vectors. * g10/call-agent.c (warn_version_mismatch): Adjust to new sematics. * g10/call-dirmngr.c (warn_version_mismatch): Ditto. * sm/call-agent.c (warn_version_mismatch): Ditto. * sm/call-dirmngr.c (warn_version_mismatch): Ditto. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/t-stringhelp.c')
-rw-r--r--common/t-stringhelp.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c
index ccadf0222..93b014ae1 100644
--- a/common/t-stringhelp.c
+++ b/common/t-stringhelp.c
@@ -40,6 +40,7 @@
#endif
#include <unistd.h>
#include <sys/types.h>
+#include <limits.h>
#include "t-support.h"
#include "stringhelp.h"
@@ -903,45 +904,63 @@ 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", 0 },
{ "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.0.0", "1.0.1", -1 },
+ { "1.0.0-", "1.0.1", -1 },
+ { "1.0.0-1", "1.0.1", -1 },
+ { "1.0.0.1", "1.0.1", -1 },
+ { "1.0.0", "1.1.0", -1 },
+ { "1.0.0-", "1.1.0", -1 },
+ { "1.0.0-1", "1.1.0", -1 },
+ { "1.0.0.1", "1.1.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.1.0", "1.0.0", 1 },
{ "1.1.1", "1.1.0", 1 },
- { "1.1.2", "1.1.2", 1 },
+ { "1.1.2", "1.1.2", 0 },
{ "1.1.2", "1.0.2", 1 },
{ "1.1.2", "0.0.2", 1 },
- { "1.1.2", "1.1.3", 0 },
+ { "1.1.2", "1.1.3", -1 },
{ "0.99.1", "0.9.9", 1 },
- { "0.9.1", "0.91.0", 0 },
+ { "0.9.1", "0.91.0", -1 },
{ "1.5.3", "1.5", 1 },
- { "1.5.0", "1.5", 1 },
- { "1.4.99", "1.5", 0 },
+ { "1.5.0", "1.5", 0 },
+ { "1.4.99", "1.5", -1 },
{ "1.5", "1.4.99", 1 },
- { "1.5", "1.5.0", 1 },
- { "1.5", "1.5.1", 0 },
+ { "1.5", "1.5.0", 0 },
+ { "1.5", "1.5.1", -1 },
{ "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 }
+ { "1.5.3a", "1.5.3b", -1 },
+
+ { "3.1.4-ab", "3.1.4-ab", 0 },
+ { "3.1.4-ab", "3.1.4-ac", -1 },
+ { "3.1.4-ac", "3.1.4-ab", 1 },
+ { "3.1.4-ab", "3.1.4-abb", -1 },
+ { "3.1.4-abb", "3.1.4-ab", 1 },
+
+ { "", "", INT_MIN },
+ { NULL, "", INT_MIN },
+ { "1.2.3", "", INT_MIN },
+ { "1.2.3", "2", INT_MIN },
+
+ /* Test cases for validity of A. */
+ { "", NULL, INT_MIN },
+ { "1", NULL, INT_MIN },
+ { "1.", NULL, 0 },
+ { "1.0", NULL, 0 },
+ { "1.0.", NULL, 0 },
+ { "a1.2", NULL, INT_MIN },
+ { NULL, NULL, INT_MIN }
};
int idx;
int res;