spawn: Use special invocation for <spawn.h> on OS/2 kLIBC.
[gnulib.git] / tests / test-filevercmp.c
blobd6c65fad9b182ca3b3df099e275b8dd66347e26d
1 /* Test of filevercmp() function.
2 Copyright (C) 2008-2021 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include "filevercmp.h"
21 #include <stddef.h>
23 #include "macros.h"
25 /* set of well sorted examples */
26 static const char *const examples[] =
28 "",
29 ".",
30 "..",
31 ".0",
32 ".9",
33 ".A",
34 ".Z",
35 ".a~",
36 ".a",
37 ".b~",
38 ".b",
39 ".z",
40 ".zz~",
41 ".zz",
42 ".zz.~1~",
43 ".zz.0",
44 "0",
45 "9",
46 "A",
47 "Z",
48 "a~",
49 "a",
50 "a.b~",
51 "a.b",
52 "a.bc~",
53 "a.bc",
54 "b~",
55 "b",
56 "gcc-c++-10.fc9.tar.gz",
57 "gcc-c++-10.fc9.tar.gz.~1~",
58 "gcc-c++-10.fc9.tar.gz.~2~",
59 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2",
60 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2.~1~",
61 "glibc-2-0.1.beta1.fc10.rpm",
62 "glibc-common-5-0.2.beta2.fc9.ebuild",
63 "glibc-common-5-0.2b.deb",
64 "glibc-common-11b.ebuild",
65 "glibc-common-11-0.6rc2.ebuild",
66 "libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz",
67 "libstdc++-4a.fc8.tar.gz",
68 "libstdc++-4.10.4.20040204svn.rpm",
69 "libstdc++-devel-3.fc8.ebuild",
70 "libstdc++-devel-3a.fc9.tar.gz",
71 "libstdc++-devel-8.fc8.deb",
72 "libstdc++-devel-8.6.2-0.4b.fc8",
73 "nss_ldap-1-0.2b.fc9.tar.bz2",
74 "nss_ldap-1-0.6rc2.fc8.tar.gz",
75 "nss_ldap-1.0-0.1a.tar.gz",
76 "nss_ldap-10beta1.fc8.tar.gz",
77 "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild",
78 "z",
79 "zz~",
80 "zz",
81 "zz.~1~",
82 "zz.0",
83 "#.b#",
84 NULL
87 int
88 main (void)
90 const char *const *i;
92 /* Following tests taken from test-strverscmp.c */
93 ASSERT (filevercmp ("", "") == 0);
94 ASSERT (filevercmp ("a", "a") == 0);
95 ASSERT (filevercmp ("a", "b") < 0);
96 ASSERT (filevercmp ("b", "a") > 0);
97 ASSERT (filevercmp ("a0", "a") > 0);
98 ASSERT (filevercmp ("00", "01") < 0);
99 ASSERT (filevercmp ("01", "010") < 0);
100 ASSERT (filevercmp ("9", "10") < 0);
101 ASSERT (filevercmp ("0a", "0") > 0);
103 /* compare each version string with each other - O(n^2) */
104 for (i = examples; *i; i++)
106 const char *const *j;
107 for (j = examples; *j; j++)
109 int result = filevercmp (*i, *j);
110 if (result < 0)
111 ASSERT (i < j);
112 else if (0 < result)
113 ASSERT (j < i);
114 else
115 ASSERT (i == j);
119 return 0;